using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Text; using System.Collections; using System.Collections.Generic; using DSWeb.Models; using DSWeb.DataAccess; namespace DSWeb.EntityDA { public class CrmSeaeorderctnDA { private const string PARM_CrmSeaeorderctn_GID = "@CTN_ID"; private const string PARM_CRM_SEAE_ORDER_CTN_ORDNO = "@ordno"; private const string SQL_SELECT_CrmSeaeorderctn_ALL = " SELECT CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK FROM crm_seaeorderctn order by ORDNO"; private const string SQL_SELECT_CrmSeaeorderctn_BYGID = " SELECT CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK FROM crm_seaeorderctn WHERE CTN_ID = @CTN_ID"; private const string SQL_SELECT_CrmSeaeorderctn_TOP1 = " SELECT top 1 CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK FROM crm_seaeorderctn order by ORDNO"; private string strSqlInsertInfo = "insert into [crm_seaeorderctn](CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK) values(@CTN_ID,@ORDNO,@CTNALL,@CTNNUM,@REMARK)"; private string strSqlUpdateInfo = "update [crm_seaeorderctn] set CTNALL=@CTNALL,CTNNUM=@CTNNUM,REMARK=@REMARK where CTN_ID=@CTN_ID"; private const string SQL_DELETE_CrmSeaeorderctn_BY_GID = "DELETE FROM crm_seaeorderctn WHERE CTN_ID= @CTN_ID"; private const string SQL_SELECT_CRMSEAEORDERCTN_BY_ORDNO = " SELECT CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK FROM crm_seaeorderctn WHERE ORDNO = @ordno order by ORDNO"; #region 根据销售订舱ORDNO获取集装箱信息 /// /// 根据销售订舱ORDNO获取集装箱信息 /// /// /// public IList GetCrmSeaeOrderCtnByOrdNo(string tempOrdno) { IList crmSeaeOrderCtnEntities = new List(); SqlParameter parm = new SqlParameter(PARM_CRM_SEAE_ORDER_CTN_ORDNO, SqlDbType.VarChar, 36); parm.Value = tempOrdno; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CRMSEAEORDERCTN_BY_ORDNO, parm)) { try { while (sqlRead.Read()) { CrmSeaeorderctnEntity crmSeaeOrderCtnEntity = new CrmSeaeorderctnEntity(); if (!sqlRead.IsDBNull(0)) { crmSeaeOrderCtnEntity.CTN_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { crmSeaeOrderCtnEntity.ORDNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { crmSeaeOrderCtnEntity.CTNALL = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { crmSeaeOrderCtnEntity.CTNNUM = sqlRead.GetInt32(3); } if (!sqlRead.IsDBNull(4)) { crmSeaeOrderCtnEntity.REMARK = sqlRead.GetString(4); } crmSeaeOrderCtnEntities.Add(crmSeaeOrderCtnEntity); } } catch (Exception execError) { throw execError; } } return crmSeaeOrderCtnEntities; } #endregion #region 获取所有公司信息 /// /// 获取所有公司信息 /// /// List public IList GetAllCrmSeaeorderctn() { IList CrmSeaeorderctnEntites = new List(); CrmSeaeorderctnEntity CrmSeaeorderctnEntity = null; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CrmSeaeorderctn_ALL, null)) { try { while (sqlRead.Read()) { CrmSeaeorderctnEntity = new CrmSeaeorderctnEntity(); if (!sqlRead.IsDBNull(0)) { CrmSeaeorderctnEntity.CTN_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { CrmSeaeorderctnEntity.ORDNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { CrmSeaeorderctnEntity.CTNALL = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { CrmSeaeorderctnEntity.CTNNUM = sqlRead.GetInt32(3); } if (!sqlRead.IsDBNull(4)) { CrmSeaeorderctnEntity.REMARK = sqlRead.GetString(4); } CrmSeaeorderctnEntites.Add(CrmSeaeorderctnEntity); } } catch (Exception execError) { throw execError; } } return CrmSeaeorderctnEntites; } #endregion #region 根据公司GID获取公司信息 /// /// 根据公司GID获取公司信息 /// /// /// public CrmSeaeorderctnEntity GetCrmSeaeorderctnByID(string strGid) { CrmSeaeorderctnEntity CrmSeaeorderctnEntity = null; SqlParameter parm = new SqlParameter(PARM_CrmSeaeorderctn_GID, SqlDbType.VarChar, 36); parm.Value = strGid; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CrmSeaeorderctn_BYGID, parm)) { try { while (sqlRead.Read()) { CrmSeaeorderctnEntity = new CrmSeaeorderctnEntity(); if (!sqlRead.IsDBNull(0)) { CrmSeaeorderctnEntity.CTN_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { CrmSeaeorderctnEntity.ORDNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { CrmSeaeorderctnEntity.CTNALL = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { CrmSeaeorderctnEntity.CTNNUM = sqlRead.GetInt32(3); } if (!sqlRead.IsDBNull(4)) { CrmSeaeorderctnEntity.REMARK = sqlRead.GetString(4); } } } catch (Exception execError) { throw execError; } } return CrmSeaeorderctnEntity; } #endregion #region 根据公司GID获取公司信息 /// /// 根据公司GID获取公司信息 /// /// /// public CrmSeaeorderctnEntity GetCrmSeaeorderctnTop1() { CrmSeaeorderctnEntity CrmSeaeorderctnEntity = null; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_CrmSeaeorderctn_TOP1, null)) { try { while (sqlRead.Read()) { CrmSeaeorderctnEntity = new CrmSeaeorderctnEntity(); if (!sqlRead.IsDBNull(0)) { CrmSeaeorderctnEntity.CTN_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { CrmSeaeorderctnEntity.ORDNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { CrmSeaeorderctnEntity.CTNALL = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { CrmSeaeorderctnEntity.CTNNUM = sqlRead.GetInt32(3); } if (!sqlRead.IsDBNull(4)) { CrmSeaeorderctnEntity.REMARK = sqlRead.GetString(4); } } } catch (Exception execError) { throw execError; } } return CrmSeaeorderctnEntity; } #endregion /// /// 插入信息 /// /// 实体类 /// 值为1插入数据正常,-1操作异常 public int InserInfo(CrmSeaeorderctnEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetInsertParms(); parms[0].Value = infoEntity.CTN_ID;//编号 parms[1].Value = infoEntity.ORDNO;//订舱编号 parms[2].Value = infoEntity.CTNALL;//表现形式 parms[3].Value = infoEntity.CTNNUM;//箱量 parms[4].Value = infoEntity.REMARK;//备注 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; } /// /// 更新信息 /// /// 实体类 /// 值为1更新数据正常,-1操作异常 public int UpdateInfo(CrmSeaeorderctnEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetUpdateParms(); parms[0].Value = infoEntity.CTN_ID;//编号 parms[1].Value = infoEntity.CTNALL;//表现形式 parms[2].Value = infoEntity.CTNNUM;//箱量 parms[3].Value = infoEntity.REMARK;//备注 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 生成插入语句参数 /// /// 生成插入语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetInsertParms() { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@CTN_ID",SqlDbType.VarChar,36),//编号 new SqlParameter("@ORDNO",SqlDbType.VarChar,36),//订舱编号 new SqlParameter("@CTNALL",SqlDbType.VarChar,10),//表现形式 new SqlParameter("@CTNNUM",SqlDbType.Int),//箱量 new SqlParameter("@REMARK",SqlDbType.VarChar,50)//备注 }; return parms; } #endregion #region 生成更新语句参数 /// /// 生成更新语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetUpdateParms() { SqlParameter[] parms = new SqlParameter[]{ new SqlParameter("@CTN_ID",SqlDbType.VarChar,36),//编号 new SqlParameter("@CTNALL",SqlDbType.VarChar,10),//表现形式 new SqlParameter("@CTNNUM",SqlDbType.Int),//箱量 new SqlParameter("@REMARK",SqlDbType.VarChar,50)//备注 }; return parms; } #endregion #region 返回数据集 公司表(CrmSeaeorderctn)信息 /// /// 返回 公司表(CrmSeaeorderctn)信息 /// /// public DataSet GetCrmSeaeorderctnSQL(string strSQL) { string str = "select * from [crm_seaeorderctn] where 1=1 " + strSQL; DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); try { if (DS.Tables[0].Rows.Count <= 0) { DS = null; } } catch { DS = null; } return DS; } #endregion #region 返回数据集 公司表(CrmSeaeorderctn)信息 /// 返回 公司表(CrmSeaeorderctn)删除 /// /// /// public String GetCrmSeaeorderctnDel(string strCTN_ID, string strUserID) { string alt = ""; string str = "delete from crm_seaeorderctn where CTN_ID='" + strCTN_ID + "'"; bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str); if (bl == false) { alt = "预订舱集装箱信息表(crm_seaeorderctn)删除操作出错!"; return alt; } else { //string str1 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除预订舱集装箱信息表(crm_seaeorderctn)的信息','删除操作','" + str + "','" + strUserID + "')"; //bool bl1 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str1); } return alt; } #endregion /// /// 根据SQL语句查询账户数据集 /// /// /// public DataSet GetExcuteSql(string strSql) { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return userSet; } #region 插入账户列表信息 /// /// 插入账户列表信息 /// /// 插入SQL语句组,将所有要执行的插入语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示插入完成;为-1插入出现异常但未正确回滚事务;为-2插入异常,事务已经成功回滚;默认状态为0 public int InsertCrmSeaeorderctnFromGrid(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 更新账户列表信息 /// /// 更新账户列表信息 /// /// 更新SQL语句组,将所有要执行的更新语句写入ArrayList,每个索引对应一条SQL语句,执行时需要遍历操作 /// 返回状态值 为1表示更新完成;为-1更新出现异常但未正确回滚事务;为-2更新异常,事务已经成功回滚;默认状态为0 public int UpdateCrmSeaeorderctnFromGrid(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 通过关联编号LINKID与账户类型获取账户信息 /// /// 通过关联编号LINKID与账户类型获取账户信息 /// /// /// public CrmSeaeorderctnEntity GetCrmSeaeorderctnByLINKIDAndType(string strCTN_ID) { CrmSeaeorderctnEntity CrmSeaeorderctnEntity = null; string strSql = " SELECT top 1 CTN_ID,ORDNO,CTNALL,CTNNUM,REMARK FROM crm_seaeorderctn WHERE ORDNO = '" + strCTN_ID + "'"; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null)) { try { while (sqlRead.Read()) { CrmSeaeorderctnEntity = new CrmSeaeorderctnEntity(); if (!sqlRead.IsDBNull(0)) { CrmSeaeorderctnEntity.CTN_ID = sqlRead.GetString(0); } if (!sqlRead.IsDBNull(1)) { CrmSeaeorderctnEntity.ORDNO = sqlRead.GetString(1); } if (!sqlRead.IsDBNull(2)) { CrmSeaeorderctnEntity.CTNALL = sqlRead.GetString(2); } if (!sqlRead.IsDBNull(3)) { CrmSeaeorderctnEntity.CTNNUM = sqlRead.GetInt32(3); } if (!sqlRead.IsDBNull(4)) { CrmSeaeorderctnEntity.REMARK = sqlRead.GetString(4); } } } catch (Exception execError) { throw execError; } } return CrmSeaeorderctnEntity; } #endregion #region 通过账户GID删除单条账户 public int DeleteCrmSeaeorderctnByGid(string tempGid) { int result = 0; SqlParameter parm = new SqlParameter(PARM_CrmSeaeorderctn_GID, SqlDbType.VarChar, 36); parm.Value = tempGid; using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction)) { try { SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_DELETE_CrmSeaeorderctn_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 #region 根据SQL语句查询海运出口数据集 /// /// 返回 某字段 /// /// public DataSet GetFieldAll(string strSQL) { DataSet DS = new DataSet(); try { string str = "select * from crm_seaeorderctn where 1=1 " + strSQL + ""; DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); int ii = DS.Tables[0].Rows.Count; } catch { DS = null; } return DS; } #endregion } }