Esempio n. 1
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            //代理商信息            
         //   Queryworker.ReportProgress(1, "代理商信息...\r\n");
            AgentStarDao agentStarDao = new AgentStarDao();
            //agentDao.Get("P001");
            IList<AgentStar> agentStarList = agentStarDao.GetListByKeyword(this.txtKeyword.Text.Trim());
            dgAgentStar.Rows.Clear();
            dgAgentStar.Columns.Clear();

            if (agentStarList != null && agentStarList.Count > 0)
            {
                dgAgentStar.Columns.Add("时间", "时间");
                dgAgentStar.Columns.Add("代理商编号", "代理商编号");
                dgAgentStar.Columns.Add("代理商名称", "代理商名称");
                dgAgentStar.Columns.Add("渠道编码", "渠道编码");
                dgAgentStar.Columns.Add("渠道名称", "渠道名称");
                dgAgentStar.Columns.Add("星级", "星级");

               
               

                for (int i = 0; i < agentStarList.Count; i++)
                {
                    dgAgentStar.Rows.Add();
                    DataGridViewRow row = dgAgentStar.Rows[i];
                    row.Cells[0].Value = agentStarList[i].dateTime;
                    row.Cells[1].Value = agentStarList[i].agentNo;
                    row.Cells[2].Value = agentStarList[i].agentName;
                    row.Cells[3].Value = agentStarList[i].branchNo;                  
                    row.Cells[4].Value = agentStarList[i].branchName;
                    row.Cells[5].Value = agentStarList[i].star;
                }
            }

            dgAgentStar.ColumnHeadersDefaultCellStyle.WrapMode = DataGridViewTriState.False;
            this.dgAgentStar.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            dgAgentStar.AutoResizeColumns();


            
           
            this.Cursor = Cursors.Default;     
           

        }
Esempio n. 2
0
        /// <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);


        }