DS7/DSWeb/EntityDA/CRMClientQuotationDA.cs

874 lines
50 KiB
C#

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
using DSWeb.Models;
using WebSqlHelper;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
namespace DSWeb.EntityDA
{
public class CRMClientQuotationDA
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(CRMClientQuotationEntity model)
{
string strSql = "insert into crm_quotation(";
strSql += "GID,LANE,CARRIER,{2}ENTREPORT,TT,GOODSNAME,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,CLIENTGID,MODIFIEDTIME,SHORTNAME,DESCRIPTION,SALE,{0}CORPID,PORTLOAD,PORTDISCHARGE,CONTACTNAME,{4}WEEK";
strSql += ") values (";
strSql += "@GID,@LANE,@CARRIER,{3}@ENTREPORT,@TT,@GOODSNAME,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,@CLIENTGID,getdate(),@SHORTNAME,@DESCRIPTION,@SALE,{1}@CORPID,@PORTLOAD,@PORTDISCHARGE,@CONTACTNAME,{5}@WEEK";
strSql += ") ";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) ,
new SqlParameter("@LANE", SqlDbType.VarChar,30) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@ENTREPORT", SqlDbType.VarChar,60) ,
new SqlParameter("@TT", SqlDbType.VarChar,50) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@DESCRIPTION", SqlDbType.VarChar,50) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
//new SqlParameter("@QUOTATIONDATE", SqlDbType.DateTime) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20),
new SqlParameter("@WEEK", SqlDbType.VarChar,10)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.LANE;
parameters[2].Value = model.CARRIER;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.ENTREPORT;
parameters[4].Value = model.TT;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.REMARK;
parameters[7].Value = model.CREATEUSER;
//parameters[9].Value = model.CREATETIME;
parameters[8].Value = model.MODIFIEDUSER;
parameters[9].Value = model.CLIENTGID;
//parameters[12].Value = model.MODIFIEDTIME;
parameters[10].Value = model.SHORTNAME;
parameters[11].Value = model.DESCRIPTION;
parameters[12].Value = model.SALE;
//parameters[16].Value = model.QUOTATIONDATE;
parameters[13].Value = model.CORPID;
parameters[14].Value = model.PORTLOAD;
parameters[15].Value = model.PORTDISCHARGE;
parameters[16].Value = model.CONTACTNAME;
parameters[17].Value = model.WEEK;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ETD.ToString() + "',";
string strETD_name = strETD.Equals("") ? "" : "ETD,";
string strQUOTATIONDATE = model.QUOTATIONDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.QUOTATIONDATE.ToString() + "',";
string strQUOTATIONDATE_name = strQUOTATIONDATE.Equals("") ? "" : "QUOTATIONDATE,";
string strVALIDDATE = model.VALIDDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.VALIDDATE.ToString() + "',";
string strVALIDDATE_name = strVALIDDATE.Equals("") ? "" : "VALIDDATE,";
strSql = String.Format(strSql, strETD_name, strETD, strQUOTATIONDATE_name, strQUOTATIONDATE, strVALIDDATE_name, strVALIDDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 增加一条数据
/// </summary>
public int AddAll(CRMClientQuotationEntity model, IList<CRMClientQuotationDetailEntity> feeEntities, IList<CRMClientQuotationDetailEntity> feeEntities2)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strSql = "insert into crm_quotation(";
strSql += "GID,LANE,CARRIER,{2}ENTREPORT,TT,GOODSNAME,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,CLIENTGID,MODIFIEDTIME,SHORTNAME,DESCRIPTION,SALE,{0}CORPID,PORTLOAD,PORTDISCHARGE,CONTACTNAME,{4}WEEK";
strSql += ") values (";
strSql += "@GID,@LANE,@CARRIER,{3}@ENTREPORT,@TT,@GOODSNAME,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,@CLIENTGID,getdate(),@SHORTNAME,@DESCRIPTION,@SALE,{1}@CORPID,@PORTLOAD,@PORTDISCHARGE,@CONTACTNAME,{5}@WEEK";
strSql += ") ";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) ,
new SqlParameter("@LANE", SqlDbType.VarChar,30) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@ENTREPORT", SqlDbType.VarChar,60) ,
new SqlParameter("@TT", SqlDbType.VarChar,50) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@DESCRIPTION", SqlDbType.VarChar,50) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
//new SqlParameter("@QUOTATIONDATE", SqlDbType.DateTime) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20),
new SqlParameter("@WEEK", SqlDbType.VarChar,10)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.LANE;
parameters[2].Value = model.CARRIER;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.ENTREPORT;
parameters[4].Value = model.TT;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.REMARK;
parameters[7].Value = model.CREATEUSER;
//parameters[9].Value = model.CREATETIME;
parameters[8].Value = model.MODIFIEDUSER;
parameters[9].Value = model.CLIENTGID;
//parameters[12].Value = model.MODIFIEDTIME;
parameters[10].Value = model.SHORTNAME;
parameters[11].Value = model.DESCRIPTION;
parameters[12].Value = model.SALE;
//parameters[16].Value = model.QUOTATIONDATE;
parameters[13].Value = model.CORPID;
parameters[14].Value = model.PORTLOAD;
parameters[15].Value = model.PORTDISCHARGE;
parameters[16].Value = model.CONTACTNAME;
parameters[17].Value = model.WEEK;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ETD.ToString() + "',";
string strETD_name = strETD.Equals("") ? "" : "ETD,";
string strQUOTATIONDATE = model.QUOTATIONDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.QUOTATIONDATE.ToString() + "',";
string strQUOTATIONDATE_name = strQUOTATIONDATE.Equals("") ? "" : "QUOTATIONDATE,";
string strVALIDDATE = model.VALIDDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.VALIDDATE.ToString() + "',";
string strVALIDDATE_name = strVALIDDATE.Equals("") ? "" : "VALIDDATE,";
strSql = String.Format(strSql, strETD_name, strETD, strQUOTATIONDATE_name, strQUOTATIONDATE, strVALIDDATE_name, strVALIDDATE);
iResult = -2;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, parameters);
//
foreach (CRMClientQuotationDetailEntity feeEntity1 in feeEntities)
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into crm_quotation_detail(");
strSql1.Append("GID,LINKGID,FEETYPE,FEENAME,UNIT,UNITPRICE,CURRENCY,CARRIER,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql1.Append(") values (");
strSql1.Append("@GID,@LINKGID,@FEETYPE,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@CARRIER,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql1.Append(") ");
SqlParameter[] parameters1 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters1[0].Value = feeEntity1.GID;
parameters1[1].Value = feeEntity1.LINKGID;
parameters1[2].Value = feeEntity1.FEETYPE;
parameters1[3].Value = feeEntity1.FEENAME;
parameters1[4].Value = feeEntity1.UNIT;
parameters1[5].Value = feeEntity1.UNITPRICE;
parameters1[6].Value = feeEntity1.CURRENCY;
parameters1[7].Value = feeEntity1.CARRIER;
parameters1[8].Value = feeEntity1.REMARK;
parameters1[9].Value = feeEntity1.CREATEUSER;
parameters1[10].Value = feeEntity1.MODIFIEDUSER;
//
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql1.ToString(), parameters1);
}
//
foreach (CRMClientQuotationDetailEntity feeEntity2 in feeEntities2)
{
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("insert into crm_quotation_detail(");
strSql2.Append("GID,LINKGID,FEETYPE,FEENAME,UNIT,UNITPRICE,CURRENCY,CARRIER,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql2.Append(") values (");
strSql2.Append("@GID,@LINKGID,@FEETYPE,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@CARRIER,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql2.Append(") ");
SqlParameter[] parameters2 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters2[0].Value = feeEntity2.GID;
parameters2[1].Value = feeEntity2.LINKGID;
parameters2[2].Value = feeEntity2.FEETYPE;
parameters2[3].Value = feeEntity2.FEENAME;
parameters2[4].Value = feeEntity2.UNIT;
parameters2[5].Value = feeEntity2.UNITPRICE;
parameters2[6].Value = feeEntity2.CURRENCY;
parameters2[7].Value = feeEntity2.CARRIER;
parameters2[8].Value = feeEntity2.REMARK;
parameters2[9].Value = feeEntity2.CREATEUSER;
parameters2[10].Value = feeEntity2.MODIFIEDUSER;
//
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters2);
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(CRMClientQuotationEntity model)
{
string strSql = "update crm_quotation set ";
//strSql += " GID = @GID , ";
strSql += " LANE = @LANE , ";
strSql += " CARRIER = @CARRIER , ";
strSql += " {0}{1} ";
strSql += " ENTREPORT = @ENTREPORT , ";
strSql += " TT = @TT , ";
strSql += " GOODSNAME = @GOODSNAME , ";
strSql += " REMARK = @REMARK , ";
//strSql += " CREATEUSER = @CREATEUSER , ";
//strSql += " CREATETIME = @CREATETIME , ";
strSql += " MODIFIEDUSER = @MODIFIEDUSER , ";
strSql += " CLIENTGID = @CLIENTGID , ";
strSql += " MODIFIEDTIME = getdate() , ";
strSql += " SHORTNAME = @SHORTNAME , ";
strSql += " DESCRIPTION = @DESCRIPTION , ";
strSql += " CONTACTNAME = @CONTACTNAME , ";
strSql += " SALE = @SALE , ";
strSql += " {2}{3} ";
strSql += " CORPID = @CORPID , ";
strSql += " PORTLOAD = @PORTLOAD , ";
strSql += " PORTDISCHARGE = @PORTDISCHARGE , ";
strSql += " {4}{5} ";
strSql += " WEEK = @WEEK ";
strSql += " where GID=@GID";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) ,
new SqlParameter("@LANE", SqlDbType.VarChar,30) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@ENTREPORT", SqlDbType.VarChar,60) ,
new SqlParameter("@TT", SqlDbType.VarChar,50) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
//new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@DESCRIPTION", SqlDbType.VarChar,50) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
//new SqlParameter("@QUOTATIONDATE", SqlDbType.DateTime) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@WEEK", SqlDbType.VarChar,10)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.LANE;
parameters[2].Value = model.CARRIER;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.ENTREPORT;
parameters[4].Value = model.TT;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.REMARK;
//parameters[8].Value = model.CREATEUSER;
//parameters[9].Value = model.CREATETIME;
parameters[7].Value = model.MODIFIEDUSER;
parameters[8].Value = model.CLIENTGID;
//parameters[12].Value = model.MODIFIEDTIME;
parameters[9].Value = model.SHORTNAME;
parameters[10].Value = model.DESCRIPTION;
parameters[11].Value = model.SALE;
//parameters[13].Value = model.QUOTATIONDATE;
parameters[12].Value = model.CORPID;
parameters[13].Value = model.PORTLOAD;
parameters[14].Value = model.PORTDISCHARGE;
parameters[15].Value = model.CONTACTNAME;
parameters[16].Value = model.WEEK;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.ETD.ToString() + "',";
string strETD_name = "ETD=";
string strQUOTATIONDATE = model.QUOTATIONDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.QUOTATIONDATE.ToString() + "',";
string strQUOTATIONDATE_name = "QUOTATIONDATE=";
string strVALIDDATE = model.VALIDDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.VALIDDATE.ToString() + "',";
string strVALIDDATE_name = "VALIDDATE=";
strSql = String.Format(strSql, strETD_name, strETD, strQUOTATIONDATE_name, strQUOTATIONDATE, strVALIDDATE_name, strVALIDDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int UpdateAll(CRMClientQuotationEntity model, IList<CRMClientQuotationDetailEntity> feeEntities, IList<CRMClientQuotationDetailEntity> feeEntities2)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strSql = "update crm_quotation set ";
//strSql += " GID = @GID , ";
strSql += " LANE = @LANE , ";
strSql += " CARRIER = @CARRIER , ";
strSql += " {0}{1} ";
strSql += " ENTREPORT = @ENTREPORT , ";
strSql += " TT = @TT , ";
strSql += " GOODSNAME = @GOODSNAME , ";
strSql += " REMARK = @REMARK , ";
//strSql += " CREATEUSER = @CREATEUSER , ";
//strSql += " CREATETIME = @CREATETIME , ";
strSql += " MODIFIEDUSER = @MODIFIEDUSER , ";
strSql += " CLIENTGID = @CLIENTGID , ";
strSql += " MODIFIEDTIME = getdate() , ";
strSql += " SHORTNAME = @SHORTNAME , ";
strSql += " DESCRIPTION = @DESCRIPTION , ";
strSql += " CONTACTNAME = @CONTACTNAME , ";
strSql += " SALE = @SALE , ";
strSql += " {2}{3} ";
strSql += " CORPID = @CORPID , ";
strSql += " PORTLOAD = @PORTLOAD , ";
strSql += " PORTDISCHARGE = @PORTDISCHARGE , ";
strSql += " {4}{5} ";
strSql += " WEEK = @WEEK ";
strSql += " where GID=@GID";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) ,
new SqlParameter("@LANE", SqlDbType.VarChar,30) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@ENTREPORT", SqlDbType.VarChar,60) ,
new SqlParameter("@TT", SqlDbType.VarChar,50) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
//new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@DESCRIPTION", SqlDbType.VarChar,50) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
//new SqlParameter("@QUOTATIONDATE", SqlDbType.DateTime) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@WEEK", SqlDbType.VarChar,10)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.LANE;
parameters[2].Value = model.CARRIER;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.ENTREPORT;
parameters[4].Value = model.TT;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.REMARK;
//parameters[8].Value = model.CREATEUSER;
//parameters[9].Value = model.CREATETIME;
parameters[7].Value = model.MODIFIEDUSER;
parameters[8].Value = model.CLIENTGID;
//parameters[12].Value = model.MODIFIEDTIME;
parameters[9].Value = model.SHORTNAME;
parameters[10].Value = model.DESCRIPTION;
parameters[11].Value = model.SALE;
//parameters[13].Value = model.QUOTATIONDATE;
parameters[12].Value = model.CORPID;
parameters[13].Value = model.PORTLOAD;
parameters[14].Value = model.PORTDISCHARGE;
parameters[15].Value = model.CONTACTNAME;
parameters[16].Value = model.WEEK;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.ETD.ToString() + "',";
string strETD_name = "ETD=";//strETD.Equals("") ? "" : "ETD=";
string strQUOTATIONDATE = model.QUOTATIONDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.QUOTATIONDATE.ToString() + "',";
string strQUOTATIONDATE_name = "QUOTATIONDATE="; //strETA.Equals("") ? "" : "ETA=";
string strVALIDDATE = model.VALIDDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.VALIDDATE.ToString() + "',";
string strVALIDDATE_name = "VALIDDATE=";//strETD.Equals("") ? "" : "ETD=";
strSql = String.Format(strSql, strETD_name, strETD, strQUOTATIONDATE_name, strQUOTATIONDATE, strVALIDDATE_name, strVALIDDATE);
iResult = -2;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, parameters);
//
T_ALL_DA T_ALL_DA = new T_ALL_DA();
foreach (CRMClientQuotationDetailEntity feeEntity1 in feeEntities)
{
string ls = "";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "select gid from crm_quotation_detail where gid='"+feeEntity1.GID.ToString().Trim()+"'", null);
if (statusObj == null)
{
ls = "";
}
else
{
ls = statusObj.ToString().Trim();
}
if (ls.Trim() == "")
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("insert into crm_quotation_detail(");
strSql1.Append("GID,LINKGID,FEETYPE,FEENAME,UNIT,UNITPRICE,CURRENCY,CARRIER,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql1.Append(") values (");
strSql1.Append("@GID,@LINKGID,@FEETYPE,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@CARRIER,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql1.Append(") ");
SqlParameter[] parameters1 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters1[0].Value = feeEntity1.GID;
parameters1[1].Value = feeEntity1.LINKGID;
parameters1[2].Value = feeEntity1.FEETYPE;
parameters1[3].Value = feeEntity1.FEENAME;
parameters1[4].Value = feeEntity1.UNIT;
parameters1[5].Value = feeEntity1.UNITPRICE;
parameters1[6].Value = feeEntity1.CURRENCY;
parameters1[7].Value = feeEntity1.CARRIER;
parameters1[8].Value = feeEntity1.REMARK;
parameters1[9].Value = feeEntity1.CREATEUSER;
parameters1[10].Value = feeEntity1.MODIFIEDUSER;
//
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql1.ToString(), parameters1);
}
else
{
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("update crm_quotation_detail set ");
strSql1.Append(" LINKGID = @LINKGID , ");
strSql1.Append(" FEETYPE = @FEETYPE , ");
strSql1.Append(" FEENAME = @FEENAME , ");
strSql1.Append(" UNIT = @UNIT , ");
strSql1.Append(" UNITPRICE = @UNITPRICE , ");
strSql1.Append(" CURRENCY = @CURRENCY , ");
strSql1.Append(" CARRIER = @CARRIER , ");
strSql1.Append(" REMARK = @REMARK , ");
strSql1.Append(" MODIFIEDUSER = @MODIFIEDUSER , ");
strSql1.Append(" MODIFIEDTIME = getdate() ");
strSql1.Append(" where GID=@GID");
SqlParameter[] parameters1 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters1[0].Value = feeEntity1.GID;
parameters1[1].Value = feeEntity1.LINKGID;
parameters1[2].Value = feeEntity1.FEETYPE;
parameters1[3].Value = feeEntity1.FEENAME;
parameters1[4].Value = feeEntity1.UNIT;
parameters1[5].Value = feeEntity1.UNITPRICE;
parameters1[6].Value = feeEntity1.CURRENCY;
parameters1[7].Value = feeEntity1.CARRIER;
parameters1[8].Value = feeEntity1.REMARK;
parameters1[9].Value = feeEntity1.MODIFIEDUSER;
//
iResult = -5;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql1.ToString(), parameters1);
}
}
//
foreach (CRMClientQuotationDetailEntity feeEntity2 in feeEntities2)
{
string ls2 = "";
object statusObj2 = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, "select gid from crm_quotation_detail where gid='" + feeEntity2.GID.ToString().Trim() + "'", null);
if (statusObj2 == null)
{
ls2 = "";
}
else
{
ls2 = statusObj2.ToString().Trim();
}
if (ls2.Trim() == "")
{
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("insert into crm_quotation_detail(");
strSql2.Append("GID,LINKGID,FEETYPE,FEENAME,UNIT,UNITPRICE,CURRENCY,CARRIER,REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME");
strSql2.Append(") values (");
strSql2.Append("@GID,@LINKGID,@FEETYPE,@FEENAME,@UNIT,@UNITPRICE,@CURRENCY,@CARRIER,@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate()");
strSql2.Append(") ");
SqlParameter[] parameters2 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters2[0].Value = feeEntity2.GID;
parameters2[1].Value = feeEntity2.LINKGID;
parameters2[2].Value = feeEntity2.FEETYPE;
parameters2[3].Value = feeEntity2.FEENAME;
parameters2[4].Value = feeEntity2.UNIT;
parameters2[5].Value = feeEntity2.UNITPRICE;
parameters2[6].Value = feeEntity2.CURRENCY;
parameters2[7].Value = feeEntity2.CARRIER;
parameters2[8].Value = feeEntity2.REMARK;
parameters2[9].Value = feeEntity2.CREATEUSER;
parameters2[10].Value = feeEntity2.MODIFIEDUSER;
//
iResult = -4;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters2);
}
else
{
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("update crm_quotation_detail set ");
strSql2.Append(" LINKGID = @LINKGID , ");
strSql2.Append(" FEETYPE = @FEETYPE , ");
strSql2.Append(" FEENAME = @FEENAME , ");
strSql2.Append(" UNIT = @UNIT , ");
strSql2.Append(" UNITPRICE = @UNITPRICE , ");
strSql2.Append(" CURRENCY = @CURRENCY , ");
strSql2.Append(" CARRIER = @CARRIER , ");
strSql2.Append(" REMARK = @REMARK , ");
strSql2.Append(" MODIFIEDUSER = @MODIFIEDUSER , ");
strSql2.Append(" MODIFIEDTIME = getdate() ");
strSql2.Append(" where GID=@GID");
SqlParameter[] parameters2 = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FEETYPE", SqlDbType.VarChar,50) ,
new SqlParameter("@FEENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@UNIT", SqlDbType.VarChar,20) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CARRIER", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,200) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36)
};
parameters2[0].Value = feeEntity2.GID;
parameters2[1].Value = feeEntity2.LINKGID;
parameters2[2].Value = feeEntity2.FEETYPE;
parameters2[3].Value = feeEntity2.FEENAME;
parameters2[4].Value = feeEntity2.UNIT;
parameters2[5].Value = feeEntity2.UNITPRICE;
parameters2[6].Value = feeEntity2.CURRENCY;
parameters2[7].Value = feeEntity2.CARRIER;
parameters2[8].Value = feeEntity2.REMARK;
parameters2[9].Value = feeEntity2.MODIFIEDUSER;
//
iResult = -6;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2.ToString(), parameters2);
}
}
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from crm_quotation ");
strSql.Append(" where GID=@GID");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100) };
parameters[0].Value = GID;
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 删除多条数据
/// </summary>
public int Deletes(string sGID)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
string strSql="delete from crm_quotation_detail where LINKGID in (" + sGID + ")";
string strSql2="delete from crm_quotation where GID in (" + sGID + ")";
iResult = -2;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql, null);
iResult = -3;//
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql2, null);
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public CRMClientQuotationEntity GetModel(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, LANE, CARRIER, convert(char(10),ETD,20) ETD, ENTREPORT, TT, GOODSNAME, REMARK, CREATEUSER, CREATETIME, MODIFIEDUSER, CLIENTGID, MODIFIEDTIME, SHORTNAME, DESCRIPTION, SALE, convert(char(10),QUOTATIONDATE,20) QUOTATIONDATE, CORPID, PORTLOAD, PORTDISCHARGE,CONTACTNAME,VALIDDATE,WEEK ");
strSql.Append(" from crm_quotation ");
strSql.Append(" where GID=@GID");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,100)};
parameters[0].Value = GID;
CRMClientQuotationEntity model = new CRMClientQuotationEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
model.GID = ds.Tables[0].Rows[0]["GID"].ToString();
model.LANE = ds.Tables[0].Rows[0]["LANE"].ToString();
model.CARRIER = ds.Tables[0].Rows[0]["CARRIER"].ToString();
if (ds.Tables[0].Rows[0]["ETD"].ToString() != "")
{
model.ETD = DateTime.Parse(ds.Tables[0].Rows[0]["ETD"].ToString());
}
model.ENTREPORT = ds.Tables[0].Rows[0]["ENTREPORT"].ToString();
model.TT = ds.Tables[0].Rows[0]["TT"].ToString();
model.GOODSNAME = ds.Tables[0].Rows[0]["GOODSNAME"].ToString();
model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
model.CREATEUSER = ds.Tables[0].Rows[0]["CREATEUSER"].ToString();
if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
}
model.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString();
model.CLIENTGID = ds.Tables[0].Rows[0]["CLIENTGID"].ToString();
if (ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString());
}
model.SHORTNAME = ds.Tables[0].Rows[0]["SHORTNAME"].ToString();
model.DESCRIPTION = ds.Tables[0].Rows[0]["DESCRIPTION"].ToString();
model.CONTACTNAME = ds.Tables[0].Rows[0]["CONTACTNAME"].ToString();
model.SALE = ds.Tables[0].Rows[0]["SALE"].ToString();
if (ds.Tables[0].Rows[0]["QUOTATIONDATE"].ToString() != "")
{
model.QUOTATIONDATE = DateTime.Parse(ds.Tables[0].Rows[0]["QUOTATIONDATE"].ToString());
}
model.CORPID = ds.Tables[0].Rows[0]["CORPID"].ToString();
model.PORTLOAD = ds.Tables[0].Rows[0]["PORTLOAD"].ToString();
model.PORTDISCHARGE = ds.Tables[0].Rows[0]["PORTDISCHARGE"].ToString();
model.WEEK = ds.Tables[0].Rows[0]["WEEK"].ToString();
if (ds.Tables[0].Rows[0]["VALIDDATE"].ToString() != "")
{
model.VALIDDATE = DateTime.Parse(ds.Tables[0].Rows[0]["VALIDDATE"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM crm_quotation ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
DataSet DS = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
}
}