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_Data_Assessment
	/// </summary>
	public partial class T_Data_Assessment
    {
        public T_Data_Assessment()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Data_Assessment");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CallCenterApi.Model.T_Data_Assessment model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Data_Assessment set ");
            strSql.Append("F_DeptId=@F_DeptId,");
            strSql.Append("F_DeptName=@F_DeptName,");
            strSql.Append("F_PartentId=@F_PartentId,");
            strSql.Append("F_BatchNo=@F_BatchNo,");
            strSql.Append("F_CS_ReciveCount=@F_CS_ReciveCount,");
            strSql.Append("F_CS_RecTimelyCount=@F_CS_RecTimelyCount,");
            strSql.Append("F_JB_AssginCount=@F_JB_AssginCount,");
            strSql.Append("F_JB_HandleCount=@F_JB_HandleCount,");
            strSql.Append("F_JB_HandleOverCount=@F_JB_HandleOverCount,");
            strSql.Append("F_HF_VisitCount=@F_HF_VisitCount,");
            strSql.Append("F_HF_SatisfiedCount=@F_HF_SatisfiedCount,");
            strSql.Append("F_HF_DissatisfiedCount=@F_HF_DissatisfiedCount,");
            strSql.Append("F_TH_BackCount=@F_TH_BackCount,");
            strSql.Append("F_TH_BackTimelyCount=@F_TH_BackTimelyCount,");
            strSql.Append("F_ZSK_ActualCount=@F_ZSK_ActualCount,");
            strSql.Append("F_ZSK_ShouldCount=@F_ZSK_ShouldCount,");
            strSql.Append("F_ZSK_CorrCount=@F_ZSK_CorrCount,");
            strSql.Append("F_GF_NonstandardCount=@F_GF_NonstandardCount,");
            strSql.Append("F_TB_BulletinOrderCount=@F_TB_BulletinOrderCount,");
            strSql.Append("F_TB_BulletinCount=@F_TB_BulletinCount,");
            strSql.Append("F_DF_CSCore=@F_DF_CSCore,");
            strSql.Append("F_DF_THCore=@F_DF_THCore,");
            strSql.Append("F_DF_BLCore=@F_DF_BLCore,");
            strSql.Append("F_DF_HFCore=@F_DF_HFCore,");
            strSql.Append("F_DF_ZSKCore=@F_DF_ZSKCore,");
            strSql.Append("F_DF_GFCore=@F_DF_GFCore,");
            strSql.Append("F_DF_TBCore=@F_DF_TBCore,");
            strSql.Append("F_DF_ZJ=@F_DF_ZJ,");
            strSql.Append("F_SSLimittime=@F_SSLimittime,"); 
            strSql.Append("F_CreateTime=@F_CreateTime");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_DeptId", SqlDbType.Int,4),
                    new SqlParameter("@F_DeptName", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_PartentId", SqlDbType.Int,4),
                    new SqlParameter("@F_BatchNo", SqlDbType.NVarChar,8),
                    new SqlParameter("@F_CS_ReciveCount", SqlDbType.Int,4),
                    new SqlParameter("@F_CS_RecTimelyCount", SqlDbType.Int,4),
                    new SqlParameter("@F_JB_AssginCount", SqlDbType.Int,4),
                    new SqlParameter("@F_JB_HandleCount", SqlDbType.Int,4),
                    new SqlParameter("@F_JB_HandleOverCount", SqlDbType.Int,4),
                    new SqlParameter("@F_HF_VisitCount", SqlDbType.Int,4),
                    new SqlParameter("@F_HF_SatisfiedCount", SqlDbType.Int,4),
                    new SqlParameter("@F_HF_DissatisfiedCount", SqlDbType.Int,4),
                    new SqlParameter("@F_TH_BackCount", SqlDbType.Int,4),
                    new SqlParameter("@F_TH_BackTimelyCount", SqlDbType.Int,4),
                    new SqlParameter("@F_ZSK_ActualCount", SqlDbType.Int,4),
                    new SqlParameter("@F_ZSK_ShouldCount", SqlDbType.Int,4),
                    new SqlParameter("@F_ZSK_CorrCount", SqlDbType.Int,4),
                    new SqlParameter("@F_GF_NonstandardCount", SqlDbType.Int,4),
                    new SqlParameter("@F_TB_BulletinOrderCount", SqlDbType.Int,4),
                    new SqlParameter("@F_TB_BulletinCount", SqlDbType.Int,4),
                    new SqlParameter("@F_DF_CSCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_THCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_BLCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_HFCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_ZSKCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_GFCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_TBCore", SqlDbType.Decimal,9),
                    new SqlParameter("@F_DF_ZJ", SqlDbType.Decimal,9),
                    new SqlParameter("@F_SSLimittime", SqlDbType.DateTime),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_DeptId;
            parameters[1].Value = model.F_DeptName;
            parameters[2].Value = model.F_PartentId;
            parameters[3].Value = model.F_BatchNo;
            parameters[4].Value = model.F_CS_ReciveCount;
            parameters[5].Value = model.F_CS_RecTimelyCount;
            parameters[6].Value = model.F_JB_AssginCount;
            parameters[7].Value = model.F_JB_HandleCount;
            parameters[8].Value = model.F_JB_HandleOverCount;
            parameters[9].Value = model.F_HF_VisitCount;
            parameters[10].Value = model.F_HF_SatisfiedCount;
            parameters[11].Value = model.F_HF_DissatisfiedCount;
            parameters[12].Value = model.F_TH_BackCount;
            parameters[13].Value = model.F_TH_BackTimelyCount;
            parameters[14].Value = model.F_ZSK_ActualCount;
            parameters[15].Value = model.F_ZSK_ShouldCount;
            parameters[16].Value = model.F_ZSK_CorrCount;
            parameters[17].Value = model.F_GF_NonstandardCount;
            parameters[18].Value = model.F_TB_BulletinOrderCount;
            parameters[19].Value = model.F_TB_BulletinCount;
            parameters[20].Value = model.F_DF_CSCore;
            parameters[21].Value = model.F_DF_THCore;
            parameters[22].Value = model.F_DF_BLCore;
            parameters[23].Value = model.F_DF_HFCore;
            parameters[24].Value = model.F_DF_ZSKCore;
            parameters[25].Value = model.F_DF_GFCore;
            parameters[26].Value = model.F_DF_TBCore;
            parameters[27].Value = model.F_DF_ZJ;
            parameters[28].Value = model.F_SSLimittime; 
             parameters[29].Value = model.F_CreateTime;
            parameters[30].Value = model.F_Id;

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


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

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

            CallCenterApi.Model.T_Data_Assessment model = new CallCenterApi.Model.T_Data_Assessment();
            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_Data_Assessment DataRowToModel(DataRow row)
        {
            Model.T_Data_Assessment model = new Model.T_Data_Assessment();
            if (row != null)
            {
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
                {
                    model.F_Id = int.Parse(row["F_Id"].ToString());
                }
                if (row["F_DeptId"] != null && row["F_DeptId"].ToString() != "")
                {
                    model.F_DeptId = int.Parse(row["F_DeptId"].ToString());
                }
                if (row["F_DeptName"] != null && row["F_DeptName"].ToString() != "")
                {
                    model.F_DeptName = row["F_DeptName"].ToString();
                }
                if (row["F_PartentId"] != null && row["F_PartentId"].ToString() != "")
                {
                    model.F_PartentId = int.Parse(row["F_PartentId"].ToString());
                }
                if (row["F_BatchNo"] != null && row["F_BatchNo"].ToString() != "")
                {
                    model.F_BatchNo = row["F_BatchNo"].ToString();
                }
                if (row["F_CS_ReciveCount"] != null && row["F_CS_ReciveCount"].ToString() != "")
                {
                    model.F_CS_ReciveCount = int.Parse(row["F_CS_ReciveCount"].ToString());
                }
                if (row["F_CS_RecTimelyCount"] != null && row["F_CS_RecTimelyCount"].ToString() != "")
                {
                    model.F_CS_RecTimelyCount = int.Parse(row["F_CS_RecTimelyCount"].ToString());
                }
                if (row["F_JB_AssginCount"] != null && row["F_JB_AssginCount"].ToString() != "")
                {
                    model.F_JB_AssginCount = int.Parse(row["F_JB_AssginCount"].ToString());
                }
                if (row["F_JB_HandleCount"] != null && row["F_JB_HandleCount"].ToString() != "")
                {
                    model.F_JB_HandleCount = int.Parse(row["F_JB_HandleCount"].ToString());
                }
                if (row["F_JB_HandleOverCount"] != null && row["F_JB_HandleOverCount"].ToString() != "")
                {
                    model.F_JB_HandleOverCount = int.Parse(row["F_JB_HandleOverCount"].ToString());
                }
                if (row["F_HF_VisitCount"] != null && row["F_HF_VisitCount"].ToString() != "")
                {
                    model.F_HF_VisitCount = int.Parse(row["F_HF_VisitCount"].ToString());
                }
                if (row["F_HF_SatisfiedCount"] != null && row["F_HF_SatisfiedCount"].ToString() != "")
                {
                    model.F_HF_SatisfiedCount = int.Parse(row["F_HF_SatisfiedCount"].ToString());
                }
                if (row["F_HF_DissatisfiedCount"] != null && row["F_HF_DissatisfiedCount"].ToString() != "")
                {
                    model.F_HF_DissatisfiedCount = int.Parse(row["F_HF_DissatisfiedCount"].ToString());
                }
                if (row["F_TH_BackCount"] != null && row["F_TH_BackCount"].ToString() != "")
                {
                    model.F_TH_BackCount = int.Parse(row["F_TH_BackCount"].ToString());
                }
                if (row["F_TH_BackTimelyCount"] != null && row["F_TH_BackTimelyCount"].ToString() != "")
                {
                    model.F_TH_BackTimelyCount = int.Parse(row["F_TH_BackTimelyCount"].ToString());
                }
                if (row["F_ZSK_ActualCount"] != null && row["F_ZSK_ActualCount"].ToString() != "")
                {
                    model.F_ZSK_ActualCount = int.Parse(row["F_ZSK_ActualCount"].ToString());
                }
                if (row["F_ZSK_ShouldCount"] != null && row["F_ZSK_ShouldCount"].ToString() != "")
                {
                    model.F_ZSK_ShouldCount = int.Parse(row["F_ZSK_ShouldCount"].ToString());
                }
                if (row["F_ZSK_CorrCount"] != null && row["F_ZSK_CorrCount"].ToString() != "")
                {
                    model.F_ZSK_CorrCount = int.Parse(row["F_ZSK_CorrCount"].ToString());
                }
                if (row["F_GF_NonstandardCount"] != null && row["F_GF_NonstandardCount"].ToString() != "")
                {
                    model.F_GF_NonstandardCount = int.Parse(row["F_GF_NonstandardCount"].ToString());
                }
                if (row["F_TB_BulletinOrderCount"] != null && row["F_TB_BulletinOrderCount"].ToString() != "")
                {
                    model.F_TB_BulletinOrderCount = int.Parse(row["F_TB_BulletinOrderCount"].ToString());
                }
                if (row["F_TB_BulletinCount"] != null && row["F_TB_BulletinCount"].ToString() != "")
                {
                    model.F_TB_BulletinCount = int.Parse(row["F_TB_BulletinCount"].ToString());
                }
                if (row["F_DF_CSCore"] != null && row["F_DF_CSCore"].ToString() != "")
                {
                    model.F_DF_CSCore = decimal.Parse(row["F_DF_CSCore"].ToString());
                }
                if (row["F_DF_THCore"] != null && row["F_DF_THCore"].ToString() != "")
                {
                    model.F_DF_THCore = decimal.Parse(row["F_DF_THCore"].ToString());
                }
                if (row["F_DF_BLCore"] != null && row["F_DF_BLCore"].ToString() != "")
                {
                    model.F_DF_BLCore = decimal.Parse(row["F_DF_BLCore"].ToString());
                }
                if (row["F_DF_HFCore"] != null && row["F_DF_HFCore"].ToString() != "")
                {
                    model.F_DF_HFCore = decimal.Parse(row["F_DF_HFCore"].ToString());
                }
                if (row["F_DF_ZSKCore"] != null && row["F_DF_ZSKCore"].ToString() != "")
                {
                    model.F_DF_ZSKCore = decimal.Parse(row["F_DF_ZSKCore"].ToString());
                }
                if (row["F_DF_GFCore"] != null && row["F_DF_GFCore"].ToString() != "")
                {
                    model.F_DF_GFCore = decimal.Parse(row["F_DF_GFCore"].ToString());
                }
                if (row["F_DF_TBCore"] != null && row["F_DF_TBCore"].ToString() != "")
                {
                    model.F_DF_TBCore = decimal.Parse(row["F_DF_TBCore"].ToString());
                }
                if (row["F_DF_ZJ"] != null && row["F_DF_ZJ"].ToString() != "")
                {
                    model.F_DF_ZJ = decimal.Parse(row["F_DF_ZJ"].ToString());
                }
                if (row["F_SSLimittime"] != null && row["F_SSLimittime"].ToString() != "")
                {
                    model.F_SSLimittime = DateTime.Parse(row["F_SSLimittime"].ToString());
                }
                
                if (row["F_CreateTime"] != null && row["F_CreateTime"].ToString() != "")
                {
                    model.F_CreateTime = DateTime.Parse(row["F_CreateTime"].ToString());
                }
                
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Data_Assessment ");
            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(" * ");
            strSql.Append(" FROM T_Data_Assessment ");
            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_Data_Assessment ");
            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_Data_Assessment 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  Method
    }
}
