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 DSCustomer.Message { public partial class MessageService : PageBase { 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;//显示页数 private string strMessageGID;//消息GID private int iType;//消息类型 private string strBillNO;//业务编号 private int iIncludeTop;//包含编号 private int iNotIncludeTop;//不包含编号 private int iCheckType;//查看类型 1-查看未读消息 2-查看已读消息 3-查看所有消息 private int iMsgInterval;//消息提醒设置间隔时间 protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] != null) { strUserID = Session["USERID"].ToString(); } 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["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; } if (strHandle != null) { if (strHandle == "messagelist") { Response.Write(GetMessageList()); } if (strHandle == "messagelistpage") { Response.Write(GetMakeOutListPage()); } if (strHandle == "messagetotal") { Response.Write(GetMessageTotal(strUserID)); } if (strHandle == "getmessageinfo" && strMessageGID != null) { Response.Write(GetMessageInfo(strMessageGID)); } if (strHandle == "setread" && strMessageGID != null) { Response.Write(SetMessageRead(strMessageGID)); } if (strHandle == "deletemessage" && strMessageGID != null) { Response.Write(DeleteMessage(strMessageGID,strUserID)); } if (strHandle == "postmessage" && iType != 0) { Response.Write(PostMessage(iType,strShowName,strBillNO)); } if (strHandle == "getmessagecount" && strMessageGID != null) { Response.Write(GetMessageTopCount(strMessageGID)); } if (strHandle == "messagepagelist") { Response.Write(GetMessagePageList()); } if (strHandle == "saveuserset" && iMsgInterval > 0) { Response.Write(SaveUserMessageSetting(iMsgInterval,strUserID)); } } } #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 = ""; MessageDA messageDA = new MessageDA(); string strCondition = ""; switch (iCheckType) { case 1: strCondition = " AND ISNULL(ISREAD,0) <> 1"; break; case 2: strCondition = " AND ISNULL(ISREAD,0) = 1"; break; case 3: break; default: break; } StringBuilder messageBuilder = new StringBuilder(); if (iIncludeTop >= 1 && iNotIncludeTop >= 1) { strSql = String.Format(" SELECT TOP {0} GID,NAME,DESCRIPTION,CREATETIME,ISREAD,READCOUNT,MESSAGECONTENT,LASTREADTIME,RECEIVER,TYPE,TASKURL,TASKID " + " FROM sys_message WHERE 1 > 0 {1} " + strCondition + " ORDER BY CREATETIME DESC ", iIncludeTop, (iNotIncludeTop > 1 ? " AND GID NOT IN(SELECT TOP " + iNotIncludeTop + " GID FROM sys_message WHERE ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY CREATETIME DESC) " : "")); DataTable sourceTable = messageDA.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("\"name\":\"" + sourceTable.Rows[0]["NAME"].ToString() + "\","); messageBuilder.Append("\"desc\":\"" + sourceTable.Rows[0]["DESCRIPTION"].ToString() + "\","); messageBuilder.Append("\"isread\":" + (sourceTable.Rows[0]["ISREAD"].ToString().ToLower().Equals("true") ? 1 : 0) + ","); messageBuilder.Append("\"time\":\"" + sourceTable.Rows[0]["CREATETIME"].ToString() + "\","); messageBuilder.Append("\"count\":" + sourceTable.Rows[0]["READCOUNT"].ToString() + ","); messageBuilder.Append("\"content\":\"" + sourceTable.Rows[0]["MESSAGECONTENT"].ToString() + "\","); messageBuilder.Append("\"type\":" + sourceTable.Rows[0]["TYPE"].ToString() + ","); messageBuilder.Append("\"url\":\"" + sourceTable.Rows[0]["TASKURL"].ToString() + "\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); } else { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"\","); messageBuilder.Append("\"name\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"isread\":0,"); messageBuilder.Append("\"time\":\"\","); messageBuilder.Append("\"count\":0,"); 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("\"name\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"isread\":0,"); messageBuilder.Append("\"time\":\"\","); messageBuilder.Append("\"count\":0,"); 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("\"name\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"isread\":0,"); messageBuilder.Append("\"time\":\"\","); messageBuilder.Append("\"count\":0,"); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); } return messageBuilder.ToString(); } #region 获取消息上端总数 /// /// 获取消息上端总数 /// /// 消息GID /// 返回消息上端总数 private int GetMessageTopCount(string tempMessageGID) { int iResult = 0; MessageDA messageDA = new MessageDA(); string strCondition = ""; switch (iCheckType) { case 1: strCondition = " AND ISNULL(ISREAD,0) <> 1"; break; case 2: strCondition = " AND ISNULL(ISREAD,0) = 1"; break; case 3: break; default: break; } string strSql = String.Format(" SELECT COUNT(*) FROM (SELECT * FROM sys_message WHERE CREATETIME >= (SELECT CREATETIME FROM sys_message WHERE GID = '{0}') " + " AND GID NOT IN ('{0}') " + strCondition + ") as A ", tempMessageGID); DataTable sourceTable = messageDA.GetExcuteSql(strSql).Tables[0]; if (sourceTable != null) { iResult = int.Parse(sourceTable.Rows[0][0].ToString()); } return iResult; } #endregion private int PostMessage(int tempType,string tempShowName,string tempBillNO) { int iResult = 0; MessageDA messageDA = new MessageDA(); MessageType messageType = messageDA.GetMessageTypeNum(iType); IList messageEntities = new List(); WorkFlowDoDA workFlowDoDA = new WorkFlowDoDA(); IList workFlowDoEntities = new List(); //工作流 WorkFlowHelper workFlowHelper = new WorkFlowHelper(); //查找付费工作流信息 WorkFlowEntity workFlowEntity = workFlowHelper.FindWorkFlow(WorkFlowType.FEEAUDIT); switch (messageType) { case MessageType.FEEAUDIT: //如果工作流信息存在 if (workFlowEntity != null) { workFlowDoEntities = workFlowDoDA.GetWorkFlowDoForMessage(workFlowEntity.GID, tempBillNO); if (workFlowDoEntities.Count > 0) { foreach (WorkFlowDoEntity workFlowDo in workFlowDoEntities) { if (!workFlowDo.IsFinish) { MessageEntity messageEntity = new MessageEntity(); messageEntity.GID = Guid.NewGuid().ToString(); messageEntity.Name = "FeeAudit"; messageEntity.Description = "应收应付待审核通知"; messageEntity.IsRead = false; messageEntity.ReadCount = 0; messageEntity.MessageContent = tempShowName + " 提交 [应收应付费用审核] 申请 "; messageEntity.TaskID = ""; messageEntity.Receiver = workFlowDo.Auditor; messageEntity.TaskUrl = "auditprocess/feeaudit.aspx"; messageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDIT); messageEntities.Add(messageEntity); } } if (messageEntities.Count > 0) { messageDA.CreateMessage(MessageType.FEEAUDIT, messageEntities); } } } break; case MessageType.FEEPAY: break; case MessageType.FEEPAYAPP: break; case MessageType.INVOICE: break; case MessageType.INVOICEAPP: break; case MessageType.FEEAUDITPASS: int iWorkFlowStepID = 0; int iApplicantState = 0; //如果工作流信息存在 if (workFlowEntity != null) { workFlowDoEntities = workFlowDoDA.GetWorkFlowDoAuditPassForMessage(workFlowEntity.GID, tempBillNO); IList otherWorkFlowDoEntities = new List(); if (workFlowDoEntities.Count > 0) { foreach (WorkFlowDoEntity workFlowDo in workFlowDoEntities) { foreach (WorkFlowStepEntity workFlowStepEntity in workFlowEntity.WorkFlowSteps) { if (workFlowStepEntity.StepNO == workFlowDo.StepNO) { if (workFlowStepEntity.IsLast) { if (!workFlowDo.IsFinish) { MessageEntity messageEntity = new MessageEntity(); messageEntity.GID = Guid.NewGuid().ToString(); messageEntity.Name = "FeeAudit"; messageEntity.Description = "应收应付待审核通知"; messageEntity.IsRead = false; messageEntity.ReadCount = 0; messageEntity.MessageContent = tempShowName + " 已批准 [应收应付费用审核] 审核,当前等待您的审核 "; messageEntity.TaskID = ""; messageEntity.Receiver = workFlowDo.Auditor; messageEntity.TaskUrl = "auditprocess/feeaudit.aspx"; messageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDIT); messageEntities.Add(messageEntity); if (iApplicantState == 0) { MessageEntity applicantMessageEntity = new MessageEntity(); applicantMessageEntity.GID = Guid.NewGuid().ToString(); applicantMessageEntity.Name = "FeeAudit"; applicantMessageEntity.Description = "应收应付待审核通知"; applicantMessageEntity.IsRead = false; applicantMessageEntity.ReadCount = 0; applicantMessageEntity.MessageContent = tempShowName + " 已经批准通过 [应收应付费用审核] 申请,现等待下一步审核 "; applicantMessageEntity.TaskID = ""; applicantMessageEntity.Receiver = workFlowDo.Applicant; applicantMessageEntity.TaskUrl = "shipping/orderlist.aspx"; applicantMessageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDIT); messageEntities.Add(applicantMessageEntity); iApplicantState++; } break; } else { if (iApplicantState == 0) { MessageEntity applicantMessageEntity = new MessageEntity(); applicantMessageEntity.GID = Guid.NewGuid().ToString(); applicantMessageEntity.Name = "FeeAudit"; applicantMessageEntity.Description = "应收应付待审核通知"; applicantMessageEntity.IsRead = false; applicantMessageEntity.ReadCount = 0; applicantMessageEntity.MessageContent = tempShowName + " 已经批准通过 [应收应付费用审核] 申请,全部审核已完成 "; applicantMessageEntity.TaskID = ""; applicantMessageEntity.Receiver = workFlowDo.Applicant; applicantMessageEntity.TaskUrl = "shipping/orderlist.aspx"; applicantMessageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDIT); messageEntities.Add(applicantMessageEntity); iApplicantState++; } break; } } //else //{ // MessageEntity messageEntity = new MessageEntity(); // messageEntity.GID = Guid.NewGuid().ToString(); // messageEntity.Name = "FeeAudit"; // messageEntity.Description = "应收应付待审核通知"; // messageEntity.IsRead = false; // messageEntity.ReadCount = 0; // messageEntity.MessageContent = tempShowName + " 已批准 [应收应付费用审核] 审核,当前等待您的审核 "; // messageEntity.TaskID = ""; // messageEntity.Receiver = workFlowDo.Auditor; // messageEntity.TaskUrl = "auditprocess/feeaudit.aspx"; // messageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDIT); // messageEntities.Add(messageEntity); //} } } } if (messageEntities.Count > 0) { messageDA.CreateMessage(MessageType.FEEAUDIT, messageEntities); } } } break; case MessageType.FEEAUDITREJECT: //如果工作流信息存在 if (workFlowEntity != null) { workFlowDoEntities = workFlowDoDA.GetWorkFlowDoAuditRejectForMessage(workFlowEntity.GID, tempBillNO); if (workFlowDoEntities.Count > 0) { foreach (WorkFlowDoEntity workFlowDo in workFlowDoEntities) { MessageEntity applicantMessageEntity = new MessageEntity(); applicantMessageEntity.GID = Guid.NewGuid().ToString(); applicantMessageEntity.Name = "FeeAudit"; applicantMessageEntity.Description = "应收应付待审核通知"; applicantMessageEntity.IsRead = false; applicantMessageEntity.ReadCount = 0; applicantMessageEntity.MessageContent = tempShowName + " 驳回 [应收应付费用审核] 申请 "; applicantMessageEntity.TaskID = ""; applicantMessageEntity.Receiver = workFlowDo.Applicant; applicantMessageEntity.TaskUrl = "shipping/orderlist.aspx"; applicantMessageEntity.Type = messageDA.GetMessageType(MessageType.FEEAUDITREJECT); messageEntities.Add(applicantMessageEntity); } if (messageEntities.Count > 0) { messageDA.CreateMessage(MessageType.FEEAUDITREJECT, messageEntities); } } } break; default: break; } return iResult; } #region 删除消息 /// /// 删除消息 /// /// 消息GID /// 操作人GID /// 值1表示删除成功 值不等1表示删除失败 public int DeleteMessage(string tempMessageGID,string tempUserID) { int iResult = 0; MessageDA messageDA = new MessageDA(); iResult = messageDA.DeleteMessage(tempMessageGID, tempUserID); return iResult; } #endregion #region 置消息状态为已读 /// /// 置消息状态为已读 /// /// 消息GID /// 值1表示置消息已读状态成功 值不等于1表示置消息已读状态失败 public int SetMessageRead(string tempMessageGID) { int iResult = 0; MessageDA messageDA = new MessageDA(); iResult = messageDA.DoMessageRead(tempMessageGID); return iResult; } #endregion #region 根据消息GID获取消息信息 /// /// 根据消息GID获取消息信息 /// /// 消息GID /// 返回JSON消息信息 private string GetMessageInfo(string strMessageGID) { bool isNull = true; StringBuilder messageBuilder = new StringBuilder(); MessageDA messageDA = new MessageDA(); MessageEntity messageEntity = new MessageEntity(); messageEntity = messageDA.GetMessageByGID(strMessageGID); if (messageEntity != null) { if (messageEntity.GID != null) { messageBuilder.Append("{"); messageBuilder.Append("\"message\":"); messageBuilder.Append("["); messageBuilder.Append("{"); messageBuilder.Append("\"id\":\"" + messageEntity.GID + "\","); messageBuilder.Append("\"name\":\"" + messageEntity.Name + "\","); messageBuilder.Append("\"desc\":\"" + messageEntity.Description + "\","); messageBuilder.Append("\"isread\":" + (messageEntity.IsRead ? 1 : 0) + ","); messageBuilder.Append("\"time\":\"" + messageEntity.CreateTime.ToString() + "\","); messageBuilder.Append("\"count\":" + messageEntity.ReadCount + ","); messageBuilder.Append("\"content\":\"" + messageEntity.MessageContent + "\","); messageBuilder.Append("\"type\":" + messageEntity.Type + ","); messageBuilder.Append("\"url\":\"" + messageEntity.TaskUrl + "\""); 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("\"name\":\"\","); messageBuilder.Append("\"desc\":\"\","); messageBuilder.Append("\"isread\":0,"); messageBuilder.Append("\"time\":\"\","); messageBuilder.Append("\"count\":0,"); messageBuilder.Append("\"content\":\"\","); messageBuilder.Append("\"type\":0,"); messageBuilder.Append("\"url\":\"\""); messageBuilder.Append("}"); messageBuilder.Append("]"); messageBuilder.Append("}"); isNull = false; } return messageBuilder.ToString(); } #endregion #region 获取消息统计总数 /// /// 获取消息统计总数 /// /// 接收人GID /// 返回接收人的消息统计信息 private string GetMessageTotal(string tempUserID) { MessageDA messageDA = new MessageDA(); MessageTotalEntity messageTotal = messageDA.GetMessageTotalByReceiver(tempUserID); UserMessageSettingDA userMessageSettingDA = new UserMessageSettingDA(); UserMessageSettingEntity userMessageSettingEntity = userMessageSettingDA.GetUserMsgSettingByUserID(tempUserID); int iMsgInterVal = 0; if (userMessageSettingEntity != null) { if (userMessageSettingEntity.GID != null) { iMsgInterVal = userMessageSettingEntity.MessageInterVal; } } StringBuilder totalBuilder = new StringBuilder(); if (messageTotal != null) { totalBuilder.Append("{"); totalBuilder.Append("\"totals\":"); totalBuilder.Append("["); totalBuilder.Append("{"); totalBuilder.Append("\"read\":" + messageTotal.ReadTotal + ","); totalBuilder.Append("\"unread\":" + messageTotal.UnreadTotal + ","); totalBuilder.Append("\"receiver\":\"" + messageTotal.Receiver + "\","); totalBuilder.Append("\"total\":" + messageTotal.Total+","); totalBuilder.Append("\"interval\":" + iMsgInterVal); totalBuilder.Append("}"); totalBuilder.Append("]"); totalBuilder.Append("}"); } else { totalBuilder.Append("{"); totalBuilder.Append("\"totals\":"); totalBuilder.Append("["); totalBuilder.Append("{"); totalBuilder.Append("\"read\":0,"); totalBuilder.Append("\"unread\":0,"); totalBuilder.Append("\"receiver\":\"\""); totalBuilder.Append("\"total\":0,"); totalBuilder.Append("\"interval\":0"); totalBuilder.Append("}"); totalBuilder.Append("]"); totalBuilder.Append("}"); } return totalBuilder.ToString(); } #endregion #region 获取已开出发票页总数 /// /// 获取已开出发票页总数 /// /// 返回总页数 private int GetMakeOutListPage() { MessageDA messageDA = new MessageDA(); string strSql = "SELECT COUNT(*) FROM sys_message as A WHERE 1 > 0 AND A.RECEIVER = '" + strUserID + "' AND ISNULL(ISDELETE,0) <> 1 "; 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 || checkRead == 2) { strCondition += String.Format(" AND A.ISREAD = {0}", (checkRead == 1 ? 0 : 1)); } break; default: break; } } } strSql += strCondition; } } int iTotal = int.Parse(messageDA.GetExcuteSql(strSql).Tables[0].Rows[0][0].ToString()); return iTotal; } #endregion private string GetMessageList() { MessageDA messageDA = new MessageDA(); 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 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 || checkRead == 2) { strCondition += String.Format(" AND A.ISREAD = {0}", (checkRead == 1 ? 0 : 1)); } break; default: break; } } } } } string strSql = ""; if (iCurrentPage > 0 && iShowPage > 0) { if (iCurrentPage == 1) { strSql = String.Format(" SELECT {0} A.GID,A.DESCRIPTION,A.TYPE,CASE WHEN A.ISREAD = 1 THEN 1 ELSE 0 END as ISREAD,A.READCOUNT,B.SHOWNAME,A.MESSAGECONTENT,A.CREATETIME " + " FROM sys_message as A INNER JOIN [user] as B ON A.RECEIVER = B.GID WHERE 1>0 AND A.RECEIVER = '" + strUserID + "' AND ISNULL(ISDELETE,0) <> 1 " + strCondition + " 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.TYPE,CASE WHEN A.ISREAD = 1 THEN 1 ELSE 0 END as ISREAD,A.READCOUNT,B.SHOWNAME,A.MESSAGECONTENT,A.CREATETIME " + " FROM sys_message as A INNER JOIN [user] as B ON A.RECEIVER = B.GID WHERE A.GID NOT IN " + " (SELECT {1} GID FROM sys_message WHERE 1>0 AND A.RECEIVER = '" + strUserID + "' AND ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY CREATETIME DESC ) AND A.RECEIVER = '" + strUserID + "' AND ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY A.CREATETIME DESC ", strTopInclude, strTopNotInclude); } } else { strSql = " SELECT {0} A.GID,A.DESCRIPTION,A.TYPE,CASE WHEN A.ISREAD = 1 THEN 1 ELSE 0 END as ISREAD,A.READCOUNT,B.SHOWNAME,A.MESSAGECONTENT,A.CREATETIME " + " FROM sys_message as A INNER JOIN [user] as B ON A.RECEIVER = B.GID WHERE 1>0 AND A.RECEIVER = '" + strUserID + "' AND ISNULL(ISDELETE,0) <> 1 " + strCondition + " ORDER BY A.CREATETIME DESC "; } sourceTable = getStatusNameTable(messageDA.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; 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 } }