Example #1
0
        /// <summary>
        /// 异步 开始事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            //需要执行的代码
           

            worker.ReportProgress(1, "开始导入代理商佣金...\r\n");

            //导入代理商佣金
            AgentFeeDao agentFeeDao = new AgentFeeDao();
            for (int i = 0; i < dgAgentFee.RowCount; i++)
            {
                AgentFee agentFee = new AgentFee();
                agentFee.agentFeeMonth = this.dtFeeMonth.Value.ToString("yyyy-MM");
                agentFee.agentNo = dgAgentFee[0, i].Value.ToString();
                agentFee.agentName= dgAgentFee[1, i].Value.ToString();
                agentFee.agentFeeSeq = agentFee.agentNo + this.dtFeeMonth.Value.ToString("yyyyMM") + String.Format("{0:D5}", i+1);
                agentFee.feeTotal = dgAgentFee[dgAgentFee.Columns.Count - 3, i].Value.ToString();
                agentFee.invoiceFee = dgAgentFee[dgAgentFee.Columns.Count - 2, i].Value.ToString();
                agentFee.preInvoiceFee = dgAgentFee[dgAgentFee.Columns.Count - 1, i].Value.ToString();

                for (int j = 2; j <= 101 && j < dgAgentFee.Columns.Count-3; j++)
                {

                    FieldInfo feeNameField = agentFee.GetType().GetField("feeName" + (j-1));
                    FieldInfo feeField = agentFee.GetType().GetField("fee" + (j-1));

                    String feeNameFieldValue = dgAgentFee.Columns[j].HeaderCell.Value.ToString();
                    String feeFieldValue = dgAgentFee[j, i].Value.ToString();
                    if (feeFieldValue.Trim().Equals("0") || String.IsNullOrWhiteSpace(feeFieldValue))
                    {
                        feeFieldValue = null;
                    }
                    feeNameField.SetValue(agentFee, feeNameFieldValue);
                    feeField.SetValue(agentFee, feeFieldValue);

                }

                agentFeeDao.Delete(agentFee);
                agentFeeDao.Add(agentFee);

            }
            WechatAction wechatAction = new WechatAction();
            wechatAction.sendTextMessageToWechat("@all", this.dtFeeMonth.Value.ToString("yyyy年MM月") + "佣金已发布,请通过底部菜单查询佣金详情", Settings.Default.Wechat_Secret, MyConstant.APP_Payment);

            worker.ReportProgress(2, "导入代理商佣金完成...\r\n");
           
           

            //MessageBox.Show("数据上传完毕");

        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string feeMonth =Request.QueryString["feeMonth"];
            string agentNo =Request.QueryString["agentNo"];
            logger.Info("feeMonth=" + Request.QueryString["feeMonth"]);
            logger.Info("agentNo=" + Request.QueryString["agentNo"]);
            try
            {
                
                Request.ContentEncoding = Encoding.UTF8;
                feeMonth = QueryStringEncryption.Decode(feeMonth, QueryStringEncryption.key);
                agentNo = QueryStringEncryption.Decode(agentNo, QueryStringEncryption.key);
                logger.Info("feeMonth=" + feeMonth);
                logger.Info("agentNo=" + agentNo);
            }
            catch (Exception)
            {
               return;
            }
           // agentNo = "yangqinxiao1";
          //  feeMonth = "2015-01";
            AgentFeeDao AgentFeeDao = new AgentFeeDao();

            AgentFee agentFee = AgentFeeDao.GetByKey(feeMonth, agentNo);
           // this.Label1.Text = agentFee.agent.agentName;
            if (agentFee == null)
            {
                this.lblAgentComment.Text =feeMonth+ "佣金尚未发布。";
                return;
            }

            char[] separator = "<br>".ToCharArray();
            StringBuilder sbDesc = new StringBuilder();

            if (!String.IsNullOrEmpty(agentFee.agent.agentTypeComment))
            {
               
                string[] agentTypeCommentList = agentFee.agent.agentTypeComment.Split(separator, StringSplitOptions.RemoveEmptyEntries);

                for (int count = 0; count < agentTypeCommentList.Length; count++)
                {
                    sbDesc.Append(count + 1).AppendFormat(".{0}<br><br>", agentTypeCommentList[count]);
                }
            }

            this.lblAgentComment.Text = sbDesc.ToString(); 
            if(String.IsNullOrEmpty(sbDesc.ToString())){
                this.lblAgentComment.Text = "无";
            }
            this.lblAgentName.Text = agentFee.agentName;
            this.lblAgentNo.Text = agentFee.agentNo;
            this.lblAgentType.Text = agentFee.agent.agentType;
            this.lblFeeMonth.Text = agentFee.agentFeeMonth;
            this.lblFeeSeq.Text = agentFee.agentFeeSeq;
            this.lblSendDate.Text =DateTime.Now.ToString("yyyy年MM月dd日");

            DataTable dt = new DataTable();
            dt.Columns.Add("seq");
            dt.Columns.Add("feeName");
            dt.Columns.Add("fee");
            int i = 1;
            DataRow row = null;

            HashSet<String> category = new HashSet<string>();
            Dictionary<String, Dictionary<String, String>> CategoryMap = new Dictionary<string, Dictionary<String, String>>();
            //按结账科目分类
            for (int j = 1; j <= 100; j++)
            {
                FieldInfo feeNameField = agentFee.GetType().GetField("feeName" + j);
                FieldInfo feeField = agentFee.GetType().GetField("fee" + j);
                if (feeNameField != null && feeField != null)
                {
                    String feeNameFieldValue = feeNameField.GetValue(agentFee) == null ? null : feeNameField.GetValue(agentFee).ToString();

                    String feeFieldValue = feeField.GetValue(agentFee) == null ? null : feeField.GetValue(agentFee).ToString();

                    if (!String.IsNullOrEmpty(feeFieldValue) && !String.IsNullOrWhiteSpace(feeFieldValue))
                    {
                        String headText = feeNameFieldValue;
                        int locationIndex = headText.IndexOf("-");
                        int endIndex = headText.IndexOf("(");
                        if (locationIndex == -1)
                        {
                            locationIndex = headText.IndexOf("-");
                        }
                        if (endIndex == -1)
                        {
                            endIndex = headText.IndexOf("(");
                        }
                        String key = headText.Substring(locationIndex + 1);
                        if (endIndex != -1)
                        {
                            key = headText.Substring(locationIndex + 1, endIndex - locationIndex - 1);
                        }
                        String value = feeFieldValue;
                        if (!CategoryMap.ContainsKey(key))
                        {
                            Dictionary<String, String> valueMap = new Dictionary<string, string>();
                            valueMap.Add(headText, value);
                            CategoryMap.Add(key, valueMap);
                        }
                        else
                        {
                            Dictionary<String, String> valueMap = CategoryMap[key];
                            valueMap.Add(headText, value);
                        }
                    }
                }
            }

              int index = 1;
              foreach (String itemKey in CategoryMap.Keys)
              {
                  Dictionary<String, String> valueMap = CategoryMap[itemKey];
                  float subTotal = 0;
                  foreach (String value in valueMap.Values)
                  {
                      if (!String.IsNullOrEmpty(value))
                      {
                          subTotal = subTotal + float.Parse(value);
                      }
                  }
                  if (index > 1)
                  {
                     // row = dt.NewRow();
                    //  dt.Rows.Add(row);

                  }
                  row = dt.NewRow();
                  row["seq"] =null;
                  row["feeName"] = itemKey  ;

                  row["fee"] = subTotal;
                  dt.Rows.Add(row);
                  foreach (String subKey in valueMap.Keys)
                  {
                      row = dt.NewRow();
                      row["seq"] = index++;
                      row["feeName"] = subKey;

                      row["fee"] = valueMap[subKey];
                      dt.Rows.Add(row);
                  }

              }          

            //for (int j = 1; j <= 100;j++){
            //    FieldInfo feeNameField = agentFee.GetType().GetField("feeName" + j);
            //     FieldInfo feeField = agentFee.GetType().GetField("fee" + j);
            //     if (feeNameField != null && feeField != null)
            //     {
            //         String feeNameFieldValue = feeNameField.GetValue(agentFee)==null?null:feeNameField.GetValue(agentFee).ToString();

            //         String feeFieldValue = feeField.GetValue(agentFee) == null ? null : feeField.GetValue(agentFee).ToString();

            //         if (!String.IsNullOrEmpty(feeFieldValue) && !String.IsNullOrWhiteSpace(feeFieldValue))
            //         {
            //             row = dt.NewRow();
            //             row["seq"] = i++;
            //             row["feeName"] = feeNameFieldValue;
                        
            //             row["fee"] = feeFieldValue;
            //             dt.Rows.Add(row);
            //         }
            //     }

                
            //}
             // row = dt.NewRow();
            //  dt.Rows.Add(row);

            row = dt.NewRow();
            row["seq"] =   index++ ;
            row["feeName"] =   "总计" ;
            row["fee"] =   agentFee.feeTotal ;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["seq"] = index++;
            row["feeName"] = "开票金额";
            row["fee"] = agentFee.invoiceFee;
            dt.Rows.Add(row);

            row = dt.NewRow();
            row["seq"] = index++;
            row["feeName"] = "过网开票金额";
            row["fee"] = agentFee.preInvoiceFee;
            dt.Rows.Add(row);
           
            
            GridView1.DataSource = dt.DefaultView;
            GridView1.DataBind();
            

        }
