Пример #1
0
 public StatusForm(param p_inst) //String gen_id, int cust_id)
 {
     InitializeComponent();
     for (int x = 0; x < 22; x++)
     {
         DummyList.Add(15);
     }
     Config(p_inst);
 }
 public Admin(param p_inst)
 {
     InitializeComponent();
     inst = p_inst;
     conn = inst.conn;   // db connection
     panel1.Hide();
     Sqldbstr = ConfigurationManager.AppSettings["connectionString"];
     conn     = new SqlConnection(Sqldbstr);
     btnSaveCustomer.Enabled = false;
     btnSaveLocation.Enabled = false;
 }
        public meter(param p_inst)
        {
            InitializeComponent();
            inst   = p_inst;
            genid  = inst.gen_id;
            custid = inst.cust_id;
            conn   = inst.conn;     // db connection
            indx   = inst.indx;
            tc     = inst.tc;       // used to select next index
            //Config(p_inst);
            timer1.Interval = 5000; //timer interval 5 secs
            timer1.Start();
            timer1.Tick += new EventHandler(TimerEventProcessor);
            String SqlGens = String.Format(@"SELECT Gen_id FROM Generators WHERE Cust_id ={0}", custid);
            String dbconn  = ConfigurationManager.AppSettings["ConnectionString"];

            conn = new SqlConnection(dbconn);
            SqlDataReader drg = null;

            #region initialization
            try
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }

                using (SqlCommand cmdg = new SqlCommand(SqlGens, conn))
                {
                    //cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    gen_id.Items.Clear();
                    while (drg.Read())
                    {
                        genid = drg.GetString(0).Trim();
                        GeneratorList.Add(genid);
                        gen_id.Items.Add(genid);
                    }

                    drg.Close();

                    indx = GeneratorList.IndexOf(genid.Trim());
                    gen_id.SelectedIndex = indx; // comboBox1.Items.IndexOf(genid.Trim());
                    gen_id.Show();
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.ToString());
            }
            #endregion
        }
