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.

518 lines
22 KiB
C#

11 months ago
using System;
using System.Data;
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 DSWeb.DataAccess;
using DSWeb.Models;
using System.Data.SqlClient;
using System.Collections;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class TopCtnDA
{
T_ALL_DA T_ALL_DA = new T_ALL_DA();
private const string PARM_MODULE_GID = "@BSNO";
private const string PARM_TopCtn_GID = "@CTN_ID";
private const string PARM_TOP_CTN_BSNO = "@bsno";
private const string SQL_SELECT_INFO = "select CTN_ID,BSNO,CTNCODE,SIZE,CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS,TAREWEIGHT from op_ctn where BSNO=@BSNO ORDER BY CTNALL ASC";
private string strSqlInsertInfo = "insert into [op_ctn](CTN_ID,BSNO,CTNCODE,SIZE,CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS,TAREWEIGHT) values(@CTN_ID,@BSNO,@CTNCODE,@SIZE,@CTN,@CTNNUM,@TEU,@CTNALL,@CNTRNO,@SEALNO,@PKGS,@KGS,@CBM,@REMARK,@KINDPKGS,@TAREWEIGHT)";
private string strSqlUpdateInfo = "update [op_ctn] set CTNCODE=@CTNCODE,SIZE=@SIZE,CTN=@CTN,CTNNUM=@CTNNUM,TEU=@TEU,CTNALL=@CTNALL,CNTRNO=@CNTRNO,SEALNO=@SEALNO,PKGS=@PKGS,KGS=@KGS,CBM=@CBM,REMARK=@REMARK,KINDPKGS=@KINDPKGS,TAREWEIGHT=@TAREWEIGHT where CTN_ID=@CTN_ID";
private const string SQL_SELECT_TopCtn_ALL = " SELECT CTN_ID,BSNO,CTNALL,CTNNUM FROM op_ctn order by BSNO";
private const string SQL_SELECT_TopCtn_BYGID = " SELECT CTN_ID,BSNO,CTNCODE,SIZE,CTN,CTNNUM,TEU,CTNALL,CNTRNO,SEALNO,PKGS,KGS,CBM,REMARK,KINDPKGS,TAREWEIGHT FROM op_ctn WHERE CTN_ID = @CTN_ID";
private const string SQL_SELECT_TopCtn_TOP1 = " SELECT top 1 CTN_ID,BSNO,CTNALL,CTNNUM FROM op_ctn order by BSNO";
private const string SQL_DELETE_TopCtn_BY_GID = "DELETE FROM op_ctn WHERE CTN_ID= @CTN_ID";
#region 根据GID获取op_ctn信息TopCtnEntity集
/// <summary>
/// 根据GID获取op_ctn信息TopCtnEntity集
/// </summary>
/// <param name="strRoleGID"></param>
/// <returns>返回TopCtnEntity集</returns>
public IList<TopCtnEntity> GetID(string strGID)
{
//初始化返回变量
IList<TopCtnEntity> TopCtnEntitys = new List<TopCtnEntity>();
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_MODULE_GID, SqlDbType.VarChar, 100);
parm.Value = strGID;
//
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INFO, parm))
{
try
{
//读取字段值
while (sqlRead.Read())
{
TopCtnEntity TopCtnEntity = new TopCtnEntity();
if (!sqlRead.IsDBNull(0)) { TopCtnEntity.CTN_ID = sqlRead.GetString(0); }
if (!sqlRead.IsDBNull(1)) { TopCtnEntity.BSNO = sqlRead.GetString(1); }
if (!sqlRead.IsDBNull(2)) { TopCtnEntity.CTNCODE = sqlRead.GetString(2); }
if (!sqlRead.IsDBNull(3)) { TopCtnEntity.SIZE = sqlRead.GetString(3); }
if (!sqlRead.IsDBNull(4)) { TopCtnEntity.CTN = sqlRead.GetString(4); }
if (!sqlRead.IsDBNull(5)) { TopCtnEntity.CTNNUM = sqlRead.GetInt32(5); }
if (!sqlRead.IsDBNull(6)) { TopCtnEntity.TEU = sqlRead.GetInt32(6); }
if (!sqlRead.IsDBNull(7)) { TopCtnEntity.CTNALL = sqlRead.GetString(7); }
if (!sqlRead.IsDBNull(8)) { TopCtnEntity.CNTRNO = sqlRead.GetString(8); }
if (!sqlRead.IsDBNull(9)) { TopCtnEntity.SEALNO = sqlRead.GetString(9); }
if (!sqlRead.IsDBNull(10)) { TopCtnEntity.PKGS = sqlRead.GetInt32(10); }
if (!sqlRead.IsDBNull(11)) { TopCtnEntity.KGS = sqlRead.GetDecimal(11); }
if (!sqlRead.IsDBNull(12)) { TopCtnEntity.CBM = sqlRead.GetDecimal(12); }
if (!sqlRead.IsDBNull(13)) { TopCtnEntity.REMARK = sqlRead.GetString(13); }
if (!sqlRead.IsDBNull(14)) { TopCtnEntity.KINDPKGS = sqlRead.GetString(14); }
if (!sqlRead.IsDBNull(15)) { TopCtnEntity.TAREWEIGHT = sqlRead.GetDecimal(15); }
TopCtnEntitys.Add(TopCtnEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return TopCtnEntitys;
}
#endregion
#region 根据公司GID获取公司信息
/// <summary>
/// 根据公司GID获取公司信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public TopCtnEntity GetTopCtnByID(string strGid)
{
TopCtnEntity TopCtnEntity = null;
SqlParameter parm = new SqlParameter(PARM_TopCtn_GID, SqlDbType.VarChar, 36);
parm.Value = strGid;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_TopCtn_BYGID, parm))
{
try
{
while (sqlRead.Read())
{
TopCtnEntity = new TopCtnEntity();
if (!sqlRead.IsDBNull(0)) { TopCtnEntity.CTN_ID = sqlRead.GetString(0); }
if (!sqlRead.IsDBNull(1)) { TopCtnEntity.BSNO = sqlRead.GetString(1); }
if (!sqlRead.IsDBNull(2)) { TopCtnEntity.CTNCODE = sqlRead.GetString(2); }
if (!sqlRead.IsDBNull(3)) { TopCtnEntity.SIZE = sqlRead.GetString(3); }
if (!sqlRead.IsDBNull(4)) { TopCtnEntity.CTN = sqlRead.GetString(4); }
if (!sqlRead.IsDBNull(5)) { TopCtnEntity.CTNNUM = sqlRead.GetInt32(5); }
if (!sqlRead.IsDBNull(6)) { TopCtnEntity.TEU = sqlRead.GetInt32(6); }
if (!sqlRead.IsDBNull(7)) { TopCtnEntity.CTNALL = sqlRead.GetString(7); }
if (!sqlRead.IsDBNull(8)) { TopCtnEntity.CNTRNO = sqlRead.GetString(8); }
if (!sqlRead.IsDBNull(9)) { TopCtnEntity.SEALNO = sqlRead.GetString(9); }
if (!sqlRead.IsDBNull(10)) { TopCtnEntity.PKGS = sqlRead.GetInt32(10); }
if (!sqlRead.IsDBNull(11)) { TopCtnEntity.KGS = sqlRead.GetDecimal(11); }
if (!sqlRead.IsDBNull(12)) { TopCtnEntity.CBM = sqlRead.GetDecimal(12); }
if (!sqlRead.IsDBNull(13)) { TopCtnEntity.REMARK = sqlRead.GetString(13); }
if (!sqlRead.IsDBNull(14)) { TopCtnEntity.KINDPKGS = sqlRead.GetString(14); }
if (!sqlRead.IsDBNull(15)) { TopCtnEntity.TAREWEIGHT = sqlRead.GetDecimal(15); }
}
}
catch (Exception execError)
{
throw execError;
}
}
return TopCtnEntity;
}
#endregion
#region 通过关联编号LINKID与账户类型获取账户信息
/// <summary>
/// 通过关联编号LINKID与账户类型获取账户信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
public TopCtnEntity GetTopCtnByLINKIDAndType(string strCTN_ID)
{
TopCtnEntity TopCtnEntity = null;
string strSql = " SELECT top 1 CTN_ID,BSNO,CTNALL,CTNNUM FROM op_ctn WHERE BSNO = '" + strCTN_ID + "'";
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
while (sqlRead.Read())
{
TopCtnEntity = new TopCtnEntity();
if (!sqlRead.IsDBNull(0))
{
TopCtnEntity.CTN_ID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
TopCtnEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
TopCtnEntity.CTNALL = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
TopCtnEntity.CTNNUM = sqlRead.GetInt32(3);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return TopCtnEntity;
}
#endregion
/// <summary>
/// 插入信息
/// </summary>
/// <param name="TopCtnEntity">实体类</param>
/// <returns>值为1插入数据正常,-1操作异常</returns>
public int InserInfo(TopCtnEntity infoEntity)
{
int iResult = 0;
string alt = "";
alt = T_ALL_DA.GetStrSQL("CTN_ID", "select CTN_ID from op_ctn where CTN_ID='" + infoEntity.CTN_ID.Trim() + "'");
if (alt.Trim() != "")
{
iResult = UpdateInfo(infoEntity);
return iResult;
}
//获取参数
SqlParameter[] parms = GetInsertParms();
parms[0].Value = infoEntity.CTN_ID;//编号
parms[1].Value = infoEntity.BSNO;//业务编号
parms[2].Value = infoEntity.CTNCODE;//箱型代码
parms[3].Value = infoEntity.SIZE;//尺寸
parms[4].Value = infoEntity.CTN;//箱型
parms[5].Value = infoEntity.CTNNUM;//箱量
parms[6].Value = infoEntity.TEU;//TEU
parms[7].Value = infoEntity.CTNALL;//表现形式
parms[8].Value = infoEntity.CNTRNO;//箱号
parms[9].Value = infoEntity.SEALNO;//封号
parms[10].Value = infoEntity.PKGS;//件数
parms[11].Value = infoEntity.KGS;//重量
parms[12].Value = infoEntity.CBM;//尺码
parms[13].Value = infoEntity.REMARK;//备注
parms[14].Value = infoEntity.KINDPKGS;//
parms[15].Value = infoEntity.TAREWEIGHT;//
strSqlInsertInfo = String.Format(strSqlInsertInfo);
//
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlInsertInfo, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新信息
/// </summary>
/// <param name="TopCtnEntity">实体类</param>
/// <returns>值为1更新数据正常,-1操作异常</returns>
public int UpdateInfo(TopCtnEntity infoEntity)
{
int iResult = 0;
//获取参数
SqlParameter[] parms = GetUpdateParms();
parms[0].Value = infoEntity.CTN_ID;//编号
parms[1].Value = infoEntity.CTNCODE;//箱型代码
parms[2].Value = infoEntity.SIZE;//尺寸
parms[3].Value = infoEntity.CTN;//箱型
parms[4].Value = infoEntity.CTNNUM;//箱量
parms[5].Value = infoEntity.TEU;//TEU
parms[6].Value = infoEntity.CTNALL;//表现形式
parms[7].Value = infoEntity.CNTRNO;//箱号
parms[8].Value = infoEntity.SEALNO;//封号
parms[9].Value = infoEntity.PKGS;//件数
parms[10].Value = infoEntity.KGS;//重量
parms[11].Value = infoEntity.CBM;//尺码
parms[12].Value = infoEntity.REMARK;//备注
parms[14].Value = infoEntity.KINDPKGS;//
parms[15].Value = infoEntity.TAREWEIGHT;//
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSqlUpdateInfo, parms);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#region 生成插入语句参数
/// <summary>
/// 生成插入语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetInsertParms()
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@CTN_ID",SqlDbType.VarChar,36),//编号
new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号
new SqlParameter("@CTNCODE",SqlDbType.VarChar,4),//箱型代码
new SqlParameter("@SIZE",SqlDbType.VarChar,2),//尺寸
new SqlParameter("@CTN",SqlDbType.VarChar,10),//箱型
new SqlParameter("@CTNNUM",SqlDbType.Int),//箱量
new SqlParameter("@TEU",SqlDbType.Int),//TEU
new SqlParameter("@CTNALL",SqlDbType.VarChar,10),//表现形式
new SqlParameter("@CNTRNO",SqlDbType.VarChar,30),//箱号
new SqlParameter("@SEALNO",SqlDbType.VarChar,12),//封号
new SqlParameter("@PKGS",SqlDbType.Int),//件数
new SqlParameter("@KGS",SqlDbType.Decimal),//箱内货重
new SqlParameter("@CBM",SqlDbType.Decimal),//尺码
new SqlParameter("@REMARK",SqlDbType.VarChar,50),//备注
new SqlParameter("@KINDPKGS",SqlDbType.VarChar,120),//包装类型
new SqlParameter("@TAREWEIGHT",SqlDbType.Decimal)//箱皮重
};
return parms;
}
#endregion
#region 生成更新语句参数
/// <summary>
/// 生成更新语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetUpdateParms()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@CTN_ID",SqlDbType.VarChar,36),//编号
//new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号
new SqlParameter("@CTNCODE",SqlDbType.VarChar,4),//箱型代码
new SqlParameter("@SIZE",SqlDbType.VarChar,2),//尺寸
new SqlParameter("@CTN",SqlDbType.VarChar,10),//箱型
new SqlParameter("@CTNNUM",SqlDbType.Int),//箱量
new SqlParameter("@TEU",SqlDbType.Int),//TEU
new SqlParameter("@CTNALL",SqlDbType.VarChar,10),//表现形式
new SqlParameter("@CNTRNO",SqlDbType.VarChar,30),//箱号
new SqlParameter("@SEALNO",SqlDbType.VarChar,12),//封号
new SqlParameter("@PKGS",SqlDbType.Int),//件数
new SqlParameter("@KGS",SqlDbType.Decimal),//箱内货重
new SqlParameter("@CBM",SqlDbType.Decimal),//尺码
new SqlParameter("@REMARK",SqlDbType.VarChar,50),//备注
new SqlParameter("@KINDPKGS",SqlDbType.VarChar,120),//包装类型
new SqlParameter("@TAREWEIGHT",SqlDbType.Decimal)//箱皮重
};
return parms;
}
#endregion
#region 插入账户列表信息
/// <summary>
/// 插入账户列表信息
/// </summary>
/// <param name="sqlList">插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
public int InsertTopCtnFromGrid(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 更新账户列表信息
/// <summary>
/// 更新账户列表信息
/// </summary>
/// <param name="sqlList">更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0</returns>
public int UpdateTopCtnFromGrid(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();
result = 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 DeleteTopCtnByGid(string tempGid)
{
int result = 0;
SqlParameter parm = new SqlParameter(PARM_TopCtn_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_TopCtn_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
/// <summary>
/// 根据SQL语句查询账户数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetExcuteSql(string strSql)
{
DataSet userSet = new DataSet();
userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql);
return userSet;
}
#region 根据SQL语句查询海运出口数据集
/// <summary>
/// 返回 某字段
/// </summary>
/// <returns></returns>
public DataSet GetFieldAll(string strSQL)
{
DataSet DS = new DataSet();
try
{
string str = "select * from op_ctn where 1=1 " + strSQL + "";
DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
int ii = DS.Tables[0].Rows.Count;
}
catch
{
DS = null;
}
return DS;
}
#endregion
#region 返回所有费用数据集
/// <summary>
/// 返回所有费用数据集
/// </summary>
/// <param name="strSql"></param>
/// <returns></returns>
public DataSet GetList(string strBSNO)
{
string str = "select * from op_ctn where BSNO='" + strBSNO + "'";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
str = "select top 1 CTN_ID='无数据',CTNCODE='无数据',SIZE='无数据',CTN='无数据',CTNALL='无数据',TEU='无数据',CTNNUM='无数据' from op_ctn";
DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
}
}
catch
{
str = "select top 1 CTN_ID='无数据',CTNCODE='无数据',SIZE='无数据',CTN='无数据',CTNALL='无数据',TEU='无数据',CTNNUM='无数据' from op_ctn";
DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
}
return DS;
}
#endregion
}
}