Esempio n. 1
0
        /// <summary>
        /// 短信群发
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="sendMsg"></param>
        /// <param name="qishu"></param>
        /// <param name="condition"></param>
        /// <param name="enumStatus"></param>
        /// <param name="outMsg"></param>
        /// <param name="Dtable"></param>
        /// <returns></returns>
        public static bool SendMsg(SqlTransaction tran, string sendMsg, int qishu, string condition, Model.EnumStatusModel enumStatus, out string outMsg, int IsTrem, string number)
        {
            string    ExSql    = string.Empty;
            string    tbName   = string.Empty;//
            string    columns  = string.Empty;
            string    tableMIB = " MemberInfoBalance" + qishu;
            DataTable dt       = null;

            if (IsTrem == 0)
            {
                if (enumStatus == Model.EnumStatusModel.enum_StatusMember)
                {//
                    columns = "mi.MobileTele,mi.Number as No,mib.CurrentTotalMoney,mi.Name,mi.PetName as PetName";
                    tbName  = " MemberInfo mi inner join " + tableMIB + " mib on mi.Number=mib.Number ";
                }
                else if (enumStatus == Model.EnumStatusModel.enum_StatusStore)
                {//
                    columns = " si.MobileTele ,si.StoreID as No,si.Name,si.StoreName as PetName ";
                    tbName  = " StoreInfo si ";
                }
                ExSql = "select " + columns + " from " + tbName + " where " + condition;



                dt = DAL.DBHelper.ExecuteDataTable(tran, ExSql);
            }
            else
            {
                SqlParameter[] par = new SqlParameter[] {
                    new SqlParameter("@number", number),
                    new SqlParameter("@qishu", qishu),
                    new SqlParameter("@type", IsTrem)
                };
                dt = DAL.DBHelper.ExecuteDataTable(tran, "GetTremMobile", par, CommandType.StoredProcedure);
            }

            Regex rxNo      = new Regex(@"(\[No\])", RegexOptions.IgnoreCase);
            Regex rxName    = new Regex(@"(\[Name\])", RegexOptions.IgnoreCase);
            Regex rxPetName = new Regex(@"(\[PetName\])", RegexOptions.IgnoreCase);
            Regex rxMobile  = new Regex(@"(1)\d{12}", RegexOptions.IgnoreCase);


            string mobile  = string.Empty;
            string No      = string.Empty;
            string name    = string.Empty;
            string petName = string.Empty;
            bool   flag    = false;
            int    pointer = 0;
            string tempMsg = string.Empty;
            string outInfo = string.Empty;

            foreach (DataRow dr in dt.Rows)
            {
                mobile = dr["MobileTele"].ToString().Trim();
                if (mobile != "" && !rxMobile.IsMatch(mobile))
                {
                    tempMsg = sendMsg;
                    No      = dr["No"].ToString().Trim();
                    name    = Encryption.Encryption.GetDecipherName(dr["Name"].ToString().Trim());
                    petName = Encryption.Encryption.GetDecipherName(dr["PetName"].ToString().Trim());
                    tempMsg = rxName.Replace(tempMsg, name);
                    tempMsg = rxPetName.Replace(tempMsg, petName);
                    tempMsg = rxNo.Replace(tempMsg, No);
                    flag    = BLL.MobileSMS.SendMsgTo(tran, No, "", mobile, tempMsg, out outInfo, Model.SMSCategory.sms_GroupSend);
                    if (flag)
                    {
                        pointer++;
                    }
                }
            }
            if (pointer == 0)
            {
                outMsg = BLL.Translation.Translate("007143", "无接收对象或接收对象手机号码有误");
                flag   = false;
            }
            else
            {
                outMsg = BLL.Translation.Translate("005615", "发送成功");
                flag   = true;
            }


            return(flag);
        }