Пример #4
0
        public ConfigForm(param p_inst)
        {
            InitializeComponent();
            inst = p_inst;

            foreach (String prt in SerialPort.GetPortNames())
            {
                comboBoxRxModem.Items.Add(prt);
                comboBoxPollModem.Items.Add(prt);
            }
            comboBoxRxModem.SelectedIndex   = 0;
            comboBoxPollModem.SelectedIndex = 0;

            for (int t = 1; t < 10; t++)
            {
                int i = 20;
                comboBoxPollTimer.Items.Add(i * t + " Secs");
            }
            comboBoxPollTimer.SelectedIndex = 0;
        }
        public void Config(param p_inst)
        {
            inst    = p_inst;
            conn    = inst.conn;                                    // db connection
            gen_id  = inst.gen_id;
            rx_date = dateTimePicker1.Value.ToString("dd/MM/yyyy"); //inst.dt;
            org     = inst.org;
            tc      = inst.tc;

            lblHistoricalData.Text = org + " Historical Data.  Generator: " + gen_id + ",  Date: " + rx_date;
            ClearButtons();
            btnGenData.BackColor = Color.Green;
            DataTable dt = new DataTable();

            dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
            String SQLGenData = String.Format(@"SELECT * FROM Data WHERE Gen_Id='{0}' AND Date='{1}' ORDER BY Time ASC", gen_id, rx_date);

            Sqldbstr = ConfigurationManager.AppSettings["connectionString"];
            conn     = new SqlConnection(Sqldbstr);
            try
            {
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                SqlCommand cmd = new SqlCommand(SQLGenData, conn);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    da.Fill(dt);
                    bindingSource.DataSource = dt;
                    dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
                    dataGridView1.DataSource = bindingSource;
                    dataGridView1.Enabled    = true;
                    dataGridView1.Show();
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void Config(param p_inst)
        {
            inst   = p_inst;
            conn   = inst.conn; // db connection
            genid  = inst.gen_id;
            custid = inst.cust_id;
            //tc = inst.tc;             // for backbutton
            // Update combo box
            String SqlGens = String.Format(@"SELECT Gen_id,Location FROM Generators WHERE Cust_id ={0}", custid);
            String SqlOrg  = String.Format(@"SELECT c.Organization,g.Location FROM Customers c,Generators g WHERE c.Cust_id = g.Cust_id AND c.Cust_Id= {0} AND g.Gen_id ='{1}'", custid, genid);

            // String dbconn = ConfigurationManager.AppSettings["ConnectionString"];
            SqlDataReader drg = null;

            //conn = new SqlConnection(dbconn);
            try
            {
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlCommand cmdg = new SqlCommand(SqlOrg, conn))
                {
                    cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    org = "";
                    String loc = "";
                    while (drg.Read())
                    {
                        org = drg.GetString(0);
                        loc = drg.GetString(1);
                    }
                    lblLocation.Text     = "Location: " + loc;
                    lblOrganization.Text = "Organization: " + org;
                    //blGenerator.Text = "Genertor No: " + genid;
                    //blDateTime.Text = DateTime.Now.ToString("G", new CultureInfo("en-GB"));
                }
                drg.Close();

                using (SqlCommand cmdg = new SqlCommand(SqlGens, conn))
                {
                    cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    CustGenList.Clear();
                    comboBox1.Items.Clear();
                    CustLocList.Clear();
                    while (drg.Read())
                    {
                        CustGenList.Add(drg.GetString(0).Trim());
                        comboBox1.Items.Add(drg.GetString(0).Trim());
                        CustLocList.Add(drg.GetString(1));
                    }

                    int indx = CustGenList.IndexOf(genid.Trim());
                    comboBox1.SelectedIndex = indx; // comboBox1.Items.IndexOf(genid.Trim());
                    comboBox1.Show();
                }
            }
            catch (Exception ex)
            {
                if (!drg.IsClosed)
                {
                    drg.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            finally
            {
                if (!drg.IsClosed)
                {
                    drg.Close();
                }
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
 public ReportsForm(param p_inst)
 {
     InitializeComponent();
     Config(p_inst);
 }
        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;
            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();
                }
                SqlCommand cmd2 = new SqlCommand(SqlPCustAll, conn);
                using (SqlDataReader reader = cmd2.ExecuteReader())
                {
                    c_cuidList.Clear();
                    c_pollList.Clear();
                    // OrgList.Clear();
                    while (reader.Read())
                    {
                        c_cuidList.Add(Convert.ToInt32(reader[0])); // p cust id
                        this.listBoxOrgs.Items.Add(Convert.ToString(reader[1]));
                        c_pollList.Add(Convert.ToBoolean(reader[2]));
                    }
                    reader.Close();
                }
                if (c_cuidList.Count > 0)
                {
                    listBoxOrgs.SelectedIndex = 0;
                    // gen event
                    object    sender = new object();
                    EventArgs e      = new EventArgs();
                    this.listBoxOrgs_SelectedIndexChanged(sender, e);
                }
                lblPollSeconds.Text = Convert.ToString(ConfigurationManager.AppSettings["GenPollTime"]) + " Seconds";;
                // Modem Set up
                BaudRate = Convert.ToInt16(ConfigurationManager.AppSettings["GPRSBaudRate"]);
                try
                {
                    //com = "COM10";
                    com = Convert.ToString(ConfigurationManager.AppSettings["PollMODEM"]);
                    if (com != null)
                    {
                        //gprs = new GsmCommMain(port, BaudRate, 1000);              //
                        gprsPoll = new UsbPollModem();
                        // gprsPoll.smsEvent += new SmsMessageIndication(gprs_smsEvent);
                        // gprsPoll.MsgRxdEnableInterrupt(this.usbPollport);
                        try
                        {
                            this.usbPollport = gprsPoll.OpenPort(com, BaudRate, 8, 300, 300);
                            if (gprsPoll != null) //if (ModemSts)
                            {
                                // Attach SMS message event handler
                                // gprsPoll.smsEvent +=new SmsMessageIndication(gprs_smsEvent);
                                gprsPoll.ModemStatus = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            // ModemSts = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ModemSts = false;
                    // EventLog.WriteEntry("AeiGenAlert: Comm  is Closed");
                }

                this.usbPollport.DataReceived += new SerialDataReceivedEventHandler(gprs_dataReceived);
                // Attach SMS message event handler
                // gprs.smsEvent +=new SmsMessageIndication(gprs_smsEvent);
                gprsPoll.MsgRxdEnableInterrupt(this.usbPollport);
                //; ;............ end Modem .....
                timer1.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["GenPollTime"]) * 1000;
                timer1.Enabled  = true;
                timer1.Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(" PollGens - Initz error: " + ex.Message);
            }
        }  // End of init/config
 public PollGens(param p_inst) //int id, DateTime dt, String org, int indx = 0)
 {
     InitializeComponent();
     Config(p_inst);
 }
        public Form1(param p_inst) //(int id,DateTime dt,String orgz,int index=0)
        {
            InitializeComponent();
            inst   = p_inst;
            custid = inst.cust_id;
            conn   = inst.conn; // db connection
            //selectedDate = inst.dt;
            org     = inst.org;
            indx    = inst.indx;
            tc      = inst.tc; // used to select next index
            QueryOK = inst.QueryOk;
            if (QueryOK)
            {
                btQuery.BackColor = Color.Green;
            }
            else
            {
                btQuery.BackColor = Color.Red;
            }


            String SqlGenId = String.Format(@"Select Gen_Id,Location From Generators Where Cust_Id='{0}'", custid);
            String dbconn   = ConfigurationManager.AppSettings["ConnectionString"];

            conn = new SqlConnection(dbconn);

            #region initz
            SqlDataReader drg = null;
            try
            {
                // conn.Open();
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlCommand cmdg = new SqlCommand(SqlGenId, conn))
                {
                    //cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    listGenerators.Clear();
                    listLocation.Clear();
                    while (drg.Read())
                    {
                        String genid = drg.GetString(0).Trim();
                        comboBox1.Items.Add(genid);
                        listGenerators.Add(genid);
                        listLocation.Add(drg.GetString(1));
                    }
                    drg.Close();
                    if (comboBox1.Items.Count > 1)
                    {
                        comboBox1.Items.Add("All");
                        listLocation.Add(org + " [All]");
                    }

                    comboBox1.SelectedIndex = indx;
                    inst.gen_id             = listGenerators[comboBox1.SelectedIndex].ToString(); //assign Gen_id
                    lblLoc.Text             = "Location: " + listLocation[indx];
                    lblOrg.Text             = "Organization: " + org;

                    comboBox1.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error .. No Database", "Data Base", MessageBoxButtons.OK);
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                return;
            }
            #endregion

            #region Modem Init
            Modem    = ConfigurationManager.AppSettings["GPRSRxMODEM"];
            BaudRate = Convert.ToInt16(ConfigurationManager.AppSettings["GPRSBaudRate"]);
            try
            {
                //ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_SerialPort");
                //ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_POTSModem ");
                foreach (ManagementObject queryObj in searcher.Get())
                {
                    //String mod = queryObj["Name"].ToString();
                    //MessageBox.Show("Modem: " + mod + "\n");
                    if (queryObj["Status"].ToString() == "OK" && queryObj["Name"].ToString().Contains(Modem))   // i.e "ST-Ericsson ... "
                    {
                        // string name = queryObj.GetPropertyValue("Name").ToString();
                        //MessageBox.Show(System.Convert.ToString(queryObj["Description"]));
                        com = queryObj["AttachedTo"].ToString();
                        //break;

                        //int index = com.LastIndexOf('M');
                        //if (index > 0 && index <= 5)                     // Check for valid COMx port
                        //    port = Convert.ToInt32(com.Substring(index + 1, com.Length - index - 1));
                    }
                }
                if (com == null)  // using external STM900 Modem
                {
                    String     SqlConfig  = "SELECT * FROM ConfigSystem";
                    SqlCommand cmd        = new SqlCommand(SqlConfig, conn);
                    String     ComRxModem = null;
                    bool       Configured = false;
                    // com = Convert.ToString(ConfigurationManager.AppSettings["RxMODEM"]);

                    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]);
                            // PollTimer = Convert.ToInt32(rd[2]);
                            Configured = Convert.ToBoolean(rd[3]);
                            // DateTime  = Convert.ToString(rd[4]);
                        }
                        rd.Close();
                    }
                    if (Configured)
                    {
                        com = ComRxModem;   // assign com from db
                    }
                }
                if (com != null)
                {
                    //gprs = new GsmCommMain(port, BaudRate, 1000);              //
                    gprs = new UsbModem();

                    try
                    {
                        this.usbport = gprs.OpenPort(com, BaudRate, 8, 300, 300);
                        if (this.usbport.IsOpen)
                        {
                            // String ok =  gprs.ConfigModem();    // set modem defaults
                        }
                        else
                        {
                            MessageBox.Show("Error: Unable to init Modem:");
                        }
                    }
                    catch (Exception ex)
                    {
                        // ModemSts = false;

                        //DeviceHelper helper = new DeviceHelper();
                        if (DeviceHelper.TryResetPortByName(com))    // modem?
                        {
                            this.usbport = gprs.OpenPort(com, BaudRate, 8, 300, 300);
                        }
                        else
                        {
                            MessageBox.Show("Error: Unable to Init/Reset Modem:" + ex.Message);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Comm port is Closed");
            }
            #endregion
            if (gprs != null)  //if (ModemSts)
            {
                btnGsmModule.Text      = "ON";
                btnGsmModule.BackColor = Color.Green;

                String network = gprs.GetCurrentOperator(this.usbport);
                if (network.Length > 0)
                {
                    btnNetworkStatus.Text      = network;
                    btnNetworkStatus.BackColor = Color.Green;
                }
            }
            if (gprs == null) //if (!ModemSts)
            {
                // modem not connected
                MessageBox.Show("Modem Failure", "Modem", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    this.usbport.DataReceived += new SerialDataReceivedEventHandler(gprs_dataReceived); // intrrupt handling only
                    SmsMsgInstance             = new SmsMessageIndication(ProcessSmsData);              // Delegate to process & update SQL db
                    gprs.MsgRxdEnableInterrupt(this.usbport);                                           // Now enable Rx interrupt
                    // String ok = gprs.ConfigModem();    // set modem defaults

                    // gprs.PhoneConnected += new EventHandler(gprs_ModemConnected);
                    //gprs.MessageReceived += new MessageReceivedEventHandler(gprs_SmsMessageReceived);
                    // gprs.ReceiveComplete += new  ProgressEventHandler(gprs_ReceiveComplete);
                    // gprs.PhoneDisconnected += new EventHandler(gprs_PhoneDisconnected);
                    // gprs.ModemStatus = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR = Mdem Config: " + ex.Message);
                }
                //Check that the InvalidFilesDirectory exists
                if (!Directory.Exists(ConfigurationManager.AppSettings["DiscardedSMS"]))
                {
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["DiscardedSMS"]);
                }
            }
            // String msg = "+CMT: "+923322683401","","15/11/07,16:22:46+20" D,15/11/07,16:22:43,num,1,2278,67,67,0,0,0,2192,0,0,1494,2147483647,235,480072,0,10000,498,100000,200"
        }  // form constr
        }     // for each sms

        #endregion


        public void Config(param p_inst)
        {
            inst    = p_inst;
            custid  = inst.cust_id;
            conn    = inst.conn; // db connection
            org     = inst.org;
            indx    = inst.indx;
            tc      = inst.tc; // used to select next index
            QueryOK = inst.QueryOk;
            if (QueryOK)
            {
                btQuery.BackColor = Color.Green;
            }
            else
            {
                btQuery.BackColor = Color.Red;
            }

            String SqlGenId = String.Format(@"Select Gen_Id,Location From Generators Where Cust_Id='{0}'", custid);

            /*  String dbconn = ConfigurationManager.AppSettings["ConnectionString"];
             *  conn = new SqlConnection(dbconn);
             */

            SqlDataReader drg = null;

            try
            {
                // conn.Open();
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlCommand cmdg = new SqlCommand(SqlGenId, conn))
                {
                    //cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    listGenerators.Clear();
                    listLocation.Clear();
                    comboBox1.Items.Clear();
                    while (drg.Read())
                    {
                        String genid = drg.GetString(0);
                        comboBox1.Items.Add(genid);
                        listGenerators.Add(genid);
                        listLocation.Add(drg.GetString(1));
                    }
                    drg.Close();
                    if (comboBox1.Items.Count > 1)
                    {
                        comboBox1.Items.Add("All");
                        listLocation.Add(org + " [All]");
                    }

                    comboBox1.SelectedIndex = indx;
                    inst.gen_id             = listGenerators[comboBox1.SelectedIndex].ToString(); //assign Gen_id
                    lblLoc.Text             = "Location: " + listLocation[indx];
                    lblOrg.Text             = "Organization: " + org;

                    comboBox1.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error .. No Database", "Data Base", MessageBoxButtons.OK);
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                return;
            }
        }
 public StatusForm(param p_inst) //String gen_id, int cust_id)
 {
     InitializeComponent();
     Config(p_inst);
 }
Пример #13
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();
                }
            }
        }
        public ConfigForm(param p_inst)
        {
            InitializeComponent();
            inst = p_inst;
            //////////////////////////
            UpdateLabels();
            //////////////////////////////
            int indx     = 0;
            int rxport   = 0;
            int pollport = 0;

            foreach (String prt in SerialPort.GetPortNames())
            {
                comboBoxRxModem.Items.Add(prt);      // assign ports to combobox
                comboBoxPollModem.Items.Add(prt);
                if (prt == ComRxModem)
                {
                    rxport = indx;
                }
                if (prt == ComPollModem)
                {
                    pollport = indx;
                }
                indx++;
            }
            if (comboBoxRxModem.Items.Count > 0)
            {
                comboBoxRxModem.SelectedIndex   = rxport;
                comboBoxPollModem.SelectedIndex = pollport;
            }
            int polindx = 0;

            for (int t = 0; t < 10; t++)
            {
                int temppoll = (t + 1) * STEP_INTERVAL;
                comboBoxPollTimer.Items.Add(temppoll + " Secs");
                if (temppoll == PollTimer)
                {
                    polindx = t;
                }
            }
            comboBoxPollTimer.SelectedIndex = polindx;
            DataTable dtDatabaseSources = null;

            // Retrieve the enumerator instance, and then retrieve the data sources.
            try
            {
                if (conn2.State != ConnectionState.Open)
                {
                    conn2.Open();
                }
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                dtDatabaseSources = instance.GetDataSources();

                //// Populate the data sources into DropDownList.
                foreach (DataRow row in dtDatabaseSources.Rows)
                {
                    if (!string.IsNullOrWhiteSpace(row["InstanceName"].ToString()))
                    {
                        comboBoxServerName.Items.Add(row["ServerName"].ToString() + "\\" + row["InstanceName"].ToString());
                    }
                }
                if (comboBoxServerName.Items.Count > 0)
                {
                    comboBoxServerName.SelectedIndex = 0;
                }
            }
            catch (ArgumentNullException ex)
            {
            }
            finally
            {
                if (conn2.State == ConnectionState.Open)
                {
                    conn2.Close();
                }
            }
        }  //const
 public LogsForm(param p_inst) //(String genid,String cd)
 {
     InitializeComponent();
     Config(p_inst);
 }
