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_CustomerBase
	/// </summary>
	public partial class T_Cus_CustomerBase
    {
        public T_Cus_CustomerBase()
        { }
        #region  BasicMethod

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

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_CustomerId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Cus_CustomerBase");
            strSql.Append(" where F_CustomerId=@F_CustomerId  and F_DeleteFlag=0");
            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_CustomerBase model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Cus_CustomerBase(");
            strSql.Append("F_CustomerName,F_CustomerCode,F_CustomerEName,F_CustomerPym,F_Layer,F_CustomerLayer,F_CategoryId,F_TradeId,F_RegionId,F_IndustryId,F_Address,F_Url,F_Telephone,F_Mobile,F_Fax,F_Email,F_Website,F_PostCode,F_ScaleResume,F_BusinessProfile,F_BusinessLicenseID,F_TaxID,F_OpeningBank,F_BankAccount,F_LegalRepresentative,F_LegalRepresentativeCardID,F_Nature,F_Kind,F_CustomerType,F_MainProduct,F_CustomerFrom,F_TrackInfo,F_TrackState,F_ImportDegree,F_IntentProduct,F_CreateBy,F_CreatedOn,F_ModifyBy,F_ModifiedOn,F_DeleteFlag,F_StatusCode,F_ServiceDept,F_ChargeName,F_ChargeTelephone,F_Province,F_ProductLine,F_ChargeDept,F_AfterSaleName,F_CustomerNature,F_CustomerClass,F_CustomerIndustry,F_RelationShipClass,F_CurrentVersion,F_SystemStartTime,F_QualityGuaranteeEndTime,F_AfterSaleTelephone,F_Notes,F_SystemType,F_City,F_CustomerStatus,F_DeviceCount,F_MaintenanceType,F_ERPCustomerCode,F_ServiceDeptID,F_ProductLineID,F_AfterSaleNameID,F_CustomerNatureID,F_CustomerClassID,F_RelationShipClassID,F_CityID,F_AutoFlag,F_Result,F_FileID,F_SaleOffice,F_AccessTime,F_BroadbandAccount,F_Channel,F_Fusion)");
            strSql.Append(" values (");
            strSql.Append("@F_CustomerName,@F_CustomerCode,@F_CustomerEName,@F_CustomerPym,@F_Layer,@F_CustomerLayer,@F_CategoryId,@F_TradeId,@F_RegionId,@F_IndustryId,@F_Address,@F_Url,@F_Telephone,@F_Mobile,@F_Fax,@F_Email,@F_Website,@F_PostCode,@F_ScaleResume,@F_BusinessProfile,@F_BusinessLicenseID,@F_TaxID,@F_OpeningBank,@F_BankAccount,@F_LegalRepresentative,@F_LegalRepresentativeCardID,@F_Nature,@F_Kind,@F_CustomerType,@F_MainProduct,@F_CustomerFrom,@F_TrackInfo,@F_TrackState,@F_ImportDegree,@F_IntentProduct,@F_CreateBy,@F_CreatedOn,@F_ModifyBy,@F_ModifiedOn,@F_DeleteFlag,@F_StatusCode,@F_ServiceDept,@F_ChargeName,@F_ChargeTelephone,@F_Province,@F_ProductLine,@F_ChargeDept,@F_AfterSaleName,@F_CustomerNature,@F_CustomerClass,@F_CustomerIndustry,@F_RelationShipClass,@F_CurrentVersion,@F_SystemStartTime,@F_QualityGuaranteeEndTime,@F_AfterSaleTelephone,@F_Notes,@F_SystemType,@F_City,@F_CustomerStatus,@F_DeviceCount,@F_MaintenanceType,@F_ERPCustomerCode,@F_ServiceDeptID,@F_ProductLineID,@F_AfterSaleNameID,@F_CustomerNatureID,@F_CustomerClassID,@F_RelationShipClassID,@F_CityID,@F_AutoFlag,@F_Result,@F_FileID,@F_SaleOffice,@F_AccessTime,@F_BroadbandAccount,@F_Channel,@F_Fusion)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CustomerCode", SqlDbType.VarChar,100),
                    new SqlParameter("@F_CustomerEName", SqlDbType.NVarChar,800),
                    new SqlParameter("@F_CustomerPym", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_Layer", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_CustomerLayer", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_CategoryId", SqlDbType.Int,4),
                    new SqlParameter("@F_TradeId", SqlDbType.Int,4),
                    new SqlParameter("@F_RegionId", SqlDbType.Int,4),
                    new SqlParameter("@F_IndustryId", SqlDbType.Int,4),
                    new SqlParameter("@F_Address", SqlDbType.NVarChar,300),
                    new SqlParameter("@F_Url", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Telephone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Fax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Email", SqlDbType.VarChar,200),
                    new SqlParameter("@F_Website", SqlDbType.VarChar,200),
                    new SqlParameter("@F_PostCode", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ScaleResume", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_BusinessProfile", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_BusinessLicenseID", SqlDbType.VarChar,80),
                    new SqlParameter("@F_TaxID", SqlDbType.VarChar,80),
                    new SqlParameter("@F_OpeningBank", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_BankAccount", SqlDbType.VarChar,80),
                    new SqlParameter("@F_LegalRepresentative", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LegalRepresentativeCardID", SqlDbType.VarChar,30),
                    new SqlParameter("@F_Nature", SqlDbType.NVarChar,80),
                    new SqlParameter("@F_Kind", SqlDbType.NVarChar,80),
                    new SqlParameter("@F_CustomerType", SqlDbType.Int,4),
                    new SqlParameter("@F_MainProduct", SqlDbType.Text),
                    new SqlParameter("@F_CustomerFrom", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TrackInfo", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TrackState", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ImportDegree", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_IntentProduct", SqlDbType.Text),
                    new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
                    new SqlParameter("@F_CreatedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_ModifyBy", SqlDbType.Int,4),
                    new SqlParameter("@F_ModifiedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_StatusCode", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_ServiceDept", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ChargeName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ChargeTelephone", SqlDbType.VarChar,15),
                    new SqlParameter("@F_Province", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ProductLine", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ChargeDept", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_AfterSaleName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CustomerNature", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CustomerClass", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CustomerIndustry", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_RelationShipClass", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CurrentVersion", SqlDbType.VarChar,100),
                    new SqlParameter("@F_SystemStartTime", SqlDbType.DateTime),
                    new SqlParameter("@F_QualityGuaranteeEndTime", SqlDbType.DateTime),
                    new SqlParameter("@F_AfterSaleTelephone", SqlDbType.VarChar,15),
                    new SqlParameter("@F_Notes", SqlDbType.NVarChar,500),
                    new SqlParameter("@F_SystemType", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_City", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CustomerStatus", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_DeviceCount", SqlDbType.Int,4),
                    new SqlParameter("@F_MaintenanceType", SqlDbType.NVarChar,30),
                    new SqlParameter("@F_ERPCustomerCode", SqlDbType.VarChar,100),
                    new SqlParameter("@F_ServiceDeptID", SqlDbType.Int,4),
                    new SqlParameter("@F_ProductLineID", SqlDbType.Int,4),
                    new SqlParameter("@F_AfterSaleNameID", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerNatureID", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerClassID", SqlDbType.Int,4),
                    new SqlParameter("@F_RelationShipClassID", SqlDbType.Int,4),
                    new SqlParameter("@F_CityID", SqlDbType.Int,4),
                    new SqlParameter("@F_AutoFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_Result", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_FileID", SqlDbType.SmallInt,2),
                    //F_SaleOffice,F_AccessTime,F_BroadbandAccount,F_Channele,F_Fusion
                        new SqlParameter("@F_SaleOffice", SqlDbType.NVarChar,100),
                          new SqlParameter("@F_AccessTime", SqlDbType.NVarChar,100),
                            new SqlParameter("@F_BroadbandAccount", SqlDbType.NVarChar,100),
                              new SqlParameter("@F_Channel", SqlDbType.NVarChar,100),
                                new SqlParameter("@F_Fusion", SqlDbType.NVarChar,50)
            };
            parameters[0].Value = model.F_CustomerName;
            parameters[1].Value = model.F_CustomerCode;
            parameters[2].Value = model.F_CustomerEName;
            parameters[3].Value = model.F_CustomerPym;
            parameters[4].Value = model.F_Layer;
            parameters[5].Value = model.F_CustomerLayer;
            parameters[6].Value = model.F_CategoryId;
            parameters[7].Value = model.F_TradeId;
            parameters[8].Value = model.F_RegionId;
            parameters[9].Value = model.F_IndustryId;
            parameters[10].Value = model.F_Address;
            parameters[11].Value = model.F_Url;
            parameters[12].Value = model.F_Telephone;
            parameters[13].Value = model.F_Mobile;
            parameters[14].Value = model.F_Fax;
            parameters[15].Value = model.F_Email;
            parameters[16].Value = model.F_Website;
            parameters[17].Value = model.F_PostCode;
            parameters[18].Value = model.F_ScaleResume;
            parameters[19].Value = model.F_BusinessProfile;
            parameters[20].Value = model.F_BusinessLicenseID;
            parameters[21].Value = model.F_TaxID;
            parameters[22].Value = model.F_OpeningBank;
            parameters[23].Value = model.F_BankAccount;
            parameters[24].Value = model.F_LegalRepresentative;
            parameters[25].Value = model.F_LegalRepresentativeCardID;
            parameters[26].Value = model.F_Nature;
            parameters[27].Value = model.F_Kind;
            parameters[28].Value = model.F_CustomerType;
            parameters[29].Value = model.F_MainProduct;
            parameters[30].Value = model.F_CustomerFrom;
            parameters[31].Value = model.F_TrackInfo;
            parameters[32].Value = model.F_TrackState;
            parameters[33].Value = model.F_ImportDegree;
            parameters[34].Value = model.F_IntentProduct;
            parameters[35].Value = model.F_CreateBy;
            parameters[36].Value = model.F_CreatedOn;
            parameters[37].Value = model.F_ModifyBy;
            parameters[38].Value = model.F_ModifiedOn;
            parameters[39].Value = model.F_DeleteFlag;
            parameters[40].Value = model.F_StatusCode;
            parameters[41].Value = model.F_ServiceDept;
            parameters[42].Value = model.F_ChargeName;
            parameters[43].Value = model.F_ChargeTelephone;
            parameters[44].Value = model.F_Province;
            parameters[45].Value = model.F_ProductLine;
            parameters[46].Value = model.F_ChargeDept;
            parameters[47].Value = model.F_AfterSaleName;
            parameters[48].Value = model.F_CustomerNature;
            parameters[49].Value = model.F_CustomerClass;
            parameters[50].Value = model.F_CustomerIndustry;
            parameters[51].Value = model.F_RelationShipClass;
            parameters[52].Value = model.F_CurrentVersion;
            parameters[53].Value = model.F_SystemStartTime;
            parameters[54].Value = model.F_QualityGuaranteeEndTime;
            parameters[55].Value = model.F_AfterSaleTelephone;
            parameters[56].Value = model.F_Notes;
            parameters[57].Value = model.F_SystemType;
            parameters[58].Value = model.F_City;
            parameters[59].Value = model.F_CustomerStatus;
            parameters[60].Value = model.F_DeviceCount;
            parameters[61].Value = model.F_MaintenanceType;
            parameters[62].Value = model.F_ERPCustomerCode;
            parameters[63].Value = model.F_ServiceDeptID;
            parameters[64].Value = model.F_ProductLineID;
            parameters[65].Value = model.F_AfterSaleNameID;
            parameters[66].Value = model.F_CustomerNatureID;
            parameters[67].Value = model.F_CustomerClassID;
            parameters[68].Value = model.F_RelationShipClassID;
            parameters[69].Value = model.F_CityID;
            parameters[70].Value = model.F_AutoFlag;
            parameters[71].Value = model.F_Result;
            parameters[72].Value = model.F_FileID;
          //  F_SaleOffice,F_AccessTime,F_BroadbandAccount,F_Channele,F_Fusion
            parameters[73].Value = model.F_SaleOffice;
            parameters[74].Value = model.F_AccessTime;
            parameters[75].Value = model.F_BroadbandAccount;
            parameters[76].Value = model.F_Channel;
            parameters[77].Value = model.F_Fusion;


            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_CustomerBase model)
        {
            //new SqlParameter("@F_SaleOffice", SqlDbType.NVarChar, 100),
            //              new SqlParameter("@F_AccessTime", SqlDbType.NVarChar, 100),
            //                new SqlParameter("@F_BroadbandAccount", SqlDbType.NVarChar, 100),
            //                  new SqlParameter("@F_Channel", SqlDbType.NVarChar, 100),
            //                    new SqlParameter("@F_Fusion", SqlDbType.NVarChar, 50)

    
          


            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Cus_CustomerBase set ");
            strSql.Append("F_CustomerName=@F_CustomerName,");
            strSql.Append("F_CustomerCode=@F_CustomerCode,");
            strSql.Append("F_CustomerEName=@F_CustomerEName,");
            strSql.Append("F_CustomerPym=@F_CustomerPym,");
            strSql.Append("F_Layer=@F_Layer,");
            strSql.Append("F_CustomerLayer=@F_CustomerLayer,");
            strSql.Append("F_CategoryId=@F_CategoryId,");
            strSql.Append("F_TradeId=@F_TradeId,");
            strSql.Append("F_RegionId=@F_RegionId,");
            strSql.Append("F_IndustryId=@F_IndustryId,");
            strSql.Append("F_Address=@F_Address,");
            strSql.Append("F_Url=@F_Url,");
            strSql.Append("F_Telephone=@F_Telephone,");
            strSql.Append("F_Mobile=@F_Mobile,");
            strSql.Append("F_Fax=@F_Fax,");
            strSql.Append("F_Email=@F_Email,");
            strSql.Append("F_Website=@F_Website,");
            strSql.Append("F_PostCode=@F_PostCode,");
            strSql.Append("F_ScaleResume=@F_ScaleResume,");
            strSql.Append("F_BusinessProfile=@F_BusinessProfile,");
            strSql.Append("F_BusinessLicenseID=@F_BusinessLicenseID,");
            strSql.Append("F_TaxID=@F_TaxID,");
            strSql.Append("F_OpeningBank=@F_OpeningBank,");
            strSql.Append("F_BankAccount=@F_BankAccount,");
            strSql.Append("F_LegalRepresentative=@F_LegalRepresentative,");
            strSql.Append("F_LegalRepresentativeCardID=@F_LegalRepresentativeCardID,");
            strSql.Append("F_Nature=@F_Nature,");
            strSql.Append("F_Kind=@F_Kind,");
            strSql.Append("F_CustomerType=@F_CustomerType,");
            strSql.Append("F_MainProduct=@F_MainProduct,");
            strSql.Append("F_CustomerFrom=@F_CustomerFrom,");
            strSql.Append("F_TrackInfo=@F_TrackInfo,");
            strSql.Append("F_TrackState=@F_TrackState,");
            strSql.Append("F_ImportDegree=@F_ImportDegree,");
            strSql.Append("F_IntentProduct=@F_IntentProduct,");
            strSql.Append("F_CreateBy=@F_CreateBy,");
            strSql.Append("F_CreatedOn=@F_CreatedOn,");
            strSql.Append("F_ModifyBy=@F_ModifyBy,");
            strSql.Append("F_ModifiedOn=@F_ModifiedOn,");
            strSql.Append("F_DeleteFlag=@F_DeleteFlag,");
            strSql.Append("F_StatusCode=@F_StatusCode,");
            strSql.Append("F_ServiceDept=@F_ServiceDept,");
            strSql.Append("F_ChargeName=@F_ChargeName,");
            strSql.Append("F_ChargeTelephone=@F_ChargeTelephone,");
            strSql.Append("F_Province=@F_Province,");
            strSql.Append("F_ProductLine=@F_ProductLine,");
            strSql.Append("F_ChargeDept=@F_ChargeDept,");
            strSql.Append("F_AfterSaleName=@F_AfterSaleName,");
            strSql.Append("F_CustomerNature=@F_CustomerNature,");
            strSql.Append("F_CustomerClass=@F_CustomerClass,");
            strSql.Append("F_CustomerIndustry=@F_CustomerIndustry,");
            strSql.Append("F_RelationShipClass=@F_RelationShipClass,");
            strSql.Append("F_CurrentVersion=@F_CurrentVersion,");
            strSql.Append("F_SystemStartTime=@F_SystemStartTime,");
            strSql.Append("F_QualityGuaranteeEndTime=@F_QualityGuaranteeEndTime,");
            strSql.Append("F_AfterSaleTelephone=@F_AfterSaleTelephone,");
            strSql.Append("F_Notes=@F_Notes,");
            strSql.Append("F_SystemType=@F_SystemType,");
            strSql.Append("F_City=@F_City,");
            strSql.Append("F_CustomerStatus=@F_CustomerStatus,");
            strSql.Append("F_DeviceCount=@F_DeviceCount,");
            strSql.Append("F_MaintenanceType=@F_MaintenanceType,");
            strSql.Append("F_ERPCustomerCode=@F_ERPCustomerCode,");
            strSql.Append("F_ServiceDeptID=@F_ServiceDeptID,");
            strSql.Append("F_ProductLineID=@F_ProductLineID,");
            strSql.Append("F_AfterSaleNameID=@F_AfterSaleNameID,");
            strSql.Append("F_CustomerNatureID=@F_CustomerNatureID,");
            strSql.Append("F_CustomerClassID=@F_CustomerClassID,");
            strSql.Append("F_RelationShipClassID=@F_RelationShipClassID,");
            strSql.Append("F_CityID=@F_CityID,");
            strSql.Append("F_AutoFlag=@F_AutoFlag,");
            strSql.Append("F_SaleOffice=@F_SaleOffice,");
            strSql.Append("F_AccessTime=@F_AccessTime,");
            strSql.Append("F_BroadbandAccount=@F_BroadbandAccount,");
            strSql.Append("F_Channel=@F_Channel,");
            strSql.Append("F_Fusion=@F_Fusion,");

            strSql.Append("F_Result=@F_Result");
            strSql.Append(" where F_CustomerId=@F_CustomerId");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerName", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_CustomerCode", SqlDbType.VarChar,100),
                    new SqlParameter("@F_CustomerEName", SqlDbType.NVarChar,800),
                    new SqlParameter("@F_CustomerPym", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_Layer", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_CustomerLayer", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_CategoryId", SqlDbType.Int,4),
                    new SqlParameter("@F_TradeId", SqlDbType.Int,4),
                    new SqlParameter("@F_RegionId", SqlDbType.Int,4),
                    new SqlParameter("@F_IndustryId", SqlDbType.Int,4),
                    new SqlParameter("@F_Address", SqlDbType.NVarChar,300),
                    new SqlParameter("@F_Url", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Telephone", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Fax", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_Email", SqlDbType.VarChar,200),
                    new SqlParameter("@F_Website", SqlDbType.VarChar,200),
                    new SqlParameter("@F_PostCode", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ScaleResume", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_BusinessProfile", SqlDbType.NVarChar,2000),
                    new SqlParameter("@F_BusinessLicenseID", SqlDbType.VarChar,80),
                    new SqlParameter("@F_TaxID", SqlDbType.VarChar,80),
                    new SqlParameter("@F_OpeningBank", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_BankAccount", SqlDbType.VarChar,80),
                    new SqlParameter("@F_LegalRepresentative", SqlDbType.VarChar,50),
                    new SqlParameter("@F_LegalRepresentativeCardID", SqlDbType.VarChar,30),
                    new SqlParameter("@F_Nature", SqlDbType.NVarChar,80),
                    new SqlParameter("@F_Kind", SqlDbType.NVarChar,80),
                    new SqlParameter("@F_CustomerType", SqlDbType.Int,4),
                    new SqlParameter("@F_MainProduct", SqlDbType.Text),
                    new SqlParameter("@F_CustomerFrom", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TrackInfo", SqlDbType.NVarChar,200),
                    new SqlParameter("@F_TrackState", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ImportDegree", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_IntentProduct", SqlDbType.Text),
                    new SqlParameter("@F_CreateBy", SqlDbType.Int,4),
                    new SqlParameter("@F_CreatedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_ModifyBy", SqlDbType.Int,4),
                    new SqlParameter("@F_ModifiedOn", SqlDbType.DateTime),
                    new SqlParameter("@F_DeleteFlag", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_StatusCode", SqlDbType.SmallInt,2),
                    new SqlParameter("@F_ServiceDept", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ChargeName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ChargeTelephone", SqlDbType.VarChar,15),
                    new SqlParameter("@F_Province", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_ProductLine", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ChargeDept", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_AfterSaleName", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CustomerNature", SqlDbType.NVarChar,20),
                    new SqlParameter("@F_CustomerClass", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CustomerIndustry", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_RelationShipClass", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CurrentVersion", SqlDbType.VarChar,100),
                    new SqlParameter("@F_SystemStartTime", SqlDbType.DateTime),
                    new SqlParameter("@F_QualityGuaranteeEndTime", SqlDbType.DateTime),
                    new SqlParameter("@F_AfterSaleTelephone", SqlDbType.VarChar,15),
                    new SqlParameter("@F_Notes", SqlDbType.NVarChar,500),
                    new SqlParameter("@F_SystemType", SqlDbType.NVarChar,100),
                    new SqlParameter("@F_City", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_CustomerStatus", SqlDbType.NVarChar,10),
                    new SqlParameter("@F_DeviceCount", SqlDbType.Int,4),
                    new SqlParameter("@F_MaintenanceType", SqlDbType.NVarChar,30),
                    new SqlParameter("@F_ERPCustomerCode", SqlDbType.VarChar,100),
                    new SqlParameter("@F_ServiceDeptID", SqlDbType.Int,4),
                    new SqlParameter("@F_ProductLineID", SqlDbType.Int,4),
                    new SqlParameter("@F_AfterSaleNameID", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerNatureID", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerClassID", SqlDbType.Int,4),
                    new SqlParameter("@F_RelationShipClassID", SqlDbType.Int,4),
                    new SqlParameter("@F_CityID", SqlDbType.Int,4),
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4),
                    new SqlParameter("@F_AutoFlag", SqlDbType.SmallInt,2),

                         new SqlParameter("@F_SaleOffice", SqlDbType.NVarChar, 100),
                          new SqlParameter("@F_AccessTime", SqlDbType.NVarChar, 100),
                            new SqlParameter("@F_BroadbandAccount", SqlDbType.NVarChar, 100),
                              new SqlParameter("@F_Channel", SqlDbType.NVarChar, 100),
                                new SqlParameter("@F_Fusion", SqlDbType.NVarChar, 50),



            new SqlParameter("@F_Result", SqlDbType.NVarChar,20)};
            parameters[0].Value = model.F_CustomerName;
            parameters[1].Value = model.F_CustomerCode;
            parameters[2].Value = model.F_CustomerEName;
            parameters[3].Value = model.F_CustomerPym;
            parameters[4].Value = model.F_Layer;
            parameters[5].Value = model.F_CustomerLayer;
            parameters[6].Value = model.F_CategoryId;
            parameters[7].Value = model.F_TradeId;
            parameters[8].Value = model.F_RegionId;
            parameters[9].Value = model.F_IndustryId;
            parameters[10].Value = model.F_Address;
            parameters[11].Value = model.F_Url;
            parameters[12].Value = model.F_Telephone;
            parameters[13].Value = model.F_Mobile;
            parameters[14].Value = model.F_Fax;
            parameters[15].Value = model.F_Email;
            parameters[16].Value = model.F_Website;
            parameters[17].Value = model.F_PostCode;
            parameters[18].Value = model.F_ScaleResume;
            parameters[19].Value = model.F_BusinessProfile;
            parameters[20].Value = model.F_BusinessLicenseID;
            parameters[21].Value = model.F_TaxID;
            parameters[22].Value = model.F_OpeningBank;
            parameters[23].Value = model.F_BankAccount;
            parameters[24].Value = model.F_LegalRepresentative;
            parameters[25].Value = model.F_LegalRepresentativeCardID;
            parameters[26].Value = model.F_Nature;
            parameters[27].Value = model.F_Kind;
            parameters[28].Value = model.F_CustomerType;
            parameters[29].Value = model.F_MainProduct;
            parameters[30].Value = model.F_CustomerFrom;
            parameters[31].Value = model.F_TrackInfo;
            parameters[32].Value = model.F_TrackState;
            parameters[33].Value = model.F_ImportDegree;
            parameters[34].Value = model.F_IntentProduct;
            parameters[35].Value = model.F_CreateBy;
            parameters[36].Value = model.F_CreatedOn;
            parameters[37].Value = model.F_ModifyBy;
            parameters[38].Value = model.F_ModifiedOn;
            parameters[39].Value = model.F_DeleteFlag;
            parameters[40].Value = model.F_StatusCode;
            parameters[41].Value = model.F_ServiceDept;
            parameters[42].Value = model.F_ChargeName;
            parameters[43].Value = model.F_ChargeTelephone;
            parameters[44].Value = model.F_Province;
            parameters[45].Value = model.F_ProductLine;
            parameters[46].Value = model.F_ChargeDept;
            parameters[47].Value = model.F_AfterSaleName;
            parameters[48].Value = model.F_CustomerNature;
            parameters[49].Value = model.F_CustomerClass;
            parameters[50].Value = model.F_CustomerIndustry;
            parameters[51].Value = model.F_RelationShipClass;
            parameters[52].Value = model.F_CurrentVersion;
            parameters[53].Value = model.F_SystemStartTime;
            parameters[54].Value = model.F_QualityGuaranteeEndTime;
            parameters[55].Value = model.F_AfterSaleTelephone;
            parameters[56].Value = model.F_Notes;
            parameters[57].Value = model.F_SystemType;
            parameters[58].Value = model.F_City;
            parameters[59].Value = model.F_CustomerStatus;
            parameters[60].Value = model.F_DeviceCount;
            parameters[61].Value = model.F_MaintenanceType;
            parameters[62].Value = model.F_ERPCustomerCode;
            parameters[63].Value = model.F_ServiceDeptID;
            parameters[64].Value = model.F_ProductLineID;
            parameters[65].Value = model.F_AfterSaleNameID;
            parameters[66].Value = model.F_CustomerNatureID;
            parameters[67].Value = model.F_CustomerClassID;
            parameters[68].Value = model.F_RelationShipClassID;
            parameters[69].Value = model.F_CityID;
            parameters[70].Value = model.F_CustomerId;
            parameters[71].Value = model.F_AutoFlag;

            parameters[72].Value = model.F_SaleOffice;
            parameters[73].Value = model.F_AccessTime;
            parameters[74].Value = model.F_BroadbandAccount;
            parameters[75].Value = model.F_Channel;
            parameters[76].Value = model.F_Fusion;

            parameters[77].Value = model.F_Result;

            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_CustomerBase ");
            strSql.Append("update T_Cus_CustomerBase 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_CustomerBase ");
            strSql.Append("update T_Cus_CustomerBase set F_DeleteFlag=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_CustomerBase GetModel(int F_CustomerId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_CustomerId,F_CustomerName,F_CustomerCode,F_CustomerEName,F_CustomerPym,F_Layer,F_CustomerLayer,F_CategoryId,F_TradeId,F_RegionId,F_IndustryId,F_Address,F_Url,F_Telephone,F_Mobile,F_Fax,F_Email,F_Website,F_PostCode,F_ScaleResume,F_BusinessProfile,F_BusinessLicenseID,F_TaxID,F_OpeningBank,F_BankAccount,F_LegalRepresentative,F_LegalRepresentativeCardID,F_Nature,F_Kind,F_CustomerType,F_MainProduct,F_CustomerFrom,F_TrackInfo,F_TrackState,F_ImportDegree,F_IntentProduct,F_CreateBy,F_CreatedOn,F_ModifyBy,F_ModifiedOn,F_DeleteFlag,F_StatusCode,F_ServiceDept,F_ChargeName,F_ChargeTelephone,F_Province,F_ProductLine,F_ChargeDept,F_AfterSaleName,F_CustomerNature,F_CustomerClass,F_CustomerIndustry,F_RelationShipClass,F_CurrentVersion,F_SystemStartTime,F_QualityGuaranteeEndTime,F_AfterSaleTelephone,F_Notes,F_SystemType,F_City,F_CustomerStatus,F_DeviceCount,F_MaintenanceType,F_ERPCustomerCode,F_ServiceDeptID,F_ProductLineID,F_AfterSaleNameID,F_CustomerNatureID,F_CustomerClassID,F_RelationShipClassID,F_CityID,F_Result,F_AutoFlag ,F_SaleOffice      ,F_AccessTime      ,F_BroadbandAccount      ,F_Channel      ,F_Fusion from T_Cus_CustomerBase ");
            strSql.Append(" where F_CustomerId=@F_CustomerId  and F_DeleteFlag=0");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_CustomerId", SqlDbType.Int,4)
            };
            parameters[0].Value = F_CustomerId;

            CallCenterApi.Model.T_Cus_CustomerBase model = new CallCenterApi.Model.T_Cus_CustomerBase();
            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_CustomerBase DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Cus_CustomerBase model = new CallCenterApi.Model.T_Cus_CustomerBase();
            if (row != null)
            {
                if (row["F_CustomerId"] != null && row["F_CustomerId"].ToString() != "")
                {
                    model.F_CustomerId = int.Parse(row["F_CustomerId"].ToString());
                }
                if (row["F_CustomerName"] != null)
                {
                    model.F_CustomerName = row["F_CustomerName"].ToString();
                }
                if (row["F_CustomerCode"] != null)
                {
                    model.F_CustomerCode = row["F_CustomerCode"].ToString();
                }
                if (row["F_CustomerEName"] != null)
                {
                    model.F_CustomerEName = row["F_CustomerEName"].ToString();
                }
                if (row["F_CustomerPym"] != null)
                {
                    model.F_CustomerPym = row["F_CustomerPym"].ToString();
                }
                if (row["F_Layer"] != null && row["F_Layer"].ToString() != "")
                {
                    model.F_Layer = int.Parse(row["F_Layer"].ToString());
                }
                if (row["F_CustomerLayer"] != null)
                {
                    model.F_CustomerLayer = row["F_CustomerLayer"].ToString();
                }
                if (row["F_CategoryId"] != null && row["F_CategoryId"].ToString() != "")
                {
                    model.F_CategoryId = int.Parse(row["F_CategoryId"].ToString());
                }
                if (row["F_TradeId"] != null && row["F_TradeId"].ToString() != "")
                {
                    model.F_TradeId = int.Parse(row["F_TradeId"].ToString());
                }
                if (row["F_RegionId"] != null && row["F_RegionId"].ToString() != "")
                {
                    model.F_RegionId = int.Parse(row["F_RegionId"].ToString());
                }
                if (row["F_IndustryId"] != null && row["F_IndustryId"].ToString() != "")
                {
                    model.F_IndustryId = int.Parse(row["F_IndustryId"].ToString());
                }
                if (row["F_Address"] != null)
                {
                    model.F_Address = row["F_Address"].ToString();
                }
                if (row["F_Url"] != null)
                {
                    model.F_Url = row["F_Url"].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_Fax"] != null)
                {
                    model.F_Fax = row["F_Fax"].ToString();
                }
                if (row["F_Email"] != null)
                {
                    model.F_Email = row["F_Email"].ToString();
                }
                if (row["F_Website"] != null)
                {
                    model.F_Website = row["F_Website"].ToString();
                }
                if (row["F_PostCode"] != null)
                {
                    model.F_PostCode = row["F_PostCode"].ToString();
                }
                if (row["F_ScaleResume"] != null)
                {
                    model.F_ScaleResume = row["F_ScaleResume"].ToString();
                }
                if (row["F_BusinessProfile"] != null)
                {
                    model.F_BusinessProfile = row["F_BusinessProfile"].ToString();
                }
                if (row["F_BusinessLicenseID"] != null)
                {
                    model.F_BusinessLicenseID = row["F_BusinessLicenseID"].ToString();
                }
                if (row["F_TaxID"] != null)
                {
                    model.F_TaxID = row["F_TaxID"].ToString();
                }
                if (row["F_OpeningBank"] != null)
                {
                    model.F_OpeningBank = row["F_OpeningBank"].ToString();
                }
                if (row["F_BankAccount"] != null)
                {
                    model.F_BankAccount = row["F_BankAccount"].ToString();
                }
                if (row["F_LegalRepresentative"] != null)
                {
                    model.F_LegalRepresentative = row["F_LegalRepresentative"].ToString();
                }
                if (row["F_LegalRepresentativeCardID"] != null)
                {
                    model.F_LegalRepresentativeCardID = row["F_LegalRepresentativeCardID"].ToString();
                }
                if (row["F_Nature"] != null)
                {
                    model.F_Nature = row["F_Nature"].ToString();
                }
                if (row["F_Kind"] != null)
                {
                    model.F_Kind = row["F_Kind"].ToString();
                }
                if (row["F_CustomerType"] != null && row["F_CustomerType"].ToString() != "")
                {
                    model.F_CustomerType = int.Parse(row["F_CustomerType"].ToString());
                }
                if (row["F_MainProduct"] != null)
                {
                    model.F_MainProduct = row["F_MainProduct"].ToString();
                }
                if (row["F_CustomerFrom"] != null)
                {
                    model.F_CustomerFrom = row["F_CustomerFrom"].ToString();
                }
                if (row["F_TrackInfo"] != null)
                {
                    model.F_TrackInfo = row["F_TrackInfo"].ToString();
                }
                if (row["F_TrackState"] != null)
                {
                    model.F_TrackState = row["F_TrackState"].ToString();
                }
                if (row["F_ImportDegree"] != null)
                {
                    model.F_ImportDegree = row["F_ImportDegree"].ToString();
                }
                if (row["F_IntentProduct"] != null)
                {
                    model.F_IntentProduct = row["F_IntentProduct"].ToString();
                }
                if (row["F_CreateBy"] != null && row["F_CreateBy"].ToString() != "")
                {
                    model.F_CreateBy = int.Parse(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_ModifyBy"] != null && row["F_ModifyBy"].ToString() != "")
                {
                    model.F_ModifyBy = int.Parse(row["F_ModifyBy"].ToString());
                }
                if (row["F_ModifiedOn"] != null && row["F_ModifiedOn"].ToString() != "")
                {
                    model.F_ModifiedOn = DateTime.Parse(row["F_ModifiedOn"].ToString());
                }
                if (row["F_DeleteFlag"] != null && row["F_DeleteFlag"].ToString() != "")
                {
                    model.F_DeleteFlag = int.Parse(row["F_DeleteFlag"].ToString());
                }
                if (row["F_StatusCode"] != null && row["F_StatusCode"].ToString() != "")
                {
                    model.F_StatusCode = int.Parse(row["F_StatusCode"].ToString());
                }
                if (row["F_ServiceDept"] != null)
                {
                    model.F_ServiceDept = row["F_ServiceDept"].ToString();
                }
                if (row["F_ChargeName"] != null)
                {
                    model.F_ChargeName = row["F_ChargeName"].ToString();
                }
                if (row["F_ChargeTelephone"] != null)
                {
                    model.F_ChargeTelephone = row["F_ChargeTelephone"].ToString();
                }
                if (row["F_Province"] != null)
                {
                    model.F_Province = row["F_Province"].ToString();
                }
                if (row["F_ProductLine"] != null)
                {
                    model.F_ProductLine = row["F_ProductLine"].ToString();
                }
                if (row["F_ChargeDept"] != null)
                {
                    model.F_ChargeDept = row["F_ChargeDept"].ToString();
                }
                if (row["F_AfterSaleName"] != null)
                {
                    model.F_AfterSaleName = row["F_AfterSaleName"].ToString();
                }
                if (row["F_CustomerNature"] != null)
                {
                    model.F_CustomerNature = row["F_CustomerNature"].ToString();
                }
                if (row["F_CustomerClass"] != null)
                {
                    model.F_CustomerClass = row["F_CustomerClass"].ToString();
                }
                if (row["F_CustomerIndustry"] != null)
                {
                    model.F_CustomerIndustry = row["F_CustomerIndustry"].ToString();
                }
                if (row["F_RelationShipClass"] != null)
                {
                    model.F_RelationShipClass = row["F_RelationShipClass"].ToString();
                }
                if (row["F_CurrentVersion"] != null)
                {
                    model.F_CurrentVersion = row["F_CurrentVersion"].ToString();
                }
                if (row["F_SystemStartTime"] != null && row["F_SystemStartTime"].ToString() != "")
                {
                    model.F_SystemStartTime = DateTime.Parse(row["F_SystemStartTime"].ToString());
                }
                if (row["F_QualityGuaranteeEndTime"] != null && row["F_QualityGuaranteeEndTime"].ToString() != "")
                {
                    model.F_QualityGuaranteeEndTime = DateTime.Parse(row["F_QualityGuaranteeEndTime"].ToString());
                }
                if (row["F_AfterSaleTelephone"] != null)
                {
                    model.F_AfterSaleTelephone = row["F_AfterSaleTelephone"].ToString();
                }
                if (row["F_Notes"] != null)
                {
                    model.F_Notes = row["F_Notes"].ToString();
                }
                if (row["F_SystemType"] != null)
                {
                    model.F_SystemType = row["F_SystemType"].ToString();
                }
                if (row["F_City"] != null)
                {
                    model.F_City = row["F_City"].ToString();
                }
                if (row["F_CustomerStatus"] != null)
                {
                    model.F_CustomerStatus = row["F_CustomerStatus"].ToString();
                }
                if (row["F_DeviceCount"] != null && row["F_DeviceCount"].ToString() != "")
                {
                    model.F_DeviceCount = int.Parse(row["F_DeviceCount"].ToString());
                }
                if (row["F_MaintenanceType"] != null)
                {
                    model.F_MaintenanceType = row["F_MaintenanceType"].ToString();
                }
                if (row["F_ERPCustomerCode"] != null)
                {
                    model.F_ERPCustomerCode = row["F_ERPCustomerCode"].ToString();
                }
                if (row["F_ServiceDeptID"] != null && row["F_ServiceDeptID"].ToString() != "")
                {
                    model.F_ServiceDeptID = int.Parse(row["F_ServiceDeptID"].ToString());
                }
                if (row["F_ProductLineID"] != null && row["F_ProductLineID"].ToString() != "")
                {
                    model.F_ProductLineID = int.Parse(row["F_ProductLineID"].ToString());
                }
                if (row["F_AfterSaleNameID"] != null && row["F_AfterSaleNameID"].ToString() != "")
                {
                    model.F_AfterSaleNameID = int.Parse(row["F_AfterSaleNameID"].ToString());
                }
                if (row["F_CustomerNatureID"] != null && row["F_CustomerNatureID"].ToString() != "")
                {
                    model.F_CustomerNatureID = int.Parse(row["F_CustomerNatureID"].ToString());
                }
                if (row["F_CustomerClassID"] != null && row["F_CustomerClassID"].ToString() != "")
                {
                    model.F_CustomerClassID = int.Parse(row["F_CustomerClassID"].ToString());
                }
                if (row["F_RelationShipClassID"] != null && row["F_RelationShipClassID"].ToString() != "")
                {
                    model.F_RelationShipClassID = int.Parse(row["F_RelationShipClassID"].ToString());
                }
                if (row["F_CityID"] != null && row["F_CityID"].ToString() != "")
                {
                    model.F_CityID = int.Parse(row["F_CityID"].ToString());
                }
                //2017-11-2
                if (row["F_AutoFlag"] != null && row["F_AutoFlag"].ToString() != "")
                {
                    model.F_AutoFlag = int.Parse(row["F_AutoFlag"].ToString());
                }
                if (row["F_Result"] != null)
                {
                    model.F_Result = row["F_Result"].ToString();
                }
          
                if (row["F_SaleOffice"] != null)
                {
                    model.F_SaleOffice = row["F_SaleOffice"].ToString();
                }
                if (row["F_AccessTime"] != null)
                {
                    model.F_AccessTime = row["F_AccessTime"].ToString();
                }
                if (row["F_BroadbandAccount"] != null)
                {
                    model.F_BroadbandAccount = row["F_BroadbandAccount"].ToString();
                }
                if (row["F_Channel"] != null)
                {
                    model.F_Channel = row["F_Channel"].ToString();
                }
                if (row["F_Fusion"] != null)
                {
                    model.F_Fusion = row["F_Fusion"].ToString();
                }





            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Cus_CustomerBase ");
            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_CustomerBase ");
            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_CustomerBase ");
            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_CustomerBase T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

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

        //2017-11-2
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool PhoneExists(string  F_Mobile)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Cus_CustomerBase");
            strSql.Append(" where F_Mobile=@F_Mobile  and F_DeleteFlag=0");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,100)
            };
            parameters[0].Value = F_Mobile;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 根据号码获取客户信息
        /// </summary>
        /// <param name="F_Mobile"></param>
        /// <returns></returns>
        public CallCenterApi.Model.T_Cus_CustomerBase GetModelByPhone(string F_Mobile)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  * from T_Cus_CustomerBase ");
            strSql.Append(" where F_Mobile=@F_Mobile  and F_DeleteFlag=0");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,100)
            };
            parameters[0].Value = F_Mobile;

            CallCenterApi.Model.T_Cus_CustomerBase model = new CallCenterApi.Model.T_Cus_CustomerBase();
            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 bool PhoneDelete(string F_Mobile)
        {

            StringBuilder strSql = new StringBuilder();
            //strSql.Append("delete from T_Cus_CustomerBase ");
            strSql.Append("update T_Cus_CustomerBase set F_DeleteFlag=1");
            strSql.Append(" where F_Mobile=@F_Mobile");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,100)
            };
            parameters[0].Value = F_Mobile;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        #endregion  BasicMethod
        #region  ExtensionMethod
        /// <summary>
        /// 20180509
        /// zhengbingbing
        /// 根据号码获取客户信息
        /// </summary>
        public Model.T_Cus_CustomerBase GetModelByTel(string tel)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select top 1 * from T_Cus_CustomerBase ");
            strSql.Append(" where  F_Telephone = '" + tel + "' or F_Mobile = '" + tel + "' and F_DeleteFlag=0 order by F_CreatedOn desc");
            
            Model.T_Cus_CustomerBase model = new Model.T_Cus_CustomerBase();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
        #endregion  ExtensionMethod
    }
}
