using System; using System.Data; 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.DataAccess; using DSWeb.Models; using System.Data.SqlClient; using System.Collections.Generic; namespace DSWeb.EntityDA { public class SysAnnounceDA { private const string PARM_MODULE_GID = "@GID"; private const string PARM_MODULE_PORTDISCHARGE = "@PORTDISCHARGE";//卸货港 private const string PARM_MODULE_CARRIE = "@CARRIE"; //船公司 private const string PARM_MODULE_ETD = "@ETD";//开航日 private const string PARM_MODULE_TT = "@TT";//航程 private const string SQL_SELECT_INFO = "select GID,NAME,DESCRIPTION,ANNOUNCECONTENT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,BEGINTIME,ENDTIME,ISDELETE,DELETETIME,DELETEUSER,INTERVAL,TYPE,ISISSUE from sys_announce where GID=@GID"; private const string SQL_SELECT_INFO_TYPE = "select GID,NAME,DESCRIPTION,ANNOUNCECONTENT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,BEGINTIME,ENDTIME,ISDELETE,DELETETIME,DELETEUSER,INTERVAL,TYPE,ISISSUE from sys_announce where ISISSUE=1 and ISDELETE=0 AND TYPE=@TYPE and gid not in(select ANNOUNCEGID from sys_announce_set where CLIENTGID=@CLIENTGID) and BEGINTIME<=@strDate and ENDTIME>=@strDate order by MODIFIEDTIME"; private const string SQL_DELETE_INFO = "DELETE FROM sys_announce WHERE GID=@GID"; private string SQL_INSERT_INFO = "insert into sys_announce(GID,NAME,DESCRIPTION,ANNOUNCECONTENT,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,{0}{2}ISDELETE,DELETETIME,DELETEUSER,INTERVAL,[TYPE],ISISSUE) " +" values(@GID,@NAME,@DESCRIPTION,@ANNOUNCECONTENT,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),{1}{3}0,getdate(),@DELETEUSER,@INTERVAL,@TYPE,0)"; private string SQL_UPDATE_INFO = "update sys_announce set NAME=@NAME,DESCRIPTION=@DESCRIPTION,ANNOUNCECONTENT=@ANNOUNCECONTENT,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=getdate(),{0}{1}INTERVAL=@INTERVAL,[TYPE]=@TYPE where GID=@GID"; public SysAnnounceDA() { } /// /// 返回 某字段 /// /// public string GetStrSQL(string strfield, string strSQL) { string alt = ""; DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL); if (DS != null) { if (DS.Tables[0].Rows.Count > 0) { alt = DS.Tables[0].Rows[0]["" + strfield + ""].ToString(); } } return alt; } #region 根据运价查询ORDNO获取集装箱信息 /// /// 根据运价查询ORDNO获取集装箱信息 /// /// /// public IList GetALLTYPE(string strUserID) { int inum = int.Parse(GetTYPENUM(strUserID, 2)); string strDate = GetStrSQL("strDate", "select getdate() as strDate"); //初始化参数并赋值 SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@TYPE",SqlDbType.Int),//类型 new SqlParameter("@CLIENTGID",SqlDbType.VarChar,36),//类型 new SqlParameter("@strDate",SqlDbType.DateTime)//类型 }; parms[0].Value = inum;//卸货港 parms[1].Value = strUserID;//卸货港 parms[2].Value = strDate;//卸货港 IList SysAnnounceEntities = new List(); using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INFO_TYPE, parms)) { try { while (sqlRead.Read()) { SysAnnounceEntity SysAnnounceEntity = new SysAnnounceEntity(); if (!sqlRead.IsDBNull(0)) { SysAnnounceEntity.GID = sqlRead.GetString(0); }// 惟一编号 if (!sqlRead.IsDBNull(1)) { SysAnnounceEntity.NAME = sqlRead.GetString(1); }// 系统名称 if (!sqlRead.IsDBNull(2)) { SysAnnounceEntity.DESCRIPTION = sqlRead.GetString(2); }// 中文名称或描述/标题 if (!sqlRead.IsDBNull(3)) { SysAnnounceEntity.ANNOUNCECONTENT = sqlRead.GetString(3); }// 公告内容 if (!sqlRead.IsDBNull(4)) { SysAnnounceEntity.CREATEUSER = sqlRead.GetString(4); }// 创建人 if (!sqlRead.IsDBNull(5)) { SysAnnounceEntity.CREATETIME = sqlRead.GetDateTime(5); }// 创建时间 if (!sqlRead.IsDBNull(6)) { SysAnnounceEntity.MODIFIEDUSER = sqlRead.GetString(6); }// 最后一次更新操作人 if (!sqlRead.IsDBNull(7)) { SysAnnounceEntity.MODIFIEDTIME = sqlRead.GetDateTime(7); }// 最后一次更新操作时间 if (!sqlRead.IsDBNull(8)) { SysAnnounceEntity.BEGINTIME = sqlRead.GetDateTime(8); }// 公告起始时间 if (!sqlRead.IsDBNull(9)) { SysAnnounceEntity.ENDTIME = sqlRead.GetDateTime(9); }// 公告结束时间 if (!sqlRead.IsDBNull(10)) { SysAnnounceEntity.ISDELETE = sqlRead.GetBoolean(10); }// 是否删除 if (!sqlRead.IsDBNull(11)) { SysAnnounceEntity.DELETETIME = sqlRead.GetDateTime(11); }// 删除时间 if (!sqlRead.IsDBNull(12)) { SysAnnounceEntity.DELETEUSER = sqlRead.GetString(12); }// 删除操作人 if (!sqlRead.IsDBNull(13)) { SysAnnounceEntity.INTERVAL = sqlRead.GetInt32(13); }// 公告间隔时间 if (!sqlRead.IsDBNull(14)) { SysAnnounceEntity.TYPE = sqlRead.GetInt32(14); }// 公告类型 if (!sqlRead.IsDBNull(15)) { SysAnnounceEntity.ISISSUE = sqlRead.GetBoolean(15); }// 是否发布 SysAnnounceEntities.Add(SysAnnounceEntity); } } catch (Exception execError) { throw execError; } } return SysAnnounceEntities; } #endregion #region 根据GID获取信息 /// /// 根据GID获取信息 /// /// /// public SysAnnounceEntity GetID(string strGID) { //初始化返回变量 SysAnnounceEntity SysAnnounceEntity = null; //初始化参数并赋值 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 { SysAnnounceEntity = new SysAnnounceEntity(); //读取字段值 while (sqlRead.Read()) { if (!sqlRead.IsDBNull(0)) { SysAnnounceEntity.GID = sqlRead.GetString(0); }// 惟一编号 if (!sqlRead.IsDBNull(1)) { SysAnnounceEntity.NAME = sqlRead.GetString(1); }// 系统名称 if (!sqlRead.IsDBNull(2)) { SysAnnounceEntity.DESCRIPTION = sqlRead.GetString(2); }// 中文名称或描述/标题 if (!sqlRead.IsDBNull(3)) { SysAnnounceEntity.ANNOUNCECONTENT = sqlRead.GetString(3); }// 公告内容 if (!sqlRead.IsDBNull(4)) { SysAnnounceEntity.CREATEUSER = sqlRead.GetString(4); }// 创建人 if (!sqlRead.IsDBNull(5)) { SysAnnounceEntity.CREATETIME = sqlRead.GetDateTime(5); }// 创建时间 if (!sqlRead.IsDBNull(6)) { SysAnnounceEntity.MODIFIEDUSER = sqlRead.GetString(6); }// 最后一次更新操作人 if (!sqlRead.IsDBNull(7)) { SysAnnounceEntity.MODIFIEDTIME = sqlRead.GetDateTime(7); }// 最后一次更新操作时间 if (!sqlRead.IsDBNull(8)) { SysAnnounceEntity.BEGINTIME = sqlRead.GetDateTime(8); }// 公告起始时间 if (!sqlRead.IsDBNull(9)) { SysAnnounceEntity.ENDTIME = sqlRead.GetDateTime(9); }// 公告结束时间 if (!sqlRead.IsDBNull(10)) { SysAnnounceEntity.ISDELETE = sqlRead.GetBoolean(10); }// 是否删除 if (!sqlRead.IsDBNull(11)) { SysAnnounceEntity.DELETETIME = sqlRead.GetDateTime(11); }// 删除时间 if (!sqlRead.IsDBNull(12)) { SysAnnounceEntity.DELETEUSER = sqlRead.GetString(12); }// 删除操作人 if (!sqlRead.IsDBNull(13)) { SysAnnounceEntity.INTERVAL = sqlRead.GetInt32(13); }// 公告间隔时间 if (!sqlRead.IsDBNull(14)) { SysAnnounceEntity.TYPE = sqlRead.GetInt32(14); }// 公告类型 if (!sqlRead.IsDBNull(15)) { SysAnnounceEntity.ISISSUE = sqlRead.GetBoolean(15); }// 是否发布 } } catch (Exception exceError) { //抛出异常 throw exceError; } } return SysAnnounceEntity; } #endregion /// /// 插入信息 /// /// 实体类 /// 值为1插入数据正常,-1操作异常 public int InserInfo(SysAnnounceEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetInsertParms(); parms[0].Value = infoEntity.GID;//惟一编号 parms[1].Value = infoEntity.NAME;//系统名称 parms[2].Value = infoEntity.DESCRIPTION;//中文名称或描述/标题 parms[3].Value = infoEntity.ANNOUNCECONTENT;//公告内容 parms[4].Value = infoEntity.CREATEUSER;//创建人 parms[5].Value = infoEntity.MODIFIEDUSER;//最后一次更新操作人 parms[6].Value = infoEntity.DELETEUSER;//删除操作人 parms[7].Value = infoEntity.INTERVAL;//公告间隔时间 parms[8].Value = infoEntity.TYPE;//公告类型 // BEGINTIME;//公告起始时间 datetime // ENDTIME;//公告结束时间 datetime //公告起始时间 string strBEGINTIME = infoEntity.BEGINTIME.ToString().IndexOf("0001")>-1 ? "" : "'" + infoEntity.BEGINTIME.ToString() + "',"; string strBEGINTIME_name = strBEGINTIME.Equals("") ? "" : "BEGINTIME,"; //公告结束时间 string strENDTIME = infoEntity.ENDTIME.ToString().IndexOf("0001")>-1 ? "" : "'" + infoEntity.ENDTIME.ToString() + "',"; string strENDTIME_name = strENDTIME.Equals("") ? "" : "ENDTIME,"; // SQL_INSERT_INFO = String.Format(SQL_INSERT_INFO, strBEGINTIME_name, strBEGINTIME, strENDTIME_name, strENDTIME); // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_INSERT_INFO, parms); if (existVal > 0) { iResult = 1; // //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('插入公告管理表:sys_announce','插入操作','GID=" + infoEntity.GID + "','" + infoEntity.CREATEUSER + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } /// /// 更新信息 /// /// 实体类 /// 值为1更新数据正常,-1操作异常 public int UpdateInfo(SysAnnounceEntity infoEntity) { int iResult = 0; //获取参数 SqlParameter[] parms = GetUpdateParms(); parms[0].Value = infoEntity.GID;//惟一编号 parms[1].Value = infoEntity.NAME;//系统名称 parms[2].Value = infoEntity.DESCRIPTION;//中文名称或描述/标题 parms[3].Value = infoEntity.ANNOUNCECONTENT;//公告内容 parms[4].Value = infoEntity.MODIFIEDUSER;//最后一次更新操作人 parms[5].Value = infoEntity.INTERVAL;//公告间隔时间 parms[6].Value = infoEntity.TYPE;//公告类型 // BEGINTIME;//公告起始时间 datetime // ENDTIME;//公告结束时间 datetime //公告起始时间 string strBEGINTIME = infoEntity.BEGINTIME.ToString().IndexOf("0001")>-1 ? "null," : "BEGINTIME='" + infoEntity.BEGINTIME.ToString() + "',"; //公告结束时间 string strENDTIME = infoEntity.ENDTIME.ToString().IndexOf("0001")>-1 ? "null," : "ENDTIME='" + infoEntity.ENDTIME.ToString() + "',"; // SQL_UPDATE_INFO = String.Format(SQL_UPDATE_INFO, strBEGINTIME, strENDTIME); // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL_UPDATE_INFO, parms); if (existVal > 0) { iResult = 1; // //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新公告管理表:sys_announce内容','更新操作','GID=" + infoEntity.GID + "','')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } /// /// 插入信息 /// /// 实体类 /// 值为1插入数据正常,-1操作异常 public int InserInfoCNTRTOTAL(string strSql, string strUserID) { int iResult = 0; // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, null); if (existVal > 0) { iResult = 1; // //strSql = strSql.Trim().Replace("'", "''"); //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('插入sys_announce海运业务预订舱表集装箱字段','插入操作','" + strSql + "','" + strUserID + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } #region 生成插入语句参数 /// /// 生成插入语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetInsertParms() { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号 new SqlParameter("@NAME",SqlDbType.VarChar,100),//系统名称 new SqlParameter("@DESCRIPTION",SqlDbType.VarChar,100),//中文名称或描述/标题 new SqlParameter("@ANNOUNCECONTENT",SqlDbType.VarChar,1024),//公告内容 new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人 new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人 new SqlParameter("@DELETEUSER",SqlDbType.VarChar,36),//删除操作人 new SqlParameter("@INTERVAL",SqlDbType.Int),//公告间隔时间 new SqlParameter("@TYPE",SqlDbType.Int)//公告类型 }; return parms; } #endregion #region 生成更新语句参数 /// /// 生成更新语句参数 /// /// 返回SqlParameter数组 private SqlParameter[] GetUpdateParms() { SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号 new SqlParameter("@NAME",SqlDbType.VarChar,100),//系统名称 new SqlParameter("@DESCRIPTION",SqlDbType.VarChar,100),//中文名称或描述/标题 new SqlParameter("@ANNOUNCECONTENT",SqlDbType.VarChar,1024),//公告内容 new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人 new SqlParameter("@INTERVAL",SqlDbType.Int),//公告间隔时间 new SqlParameter("@TYPE",SqlDbType.Int)//公告类型 }; return parms; } /// /// 更新信息 /// /// 实体类 /// 值为1更新数据正常,-1操作异常 public int UpdateInfoCNTRTOTAL(string strSql, string strUserID) { int iResult = 0; // using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction)) { int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, null); if (existVal > 0) { iResult = 1; // //strSql = strSql.Trim().Replace("'", "''"); //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新所有sys_announce海运业务预订舱表集装箱字段','更新操作','" + strSql + "','" + strUserID + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } else { iResult = -1;//执行异常 } } return iResult; } #endregion #region 返回所有海运出口数据集 /// /// 返回所有海运出口数据集 /// /// /// public DataSet GetSeaExportList() { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INFO); return userSet; } #endregion #region 根据SQL语句查询海运出口数据集 /// /// 根据SQL语句查询海运出口数据集 /// /// /// public DataSet GetSeaExportListByCondition(string strSql) { DataSet userSet = new DataSet(); userSet = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql); return userSet; } #endregion #region 根据SQL语句查询海运出口数据集 /// /// 返回 某字段 /// /// public DataSet GetFieldAll(string strGID) { DataSet DS = new DataSet(); try { string str = "select * from sys_announce where GID='" + strGID + "'"; DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); int ii = DS.Tables[0].Rows.Count; } catch { DS = null; } return DS; } #endregion #region 获取海运出口委托记录总页数 /// /// 获取海运出口委托记录总页数 /// /// sql查询语句 /// 返回int型海运出口委托记录总页数 public int GetPageTotal(string strSql) { int iResult = 0; using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql, null)) { try { while (sqlRead.Read()) { iResult = sqlRead.GetInt32(0); } } catch (Exception error) { throw error; } } return iResult; } #endregion #region 删除公告管理信息表 /// /// 删除公告管理信息表 /// /// 公告管理信息表GID /// 删除人ID /// 值1表示删除成功 值-1表示有异常,删除失败 值-2表示插入异常,事务已回滚成功 public String GetSysAnnounceDel(string strSel, string strUserID) { string alt = ""; string str = "update sys_announce set ISDELETE=1,DELETETIME=getdate(),DELETEUSER='"+strUserID+"' where 1=0 " + strSel; bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str); if (bl == false) { alt = "公告管理信息表sys_announce删除操作出错!"; return alt; } else { //str = str.Trim().Replace("'", "''"); //string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除公告管理信息表sys_announce','删除操作','" + str + "','" + strUserID + "')"; //bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0); } return alt; } #endregion #region 根据SQL语句查询海运出口数据集 /// /// 返回 某字段 /// /// public DataSet GetFieldAllCTN(string strSQL) { DataSet DS = new DataSet(); try { string str = "select * from sys_announcectn where 1=1 " + strSQL + ""; DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); int ii = DS.Tables[0].Rows.Count; } catch { DS = null; } return DS; } #endregion /// /// 返回所有 分公司代码 /// /// 用户GID /// public String GetCORPID(string strUserID) { string str = "select COMPANYID from user_company where USERID='" + strUserID + "' and COMPANYID in (select GID from [company] where ISDELETED=0 and ISDISABLE=0)"; DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str); if (DS.Tables[0].Rows.Count > 0) { str = DS.Tables[0].Rows[0]["COMPANYID"].ToString(); } else { str = ""; } return str; } // /// /// 返回公告类型条数 /// /// 用户GID /// public String GetTYPENUM(string strUserID,int sNUM) { T_ALL_DA T_ALL_DA = new T_ALL_DA(); int itype = 0; string alt = T_ALL_DA.GetStrSQL("GID", "select GID from [user] where GID='" + strUserID + "' and ISDELETED=0 and ISDISABLE=0"); if (alt.Trim() == "") { alt = T_ALL_DA.GetStrSQL("GID", "select GID from [info_client] where GID='" + strUserID + "' and ISSTOP=0"); if (alt.Trim() != "") { itype = 2; } } else { itype = 1; } // string strDate = T_ALL_DA.GetStrSQL("strDate", "select getdate() as strDate"); strDate = " and BEGINTIME<='" + strDate + "' and ENDTIME>='" + strDate + "'"; // string strnum = T_ALL_DA.GetStrSQL("strnum", "select count(*) as strnum from sys_announce where type='" + itype + "' and ISDELETE=0 and ISISSUE=1 and gid not in(select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISCLOSE=0)" + strDate); if (sNUM == 1) { return strnum; } else if(sNUM == 2) { return itype.ToString(); } else { return itype + "," + strnum; } } // } }