Пример #16
0
        public Form1(param p_inst) //(int id,DateTime dt,String orgz,int index=0)
        {
            InitializeComponent();
            inst   = p_inst;
            custid = inst.cust_id;
            conn   = inst.conn; // db connection
            //selectedDate = inst.dt;
            org  = inst.org;
            indx = inst.indx;
            tc   = inst.tc; // used to select next index
            btQuery.BackColor = Color.Red;
            String SqlGenId = String.Format(@"Select Gen_Id,Location From Generators Where Cust_Id='{0}'", custid);
            String dbconn   = ConfigurationManager.AppSettings["ConnectionString"];

            conn = new SqlConnection(dbconn);


            SqlDataReader drg = null;

            try
            {
                // conn.Open();
                if (conn.State != ConnectionState.Open)
                {
                    conn.Open();
                }
                using (SqlCommand cmdg = new SqlCommand(SqlGenId, conn))
                {
                    //cmdg.CommandTimeout = 60;   // 60 ms time out
                    drg = cmdg.ExecuteReader(); //CommandBehavior.CloseConnection);
                    listGenerators.Clear();
                    listLocation.Clear();
                    while (drg.Read())
                    {
                        String genid = drg.GetString(0);
                        comboBox1.Items.Add(genid);
                        listGenerators.Add(genid);
                        listLocation.Add(drg.GetString(1));
                    }
                    drg.Close();
                    if (comboBox1.Items.Count > 1)
                    {
                        comboBox1.Items.Add("All");
                        listLocation.Add(org + " [All]");
                    }

                    comboBox1.SelectedIndex = indx;
                    inst.gen_id             = listGenerators[comboBox1.SelectedIndex].ToString(); //assign Gen_id
                    lblLoc.Text             = "Location: " + listLocation[indx];
                    lblOrg.Text             = "Organization: " + org;

                    comboBox1.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error .. No Database", "Data Base", MessageBoxButtons.OK);
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                return;
            }



            // Modem = ConfigurationManager.AppSettings["GPRSMODEM"];
            BaudRate = Convert.ToInt16(ConfigurationManager.AppSettings["GPRSBaudRate"]);
            try
            {
                /*  ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_SerialPort");
                 * foreach (ManagementObject queryObj in searcher.Get())
                 * {
                 *    String mod = queryObj["Name"].ToString();
                 *    if (queryObj["Name"].ToString().Contains(Modem))   // i.e "ST-Ericsson ... "
                 *    {
                 *        com = queryObj["DeviceID"].ToString();
                 *        //int index = com.LastIndexOf('M');
                 *        //if (index > 0 && index <= 5)                     // Check for valid COMx port
                 *        //    port = Convert.ToInt32(com.Substring(index + 1, com.Length - index - 1));
                 *    }
                 * }  */
                // com = "COM3";
                com = Convert.ToString(ConfigurationManager.AppSettings["RxMODEM"]);
                if (com != null)
                {
                    //gprs = new GsmCommMain(port, BaudRate, 1000);              //
                    gprs = new UsbModem();


                    try
                    {
                        this.usbport = gprs.OpenPort(com, BaudRate, 8, 300, 300);
                        if (this.usbport.IsOpen)
                        {
                            // String ok =  gprs.ConfigModem();    // set modem defaults
                        }
                        else
                        {
                            MessageBox.Show("Error: Unable to init Modem:");
                        }
                    }
                    catch (Exception ex)
                    {
                        // ModemSts = false;
                        MessageBox.Show("Error: Unable to init Modem:" + ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: Comm port is Closed");
            }

            if (gprs != null)  //if (ModemSts)
            {
                btnGsmModule.Text      = "ON";
                btnGsmModule.BackColor = Color.Green;

                String network = gprs.GetCurrentOperator(this.usbport);
                if (network.Length > 0)
                {
                    btnNetworkStatus.Text      = network;
                    btnNetworkStatus.BackColor = Color.Green;
                }
            }
            if (gprs == null) //if (!ModemSts)
            {
                // modem not connected
                MessageBox.Show("Modem Failure", "Modem", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    this.usbport.DataReceived += new SerialDataReceivedEventHandler(gprs_dataReceived); // intrrupt handling only
                    SmsMsgInstance             = new SmsMessageIndication(ProcessSmsData);              // Delegate to process & update SQL db
                    gprs.MsgRxdEnableInterrupt(this.usbport);                                           // Now enable Rx interrupt
                    // String ok = gprs.ConfigModem();    // set modem defaults

                    // gprs.PhoneConnected += new EventHandler(gprs_ModemConnected);
                    //gprs.MessageReceived += new MessageReceivedEventHandler(gprs_SmsMessageReceived);
                    // gprs.ReceiveComplete += new  ProgressEventHandler(gprs_ReceiveComplete);
                    // gprs.PhoneDisconnected += new EventHandler(gprs_PhoneDisconnected);
                    // gprs.ModemStatus = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR = Mdem Config: " + ex.Message);
                }
                //Check that the InvalidFilesDirectory exists
                if (!Directory.Exists(ConfigurationManager.AppSettings["DiscardedSMS"]))
                {
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["DiscardedSMS"]);
                }
            }
        }  // form constr