private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                //Open communication 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));

                if (this.port != null)
                {
                    this.gboPortSettings.Enabled = false;

                    //MessageBox.Show("Modem is connected at PORT " + this.cboPortName.Text);
                    this.statusBar1.Text = "Modem is connected at PORT " + this.cboPortName.Text;

                    //Add tab pages
                    this.tabSMSapplication.TabPages.Add(tbSendSMS);
                    this.tabSMSapplication.TabPages.Add(tbReadSMS);
                    this.tabSMSapplication.TabPages.Add(tbDeleteSMS);

                    this.lblConnectionStatus.Text = "Connected at " + this.cboPortName.Text;
                    this.btnDisconnect.Enabled    = true;
                }

                else
                {
                    //MessageBox.Show("Invalid port settings");
                    this.statusBar1.Text = "Invalid port settings";
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message);
            }
        }
示例#2
0
        private void timThietBi()
        {
            dgvDevice.Columns.Clear();

            DataTable dtDevice = new DataTable();

            // Tao cau truc datatable
            dtDevice.Columns.Add("Chọn", typeof(bool));
            dtDevice.Columns.Add("Cổng", typeof(string));
            dtDevice.Columns.Add("Mạng", typeof(string));
            dtDevice.Columns.Add("Độ trễ", typeof(int));
            dtDevice.Columns.Add("Giới hạn", typeof(int));

            foreach (COMPortInfo comPort in COMPortInfo.GetCOMPortsInfo())
            {
                if (comPort.Description.Contains("PC UI Interface"))
                {
                    string portName = comPort.Name;
                    //Open communication port
                    SerialPort sPort = objclsSMS.OpenPort(portName, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                    if (sPort != null)
                    {
                        string copSim = objclsSMS.readSimCode(sPort);
                        if ("\"45201\"".Equals(copSim))
                        {
                            SettingDevice setting = ReadXML(envPath + "\\" + "Mobifone" + ".xml");
                            if (setting != null)
                            {
                                dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString());
                            }
                            else
                            {
                                dtDevice.Rows.Add(false, portName, "Mobifone", "0", "0");
                            }
                        }
                        if ("\"45202\"".Equals(copSim))
                        {
                            SettingDevice setting = ReadXML(envPath + "\\" + "Vinaphone" + ".xml");
                            if (setting != null)
                            {
                                dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString());
                            }
                            else
                            {
                                dtDevice.Rows.Add(false, portName, "Vinaphone", "0", "0");
                            }
                        }
                        if ("\"45204\"".Equals(copSim))
                        {
                            SettingDevice setting = ReadXML(envPath + "\\" + "Viettel" + ".xml");
                            if (setting != null)
                            {
                                dtDevice.Rows.Add(false, portName, setting.Cops, setting.DelayTime.ToString(), setting.Limit.ToString());
                            }
                            else
                            {
                                dtDevice.Rows.Add(false, portName, "Viettel", "0", "0");
                            }
                        }
                    }

                    else
                    {
                        //MessageBox.Show("Invalid port settings");
                        this.statusBar1.Text = "Invalid port settings";
                    }
                    objclsSMS.ClosePort(sPort);
                }
                dgvDevice.DataSource = dtDevice;
                dgvDevice.Refresh();
            }

            DataGridViewButtonColumn btnSetup = new DataGridViewButtonColumn();

            dgvDevice.Columns.Add(btnSetup);
            btnSetup.Text = "Cài đặt";
            btnSetup.Name = "";
            btnSetup.UseColumnTextForButtonValue = true;
        }
示例#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);
            }
        }
