using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using WebSqlHelper;
namespace DSWeb.EntityDA
{
public class CRMClientDA
{
private const string PARM_CRMCLIENT_GID = "@gid";
private const string SQL_SELECT_CRMCLIENT_ALL = " SELECT GID, CODENAME, SHORTNAME, NAME, DESCRIPTION, STATUS, ADDR, EMAIL, WEB, TEL, FAX, CHIEF, SALE, OP, ISCARRIER, ISBOOKING, ISYARD, "
+ " ISTRUCK, ISCONTROLLER, ISCUSTOM, ISAGENT, ISAIRLINES, ISSHIPPER, ISCONSIGNEE, ISNOTIFYPARTY, ISWAREHOUSE, COUNTRY, PROVINCE, "
+ " CITY, CORPID, BLCONTENT FROM info_client ";
private const string SQL_SELECT_CRMCLIENT_LIST = " SELECT CODENAME,SHORTNAME FROM info_client ORDER BY CODENAME ASC";
private const string SQL_SELECT_CRMCLIENT_BY_GID = " SELECT GID, CODENAME, SHORTNAME, DESCRIPTION, NAME, EnFullName, STATUS, ADDR, EMAIL, WEB, TEL, FAX, CHIEF, SALE, OP, DOC, ISCARRIER, ISBOOKING, ISYARD, ISTRUCK, ISCONTROLLER, ISCUSTOM, ISAGENT, ISAGENTCN, ISEXPRESS, ISAIRLINES, ISSHIPPER, ISCONSIGNEE, ISNOTIFYPARTY, ISWAREHOUSE, COUNTRY, PROVINCE, CITY, CORPID, BLCONTENT, ISSTOP, BillRises1, BillRises2, USDBillRises, RMBBillRises, RMBBank, RMBAccount, RMBOnlineNO, USDBank, USDAccount, USDOnlineNO, CustomAttributes1, CustomAttributes2,FARCODE, USDMaxAmountCredit, RMBMaxAmountCredit, MaxAmountCredit, STLNAME, OPNAME, OPTIME, REMARK, USDExchangeRate, STLDATE,STLFIRSTHALFDATE, STLMIDDLEDATE, STLDATEPJ, [LEVEL], LOGINNAME, LOGINPASSWORD,FAPCODE FROM info_client WHERE GID = @gid ";
private const string SQL_DELETE_CRMClient_BY_GID = "DELETE FROM info_client WHERE gid = @gid";
#region 根据往来单位GID获取往来单位信息
///
/// 根据往来单位GID获取往来单位信息
///
/// 往来单位GID
/// 返回往来单位实体类
public CRMClientEntity GetCrmClientInfoByGID(string tempCrmClientGID)
{
CRMClientEntity crmClientEntity = null;
SqlParameter parm = new SqlParameter(PARM_CRMCLIENT_GID, SqlDbType.VarChar, 36);
parm.Value = tempCrmClientGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CRMCLIENT_BY_GID, parm))
{
try
{
while (sqlRead.Read())
{
crmClientEntity = new CRMClientEntity();
if (!sqlRead.IsDBNull(0))
{
crmClientEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
crmClientEntity.CodeName = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
crmClientEntity.ShortName = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
crmClientEntity.Description = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
crmClientEntity.Name = sqlRead.GetString(4);
}
if (!sqlRead.IsDBNull(5))
{
crmClientEntity.EnFullName = sqlRead.GetString(5);
}
if (!sqlRead.IsDBNull(6))
{
crmClientEntity.Status = sqlRead.GetInt32(6);
}
if (!sqlRead.IsDBNull(7))
{
crmClientEntity.Address = sqlRead.GetString(7);
}
if (!sqlRead.IsDBNull(8))
{
crmClientEntity.Email = sqlRead.GetString(8);
}
if (!sqlRead.IsDBNull(9))
{
crmClientEntity.WebUrl = sqlRead.GetString(9);
}
if (!sqlRead.IsDBNull(10))
{
crmClientEntity.TelNumber = sqlRead.GetString(10);
}
if (!sqlRead.IsDBNull(11))
{
crmClientEntity.Fax = sqlRead.GetString(11);
}
if (!sqlRead.IsDBNull(12))
{
crmClientEntity.Chief = sqlRead.GetString(12);
}
if (!sqlRead.IsDBNull(13))
{
crmClientEntity.Sale = sqlRead.GetString(13);
}
if (!sqlRead.IsDBNull(14))
{
crmClientEntity.OP = sqlRead.GetString(14);
}
if (!sqlRead.IsDBNull(15))
{
crmClientEntity.Doc = sqlRead.GetString(15);
}
if (!sqlRead.IsDBNull(16))
{
crmClientEntity.IsCarrier = sqlRead.GetBoolean(16);
}
if (!sqlRead.IsDBNull(17))
{
crmClientEntity.IsBooking = sqlRead.GetBoolean(17);
}
if (!sqlRead.IsDBNull(18))
{
crmClientEntity.IsYard = sqlRead.GetBoolean(18);
}
if (!sqlRead.IsDBNull(19))
{
crmClientEntity.IsTruck = sqlRead.GetBoolean(19);
}
if (!sqlRead.IsDBNull(20))
{
crmClientEntity.IsController = sqlRead.GetBoolean(20);
}
if (!sqlRead.IsDBNull(21))
{
crmClientEntity.IsCustom = sqlRead.GetBoolean(21);
}
if (!sqlRead.IsDBNull(22))
{
crmClientEntity.IsAgent = sqlRead.GetBoolean(22);
}
if (!sqlRead.IsDBNull(23))
{
crmClientEntity.IsAgentCN = sqlRead.GetBoolean(23);
}
if (!sqlRead.IsDBNull(24))
{
crmClientEntity.IsExpress = sqlRead.GetBoolean(24);
}
if (!sqlRead.IsDBNull(25))
{
crmClientEntity.IsAirLines = sqlRead.GetBoolean(25);
}
if (!sqlRead.IsDBNull(26))
{
crmClientEntity.IsShipper = sqlRead.GetBoolean(26);
}
if (!sqlRead.IsDBNull(27))
{
crmClientEntity.IsConsignee = sqlRead.GetBoolean(27);
}
if (!sqlRead.IsDBNull(28))
{
crmClientEntity.IsNotifyParty = sqlRead.GetBoolean(28);
}
if (!sqlRead.IsDBNull(29))
{
crmClientEntity.IsWarehouse = sqlRead.GetBoolean(29);
}
if (!sqlRead.IsDBNull(30))
{
crmClientEntity.Country = sqlRead.GetString(30);
}
if (!sqlRead.IsDBNull(31))
{
crmClientEntity.Province = sqlRead.GetString(31);
}
if (!sqlRead.IsDBNull(32))
{
crmClientEntity.City = sqlRead.GetString(32);
}
if (!sqlRead.IsDBNull(33))
{
crmClientEntity.CORPID = sqlRead.GetString(33);
}
if (!sqlRead.IsDBNull(34))
{
crmClientEntity.Blcontent = sqlRead.GetString(34);
}
if (!sqlRead.IsDBNull(35))
{
crmClientEntity.IsStop = sqlRead.GetBoolean(35);
}
if (!sqlRead.IsDBNull(36))
{
crmClientEntity.BillRises1 = sqlRead.GetString(36);
}
if (!sqlRead.IsDBNull(37))
{
crmClientEntity.BillRises2 = sqlRead.GetString(37);
}
if (!sqlRead.IsDBNull(38))
{
crmClientEntity.USDBillRises = sqlRead.GetString(38);
}
if (!sqlRead.IsDBNull(39))
{
crmClientEntity.RMBBillRises = sqlRead.GetString(39);
}
if (!sqlRead.IsDBNull(40))
{
crmClientEntity.RMBBank = sqlRead.GetString(40);
}
if (!sqlRead.IsDBNull(41))
{
crmClientEntity.RMBAccount = sqlRead.GetString(41);
}
if (!sqlRead.IsDBNull(42))
{
crmClientEntity.RMBOnLineNO = sqlRead.GetString(42);
}
if (!sqlRead.IsDBNull(43))
{
crmClientEntity.USDBank = sqlRead.GetString(43);
}
if (!sqlRead.IsDBNull(44))
{
crmClientEntity.USDAccount = sqlRead.GetString(44);
}
if (!sqlRead.IsDBNull(45))
{
crmClientEntity.USDOnLineNO = sqlRead.GetString(45);
}
if (!sqlRead.IsDBNull(46))
{
crmClientEntity.CustomAttributes1 = sqlRead.GetString(46);
}
if (!sqlRead.IsDBNull(47))
{
crmClientEntity.CustomAttributes2 = sqlRead.GetString(47);
}
if (!sqlRead.IsDBNull(48))
{
crmClientEntity.FARCODE = sqlRead.GetString(48);
}
if (!sqlRead.IsDBNull(49))
{
crmClientEntity.USDMaxAmountCredit = sqlRead.GetDecimal(49);
}
if (!sqlRead.IsDBNull(50))
{
crmClientEntity.RMBMaxAmountCredit = sqlRead.GetDecimal(50);
}
if (!sqlRead.IsDBNull(51))
{
crmClientEntity.MaxAmountCredit = sqlRead.GetDecimal(51);
}
if (!sqlRead.IsDBNull(52))
{
crmClientEntity.StlName = sqlRead.GetString(52);
}
if (!sqlRead.IsDBNull(53))
{
crmClientEntity.OpName = sqlRead.GetString(53);
}
if (!sqlRead.IsDBNull(54))
{
crmClientEntity.OpTime = sqlRead.GetDateTime(54);
}
if (!sqlRead.IsDBNull(55))
{
crmClientEntity.Remark = sqlRead.GetString(55);
}
if (!sqlRead.IsDBNull(56))
{
crmClientEntity.USDExchangeRate = sqlRead.GetDecimal(56);
}
if (!sqlRead.IsDBNull(57))
{
crmClientEntity.StlDate = sqlRead.GetString(57);
}
if (!sqlRead.IsDBNull(58))
{
crmClientEntity.StlFirstHalfDate = sqlRead.GetString(58);
}
if (!sqlRead.IsDBNull(59))
{
crmClientEntity.StlMiddleDate = sqlRead.GetString(59);
}
if (!sqlRead.IsDBNull(60))
{
crmClientEntity.StlDatePJ = sqlRead.GetString(60);
}
if (!sqlRead.IsDBNull(61))
{
crmClientEntity.Level = sqlRead.GetString(61);
}
if (!sqlRead.IsDBNull(62))
{
crmClientEntity.LoginName = sqlRead.GetString(62);
}
if (!sqlRead.IsDBNull(63))
{
crmClientEntity.LoginPassWord = sqlRead.GetString(63);
}
if (!sqlRead.IsDBNull(64))
{
crmClientEntity.FAPCODE = sqlRead.GetString(64);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return crmClientEntity;
}
#endregion
#region 返回所有CRM系统客户信息数据集
///
/// 返回所有CRM系统客户信息数据集
///
///
///
public DataSet GetCRMClientListAll()
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CRMCLIENT_ALL);
return userSet;
}
#endregion
#region 返回所有CRM系统客户信息数据集用于绑定select
///
/// 返回所有CRM系统客户信息数据集用于绑定select
///
///
///
public DataSet GetCRMClientList()
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CRMCLIENT_LIST);
return userSet;
}
#endregion
#region 根据SQL语句查询数据集
///
/// 根据SQL语句查询数据集
///
///
///
public DataSet GetExcuteSql(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
#region 更新账户列表信息
///
/// 更新账户列表信息
///
/// 更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作
/// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0
public int UpdateCRMClientFromGrid(ArrayList sqlList)
{
int result = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
for (int i = 0; i < sqlList.Count; i++)
{
string strUpdateSql = sqlList[i].ToString();
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strUpdateSql, null);
}
sqlTran.Commit();
result = 1;//状态为1表示更新成功
}
catch (Exception execError)
{
result = -1;//有异常,更新失败
sqlTran.Rollback();
result = -2;//更新异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
#region 通过账户GID删除单条账户
public int DeleteCRMClientByGid(string tempGid)
{
int result = 0;
SqlParameter parm = new SqlParameter(PARM_CRMCLIENT_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_CRMClient_BY_GID, parm);
result = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
result = -1;//有异常,插入失败
sqlTran.Rollback();
result = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
#endregion
}
}