using System; using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Data; 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 DSWeb.EntityDA; using System.Text; using System.Text.RegularExpressions; using DSWeb.WorkFlow; namespace DSWeb.Message { public partial class SysAnnounceClientGridSource : System.Web.UI.Page { private string strHandle; private string strUserID;//用户GID private string strCompanyID;//公司GID private string strShowName;//用户显示名 private string strDeptName;//部门名称 private string strSearch;//查询条件 private int iCurrentPage;//当前页数 private int iShowPage;//显示页数 public string strMessageGID;//消息GID private int iType;//消息类型 public string strType;//消息类型 private string strBillNO;//业务编号 private int iIncludeTop;//包含编号 private int iNotIncludeTop;//不包含编号 private int iCheckType;//查看类型 1-查看未读消息 2-查看已读消息 3-查看所有消息 private int iMsgInterval;//消息提醒设置间隔时间 public string strRowId;//消息类型 protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } else { if (Request.QueryString["clientgid"] != null) { strUserID = Request.QueryString["clientgid"].ToString(); Session["USERID"] = strUserID; } else { Server.Transfer("~/Error/FriendError.aspx"); return; } } if (Session["SHOWNAME"] != null) { strShowName = Session["SHOWNAME"].ToString(); } if (Session["COMPANYID"] != null) { strCompanyID = Session["COMPANYID"].ToString(); } if (Session["DEPTNAME"] != null) { strDeptName = Session["DEPTNAME"].ToString(); } if (Request.QueryString["handle"] != null) { strHandle = Request.QueryString["handle"].ToString(); } //if (Request.QueryString["search"] != null) //{ // strSearch = Request.QueryString["search"].ToString(); //} if (Request.QueryString["cur_page"] != null) { iCurrentPage = int.Parse(Request.QueryString["cur_page"].ToString().Trim()); } else { iCurrentPage = 0; } if (Request.QueryString["show_page"] != null) { iShowPage = int.Parse(Request.QueryString["show_page"].ToString().Trim()); } else { iShowPage = 0; } if (Request.QueryString["id"] != null) { strMessageGID = Request.QueryString["id"].ToString(); } if (Request.QueryString["rowId"] != null) { strRowId = Request.QueryString["rowId"].ToString(); } if (Request.QueryString["search"] != null) { UnicodeEncoding unicode = new UnicodeEncoding(); strSearch = unicode.GetString(unicode.GetBytes(Regex.Unescape(Request.QueryString["search"].ToString()))); } if (Request.QueryString["type"] != null) { iType = int.Parse(Request.QueryString["type"].ToString()); } else { iType = 0; } if (Request.QueryString["billno"] != null) { strBillNO = Request.QueryString["billno"].ToString(); } if (Request.QueryString["include"] != null) { iIncludeTop = int.Parse(Request.QueryString["include"].ToString()); } else { iIncludeTop = 0; } if (Request.QueryString["uninclude"] != null) { iNotIncludeTop = int.Parse(Request.QueryString["uninclude"].ToString()); } else { iNotIncludeTop = 0; } if (Request.QueryString["checktype"] != null) { iCheckType = int.Parse(Request.QueryString["checktype"].ToString()); } else { iCheckType = 0; } if (Request.QueryString["times"] != null) { iMsgInterval = int.Parse(Request.QueryString["times"].ToString()); } else { iMsgInterval = 0; } //公告 SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); strType = SysAnnounceDA.GetTYPENUM(strUserID, 2); if (strType != "0") { strType = String.Format(" AND TYPE = {0}", int.Parse(strType)); } else { strType=""; } //有效期 strType += " and convert(char(10),BEGINTIME,20)<=convert(char(10),getdate(),20) and convert(char(10),ENDTIME,20)>=convert(char(10),getdate(),20)"; // if (strHandle != null) { if (strHandle == "messagelist") { Response.Write(GetMessageList()); } if (strHandle == "messagelistpage") { Response.Write(GetMakeOutListPage()); } if (strHandle == "getmessageinfo" && strMessageGID != null) { Response.Write(GetMessageInfo(strMessageGID)); } if (strHandle == "setread" && strMessageGID != null) { Response.Write(SetMessageRead(strMessageGID));//标记为已读 } if (strHandle == "deletemessage") { Response.Write(DeleteMessage(strRowId, strUserID)); } if (strHandle == "getmessagecount" && strMessageGID != null) { Response.Write(GetMessageTopCount(strMessageGID)); } if (strHandle == "getmessagecount2" && strMessageGID != null) { Response.Write(GetMessageTopCount2(strMessageGID)); } if (strHandle == "messagepagelist") { Response.Write(GetMessagePageList()); } if (strHandle == "saveuserset" && iMsgInterval > 0) { Response.Write(SaveUserMessageSetting(iMsgInterval, strUserID)); } if (strHandle == "deleteuserset") { Response.Write(DeleteUserMessageSetting(strUserID)); } if (strHandle == "isclose")//如果已经打开 { Response.Write(getISCLOSE());// } if (strHandle == "getannouncetotal") { Response.Write(GetAnnounceTotal(strUserID)); } if (strHandle == "getlbgg") { Response.Write(getlbGG()); } if (strHandle == "getconfig") { Response.Write(getConfig()); } } } #region 返回config的公告秒数 /// /// 返回config的公告秒数 /// private int getConfig() { //公告 string strIntervalCountAnnounce = System.Configuration.ConfigurationSettings.AppSettings["announceinterval"].ToString() as string; if (strIntervalCountAnnounce != null) { int iTempCount = int.Parse(strIntervalCountAnnounce); if (iTempCount < 1000) { strIntervalCountAnnounce = "4000"; } } else { strIntervalCountAnnounce = "4000"; } return int.Parse(strIntervalCountAnnounce); } #endregion #region 用户消息数new /// /// 用户消息数new /// /// 用户GID /// 值1表示删除成功 值不等于1表示删除失败 private string getlbGG() { //公告 SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); string strAnnounce = ""; strAnnounce = SysAnnounceDA.GetTYPENUM(strUserID, 1); if (strAnnounce.Trim() != "") { strAnnounce = "公告(" + strAnnounce.Trim() + ")"; } else { strAnnounce = "公告(0)"; } return strAnnounce; } #endregion #region 获取消息统计总数 /// /// 获取消息统计总数 /// /// 接收人GID /// 返回接收人的消息统计信息 private string GetAnnounceTotal(string tempUserID) { StringBuilder totalBuilder = new StringBuilder(); // SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); int inum = int.Parse(SysAnnounceSetDA.GetTYPENUM(tempUserID)); // SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); IList SysAnnounceEntities = SysAnnounceDA.GetALLTYPE(tempUserID); if (SysAnnounceEntities.Count > 0) { totalBuilder.Append("{"); totalBuilder.Append("\"totals\":"); totalBuilder.Append("["); int iCount = SysAnnounceEntities.Count > 10 ? 10 : SysAnnounceEntities.Count; for (int i = 0; i < iCount; i++)// { if (i + 1 == SysAnnounceEntities.Count) { totalBuilder.Append("{"); totalBuilder.Append("\"gid\":\"" + SysAnnounceEntities[i].GID + "\","); totalBuilder.Append("\"unread\":" + (SysAnnounceEntities.Count - inum) + ","); totalBuilder.Append("\"description\":\"" + SysAnnounceEntities[i].DESCRIPTION + "\","); totalBuilder.Append("\"total\":" + SysAnnounceEntities.Count + ","); totalBuilder.Append("\"begintime\":\"" + SysAnnounceEntities[i].BEGINTIME + "\","); totalBuilder.Append("\"interval\":1"); totalBuilder.Append("}"); } else { totalBuilder.Append("{"); totalBuilder.Append("\"gid\":\"" + SysAnnounceEntities[i].GID + "\","); totalBuilder.Append("\"unread\":" + (SysAnnounceEntities.Count - inum) + ","); totalBuilder.Append("\"description\":\"" + SysAnnounceEntities[i].DESCRIPTION + "\","); totalBuilder.Append("\"total\":" + SysAnnounceEntities.Count + ","); totalBuilder.Append("\"begintime\":\"" + SysAnnounceEntities[i].BEGINTIME + "\","); totalBuilder.Append("\"interval\":1"); totalBuilder.Append("},"); } } totalBuilder.Append("]"); totalBuilder.Append("}"); } else { totalBuilder.Append("{"); totalBuilder.Append("\"totals\":"); totalBuilder.Append("["); totalBuilder.Append("{"); totalBuilder.Append("\"gid\":\"\","); totalBuilder.Append("\"unread\":0,"); totalBuilder.Append("\"description\":\"\","); totalBuilder.Append("\"total\":0,"); totalBuilder.Append("\"begintime\":\"\","); totalBuilder.Append("\"interval\":0"); totalBuilder.Append("}"); totalBuilder.Append("]"); totalBuilder.Append("}"); } return totalBuilder.ToString(); } #endregion #region 用户消息是否关闭 /// /// 用户消息是否关闭 /// /// 用户GID /// 值1表示删除成功 值不等于1表示删除失败 private int getISCLOSE() { T_ALL_DA T_ALL_DA = new T_ALL_DA(); int iResult = 0; string str = "insert into sys_announce_set(GID,CLIENTGID,InterVal,ANNOUNCEGID,DELETEUSER,ISCLOSE) SELECT newid(),'" + strUserID.Trim() + "',1,GID,'" + strUserID.Trim() + "','true' FROM sys_announce WHERE GID not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "') and ISDELETE=0 and ISISSUE=1 " + strType; bool bl = T_ALL_DA.GetExecuteSqlCommand(str); if (bl) { iResult = 1; } /* SysAnnounceEntity SysAnnounceEntity = new SysAnnounceEntity(); SysAnnounceSetEntity SysAnnounceSetEntity = new SysAnnounceSetEntity(); SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); DataSet ds = SysAnnounceSetDA.GetExcuteSql("SELECT * FROM sys_announce WHERE GID not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "') and ISDELETE=0 and ISISSUE=1 " + strType); if (ds != null) { if (ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { SysAnnounceSetEntity.GID = getBSNO(); SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = ds.Tables[0].Rows[i]["GID"].ToString().Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = true; // iResult = SysAnnounceSetDA.InsertUserMsgSetting(SysAnnounceSetEntity); if (iResult > 0) { } else { } } } } */ return iResult; } #endregion #region 删除用户消息设置 /// /// 删除用户消息设置 /// /// 用户GID /// 值1表示删除成功 值不等于1表示删除失败 private int DeleteUserMessageSetting(string tempUserID) { int iResult = 0; UserMessageSettingDA userMessageSettingDA = new UserMessageSettingDA(); UserMessageSettingEntity userMessageSettingEntity = userMessageSettingDA.GetUserMsgSettingByUserID(tempUserID); if (userMessageSettingEntity != null) { if (userMessageSettingEntity.GID != null) { iResult = userMessageSettingDA.DeleteUserMsgSetting(tempUserID); } } return iResult; } #endregion #region 保存用户消息提醒设置 /// /// 保存用户消息提醒设置 /// /// 消息提醒间隔时间 /// 值1表示保存成功 值不等于1表示保存失败 private int SaveUserMessageSetting(int tempMsgInterval, string tempUserID) { int iResult = 0; UserMessageSettingDA userMessageSettingDA = new UserMessageSettingDA(); UserMessageSettingEntity userMessageSettingEntity = userMessageSettingDA.GetUserMsgSettingByUserID(tempUserID); if (userMessageSettingEntity != null) { if (userMessageSettingEntity.GID != null) { userMessageSettingEntity.MessageInterVal = tempMsgInterval; iResult = userMessageSettingDA.UpdateUserMsgSetting(userMessageSettingEntity); } else { userMessageSettingEntity.GID = Guid.NewGuid().ToString(); userMessageSettingEntity.UserID = tempUserID; userMessageSettingEntity.MessageInterVal = tempMsgInterval; iResult = userMessageSettingDA.InsertUserMsgSetting(userMessageSettingEntity); } } else { userMessageSettingEntity = new UserMessageSettingEntity(); userMessageSettingEntity.GID = Guid.NewGuid().ToString(); userMessageSettingEntity.UserID = tempUserID; userMessageSettingEntity.MessageInterVal = tempMsgInterval; iResult = userMessageSettingDA.InsertUserMsgSetting(userMessageSettingEntity); } return iResult; } #endregion /// /// 获取上一条、下一条消息提醒信息 /// /// public string GetMessagePageList() { string strSql = ""; SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); string strCondition = ""; switch (iCheckType) { case 1: strCondition = " AND gid not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and (ISCLOSE=0 or ISDELETE=1))"; break; case 2: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=0 and ISCLOSE=0)"; break; case 4: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1)"; break; default: break; } StringBuilder messageBuilder = new StringBuilder(); if (iIncludeTop >= 1 && iNotIncludeTop >= 1) { strSql = String.Format(" SELECT TOP {0} 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 GID NOT IN ('" + strMessageGID + "') {1} " + strCondition + strType + " ORDER BY CREATETIME DESC ", iIncludeTop,(iNotIncludeTop > 1 ? " AND GID NOT IN(SELECT TOP " + iNotIncludeTop + " GID FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND ISNULL(ISDELETE,0) <> 1 " + strCondition + strType + " AND GID NOT IN ('" + strMessageGID + "') ORDER BY CREATETIME DESC) " : "")); DataTable sourceTable = SysAnnounceSetDA.GetExcuteSql(strSql).Tables[0]; if (sourceTable != null) { if (sourceTable.Rows.Count > 0) { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"" + sourceTable.Rows[0]["GID"].ToString() + "\","); messageBuilder.Append("\"desc\":\"" + sourceTable.Rows[0]["DESCRIPTION"].ToString() + "\","); messageBuilder.Append("\"content\":\"" + sourceTable.Rows[0]["ANNOUNCECONTENT"].ToString() + "\","); messageBuilder.Append("\"type\":" + sourceTable.Rows[0]["TYPE"].ToString() + ","); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); if (messageBuilder.ToString().Trim() != "") { SysAnnounceSetDA SysAnnounceSetDA1 = new SysAnnounceSetDA(); SysAnnounceSetEntity SysAnnounceSetEntity = new SysAnnounceSetEntity(); int iRt = 0; // T_ALL_DA T_ALL_DA = new T_ALL_DA(); string strGID = T_ALL_DA.GetStrSQL("ANNOUNCEGID", "SELECT ANNOUNCEGID FROM sys_announce_set WHERE CLIENTGID = '" + strUserID + "' and ANNOUNCEGID='" + sourceTable.Rows[0]["GID"].ToString().Trim() + "'"); // if (strGID == "") { SysAnnounceSetEntity.GID = getBSNO(); SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = sourceTable.Rows[0]["GID"].ToString().Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iRt = SysAnnounceSetDA1.InsertUserMsgSetting(SysAnnounceSetEntity); } else { SysAnnounceSetEntity.GID = strGID; SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = sourceTable.Rows[0]["GID"].ToString().Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iRt = SysAnnounceSetDA1.UpdateUserMsgISCLOSE(SysAnnounceSetEntity);//已经读了 } // if (iRt > 0) { } else { } } } else { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); } } else { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); } } else { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); } return messageBuilder.ToString(); } protected String getBSNO() { string strBSNO = Guid.NewGuid().ToString(); strBSNO = strBSNO.Replace("-", ""); strBSNO = "Ann" + strBSNO; return strBSNO; } #region 获取消息上端总数 /// /// 获取消息上端总数 /// /// 消息GID /// 返回消息上端总数 private int GetMessageTopCount(string tempMessageGID) { int iResult = 0; SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); string strCondition = ""; switch (iCheckType) { case 1: strCondition = " AND gid not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1)";// and (ISCLOSE=0 or ISDELETE=1) break; case 2: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=0)";// and ISCLOSE=0 break; case 4: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1)"; break; default: break; } string strSql = String.Format(" SELECT COUNT(*) FROM (SELECT * FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND CREATETIME>=(SELECT CREATETIME FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND GID = '{0}') " + " AND GID NOT IN ('{0}') " + strCondition + strType + ") as A ", tempMessageGID); DataTable sourceTable = SysAnnounceSetDA.GetExcuteSql(strSql).Tables[0]; if (sourceTable != null) { iResult = int.Parse(sourceTable.Rows[0][0].ToString()); } return iResult; } #endregion #region 获取消息上端总数 /// /// 获取消息上端总数 /// /// 消息GID /// 返回消息上端总数 private int GetMessageTopCount2(string tempMessageGID) { int iResult = 0; SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); string strCondition = ""; switch (iCheckType) { case 1: strCondition = " AND gid not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1)";// and (ISCLOSE=0 or ISDELETE=1) break; case 2: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=0)"; //and ISCLOSE=0 break; case 4: strCondition = " AND gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1)"; break; default: break; } string strSql = String.Format(" SELECT COUNT(*) FROM (SELECT * FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND CREATETIME < (SELECT CREATETIME FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND GID = '{0}') " + " AND GID NOT IN ('{0}') " + strCondition + strType + ") as A ", tempMessageGID); DataTable sourceTable = SysAnnounceSetDA.GetExcuteSql(strSql).Tables[0]; if (sourceTable != null) { iResult = int.Parse(sourceTable.Rows[0][0].ToString()); } return iResult; } #endregion #region 删除消息 /// /// 删除消息 /// /// 消息GID /// 操作人GID /// 值1表示删除成功 值不等1表示删除失败 public int DeleteMessage(string strRowId, string tempUserID) { int iResult = 0; SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); string[] sDel = strRowId.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < sDel.Length; i++) { SysAnnounceSetEntity SysAnnounceSetEntity = new SysAnnounceSetEntity(); int iRt = 0; T_ALL_DA T_ALL_DA = new T_ALL_DA(); string strGID = T_ALL_DA.GetStrSQL("GID", "SELECT GID FROM sys_announce_set WHERE CLIENTGID = '" + tempUserID + "' and ANNOUNCEGID='" + sDel[i].ToString().Trim() + "'"); if (strGID == "") { SysAnnounceSetEntity.GID = getBSNO(); SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = sDel[i].ToString().Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iRt = SysAnnounceSetDA.InsertUserMsgSetting(SysAnnounceSetEntity); } else { SysAnnounceSetEntity.GID = strGID; SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = sDel[i].ToString().Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iRt = SysAnnounceSetDA.UpdateUserMsgISCLOSE(SysAnnounceSetEntity);//已经读了 } // if (iRt > 0) { } else { } } strRowId = strRowId.Trim().Replace(",", "' or ANNOUNCEGID='"); iResult = SysAnnounceSetDA.DeleteGID("UPDATE sys_announce_set SET ISDELETE=1,DELETETIME = GETDATE(),DELETEUSER='" + tempUserID + "' where (ANNOUNCEGID='" + strRowId + "') and CLIENTGID='" + tempUserID + "'"); return iResult; } #endregion #region 置消息状态为已读 /// /// 置消息状态为已读 /// /// 消息GID /// 值1表示置消息已读状态成功 值不等于1表示置消息已读状态失败 public int SetMessageRead(string tempMessageGID) { int iResult = 0; SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); SysAnnounceSetEntity SysAnnounceSetEntity = new SysAnnounceSetEntity(); T_ALL_DA T_ALL_DA = new T_ALL_DA(); string strGID = T_ALL_DA.GetStrSQL("GID", "SELECT GID FROM sys_announce_set WHERE CLIENTGID = '" + strUserID + "' and ANNOUNCEGID='" + tempMessageGID.Trim() + "'"); if (strGID == "") { SysAnnounceSetEntity.GID = getBSNO(); SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = tempMessageGID.Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iResult = SysAnnounceSetDA.InsertUserMsgSetting(SysAnnounceSetEntity); } else { SysAnnounceSetEntity.GID = strGID; SysAnnounceSetEntity.CLIENTGID = strUserID.Trim(); SysAnnounceSetEntity.InterVal = 1; SysAnnounceSetEntity.ANNOUNCEGID = tempMessageGID.Trim(); SysAnnounceSetEntity.DELETEUSER = strUserID.Trim(); SysAnnounceSetEntity.ISCLOSE = false; iResult = SysAnnounceSetDA.UpdateUserMsgISCLOSE(SysAnnounceSetEntity);//已经读了 } // if (iResult > 0) { } else { } return iResult; } #endregion #region 根据消息GID获取消息信息 /// /// 根据消息GID获取消息信息 /// /// 消息GID /// 返回JSON消息信息 private string GetMessageInfo(string strMessageGID) { bool isNull = true; StringBuilder messageBuilder = new StringBuilder(); SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); SysAnnounceEntity SysAnnounceEntity = new SysAnnounceEntity(); SysAnnounceEntity = SysAnnounceDA.GetID(strMessageGID); if (SysAnnounceEntity != null) { if (SysAnnounceEntity.GID != null) { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"" + SysAnnounceEntity.GID + "\","); messageBuilder.Append("\"desc\":\"" + SysAnnounceEntity.DESCRIPTION + "\","); messageBuilder.Append("\"content\":\"" + SysAnnounceEntity.ANNOUNCECONTENT + "\","); messageBuilder.Append("\"type\":" + SysAnnounceEntity.TYPE + ","); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); isNull = false; } } //如果未取到相关消息信息,则创建空JSON数据 if (isNull) { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); isNull = false; } //return messageBuilder.ToString(); return SysAnnounceEntity.ANNOUNCECONTENT.ToString(); } #endregion #region 获取已开出发票页总数 /// /// 获取已开出发票页总数 /// /// 返回总页数 private int GetMakeOutListPage() { SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); // string strSql = "SELECT COUNT(*) FROM sys_announce as A WHERE ISISSUE=1 and ISDELETE=0 AND ISNULL(ISDELETE,0) <> 1 " + strType; string strCondition = ""; if (strSearch != null) { if (!strSearch.Trim().Equals("")) { string tempSearch = strSearch; tempSearch = tempSearch.Replace("{", ""); tempSearch = tempSearch.Replace("}", ""); tempSearch = tempSearch.Replace("[", ""); tempSearch = tempSearch.Replace("]", ""); string[] searchArg = tempSearch.Split(new char[] { ',' }); for (int i = 0; i < searchArg.Length; i++) { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "btime"://begin time // strCondition += String.Format(" AND A.CREATETIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", "")); // break; //case "etime"://end time // strCondition += String.Format(" AND A.CREATETIME <= '{0} 23:59:59' ", strArg[1].Replace("\"", "")); // break; //case "content"://message content // strCondition += String.Format(" AND A.MESSAGECONTENT LIKE '%{0}%' ", strArg[1].Replace("\"", "")); // break; //case "type"://message type // strCondition += String.Format(" AND A.TYPE = {0}", strArg[1].Replace("\"", "")); // break; case "read"://message isread int checkRead = int.Parse(strArg[1].Replace("\"", "").Trim()); if (checkRead == 1) { strCondition += String.Format(" AND A.gid not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and (ISCLOSE=0 or ISDELETE=1))", (checkRead == 1 ? 0 : 1)); } else if (checkRead == 2) { strCondition += String.Format(" AND A.gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=0 and ISDELETE=0 and ISCLOSE=0)", (checkRead == 1 ? 0 : 1)); } else if (checkRead == 4) { strCondition += String.Format(" AND A.gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1 and ISDELETE=1)", (checkRead == 1 ? 0 : 1)); } break; default: break; } } } strSql += strCondition; } } int iTotal = int.Parse(SysAnnounceSetDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString()); return iTotal; } #endregion private string GetMessageList() { SysAnnounceDA SysAnnounceDA = new SysAnnounceDA(); SysAnnounceSetDA SysAnnounceSetDA = new SysAnnounceSetDA(); DataTable sourceTable; string strCondition = ""; string strTopInclude = ""; string strTopNotInclude = ""; if (strSearch != null) { if (!strSearch.Trim().Equals("")) { string tempSearch = strSearch; tempSearch = tempSearch.Replace("{", ""); tempSearch = tempSearch.Replace("}", ""); tempSearch = tempSearch.Replace("[", ""); tempSearch = tempSearch.Replace("]", ""); string[] searchArg = tempSearch.Split(new char[] { ',' }); for (int i = 0; i < searchArg.Length; i++) { string[] strArg = searchArg[i].Split(new char[] { ':' }); if (!strArg[1].Replace("\"", "").Trim().Equals("")) { switch (strArg[0].Replace("\"", "")) { //case "btime"://begin time // strCondition += String.Format(" AND A.CREATETIME >= '{0} 00:00:00' ", strArg[1].Replace("\"", "")); // break; //case "etime"://end time // strCondition += String.Format(" AND A.CREATETIME <= '{0} 23:59:59' ", strArg[1].Replace("\"", "")); // break; //case "content"://message content // strCondition += String.Format(" AND A.MESSAGECONTENT LIKE '%{0}%' ", strArg[1].Replace("\"", "")); // break; //case "type"://message type // break; case "read"://message isread int checkRead = int.Parse(strArg[1].Replace("\"", "").Trim()); if (checkRead == 1) { strCondition += String.Format(" AND A.gid not in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and (ISCLOSE=0 or ISDELETE=1))", (checkRead == 1 ? 0 : 1)); } else if (checkRead == 2) { strCondition += String.Format(" AND A.gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=0 and ISDELETE=0 and ISCLOSE=0)", (checkRead == 1 ? 0 : 1)); } else if (checkRead == 4) { strCondition += String.Format(" AND A.gid in (select ANNOUNCEGID from sys_announce_set where CLIENTGID='" + strUserID + "' and ISDELETE=1 and ISDELETE=1)", (checkRead == 1 ? 0 : 1)); } break; default: break; } } } } } ////公告 //string strTYPE = ""; //strTYPE = SysAnnounceDA.GetTYPENUM(strUserID, 2); //if (strTYPE != "0") //{ // strCondition += String.Format(" AND A.TYPE = {0}", int.Parse(strTYPE)); //} //// string strSql = ""; if (iCurrentPage > 0 && iShowPage > 0) { if (iCurrentPage == 1) { strSql = String.Format(" SELECT {0} A.GID,A.DESCRIPTION,A.BEGINTIME " + " FROM sys_announce as A WHERE A.ISISSUE=1 and A.ISDELETE=0 AND ISNULL(ISDELETE,0) <> 1 " + strCondition + strType + " ORDER BY A.CREATETIME DESC ", "top " + iShowPage.ToString()); } else { strTopNotInclude = "top " + (iShowPage * (iCurrentPage - 1)).ToString();//RowCount*PageNum strTopInclude = "top " + iShowPage.ToString(); strSql = String.Format(" SELECT {0} A.GID,A.DESCRIPTION,A.BEGINTIME " + " FROM sys_announce as A " + " (SELECT {1} GID FROM sys_announce WHERE ISISSUE=1 and ISDELETE=0 AND ISNULL(ISDELETE,0) <> 1 " + strCondition + strType + " ORDER BY CREATETIME DESC ) AND ISNULL(ISDELETE,0) <> 1 " + strCondition + strType + " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude); } } else { strSql = " SELECT {0} A.GID,A.DESCRIPTION,A.BEGINTIME " + " FROM sys_announce as A WHERE ISISSUE=1 and ISDELETE=0 AND ISNULL(ISDELETE,0) <> 1 " + strCondition + strType + " ORDER BY A.CREATETIME DESC "; } sourceTable = getStatusNameTable(SysAnnounceSetDA.GetExcuteSql(strSql).Tables[0]); StringBuilder sourceBuilder = new StringBuilder(); sourceBuilder.Append("{"); sourceBuilder.Append("rows:["); for (int i = 0; i < sourceTable.Rows.Count; i++) { sourceBuilder.Append("{id:\"" + sourceTable.Rows[i][0].ToString() + "\","); sourceBuilder.Append("data:["); sourceBuilder.Append("\"0\","); for (int j = 1; j < sourceTable.Columns.Count; j++) { if (j == sourceTable.Columns.Count - 1) { sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\""); } else { sourceBuilder.Append("\"" + sourceTable.Rows[i][j].ToString() + "\","); } } if (i == sourceTable.Rows.Count - 1) { sourceBuilder.Append("]}"); } else { sourceBuilder.Append("]},"); } } sourceBuilder.Append("]"); sourceBuilder.Append("}"); return sourceBuilder.ToString(); } #region 将数据集表中费用状态type的数字状态位转换成文字 /// /// 将数据集表中费用状态type的数字状态位转换成文字 /// /// 原数据源DataTable /// 返回新数据源DataTable private DataTable getStatusNameTable(DataTable tempTable) { DataTable sourceTable = tempTable; DataTable cloneTable = new DataTable(); int iSwitch = 0; for (int i = 0; i < sourceTable.Rows.Count; i++) { if (iSwitch == 0) { for (int j = 0; j < sourceTable.Columns.Count; j++) { if (sourceTable.Columns[j].ColumnName.Equals("TYPE")) { DataColumn newColumn = new DataColumn(); newColumn.ColumnName = sourceTable.Columns[j].ColumnName; newColumn.DataType = System.Type.GetType("System.String"); cloneTable.Columns.Add(newColumn); } else { DataColumn newColumn = new DataColumn(); newColumn.ColumnName = sourceTable.Columns[j].ColumnName; newColumn.DataType = sourceTable.Columns[j].DataType; cloneTable.Columns.Add(newColumn); } } iSwitch = 1; } DataRow cloneRow = cloneTable.NewRow(); for (int k = 0; k < sourceTable.Columns.Count; k++) { if (sourceTable.Columns[k].ColumnName.Equals("TYPE")) { int iFeeStatus = int.Parse(sourceTable.Rows[i][k].ToString()); string strFeeStatus = ""; switch (iFeeStatus) { case 1: strFeeStatus = "应收应付费用审核"; break; case 2: strFeeStatus = "付费结算"; break; case 3: strFeeStatus = "付费申请审核"; break; case 4: strFeeStatus = "发票开出"; break; case 5: strFeeStatus = "发票申请"; break; case 6: strFeeStatus = "申请电放审核"; break; case 7: strFeeStatus = "费用审核通过"; break; case 8: strFeeStatus = "费用审核驳回"; break; case 9: strFeeStatus = "费用更改申请"; break; case 10: strFeeStatus = "销售订舱审核申请"; break; default: break; } cloneRow[sourceTable.Columns[k].ColumnName] = strFeeStatus; } else { cloneRow[sourceTable.Columns[k].ColumnName] = sourceTable.Rows[i][k]; } } cloneTable.Rows.Add(cloneRow); } return cloneTable; } #endregion } }