Example #3
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            //代理商信息            
         //   Queryworker.ReportProgress(1, "代理商信息...\r\n");
           
           // Queryworker.ReportProgress(2, "代理商渠道类型...\r\n");
            //代理商渠道类型
            AgentTypeDao agentTypeDao = new AgentTypeDao();
            IList<AgentType> agentTypeList = agentTypeDao.GetList(dtFeeMonth.Value.ToString("yyyy-MM"));
            dgAgentType.Rows.Clear();
            dgAgentType.Columns.Clear();
            if (agentTypeList != null && agentTypeList.Count > 0)
            {
               
                dgAgentType.Columns.Add("代理商编号", "代理商编号");
                dgAgentType.Columns.Add("渠道类型", "渠道类型");


                for (int i = 0; i < agentTypeList.Count; i++)
                {
                    dgAgentType.Rows.Add();
                    DataGridViewRow row = dgAgentType.Rows[i];
                    row.Cells[0].Value = agentTypeList[i].agentNo;
                    row.Cells[1].Value = agentTypeList[i].agentType;

                }
            }
          //  Queryworker.ReportProgress(3, "代理商渠道类型说明...\r\n");
            //代理商渠道类型说明
            AgentTypeCommentDao agentTypeCommentDao = new AgentTypeCommentDao();
            IList<AgentTypeComment> agentTypeCommentList = agentTypeCommentDao.GetList(dtFeeMonth.Value.ToString("yyyy-MM"));
            dgAgentTypeComment.Rows.Clear();
            dgAgentTypeComment.Columns.Clear();
            if (agentTypeCommentList != null && agentTypeCommentList.Count > 0)
            {
               

                dgAgentTypeComment.Columns.Add("渠道类型", "渠道类型");
                dgAgentTypeComment.Columns.Add("佣金说明", "佣金说明");




                for (int i = 0; i < agentTypeCommentList.Count; i++)
                {
                    dgAgentTypeComment.Rows.Add();
                    DataGridViewRow row = dgAgentTypeComment.Rows[i];
                    row.Cells[0].Value = agentTypeCommentList[i].agentType;
                    row.Cells[1].Value = agentTypeCommentList[i].agentTypeComment;

                }
            }

           // Queryworker.ReportProgress(4, "代理商佣金...\r\n");
            //代理商佣金
            AgentFeeDao agentFeeDao = new AgentFeeDao();
            IList<AgentFee> agentFeeList = agentFeeDao.GetList(dtFeeMonth.Value.ToString("yyyy-MM"));

            AgentWechatAccount agentWechatAccount = new ChinaUnion_BO.AgentWechatAccount();
            AgentWechatAccountDao agentWechatAccountDao = new ChinaUnion_DataAccess.AgentWechatAccountDao();
            
            dgAgentFee.Rows.Clear();
            dgAgentFee.Columns.Clear();
            if (agentFeeList != null && agentFeeList.Count > 0)
            {
                this.grpAgentFee.Text = "月度佣金明细信息(" + agentFeeList.Count + ")";
                dgAgentFee.Columns.Add("代理商编号", "代理商编号");
                dgAgentFee.Columns.Add("代理商名称", "代理商名称");
                dgAgentFee.Columns.Add("代理商类型", "代理商类型");
                dgAgentFee.Columns.Add("代理商类型说明", "代理商类型说明");
                dgAgentFee.Columns.Add("联系人邮件", "联系人邮件");
                dgAgentFee.Columns.Add("联系人名称", "联系人名称");
                dgAgentFee.Columns.Add("告知单编号", "告知单编号");
             //   dgAgentFee.Columns["联系人邮件"].Visible = false;
              //  dgAgentFee.Columns["联系人名称"].Visible = false;
                for (int i = 0; i < agentFeeList.Count; i++)
                {
                    if (i == 0)
                    {
                        for (int j = 1; j <= 100; j++)
                        {
                            FieldInfo feeNameField = agentFeeList[i].GetType().GetField("feeName" + j);
                           // FieldInfo feeField = agentFeeList[i].GetType().GetField("fee" + j);

                            String feeNameFieldValue = feeNameField.GetValue(agentFeeList[i]) == null ? null : feeNameField.GetValue(agentFeeList[i]).ToString();
                           // String feeFieldValue = feeField.GetValue(agentFeeList[i]) == null ? null : feeField.GetValue(agentFeeList[i]).ToString(); ;

                            if (!String.IsNullOrEmpty(feeNameFieldValue) && !String.IsNullOrWhiteSpace(feeNameFieldValue))
                            {
                                dgAgentFee.Columns.Add(feeNameFieldValue, feeNameFieldValue);
                            }
                        }
                       

                        this.dgAgentFee.Columns.Add("总计", "总计");
                        this.dgAgentFee.Columns.Add("开票金额", "开票金额");
                        this.dgAgentFee.Columns.Add("过网开票金额", "过网开票金额");

                    }


                    dgAgentFee.Rows.Add();
                    DataGridViewRow row = dgAgentFee.Rows[i];

                    row.Cells[0].Value = agentFeeList[i].agentNo;
                    row.Cells[1].Value = agentFeeList[i].agent.agentName;
                    row.Cells[2].Value = agentFeeList[i].agent.agentType;
                    row.Cells[3].Value = agentFeeList[i].agent.agentTypeComment;
                    agentWechatAccount = agentWechatAccountDao.GetByAgentNo(agentFeeList[i].agentNo);
                    if (agentWechatAccount != null)
                    {
                        agentFeeList[i].agent.contactEmail = agentWechatAccount.contactEmail;
                        agentFeeList[i].agent.contactName = agentWechatAccount.contactName;
                    }
                    row.Cells[4].Value = agentFeeList[i].agent.contactEmail;
                    row.Cells[5].Value = agentFeeList[i].agent.contactName;
                    row.Cells[6].Value = agentFeeList[i].agentFeeSeq;

                    int feeColIndex = 6;
                    int fixColCount = 7;

                    for (int j = 1; j <= 100 ; j++)
                    {
                       // FieldInfo feeNameField = agentFeeList[i].GetType().GetField("feeName" + j);
                        FieldInfo feeField = agentFeeList[i].GetType().GetField("fee" + j);

                      //  String feeNameFieldValue = feeNameField.GetValue(agentFeeList[i]) == null ? null : feeNameField.GetValue(agentFeeList[i]).ToString();
                        String feeFieldValue = feeField.GetValue(agentFeeList[i]) == null ? null : feeField.GetValue(agentFeeList[i]).ToString(); ;

                        if (dgAgentFee.Columns.Count >= fixColCount + j)
                        {
                            row.Cells[feeColIndex + j].Value = feeFieldValue;
                        }
                    }
                  

                    row.Cells[dgAgentFee.Columns.Count - 3].Value = agentFeeList[i].feeTotal;
                    row.Cells[dgAgentFee.Columns.Count - 2].Value = agentFeeList[i].invoiceFee;
                    row.Cells[dgAgentFee.Columns.Count - 1].Value = agentFeeList[i].preInvoiceFee;

                }
            }
            this.dgAgentType.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            dgAgentType.AutoResizeColumns();
            this.dgAgentTypeComment.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            dgAgentTypeComment.AutoResizeColumns();
            //this.dgAgent.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
            //dgAgent.AutoResizeColumns();
            if (dgAgentFee.RowCount > 0)
            {
                this.btnMail.Visible = true;
            }
            else
            {
                this.btnMail.Visible = false;
            }

            this.Cursor = Cursors.Default;     
           

        }
