using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Dynamic; namespace LYFZ.Software.MainBusiness.SMSManagement { public class frmAddMicroTemplate:LYFZ.Software.UI.SMSManagement.frmAddMicroTemplate { public frmAddMicroTemplate() { this.Load += frmAddSMSTemplate_Load; this.cboxEvent.SelectedIndexChanged += cboxEvent_SelectedIndexChanged; this.number.Value = 1; this.btnSave.Click += btnSave_Click; this.Shown += frmAddSMSTemplate_Shown; } /// /// 父窗体 /// public frmSMSTemplateSet ThisParentForm = null; void btnAddTemplate_Click(object sender, EventArgs e) { this.Hide(); frmAddMicroTemplateItem frmAddSTItem = new frmAddMicroTemplateItem(); if (frmAddSTItem.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { if (ThisParentForm != null) { ThisParentForm.tabControlEx1.SelectedIndex = 3; ThisParentForm.BindDgvMicroTemplateIDList(); } } catch { } } this.Close(); } /// /// 当前消息模板 /// EnumPublic.MicroTemplate _TemplateNo = EnumPublic.MicroTemplate.新订单通知; /// /// 当前消息模板 /// public EnumPublic.MicroTemplate TemplateNo { get { return _TemplateNo; } set { _TemplateNo = value; } } /// /// 当前短信类别 /// EnumPublic.SmsCategory sCategory = EnumPublic.SmsCategory.公共短信; /// /// 当前短信类别 /// public EnumPublic.SmsCategory SCategory { get { return sCategory; } set { sCategory = value; } } void frmAddSMSTemplate_Shown(object sender, EventArgs e) { } LYFZ.DAL.DAL_SMSTemplates smsDal = new DAL.DAL_SMSTemplates(); LYFZ.Model.Model_SMSTemplates smsModel = new Model.Model_SMSTemplates(); /// /// 当前模板对象 /// public LYFZ.Model.Model_SMSTemplates SmsModel { get { return smsModel; } set { smsModel = value; } } LYFZ.Model.Model_SMSTemplates _TemplateIDModel = new Model.Model_SMSTemplates(); /// /// 当前模板ID对象 /// public LYFZ.Model.Model_SMSTemplates TemplateIDModel { get { return _TemplateIDModel; } set { _TemplateIDModel = value; } } void btnSave_Click(object sender, EventArgs e) { if (this.cboxEvent.Text.Length <= 0) { MessageBoxCustom.Show("请选择模板消息发送事件"); return; } if (this.txtdescription.Text.Length <= 0) { MessageBoxCustom.Show("请输入消息描述"); return; } if (this.txtRemark.Text.Length <= 0) { MessageBoxCustom.Show("请输入消息备注"); return; } if (this.TemplateIDModel==null||this.TemplateIDModel.ID <= 0) { MessageBoxCustom.Show("当前选择事件还未设置消息模板,请在“微信模板库管理”设置好微信消息模板后重试"); return; } int sumSmsCount = 0; try { sumSmsCount = smsDal.GetRecordCount("ST_Type=" + (int)EnumPublic.SmsTemplateType.微信消息模板 + " and ST_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID + "'"); } catch { } smsModel.ST_Type = (int)EnumPublic.SmsTemplateType.微信消息模板; smsModel.ST_Title = this.TemplateNo.ToString(); smsModel.ST_Category=(int)this.SCategory; smsModel.ST_SendChannel = 1; smsModel.ST_ReceiveObjects = this.txtURL.Text.Trim(); smsModel.ST_SendEvent = (int)((EnumPublic.MicroSendEvent)Enum.Parse(typeof(EnumPublic.MicroSendEvent), this.cboxEvent.Text)); smsModel.ST_SMSContent = this.txtdescription.Text.Trim(); smsModel.ST_Remark = this.txtRemark.Text.Trim(); smsModel.ST_IsEnabled = this.checkBoxEx1.Checked; smsModel.ST_CreateDatetime = SDateTime.Now; smsModel.ST_UpdateDatetime = SDateTime.Now; smsModel.ST_DividedShop =LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID; this.smsModel.ST_SendEventValue = Convert.ToInt32(this.number.Value).ToString(); bool ret = false; if (smsModel.ID > 0) { ret = smsDal.Update(smsModel); } else { if (smsDal.GetRecordCount("ST_Type=" + smsModel.ST_Type.ToString() + " and [ST_Category]=" + smsModel.ST_Category.ToString() + " and [ST_SendEvent]=" + smsModel.ST_SendEvent.ToString() + " and [ST_Title]='" + smsModel.ST_Title + "' and ST_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID + "'") > 0) { MessageBoxCustom.Show("请不要重复添加模板"); return; } if (sumSmsCount > 1000) { MessageBoxCustom.Show("对不起,微信模板设置多只能添加1000条记录,请删除无用微信模板设置记录后重试。"); return; } ret = smsDal.Add(smsModel); } if (ret) { MessageBoxCustom.Show("保存成功\r\n温馨提醒:请不要在模板消息中输入任何营销类文字,严格按照微信公众号使用规范发送模板消息,以免被微信封号!!!"); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBoxCustom.Show("保存失败,请检查网络环境或关闭后重试。"); } } LYFZ.EnumPublic.MicroSendEvent currentEvent = EnumPublic.MicroSendEvent.客人订单后X分钟; /// /// 当前事件 /// public LYFZ.EnumPublic.MicroSendEvent CurrentEvent { get { return currentEvent; } set { currentEvent = value; } } LYFZ.ComponentLibrary.NumericUpDownEx number = new ComponentLibrary.NumericUpDownEx(); LYFZ.ComponentLibrary.NumericUpDownEx number2 = new ComponentLibrary.NumericUpDownEx(); LYFZ.ComponentLibrary.LabelEx labTxt = new ComponentLibrary.LabelEx(); void cboxEvent_SelectedIndexChanged(object sender, EventArgs e) { try { this.CurrentEvent = (EnumPublic.MicroSendEvent)Enum.Parse(typeof(EnumPublic.MicroSendEvent), this.cboxEvent.Text); this.TemplateNo = (EnumPublic.MicroTemplate)Convert.ToInt32(LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(this.CurrentEvent)); this.lbTitle.Text = this.TemplateNo.ToString(); this.lbContentExamples.Text = LYFZ.BLL.BLL_SMSTemplates.GetMicroTemplateExample(this.TemplateNo); this.TemplateIDModel = (LYFZ.Model.Model_SMSTemplates)smsDal.GetModelObject("ST_Category=" + (int)this.TemplateNo + " and ST_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID + "'"); this.lbNo.Text = this.TemplateIDModel.ST_Remark.Trim(); if (this.lbNo.Text.Trim().Length <= 1) { this.lbNo.Text = "没有找到相关模板"; this.lbNo.ForeColor = System.Drawing.Color.Red; } else { this.lbNo.ForeColor = this.lbTitle.ForeColor; } } catch { } // LYFZ.ComponentLibrary.TextBoxEx textBox = new ComponentLibrary.TextBoxEx(); this.plEventValue.Controls.Clear(); number.Maximum=999999; number.Minimum=0; number.TextAlign= System.Windows.Forms.HorizontalAlignment.Center; number.Width = 90; number.Font = this.cboxEvent.Font; number.Location = new System.Drawing.Point(10, 4); labTxt.Text = "分钟"; labTxt.Width = 60; labTxt.Font = this.cboxEvent.Font; labTxt.Location = new System.Drawing.Point(number.Location.X + number.Width+5,6); this.plEventValue.Controls.Add(number); this.plEventValue.Controls.Add(labTxt); this.lbTips.Text = GetControlPropertyAttribute(this.CurrentEvent,SCategory); } /// /// 设置事件值 /// /// void SetSendEventValue(string value) { int i = 0; if (value.Trim().Length > 0) { if (int.TryParse(value, out i)) { this.number.Value = i; } else if (value.Contains(":")) { string[] tempIs = value.Split(':'); if (tempIs.Length > 0) { if (int.TryParse(tempIs[0], out i)) { this.number.Value = i; } } if (tempIs.Length > 1) { if (int.TryParse(tempIs[1], out i)) { this.number2.Value = i; } } } } } /// /// 获取事件的说明属性信息 /// /// /// public static string GetControlPropertyAttribute(EnumPublic.MicroSendEvent sEvent,EnumPublic.SmsCategory sType) { string XXBString = ""; if (sType == EnumPublic.SmsCategory.儿童短信) { XXBString = "、XXB 为宝宝(儿童)名字 "; } return "说明:XXX 为客户姓名 " + XXBString + "\r\nXXSPDM 为店名、XXSPTEL 为本店电话、XXSPDZ 为本店地址、XXSPDZM 为本店店长"//XXSPWZ 为本店网址、 +"\r\n[注意替换代码一定要大写,客人称呼为“先生/女士”] 以上内容建义不要超过100个字符"; } void frmAddSMSTemplate_Load(object sender, EventArgs e) { BindSendEvent(); BindTemplateInfo(); } void BindTemplateInfo() { if (smsModel.ID > 0) { SetSendEventValue(SmsModel.ST_SendEventValue); this.checkBoxEx1.Checked = this.SmsModel.ST_IsEnabled; this.TemplateNo = (EnumPublic.MicroTemplate)Enum.Parse(typeof(EnumPublic.MicroTemplate), SmsModel.ST_Title); this.txtdescription.Text = SmsModel.ST_SMSContent; this.txtRemark.Text = SmsModel.ST_Remark; this.txtURL.Text = SmsModel.ST_ReceiveObjects; this.cboxEvent.SelectedItem = ((EnumPublic.MicroSendEvent)this.SmsModel.ST_SendEvent).ToString(); this.SCategory = (EnumPublic.SmsCategory)SmsModel.ST_Category; this.Text = "编辑" + this.SCategory.ToString().Replace("短信", "微信模板消息推送") + "事件设置"; } } /// /// 邦定短信事件 /// void BindSendEvent() { this.cboxEvent.Items.Clear(); this.cboxEvent.DataSource = GetEventList(); cboxEvent_SelectedIndexChanged(null,null); } List GetEventList() { List elist = new List(); //elist.AddRange(Enum.GetNames(typeof(LYFZ.EnumPublic.SmsSendEvent))); Array arrys = Enum.GetValues(typeof(LYFZ.EnumPublic.MicroSendEvent)); foreach (int value in arrys) { switch (this.SCategory) { case EnumPublic.SmsCategory.公共短信: if (value >= 999980) { elist.Add(((LYFZ.EnumPublic.MicroSendEvent)value).ToString()); } break; case EnumPublic.SmsCategory.婚纱短信: case EnumPublic.SmsCategory.儿童短信: case EnumPublic.SmsCategory.写真短信: case EnumPublic.SmsCategory.医院跟踪短信: if (value < 999980) { elist.Add(((LYFZ.EnumPublic.MicroSendEvent)value).ToString()); } break; case EnumPublic.SmsCategory.婚庆订单短信: case EnumPublic.SmsCategory.服务订单短信: if (value == 999901 || value == 999906 || value == 999907 || value == 999950 || value == 999951) { if (value != 999950) { if (value == 999951) { elist.Insert(1, LYFZ.EnumPublic.MicroSendEvent.服务预约后X分钟.ToString()); elist.Insert(2, LYFZ.EnumPublic.MicroSendEvent.服务完成后X分钟.ToString()); } else { elist.Add(((LYFZ.EnumPublic.MicroSendEvent)value).ToString()); } } } break; } } switch (this.SCategory) { case EnumPublic.SmsCategory.婚纱短信: case EnumPublic.SmsCategory.儿童短信: case EnumPublic.SmsCategory.写真短信: elist.Remove(EnumPublic.MicroSendEvent.服务预约后X分钟.ToString()); elist.Remove(EnumPublic.MicroSendEvent.服务完成后X分钟.ToString()); elist.Insert(3, EnumPublic.MicroSendEvent.服务预约后X分钟.ToString()); elist.Insert(4, EnumPublic.MicroSendEvent.服务完成后X分钟.ToString()); break; } return elist; } } }