示例#4
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                // Si on utilise 4 Sim
                if (this.checkBPort4.Checked)
                {
                    // On d�finit les 4 ports
                    this.port1 = objclsSMS.OpenPort(this.cboPortName4P1.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                    this.port2 = objclsSMS.OpenPort(this.cboPortName4P2.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                    this.port3 = objclsSMS.OpenPort(this.cboPortName4P3.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                    this.port4 = objclsSMS.OpenPort(this.cboPortName4P4.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));

                    if (this.port1 != null || this.port2 != null || this.port3 != null || this.port4 != null)
                    {
                        this.gboPortSettings.Enabled = false;

                        // Modem connect� aux 4 ports
                        this.statusBar1.Text = "Modem is connected at PORT " + this.cboPortName4P1.Text + " & " + this.cboPortName4P2.Text + " & " + this.cboPortName4P3.Text + " & " + this.cboPortName4P4.Text;

                        //Add tab pages
                        this.tabSMSapplication.TabPages.Add(tbSendSMS);
                        this.tabSMSapplication.TabPages.Add(tbReadSMS);
                        this.tabSMSapplication.TabPages.Add(tbDeleteSMS);
                        this.tabSMSapplication.TabPages.Add(tbRequestSMS);

                        this.lblConnectionStatus.Text = "Connected at " + this.cboPortName4P1.Text + " & " + this.cboPortName4P2.Text + " & " + this.cboPortName4P3.Text + " & " + this.cboPortName4P4.Text;

                        this.btnDisconnect.Enabled = true;
                    }
                    else
                    {
                        if (this.port1 == null)
                        {
                            MessageBox.Show("Port " + this.port1.PortName + " verrouill�.");
                        }

                        if (this.port2 == null)
                        {
                            MessageBox.Show("Port " + this.port2.PortName + " verrouill�.");
                        }

                        if (this.port3 == null)
                        {
                            MessageBox.Show("Port " + this.port3.PortName + " verrouill�.");
                        }

                        if (this.port4 == null)
                        {
                            MessageBox.Show("Port " + this.port4.PortName + " verrouill�.");
                        }

                        this.statusBar1.Text = "Invalid port settings";
                    }
                }
                // Si on utilise 2 Sim
                else if (this.checkBPort2.Checked)
                {
                    this.port1 = objclsSMS.OpenPort(this.cboPortName2P1.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));
                    this.port2 = objclsSMS.OpenPort(this.cboPortName2P2.Text, Convert.ToInt32(this.cboBaudRate.Text), Convert.ToInt32(this.cboDataBits.Text), Convert.ToInt32(this.txtReadTimeOut.Text), Convert.ToInt32(this.txtWriteTimeOut.Text));


                    if (this.port1 != null || this.port2 != null)
                    {
                        this.gboPortSettings.Enabled = false;

                        // Modem connect� aux 2 ports
                        this.statusBar1.Text = "Modem is connected at PORT " + this.cboPortName2P1.Text + " & " + this.cboPortName2P2.Text;

                        //Add tab pages
                        this.tabSMSapplication.TabPages.Add(tbSendSMS);
                        this.tabSMSapplication.TabPages.Add(tbReadSMS);
                        this.tabSMSapplication.TabPages.Add(tbDeleteSMS);
                        this.tabSMSapplication.TabPages.Add(tbRequestSMS);

                        this.lblConnectionStatus.Text = "Connected at " + this.cboPortName2P1.Text + " & " + this.cboPortName2P2.Text;

                        this.btnDisconnect.Enabled = true;
                    }

                    else
                    {
                        if (this.port1 == null)
                        {
                            MessageBox.Show("Port " + this.port1.PortName + " verrouill�.");
                        }

                        if (this.port2 == null)
                        {
                            MessageBox.Show("Port " + this.port2.PortName + " verrouill�.");
                        }

                        this.statusBar1.Text = "Invalid port settings";
                    }
                }
                else if (this.checkBPort1.Checked)
                {
                    // On d�finit le port
                    this.port1 = 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));

                    if (this.port1 != null)
                    {
                        this.gboPortSettings.Enabled = false;

                        //MessageBox.Show("Modem is connected at PORT " + this.cboPortName.Text);
                        this.statusBar1.Text = "Modem is connected at PORT " + this.cboPortName.Text;

                        //Add tab pages
                        this.tabSMSapplication.TabPages.Add(tbSendSMS);
                        this.tabSMSapplication.TabPages.Add(tbReadSMS);
                        this.tabSMSapplication.TabPages.Add(tbDeleteSMS);
                        this.tabSMSapplication.TabPages.Add(tbRequestSMS);

                        this.lblConnectionStatus.Text = "Connected at " + this.cboPortName.Text;

                        this.btnDisconnect.Enabled = true;
                    }
                    else
                    {
                        if (this.port1 == null)
                        {
                            MessageBox.Show("Port " + this.port1.PortName + " verrouill�.");
                        }

                        this.statusBar1.Text = "Invalid port settings";
                    }
                }
                else if (!this.checkBPort1.Checked && !this.checkBPort4.Checked && !this.checkBPort2.Checked)
                {
                    MessageBox.Show("How many Sim do you want to use ?");
                }
            }
            catch (Exception ex)
            {
                ErrorLog(ex.Message);
            }
        }