コード例 #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            if (validSMS)
            {
                String            sendTo   = String.Empty;
                String            sendName = String.Empty;
                String            status;
                bool              success  = false;
                int               entries  = 0;
                List <SMSMessage> messages = new List <SMSMessage>();

                if (!String.IsNullOrEmpty(txtMessage.Text) && txtMessage.Text.Length <= 160)
                {
                    var builder = new System.Text.StringBuilder();
                    builder.Append(sendTo);
                    var builder1 = new System.Text.StringBuilder();
                    builder1.Append(sendName);
                    foreach (SMSCustomer smsc in smsCustomers.customers)
                    {
                        if (smsc.include && !chkBillCustomer.Checked)
                        {
                            builder.Append(smsc.customerNumber + ";");
                            builder1.Append(smsc.customerName + ";");
                            entries++;
                        }
                        else if (smsc.include)
                        {
                            SMSMessage m = AddSMS(smsc.customerAccount, smsc.customerNumber);
                            messages.Add(m);
                        }
                    }
                    sendName = builder1.ToString();
                    sendTo   = builder.ToString();
                }
                else
                {
                    MessageBox.Show("Please enter a valid message", "SMS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtMessage.Focus();
                    return;
                }
                if (!String.IsNullOrEmpty(sendName) && !String.IsNullOrEmpty(sendTo))
                {
                    SMSMessage m   = AddSMS(sendName, sendTo);
                    String     msg = "";

                    if (!String.IsNullOrEmpty(m.message))
                    {
                        success = sms.SendBulkMessage(m, chkImmediate.Checked, out status);
                        if (success)
                        {
                            msg = "Message sent";
                            if (m.bulkbillable)
                            {
                                PostPastel(m.message, entries, out status);
                            }
                        }
                        else
                        {
                            msg = status;
                        }
                    }
                    else
                    {
                        msg = "Cannot send SMS";
                    }
                    MessageBox.Show(msg, "SMS", MessageBoxButtons.OK, (success ? MessageBoxIcon.Information : MessageBoxIcon.Error));
                }
                else
                {
                    int mCount = 0;
                    foreach (SMSMessage m in messages)
                    {
                        if (sms.SendMessage(m, chkImmediate.Checked, out status))
                        {
                            mCount++;
                        }
                    }
                    MessageBox.Show(mCount.ToString() + " SMS Sent", "SMS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (Prompt.ShowDialog("Password", "SMS") == "sheldonpwd")
                {
                    validSMS = true;
                    btnSend_Click(sender, e);
                }
            }
        }