Esempio n. 2
0
    protected void btnSend_Click(object sender, EventArgs e)
    {
        string mobile = string.Empty;
        int    IsTrem = 0;
        string number = "";
        string msg    = BLL.CommonClass.ValidData.InputText(this.txtMsg.Text.Trim());

        if (msg == "")
        {
            BLL.CommonClass.Transforms.JSAlert(GetTran("005813", "请填写发送内容"));
            return;
        }
        else if (msg.Length > 256)
        {
            BLL.CommonClass.Transforms.JSAlert(BLL.Translation.Translate("006807", "短信内容不能超过256个字符!"));
            return;
        }

        string         bianhao      = string.Empty;
        string         info         = string.Empty;
        string         selectRValue = this.ddlRecever.SelectedItem.Value.Trim();
        string         keyCodes     = BLL.CommonClass.ValidData.InputText(this.txtkeyWords.Text);
        SqlTransaction tran         = null;
        SqlConnection  con          = DAL.DBHelper.SqlCon();

        try
        {
            con.Open();
            tran = con.BeginTransaction();
            string MobileErr = string.Empty;
            string MobileSuc = string.Empty;
            if (selectRValue == "-1")
            {//向指定号码发送
                if (ListBoxMobiles.Items.Count < 1)
                {
                    BLL.CommonClass.Transforms.JSAlert(GetTran("005812", "请添加手机号码"));
                    return;
                }
                foreach (ListItem li in ListBoxMobiles.Items)
                {
                    mobile = li.Value.Trim();
                    bool flag = BLL.MobileSMS.SendMsgTo(tran, bianhao, bianhao, mobile, msg, out info, Model.SMSCategory.sms_ManualSent);
                    if (!flag)
                    {
                        if (MobileErr == "")
                        {
                            MobileErr += mobile;
                        }
                        else
                        {
                            MobileErr += "," + mobile;
                        }
                    }
                    else
                    {
                        if (MobileSuc == "")
                        {
                            MobileSuc += mobile;
                        }
                        else
                        {
                            MobileSuc += "," + mobile;
                        }
                    }
                }
                if (MobileErr == "")
                {
                    BLL.CommonClass.Transforms.JSAlert(GetTran("005615", "发送成功!"));
                    this.txtMsg.Text = string.Empty;
                }
                else
                {
                    BLL.CommonClass.Transforms.JSAlert("(" + MobileErr + ")" + GetTran("005616", "发送失败") + ":" + info);
                }
            }
            else
            {//向特定群体发送
                string condition = " 1=1 ";
                int    jibie     = int.Parse(this.ddlJibie.SelectedValue.Trim());
                int    typeValue = int.Parse(this.ddlMemberType.SelectedValue.Trim());
                int    qishu     = int.Parse(this.ddlQishu.SelectedItem.Value.Trim());
                Model.EnumStatusModel enumStatus = Model.EnumStatusModel.enum_StatusStore;
                if (selectRValue == "2")
                {
                    #region //向店长发送
                    enumStatus = Model.EnumStatusModel.enum_StatusStore;
                    if (jibie != -1)
                    {
                        condition += " and  StoreLevelInt=" + jibie + " ";
                    }
                    #endregion
                }
                else if (selectRValue == "3")
                {
                    #region //向会员发送
                    enumStatus = Model.EnumStatusModel.enum_StatusMember;
                    condition += " and mi.MemberState=1 and mi.Number not in(select userid from BlackList)";
                    if (typeValue == 0)
                    {//今天生日的会员
                        DateTime dateNow = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd"));
                        //condition += " and Birthday between '" + dateNow + "' and '" + dateNow.AddDays(1) + "' ";
                        condition += " and datepart(month,birthday)=" + DateTime.UtcNow.Month + " and datepart(day,birthday)=" + DateTime.UtcNow.Day + "";
                    }
                    else if (typeValue == 1)
                    {
                        if (jibie != -1)
                        {
                            condition += " and  LevelInt=" + jibie + " ";
                        }
                        double bonus = 0;

                        if (qishu != -1)
                        {
                            if (keyCodes == "")
                            {
                                keyCodes = "0";
                            }
                            try
                            {
                                if (keyCodes.Length > 11)
                                {
                                    BLL.CommonClass.Transforms.JSAlert(GetTran("006579", "奖金格式错误"));
                                    return;
                                }
                                bonus = double.Parse(keyCodes);
                            }
                            catch
                            {
                                BLL.CommonClass.Transforms.JSAlert(GetTran("006579", "奖金格式错误"));
                                return;
                            }
                            if (bonus > 0)
                            {
                                string match = this.ddlMatch.SelectedItem.Value.Trim();
                                Regex  rx0   = new Regex(@"(&gt;)", RegexOptions.IgnoreCase);
                                Regex  rx1   = new Regex(@"(&lt;)", RegexOptions.IgnoreCase);
                                match      = rx0.Replace(match, ">");
                                match      = rx1.Replace(match, "<");
                                condition += " and CurrentTotalMoney>0 and CurrentTotalMoney " + match + " " + keyCodes;
                            }
                        }
                    }
                    else if (typeValue == 2)
                    {
                        IsTrem = 2;
                        number = this.MangeTerm.Text.Trim();
                        if (string.IsNullOrEmpty(number))
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + GetTran("000000", "请填写团队网络起点") + "')", true);
                            return;
                        }
                    }

                    else if (typeValue == 3)
                    {
                        IsTrem = 1;
                        number = this.MangeTerm.Text.Trim();
                        if (string.IsNullOrEmpty(number))
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "", "alert('" + GetTran("000000", "请填写团队网络起点") + "')", true);
                            return;
                        }
                    }
                    #endregion
                }
                bool flag = BLL.other.Company.SMSBLL.SendMsg(tran, msg, qishu, condition, enumStatus, out info, IsTrem, number);
            }
            tran.Commit();
            BLL.CommonClass.Transforms.JSAlert(info);
            this.txtMsg.Text = string.Empty;
        }
        catch (Exception ex)
        {
            tran.Rollback();
            BLL.CommonClass.Transforms.JSAlert(GetTran("000004", "异常") + ":" + ex.Message);
        }
        finally
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
        }
    }