using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CallCenterApi.DB;//Please add references
namespace CallCenterApi.DAL
{

    /// <summary>
    /// 数据访问类:T_Bus_WorkOrder
    /// </summary>
    public partial class T_Bus_WorkOrder
    {
        public T_Bus_WorkOrder()
        {
        }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("F_Id", "T_Bus_WorkOrder");
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string F_WorkOrderId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Bus_WorkOrder");
            strSql.Append(" where F_WorkOrderId=@F_WorkOrderId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WorkOrderId", SqlDbType.NVarChar,20)
            };
            parameters[0].Value = F_WorkOrderId;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(CallCenterApi.Model.T_Bus_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Bus_WorkOrder(");
            strSql.Append("F_WorkOrderId,F_CusName,F_CusSex,F_CusPhone,F_CusAddress,F_ConName,F_ConPhone,F_ZipCode,F_Email,F_InfoSource,F_ComTitle,F_ComContent,F_File,F_InfoType,F_InfoConBigType,F_InfoConSmallType,F_SourceArea,F_SourceAddress,F_IsProtect,F_IsResult,F_Result,F_CallRecordId,F_LeaveRecordId,F_WorkState,F_IsClosed,F_RemindDay,F_LimitTime,F_IsOverdue,F_CreateUser,F_CreateTime,F_IsEnabled,F_EnableTime,F_IsDelete,F_DeleteTime,F_Key,F_SplitUser,F_Level,F_CloseTime,F_CloseUser,F_EndUser,F_EndTime,F_IsSatisfie,F_FinalOpinion,F_IsRelease,F_CallId,F_IsReturn,F_IsNotice,F_NoticeUser,F_NoticeTime,F_SubmitTime)");
            strSql.Append(" values (");
            strSql.Append("@F_WorkOrderId,@F_CusName,@F_CusSex,@F_CusPhone,@F_CusAddress,@F_ConName,@F_ConPhone,@F_ZipCode,@F_Email,@F_InfoSource,@F_ComTitle,@F_ComContent,@F_File,@F_InfoType,@F_InfoConBigType,@F_InfoConSmallType,@F_SourceArea,@F_SourceAddress,@F_IsProtect,@F_IsResult,@F_Result,@F_CallRecordId,@F_LeaveRecordId,@F_WorkState,@F_IsClosed,@F_RemindDay,@F_LimitTime,@F_IsOverdue,@F_CreateUser,@F_CreateTime,@F_IsEnabled,@F_EnableTime,@F_IsDelete,@F_DeleteTime,@F_Key,@F_SplitUser,@F_Level,@F_CloseTime,@F_CloseUser,@F_EndUser,@F_EndTime,@F_IsSatisfie,@F_FinalOpinion,@F_IsRelease,@F_CallId,@F_IsReturn,@F_IsNotice,@F_NoticeUser,@F_NoticeTime,@F_SubmitTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WorkOrderId", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusSex", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CusPhone", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusAddress", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_ConName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ConPhone", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ZipCode", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_Email", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_InfoSource", SqlDbType.Int,4),
                    new SqlParameter("@F_ComTitle", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_ComContent", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_File", SqlDbType.VarChar,500),
                    new SqlParameter("@F_InfoType", SqlDbType.Int,4),
                    new SqlParameter("@F_InfoConBigType", SqlDbType.Int,4),
                    new SqlParameter("@F_InfoConSmallType", SqlDbType.Int,4),
                    new SqlParameter("@F_SourceArea", SqlDbType.Int,4),
                    new SqlParameter("@F_SourceAddress", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsProtect", SqlDbType.Int,4),
                    new SqlParameter("@F_IsResult", SqlDbType.Int,4),
                    new SqlParameter("@F_Result", SqlDbType.Text),
                    new SqlParameter("@F_CallRecordId", SqlDbType.Int,4),
                    new SqlParameter("@F_LeaveRecordId", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkState", SqlDbType.Int,4),
                    new SqlParameter("@F_IsClosed", SqlDbType.Int,4),
                    new SqlParameter("@F_RemindDay", SqlDbType.Int,4),
                    new SqlParameter("@F_LimitTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsOverdue", SqlDbType.Int,4),
                    new SqlParameter("@F_CreateUser", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsEnabled", SqlDbType.Int,4),
                    new SqlParameter("@F_EnableTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Key", SqlDbType.VarChar,500),
                    new SqlParameter("@F_SplitUser", SqlDbType.VarChar,500),
                    new SqlParameter("@F_Level", SqlDbType.Int,4),
                    new SqlParameter("@F_CloseTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CloseUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EndUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EndTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsSatisfie", SqlDbType.Int,4),
                    new SqlParameter("@F_FinalOpinion", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_IsRelease", SqlDbType.Int,4),
                    new SqlParameter("@F_CallId", SqlDbType.VarChar,50),
                    new SqlParameter("@F_IsReturn", SqlDbType.Int,4),
                    new SqlParameter("@F_IsNotice", SqlDbType.Int,4),
                    new SqlParameter("@F_NoticeUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_NoticeTime", SqlDbType.DateTime),
                    new SqlParameter("@F_SubmitTime", SqlDbType.DateTime)};
            parameters[0].Value = model.F_WorkOrderId;
            parameters[1].Value = model.F_CusName;
            parameters[2].Value = model.F_CusSex;
            parameters[3].Value = model.F_CusPhone;
            parameters[4].Value = model.F_CusAddress;
            parameters[5].Value = model.F_ConName;
            parameters[6].Value = model.F_ConPhone;
            parameters[7].Value = model.F_ZipCode;
            parameters[8].Value = model.F_Email;
            parameters[9].Value = model.F_InfoSource;
            parameters[10].Value = model.F_ComTitle;
            parameters[11].Value = model.F_ComContent;
            parameters[12].Value = model.F_File;
            parameters[13].Value = model.F_InfoType;
            parameters[14].Value = model.F_InfoConBigType;
            parameters[15].Value = model.F_InfoConSmallType;
            parameters[16].Value = model.F_SourceArea;
            parameters[17].Value = model.F_SourceAddress;
            parameters[18].Value = model.F_IsProtect;
            parameters[19].Value = model.F_IsResult;
            parameters[20].Value = model.F_Result;
            parameters[21].Value = model.F_CallRecordId;
            parameters[22].Value = model.F_LeaveRecordId;
            parameters[23].Value = model.F_WorkState;
            parameters[24].Value = model.F_IsClosed;
            parameters[25].Value = model.F_RemindDay;
            parameters[26].Value = model.F_LimitTime;
            parameters[27].Value = model.F_IsOverdue;
            parameters[28].Value = model.F_CreateUser;
            parameters[29].Value = model.F_CreateTime;
            parameters[30].Value = model.F_IsEnabled;
            parameters[31].Value = model.F_EnableTime;
            parameters[32].Value = model.F_IsDelete;
            parameters[33].Value = model.F_DeleteTime;
            parameters[34].Value = model.F_Key;
            parameters[35].Value = model.F_SplitUser;
            parameters[36].Value = model.F_Level;
            parameters[37].Value = model.F_CloseTime;
            parameters[38].Value = model.F_CloseUser;
            parameters[39].Value = model.F_EndUser;
            parameters[40].Value = model.F_EndTime;
            parameters[41].Value = model.F_IsSatisfie;
            parameters[42].Value = model.F_FinalOpinion;
            parameters[43].Value = model.F_IsRelease;
            parameters[44].Value = model.F_CallId;
            parameters[45].Value = model.F_IsReturn;
            parameters[46].Value = model.F_IsNotice;
            parameters[47].Value = model.F_NoticeUser;
            parameters[48].Value = model.F_NoticeTime;
            parameters[49].Value = model.F_SubmitTime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CallCenterApi.Model.T_Bus_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Bus_WorkOrder set ");
            strSql.Append("F_WorkOrderId=@F_WorkOrderId,");
            strSql.Append("F_CusName=@F_CusName,");
            strSql.Append("F_CusSex=@F_CusSex,");
            strSql.Append("F_CusPhone=@F_CusPhone,");
            strSql.Append("F_CusAddress=@F_CusAddress,");
            strSql.Append("F_ConName=@F_ConName,");
            strSql.Append("F_ConPhone=@F_ConPhone,");
            strSql.Append("F_ZipCode=@F_ZipCode,");
            strSql.Append("F_Email=@F_Email,");
            strSql.Append("F_InfoSource=@F_InfoSource,");
            strSql.Append("F_ComTitle=@F_ComTitle,");
            strSql.Append("F_ComContent=@F_ComContent,");
            strSql.Append("F_File=@F_File,");
            strSql.Append("F_InfoType=@F_InfoType,");
            strSql.Append("F_InfoConBigType=@F_InfoConBigType,");
            strSql.Append("F_InfoConSmallType=@F_InfoConSmallType,");
            strSql.Append("F_SourceArea=@F_SourceArea,");
            strSql.Append("F_SourceAddress=@F_SourceAddress,");
            strSql.Append("F_IsProtect=@F_IsProtect,");
            strSql.Append("F_IsResult=@F_IsResult,");
            strSql.Append("F_Result=@F_Result,");
            strSql.Append("F_CallRecordId=@F_CallRecordId,");
            strSql.Append("F_LeaveRecordId=@F_LeaveRecordId,");
            strSql.Append("F_WorkState=@F_WorkState,");
            strSql.Append("F_IsClosed=@F_IsClosed,");
            strSql.Append("F_RemindDay=@F_RemindDay,");
            strSql.Append("F_LimitTime=@F_LimitTime,");
            strSql.Append("F_IsOverdue=@F_IsOverdue,");
            strSql.Append("F_CreateUser=@F_CreateUser,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_IsEnabled=@F_IsEnabled,");
            strSql.Append("F_EnableTime=@F_EnableTime,");
            strSql.Append("F_IsDelete=@F_IsDelete,");
            strSql.Append("F_DeleteTime=@F_DeleteTime,");
            strSql.Append("F_Key=@F_Key,");
            strSql.Append("F_SplitUser=@F_SplitUser,");
            strSql.Append("F_Level=@F_Level,");
            strSql.Append("F_CloseTime=@F_CloseTime,");
            strSql.Append("F_CloseUser=@F_CloseUser,");
            strSql.Append("F_EndUser=@F_EndUser,");
            strSql.Append("F_EndTime=@F_EndTime,");
            strSql.Append("F_IsSatisfie=@F_IsSatisfie,");
            strSql.Append("F_FinalOpinion=@F_FinalOpinion,");
            strSql.Append("F_IsRelease=@F_IsRelease,");
            strSql.Append("F_CallId=@F_CallId,");
            strSql.Append("F_IsReturn=@F_IsReturn,");
            strSql.Append("F_IsNotice=@F_IsNotice,");
            strSql.Append("F_NoticeUser=@F_NoticeUser,");
            strSql.Append("F_NoticeTime=@F_NoticeTime,");
            strSql.Append("F_SubmitTime=@F_SubmitTime");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WorkOrderId", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusSex", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CusPhone", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CusAddress", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_ConName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ConPhone", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ZipCode", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_Email", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_InfoSource", SqlDbType.Int,4),
                    new SqlParameter("@F_ComTitle", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_ComContent", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_File", SqlDbType.VarChar,500),
                    new SqlParameter("@F_InfoType", SqlDbType.Int,4),
                    new SqlParameter("@F_InfoConBigType", SqlDbType.Int,4),
                    new SqlParameter("@F_InfoConSmallType", SqlDbType.Int,4),
                    new SqlParameter("@F_SourceArea", SqlDbType.Int,4),
                    new SqlParameter("@F_SourceAddress", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsProtect", SqlDbType.Int,4),
                    new SqlParameter("@F_IsResult", SqlDbType.Int,4),
                    new SqlParameter("@F_Result", SqlDbType.Text),
                    new SqlParameter("@F_CallRecordId", SqlDbType.Int,4),
                    new SqlParameter("@F_LeaveRecordId", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkState", SqlDbType.Int,4),
                    new SqlParameter("@F_IsClosed", SqlDbType.Int,4),
                    new SqlParameter("@F_RemindDay", SqlDbType.Int,4),
                    new SqlParameter("@F_LimitTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsOverdue", SqlDbType.Int,4),
                    new SqlParameter("@F_CreateUser", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsEnabled", SqlDbType.Int,4),
                    new SqlParameter("@F_EnableTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Key", SqlDbType.VarChar,500),
                    new SqlParameter("@F_SplitUser", SqlDbType.VarChar,500),
                    new SqlParameter("@F_Level", SqlDbType.Int,4),
                    new SqlParameter("@F_CloseTime", SqlDbType.DateTime),
                    new SqlParameter("@F_CloseUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EndUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_EndTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsSatisfie", SqlDbType.Int,4),
                    new SqlParameter("@F_FinalOpinion", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_IsRelease", SqlDbType.Int,4),
                    new SqlParameter("@F_CallId", SqlDbType.VarChar,50),
                    new SqlParameter("@F_IsReturn", SqlDbType.Int,4),
                    new SqlParameter("@F_IsNotice", SqlDbType.Int,4),
                    new SqlParameter("@F_NoticeUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_NoticeTime", SqlDbType.DateTime),
                    new SqlParameter("@F_SubmitTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_WorkOrderId;
            parameters[1].Value = model.F_CusName;
            parameters[2].Value = model.F_CusSex;
            parameters[3].Value = model.F_CusPhone;
            parameters[4].Value = model.F_CusAddress;
            parameters[5].Value = model.F_ConName;
            parameters[6].Value = model.F_ConPhone;
            parameters[7].Value = model.F_ZipCode;
            parameters[8].Value = model.F_Email;
            parameters[9].Value = model.F_InfoSource;
            parameters[10].Value = model.F_ComTitle;
            parameters[11].Value = model.F_ComContent;
            parameters[12].Value = model.F_File;
            parameters[13].Value = model.F_InfoType;
            parameters[14].Value = model.F_InfoConBigType;
            parameters[15].Value = model.F_InfoConSmallType;
            parameters[16].Value = model.F_SourceArea;
            parameters[17].Value = model.F_SourceAddress;
            parameters[18].Value = model.F_IsProtect;
            parameters[19].Value = model.F_IsResult;
            parameters[20].Value = model.F_Result;
            parameters[21].Value = model.F_CallRecordId;
            parameters[22].Value = model.F_LeaveRecordId;
            parameters[23].Value = model.F_WorkState;
            parameters[24].Value = model.F_IsClosed;
            parameters[25].Value = model.F_RemindDay;
            parameters[26].Value = model.F_LimitTime;
            parameters[27].Value = model.F_IsOverdue;
            parameters[28].Value = model.F_CreateUser;
            parameters[29].Value = model.F_CreateTime;
            parameters[30].Value = model.F_IsEnabled;
            parameters[31].Value = model.F_EnableTime;
            parameters[32].Value = model.F_IsDelete;
            parameters[33].Value = model.F_DeleteTime;
            parameters[34].Value = model.F_Key;
            parameters[35].Value = model.F_SplitUser;
            parameters[36].Value = model.F_Level;
            parameters[37].Value = model.F_CloseTime;
            parameters[38].Value = model.F_CloseUser;
            parameters[39].Value = model.F_EndUser;
            parameters[40].Value = model.F_EndTime;
            parameters[41].Value = model.F_IsSatisfie;
            parameters[42].Value = model.F_FinalOpinion;
            parameters[43].Value = model.F_IsRelease;
            parameters[44].Value = model.F_CallId;
            parameters[45].Value = model.F_IsReturn;
            parameters[46].Value = model.F_IsNotice;
            parameters[47].Value = model.F_NoticeUser;
            parameters[48].Value = model.F_NoticeTime;
            parameters[49].Value = model.F_SubmitTime;
            parameters[50].Value = model.F_Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Bus_WorkOrder ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_Idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Bus_WorkOrder ");
            strSql.Append(" where F_Id in (" + F_Idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteLogicList(string F_WorkOrderIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Bus_WorkOrder set F_IsDelete=1 ");
            strSql.Append(" where F_WorkOrderId in (" + F_WorkOrderIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CallCenterApi.Model.T_Bus_WorkOrder GetModel(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from T_Bus_WorkOrder ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

            CallCenterApi.Model.T_Bus_WorkOrder model = new CallCenterApi.Model.T_Bus_WorkOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CallCenterApi.Model.T_Bus_WorkOrder GetModel(string F_WorkOrderId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from T_Bus_WorkOrder ");
            strSql.Append(" where F_WorkOrderId=@F_WorkOrderId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WorkOrderId", SqlDbType.NVarChar,20)
            };
            parameters[0].Value = F_WorkOrderId;

            CallCenterApi.Model.T_Bus_WorkOrder model = new CallCenterApi.Model.T_Bus_WorkOrder();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CallCenterApi.Model.T_Bus_WorkOrder DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Bus_WorkOrder model = new CallCenterApi.Model.T_Bus_WorkOrder();
            if (row != null)
            {
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
                {
                    model.F_Id = int.Parse(row["F_Id"].ToString());
                }
                if (row["F_WorkOrderId"] != null)
                {
                    model.F_WorkOrderId = row["F_WorkOrderId"].ToString();
                }
                if (row["F_CusName"] != null)
                {
                    model.F_CusName = row["F_CusName"].ToString();
                }
                if (row["F_CusSex"] != null)
                {
                    model.F_CusSex = row["F_CusSex"].ToString();
                }
                if (row["F_CusPhone"] != null)
                {
                    model.F_CusPhone = row["F_CusPhone"].ToString();
                }
                if (row["F_CusAddress"] != null)
                {
                    model.F_CusAddress = row["F_CusAddress"].ToString();
                }
                if (row["F_ConName"] != null)
                {
                    model.F_ConName = row["F_ConName"].ToString();
                }
                if (row["F_ConPhone"] != null)
                {
                    model.F_ConPhone = row["F_ConPhone"].ToString();
                }
                if (row["F_ZipCode"] != null)
                {
                    model.F_ZipCode = row["F_ZipCode"].ToString();
                }
                if (row["F_Email"] != null)
                {
                    model.F_Email = row["F_Email"].ToString();
                }
                if (row["F_InfoSource"] != null && row["F_InfoSource"].ToString() != "")
                {
                    model.F_InfoSource = int.Parse(row["F_InfoSource"].ToString());
                }
                if (row["F_ComTitle"] != null)
                {
                    model.F_ComTitle = row["F_ComTitle"].ToString();
                }
                if (row["F_ComContent"] != null)
                {
                    model.F_ComContent = row["F_ComContent"].ToString();
                }
                if (row["F_File"] != null)
                {
                    model.F_File = row["F_File"].ToString();
                }
                if (row["F_InfoType"] != null && row["F_InfoType"].ToString() != "")
                {
                    model.F_InfoType = int.Parse(row["F_InfoType"].ToString());
                }
                if (row["F_InfoConBigType"] != null && row["F_InfoConBigType"].ToString() != "")
                {
                    model.F_InfoConBigType = int.Parse(row["F_InfoConBigType"].ToString());
                }
                if (row["F_InfoConSmallType"] != null && row["F_InfoConSmallType"].ToString() != "")
                {
                    model.F_InfoConSmallType = int.Parse(row["F_InfoConSmallType"].ToString());
                }
                if (row["F_SourceArea"] != null && row["F_SourceArea"].ToString() != "")
                {
                    model.F_SourceArea = int.Parse(row["F_SourceArea"].ToString());
                }
                if (row["F_SourceAddress"] != null)
                {
                    model.F_SourceAddress = row["F_SourceAddress"].ToString();
                }
                if (row["F_IsProtect"] != null && row["F_IsProtect"].ToString() != "")
                {
                    model.F_IsProtect = int.Parse(row["F_IsProtect"].ToString());
                }
                if (row["F_IsResult"] != null && row["F_IsResult"].ToString() != "")
                {
                    model.F_IsResult = int.Parse(row["F_IsResult"].ToString());
                }
                if (row["F_Result"] != null)
                {
                    model.F_Result = row["F_Result"].ToString();
                }
                if (row["F_CallRecordId"] != null && row["F_CallRecordId"].ToString() != "")
                {
                    model.F_CallRecordId = int.Parse(row["F_CallRecordId"].ToString());
                }
                if (row["F_LeaveRecordId"] != null && row["F_LeaveRecordId"].ToString() != "")
                {
                    model.F_LeaveRecordId = int.Parse(row["F_LeaveRecordId"].ToString());
                }
                if (row["F_WorkState"] != null && row["F_WorkState"].ToString() != "")
                {
                    model.F_WorkState = int.Parse(row["F_WorkState"].ToString());
                }
                if (row["F_IsClosed"] != null && row["F_IsClosed"].ToString() != "")
                {
                    model.F_IsClosed = int.Parse(row["F_IsClosed"].ToString());
                }
                if (row["F_RemindDay"] != null && row["F_RemindDay"].ToString() != "")
                {
                    model.F_RemindDay = int.Parse(row["F_RemindDay"].ToString());
                }
                if (row["F_LimitTime"] != null && row["F_LimitTime"].ToString() != "")
                {
                    model.F_LimitTime = DateTime.Parse(row["F_LimitTime"].ToString());
                }
                if (row["F_IsOverdue"] != null && row["F_IsOverdue"].ToString() != "")
                {
                    model.F_IsOverdue = int.Parse(row["F_IsOverdue"].ToString());
                }
                if (row["F_CreateUser"] != null)
                {
                    model.F_CreateUser = row["F_CreateUser"].ToString();
                }
                if (row["F_CreateTime"] != null && row["F_CreateTime"].ToString() != "")
                {
                    model.F_CreateTime = DateTime.Parse(row["F_CreateTime"].ToString());
                }
                if (row["F_IsEnabled"] != null && row["F_IsEnabled"].ToString() != "")
                {
                    model.F_IsEnabled = int.Parse(row["F_IsEnabled"].ToString());
                }
                if (row["F_EnableTime"] != null && row["F_EnableTime"].ToString() != "")
                {
                    model.F_EnableTime = DateTime.Parse(row["F_EnableTime"].ToString());
                }
                if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "")
                {
                    model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString());
                }
                if (row["F_DeleteTime"] != null && row["F_DeleteTime"].ToString() != "")
                {
                    model.F_DeleteTime = DateTime.Parse(row["F_DeleteTime"].ToString());
                }
                if (row["F_Key"] != null)
                {
                    model.F_Key = row["F_Key"].ToString();
                }
                if (row["F_SplitUser"] != null)
                {
                    model.F_SplitUser = row["F_SplitUser"].ToString();
                }
                if (row["F_Level"] != null && row["F_Level"].ToString() != "")
                {
                    model.F_Level = int.Parse(row["F_Level"].ToString());
                }
                if (row["F_CloseTime"] != null && row["F_CloseTime"].ToString() != "")
                {
                    model.F_CloseTime = DateTime.Parse(row["F_CloseTime"].ToString());
                }
                if (row["F_CloseUser"] != null)
                {
                    model.F_CloseUser = row["F_CloseUser"].ToString();
                }
                if (row["F_EndUser"] != null)
                {
                    model.F_EndUser = row["F_EndUser"].ToString();
                }
                if (row["F_EndTime"] != null && row["F_EndTime"].ToString() != "")
                {
                    model.F_EndTime = DateTime.Parse(row["F_EndTime"].ToString());
                }
                if (row["F_IsSatisfie"] != null && row["F_IsSatisfie"].ToString() != "")
                {
                    model.F_IsSatisfie = int.Parse(row["F_IsSatisfie"].ToString());
                }
                if (row["F_FinalOpinion"] != null)
                {
                    model.F_FinalOpinion = row["F_FinalOpinion"].ToString();
                }
                if (row["F_IsRelease"] != null && row["F_IsRelease"].ToString() != "")
                {
                    model.F_IsRelease = int.Parse(row["F_IsRelease"].ToString());
                }
                if (row["F_CallId"] != null)
                {
                    model.F_CallId = row["F_CallId"].ToString();
                }
                if (row["F_IsReturn"] != null && row["F_IsReturn"].ToString() != "")
                {
                    model.F_IsReturn = int.Parse(row["F_IsReturn"].ToString());
                }
                if (row["F_IsNotice"] != null && row["F_IsNotice"].ToString() != "")
                {
                    model.F_IsNotice = int.Parse(row["F_IsNotice"].ToString());
                }
                if (row["F_NoticeUser"] != null)
                {
                    model.F_NoticeUser = row["F_NoticeUser"].ToString();
                }
                if (row["F_NoticeTime"] != null && row["F_NoticeTime"].ToString() != "")
                {
                    model.F_NoticeTime = DateTime.Parse(row["F_NoticeTime"].ToString());
                }
                if (row["F_SubmitTime"] != null && row["F_SubmitTime"].ToString() != "")
                {
                    model.F_SubmitTime = DateTime.Parse(row["F_SubmitTime"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM T_Bus_WorkOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }

            strSql.Append(" * FROM T_Bus_WorkOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM T_Bus_WorkOrder ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.F_Id desc");
            }
            strSql.Append(")AS Row, T.*  from T_Bus_WorkOrder T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "T_Bus_WorkOrder";
            parameters[1].Value = "F_Id";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/


        /// <summary>
        /// 根据坐席号获取新的工单号
        /// </summary>
        /// <param name="p_UserCode"></param>
        /// <returns></returns>
        public string GetNewWorkOrderID(string p_UserCode)
        {

            string newWorkOrderID = string.Empty;//新工单号

            #region 旧方法
            //string oldWorkOrderID = string.Empty;
            //string headPart = DateTime.Now.ToString("yyyyMMdd");//工单号前8位
            //string middlePart = string.Empty;//工单号中间部分
            //string endPart = "0001";//工单号最后部分，如果超过初始位数，自动从头开始           
            //StringBuilder strSql = new StringBuilder();
            //object p_Result = null;
            ////如果是网站
            //if (string.IsNullOrEmpty(p_UserCode.Trim()))
            //{
            //    middlePart = "00";
            //    strSql.Append("select top 1 F_WorkOrderId from T_Bus_WorkOrder");
            //    //strSql.Append(" where F_UserCode is null or F_UserCode=''  order by F_RegDate desc");
            //    strSql.AppendFormat(" where F_WorkOrderId like '{0}%' order by F_WorkOrderId desc", headPart + middlePart);
            //    p_Result = DbHelperSQL.GetSingle(strSql.ToString());
            //}
            //else
            //{
            //    middlePart = p_UserCode;
            //    strSql.Append("select top 1 F_WorkOrderId from T_Bus_WorkOrder");
            //    //strSql.Append(" where  F_UserCode=@F_UserCode  order by F_RegDate desc");
            //    strSql.AppendFormat(" where  F_WorkOrderId like '{0}%'  order by F_WorkOrderId desc", headPart + middlePart);
            //    SqlParameter[] parameters = {
            //        new SqlParameter("@F_UserCode", SqlDbType.NVarChar,20)};
            //    parameters[0].Value = p_UserCode;
            //    p_Result = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            //}


            //if (p_Result != null)
            //{

            //    oldWorkOrderID = p_Result.ToString();
            //    if (oldWorkOrderID.Length > 8)
            //    {
            //        string oldHead = oldWorkOrderID.Substring(0, 8);
            //        string oldEnd = oldWorkOrderID.Substring(oldWorkOrderID.Length - endPart.Length);
            //        int num = Convert.ToInt32(oldEnd) + 1;
            //        string newCode = string.Empty;
            //        for (int i = num.ToString().Length; i < endPart.Length; i++)
            //        {
            //            newCode += "0";
            //        }
            //        endPart = newCode + num;
            //    }

            //}
            //newWorkOrderID = headPart + middlePart + endPart; 
            #endregion

            newWorkOrderID=DbHelperSQL.GetSingle("select dbo.GetNewWorkOrderId('"+ p_UserCode + "')").ToString();

            return newWorkOrderID;
        }
        #endregion  Method
    }
}

