Ejemplo n.º 1
0
        //确定
        private void btnOk_Click(object sender, EventArgs e)
        {
            String TypeStr        = "";
            String CopyRightToCOM = "";
            String CopyRightStr   = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";

            if (SmsClass.Sms_Connection(CopyRightStr, (uint)(port.SelectedIndex + 1), uint.Parse(baud.Text), out TypeStr, out CopyRightToCOM) != 1)
            {
                GeneralClass.printErrorMsg("设置出错,请重试!");
                return;
            }

            SmsClass.Sms_Disconnection();
            BathClass.printInformation("设置成功!");
            IOUtil.set_config_by_key(ConfigKeys.KEY_SMSPORT, port.Text);
            IOUtil.set_config_by_key(ConfigKeys.KEY_SMSBAUD, baud.Text);
            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 2
0
        //发送单条短信
        private void BtnSendOneMsg_Click(object sender, EventArgs e)
        {
            stop_flag = true;
            if (dgv.CurrentCell == null)
            {
                return;
            }

            String TypeStr        = "";
            String CopyRightToCOM = "";
            String CopyRightStr   = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";

            smsPort = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSPORT);
            smsBaud = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSBAUD);
            if (smsPort == "" || smsBaud == "")
            {
                SMmsForm smsForm = new SMmsForm();
                if (smsForm.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                smsPort = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSPORT);
                smsBaud = IOUtil.get_config_by_key(ConfigKeys.KEY_SMSBAUD);
            }

            if (smsPort == "" || smsBaud == "" || msg.Text == "")
            {
                return;
            }

            if (SmsClass.Sms_Connection(CopyRightStr, uint.Parse(smsPort[3].ToString()), uint.Parse(smsBaud), out TypeStr, out CopyRightToCOM) != 1)
            {
                this.Invoke(new delegate_no_para(close_smsMsgForm));
                BathClass.printErrorMsg("短信猫连接失败,请重试!");
                return;
            }

            DataGridViewRow r = dgv.CurrentRow;

            change_row_color(r, Color.Cyan);
            string phone = MConvert <string> .ToTypeOrDefault(r.Cells[2].Value, "");

            if (phone.Length != 11)
            {
                BathClass.printErrorMsg("电话号码格式不正确,需要11位电话号码");
                change_row_color(r, Color.OrangeRed);
            }

            if (SmsClass.Sms_Send(phone, msg.Text) == 0)
            {
                BathClass.printErrorMsg("发送失败!");
                change_row_color(r, Color.OrangeRed);
            }
            else
            {
                BathClass.printInformation("发送成功!");
                change_row_color(r, Color.LightGreen);
            }

            SmsClass.Sms_Disconnection();
        }
Ejemplo n.º 3
0
        //发送短信线程
        private void sendMsg_thread()
        {
            try
            {
                String TypeStr        = "";
                String CopyRightToCOM = "";
                String CopyRightStr   = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";

                this.Invoke(new delegate_no_para(show_smsMsgForm));
                this.Invoke(new delegate_msgForm_addMsg(msgForm_addMsg), new object[] { "正在连接短信猫......." });
                if (SmsClass.Sms_Connection(CopyRightStr, uint.Parse(smsPort[3].ToString()), uint.Parse(smsBaud), out TypeStr, out CopyRightToCOM) != 1)
                {
                    this.Invoke(new delegate_no_para(close_smsMsgForm));
                    BathClass.printErrorMsg("短信猫连接失败,请重试!");
                    return;
                }

                List <string> phones   = new List <string>();
                string        phone    = "";
                string        fileName = "短信发送-" + DateTime.Now.ToString("yyMMddHHmm") + ".txt";
                IOUtil.insert_file(" 卡号   姓名    电话          短信", fileName);
                int i = 0;

                string txtStart = TextMsgStart.Text.Trim();
                if (txtStart != "")
                {
                    i = MConvert <int> .ToTypeOrDefault(txtStart, 1) - 1;
                }
                string sent_flag = "成功";
                while (!stop_flag)
                {
                    if (i >= dgv.Rows.Count)
                    {
                        break;
                    }

                    if (smsMsgForm.IsDisposed)
                    {
                        SmsClass.Sms_Disconnection();
                        break;
                    }
                    sent_flag = "成功";
                    DataGridViewRow r = dgv.Rows[i];
                    this.Invoke(new delegate_change_current_cell(change_current_cell), new object[] { i });
                    this.Invoke(new delegate_change_row_color(change_row_color), new object[] { r, Color.Cyan });
                    phone = MConvert <string> .ToTypeOrDefault(r.Cells[2].Value, "");

                    if (phone.Length != 11 || phones.Contains(phone))
                    {
                        i++;
                        this.Invoke(new delegate_change_row_color(change_row_color), new object[] { r, Color.OrangeRed });
                        continue;
                    }
                    if (SmsClass.Sms_Send(phone, msg.Text) == 0)
                    {
                        sent_flag = "失败";
                        this.Invoke(new delegate_change_row_color(change_row_color), new object[] { r, Color.OrangeRed });
                    }
                    else
                    {
                        phones.Add(phone);
                        this.Invoke(new delegate_change_row_color(change_row_color), new object[] { r, Color.LightGreen });
                    }

                    this.Invoke(new delegate_msgForm_addMsg(msgForm_addMsg),
                                new object[] { "卡号:" + MConvert <string> .ToTypeOrDefault(r.Cells[0].Value, "") +
                                               ",姓名:" + MConvert <string> .ToTypeOrDefault(r.Cells[1].Value, "") +
                                               ",电话:" + phone +
                                               ",发送:" + sent_flag });
                    IOUtil.insert_file(MConvert <string> .ToTypeOrDefault(r.Cells[0].Value, "") + "   " +
                                       MConvert <string> .ToTypeOrDefault(r.Cells[1].Value, "") + "   " + phone + "   " + sent_flag, fileName);
                    i++;
                }

                IOUtil.insert_file("一共发送:" + phones.Count.ToString() + "条短信", fileName);
                this.Invoke(new delegate_msgForm_addMsg(msgForm_addMsg), new object[] { "发送结束,正在关闭短信猫!" });
                SmsClass.Sms_Disconnection();
                this.Invoke(new delegate_msgForm_addMsg(msgForm_addMsg), new object[] { "短信发送结束,短信猫关闭成功!" });
            }
            catch (System.Exception e)
            {
                BathClass.printErrorMsg(e.Message);
            }
        }