private void btnQuery_Click(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; //代理商信息 AgentScoreDao agentScoreDao = new AgentScoreDao(); //agentDao.Get("P001"); IList<AgentScore> agentScoreList = agentScoreDao.GetListByKeyword(this.txtKeyword.Text.Trim()); dgAgentScore.Rows.Clear(); dgAgentScore.Columns.Clear(); if (agentScoreList != null && agentScoreList.Count > 0) { dgAgentScore.Columns.Add("时间", "时间"); dgAgentScore.Columns.Add("代理商编号", "代理商编号"); dgAgentScore.Columns.Add("代理商名称", "代理商名称"); dgAgentScore.Columns.Add("渠道编码", "渠道编码"); dgAgentScore.Columns.Add("渠道名称", "渠道名称"); dgAgentScore.Columns.Add("积分", "积分"); dgAgentScore.Columns.Add("本月积分", "本月积分"); for (int i = 0; i < agentScoreList.Count; i++) { dgAgentScore.Rows.Add(); DataGridViewRow row = dgAgentScore.Rows[i]; row.Cells[0].Value = agentScoreList[i].dateTime; row.Cells[1].Value = agentScoreList[i].agentNo; row.Cells[2].Value = agentScoreList[i].agentName; row.Cells[3].Value = agentScoreList[i].branchNo; row.Cells[4].Value = agentScoreList[i].branchName; row.Cells[5].Value = agentScoreList[i].score; row.Cells[6].Value = agentScoreList[i].standardScore; } } dgAgentScore.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False; this.dgAgentScore.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dgAgentScore.AutoResizeColumns(); this.Cursor = Cursors.Default; }
/// <summary> /// 处理企业号的信息 /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { logger.Info(context.Request.Url.AbsoluteUri); string sToken = "PerformanceHandler"; string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx4fe8b74e01fffcbb"; string sEncodingAESKey = "U7gOrkwP22ND4bIHSxU0WJqIestRcG2QroykyVKDUSG"; // string sToken = Properties.Settings.Default.Wechat_AgentFee_Token;//"AgentFee"; // string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx31204de5a3ae758e"; // string sEncodingAESKey = Properties.Settings.Default.Wechat_AgentFee_EncodingAESKey;// "he8dYrZ5gLbDrDhfHVJkea1AfmHgRZQJq47kuKpQrSO"; System.Collections.Specialized.NameValueCollection queryStrings = context.Request.QueryString; Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID); context.Request.ContentEncoding = Encoding.UTF8; string sReqMsgSig = queryStrings["msg_signature"]; string sReqTimeStamp = queryStrings["timestamp"]; string sReqNonce = queryStrings["nonce"]; // 获取Post请求的密文数据 StreamReader reader = new StreamReader(context.Request.InputStream, Encoding.GetEncoding("UTF-8")); string sReqData = reader.ReadToEnd(); reader.Close(); string sMsg = ""; // 解析之后的明文 int ret = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, sReqData, ref sMsg); if (ret != 0) { logger.Info("ERR: Decrypt Fail, ret: " + ret); System.Console.WriteLine("ERR: Decrypt Fail, ret: " + ret); return; } // ret==0表示解密成功,sMsg表示解密之后的明文xml串 XmlDocument doc = new XmlDocument(); doc.LoadXml(sMsg); WechatMessage wechatMessage = new WechatMessage(doc.DocumentElement); // 需要发送的明文 String actionType = wechatMessage.EventKey; StringBuilder sb = new StringBuilder(); sb.AppendFormat("<xml>"); sb.AppendFormat("<ToUserName><![CDATA[{0}]]></ToUserName>", wechatMessage.FromUserName); sb.AppendFormat("<FromUserName><![CDATA[{0}]]></FromUserName>", wechatMessage.ToUserName); sb.AppendFormat("<CreateTime>{0}</CreateTime>", wechatMessage.CreateTime); // string sRespData = "<MsgId>1234567890123456</MsgId>"; logger.Info("EventKey: " + wechatMessage.EventKey); AgentWechatAccountDao agentWechatAccountDao = new AgentWechatAccountDao(); AgentWechatAccount agentWechatAccount = agentWechatAccountDao.Get(wechatMessage.FromUserName); if (agentWechatAccount != null && wechatMessage != null && !String.IsNullOrEmpty(wechatMessage.Event) && wechatMessage.Event.Equals("enter_agent")) { WechatQueryLog wechatQueryLog = new ChinaUnion_BO.WechatQueryLog(); wechatQueryLog.agentName = ""; wechatQueryLog.module = Util.MyConstant.module_Performance; wechatQueryLog.subSystem = "业绩查询"; wechatQueryLog.queryTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); wechatQueryLog.queryString = "成员进入应用"; wechatQueryLog.wechatId = agentWechatAccount.contactId; WechatQueryLogDao wechatQueryLogDao = new WechatQueryLogDao(); try { wechatQueryLogDao.Add(wechatQueryLog); } catch { } } if (agentWechatAccount != null && !String.IsNullOrEmpty(agentWechatAccount.status) && !agentWechatAccount.status.Equals("Y")) { sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "对不起,你的账号已被停用,请联系联通工作人员!\n\n"); } else if (agentWechatAccount == null) { sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "用户不存在,请联系联通工作人员!\n\n"); } else { String agentNo = agentWechatAccount.branchNo; if (String.IsNullOrEmpty(agentNo)) { agentNo = agentWechatAccount.agentNo; } String agentType = agentWechatAccount.type; AgentMonthPerformanceDao agentMonthPerformanceDao = new ChinaUnion_DataAccess.AgentMonthPerformanceDao(); AgentDailyPerformanceDao agentDailyPerformanceDao = new ChinaUnion_DataAccess.AgentDailyPerformanceDao(); AgentStarDao agentStarDao = new AgentStarDao(); IList<AgentStar> agentStarList = null; AgentScoreDao agentScoreDao = new AgentScoreDao(); IList<AgentScore> agentScoreList = null; String dateTime = ""; DateTime dt = DateTime.Now.AddMonths(-3); //当前时间 DateTime startQuarter = dt.AddMonths(0 - (dt.Month - 1) % 3).AddDays(1 - dt.Day); //本季度初 if (startQuarter.Month >= 1 && startQuarter.Month <= 3) { dateTime = startQuarter.Year + "年第一季度"; } if (startQuarter.Month >= 4 && startQuarter.Month <= 6) { dateTime = startQuarter.Year + "年第二季度"; } if (startQuarter.Month >= 7 && startQuarter.Month <= 9) { dateTime = startQuarter.Year + "年第三季度"; } if (startQuarter.Month >= 10 && startQuarter.Month <= 12) { dateTime = startQuarter.Year + "年第四季度"; } logger.Info("agentNo: " + agentNo); logger.Info("agentType: " + agentType); switch (actionType) { case "curQuaterStar": case "HistoryQuaterStar": if (actionType.Equals("curQuaterStar")) { agentStarList = agentStarDao.GetLatestByKeyword(agentNo, dateTime); } if (actionType.Equals("HistoryQuaterStar")) { agentStarList = agentStarDao.GetListByKeyword(agentNo); } if (agentStarList != null && agentStarList.Count > 0) { logger.Info("Exist Record: " + agentStarList.Count); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); StringBuilder sbContent = new StringBuilder(); sbContent.AppendFormat("星级查询详情").Append("\n"); for (int i = 0; i < agentStarList.Count;i++ ) { AgentStar agentStar = agentStarList[i]; sbContent.AppendFormat("\n时间:{0}", agentStar.dateTime).Append("\n"); // sbContent.AppendFormat("代理商编号:{0}", agentStar.agentNo).Append("\n"); //sbContent.AppendFormat("代理商名称:{0}", agentStar.agentName).Append("\n"); if (!String.IsNullOrEmpty(agentStar.branchNo)) { sbContent.AppendFormat("渠道编码:{0}", agentStar.branchNo).Append("\n"); sbContent.AppendFormat("渠道名称:{0}", agentStar.branchName).Append("\n"); } sbContent.AppendFormat("星级:{0}", agentStar.star).Append("\n"); } sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", sbContent.ToString()); // sb.Append(sbContent.ToString()); // sb.Append(this.createNewsMessages(feeDate, wechatMessage.FromUserName, agentDailyPerformance)); } else { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "本期无星级或尚未发布,请耐心等候\n\n"); } WechatQueryLog wechatQueryLog = new ChinaUnion_BO.WechatQueryLog(); wechatQueryLog.agentName = ""; wechatQueryLog.module = Util.MyConstant.module_Performance; wechatQueryLog.subSystem = "星级查询"; wechatQueryLog.queryTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); wechatQueryLog.queryString = dateTime; wechatQueryLog.wechatId = agentNo; WechatQueryLogDao wechatQueryLogDao = new WechatQueryLogDao(); try { wechatQueryLogDao.Add(wechatQueryLog); } catch { } break; case "curScore": case "HistoryScore": String month = DateTime.Now.AddMonths(-1).ToString("yyyyMM"); if (actionType.Equals("curScore")) { agentScoreList = agentScoreDao.GetLatestByKeyword(agentNo, month); } if (actionType.Equals("HistoryScore")) { agentScoreList = agentScoreDao.GetListByKeyword(agentNo); } if (agentScoreList != null && agentScoreList.Count > 0) { logger.Info("Exist Record: " + agentScoreList.Count); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); StringBuilder sbContent = new StringBuilder(); sbContent.AppendFormat("积分查询详情").Append("\n"); for (int i = 0; i < agentScoreList.Count; i++) { AgentScore agentScore = agentScoreList[i]; sbContent.AppendFormat("\n时间:{0}", agentScore.dateTime).Append("\n"); if (!String.IsNullOrEmpty(agentScore.agentNo)) { sbContent.AppendFormat("代理商编号:{0}", agentScore.agentNo).Append("\n"); sbContent.AppendFormat("代理商名称:{0}", agentScore.agentName).Append("\n"); } if (!String.IsNullOrEmpty(agentScore.branchNo)) { sbContent.AppendFormat("渠道编码:{0}", agentScore.branchNo).Append("\n"); sbContent.AppendFormat("渠道名称:{0}", agentScore.branchName).Append("\n"); } sbContent.AppendFormat("渠道积分:{0}", agentScore.score).Append("\n"); sbContent.AppendFormat("本月得分:{0}", agentScore.standardScore).Append("\n"); } sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", sbContent.ToString()); // sb.Append(sbContent.ToString()); // sb.Append(this.createNewsMessages(feeDate, wechatMessage.FromUserName, agentDailyPerformance)); } else { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "本期无积分或尚未发布,请耐心等候\n\n"); } wechatQueryLog = new ChinaUnion_BO.WechatQueryLog(); wechatQueryLog.agentName = ""; wechatQueryLog.module = Util.MyConstant.module_Performance; wechatQueryLog.subSystem = "积分查询"; wechatQueryLog.queryTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); wechatQueryLog.queryString = month; wechatQueryLog.wechatId = agentNo; wechatQueryLogDao = new WechatQueryLogDao(); try { wechatQueryLogDao.Add(wechatQueryLog); } catch { } break; case "YesterdayPerformance": String feeDate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"); AgentDailyPerformance agentDailyPerformance = new AgentDailyPerformance(); agentDailyPerformance = agentDailyPerformanceDao.GetSummary(agentNo, feeDate,agentType); if (agentDailyPerformance != null) { logger.Info("Exist Record: " + agentNo); sb.Append(this.createNewsMessages(feeDate, agentNo, agentDailyPerformance, agentType)); } else { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", DateTime.Now.AddDays(-1).ToString("yyyy年MM月dd日") + "无业绩或者业绩尚未发布\n\n"); } break; case "HistoryDayPerformance": String date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd"); IList<AgentDailyPerformance> agentDailyPerformanceList = agentDailyPerformanceDao.GetAllListDate(agentNo, agentType,date); if (agentDailyPerformanceList == null || agentDailyPerformanceList.Count == 0) { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "近期无业绩或者业绩尚未发布!\n\n"); } else { sb.Append(this.createNewsMessages(agentNo, agentDailyPerformanceList, agentType)); } break; case "LastMonthPerformance": // case "YesterdayPerformance": String feeMonth = DateTime.Now.AddMonths(-1).ToString("yyyy-MM"); AgentMonthPerformance agentMonthPerformance = new AgentMonthPerformance(); agentMonthPerformance = agentMonthPerformanceDao.GetSummary(agentNo, feeMonth, agentType); if (agentMonthPerformance != null) { logger.Info("Exist Record: " + agentMonthPerformance.agentName); sb.Append(this.createNewsMessages(feeMonth, agentNo, agentMonthPerformance, agentType)); } else { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", feeMonth.Substring(0,4)+"年"+feeMonth.Substring(5,2)+ "月" + "业绩尚未发布,请耐心等待!\n\n"); } break; case "HistoryMonthPerformance": IList<AgentMonthPerformance> agentMonthPerformanceList = agentMonthPerformanceDao.GetAllListMonth(agentNo,agentType); if (agentMonthPerformanceList == null || agentMonthPerformanceList.Count == 0) { logger.Info("is not Existed Record: "); sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>"); sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "近期业绩尚未发布,请耐心等待!\n\n"); } else { sb.Append(this.createNewsMessages(agentNo, agentMonthPerformanceList, agentType)); } break; } } // sb.AppendFormat("<AgentID>{0}</AgentID>", textMessage.AgentID); sb.AppendFormat("</xml>"); string sRespData = sb.ToString(); string sEncryptMsg = ""; //xml格式的密文 ret = wxcpt.EncryptMsg(sRespData, sReqTimeStamp, sReqNonce, ref sEncryptMsg); logger.Info("sRespData=" + sRespData); logger.Info("ret=" + ret); if (ret != 0) { System.Console.WriteLine("ERR: EncryptMsg Fail, ret: " + ret); return; } context.Response.Write(sEncryptMsg); }
/// <summary> /// 异步 开始事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void worker_DoWork(object sender, DoWorkEventArgs e) { //需要执行的代码 worker.ReportProgress(3, "开始导入积分...\r\n"); //导入积分 AgentScoreDao agentScoreDao = new AgentScoreDao(); for (int i = 0; i < dgAgentScore.RowCount; i++) { AgentScore agentScore = new AgentScore(); agentScore.dateTime = dgAgentScore[0, i].Value.ToString(); agentScore.agentNo = dgAgentScore[1, i].Value.ToString(); agentScore.agentName = dgAgentScore[2, i].Value.ToString(); agentScore.branchNo = dgAgentScore[3, i].Value.ToString(); agentScore.branchName = dgAgentScore[4, i].Value.ToString(); agentScore.score = dgAgentScore[5, i].Value.ToString(); agentScore.standardScore = dgAgentScore[6, i].Value.ToString(); agentScoreDao.Delete(agentScore.agentNo.Trim(), agentScore.branchNo.Trim(), agentScore.dateTime.Trim()); agentScoreDao.Add(agentScore); if (!String.IsNullOrEmpty(agentScore.agentNo)) { worker.ReportProgress(4, "正在导入代理商:" + agentScore.agentNo + "积分...\r\n"); } else { worker.ReportProgress(4, "正在导入渠道:" + agentScore.branchNo + "积分...\r\n"); } } worker.ReportProgress(5, "导入积分完成...\r\n"); //MessageBox.Show("数据上传完毕"); }