using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LYFZ.Software.MainBusiness.SMSManagement { public class frmAddSMSTemplate:LYFZ.Software.UI.SMSManagement.frmAddSMSTemplate { public frmAddSMSTemplate() { this.Load += frmAddSMSTemplate_Load; this.cboxEvent.SelectedIndexChanged += cboxEvent_SelectedIndexChanged; this.number.Value = 1; this.btnSave.Click += btnSave_Click; this.Shown += frmAddSMSTemplate_Shown; this.linkSelectSms.Click += linkSelectSms_Click; this.txtSmsInfo.EventTextBoxEx_TextChanged += txtSmsInfo_EventTextBoxEx_TextChanged; this.lbWordCount.Text = SmsSend.FrmSendSms.GetlblNameTextString(0, 0); } void txtSmsInfo_EventTextBoxEx_TextChanged(object sender, EventArgs e) { string SmsInfo = txtSmsInfo.Text; this.lbWordCount.Text = SmsSend.FrmSendSms.GetlblNameTextString(SmsInfo.Length, SmsSend.FrmSendSms.GetSmsSizeCount(SmsInfo.ToString(), SmsSend.FrmSendSms.Works64)); } /// /// 当前短信类别 /// EnumPublic.SmsCategory sCategory = EnumPublic.SmsCategory.公共短信; /// /// 当前短信类别 /// public EnumPublic.SmsCategory SCategory { get { return sCategory; } set { sCategory = value; } } void linkSelectSms_Click(object sender, EventArgs e) { frmSelectSmsInfo selectInfo = new frmSelectSmsInfo(); if (selectInfo.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (selectInfo.SmsModel.ID > 0) { this.txtSmsInfo.Text = selectInfo.SmsModel.ST_SMSContent; } } } void frmAddSMSTemplate_Shown(object sender, EventArgs e) { if (this.SmsModel.ID > 0) { this.cboxEvent.SelectedItem = ((EnumPublic.SmsSendEvent)this.SmsModel.ST_SendEvent).ToString(); this.SCategory = (EnumPublic.SmsCategory)SmsModel.ST_Category; } this.Text = "添加" + this.SCategory.ToString() + "事件设置"; } 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; } } void btnSave_Click(object sender, EventArgs e) { if (this.cboxEvent.Text.Length <= 0) { MessageBoxCustom.Show("请选择短信发送事件"); return; } if (this.txtSmsInfo.Text.Length <= 0) { MessageBoxCustom.Show("请输入短信内容"); return; } if (this.txtReceiver.Text.Length <= 0) { MessageBoxCustom.Show("请输入短信接收手机号"); return; } int sumSmsCount = 0; try { sumSmsCount = smsDal.GetRecordCount("ST_Type=1 and ST_DividedShop='" + LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID.Trim() + "'"); } catch { } smsModel.ST_Type = (int)EnumPublic.SmsTemplateType.事件短信; smsModel.ST_Title = ""; smsModel.ST_Category=(int)this.SCategory; smsModel.ST_SendChannel = 0; smsModel.ST_ReceiveObjects = this.txtReceiver.Text.Trim(); smsModel.ST_SendEvent = (int)((EnumPublic.SmsSendEvent)Enum.Parse(typeof(EnumPublic.SmsSendEvent), this.cboxEvent.Text)); smsModel.ST_SMSContent = this.txtSmsInfo.Text; smsModel.ST_IsEnabled = this.checkBoxEx1.Checked; smsModel.ST_CreateDatetime = SDateTime.Now; smsModel.ST_UpdateDatetime = SDateTime.Now; smsModel.ST_DividedShop = LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID; if (smsModel.ST_ReceiveObjects.Split(',').Length > 100) { MessageBoxCustom.Show("最多只能输入100个手机号!"); return; } switch (this.CurrentEvent) { case EnumPublic.SmsSendEvent.每天X时X分发送财务短信到X手机: string retMsg = LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(this.txtReceiver.Text.Trim()); if (retMsg.Trim().Length > 0) { MessageBoxCustom.Show("手机号输入错误:" + retMsg); return; } this.smsModel.ST_SendEventValue = Convert.ToInt32(this.number.Value).ToString() + ":" + Convert.ToInt32(this.number2.Value).ToString(); break; case EnumPublic.SmsSendEvent.宝宝生日前X天且X岁以下: case EnumPublic.SmsSendEvent.宝宝X岁前X天成长跟踪短信: this.smsModel.ST_SendEventValue = Convert.ToInt32(this.number.Value).ToString() + ":" + Convert.ToInt32(this.number2.Value).ToString(); break; case EnumPublic.SmsSendEvent.客户来电挂机后X分钟: case EnumPublic.SmsSendEvent.未知来电挂机后X分钟: case EnumPublic.SmsSendEvent.员工来电挂机后X分钟: this.smsModel.ST_SendEventValue = Convert.ToInt32(this.number.Value).ToString() + ":" + ((ItemValue)comBox.SelectedItem).Value.ToString(); break; case EnumPublic.SmsSendEvent.客户云选片完成后发通知短信: case EnumPublic.SmsSendEvent.客户云看样完成后发通知短信: string retMsg2 = LYFZ.WinAPI.CustomPublicMethod.ValidationPhones(this.txtReceiver.Text.Trim()); if (retMsg2.Trim().Length > 0) { MessageBoxCustom.Show("手机号输入错误:" + retMsg2); return; } this.smsModel.ST_SendEventValue = "0"; break; default: this.smsModel.ST_SendEventValue = Convert.ToInt32(this.number.Value).ToString(); break; } bool ret = false; if (smsModel.ID > 0) { ret = smsDal.Update(smsModel); } else { if (sumSmsCount > 1000) { MessageBoxCustom.Show("对不起,短信设置多只能添加1000条记录,请删除无用短信设置记录后重试。"); return; } try { sumSmsCount = smsDal.GetRecordCount(String.Format("ST_Type=1 and ST_DividedShop='{0}' and ST_Category={3} and ST_SendEvent={1} and ST_SendEventValue='{2}'", LYFZ.BLL.BLL_ErpCompanyInfo.CurrentCompanyInfoID.Trim(), smsModel.ST_SendEvent, this.smsModel.ST_SendEventValue, this.smsModel.ST_Category)); } catch { } if (sumSmsCount > 0) { MessageBoxCustom.Show("对不起,相同类型事件的短信模板已以存在,请不要重复添加。"); return; } ret = smsDal.Add(smsModel); } if (ret) { MessageBoxCustom.Show("保存成功"); this.DialogResult = System.Windows.Forms.DialogResult.OK; } else { MessageBoxCustom.Show("保存失败,请检查网络环境或关闭后重试。"); } } LYFZ.EnumPublic.SmsSendEvent currentEvent = EnumPublic.SmsSendEvent.客人生日前X天; /// /// 当前事件 /// public LYFZ.EnumPublic.SmsSendEvent 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(); LYFZ.ComponentLibrary.LabelEx labTxt2 = new ComponentLibrary.LabelEx(); LYFZ.ComponentLibrary.ComboBoxEx comBox = new ComponentLibrary.ComboBoxEx(); void cboxEvent_SelectedIndexChanged(object sender, EventArgs e) { try { this.CurrentEvent = (EnumPublic.SmsSendEvent)Enum.Parse(typeof(EnumPublic.SmsSendEvent), this.cboxEvent.Text); } 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); comBox.Items.Clear(); comBox.ReadOnly = true; comBox.Width = 90; comBox.Font= this.cboxEvent.Font; comBox.Location = new System.Drawing.Point(labTxt.Location.X + labTxt.Width, 4); comBox.Items.Add(new ItemValue("y","一年内一次")); comBox.Items.Add(new ItemValue("m", "一月内一次")); comBox.Items.Add(new ItemValue("d", "一天内一次")); // comBox.Items.Add(new ItemValue("a", "实时发送")); comBox.SelectedIndex = 0; number2.Maximum = 59; number2.Minimum = 0; number2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; number2.Width = 90; number2.Font = this.cboxEvent.Font; number2.Location = new System.Drawing.Point(labTxt.Location.X + labTxt.Width, 4); labTxt2.Text = "分"; labTxt2.Font = this.cboxEvent.Font; labTxt2.Location = new System.Drawing.Point(number2.Location.X + number2.Width + 5, 6); this.plEventValue.Controls.Add(number); this.plEventValue.Controls.Add(labTxt); labTxt.Text = "分钟"; this.lbTips.Text = GetControlPropertyAttribute(this.CurrentEvent); this.txtSmsInfo.ReadOnly = false; this.linkSelectSms.Enabled = true; this.txtReceiver.ReadOnly = true; this.txtReceiver.Text = "相关客户"; if (smsModel.ID > 0) { this.txtReceiver.Text = SmsModel.ST_ReceiveObjects; this.txtSmsInfo.Text = SmsModel.ST_SMSContent; SetSendEventValue(SmsModel.ST_SendEventValue); this.checkBoxEx1.Checked = this.SmsModel.ST_IsEnabled; } if (this.CurrentEvent != EnumPublic.SmsSendEvent.每天X时X分发送财务短信到X手机) { if (this.txtSmsInfo.Text.Trim() == "系统自动生成") { this.txtSmsInfo.Text = ""; } } switch (this.CurrentEvent) { case EnumPublic.SmsSendEvent.客人订单后X分钟: case EnumPublic.SmsSendEvent.订单件齐后X分钟发送取件通知: case EnumPublic.SmsSendEvent.拍照预约后X分钟: case EnumPublic.SmsSendEvent.拍照完成后X分钟: case EnumPublic.SmsSendEvent.服务预约后X分钟: case EnumPublic.SmsSendEvent.服务完成后X分钟: case EnumPublic.SmsSendEvent.客人预约选片后X分钟: case EnumPublic.SmsSendEvent.客人选片完成后X分钟: case EnumPublic.SmsSendEvent.客人预约看样后X分钟: case EnumPublic.SmsSendEvent.客人看样后X分钟: case EnumPublic.SmsSendEvent.客人取件后X分钟: case EnumPublic.SmsSendEvent.转介绍后X分钟发送短信给介绍人: case EnumPublic.SmsSendEvent.发放会员卡后X分钟发会员短信: case EnumPublic.SmsSendEvent.现金卡消费后X分钟后发提醒短信: case EnumPublic.SmsSendEvent.现金卡充值后X分钟后发提醒短信: case EnumPublic.SmsSendEvent.来单录入后X分钟: case EnumPublic.SmsSendEvent.会员积分变动后X分钟: case EnumPublic.SmsSendEvent.删除会员后X分钟: case EnumPublic.SmsSendEvent.注消会员后X分钟: case EnumPublic.SmsSendEvent.修改会员支付密码后X分钟: case EnumPublic.SmsSendEvent.会员服务卡使用后X分钟: case EnumPublic.SmsSendEvent.礼服出租订单后X分钟: case EnumPublic.SmsSendEvent.礼服出租还衣后X分钟: case EnumPublic.SmsSendEvent.礼服出售订单后X分钟: case EnumPublic.SmsSendEvent.积分兑换后X分钟发提醒短信: case EnumPublic.SmsSendEvent.会员返现卡提现后X分钟: case EnumPublic.SmsSendEvent.会员返现卡获得返现金后X分钟: case EnumPublic.SmsSendEvent.支付成功后X分钟发提醒消息: case EnumPublic.SmsSendEvent.客片上传完成后X分钟发通知短信: labTxt.Text = "分钟"; this.txtReceiver.Text = "相关客户"; break; case EnumPublic.SmsSendEvent.客户来电挂机后X分钟: case EnumPublic.SmsSendEvent.未知来电挂机后X分钟: this.plEventValue.Controls.Add(comBox); this.plEventValue.Controls.Add(labTxt2); labTxt2.Text = "发送周期"; labTxt.Text = "分钟"; this.txtReceiver.Text = "相关客户"; break; case EnumPublic.SmsSendEvent.礼服出租还衣前X天: case EnumPublic.SmsSendEvent.礼服出租取衣前X天: case EnumPublic.SmsSendEvent.礼服出售取衣前X天: case EnumPublic.SmsSendEvent.客人生日前X天: case EnumPublic.SmsSendEvent.客人婚礼前X天: case EnumPublic.SmsSendEvent.结婚纪念日前X天: case EnumPublic.SmsSendEvent.宝宝生日前X天: case EnumPublic.SmsSendEvent.宝宝X天成长跟踪短信: case EnumPublic.SmsSendEvent.家长生日前X天: case EnumPublic.SmsSendEvent.怀孕X天周期跟踪短信: case EnumPublic.SmsSendEvent.会员积分有效期到期前X天: case EnumPublic.SmsSendEvent.会员储值有效期到期前X天: case EnumPublic.SmsSendEvent.会员服务套餐有效期到期前X天: case EnumPublic.SmsSendEvent.会员新摄会有效期到期前X天: case EnumPublic.SmsSendEvent.会员返现卡有效期到期前X天: case EnumPublic.SmsSendEvent.拍照预约后拍照前X天: case EnumPublic.SmsSendEvent.服务预约后服务前X天: case EnumPublic.SmsSendEvent.选片预约后选片前X天: case EnumPublic.SmsSendEvent.看样预约后看样前X天: labTxt.Text = "天"; this.txtReceiver.Text = "相关客户"; break; case EnumPublic.SmsSendEvent.宝宝生日前X天且X岁以下: labTxt.Text = "天"; this.txtReceiver.Text = "相关客户"; this.plEventValue.Controls.Add(number2); this.plEventValue.Controls.Add(labTxt2); labTxt2.Text = "岁以下"; break; case EnumPublic.SmsSendEvent.员工生日前X天: labTxt.Text = "天"; this.txtReceiver.Text = "相关员工"; break; case EnumPublic.SmsSendEvent.员工来电挂机后X分钟: this.plEventValue.Controls.Add(comBox); this.plEventValue.Controls.Add(labTxt2); labTxt2.Text = "发送周期"; labTxt.Text = "分钟"; this.txtReceiver.Text = "相关员工"; break; case EnumPublic.SmsSendEvent.宝宝X岁前X天成长跟踪短信: labTxt.Text = "岁 前"; this.txtReceiver.Text = "相关客户"; this.plEventValue.Controls.Add(number2); this.plEventValue.Controls.Add(labTxt2); labTxt2.Text = "天"; break; case EnumPublic.SmsSendEvent.当积分接近X的百分之80时: case EnumPublic.SmsSendEvent.当积分达到或超过X分时: labTxt.Text = "分"; this.txtReceiver.Text = "相关客户"; break; case EnumPublic.SmsSendEvent.每天X时X分发送财务短信到X手机: labTxt.Text = "时"; this.plEventValue.Controls.Add(number2); this.plEventValue.Controls.Add(labTxt2); labTxt2.Text = "分"; this.txtSmsInfo.ReadOnly = true; this.txtSmsInfo.Text = "系统自动生成"; this.txtReceiver.ReadOnly = false; this.linkSelectSms.Enabled = false; if (this.txtReceiver.Text.Trim().Contains("相关")) { this.txtReceiver.Text = ""; } this.lbTips.Text = ""; break; case EnumPublic.SmsSendEvent.员工生日前X天发送短信给X手机号: labTxt.Text = "天"; this.txtReceiver.ReadOnly = false; this.linkSelectSms.Enabled = true; if (this.txtReceiver.Text.Trim().Contains("相关")) { this.txtReceiver.Text = ""; } break; case EnumPublic.SmsSendEvent.女宾生日前X天发短信给男宾: case EnumPublic.SmsSendEvent.男宾生日前X天发短信给女宾: labTxt.Text = "天"; this.txtReceiver.Text = "相关客户"; break; case EnumPublic.SmsSendEvent.客户云选片完成后发通知短信: case EnumPublic.SmsSendEvent.客户云看样完成后发通知短信: this.plEventValue.Controls.Clear(); this.txtReceiver.ReadOnly = false; if (this.txtReceiver.Text.Trim().Contains("相关")) { this.txtReceiver.Text = ""; } break; } } /// /// 设置事件值 /// /// 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; } else if (tempIs[1].Trim().Length==1) { switch (tempIs[1].Trim()) { case "y": comBox.SelectedIndex = 0; break; case "m": comBox.SelectedIndex = 1; break; case "d": comBox.SelectedIndex = 2; break; case "a": comBox.SelectedIndex = 3; break; } } } } } } /// /// 获取事件的说明属性信息 /// /// /// string GetControlPropertyAttribute(EnumPublic.SmsSendEvent sEvent) { string ret = LYFZ.WinAPI.CustomPublicMethod.ConvertEnumToDescription(sEvent); if (!ret.Contains("说明:")) { ret = "说明:“XXX先生/女士”、“XXX先生”、“XXX女士”为客户姓名和称呼"; } string XXBString = ""; if (SCategory == EnumPublic.SmsCategory.儿童短信) { if (!ret.Contains("XXB")) { XXBString = "、XXB 为宝宝(儿童)名字 "; } } if (sEvent == EnumPublic.SmsSendEvent.客户云选片完成后发通知短信 || sEvent == EnumPublic.SmsSendEvent.客户云看样完成后发通知短信) { return ret.Replace(":XXX", ":“XXX先生/女士”、“XXX先生”、“XXX女士”").Replace("姓名;", "姓名和称呼;") + " \r\n[注意替换代码一定要大写,客人称呼为“先生/女士”]"; } else { return ret.Replace(":XXX", ":“XXX先生/女士”、“XXX先生”、“XXX女士”").Replace("姓名;", "姓名和称呼;") + "\r\nXXSPDM 为店名、XXSPTEL 为本店电话、XXSPDZ 为本店地址、XXSPDZM 为本店店长 "//XXSPWZ 为本店网址、 + XXBString + " \r\n[注意替换代码一定要大写,客人称呼为“先生/女士”]"; } } void frmAddSMSTemplate_Load(object sender, EventArgs e) { BindSendEvent(); } /// /// 邦定短信事件 /// void BindSendEvent() { this.cboxEvent.Items.Clear(); this.cboxEvent.DataSource = GetEventList(this.SCategory); } List GetEventList(EnumPublic.SmsCategory _SCategory) { List elist = new List(); string[] arrys = Enum.GetNames(typeof(LYFZ.EnumPublic.SmsSendEvent)); int[] continueValues = new int[] { 120, 121, 107, 108, 109, 110 }; foreach (string sName in arrys) { LYFZ.EnumPublic.SmsSendEvent sEvent = (LYFZ.EnumPublic.SmsSendEvent)Enum.Parse(typeof(LYFZ.EnumPublic.SmsSendEvent), sName); int value = (int)sEvent; //用于调整“订单件齐后X分钟发送取件通知”的位置 if (sEvent == EnumPublic.SmsSendEvent.订单件齐后X分钟发送取件通知) { continue; } if (_SCategory != EnumPublic.SmsCategory.公共短信 && _SCategory != EnumPublic.SmsCategory.医院跟踪短信 && _SCategory != EnumPublic.SmsCategory.礼服管理短信 && sEvent == EnumPublic.SmsSendEvent.客人取件后X分钟) { elist.Add(EnumPublic.SmsSendEvent.订单件齐后X分钟发送取件通知.ToString()); } // if (value == 120 || value == 121) if(continueValues.Any(i=>i==value)) { continue; } //end switch (_SCategory) { case EnumPublic.SmsCategory.公共短信: if ((value > 900 && value < 9990) || value == 114) { elist.Add(sEvent.ToString()); } break; case EnumPublic.SmsCategory.婚纱短信: if ((value < 200 || (value >= 300 && value < 400)) && value != 114) { elist.Add(sEvent.ToString()); } break; case EnumPublic.SmsCategory.儿童短信: if (value < 300 && value != 114) { elist.Add(sEvent.ToString()); } break; case EnumPublic.SmsCategory.写真短信: if (value < 200 && value != 114) { elist.Add(sEvent.ToString()); } break; case EnumPublic.SmsCategory.医院跟踪短信: if (value == 217 || value == 218 || value == 219 || value == 9991 || value == 9992) { elist.Add(sEvent.ToString()); } break; case EnumPublic.SmsCategory.婚庆订单短信: case EnumPublic.SmsCategory.服务订单短信: if ((value > 400 && value < 500) || value == 100 || value == 101 || value == 106) { if (value != 450) { if (value == 451) { elist.Insert(1, EnumPublic.SmsSendEvent.服务预约后X分钟.ToString()); elist.Insert(2, sEvent.ToString()); } else { elist.Add(sEvent.ToString()); } } } break; case EnumPublic.SmsCategory.礼服管理短信: if ((value > 800 && value < 900)) { elist.Add(sEvent.ToString()); } break; } } switch (_SCategory) { case EnumPublic.SmsCategory.婚纱短信: case EnumPublic.SmsCategory.儿童短信: case EnumPublic.SmsCategory.写真短信: elist.Insert(3, EnumPublic.SmsSendEvent.服务预约后X分钟.ToString()); elist.Insert(4, EnumPublic.SmsSendEvent.服务完成后X分钟.ToString()); elist.Insert(5, EnumPublic.SmsSendEvent.客人预约选片后X分钟.ToString()); elist.Insert(7, EnumPublic.SmsSendEvent.客人预约看样后X分钟.ToString()); elist.Insert(2, EnumPublic.SmsSendEvent.拍照预约后拍照前X天.ToString()); elist.Insert(5, EnumPublic.SmsSendEvent.服务预约后服务前X天.ToString()); elist.Insert(8, EnumPublic.SmsSendEvent.选片预约后选片前X天.ToString()); elist.Insert(11, EnumPublic.SmsSendEvent.看样预约后看样前X天.ToString()); break; case EnumPublic.SmsCategory.婚庆订单短信: case EnumPublic.SmsCategory.服务订单短信: elist.Insert(2, EnumPublic.SmsSendEvent.服务预约后服务前X天.ToString()); break; } return elist; } } }