Example #4
0
        private void frmMailReSend_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            worker = new BackgroundWorker();
            worker.WorkerReportsProgress = true;
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);


            AgentFeeDao agentFeeDao = new AgentFeeDao();
            IList<AgentFee> agentFeeList = agentFeeDao.GetList(this.feeMonth);

            if (agentFeeList != null && agentFeeList.Count > 0)
            {
                dgAgentFee.Rows.Clear();
                dgAgentFee.Columns.Clear();

                this.dgAgentFee.Columns.Add("代理商编号", "代理商编号");
                this.dgAgentFee.Columns.Add("代理商名称", "代理商名称");
                this.dgAgentFee.Columns.Add("代理商类型", "代理商类型");
                this.dgAgentFee.Columns.Add("代理商类型说明", "代理商类型说明");
                this.dgAgentFee.Columns.Add("联系人邮件", "联系人邮件");
                this.dgAgentFee.Columns.Add("联系人名称", "联系人名称");
                this.dgAgentFee.Columns.Add("告知单编号", "告知单编号");

                dgAgentFee.Columns["联系人邮件"].Visible = false;
                dgAgentFee.Columns["联系人名称"].Visible = false;

                for (int i = 0; i < agentFeeList.Count; i++)
                {
                    if (i == 0)
                    {
                        for (int j = 1; j <= 100; j++)
                        {
                            FieldInfo feeNameField = agentFeeList[i].GetType().GetField("feeName" + j);
                            // FieldInfo feeField = agentFeeList[i].GetType().GetField("fee" + j);

                            String feeNameFieldValue = feeNameField.GetValue(agentFeeList[i]) == null ? null : feeNameField.GetValue(agentFeeList[i]).ToString();
                            // String feeFieldValue = feeField.GetValue(agentFeeList[i]) == null ? null : feeField.GetValue(agentFeeList[i]).ToString(); ;

                            if (!String.IsNullOrEmpty(feeNameFieldValue) && !String.IsNullOrWhiteSpace(feeNameFieldValue))
                            {
                                dgAgentFee.Columns.Add(feeNameFieldValue, feeNameFieldValue);
                            }
                        }


                        this.dgAgentFee.Columns.Add("总计", "总计");
                        this.dgAgentFee.Columns.Add("开票金额", "开票金额");
                        this.dgAgentFee.Columns.Add("过网开票金额", "过网开票金额");

                    }

                    if (!htReSendMail.Contains(agentFeeList[i].agent.agentName))
                    {
                        continue;
                    }
                    dgAgentFee.Rows.Add();
                    DataGridViewRow row = dgAgentFee.Rows[dgAgentFee.RowCount-1];

                    row.Cells[0].Value = agentFeeList[i].agentNo;
                    row.Cells[1].Value = agentFeeList[i].agent.agentName;
                    row.Cells[2].Value = agentFeeList[i].agent.agentType;
                    row.Cells[3].Value = agentFeeList[i].agent.agentTypeComment.Replace(",","、").Replace("#","%");
                    row.Cells[4].Value = agentFeeList[i].agent.contactEmail;
                    row.Cells[5].Value = agentFeeList[i].agent.contactName;
                    row.Cells[6].Value = agentFeeList[i].agentFeeSeq;




                    int feeColIndex = 6;
                    int fixColCount = 7;

                    for (int j = 1; j <= 100; j++)
                    {
                        // FieldInfo feeNameField = agentFeeList[i].GetType().GetField("feeName" + j);
                        FieldInfo feeField = agentFeeList[i].GetType().GetField("fee" + j);

                        //  String feeNameFieldValue = feeNameField.GetValue(agentFeeList[i]) == null ? null : feeNameField.GetValue(agentFeeList[i]).ToString();
                        String feeFieldValue = feeField.GetValue(agentFeeList[i]) == null ? null : feeField.GetValue(agentFeeList[i]).ToString(); ;

                        if (dgAgentFee.Columns.Count >= fixColCount + j)
                        {
                            row.Cells[feeColIndex + j].Value = feeFieldValue;
                        }
                    }

                    row.Cells[dgAgentFee.Columns.Count - 3].Value = agentFeeList[i].feeTotal;
                    row.Cells[dgAgentFee.Columns.Count - 2].Value = agentFeeList[i].invoiceFee;
                    row.Cells[dgAgentFee.Columns.Count - 1].Value = agentFeeList[i].preInvoiceFee;

                }
            }
            showHtml(0);
          

            this.Cursor = Cursors.Default;
        }
        /// <summary>
        /// 处理企业号的信息
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {


            logger.Info(context.Request.Url.AbsoluteUri);


            // string sToken = "AgentFee";
            // string sCorpID = "wx4fe8b74e01fffcbb";
            // string sEncodingAESKey = "gvGJnhpjeljcKzvfe8B8vnmMBBLkJFuzUYSjsGcDQFE";

            string sToken ="AgentFeeAndInvoicePaymentHandler";//"AgentFee";
            string sCorpID = Properties.Settings.Default.Wechat_CorpId;// "wx31204de5a3ae758e";
            string sEncodingAESKey = "4m6avCYhQ2p4IwjtMpFWNHRd46k2uIgdLbHSAlyCQsJ";// "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_Commission;
                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;
                }
                switch (actionType)
                {
                    case "FeeQueryHelp":
                        sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                        sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "佣金查询说明\n\n");

                        break;

                    case "last6MonthBonus":
                        String strBonusList = "最近6月红包查询\n\n";
                        for (int i = 1; i <= 6; i++)
                        {
                            String tempFeeMonth = DateTime.Now.AddMonths(0 - i).ToString("yyyyMM");

                            String url1 = String.Format("http://{0}/Wechat/AgentBonusDetailQuery.aspx?agentNo={1}&feeMonth={2}", Properties.Settings.Default.Host, QueryStringEncryption.Encode(agentNo, QueryStringEncryption.key), QueryStringEncryption.Encode(tempFeeMonth, QueryStringEncryption.key));

                            strBonusList = strBonusList + "<a href=\"" + url1 + "\">" + i + ":" + tempFeeMonth + "</a>";
                            strBonusList = strBonusList + "\n\n";
                        }
                        sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                        sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", strBonusList);
                        break;

                    case "preMonthBonus":
                    case "curMonthBonus":
                        String feeMonthBonus = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
                        if (actionType.Equals("preMonthBonus"))
                        {
                            feeMonthBonus = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
                        }
                        AgentBonusDao agentBonusDao = new AgentBonusDao();
                        AgentBonus agentBonus = agentBonusDao.GetByKey(feeMonthBonus, agentNo);
                        if (agentBonus != null && !String.IsNullOrEmpty(agentBonus.agentNo))
                        {
                            sb.Append(this.createAgentBonusNewsMessages(feeMonthBonus, agentBonus, agentNo));
                        }
                        else
                        {
                            sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                            sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "本月无红包或者红包尚未发布!\n\n");
                        }
                        break;

                    case "Latest6MonthFeeQuery":
                        String strList = "最近6月佣金查询\n\n";
                        for (int i = 1; i <= 6; i++)
                        {
                            String tempFeeMonth = DateTime.Now.AddMonths(0 - i).ToString("yyyy-MM");

                            String url1 = String.Format("http://{0}/Wechat/AgentFeeQuery.aspx?agentNo={1}&feeMonth={2}", Properties.Settings.Default.Host, QueryStringEncryption.Encode(agentNo, QueryStringEncryption.key), QueryStringEncryption.Encode(tempFeeMonth, QueryStringEncryption.key));

                            strList = strList + "<a href=\"" + url1 + "\">" + i + ":" + tempFeeMonth + "</a>";
                            strList = strList + "\n\n";
                        }
                        sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                        sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", strList);
                        break;

                    case "PreMonthFeeQuery":
                    case "CurMonthFeeQuery":
                        String feeMonth = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
                        if (actionType.Equals("PreMonthFeeQuery"))
                        {
                            feeMonth = DateTime.Now.AddMonths(-2).ToString("yyyy-MM");
                        }
                        AgentFeeDao agentFeeDao = new AgentFeeDao();
                        AgentFee agentFee = agentFeeDao.GetByKey(feeMonth, agentNo);
                        if (agentFee != null && !String.IsNullOrEmpty(agentFee.agentFeeSeq))
                        {
                            sb.Append(this.createAgentFeeNewsMessages(feeMonth, agentFee, agentNo));
                        }
                        else
                        {
                            sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                            sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "本月无佣金或者佣金尚未发布\n\n");
                        }
                        break;
                    case "PaymentQueryHelp":
                        sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                        sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "发票支付查询说明\n\n");

                        break;

                    case "Latest6MonthPaymentQuery":
                        String strList1 = "最近6月发票支付查询\n\n";
                        for (int i = 1; i <= 6; i++)
                        {
                            String tempFeeMonth = DateTime.Now.AddMonths(0 - i).ToString("yyyyMM");

                            String url1 = String.Format("http://{0}/Wechat/InvoicePaymentQuery.aspx?agentNo={1}&feeMonth={2}", Properties.Settings.Default.Host, QueryStringEncryption.Encode(agentNo, QueryStringEncryption.key), QueryStringEncryption.Encode(tempFeeMonth, QueryStringEncryption.key));

                            strList1 = strList1 + "<a href=\"" + url1 + "\">" + i + ":" + tempFeeMonth + "</a>";
                            strList1 = strList1 + "\n\n";
                        }
                        sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                        sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", strList1);
                        break;

                    case "PreMonthPaymentQuery":
                    case "CurMonthPaymentQuery":
                        feeMonth = DateTime.Now.AddMonths(-1).ToString("yyyyMM");
                        if (actionType.Equals("PreMonthPaymentQuery"))
                        {
                            feeMonth = DateTime.Now.AddMonths(-2).ToString("yyyyMM");
                        }
                        InvoicePaymentDao agentInvoicePaymentDao = new InvoicePaymentDao();

                        IList<InvoicePayment> agentInvoicePaymentList = new List<InvoicePayment>();

                        //  agentNo = "";//"DL224049";
                        // feeMonth = "201412";
                        logger.Info("1.feeMonth=" + feeMonth);
                        logger.Info("2.agentNo=" + agentNo);

                        agentInvoicePaymentList = agentInvoicePaymentDao.GetList(agentNo, null, feeMonth, null);

                        if (agentInvoicePaymentList != null && agentInvoicePaymentList.Count > 0)
                        {
                            sb.Append(this.createPaymentNewsMessages(feeMonth, agentNo, agentInvoicePaymentList));
                        }
                        else
                        {
                            sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                            sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", feeMonth.Substring(0, 4) + "年" + feeMonth.Substring(4, 2) + "月" + "无发票受理记录或尚未完成,请耐心等候!\n\n");
                        }
                        break;
                    default:

                        if (!Regex.IsMatch(wechatMessage.Content, "((20[0-9][0-9])|(19[0-9][0-9]))-((0[1-9])|(1[0-2]))"))
                        {
                            sb.AppendFormat("<MsgType><![CDATA[text]]></MsgType>");
                            sb.AppendFormat("<Content><![CDATA[{0}]]></Content>", "请输入\"yyyy-mm\"查询某月佣金,支付结算和红包,例如:\"" + DateTime.Now.ToString("yyyy-MM") + "\"查询" + DateTime.Now.ToString("yyyy年MM月") + "佣金\n\n");
                        }
                        else
                        {
                            feeMonth = wechatMessage.Content;
                            agentFeeDao = new AgentFeeDao();
                            agentFee = agentFeeDao.GetByKey(feeMonth, wechatMessage.FromUserName);

                             agentBonusDao = new AgentBonusDao();
                             feeMonthBonus = feeMonth.Replace("-", "");
                             agentBonus = agentBonusDao.GetByKey(feeMonthBonus, agentNo);

                             agentInvoicePaymentDao = new InvoicePaymentDao();
                            String feeMonthInvoice = feeMonth.Replace("-", "");
                             agentInvoicePaymentList = agentInvoicePaymentDao.GetList(agentNo, null, feeMonthInvoice, null);




                             sb.Append(this.createAllNewsMessages(feeMonth, wechatMessage.FromUserName, agentFee, agentBonus, agentInvoicePaymentList));

                          
                        }

                        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("ret=" + ret);
            if (ret != 0)
            {
                System.Console.WriteLine("ERR: EncryptMsg Fail, ret: " + ret);


                return;
            }

            context.Response.Write(sEncryptMsg);


        }