Exemple #1
0
        private void threadSendSMS_DoWork(object sender, DoWorkEventArgs e)
        {
            sms.InitModem();
            sms.OpenModemCommunication();
            Box.infoBox("Message Start sending...!");
            sendingProcess = true;

            lblSMSNo.Invoke(new MethodInvoker(delegate
            {
                lblSMSNo.Text   = Convert.ToString(tobeSent());
                lblSMSSent.Text = Convert.ToString(sentMsg());
            }));



            for (int i = 0; i < dataToSend.Rows.Count; i++)
            {
                string mobileno = Convert.ToString(dataToSend.Rows[i]["mobile"]);
                string msg      = Convert.ToString(dataToSend.Rows[i]["msg"]);
                int    msgsID   = Convert.ToInt32(dataToSend.Rows[i]["msgsID"]);
                sms.SendMessage(mobileno, msg, true);
                markSent(msgsID);
                lblSMSSent.Invoke(new MethodInvoker(delegate
                {
                    lblSMSSent.Text = Convert.ToString(sentMsg());
                }));

                Thread.Sleep(2000);
            }

            sendingProcess = false;
            sms.CloseModemCommunication();
        }
        private void threadSMS_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                sms.s_port = portNo;
                sms.InitModem();
                sms.OpenModemCommunication();


                if (btnConnect.InvokeRequired)
                {
                    btnConnect.Invoke(new MethodInvoker(delegate
                    {
                        btnConnect.Text     = "Disconnect";
                        btnConnect.Enabled  = true;
                        isSMSModemConnected = true;
                        isLoop = true;
                        txtModemLogs.AppendText(Environment.NewLine + "System : Modem Connected Successfully.");
                    }));
                }


                if (isSMSModemConnected)
                {
                    DataTable dt = new DataTable();
                    string    mobileno, timelog, status, name, bodyMsg = "";
                    int       attlogid;


                    //////////
                    ////.////
                    /////////////
                    ///Dara ang LOOP SIGA KAG MATA!!!
                    while (isLoop)
                    {
                        dt.Clear();
                        using (MySqlConnection conn = new MySqlConnection(Connection.getConnectionString()))
                        {
                            MySqlCommand threadCmd;

                            //conn = Connection.con();
                            conn.Open();
                            string threadQuery = "select * from vw_attlog where dateDay=?dDay and isSent=0 and isExempted = 0";
                            threadCmd = new MySqlCommand(threadQuery, conn);
                            threadCmd.Parameters.AddWithValue("?dDay", DateTime.Now.ToString("yyyy-MM-dd"));
                            MySqlDataAdapter aa = new MySqlDataAdapter(threadCmd);
                            aa.Fill(dt);
                            aa.Dispose();
                            threadCmd.Dispose();
                            conn.Close();
                        }



                        if (dt.Rows.Count > 0)
                        {
                            for (int row = 0; row < dt.Rows.Count; row++)
                            {
                                attlogid = Convert.ToInt32(dt.Rows[row]["attlogID"]);
                                mobileno = Convert.ToString(dt.Rows[row]["pMobileNo"]);
                                timelog  = Convert.ToString(dt.Rows[row]["datetimeLog"]);
                                status   = Convert.ToString(dt.Rows[row]["remarks"]);
                                name     = Convert.ToString(dt.Rows[row]["lname"]) + ", " + Convert.ToString(dt.Rows[row]["fname"]);

                                if (status == "IN")
                                {
                                    bodyMsg = "Your son/daughter (" + name + ") has entered school premise @ " + timelog;
                                }
                                else if (status == "OUT")
                                {
                                    //bodyMsg = "As of " + timelog + ", " + name + " megawas sa gate!. PLEASE DO NOT REPLY.";
                                    bodyMsg = "Your son/daughter (" + name + ") has went out the school premise @ " + timelog;
                                }
                                else if (status == "ABSENT")
                                {
                                    bodyMsg = "As of " + timelog + ", " + name + " recorded as absent as this day.";
                                }

                                txtModemLogs.Invoke(new MethodInvoker(delegate
                                {
                                    txtModemLogs.AppendText(Environment.NewLine + "System : Sending to " + mobileno + " (" + name + ")");
                                }));

                                sms.SendMessage(mobileno, bodyMsg, false);
                                updateIsSent(attlogid);

                                txtModemLogs.Invoke(new MethodInvoker(delegate
                                {
                                    txtModemLogs.AppendText(Environment.NewLine + "System : Message sending sent.");
                                }));

                                Thread.Sleep(5000);
                            }
                        }

                        Thread.Sleep(5000);
                    }
                }
            }
            catch (Exception er)
            {
                txtModemLogs.Invoke(new MethodInvoker(delegate
                {
                    txtModemLogs.AppendText(Environment.NewLine + "System : ERROR : " + er.Message);
                    btnConnect.Enabled = true;
                    btnConnect.Text    = "Connect";
                }));
            }
        } // threadSMS Do_Work method
