Example #1
0
 public static AEISmsAlert getInstance(string modem, int bauds) //string modem,int baudrate)
 {
     Modem    = modem;
     BaudRate = bauds;
     if (Inst == null)
     {
         Inst = new AEISmsAlert();
         STS  = Inst.Open();
     }
     return(Inst);
 }
Example #2
0
        public void Config(param p_inst)
        {
            inst   = p_inst;
            custid = inst.cust_id;
            //conn = inst.conn;   // db connection
            //selectedDate = inst.dt;
            org     = inst.org;
            indx    = inst.indx;
            PollChk = inst.PollChk;
            if (PollChk)
            {
                rbPoll.Checked  = true;
                rbTimer.Checked = false;
            }
            else
            {
                rbPoll.Checked  = false;
                rbTimer.Checked = true;
            }
            tc = inst.tc;   // used to select next index


            String dbconn = ConfigurationManager.AppSettings["ConnectionString"];

            conn = new SqlConnection(dbconn);
            try
            {
                // conn.Open();
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                UpdateOrgListBox();  // populate ListBoxOrg
                lblPollSeconds.Text = Convert.ToString(ConfigurationManager.AppSettings["GenPollTime"]) + " Seconds";
                // Modem Set up
                BaudRate = Convert.ToInt16(ConfigurationManager.AppSettings["GPRSBaudRate"]);
                string modem = ConfigurationManager.AppSettings["GPRSPollModem"];
                try
                {
                    pollmodem = AEISmsAlert.getInstance(modem, BaudRate); //(modem, BaudRate);
                    //EventHandler PhoneConnected += new EventHandler(comm_phoneconnected);
                    //EventHandler PhoneDisconnected += new EventHandler(comm_phoneDisconnected);

                    if (pollmodem.OK)
                    {
                        btnGsmModule.Text      = "ON";
                        btnGsmModule.BackColor = Color.Green;
                        try
                        {
                            btnNetworkStatus.Text      = pollmodem.GetOPerator();
                            btnNetworkStatus.BackColor = Color.Green;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Operator not found: " + ex.Message);
                        }
                    }



                    // com = Convert.ToString(ConfigurationManager.AppSettings["PollMODEM"]);
                    String     SqlConfig = "SELECT * FROM ConfigSystem";
                    SqlCommand cmd       = new SqlCommand(SqlConfig, conn);

                    try
                    {
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        using (SqlDataReader rd = cmd.ExecuteReader())
                        {
                            while (rd.Read())
                            {
                                // ComRxModem = Convert.ToString(rd[0]);
                                // ComPollModem = Convert.ToString(rd[1]).Trim();
                                PollTimer  = Convert.ToInt32(rd[2]);
                                Configured = Convert.ToBoolean(rd[3]);
                                // DateTime  = Convert.ToString(rd[4]);
                            }
                            rd.Close();
                        }
                        if (Configured)
                        {
                            // com = ComPollModem;   // assign com from db
                            lblPollSeconds.Text = PollTimer + " Secs";
                        }
                    }
                    catch (Exception ex)
                    {
                        //ModemSts = false;
                        // EventLog.WriteEntry("AeiGenAlert: Comm  is Closed");
                    }


                    // reanable timer
                    if (Configured)
                    {
                        timer1.Interval = PollTimer * 1000;
                    }
                    else
                    {
                        timer1.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["GenPollTime"]) * 1000;
                    }
                    timer1.Enabled = true;
                    timer1.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(" PollGens - Initz error: " + ex.Message);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }