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

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(CallCenterApi.Model.T_Cus_CustomerBaseNew model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Cus_CustomerBaseNew(");
            strSql.Append("F_CustomerCode,F_CompanyName,F_AreaID,F_BranchID,F_Salesman,F_SalesPhone,F_CustomerNature,F_Channel,F_Credit,F_Legal,F_LegalPhone,F_AddressProvince,F_AddressCity,F_AddressCountry,F_AddressTownship,F_AddressFull,F_Brands,F_Product,F_FrozenFlag,F_IsOpenAccount,F_LevelCode,F_LevelName,F_MnemonicCode,F_InvoiceBank,F_InvoiceBankAccount,F_TaxRegCode,F_IsRunXLX,F_AnnualSales,F_Formula,F_RaiseCrops,F_PlantingArea,F_FertilizerBrand,F_FileId,F_WxPassword,F_WxOpenId,F_Remark,F_CreateBy,F_CreateOn,F_UpdateCount,F_UpdateBy,F_UpdateOn,F_IsDelete,F_DeleteBy,F_DeleteOn,F_Gender)");
            strSql.Append(" values (");
            strSql.Append("@F_CustomerCode,@F_CompanyName,@F_AreaID,@F_BranchID,@F_Salesman,@F_SalesPhone,@F_CustomerNature,@F_Channel,@F_Credit,@F_Legal,@F_LegalPhone,@F_AddressProvince,@F_AddressCity,@F_AddressCountry,@F_AddressTownship,@F_AddressFull,@F_Brands,@F_Product,@F_FrozenFlag,@F_IsOpenAccount,@F_LevelCode,@F_LevelName,@F_MnemonicCode,@F_InvoiceBank,@F_InvoiceBankAccount,@F_TaxRegCode,@F_IsRunXLX,@F_AnnualSales,@F_Formula,@F_RaiseCrops,@F_PlantingArea,@F_FertilizerBrand,@F_FileId,@F_WxPassword,@F_WxOpenId,@F_Remark,@F_CreateBy,@F_CreateOn,@F_UpdateCount,@F_UpdateBy,@F_UpdateOn,@F_IsDelete,@F_DeleteBy,@F_DeleteOn,@F_Gender)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerCode", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_CompanyName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AreaID", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_BranchID", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Salesman", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_SalesPhone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CustomerNature", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Channel", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Credit", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Legal", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LegalPhone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressProvince", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressCity", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressCountry", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressTownship", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressFull", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Brands", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Product", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FrozenFlag", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsOpenAccount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LevelCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LevelName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_MnemonicCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_InvoiceBank", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_InvoiceBankAccount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TaxRegCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsRunXLX", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualSales", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Formula", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_RaiseCrops", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_PlantingArea", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FertilizerBrand", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FileId", SqlDbType.Int,4),
                    new SqlParameter("@F_WxPassword", SqlDbType.VarChar,100),
                    new SqlParameter("@F_WxOpenId", SqlDbType.NVarChar,300),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateBy", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_UpdateCount", SqlDbType.Int,4),
                    new SqlParameter("@F_UpdateBy", SqlDbType.VarChar,50),
                    new SqlParameter("@F_UpdateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_DeleteBy", SqlDbType.NVarChar,100),
                     new SqlParameter("@F_Gender", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_DeleteOn", SqlDbType.DateTime)};
            parameters[0].Value = model.F_CustomerCode;
            parameters[1].Value = model.F_CompanyName;
            parameters[2].Value = model.F_AreaID;
            parameters[3].Value = model.F_BranchID;
            parameters[4].Value = model.F_Salesman;
            parameters[5].Value = model.F_SalesPhone;
            parameters[6].Value = model.F_CustomerNature;
            parameters[7].Value = model.F_Channel;
            parameters[8].Value = model.F_Credit;
            parameters[9].Value = model.F_Legal;
            parameters[10].Value = model.F_LegalPhone;
            parameters[11].Value = model.F_AddressProvince;
            parameters[12].Value = model.F_AddressCity;
            parameters[13].Value = model.F_AddressCountry;
            parameters[14].Value = model.F_AddressTownship;
            parameters[15].Value = model.F_AddressFull;
            parameters[16].Value = model.F_Brands;
            parameters[17].Value = model.F_Product;
            parameters[18].Value = model.F_FrozenFlag;
            parameters[19].Value = model.F_IsOpenAccount;
            parameters[20].Value = model.F_LevelCode;
            parameters[21].Value = model.F_LevelName;
            parameters[22].Value = model.F_MnemonicCode;
            parameters[23].Value = model.F_InvoiceBank;
            parameters[24].Value = model.F_InvoiceBankAccount;
            parameters[25].Value = model.F_TaxRegCode;
            parameters[26].Value = model.F_IsRunXLX;
            parameters[27].Value = model.F_AnnualSales;
            parameters[28].Value = model.F_Formula;
            parameters[29].Value = model.F_RaiseCrops;
            parameters[30].Value = model.F_PlantingArea;
            parameters[31].Value = model.F_FertilizerBrand;
            parameters[32].Value = model.F_FileId;
            parameters[33].Value = model.F_WxPassword;
            parameters[34].Value = model.F_WxOpenId;
            parameters[35].Value = model.F_Remark;
            parameters[36].Value = model.F_CreateBy;
            parameters[37].Value = model.F_CreateOn;
            parameters[38].Value = model.F_UpdateCount;
            parameters[39].Value = model.F_UpdateBy;
            parameters[40].Value = model.F_UpdateOn;
            parameters[41].Value = model.F_IsDelete;
            parameters[42].Value = model.F_DeleteBy;
            parameters[43].Value = model.F_Gender;
            parameters[44].Value = model.F_DeleteOn;

            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_CustomerBaseNew model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Cus_CustomerBaseNew set ");
            strSql.Append("F_CustomerCode=@F_CustomerCode,");
            strSql.Append("F_CompanyName=@F_CompanyName,");
            strSql.Append("F_AreaID=@F_AreaID,");
            strSql.Append("F_BranchID=@F_BranchID,");
            strSql.Append("F_Salesman=@F_Salesman,");
            strSql.Append("F_SalesPhone=@F_SalesPhone,");
            strSql.Append("F_CustomerNature=@F_CustomerNature,");
            strSql.Append("F_Channel=@F_Channel,");
            strSql.Append("F_Credit=@F_Credit,");
            strSql.Append("F_Legal=@F_Legal,");
            strSql.Append("F_LegalPhone=@F_LegalPhone,");
            strSql.Append("F_AddressProvince=@F_AddressProvince,");
            strSql.Append("F_AddressCity=@F_AddressCity,");
            strSql.Append("F_AddressCountry=@F_AddressCountry,");
            strSql.Append("F_AddressTownship=@F_AddressTownship,");
            strSql.Append("F_AddressFull=@F_AddressFull,");
            strSql.Append("F_Brands=@F_Brands,");
            strSql.Append("F_Product=@F_Product,");
            strSql.Append("F_FrozenFlag=@F_FrozenFlag,");
            strSql.Append("F_IsOpenAccount=@F_IsOpenAccount,");
            strSql.Append("F_LevelCode=@F_LevelCode,");
            strSql.Append("F_LevelName=@F_LevelName,");
            strSql.Append("F_MnemonicCode=@F_MnemonicCode,");
            strSql.Append("F_InvoiceBank=@F_InvoiceBank,");
            strSql.Append("F_InvoiceBankAccount=@F_InvoiceBankAccount,");
            strSql.Append("F_TaxRegCode=@F_TaxRegCode,");
            strSql.Append("F_IsRunXLX=@F_IsRunXLX,");
            strSql.Append("F_AnnualSales=@F_AnnualSales,");
            strSql.Append("F_Formula=@F_Formula,");
            strSql.Append("F_RaiseCrops=@F_RaiseCrops,");
            strSql.Append("F_PlantingArea=@F_PlantingArea,");
            strSql.Append("F_FertilizerBrand=@F_FertilizerBrand,");
            strSql.Append("F_FileId=@F_FileId,");
            strSql.Append("F_WxPassword=@F_WxPassword,");
            strSql.Append("F_WxOpenId=@F_WxOpenId,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_CreateBy=@F_CreateBy,");
            strSql.Append("F_CreateOn=@F_CreateOn,");
            strSql.Append("F_UpdateCount=@F_UpdateCount,");
            strSql.Append("F_UpdateBy=@F_UpdateBy,");
            strSql.Append("F_UpdateOn=@F_UpdateOn,");
            strSql.Append("F_IsDelete=@F_IsDelete,");
            strSql.Append("F_DeleteBy=@F_DeleteBy,");
            strSql.Append("F_Gender=@F_Gender,");
            strSql.Append("F_DeleteOn=@F_DeleteOn");
            strSql.Append(" where F_CustomerId=@F_CustomerId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CompanyName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AreaID", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_BranchID", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Salesman", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_SalesPhone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CustomerNature", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Channel", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Credit", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Legal", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LegalPhone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressProvince", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressCity", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressCountry", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressTownship", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AddressFull", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Brands", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Product", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FrozenFlag", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsOpenAccount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LevelCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_LevelName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_MnemonicCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_InvoiceBank", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_InvoiceBankAccount", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TaxRegCode", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_IsRunXLX", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_AnnualSales", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Formula", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_RaiseCrops", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_PlantingArea", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FertilizerBrand", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_FileId", SqlDbType.Int,4),
                    new SqlParameter("@F_WxPassword", SqlDbType.VarChar,100),
                    new SqlParameter("@F_WxOpenId", SqlDbType.NVarChar,300),
                    new SqlParameter("@F_Remark", SqlDbType.NText),
                    new SqlParameter("@F_CreateBy", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_CreateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_UpdateCount", SqlDbType.Int,4),
                    new SqlParameter("@F_UpdateBy", SqlDbType.VarChar,50),
                    new SqlParameter("@F_UpdateOn", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_DeleteBy", SqlDbType.NVarChar,100),
                      new SqlParameter("@F_Gender", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_DeleteOn", SqlDbType.DateTime),
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_CustomerCode;
            parameters[1].Value = model.F_CompanyName;
            parameters[2].Value = model.F_AreaID;
            parameters[3].Value = model.F_BranchID;
            parameters[4].Value = model.F_Salesman;
            parameters[5].Value = model.F_SalesPhone;
            parameters[6].Value = model.F_CustomerNature;
            parameters[7].Value = model.F_Channel;
            parameters[8].Value = model.F_Credit;
            parameters[9].Value = model.F_Legal;
            parameters[10].Value = model.F_LegalPhone;
            parameters[11].Value = model.F_AddressProvince;
            parameters[12].Value = model.F_AddressCity;
            parameters[13].Value = model.F_AddressCountry;
            parameters[14].Value = model.F_AddressTownship;
            parameters[15].Value = model.F_AddressFull;
            parameters[16].Value = model.F_Brands;
            parameters[17].Value = model.F_Product;
            parameters[18].Value = model.F_FrozenFlag;
            parameters[19].Value = model.F_IsOpenAccount;
            parameters[20].Value = model.F_LevelCode;
            parameters[21].Value = model.F_LevelName;
            parameters[22].Value = model.F_MnemonicCode;
            parameters[23].Value = model.F_InvoiceBank;
            parameters[24].Value = model.F_InvoiceBankAccount;
            parameters[25].Value = model.F_TaxRegCode;
            parameters[26].Value = model.F_IsRunXLX;
            parameters[27].Value = model.F_AnnualSales;
            parameters[28].Value = model.F_Formula;
            parameters[29].Value = model.F_RaiseCrops;
            parameters[30].Value = model.F_PlantingArea;
            parameters[31].Value = model.F_FertilizerBrand;
            parameters[32].Value = model.F_FileId;
            parameters[33].Value = model.F_WxPassword;
            parameters[34].Value = model.F_WxOpenId;
            parameters[35].Value = model.F_Remark;
            parameters[36].Value = model.F_CreateBy;
            parameters[37].Value = model.F_CreateOn;
            parameters[38].Value = model.F_UpdateCount;
            parameters[39].Value = model.F_UpdateBy;
            parameters[40].Value = model.F_UpdateOn;
            parameters[41].Value = model.F_IsDelete;
            parameters[42].Value = model.F_DeleteBy;
            parameters[43].Value = model.F_Gender;
            parameters[44].Value = model.F_DeleteOn;
            parameters[45].Value = model.F_CustomerId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int F_CustomerId)
        {

            StringBuilder strSql = new StringBuilder();
            //strSql.Append("delete from T_Cus_CustomerBaseNew ");
            strSql.Append("update T_Cus_CustomerBaseNew set F_DeleteFlag=1 ");
            strSql.Append(" where F_CustomerId=@F_CustomerId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4)
            };
            parameters[0].Value = F_CustomerId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_CustomerIdlist)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("delete from T_Cus_CustomerBaseNew ");
           strSql.Append("update T_Cus_CustomerBaseNew set F_IsDelete=1 ");
            strSql.Append(" where F_CustomerId in (" + F_CustomerIdlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CallCenterApi.Model.T_Cus_CustomerBaseNew GetModel(string F_CustomerCode)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from T_Cus_CustomerBaseNew ");
            strSql.Append(" where F_CustomerCode=@F_CustomerCode");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerCode", SqlDbType.VarChar,50)         };
            parameters[0].Value = F_CustomerCode;

            CallCenterApi.Model.T_Cus_CustomerBaseNew model = new CallCenterApi.Model.T_Cus_CustomerBaseNew();
            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_CustomerBaseNew GetModel(int F_CustomerId)
        {

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

            CallCenterApi.Model.T_Cus_CustomerBaseNew model = new CallCenterApi.Model.T_Cus_CustomerBaseNew();
            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_CustomerBaseNew DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Cus_CustomerBaseNew model = new CallCenterApi.Model.T_Cus_CustomerBaseNew();
            if (row != null)
            {
                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_CompanyName"] != null)
                {
                    model.F_CompanyName = row["F_CompanyName"].ToString();
                }
                if (row["F_Gender"] != null)
                {
                    model.F_Gender = row["F_Gender"].ToString();
                }
                if (row["F_AreaID"] != null)
                {
                    model.F_AreaID = row["F_AreaID"].ToString();
                }
                if (row["F_BranchID"] != null)
                {
                    model.F_BranchID = row["F_BranchID"].ToString();
                }
                if (row["F_Salesman"] != null)
                {
                    model.F_Salesman = row["F_Salesman"].ToString();
                }
                if (row["F_SalesPhone"] != null)
                {
                    model.F_SalesPhone = row["F_SalesPhone"].ToString();
                }
                if (row["F_CustomerNature"] != null)
                {
                    model.F_CustomerNature = row["F_CustomerNature"].ToString();
                }
                if (row["F_Channel"] != null)
                {
                    model.F_Channel = row["F_Channel"].ToString();
                }
                if (row["F_Credit"] != null)
                {
                    model.F_Credit = row["F_Credit"].ToString();
                }
                if (row["F_Legal"] != null)
                {
                    model.F_Legal = row["F_Legal"].ToString();
                }
                if (row["F_LegalPhone"] != null)
                {
                    model.F_LegalPhone = row["F_LegalPhone"].ToString();
                }
                if (row["F_AddressProvince"] != null)
                {
                    model.F_AddressProvince = row["F_AddressProvince"].ToString();
                }
                if (row["F_AddressCity"] != null)
                {
                    model.F_AddressCity = row["F_AddressCity"].ToString();
                }
                if (row["F_AddressCountry"] != null)
                {
                    model.F_AddressCountry = row["F_AddressCountry"].ToString();
                }
                if (row["F_AddressTownship"] != null)
                {
                    model.F_AddressTownship = row["F_AddressTownship"].ToString();
                }
                if (row["F_AddressFull"] != null)
                {
                    model.F_AddressFull = row["F_AddressFull"].ToString();
                }
                if (row["F_Brands"] != null)
                {
                    model.F_Brands = row["F_Brands"].ToString();
                }
                if (row["F_Product"] != null)
                {
                    model.F_Product = row["F_Product"].ToString();
                }
                if (row["F_FrozenFlag"] != null)
                {
                    model.F_FrozenFlag = row["F_FrozenFlag"].ToString();
                }
                if (row["F_IsOpenAccount"] != null)
                {
                    model.F_IsOpenAccount = row["F_IsOpenAccount"].ToString();
                }
                if (row["F_LevelCode"] != null)
                {
                    model.F_LevelCode = row["F_LevelCode"].ToString();
                }
                if (row["F_LevelName"] != null)
                {
                    model.F_LevelName = row["F_LevelName"].ToString();
                }
                if (row["F_MnemonicCode"] != null)
                {
                    model.F_MnemonicCode = row["F_MnemonicCode"].ToString();
                }
                if (row["F_InvoiceBank"] != null)
                {
                    model.F_InvoiceBank = row["F_InvoiceBank"].ToString();
                }
                if (row["F_InvoiceBankAccount"] != null)
                {
                    model.F_InvoiceBankAccount = row["F_InvoiceBankAccount"].ToString();
                }
                if (row["F_TaxRegCode"] != null)
                {
                    model.F_TaxRegCode = row["F_TaxRegCode"].ToString();
                }
                if (row["F_IsRunXLX"] != null)
                {
                    model.F_IsRunXLX = row["F_IsRunXLX"].ToString();
                }
                if (row["F_AnnualSales"] != null)
                {
                    model.F_AnnualSales = row["F_AnnualSales"].ToString();
                }
                if (row["F_Formula"] != null)
                {
                    model.F_Formula = row["F_Formula"].ToString();
                }
                if (row["F_RaiseCrops"] != null)
                {
                    model.F_RaiseCrops = row["F_RaiseCrops"].ToString();
                }
                if (row["F_PlantingArea"] != null)
                {
                    model.F_PlantingArea = row["F_PlantingArea"].ToString();
                }
                if (row["F_FertilizerBrand"] != null)
                {
                    model.F_FertilizerBrand = row["F_FertilizerBrand"].ToString();
                }
                if (row["F_FileId"] != null && row["F_FileId"].ToString() != "")
                {
                    model.F_FileId = int.Parse(row["F_FileId"].ToString());
                }
                if (row["F_WxPassword"] != null)
                {
                    model.F_WxPassword = row["F_WxPassword"].ToString();
                }
                if (row["F_WxOpenId"] != null)
                {
                    model.F_WxOpenId = row["F_WxOpenId"].ToString();
                }
                if (row["F_Remark"] != null)
                {
                    model.F_Remark = row["F_Remark"].ToString();
                }
                if (row["F_CreateBy"] != null)
                {
                    model.F_CreateBy = row["F_CreateBy"].ToString();
                }
                if (row["F_CreateOn"] != null && row["F_CreateOn"].ToString() != "")
                {
                    model.F_CreateOn = DateTime.Parse(row["F_CreateOn"].ToString());
                }
                if (row["F_UpdateCount"] != null && row["F_UpdateCount"].ToString() != "")
                {
                    model.F_UpdateCount = int.Parse(row["F_UpdateCount"].ToString());
                }
                if (row["F_UpdateBy"] != null)
                {
                    model.F_UpdateBy = row["F_UpdateBy"].ToString();
                }
                if (row["F_UpdateOn"] != null && row["F_UpdateOn"].ToString() != "")
                {
                    model.F_UpdateOn = DateTime.Parse(row["F_UpdateOn"].ToString());
                }
                if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "")
                {
                    model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString());
                }
                if (row["F_DeleteBy"] != null)
                {
                    model.F_DeleteBy = row["F_DeleteBy"].ToString();
                }
                if (row["F_DeleteOn"] != null && row["F_DeleteOn"].ToString() != "")
                {
                    model.F_DeleteOn = DateTime.Parse(row["F_DeleteOn"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Cus_CustomerBaseNew ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        ///   
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetExpt(string strWhere)
        {
            StringBuilder strSql = new StringBuilder(); strSql.Append("select F_CustomerCode,F_CompanyName,F_AreaName = (select d.F_DeptName from T_Sys_Department d where d .F_DeptId = c.F_AreaID    ),F_BranchName = (select d.F_DeptName from T_Sys_Department d where d .F_DeptId = c.F_BranchID    ),F_Salesman,F_SalesPhone,F_Channel,F_Credit,F_Legal,F_LegalPhone, case F_Gender when '1' then '男' when '2'then '女'  else '-' end F_Gender , F_AddressProvince,F_AddressCity,F_AddressCountry,F_AddressTownship,F_AddressFull,F_Brands,F_Brands,F_IsRunXLX,F_AnnualSales,F_Formula,F_RaiseCrops,F_PlantingArea,F_FertilizerBrand,F_Remark  from dbo.T_Cus_CustomerBaseNew c  ");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where 1=1" + strWhere);
            }
            strSql.Append(" order by F_CreateOn desc");
            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_CustomerBaseNew ");
            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_CustomerBaseNew ");
            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_CustomerId desc");
            }
            strSql.Append(")AS Row, T.*  from T_Cus_CustomerBaseNew 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
        /// <summary>
        /// 根据Openid 获取用户
        /// </summary>
        public CallCenterApi.Model.T_Cus_CustomerBaseNew GetModelByOpenid(string openid)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 * from T_Cus_CustomerBaseNew ");
            strSql.Append(" where F_WxOpenId=@F_WxOpenId and F_IsDelete=0 ");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_WxOpenId", SqlDbType.NVarChar,200)
            };
            parameters[0].Value = openid;

            CallCenterApi.Model.T_Cus_CustomerBaseNew model = new CallCenterApi.Model.T_Cus_CustomerBaseNew();
            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>
        /// <param name="id"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public bool UpdatePWD(string ids,string pwd)
        {
            StringBuilder strSql = new StringBuilder();
            //strSql.Append("delete from T_Cus_CustomerBaseNew ");
            strSql.Append("update T_Cus_CustomerBaseNew set F_WxPassword='"+ pwd + "' ");
            strSql.Append(" where F_CustomerId in (" + ids + ") ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion  ExtensionMethod
    }
}
