private String dialogOpenServer()
 {
     try
     {
         if (dialogServerSearchPort() != "")
         {
             const String   KEY = "79B8242B-22A1-4AE8-B52B-D6A298B17AE2";
             SqlConfigClass sqlMessageServerDataTable = new SqlConfigClass();
             DataTable      dt = sqlMessageServerDataTable.dialogServerSendMessagePublic("EXECUTE _sp_DIALOG_SMS_SERVER_OPEN @KEY = '" + KEY + "'");
             DataRow        dr = dt.Rows[0];
             if (dr["SUCCES"].ToString() == "1")
             {
                 _dialogServerSerialPort.Write("AT+CMGF=1\r");
                 System.Threading.Thread.Sleep(500);
                 _dialogServerSerialPort.Write("AT+CMGS=\"+" + dr["AdminNumber"].ToString() + "\"\r");
                 System.Threading.Thread.Sleep(1000);
                 _dialogServerSerialPort.Write("Server is started at " + DateTime.Now.ToString("h:mm:ss tt") + " on " + DateTime.Today.ToString("D") + "\r\rDialog Access Network Planning, \rWestern North Region." + (char)(26));
                 System.Threading.Thread.Sleep(1000);
                 _dialogServerSerialPort.Close();
             }
             return(_truePortName);
         }
     }
     catch (SqlException)
     {
         _dialogServerSerialPort.Close();
         MessageBox.Show("The Sql Server can't be opened. Check the internet connection and try again.", "Sql Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return("");
     }
     catch (Exception)
     {
         _dialogServerSerialPort.Close();
         MessageBox.Show("The message server serial port can't be opened. Check the com port and try again.", "Port Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return("");
     }
     _dialogServerSerialPort.Close();
     MessageBox.Show("The message server serial port can't be opened. Check the com port and try again.", "Port Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     return("");
 }
 private Boolean dialogOpenServer()
 {
     if (dialogServerSearchPort())
     {
         InitializePort();
         _dialogMessageServerSerialPort.PortName = _truePortName;
         _dialogMessageServerSerialPort.Open();
         if (_dialogMessageServerSerialPort.IsOpen)
         {
             try
             {
                 const String   KEY = "C8D918DB-296E-4105-A652-87A0B4BA3A65";
                 SqlConfigClass sqlMessageServerDataTable = new SqlConfigClass();
                 DataTable      dt = sqlMessageServerDataTable.dialogServerSendMessagePublic("EXECUTE _sp_DIALOG_SMS_SERVER_OPEN @KEY = '" + KEY + "'");
                 DataRow        dr = dt.Rows[0];
                 if (dr["SUCCES"].ToString() == "1")
                 {
                     _dialogMessageServerSerialPort.Write("AT+CMGF=1\r");
                     System.Threading.Thread.Sleep(300);
                     _dialogMessageServerSerialPort.Write("AT+CMGS=\"+" + dr["AdminNumber"].ToString() + "\"\r");
                     System.Threading.Thread.Sleep(500);
                     _dialogMessageServerSerialPort.Write("Server is started at " + DateTime.Now.ToString("h:mm:ss tt") + " on " + DateTime.Today.ToString("D") + "\r\rDialog Access Network Planning, \rWestern North Region." + (char)(26));
                     System.Threading.Thread.Sleep(1000);
                     _dialogMessageServerSerialPort.Write("AT+CMGF=1\r");
                     System.Threading.Thread.Sleep(150);
                     _dialogMessageServerSerialPort.Write("AT+CMGD=?\r");
                     System.Threading.Thread.Sleep(1000);
                     _dialogMessageServerSerialPort.Close();
                     return(true);
                 }
                 else if (dr["SUCCES"].ToString() == "0" || dr["ERROR"].ToString() == "1")
                 {
                     _dialogMessageServerSerialPort.Close();
                     _IsTruePortOK = false;
                     _PortMessage  = "401:\r\r" + dr["MESSAGE"].ToString();
                     return(false);
                 }
                 else
                 {
                     _dialogMessageServerSerialPort.Close();
                     _IsTruePortOK = false;
                     _PortMessage  = "402:\r\r" + "The Sql Server can't be opened. Check the internet connection and try again.";
                     return(false);
                 }
             }
             catch (Exception)
             {
                 _dialogMessageServerSerialPort.Close();
                 _IsTruePortOK = false;
                 _PortMessage  = "403:\r\r" + "The message server serial port can't be opened. Check the com port and try again. The GSM SIM 800A COM Port Warning.!";
                 return(false);
             }
         }
         else
         {
             _dialogMessageServerSerialPort.Close();
             _IsTruePortOK = false;
             _PortMessage  = "404:\r\r" + "The message server serial port can't be opened. Check the com port and try again. The GSM SIM 800A COM Port Warning.!";
             return(false);
         }
     }
     else
     {
         _dialogMessageServerSerialPort.Close();
         _IsTruePortOK = false;
         _PortMessage  = "405:\r\r" + "The message server serial port can't be opened. Check the com port and try again. The GSM SIM 800A COM Port Warning.!";
         return(false);
     }
 }