public MTSCommunicatorM2MXMLAPI GetSoapService() { int port = -1; MTSCommunicatorM2MXMLAPI client = null; client = new MTSCommunicatorM2MXMLAPI(); if (chbUseProxy.Checked && int.TryParse(txtProxyPort.Text, out port)) { client.Proxy = new WebProxy(txtProxyServer.Text, port); } return(client); }
public void GetBalance(string login, string password) { try { label3.Text = "Баланс: "; //Прокси для вызова методов сервиса MTSCommunicatorM2MXMLAPI client = GetSoapService(); //Получить статус доставки для сообщения label3.Text = string.Format("Баланс: " + client.GetBalance(login, password) + " на " + DateTime.Now.ToString("HH:mm:ss dd.MM.yy")); } catch (Exception ex) { MessageBox.Show(string.Format(ex.Message)); } }
private void btnSend_Click(object sender, EventArgs e) { stopwatch.Start(); labTime.Text = "Время отправки СМС:"; labSend.Text = "Отправлено:"; myConnection.Open(); myCommand.Connection = myConnection; list.Clear(); int count_sms = 0; string idSMS; try { myCommand.CommandText = string.Format("select distinct plan.licscht,plan.phone,plan.sms,plan.id from plan " + "where delivery = 0 " + "and sms_id = 0 " + "and length(phone) = 11 " + "and date_format(sendDate, '%Y-%m') = date_format(now(), '%Y-%m') " + "and plan.licscht not in (select ls from tmp_ignore) " + "order by plan.msg_type, licscht; "); myCommand.Prepare();//подготавливает строку MyDataReader = myCommand.ExecuteReader(); while (MyDataReader.Read()) { list.Add(MyDataReader.GetString(0)); list.Add(MyDataReader.GetString(1)); list.Add(MyDataReader.GetString(2)); list.Add(MyDataReader.GetString(3)); } MyDataReader.Close(); //Прокси для вызова методов сервиса MTSCommunicatorM2MXMLAPI client = GetSoapService(); for (int i = 0; i <= list.Count - 4; i += 4) { idSMS = client.SendMessage(list[i + 1], list[i + 2], "Vodokanal", txtLogin.Text, GetMd5Hash(txtPassword.Text)); if (IsDigitsOnly(idSMS)) { //Сформировать запрос sCommand.Append(string.Format("update plan set sms_id=" + idSMS + " where licscht='{0}' and phone='{1}' and id='{2}' and date_format(sendDate,'%Y-%m')=date_format(now(),'%Y-%m') and sms_id=0; ", list[i + 0], list[i + 1], list[i + 3])); //сравниваю по тексту... вдруг на один номер несколько смс и я могу присвоить айди не той СМСки. //это была глупая идея... лучше сравнивать по внутр айди смс count_sms++; } else { //errorString.Append(string.Format(idSMS + "\n")); } } //Подготавливаем и выполняем myCommand.CommandText = sCommand.ToString(); myCommand.Prepare(); myCommand.ExecuteNonQuery(); } catch (Exception ex) { labSend.Text = Convert.ToString(string.Format("Отправлено: {0}", count_sms)); MessageBox.Show(string.Format(ex.Message)); if (sCommand.ToString() != "") { //Подготавливаем и выполняем myCommand.CommandText = sCommand.ToString(); myCommand.Prepare(); myCommand.ExecuteNonQuery(); } } stopwatch.Stop(); myConnection.Close(); sCommand.Clear(); labTime.Text = string.Format("Время отправки СМС: " + stopwatch.Elapsed); labSend.Text = Convert.ToString(string.Format("Отправлено: {0}", count_sms)); stopwatch.Reset(); // if (!String.IsNullOrEmpty(errorString.ToString())) // { // Error error = new Error(errorString.ToString()); // error.Show(); // } }
public string GetList(string txtLogin, string txtPassword) { sCommand.Clear(); int countStatus0 = 0; int countStatus1 = 0; int countStatus2 = 0; int status = 0; list.Clear(); try { mainForm main = new mainForm(); myConnection.Open(); myCommand.Connection = myConnection; myCommand.CommandText = string.Format(@"select plan.sms_id from plan where delivery = 0 and sms_id <> 0 and length(phone) = 11 and (date_format(sendDate, '%Y-%m') = date_format(now(), '%Y-%m') or date_format(sendDate, '%Y-%m') = date_format(now() - INTERVAL 1 MONTH, '%Y-%m')); " ); myCommand.Prepare();//подготавливает строку MyDataReader = myCommand.ExecuteReader(); //Прокси для вызова методов сервиса MTSCommunicatorM2MXMLAPI client = main.GetSoapService(); while (MyDataReader.Read()) { list.Add(MyDataReader.GetString(0)); } MyDataReader.Close(); for (int i = 0; i < list.Count; i++) { //Получить статус доставки для сообщения DeliveryInfo[] info = client.GetMessageStatus(Convert.ToInt64(list[i]), txtLogin, txtPassword); switch (info[0].DeliveryStatus.ToString()) { case "Pending": case "Sending": case "Sent": case "NotSent": status = 0; countStatus0++; break; case "Delivered": status = 1; countStatus1++; break; case "NotDelivered": case "TimedOut": case "Error": status = 2; countStatus2++; break; default: break; } sCommand.Append(string.Format("update plan set delivery='{0}', delivery_type='{1}', reciveDate='{2}' where sms_id={3}; ", status, info[0].DeliveryStatus, info[0].DeliveryDate.ToString("yyyy-MM-dd HH:mm:ss"), list[i])); if ((countStatus0 + countStatus1 + countStatus2) % 1000 == 0) { myCommand.CommandText = sCommand.ToString(); myCommand.Prepare(); myCommand.ExecuteNonQuery(); sCommand.Clear(); } } //Подготавливаем и выполняем myCommand.CommandText = sCommand.ToString(); myCommand.Prepare(); myCommand.ExecuteNonQuery(); myConnection.Close(); sCommand.Clear(); return(string.Format("Доставлено:\n" + "В ожид.: {0}\n" + "Получ.: {1}\n" + "Ошибка: {2}\n" + "Всего: {3}\n", countStatus0, countStatus1, countStatus2, (countStatus0 + countStatus1 + countStatus2))); } catch (Exception ex) { MessageBox.Show(string.Format(ex.Message)); myConnection.Close(); return(string.Format("Доставлено:\n" + "В ожид.: {0}\n" + "Получ.: {1}\n" + "Ошибка: {2}\n" + "Всего: {3}\n", countStatus0, countStatus1, countStatus2, (countStatus0 + countStatus1 + countStatus2))); } }