Exemple #3
0
        private void threadSMS_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                sms.InitModem();
                sms.OpenModemCommunication();

                if (lblSMS.GetCurrentParent().InvokeRequired)
                {
                    lblSMS.GetCurrentParent().Invoke(new MethodInvoker(delegate
                    {
                        lblSMS.Text = "SMS : CONNECTED";
                        isModemOK   = true;
                    }));
                }

                if (isModemOK)
                {
                    DataTable dt = new DataTable();
                    string    mobileno, timelog, status, name, bodyMsg = "";
                    int       attlogid;

                    while (true)
                    {
                        dt.Clear();
                        using (MySqlConnection conn = new MySqlConnection())
                        {
                            MySqlCommand threadCmd;
                            conn.Open();
                            string threadQuery = "select * from vw_attlog where dateDay=?dDay and isSent=0 and ayCode=?aycode";
                            threadCmd = new MySqlCommand(threadQuery, conn);
                            threadCmd.Parameters.AddWithValue("?dDay", DateTime.Now.ToString("yyyy-MM-dd"));
                            MySqlDataAdapter aa = new MySqlDataAdapter(threadCmd);
                            aa.Fill(dt);
                            aa.Dispose();
                            threadCmd.Dispose();
                            conn.Close();
                        }


                        if (dt.Rows.Count > 0)
                        {
                            for (int row = 0; row < dt.Rows.Count; row++)
                            {
                                attlogid = Convert.ToInt32(dt.Rows[row]["attlogID"]);
                                mobileno = Convert.ToString(dt.Rows[row]["mobileNo"]);
                                timelog  = Convert.ToString(dt.Rows[row]["datetimeLog"]);
                                status   = Convert.ToString(dt.Rows[row]["remarks"]);
                                name     = Convert.ToString(dt.Rows[row]["lname"]) + ", " + Convert.ToString(dt.Rows[row]["fname"]);

                                if (status == "IN")
                                {
                                    bodyMsg = "Your son/daughter (" + name + ") has entered school premise @ " + timelog;
                                }
                                else if (status == "OUT")
                                {
                                    bodyMsg = "As of " + timelog + ", " + name + " megawas sa gate!. PLEASE DO NOT REPLY.";
                                }


                                sms.SendMessage(mobileno, bodyMsg, false);
                                updateIsSent(attlogid);
                                Sleep(5000);
                            }
                        }

                        Sleep(5000);
                    }
                }
            }
            catch (Exception er)
            {
                if (lblSMS.GetCurrentParent().InvokeRequired)
                {
                    lblSMS.GetCurrentParent().Invoke(new MethodInvoker(delegate
                    {
                        isModemOK   = false;
                        lblSMS.Text = "SMS : ERROR";
                        Box.errBox(er.Message);
                    }));
                }
                //throw;
            }
        }