using CallCenterApi.DB;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CallCenterApi.DAL
{
    // <summary>
    /// 数据访问类:T_Sys_UserAccount
    /// </summary>
    public partial class T_Sys_UserAccount
    {
        public T_Sys_UserAccount()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQL.GetMaxID("F_UserId", "T_Sys_UserAccount");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_UserId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Sys_UserAccount");
            strSql.Append(" where F_UserId=@F_UserId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserId", SqlDbType.Int,4)
            };
            parameters[0].Value = F_UserId;

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


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.T_Sys_UserAccount model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Sys_UserAccount(");
            strSql.Append("F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup)");
            strSql.Append(" values (");
            strSql.Append("@F_UserCode,@F_Password,@F_ExtensionNumber,@F_UserName,@F_DeptId,@F_RoleId,@F_GroupId,@F_SeatFlag,@F_SeatRight,@F_SeatLevel,@F_SexFlag,@F_RemindFlag,@F_Remark,@F_Telephone,@F_Mobile,@F_HomePhone,@F_Birthday,@F_CreateOn,@F_CancelOn,@F_DeleteFlag,@F_APPOnFlag,@F_LastActiveTime,@F_See,@F_HJType,@F_PId,@F_TmId,@F_WorkNumber,@F_DeptCode,@F_WXNo,@F_SeartGroupID,@F_SeartGroup)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Password", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ExtensionNumber", SqlDbType.VarChar,50),
                    new SqlParameter("@F_UserName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_RoleId", SqlDbType.Int,4),
                    new SqlParameter("@F_GroupId", SqlDbType.Int,4),
                    new SqlParameter("@F_SeatFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_SeatRight", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SeatLevel", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SexFlag", SqlDbType.VarChar,50),
                    new SqlParameter("@F_RemindFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_Remark", SqlDbType.VarChar,200),
                    new SqlParameter("@F_Telephone", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Mobile", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HomePhone", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Birthday", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_CancelOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_APPOnFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_LastActiveTime", SqlDbType.DateTime),
                    new SqlParameter("@F_See", SqlDbType.VarChar,100),
                    new SqlParameter("@F_HJType", SqlDbType.Int,4),
                    new SqlParameter("@F_PId", SqlDbType.Int,4),
                    new SqlParameter("@F_TmId", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkNumber", SqlDbType.VarChar,-1),
                    new SqlParameter("@F_DeptCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WXNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_SeartGroupID", SqlDbType.Int,4),
                    new SqlParameter("@F_SeartGroup", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.F_UserCode;
            parameters[1].Value = model.F_Password;
            parameters[2].Value = model.F_ExtensionNumber;
            parameters[3].Value = model.F_UserName;
            parameters[4].Value = model.F_DeptId;
            parameters[5].Value = model.F_RoleId;
            parameters[6].Value = model.F_GroupId;
            parameters[7].Value = model.F_SeatFlag;
            parameters[8].Value = model.F_SeatRight;
            parameters[9].Value = model.F_SeatLevel;
            parameters[10].Value = model.F_SexFlag;
            parameters[11].Value = model.F_RemindFlag;
            parameters[12].Value = model.F_Remark;
            parameters[13].Value = model.F_Telephone;
            parameters[14].Value = model.F_Mobile;
            parameters[15].Value = model.F_HomePhone;
            parameters[16].Value = model.F_Birthday;
            parameters[17].Value = model.F_CreateOn;
            parameters[18].Value = model.F_CancelOn;
            parameters[19].Value = model.F_DeleteFlag;
            parameters[20].Value = model.F_APPOnFlag;
            parameters[21].Value = model.F_LastActiveTime;
            parameters[22].Value = model.F_See;
            parameters[23].Value = model.F_HJType;
            parameters[24].Value = model.F_PId;
            parameters[25].Value = model.F_TmId;
            parameters[26].Value = model.F_WorkNumber;
            parameters[27].Value = model.F_DeptCode;
            parameters[28].Value = model.F_WXNo;
            parameters[29].Value = model.F_SeartGroupID;
            parameters[30].Value = model.F_SeartGroup;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.T_Sys_UserAccount model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Sys_UserAccount set ");
            strSql.Append("F_UserCode=@F_UserCode,");
            strSql.Append("F_Password=@F_Password,");
            strSql.Append("F_ExtensionNumber=@F_ExtensionNumber,");
            strSql.Append("F_UserName=@F_UserName,");
            strSql.Append("F_DeptId=@F_DeptId,");
            strSql.Append("F_RoleId=@F_RoleId,");
            strSql.Append("F_GroupId=@F_GroupId,");
            strSql.Append("F_SeatFlag=@F_SeatFlag,");
            strSql.Append("F_SeatRight=@F_SeatRight,");
            strSql.Append("F_SeatLevel=@F_SeatLevel,");
            strSql.Append("F_SexFlag=@F_SexFlag,");
            strSql.Append("F_RemindFlag=@F_RemindFlag,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_Telephone=@F_Telephone,");
            strSql.Append("F_Mobile=@F_Mobile,");
            strSql.Append("F_HomePhone=@F_HomePhone,");
            strSql.Append("F_Birthday=@F_Birthday,");
            strSql.Append("F_CreateOn=@F_CreateOn,");
            strSql.Append("F_CancelOn=@F_CancelOn,");
            strSql.Append("F_DeleteFlag=@F_DeleteFlag,");
            strSql.Append("F_APPOnFlag=@F_APPOnFlag,");
            strSql.Append("F_LastActiveTime=@F_LastActiveTime,");
            strSql.Append("F_See=@F_See,");
            strSql.Append("F_HJType=@F_HJType,");
            strSql.Append("F_PId=@F_PId,");
            strSql.Append("F_TmId=@F_TmId,");
            strSql.Append("F_WorkNumber=@F_WorkNumber,");
            strSql.Append("F_DeptCode=@F_DeptCode,");
            strSql.Append("F_WXNo=@F_WXNo,");
            strSql.Append("F_SeartGroupID=@F_SeartGroupID,");
            strSql.Append("F_SeartGroup=@F_SeartGroup");
            strSql.Append(" where F_UserId=@F_UserId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Password", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ExtensionNumber", SqlDbType.VarChar,50),
                    new SqlParameter("@F_UserName", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_RoleId", SqlDbType.Int,4),
                    new SqlParameter("@F_GroupId", SqlDbType.Int,4),
                    new SqlParameter("@F_SeatFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_SeatRight", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SeatLevel", SqlDbType.VarChar,50),
                    new SqlParameter("@F_SexFlag", SqlDbType.VarChar,50),
                    new SqlParameter("@F_RemindFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_Remark", SqlDbType.VarChar,200),
                    new SqlParameter("@F_Telephone", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Mobile", SqlDbType.VarChar,50),
                    new SqlParameter("@F_HomePhone", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Birthday", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_CancelOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_APPOnFlag", SqlDbType.Bit,1),
                    new SqlParameter("@F_LastActiveTime", SqlDbType.DateTime),
                    new SqlParameter("@F_See", SqlDbType.VarChar,100),
                    new SqlParameter("@F_HJType", SqlDbType.Int,4),
                    new SqlParameter("@F_PId", SqlDbType.Int,4),
                    new SqlParameter("@F_TmId", SqlDbType.Int,4),
                    new SqlParameter("@F_WorkNumber", SqlDbType.VarChar,-1),
                    new SqlParameter("@F_DeptCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_WXNo", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_SeartGroupID", SqlDbType.Int,4),
                    new SqlParameter("@F_SeartGroup", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_UserId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_UserCode;
            parameters[1].Value = model.F_Password;
            parameters[2].Value = model.F_ExtensionNumber;
            parameters[3].Value = model.F_UserName;
            parameters[4].Value = model.F_DeptId;
            parameters[5].Value = model.F_RoleId;
            parameters[6].Value = model.F_GroupId;
            parameters[7].Value = model.F_SeatFlag;
            parameters[8].Value = model.F_SeatRight;
            parameters[9].Value = model.F_SeatLevel;
            parameters[10].Value = model.F_SexFlag;
            parameters[11].Value = model.F_RemindFlag;
            parameters[12].Value = model.F_Remark;
            parameters[13].Value = model.F_Telephone;
            parameters[14].Value = model.F_Mobile;
            parameters[15].Value = model.F_HomePhone;
            parameters[16].Value = model.F_Birthday;
            parameters[17].Value = model.F_CreateOn;
            parameters[18].Value = model.F_CancelOn;
            parameters[19].Value = model.F_DeleteFlag;
            parameters[20].Value = model.F_APPOnFlag;
            parameters[21].Value = model.F_LastActiveTime;
            parameters[22].Value = model.F_See;
            parameters[23].Value = model.F_HJType;
            parameters[24].Value = model.F_PId;
            parameters[25].Value = model.F_TmId;
            parameters[26].Value = model.F_WorkNumber;
            parameters[27].Value = model.F_DeptCode;
            parameters[28].Value = model.F_WXNo;
            parameters[29].Value = model.F_SeartGroupID;
            parameters[30].Value = model.F_SeartGroup;
            parameters[31].Value = model.F_UserId;

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

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

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

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_UserIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Sys_UserAccount ");
            strSql.Append(" where F_UserId in (" + F_UserIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_UserIdlist, int state)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Sys_UserAccount set F_DeleteFlag=@state");
            strSql.Append(" where F_UserId in (" + F_UserIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), new SqlParameter("@state", state));
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 登录得到一个对象实体
        /// </summary>
        public Model.T_Sys_UserAccount LoginGetModel(string F_UserCode,string F_Password)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup from T_Sys_UserAccount ");
            strSql.Append(" where F_UserCode=@F_UserCode and F_Password=@F_Password and  F_DeleteFlag=0");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50),
                    new SqlParameter("@F_Password", SqlDbType.VarChar,50)
            };
            parameters[0].Value = F_UserCode;
            parameters[1].Value = F_Password;

            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
            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 Model.T_Sys_UserAccount GetModel(string F_UserCode)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_UserId,F_UserCode,F_ExtensionNumber,F_UserName,F_Password,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup from T_Sys_UserAccount ");
            strSql.Append(" where F_UserCode=@F_UserCode");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserCode", SqlDbType.VarChar,50)
            };
            parameters[0].Value = F_UserCode;

            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
            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 Model.T_Sys_UserAccount GetModel(int F_UserId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup from T_Sys_UserAccount ");
            strSql.Append(" where F_UserId=@F_UserId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_UserId", SqlDbType.Int,4)
            };
            parameters[0].Value = F_UserId;

            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
            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 Model.T_Sys_UserAccount DataRowToModel(DataRow row)
        {
            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
            if (row != null)
            {
                if (row["F_UserId"] != null && row["F_UserId"].ToString() != "")
                {
                    model.F_UserId = int.Parse(row["F_UserId"].ToString());
                }
                if (row["F_UserCode"] != null)
                {
                    model.F_UserCode = row["F_UserCode"].ToString();
                }
                if (row["F_Password"] != null)
                {
                    model.F_Password = row["F_Password"].ToString();
                }
                
                if (row["F_ExtensionNumber"] != null)
                {
                    model.F_ExtensionNumber = row["F_ExtensionNumber"].ToString();
                }
                if (row["F_UserName"] != null)
                {
                    model.F_UserName = row["F_UserName"].ToString();
                }
                if (row["F_DeptId"] != null && row["F_DeptId"].ToString() != "")
                {
                    model.F_DeptId = int.Parse(row["F_DeptId"].ToString());
                }
                if (row["F_RoleId"] != null && row["F_RoleId"].ToString() != "")
                {
                    model.F_RoleId = int.Parse(row["F_RoleId"].ToString());
                }
                if (row["F_GroupId"] != null && row["F_GroupId"].ToString() != "")
                {
                    model.F_GroupId = int.Parse(row["F_GroupId"].ToString());
                }
                if (row["F_SeatFlag"] != null && row["F_SeatFlag"].ToString() != "")
                {
                    if ((row["F_SeatFlag"].ToString() == "1") || (row["F_SeatFlag"].ToString().ToLower() == "true"))
                    {
                        model.F_SeatFlag = true;
                    }
                    else
                    {
                        model.F_SeatFlag = false;
                    }
                }
                if (row["F_SeatRight"] != null)
                {
                    model.F_SeatRight = row["F_SeatRight"].ToString();
                }
                if (row["F_SeatLevel"] != null)
                {
                    model.F_SeatLevel = row["F_SeatLevel"].ToString();
                }
                if (row["F_SexFlag"] != null)
                {
                    model.F_SexFlag = row["F_SexFlag"].ToString();
                }
                if (row["F_RemindFlag"] != null && row["F_RemindFlag"].ToString() != "")
                {
                    if ((row["F_RemindFlag"].ToString() == "1") || (row["F_RemindFlag"].ToString().ToLower() == "true"))
                    {
                        model.F_RemindFlag = true;
                    }
                    else
                    {
                        model.F_RemindFlag = false;
                    }
                }
                if (row["F_Remark"] != null)
                {
                    model.F_Remark = row["F_Remark"].ToString();
                }
                if (row["F_Telephone"] != null)
                {
                    model.F_Telephone = row["F_Telephone"].ToString();
                }
                if (row["F_Mobile"] != null)
                {
                    model.F_Mobile = row["F_Mobile"].ToString();
                }
                if (row["F_HomePhone"] != null)
                {
                    model.F_HomePhone = row["F_HomePhone"].ToString();
                }
                if (row["F_Birthday"] != null && row["F_Birthday"].ToString() != "")
                {
                    model.F_Birthday = DateTime.Parse(row["F_Birthday"].ToString());
                }
                if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "")
                {
                    model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString());
                }
                if (row["F_CancelOn"] != null && row["F_CancelOn"].ToString() != "")
                {
                    model.F_CancelOn = DateTime.Parse(row["F_CancelOn"].ToString());
                }
                if (row["F_DeleteFlag"] != null && row["F_DeleteFlag"].ToString() != "")
                {
                    model.F_DeleteFlag = int.Parse(row["F_DeleteFlag"].ToString());
                }
                if (row["F_APPOnFlag"] != null && row["F_APPOnFlag"].ToString() != "")
                {
                    if ((row["F_APPOnFlag"].ToString() == "1") || (row["F_APPOnFlag"].ToString().ToLower() == "true"))
                    {
                        model.F_APPOnFlag = true;
                    }
                    else
                    {
                        model.F_APPOnFlag = false;
                    }
                }
                if (row["F_LastActiveTime"] != null && row["F_LastActiveTime"].ToString() != "")
                {
                    model.F_LastActiveTime = DateTime.Parse(row["F_LastActiveTime"].ToString());
                }
                if (row["F_See"] != null)
                {
                    model.F_See = row["F_See"].ToString();
                }
                if (row["F_HJType"] != null && row["F_HJType"].ToString() != "")
                {
                    model.F_HJType = int.Parse(row["F_HJType"].ToString());
                }
                if (row["F_PId"] != null && row["F_PId"].ToString() != "")
                {
                    model.F_PId = int.Parse(row["F_PId"].ToString());
                }
                if (row["F_TmId"] != null && row["F_TmId"].ToString() != "")
                {
                    model.F_TmId = int.Parse(row["F_TmId"].ToString());
                }
                if (row["F_WorkNumber"] != null)
                {
                    model.F_WorkNumber = row["F_WorkNumber"].ToString();
                }
                if (row["F_DeptCode"] != null)
                {
                    model.F_DeptCode = row["F_DeptCode"].ToString();
                }
                if (row["F_WXNo"] != null)
                {
                    model.F_WXNo = row["F_WXNo"].ToString();
                }
                if (row["F_SeartGroupID"] != null && row["F_SeartGroupID"].ToString() != "")
                {
                    model.F_SeartGroupID = int.Parse(row["F_SeartGroupID"].ToString());
                }
                if (row["F_SeartGroup"] != null)
                {
                    model.F_SeartGroup = row["F_SeartGroup"].ToString();
                }
            }
            return model;
        }

        public Model.T_Sys_UserAccount DataRowToModel1(DataRow row)
        {
            Model.T_Sys_UserAccount model = new Model.T_Sys_UserAccount();
            if (row != null)
            {
                if (row["F_UserId"] != null && row["F_UserId"].ToString() != "")
                {
                    model.F_UserId = int.Parse(row["F_UserId"].ToString());
                }
                if (row["F_UserCode"] != null)
                {
                    model.F_UserCode = row["F_UserCode"].ToString();
                }
                if (row["F_UserName"] != null)
                {
                    model.F_UserName = row["F_UserName"].ToString();
                }
                if (row["F_GroupId"] != null && row["F_GroupId"].ToString() != "")
                {
                    model.F_GroupId = int.Parse(row["F_GroupId"].ToString());
                }

            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup ");
            strSql.Append(" FROM T_Sys_UserAccount ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet GetListView(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM V_UserAccount ");
            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(" F_UserId,F_UserCode,F_Password,F_ExtensionNumber,F_UserName,F_DeptId,F_RoleId,F_GroupId,F_SeatFlag,F_SeatRight,F_SeatLevel,F_SexFlag,F_RemindFlag,F_Remark,F_Telephone,F_Mobile,F_HomePhone,F_Birthday,F_CreateOn,F_CancelOn,F_DeleteFlag,F_APPOnFlag,F_LastActiveTime,F_See,F_HJType,F_PId,F_TmId,F_WorkNumber,F_DeptCode,F_WXNo,F_SeartGroupID,F_SeartGroup ");
            strSql.Append(" FROM T_Sys_UserAccount ");
            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_Sys_UserAccount ");
            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_UserId desc");
            }
            strSql.Append(")AS Row, T.*  from T_Sys_UserAccount 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());
        }

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}
