You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/EntityDA/OpApplyDA.cs

357 lines
20 KiB
C#

2 years ago
using System;
using System.Data;
using System.Text;
using System.Configuration;
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 DSWeb.Models;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using WebSqlHelper;
using System.Linq;
using System.Xml.Linq;
namespace DSWeb.EntityDA
{
public class OpApplyDA
{
public OpApplyDA()
{
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(OpApplyEntity model)
{
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@STORAGENAMENEW", SqlDbType.VarChar,100) ,
new SqlParameter("@PKGS", SqlDbType.Int,4) ,
new SqlParameter("@KGS", SqlDbType.Decimal,9) ,
new SqlParameter("@NETWEIGHT", SqlDbType.Decimal,9) ,
new SqlParameter("@UNITOFWEIGHT", SqlDbType.VarChar,10) ,
new SqlParameter("@CBM", SqlDbType.Decimal,9) ,
new SqlParameter("@IMPORTVALUE", SqlDbType.Decimal,9) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CUSTOMSER", SqlDbType.VarChar,20) ,
new SqlParameter("@BSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CUSTOMNO", SqlDbType.VarChar,1024) ,
//new SqlParameter("@UPDATETIME", SqlDbType.DateTime) ,
//new SqlParameter("@CUSTOMDATE", SqlDbType.DateTime) ,
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("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@CUSTNO", SqlDbType.VarChar,30) ,
//new SqlParameter("@BSDATE", SqlDbType.DateTime) ,
new SqlParameter("@INSPECTIONNO", SqlDbType.VarChar,20) ,
new SqlParameter("@CUSTOMTYPE", SqlDbType.VarChar,10) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@CLIENTNAMEOLD", SqlDbType.VarChar,20) ,
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@ACCDATE", SqlDbType.VarChar,7)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.STORAGENAMENEW;
parameters[2].Value = model.PKGS;
parameters[3].Value = model.KGS;
parameters[4].Value = model.NETWEIGHT;
parameters[5].Value = model.UNITOFWEIGHT;
parameters[6].Value = model.CBM;
parameters[7].Value = model.IMPORTVALUE;
parameters[8].Value = model.UNITPRICE;
parameters[9].Value = model.CURRENCY;
parameters[10].Value = model.CUSTOMSER;
parameters[11].Value = model.BSNO;
parameters[12].Value = model.CUSTOMNO;
//parameters[13].Value = model.UPDATETIME;
//parameters[14].Value = model.CUSTOMDATE;
parameters[13].Value = model.REMARK;
parameters[14].Value = model.CREATEUSER;
//parameters[17].Value = model.CREATETIME;
parameters[15].Value = model.MODIFIEDUSER;
//parameters[19].Value = model.MODIFIEDTIME;
parameters[16].Value = model.CUSTNO;
//parameters[21].Value = model.BSDATE;
parameters[17].Value = model.INSPECTIONNO;
parameters[18].Value = model.CUSTOMTYPE;
parameters[19].Value = model.CUSTOMERNAME;
parameters[20].Value = model.CLIENTNAMEOLD;
parameters[21].Value = model.STORAGENAME;
parameters[22].Value = model.ACCDATE;
//
string strUPDATETIME = model.UPDATETIME.ToString().IndexOf("0001") > -1 ? "" : "'" + model.UPDATETIME.ToString() + "',";
string strUPDATETIME_name = strUPDATETIME.Equals("") ? "" : "UPDATETIME,";
string strCUSTOMDATE = model.CUSTOMDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.CUSTOMDATE.ToString() + "',";
string strCUSTOMDATE_name = strCUSTOMDATE.Equals("") ? "" : "CUSTOMDATE,";
string strBSDATE = model.BSDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.BSDATE.ToString() + "',";
string strBSDATE_name = strBSDATE.Equals("") ? "" : "BSDATE,";
//
String strSql = String.Format("insert into op_apply(GID,STORAGENAMENEW,PKGS,KGS,NETWEIGHT,UNITOFWEIGHT,CBM,IMPORTVALUE,UNITPRICE,CURRENCY,CUSTOMSER,BSNO,CUSTOMNO,{0}{2}REMARK,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,CUSTNO,{4}INSPECTIONNO,CUSTOMTYPE,CUSTOMERNAME,CLIENTNAMEOLD,STORAGENAME,ACCDATE)"
+ " values (@GID,@STORAGENAMENEW,@PKGS,@KGS,@NETWEIGHT,@UNITOFWEIGHT,@CBM,@IMPORTVALUE,@UNITPRICE,@CURRENCY,@CUSTOMSER,@BSNO,@CUSTOMNO,{1}{3}@REMARK,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),@CUSTNO,{5}@INSPECTIONNO,@CUSTOMTYPE,@CUSTOMERNAME,@CLIENTNAMEOLD,@STORAGENAME,@ACCDATE) ", strUPDATETIME_name, strUPDATETIME, strCUSTOMDATE_name, strCUSTOMDATE, strBSDATE_name, strBSDATE);
//
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('增加信息','增加操作','添加委托编号为“" + model.CUSTNO.ToString() + "”的报关及货转信息','" + model.MODIFIEDUSER.ToString() + "')";
bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(OpApplyEntity model)
{
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@STORAGENAMENEW", SqlDbType.VarChar,100) ,
new SqlParameter("@PKGS", SqlDbType.Int,4) ,
new SqlParameter("@KGS", SqlDbType.Decimal,9) ,
new SqlParameter("@NETWEIGHT", SqlDbType.Decimal,9) ,
new SqlParameter("@UNITOFWEIGHT", SqlDbType.VarChar,10) ,
new SqlParameter("@CBM", SqlDbType.Decimal,9) ,
new SqlParameter("@IMPORTVALUE", SqlDbType.Decimal,9) ,
new SqlParameter("@UNITPRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@CURRENCY", SqlDbType.VarChar,20) ,
new SqlParameter("@CUSTOMSER", SqlDbType.VarChar,20) ,
new SqlParameter("@BSNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CUSTOMNO", SqlDbType.VarChar,1024) ,
//new SqlParameter("@UPDATETIME", SqlDbType.DateTime) ,
//new SqlParameter("@CUSTOMDATE", SqlDbType.DateTime) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
new SqlParameter("@CUSTNO", SqlDbType.VarChar,30) ,
//new SqlParameter("@BSDATE", SqlDbType.DateTime) ,
new SqlParameter("@INSPECTIONNO", SqlDbType.VarChar,20) ,
new SqlParameter("@CUSTOMTYPE", SqlDbType.VarChar,10) ,
new SqlParameter("@CUSTOMERNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@CLIENTNAMEOLD", SqlDbType.VarChar,20) ,
new SqlParameter("@STORAGENAME", SqlDbType.VarChar,100) ,
new SqlParameter("@ACCDATE", SqlDbType.VarChar,7)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.STORAGENAMENEW;
parameters[2].Value = model.PKGS;
parameters[3].Value = model.KGS;
parameters[4].Value = model.NETWEIGHT;
parameters[5].Value = model.UNITOFWEIGHT;
parameters[6].Value = model.CBM;
parameters[7].Value = model.IMPORTVALUE;
parameters[8].Value = model.UNITPRICE;
parameters[9].Value = model.CURRENCY;
parameters[10].Value = model.CUSTOMSER;
parameters[11].Value = model.BSNO;
parameters[12].Value = model.CUSTOMNO;
parameters[13].Value = model.UPDATETIME;
parameters[14].Value = model.CUSTOMDATE;
parameters[15].Value = model.REMARK;
parameters[16].Value = model.CREATEUSER;
parameters[17].Value = model.CREATETIME;
parameters[18].Value = model.MODIFIEDUSER;
parameters[19].Value = model.MODIFIEDTIME;
parameters[20].Value = model.CUSTNO;
parameters[21].Value = model.BSDATE;
parameters[22].Value = model.INSPECTIONNO;
parameters[23].Value = model.CUSTOMTYPE;
parameters[24].Value = model.CUSTOMERNAME;
parameters[25].Value = model.CLIENTNAMEOLD;
parameters[26].Value = model.STORAGENAME;
parameters[27].Value = model.ACCDATE;
//
string strUPDATETIME = model.UPDATETIME.ToString().IndexOf("0001") > -1 ? "" : "UPDATETIME='" + model.UPDATETIME.ToString() + "',";
string strCUSTOMDATE = model.CUSTOMDATE.ToString().IndexOf("0001") > -1 ? "" : "CUSTOMDATE='" + model.CUSTOMDATE.ToString() + "',";
string strBSDATE = model.BSDATE.ToString().IndexOf("0001") > -1 ? "" : "BSDATE='" + model.BSDATE.ToString() + "',";
//
String strSql = String.Format("update op_apply set STORAGENAMENEW = @STORAGENAMENEW, PKGS = @PKGS, KGS = @KGS, NETWEIGHT = @NETWEIGHT, UNITOFWEIGHT = @UNITOFWEIGHT, CBM = @CBM, IMPORTVALUE = @IMPORTVALUE, UNITPRICE = @UNITPRICE, CURRENCY = @CURRENCY, CUSTOMSER = @CUSTOMSER, BSNO = @BSNO, CUSTOMNO = @CUSTOMNO, {0} {1} REMARK = @REMARK, MODIFIEDUSER = @MODIFIEDUSER, MODIFIEDTIME = getdate(), CUSTNO = @CUSTNO, {2} INSPECTIONNO = @INSPECTIONNO, CUSTOMTYPE = @CUSTOMTYPE, CUSTOMERNAME = @CUSTOMERNAME, CLIENTNAMEOLD = @CLIENTNAMEOLD, STORAGENAME = @STORAGENAME, ACCDATE = @ACCDATE where GID=@GID ", strUPDATETIME, strCUSTOMDATE, strBSDATE);
//
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('更新信息表','更新操作','修改委托编号为“" + model.CUSTNO.ToString() + "”的报关及货转信息','" + model.MODIFIEDUSER.ToString() + "')";
bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string GID, string strCUSTNO, string strUserID)
{
OpApplyEntity model = GetModel(GID);
//
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from op_apply where GID=@GID");
SqlParameter[] parameters = {new SqlParameter("@GID", SqlDbType.VarChar,36)};
parameters[0].Value = GID;
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
//
string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除信息表','删除操作','删除委托编号为“" + model.CUSTNO.ToString().Trim() + "”的报关及货转信息','" + model.MODIFIEDUSER.ToString().Trim() + "')";
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, str0, null);
//
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public OpApplyEntity GetModel(string GID)
{
//初始化返回变量
OpApplyEntity model = null;
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, STORAGENAMENEW, PKGS, KGS, NETWEIGHT, UNITOFWEIGHT, CBM, IMPORTVALUE, UNITPRICE, CURRENCY, CUSTOMSER, BSNO, CUSTOMNO, UPDATETIME, CUSTOMDATE, REMARK, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, CUSTNO, BSDATE, INSPECTIONNO, CUSTOMTYPE, CUSTOMERNAME, CLIENTNAMEOLD, STORAGENAME, ACCDATE ");
strSql.Append(" from op_apply ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {new SqlParameter("@GID", SqlDbType.VarChar,36)};
parameters[0].Value = GID;
//
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters))
{
try
{
model = new OpApplyEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { model.GID = sqlRead.GetString(0); }
if (!sqlRead.IsDBNull(1)) { model.STORAGENAMENEW = sqlRead.GetString(1); }
if (!sqlRead.IsDBNull(2)) { model.PKGS = sqlRead.GetInt32(2); }
if (!sqlRead.IsDBNull(3)) { model.KGS = sqlRead.GetDecimal(3); }
if (!sqlRead.IsDBNull(4)) { model.NETWEIGHT = sqlRead.GetDecimal(4); }
if (!sqlRead.IsDBNull(5)) { model.UNITOFWEIGHT = sqlRead.GetString(5); }
if (!sqlRead.IsDBNull(6)) { model.CBM = sqlRead.GetDecimal(6); }
if (!sqlRead.IsDBNull(7)) { model.IMPORTVALUE = sqlRead.GetDecimal(7); }
if (!sqlRead.IsDBNull(8)) { model.UNITPRICE = sqlRead.GetDecimal(8); }
if (!sqlRead.IsDBNull(9)) { model.CURRENCY = sqlRead.GetString(9); }
if (!sqlRead.IsDBNull(10)) { model.CUSTOMSER = sqlRead.GetString(10); }
if (!sqlRead.IsDBNull(11)) { model.BSNO = sqlRead.GetString(11); }
if (!sqlRead.IsDBNull(12)) { model.CUSTOMNO = sqlRead.GetString(12); }
if (!sqlRead.IsDBNull(13)) { model.UPDATETIME = sqlRead.GetDateTime(13); }
if (!sqlRead.IsDBNull(14)) { model.CUSTOMDATE = sqlRead.GetDateTime(14); }
if (!sqlRead.IsDBNull(15)) { model.REMARK = sqlRead.GetString(15); }
if (!sqlRead.IsDBNull(16)) { model.CREATEUSER = sqlRead.GetString(16); }
if (!sqlRead.IsDBNull(17)) { model.CREATETIME = sqlRead.GetDateTime(17); }
if (!sqlRead.IsDBNull(18)) { model.MODIFIEDUSER = sqlRead.GetString(18); }
if (!sqlRead.IsDBNull(19)) { model.MODIFIEDTIME = sqlRead.GetDateTime(19); }
if (!sqlRead.IsDBNull(20)) { model.CUSTNO = sqlRead.GetString(20); }
if (!sqlRead.IsDBNull(21)) { model.BSDATE = sqlRead.GetDateTime(21); }
if (!sqlRead.IsDBNull(22)) { model.INSPECTIONNO = sqlRead.GetString(22); }
if (!sqlRead.IsDBNull(23)) { model.CUSTOMTYPE = sqlRead.GetString(23); }
if (!sqlRead.IsDBNull(24)) { model.CUSTOMERNAME = sqlRead.GetString(24); }
if (!sqlRead.IsDBNull(25)) { model.CLIENTNAMEOLD = sqlRead.GetString(25); }
if (!sqlRead.IsDBNull(26)) { model.STORAGENAME = sqlRead.GetString(26); }
if (!sqlRead.IsDBNull(27)) { model.ACCDATE = sqlRead.GetString(27); }
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return model;
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * FROM op_apply ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
#region 根据SQL语句查询入库数据集
/// <summary>
/// 根据SQL语句查询入库数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetRateListByCondition(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#endregion
//
}
}