Ejemplo n.º 1
0
 private void btnSendSMS_Click(object sender, EventArgs e)
 {
     //.............................................. Send SMS ....................................................
     try
     {
         if (objclsSMS.sendMsg(this.port, this.txtSIM.Text, this.txtMessage.Text))
         {
             //MessageBox.Show("Message has sent successfully");
             this.statusBar1.Text = "Message has sent successfully";
         }
         else
         {
             //MessageBox.Show("Failed to send message");
             this.statusBar1.Text = "Failed to send message";
         }
     }
     catch (Exception ex)
     {
         ErrorLog(ex.Message);
     }
 }
Ejemplo n.º 2
0
        public void NotificarClientes()
        {
            var table = new DataSet();

            /* string cnx = @"Server=192.158.237.98; Database=waveslab_mp_db; Uid=waveslab_web; Pwd=rDcS6GwEYKhnw8dt; persistsecurityinfo=True; Port=3306; SslMode=none;";*/

            /*   string cnx = @"Server=192.158.237.98; Database=waveslab_DB; Uid=waveslab_web; Pwd=rDcS6GwEYKhnw8dt; persistsecurityinfo=True; Port=3306; SslMode=none;";*/

            string cnx = @"Server=192.158.237.98; Database=masterzo_db; Uid=masterzon_sms; Pwd=rMD)AO4Kr9O0; persistsecurityinfo=True; Port=3306; SslMode=none;";

            btnSendSMS.Text      = "Detener";
            btnSendSMS.BackColor = Color.Coral;

            if (cnx.Substring(32, 11) == "waveslab_DB")
            {
                tbSendSMS.BackColor = Color.AntiqueWhite;
            }
            try
            {
                using (MySqlConnection conn = new MySqlConnection(cnx))
                {
                    string s = "SELECT num_destinatario,des_mensaje,cod_notificacion FROM sis_notificaciones_sms where cod_notificacion = (SELECT min(cod_notificacion) as cod_notificacion FROM sis_notificaciones_sms WHERE ind_prioridad = (select min(ind_prioridad) as ind_prioridad FROM sis_notificaciones_sms where cod_estado = 'P') and cod_estado = 'P')";

                    using (conn)
                        using (MySqlCommand mcd2 = new MySqlCommand(s, conn))
                        {
                            conn.Open();
                            using (MySqlDataReader mdr = mcd2.ExecuteReader())
                            {
                                DataTable dt = new DataTable("Tabla_Pendientes");
                                dt.Load(mdr);
                                table.Tables.Add(dt);

                                DateTime hora = DateTime.Now;
                                txtFecHoraInicio.Text    = hora.ToString("yyyy/MM/dd_HH:mm:ss");
                                this.textIntervalos.Text = "120";
                                foreach (DataRow fila in dt.Rows)
                                {
                                    this.textIntervalos.Text = "20";

                                    string num_destino = fila["num_destinatario"].ToString();
                                    string txt_mensaje = fila["des_mensaje"].ToString();
                                    string codigo      = fila["cod_notificacion"].ToString();

                                    /*----------------------------------------------*/
                                    string          sql_update = string.Concat("UPDATE sis_notificaciones_sms SET cod_estado = 'E', fec_hora_envio = now() WHERE cod_notificacion = ", codigo);
                                    MySqlCommand    mcd3       = new MySqlCommand(sql_update, conn);
                                    MySqlDataReader mdrUpdate  = mcd3.ExecuteReader();

                                    if (objclsSMS.sendMsg(this.port, num_destino, txt_mensaje))
                                    {
                                        /*  string sql_update = string.Concat("UPDATE sis_notificaciones_sms SET cod_estado = 'E', fec_hora_envio = now() WHERE cod_notificacion = ", codigo );
                                         * MySqlCommand mcd3 = new MySqlCommand(sql_update, conn);
                                         * MySqlDataReader mdrUpdate = mcd3.ExecuteReader();
                                         */

                                        //MessageBox.Show("Message has sent successfully");
                                        this.statusBar1.Text = string.Concat("Enviado correctamente al numero: ", num_destino);
                                        this.txtMessage.Text = string.Concat(txtFecHoraInicio.Text, " Mensaje enviado correctamente al numero: ", num_destino) + Environment.NewLine + this.txtMessage.Text;
                                    }
                                    else
                                    {
                                        //MessageBox.Show("Failed to send message");
                                        this.statusBar1.Text = string.Concat("ERROR en envio de SMS al numero: ", num_destino);
                                        this.txtMessage.Text = string.Concat("ERROR en envio de SMS al numero: ", num_destino) + Environment.NewLine + this.txtMessage.Text;

                                        string sql_bitacora = string.Concat("INSERT INTO sis_bitacora_eventos(`fec_hora_evento`, `cod_usuario`, `des_archivo`, `des_proceso`, `des_query`, `des_definicion`) VALUES(DATE_ADD(now(), INTERVAL 2 HOUR), 'Mensajero', 'SMSapplication', 'NotificarClientes()',", s, ", 'ERROR en envio de SMS')");

                                        MySqlCommand    mcd_bitacora = new MySqlCommand(sql_bitacora, conn);
                                        MySqlDataReader mdrBitacora  = mcd_bitacora.ExecuteReader();
                                    }
                                }
                            }
                        }
                }
            }

            catch (Exception ex)
            {
                this.txtMessage.Text = this.txtMessage.Text + Environment.NewLine + ex.Message + txtFecHoraInicio.Text;
                ErrorLog(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void bgwSendSMS_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                SetText("Connection Status");

                //.............................................. Send SMS ....................................................
                try
                {
                    SetText("Sending sms to cc #: " + strMobileNo);

                    if (strMessage == "rbstest")
                    {
                        ListViewItem item = new ListViewItem(new string[] { iCtr.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), strMobileNo, "OK" });
                        SetSentMessage(item);
                        SetText("[" + iCtr.ToString() + "/" + iCount.ToString() + "]: msg sent to " + strMobileNo);
                    }
                    else
                    {
                        try
                        {
                            try
                            { objclsSMS.ClosePort(this.port); }
                            catch { }
                            Thread.Sleep(60);
                            try
                            {
                                ErrorLog(this.cboPortName.Text + " : opening port");
                                this.port = objclsSMS.OpenPort(this.cboPortName.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                                ErrorLog(this.cboPortName.Text + " : port is open");
                            }
                            catch {}
                            try
                            {
                                if (objclsSMS.sendMsg(this.port, strMobileNo, strMessage))
                                {
                                    ErrorLog("Message has sent successfully");
                                    ErrorLog("[0/0]: msg sent to " + strMobileNo);

                                    ListViewItem item = new ListViewItem(new string[] { iCtr.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), strMobileNo, "sent: Read" });
                                    SetSentMessage(item);
                                    SetText("[" + iCtr.ToString() + "/" + iCount.ToString() + "]: msg sent to " + strMobileNo);
                                    iCtrRead++;
                                }
                                else
                                {
                                    //MessageBox.Show("Failed to send message");
                                    SetText("Failed to send message");
                                    SetText("[0/0]: msg failed sent to " + strMobileNo);

                                    ErrorLog("Failed to send message");
                                    ErrorLog("[0/0]: msg failed sent to " + strMobileNo);

                                    ListViewItem item = new ListViewItem(new string[] { iCtr.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), strMobileNo, "sent: NotRead" });
                                    SetSentMessage(item);
                                    SetText("[" + iCtr.ToString() + "/" + iCount.ToString() + "]: msg sent no reply from SMSC to " + strMobileNo);
                                    iCtrNotRead++;
                                }
                            }
                            catch (Exception ex)
                            {
                                ListViewItem item = new ListViewItem(new string[] { iCtr.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), strMobileNo, "sent: PhoneNoResp" });
                                SetSentMessage(item);
                                SetText("[" + iCtr.ToString() + "/" + iCount.ToString() + "]: msg sent no reply from SMSC to " + strMobileNo);

                                ErrorLog("[" + iCtr.ToString() + "/" + iCount.ToString() + "]:error msg..." + ex.Message);
                                iCtrClosedPhone++;
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog("error opening..." + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog(ex.Message);
                    return;
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message);
            }
        }
Ejemplo n.º 4
0
        void guiTinNhan(string cong, string mang, int doTre, int gioiHanTin, bool phanBietMang)
        {
            SerialPort portMoi = objclsSMS.OpenPort(cong, Convert.ToInt32(cboBaudRate.Text), Convert.ToInt32(cboDataBits.Text), Convert.ToInt32(txtReadTimeOut.Text), Convert.ToInt32(txtWriteTimeOut.Text));

            if (portMoi != null)
            {
                // Neu nhu check box phan biet mang khi gui duoc chon
                if (phanBietMang)
                {
                    for (int i = 0; i < dgvPhoneList.Rows.Count; i++)
                    {
                        try
                        {
                            // Lay dau so gom 3 chu so tu so dien thoai de kiem tra la mang gi
                            string dauSo3So = dgvPhoneList.Rows[i].Cells[1].Value.ToString().Substring(0, 3);

                            // Lay dau so gom  chu so tu so dien thoai de kiem tra la mang gi
                            string dauSo4So = dgvPhoneList.Rows[i].Cells[1].Value.ToString().Substring(0, 4);

                            if (cbThietBiCungMang.Checked)
                            {
                                // Neu dau so cua so dien thoai trung voi mang thi ta gui
                                if (mang.Equals(PhoneNumberUtil.getTenNhaMang(dauSo3So)) || mang.Equals(PhoneNumberUtil.getTenNhaMang(dauSo4So)))
                                {
                                    // Kiem tra checkbox xem so co duoc gui hay khong
                                    // Va kiem tra tinh trang xem da duoc gui hay chua
                                    if (Convert.ToBoolean(dgvPhoneList.Rows[i].Cells[0].Value) && ("".Equals(dgvPhoneList.Rows[i].Cells[6].Value.ToString()) || "Gửi thành công".Equals(dgvPhoneList.Rows[i].Cells[6].Value.ToString())))
                                    {
                                        String textThayDoi = this.txtMessage.Text.Replace(SMSConstants.AddMessage_ThongTin1, dgvPhoneList.Rows[i].Cells[3].Value.ToString());
                                        textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_ThongTin2, dgvPhoneList.Rows[i].Cells[4].Value.ToString());
                                        textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_ThongTin3, dgvPhoneList.Rows[i].Cells[5].Value.ToString());
                                        textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_HoTen, dgvPhoneList.Rows[i].Cells[2].Value.ToString());
                                        textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_SoDienThoai, dgvPhoneList.Rows[i].Cells[1].Value.ToString());

                                        if (objclsSMS.sendMsg(portMoi, dgvPhoneList.Rows[i].Cells[1].Value.ToString(), textThayDoi))
                                        {
                                            dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thành công";
                                        }
                                        else
                                        {
                                            dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thất bại";
                                        }
                                    }
                                }
                            }
                            else
                            {
                                // Kiem tra checkbox xem so co duoc gui hay khong
                                // Va kiem tra tinh trang xem da duoc gui hay chua
                                if (Convert.ToBoolean(dgvPhoneList.Rows[i].Cells[0].Value) && "".Equals(dgvPhoneList.Rows[i].Cells[6].Value.ToString()) || "Gửi thành công".Equals(dgvPhoneList.Rows[i].Cells[6].Value.ToString()))
                                {
                                    String textThayDoi = this.txtMessage.Text.Replace(SMSConstants.AddMessage_ThongTin1, dgvPhoneList.Rows[i].Cells[3].Value.ToString());
                                    textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_ThongTin2, dgvPhoneList.Rows[i].Cells[4].Value.ToString());
                                    textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_ThongTin3, dgvPhoneList.Rows[i].Cells[5].Value.ToString());
                                    textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_HoTen, dgvPhoneList.Rows[i].Cells[2].Value.ToString());
                                    textThayDoi = textThayDoi.Replace(SMSConstants.AddMessage_SoDienThoai, dgvPhoneList.Rows[i].Cells[1].Value.ToString());


                                    if (objclsSMS.sendMsg(portMoi, dgvPhoneList.Rows[i].Cells[1].Value.ToString(), textThayDoi))
                                    {
                                        dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thành công";
                                    }
                                    else
                                    {
                                        dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thất bại";
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            // Truong hop gui loi tinh trang se la gui that bai
                            dgvPhoneList.Rows[i].Cells[6].Value = "";

                            // Ghi log neu nhu exception xay ra
                            ErrorLog(ex.Message);
                        }
                        dgvPhoneList.Refresh();
                        Thread.Sleep(doTre * 1000);
                    }
                }
                else //Neu nhu checkbox gui phan biet mang khong duoc chon
                {
                    for (int i = 0; i < dgvPhoneList.Rows.Count; i++)
                    {
                        try
                        {
                            // Ta gui ma khong can phan biet mang
                            // Chi kiem tra xem so co duoc chon de gui hay khong
                            // Hay tinh trang la chua duoc gui
                            if (Convert.ToBoolean(dgvPhoneList.Rows[i].Cells[0].Value) && "".Equals(dgvPhoneList.Rows[i].Cells[6].Value.ToString()))
                            {
                                if (objclsSMS.sendMsg(this.port, dgvPhoneList.Rows[i].Cells[1].Value.ToString(), this.txtMessage.Text))
                                {
                                    dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thành công";
                                }
                                else
                                {
                                    dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thất bại";
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            // Truong hop gui loi tinh trang se la gui that bai
                            dgvPhoneList.Rows[i].Cells[6].Value = "Gửi thất bại";

                            // Ghi log neu nhu exception xay ra
                            ErrorLog(ex.Message);
                        }
                        dgvPhoneList.Refresh();
                        Thread.Sleep(doTre * 1000);
                    }
                }
            }
            portMoi.Close();
        }