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

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


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CallCenterApi.Model.T_Cus_CustomerFinanceLog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Cus_CustomerFinanceLog(");
            strSql.Append("F_CusFinId,F_CustomerId,F_CustomerCode,F_MonthState,F_AnnualIncome,F_AnnualProfit,F_AnnualCost,F_AnnualPersonCount,F_AnnualWages,F_QuarterlyCost,F_QuarterlyPersonCount,F_QuarterlyWages,F_QuarterlyIncome,F_QPVAT,F_QPSurtax,F_QPTaxes,F_QPConTax,F_QPPerinTax,F_QPStampTax,F_QPOtherTax,F_Extend1,F_Extend2,F_Extend3,F_Extend4,F_Extend5,F_Remark1,F_Remark2,F_Remark3,F_CreateBy,F_CreatedOn,F_DeleteFlag)");
            strSql.Append(" values (");
            strSql.Append("@F_CusFinId,@F_CustomerId,@F_CustomerCode,@F_MonthState,@F_AnnualIncome,@F_AnnualProfit,@F_AnnualCost,@F_AnnualPersonCount,@F_AnnualWages,@F_QuarterlyCost,@F_QuarterlyPersonCount,@F_QuarterlyWages,@F_QuarterlyIncome,@F_QPVAT,@F_QPSurtax,@F_QPTaxes,@F_QPConTax,@F_QPPerinTax,@F_QPStampTax,@F_QPOtherTax,@F_Extend1,@F_Extend2,@F_Extend3,@F_Extend4,@F_Extend5,@F_Remark1,@F_Remark2,@F_Remark3,@F_CreateBy,@F_CreatedOn,@F_DeleteFlag)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CusFinId", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerCode", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_MonthState", SqlDbType.NVarChar,500),
                    new SqlParameter("@F_AnnualIncome", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualProfit", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualCost", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualPersonCount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualWages", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyCost", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyPersonCount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyWages", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyIncome", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPVAT", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPSurtax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPTaxes", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPConTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPPerinTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPStampTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPOtherTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Extend1", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend2", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend3", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend4", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend5", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Remark1", SqlDbType.NText),
                    new SqlParameter("@F_Remark2", SqlDbType.NText),
                    new SqlParameter("@F_Remark3", SqlDbType.NText),
                    new SqlParameter("@F_CreateBy", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_CreatedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2)};
            parameters[0].Value = model.F_CusFinId;
            parameters[1].Value = model.F_CustomerId;
            parameters[2].Value = model.F_CustomerCode;
            parameters[3].Value = model.F_MonthState;
            parameters[4].Value = model.F_AnnualIncome;
            parameters[5].Value = model.F_AnnualProfit;
            parameters[6].Value = model.F_AnnualCost;
            parameters[7].Value = model.F_AnnualPersonCount;
            parameters[8].Value = model.F_AnnualWages;
            parameters[9].Value = model.F_QuarterlyCost;
            parameters[10].Value = model.F_QuarterlyPersonCount;
            parameters[11].Value = model.F_QuarterlyWages;
            parameters[12].Value = model.F_QuarterlyIncome;
            parameters[13].Value = model.F_QPVAT;
            parameters[14].Value = model.F_QPSurtax;
            parameters[15].Value = model.F_QPTaxes;
            parameters[16].Value = model.F_QPConTax;
            parameters[17].Value = model.F_QPPerinTax;
            parameters[18].Value = model.F_QPStampTax;
            parameters[19].Value = model.F_QPOtherTax;
            parameters[20].Value = model.F_Extend1;
            parameters[21].Value = model.F_Extend2;
            parameters[22].Value = model.F_Extend3;
            parameters[23].Value = model.F_Extend4;
            parameters[24].Value = model.F_Extend5;
            parameters[25].Value = model.F_Remark1;
            parameters[26].Value = model.F_Remark2;
            parameters[27].Value = model.F_Remark3;
            parameters[28].Value = model.F_CreateBy;
            parameters[29].Value = model.F_CreatedOn;
            parameters[30].Value = model.F_DeleteFlag;

            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_Cus_CustomerFinanceLog model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Cus_CustomerFinanceLog set ");
            strSql.Append("F_CusFinId=@F_CusFinId,");
            strSql.Append("F_CustomerId=@F_CustomerId,");
            strSql.Append("F_CustomerCode=@F_CustomerCode,");
            strSql.Append("F_MonthState=@F_MonthState,");
            strSql.Append("F_AnnualIncome=@F_AnnualIncome,");
            strSql.Append("F_AnnualProfit=@F_AnnualProfit,");
            strSql.Append("F_AnnualCost=@F_AnnualCost,");
            strSql.Append("F_AnnualPersonCount=@F_AnnualPersonCount,");
            strSql.Append("F_AnnualWages=@F_AnnualWages,");
            strSql.Append("F_QuarterlyCost=@F_QuarterlyCost,");
            strSql.Append("F_QuarterlyPersonCount=@F_QuarterlyPersonCount,");
            strSql.Append("F_QuarterlyWages=@F_QuarterlyWages,");
            strSql.Append("F_QuarterlyIncome=@F_QuarterlyIncome,");
            strSql.Append("F_QPVAT=@F_QPVAT,");
            strSql.Append("F_QPSurtax=@F_QPSurtax,");
            strSql.Append("F_QPTaxes=@F_QPTaxes,");
            strSql.Append("F_QPConTax=@F_QPConTax,");
            strSql.Append("F_QPPerinTax=@F_QPPerinTax,");
            strSql.Append("F_QPStampTax=@F_QPStampTax,");
            strSql.Append("F_QPOtherTax=@F_QPOtherTax,");
            strSql.Append("F_Extend1=@F_Extend1,");
            strSql.Append("F_Extend2=@F_Extend2,");
            strSql.Append("F_Extend3=@F_Extend3,");
            strSql.Append("F_Extend4=@F_Extend4,");
            strSql.Append("F_Extend5=@F_Extend5,");
            strSql.Append("F_Remark1=@F_Remark1,");
            strSql.Append("F_Remark2=@F_Remark2,");
            strSql.Append("F_Remark3=@F_Remark3,");
            strSql.Append("F_CreateBy=@F_CreateBy,");
            strSql.Append("F_CreatedOn=@F_CreatedOn,");
            strSql.Append("F_DeleteFlag=@F_DeleteFlag");
            strSql.Append(" where F_CusFinLogId=@F_CusFinLogId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CusFinId", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerCode", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_MonthState", SqlDbType.NVarChar,500),
                    new SqlParameter("@F_AnnualIncome", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualProfit", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualCost", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualPersonCount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualWages", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyCost", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyPersonCount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyWages", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QuarterlyIncome", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPVAT", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPSurtax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPTaxes", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPConTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPPerinTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPStampTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_QPOtherTax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Extend1", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend2", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend3", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend4", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Extend5", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_Remark1", SqlDbType.NText),
                    new SqlParameter("@F_Remark2", SqlDbType.NText),
                    new SqlParameter("@F_Remark3", SqlDbType.NText),
                    new SqlParameter("@F_CreateBy", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_CreatedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_CusFinLogId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_CusFinId;
            parameters[1].Value = model.F_CustomerId;
            parameters[2].Value = model.F_CustomerCode;
            parameters[3].Value = model.F_MonthState;
            parameters[4].Value = model.F_AnnualIncome;
            parameters[5].Value = model.F_AnnualProfit;
            parameters[6].Value = model.F_AnnualCost;
            parameters[7].Value = model.F_AnnualPersonCount;
            parameters[8].Value = model.F_AnnualWages;
            parameters[9].Value = model.F_QuarterlyCost;
            parameters[10].Value = model.F_QuarterlyPersonCount;
            parameters[11].Value = model.F_QuarterlyWages;
            parameters[12].Value = model.F_QuarterlyIncome;
            parameters[13].Value = model.F_QPVAT;
            parameters[14].Value = model.F_QPSurtax;
            parameters[15].Value = model.F_QPTaxes;
            parameters[16].Value = model.F_QPConTax;
            parameters[17].Value = model.F_QPPerinTax;
            parameters[18].Value = model.F_QPStampTax;
            parameters[19].Value = model.F_QPOtherTax;
            parameters[20].Value = model.F_Extend1;
            parameters[21].Value = model.F_Extend2;
            parameters[22].Value = model.F_Extend3;
            parameters[23].Value = model.F_Extend4;
            parameters[24].Value = model.F_Extend5;
            parameters[25].Value = model.F_Remark1;
            parameters[26].Value = model.F_Remark2;
            parameters[27].Value = model.F_Remark3;
            parameters[28].Value = model.F_CreateBy;
            parameters[29].Value = model.F_CreatedOn;
            parameters[30].Value = model.F_DeleteFlag;
            parameters[31].Value = model.F_CusFinLogId;

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

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

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

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


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

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

            CallCenterApi.Model.T_Cus_CustomerFinanceLog model = new CallCenterApi.Model.T_Cus_CustomerFinanceLog();
            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_Cus_CustomerFinanceLog DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Cus_CustomerFinanceLog model = new CallCenterApi.Model.T_Cus_CustomerFinanceLog();
            if (row != null)
            {
                if (row["F_CusFinLogId"] != null && row["F_CusFinLogId"].ToString() != "")
                {
                    model.F_CusFinLogId = int.Parse(row["F_CusFinLogId"].ToString());
                }
                if (row["F_CusFinId"] != null && row["F_CusFinId"].ToString() != "")
                {
                    model.F_CusFinId = int.Parse(row["F_CusFinId"].ToString());
                }
                if (row["F_CustomerId"] != null && row["F_CustomerId"].ToString() != "")
                {
                    model.F_CustomerId = int.Parse(row["F_CustomerId"].ToString());
                }
                if (row["F_CustomerCode"] != null)
                {
                    model.F_CustomerCode = row["F_CustomerCode"].ToString();
                }
                if (row["F_MonthState"] != null)
                {
                    model.F_MonthState = row["F_MonthState"].ToString();
                }
                if (row["F_AnnualIncome"] != null)
                {
                    model.F_AnnualIncome = row["F_AnnualIncome"].ToString();
                }
                if (row["F_AnnualProfit"] != null)
                {
                    model.F_AnnualProfit = row["F_AnnualProfit"].ToString();
                }
                if (row["F_AnnualCost"] != null)
                {
                    model.F_AnnualCost = row["F_AnnualCost"].ToString();
                }
                if (row["F_AnnualPersonCount"] != null)
                {
                    model.F_AnnualPersonCount = row["F_AnnualPersonCount"].ToString();
                }
                if (row["F_AnnualWages"] != null)
                {
                    model.F_AnnualWages = row["F_AnnualWages"].ToString();
                }
                if (row["F_QuarterlyCost"] != null)
                {
                    model.F_QuarterlyCost = row["F_QuarterlyCost"].ToString();
                }
                if (row["F_QuarterlyPersonCount"] != null)
                {
                    model.F_QuarterlyPersonCount = row["F_QuarterlyPersonCount"].ToString();
                }
                if (row["F_QuarterlyWages"] != null)
                {
                    model.F_QuarterlyWages = row["F_QuarterlyWages"].ToString();
                }
                if (row["F_QuarterlyIncome"] != null)
                {
                    model.F_QuarterlyIncome = row["F_QuarterlyIncome"].ToString();
                }
                if (row["F_QPVAT"] != null)
                {
                    model.F_QPVAT = row["F_QPVAT"].ToString();
                }
                if (row["F_QPSurtax"] != null)
                {
                    model.F_QPSurtax = row["F_QPSurtax"].ToString();
                }
                if (row["F_QPTaxes"] != null)
                {
                    model.F_QPTaxes = row["F_QPTaxes"].ToString();
                }
                if (row["F_QPConTax"] != null)
                {
                    model.F_QPConTax = row["F_QPConTax"].ToString();
                }
                if (row["F_QPPerinTax"] != null)
                {
                    model.F_QPPerinTax = row["F_QPPerinTax"].ToString();
                }
                if (row["F_QPStampTax"] != null)
                {
                    model.F_QPStampTax = row["F_QPStampTax"].ToString();
                }
                if (row["F_QPOtherTax"] != null)
                {
                    model.F_QPOtherTax = row["F_QPOtherTax"].ToString();
                }
                if (row["F_Extend1"] != null)
                {
                    model.F_Extend1 = row["F_Extend1"].ToString();
                }
                if (row["F_Extend2"] != null)
                {
                    model.F_Extend2 = row["F_Extend2"].ToString();
                }
                if (row["F_Extend3"] != null)
                {
                    model.F_Extend3 = row["F_Extend3"].ToString();
                }
                if (row["F_Extend4"] != null)
                {
                    model.F_Extend4 = row["F_Extend4"].ToString();
                }
                if (row["F_Extend5"] != null)
                {
                    model.F_Extend5 = row["F_Extend5"].ToString();
                }
                if (row["F_Remark1"] != null)
                {
                    model.F_Remark1 = row["F_Remark1"].ToString();
                }
                if (row["F_Remark2"] != null)
                {
                    model.F_Remark2 = row["F_Remark2"].ToString();
                }
                if (row["F_Remark3"] != null)
                {
                    model.F_Remark3 = row["F_Remark3"].ToString();
                }
                if (row["F_CreateBy"] != null)
                {
                    model.F_CreateBy = row["F_CreateBy"].ToString();
                }
                if (row["F_CreatedOn"] != null && row["F_CreatedOn"].ToString() != "")
                {
                    model.F_CreatedOn = DateTime.Parse(row["F_CreatedOn"].ToString());
                }
                if (row["F_DeleteFlag"] != null && row["F_DeleteFlag"].ToString() != "")
                {
                    model.F_DeleteFlag = int.Parse(row["F_DeleteFlag"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Cus_CustomerFinanceLog ");
            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_Cus_CustomerFinanceLog ");
            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_Cus_CustomerFinanceLog ");
            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_CusFinLogId desc");
            }
            strSql.Append(")AS Row, T.*  from T_Cus_CustomerFinanceLog 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
    }
}
