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.

435 lines
17 KiB
C#

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 OpSeaiTruckDA
{
private const string PARM_MODULE_GID = "@BSNO";
private const string PARM_OpSeaiTruck_GID = "@GID";
private const string PARM_Top_seai_truck_BSNO = "@bsno";
private const string SQL_SELECT_INFO = "select GID,BSNO,TRUCKER,TRUCKNO,TRUCKDATE from op_seai_truck where BSNO=@BSNO ORDER BY CTNALL ASC";
private string strSqlInsertInfo = "insert into [op_seai_truck](GID,BSNO,TRUCKER,{0}TRUCKNO) values(@GID,@BSNO,@TRUCKER,{1}@TRUCKNO)";
private string strSqlUpdateInfo = "update [op_seai_truck] set TRUCKER=@TRUCKER,TRUCKNO=@TRUCKNO,{0}TRUCKDATE=@TRUCKDATE where GID=@GID";
private const string SQL_SELECT_OpSeaiTruck_ALL = " SELECT GID,BSNO,TRUCKER,TRUCKNO,TRUCKDATE FROM op_seai_truck order by BSNO";
private const string SQL_SELECT_OpSeaiTruck_BYGID = " SELECT GID,BSNO,TRUCKER,TRUCKNO,TRUCKDATE FROM op_seai_truck WHERE GID = @GID";
private const string SQL_SELECT_OpSeaiTruck_TOP1 = " SELECT top 1 GID,BSNO,TRUCKER,TRUCKNO,TRUCKDATE FROM op_seai_truck order by BSNO";
private const string SQL_DELETE_OpSeaiTruck_BY_GID = "DELETE FROM op_seai_truck WHERE GID= @GID";
#region 根据GID获取op_seai_truck信息OpSeaiTruckEntity集
/// <summary>
/// 根据GID获取op_seai_truck信息OpSeaiTruckEntity集
/// </summary>
/// <param name="strRoleGID"></param>
/// <returns>返回OpSeaiTruckEntity集</returns>
public IList<OpSeaiTruckEntity> GetID(string strGID)
{
//初始化返回变量
IList<OpSeaiTruckEntity> OpSeaiTruckEntitys = new List<OpSeaiTruckEntity>();
//初始化参数并赋值
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())
{
OpSeaiTruckEntity OpSeaiTruckEntity = new OpSeaiTruckEntity();
if (!sqlRead.IsDBNull(0)) { OpSeaiTruckEntity.GID = sqlRead.GetString(0); }
if (!sqlRead.IsDBNull(1)) { OpSeaiTruckEntity.BSNO = sqlRead.GetString(1); }
if (!sqlRead.IsDBNull(2)) { OpSeaiTruckEntity.TRUCKER = sqlRead.GetString(2); }
if (!sqlRead.IsDBNull(3)) { OpSeaiTruckEntity.TRUCKNO = sqlRead.GetString(3); }
if (!sqlRead.IsDBNull(4)) { OpSeaiTruckEntity.TRUCKDATE = sqlRead.GetDateTime(4); }
OpSeaiTruckEntitys.Add(OpSeaiTruckEntity);
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return OpSeaiTruckEntitys;
}
#endregion
#region 根据公司GID获取公司信息
/// <summary>
/// 根据公司GID获取公司信息
/// </summary>
/// <param name="strGid"></param>
/// <returns></returns>
public OpSeaiTruckEntity GetOpSeaiTruckByID(string strGid)
{
OpSeaiTruckEntity OpSeaiTruckEntity = null;
SqlParameter parm = new SqlParameter(PARM_OpSeaiTruck_GID, SqlDbType.VarChar, 36);
parm.Value = strGid;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_OpSeaiTruck_BYGID, parm))
{
try
{
while (sqlRead.Read())
{
OpSeaiTruckEntity = new OpSeaiTruckEntity();
if (!sqlRead.IsDBNull(0)) { OpSeaiTruckEntity.GID = sqlRead.GetString(0); }
if (!sqlRead.IsDBNull(1)) { OpSeaiTruckEntity.BSNO = sqlRead.GetString(1); }
if (!sqlRead.IsDBNull(2)) { OpSeaiTruckEntity.TRUCKER = sqlRead.GetString(2); }
if (!sqlRead.IsDBNull(3)) { OpSeaiTruckEntity.TRUCKNO = sqlRead.GetString(3); }
if (!sqlRead.IsDBNull(4)) { OpSeaiTruckEntity.TRUCKDATE = sqlRead.GetDateTime(4); }
}
}
catch (Exception execError)
{
throw execError;
}
}
return OpSeaiTruckEntity;
}
#endregion
#region 通过关联编号LINKID与账户类型获取账户信息
/// <summary>
/// 通过关联编号LINKID与账户类型获取账户信息
/// </summary>
/// <param name="strGID"></param>
/// <returns></returns>
public OpSeaiTruckEntity GetOpSeaiTruckByLINKIDAndType(string strGID)
{
OpSeaiTruckEntity OpSeaiTruckEntity = null;
string strSql = " SELECT top 1 GID,BSNO,TRUCKER,TRUCKNO,TRUCKDATE FROM op_seai_truck WHERE BSNO = '" + strGID + "'";
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null))
{
try
{
while (sqlRead.Read())
{
OpSeaiTruckEntity = new OpSeaiTruckEntity();
if (!sqlRead.IsDBNull(0))
{
OpSeaiTruckEntity.GID = sqlRead.GetString(0);
}
if (!sqlRead.IsDBNull(1))
{
OpSeaiTruckEntity.BSNO = sqlRead.GetString(1);
}
if (!sqlRead.IsDBNull(2))
{
OpSeaiTruckEntity.TRUCKER = sqlRead.GetString(2);
}
if (!sqlRead.IsDBNull(3))
{
OpSeaiTruckEntity.TRUCKNO = sqlRead.GetString(3);
}
if (!sqlRead.IsDBNull(4))
{
OpSeaiTruckEntity.TRUCKDATE = sqlRead.GetDateTime(4);
}
}
}
catch (Exception execError)
{
throw execError;
}
}
return OpSeaiTruckEntity;
}
#endregion
/// <summary>
/// 插入信息
/// </summary>
/// <param name="OpSeaiTruckEntity">实体类</param>
/// <returns>值为1插入数据正常,-1操作异常</returns>
public int InserInfo(OpSeaiTruckEntity infoEntity)
{
int iResult = 0;
string alt = "";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
alt = T_ALL_DA.GetStrSQL("GID", "select GID from op_seai_truck where GID='" + infoEntity.GID.Trim() + "'");
if (alt.Trim() != "")
{
iResult = UpdateInfo(infoEntity);
return iResult;
}
//获取参数
SqlParameter[] parms = GetInsertParms();
parms[0].Value = infoEntity.GID;//编号
parms[1].Value = infoEntity.BSNO;//业务编号
parms[2].Value = infoEntity.TRUCKER;
parms[3].Value = infoEntity.TRUCKNO;
//parms[4].Value = infoEntity.TRUCKDATE;
string strTRUCKDATE = infoEntity.TRUCKDATE.ToString().IndexOf("0001")>-1 ? "" : "'" + infoEntity.TRUCKDATE.ToString() + "',";
string strTRUCKDATE_name = strTRUCKDATE.Equals("") ? "" : "TRUCKDATE,";
//
strSqlInsertInfo = String.Format(strSqlInsertInfo, strTRUCKDATE_name, strTRUCKDATE);
//
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="OpSeaiTruckEntity">实体类</param>
/// <returns>值为1更新数据正常,-1操作异常</returns>
public int UpdateInfo(OpSeaiTruckEntity infoEntity)
{
int iResult = 0;
//获取参数
SqlParameter[] parms = GetUpdateParms();
parms[0].Value = infoEntity.GID;//编号
parms[1].Value = infoEntity.BSNO;//业务编号
parms[2].Value = infoEntity.TRUCKER;
parms[3].Value = infoEntity.TRUCKNO;
//parms[4].Value = infoEntity.TRUCKDATE;
//
string strTRUCKDATE = infoEntity.TRUCKDATE.ToString().IndexOf("0001")>-1 ? "" : "TRUCKDATE='" + infoEntity.TRUCKDATE.ToString() + "',";
//
strSqlUpdateInfo = String.Format(strSqlUpdateInfo, strTRUCKDATE);
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("@GID",SqlDbType.VarChar,36),//编号
new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号
new SqlParameter("@TRUCKER",SqlDbType.VarChar,20),
new SqlParameter("@TRUCKNO",SqlDbType.VarChar,50),
//new SqlParameter("@TRUCKDATE",SqlDbType.DateTime)
};
return parms;
}
#endregion
#region 生成更新语句参数
/// <summary>
/// 生成更新语句参数
/// </summary>
/// <returns>返回SqlParameter数组</returns>
private SqlParameter[] GetUpdateParms()
{
SqlParameter[] parms = new SqlParameter[]{
new SqlParameter("@GID",SqlDbType.VarChar,36),//编号
new SqlParameter("@BSNO",SqlDbType.VarChar,100),//业务编号
new SqlParameter("@TRUCKER",SqlDbType.VarChar,20),
new SqlParameter("@TRUCKNO",SqlDbType.VarChar,50),
//new SqlParameter("@TRUCKDATE",SqlDbType.DateTime)
};
return parms;
}
#endregion
#region 插入账户列表信息
/// <summary>
/// 插入账户列表信息
/// </summary>
/// <param name="sqlList">插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作</param>
/// <returns>返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0</returns>
public int InsertOpSeaiTruckFromGrid(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 UpdateOpSeaiTruckFromGrid(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 DeleteOpSeaiTruckByGid(string tempGid)
{
int result = 0;
SqlParameter parm = new SqlParameter(PARM_OpSeaiTruck_GID, SqlDbType.VarChar, 36);
parm.Value = tempGid;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_OpSeaiTruck_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_seai_truck where 1=1 " + strSQL + "";
DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
int ii = DS.Tables[0].Rows.Count;
}
catch
{
DS = null;
}
return DS;
}
#endregion
}
}