123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace LYFZ.Software.MainBusiness.SMSManagement
- {
- public partial class frmAddMicroTemplateItem : LYFZ.Software.UI.SMSManagement.frmAddMicroTemplateItem
- {
- public frmAddMicroTemplateItem()
- {
- this.btnSave.Click += btnSave_Click;
- this.Shown += frmAddMicroTemplateItem_Shown;
- this.cboxTList.SelectedIndexChanged += cboxTList_SelectedIndexChanged;
- this.chkAutoGet.CheckedChanged += chkAutoGet_CheckedChanged;
- this.linkLabelURL.Click += linkLabelURL_Click;
- }
- void linkLabelURL_Click(object sender, EventArgs e)
- {
- try
- {
- System.Diagnostics.Process.Start(BLL.BLL_MicroInterface.GetGlobalReturnCodeURL());
- }
- catch { }
- }
- void frmAddMicroTemplateItem_Shown(object sender, EventArgs e)
- {
- modInterFace = bllInterface.GetModelMicroInterface(LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID);
- BindTemplateNo();
- if (this.SmsModel.ID > 0)
- {
- this.TemplateNo = (EnumPublic.MicroTemplate)this.SmsModel.ST_Category;
- this.cboxTList.SelectedItem = this.TemplateNo.ToString();
- this.txtSmsTID.Text = this.SmsModel.ST_Remark;
- this.lbTitle.Text = this.TemplateNo.ToString();
- this.lbContentExamples.Text = LYFZ.BLL.BLL_SMSTemplates.GetMicroTemplateExample(this.TemplateNo);
- this.txtSmsTNo.Text = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(this.TemplateNo);
- this.chkAutoGet.Checked = false;
- this.chkAutoGet.Enabled = false;
- this.cboxTList.Enabled = false;
- this.btnSave.Text = "保 存 修 改";
- }
- }
- void chkAutoGet_CheckedChanged(object sender, EventArgs e)
- {
- this.txtSmsTID.ReadOnly = this.chkAutoGet.Checked;
- }
- void cboxTList_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (this.cboxTList.SelectedItem != null)
- {
- this.TemplateNo = (EnumPublic.MicroTemplate)Enum.Parse(typeof(EnumPublic.MicroTemplate), this.cboxTList.SelectedItem.ToString());
- this.lbTitle.Text = this.TemplateNo.ToString();
- this.lbContentExamples.Text = LYFZ.BLL.BLL_SMSTemplates.GetMicroTemplateExample(this.TemplateNo);
- this.txtSmsTNo.Text = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(this.TemplateNo);
- }
- }
- /// <summary>
- /// 当前消息模板
- /// </summary>
- EnumPublic.MicroTemplate _TemplateNo = EnumPublic.MicroTemplate.新订单通知;
- /// <summary>
- /// 当前消息模板
- /// </summary>
- public EnumPublic.MicroTemplate TemplateNo
- {
- get { return _TemplateNo; }
- set { _TemplateNo = value; }
- }
- /// <summary>
- /// 邦定消息模板
- /// </summary>
- void BindTemplateNo()
- {
- this.cboxTList.Items.Clear();
- this.cboxTList.DataSource = GetTemplateNoList();
- }
- List<string> GetTemplateNoList()
- {
- List<string> elist = new List<string>();
- elist.AddRange(Enum.GetNames(typeof(LYFZ.EnumPublic.MicroTemplate)));
- return elist;
- }
- LYFZ.DAL.DAL_SMSTemplates smsDal = new DAL.DAL_SMSTemplates();
- LYFZ.Model.Model_SMSTemplates smsModel = new Model.Model_SMSTemplates();
- /// <summary>
- /// 模板ID对象
- /// </summary>
- public LYFZ.Model.Model_SMSTemplates SmsModel
- {
- get { return smsModel; }
- set { smsModel = value; }
- }
- /// <summary>
- /// 客户端配置信息
- /// </summary>
- // LYFZ.Model.Model_Config mConfig = null;
- LYFZ.BLL.BLL_SMSTemplates mybllsmsT = new BLL.BLL_SMSTemplates();
- BLL.BLL_ErpMicroInterface bllInterface = new BLL.BLL_ErpMicroInterface();
- LYFZ.Model.Model_ErpMicroInterface modInterFace = new Model.Model_ErpMicroInterface();
- void btnSave_Click(object sender, EventArgs e)
- {
- this.SmsModel.ST_Remark = this.txtSmsTID.Text.Trim();
- if (!this.chkAutoGet.Checked && this.SmsModel.ST_Remark.Trim().Length <= 0)
- {
- ExMessageBoxCustom.Show("模板ID不能为空");
- return;
- }
- if (this.SmsModel.ID > 0)
- {
- if (smsDal.Update(this.SmsModel))
- {
- ExMessageBoxCustom.Show("修改微信模板ID成功。");
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- else
- {
- ExMessageBoxCustom.Show("修改微信模板ID失败,请关闭软件并重新启动后再试。");
- }
- }
- else
- {
- this.SmsModel.ST_Type = (int)EnumPublic.SmsTemplateType.微信模板ID;
- this.SmsModel.ST_Title = this.TemplateNo.ToString();
- this.SmsModel.ST_Category = (int)this.TemplateNo;
- this.SmsModel.ST_SMSContent = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(this.TemplateNo);
- this.SmsModel.ST_CreateDatetime = SDateTime.Now;
- this.SmsModel.ST_UpdateDatetime = SDateTime.Now;
- this.SmsModel.ST_DividedShop = LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID;
- bool isAutoGet = this.chkAutoGet.Checked;
- if (modInterFace.AppID == null || modInterFace.AppID.Trim().Length<=0)
- {
- MessageBoxCustom.Show("您还没有设置本店的公众号,请设置后重试");
- return;
- }
- LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
- {
- backgroundWorker.ReportProgress(0, "正在检查数据...");
- if (!this.smsDal.ExistsMicroTemplate(this.SmsModel.ST_Category, LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetCompanyInfoID()))
- {
- if (isAutoGet)
- {
- backgroundWorker.ReportProgress(0, "正在下载模板...");
- // mConfig = new LYFZ.BLL.BLL_Config().GetModel_SysConfig();
- // int PortNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.WebServerPort;
- // if (!LYFZ.WinAPI.CustomPublicMethod.CheckInternaNetworkAddress(mConfig.ServerHostOrIP) && LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.YS_EnableMapped)
- // {
- // PortNumber = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.YS_tAppport;
- // }
- //从公众号下载模板
- /* int clearAccessToken =0;//是否清容并刷新AccessToken
- if (this.chkaccess_token.Checked)
- {
- clearAccessToken = 1;
- }*/
- string resultStr = "";
- try
- {
-
- /*string url = LYFZ.BLL.BLL_MicroInterface.GetTemplatesIDUrl(mConfig.ServerHostOrIP, PortNumber, this.SmsModel.ST_SMSContent, this.SmsModel.ST_Category.ToString(), clearAccessToken);
- System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
-
- var result = client.GetAsync(url).Result;
- resultStr = result.Content.ReadAsStringAsync().Result;
- var retObj = Codeplex.Data.DynamicJson.Parse(resultStr);
- client.Dispose();*/
- // LYFZ.Model.Model_MicroInterface modelMIF = new BLL.BLL_MicroInterface().Model;
- string TemplatesNo = this.SmsModel.ST_SMSContent;
- EnumPublic.MicroTemplate TemplatesTitle = (EnumPublic.MicroTemplate)Convert.ToInt32(this.SmsModel.ST_Category.ToString());
- string getTemplatesUrl = "http://wx.lyfz.net/WeiXinAPP/WXServiceHandler.aspx?type=gettemplatesid&appid=" + modInterFace.AppID.Trim() + "&templatesno=" + TemplatesNo;
- string retTemplatesStr = LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestGET(getTemplatesUrl, Encoding.UTF8);
- //"{ \"errcode\":-100,\"errmsg\":\"发送模板消息失败\", \"msgid\":\"\"}";
- if (retTemplatesStr.Contains("\"errcode\":"))
- {
- var retTemplatesID = Codeplex.Data.DynamicJson.Parse(retTemplatesStr);// LYFZ.Weixin.SDK.TemplateMessageAPI.GetTemplates(LYFZ.Weixin.SDK.Helpers.TokenHelper.AccessToken, this.SmsModel.ST_SMSContent);
- if (retTemplatesID.errmsg.ToString().ToLower() == "ok")
- {
- LYFZ.Model.Model_SMSTemplates modelsmsT = new Model.Model_SMSTemplates();
- modelsmsT.ST_Type = (int)EnumPublic.SmsTemplateType.微信模板ID;
- modelsmsT.ST_Title = TemplatesTitle.ToString();
- modelsmsT.ST_Category = (int)TemplatesTitle;
- modelsmsT.ST_SMSContent = TemplatesNo;
- modelsmsT.ST_Remark = retTemplatesID.template_id.ToString();
- modelsmsT.ST_CreateDatetime = DateTime.Now;
- modelsmsT.ST_UpdateDatetime = DateTime.Now;
- modelsmsT.ST_DividedShop = LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID;
- if (mybllsmsT.Add(modelsmsT))
- {
- ExMessageBoxCustom.Show("添加微信模板成功。", backgroundWorker: backgroundWorker);
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- else
- {
- ExMessageBoxCustom.Show("向数据库插入记录时失败,请稍后重试。", backgroundWorker: backgroundWorker);
- }
- }
- else
- {
- ExMessageBoxCustom.Show("添加微信模板失败,错误代码:" + retTemplatesID.ToString(), backgroundWorker: backgroundWorker);
- }
- }
- else {
- ExMessageBoxCustom.Show("添加微信模板失败,原因:" + retTemplatesStr, backgroundWorker: backgroundWorker);
- }
- }
- catch (Exception ex){
- ExMessageBoxCustom.Show("添加微信模板失败,错误代码:" + ex.Message + "\r\n" + resultStr, backgroundWorker: backgroundWorker);
- }
- }
- else
- {
- backgroundWorker.ReportProgress(0, "正在保存模板...");
- if (smsDal.Add(this.SmsModel))
- {
- ExMessageBoxCustom.Show("添加微信模板成功。", backgroundWorker: backgroundWorker);
- this.DialogResult = System.Windows.Forms.DialogResult.OK;
- }
- else
- {
- ExMessageBoxCustom.Show("添加微信模板ID失败,请关闭软件并重新启动后再试。", backgroundWorker: backgroundWorker);
- }
- }
- }
- else
- {
- ExMessageBoxCustom.Show("要添加微信模板已经存在,如果你要更新模板,请删除后重试。", backgroundWorker: backgroundWorker);
- }
- });
- }
- }
- }
- }
|