Ejemplo n.º 1
0
        private void UpdateMessage(String msgID, String batchID)
        {
            String query = String.Format("UPDATE tblSMS SET batchID = '{0}', status = '1' WHERE id = '{1}'", batchID, msgID);

            DataHandler.setData(query, out dataStatus);
        }
Ejemplo n.º 2
0
        private void GetMail()
        {
            timer.Enabled = false;
            popMessages   = FetchAllMessages(hostName, port, useSSL, username, password);
            mailMessages  = new List <MailMessage>();
            if (popMessages.Count > 0)
            {
                if (messages == null)
                {
                    messages = new Dictionary <string, EmailConstruct>();
                }
                foreach (Message m in popMessages)
                {
                    try
                    {
                        if (!messages.ContainsKey(m.Headers.MessageId))
                        {
                            if (NewMessageEvent != null)
                            {
                                NewMessageEvent(this, new MessageArgs("Event Fired: MailPopped"));
                            }
                            EmailConstruct e = new EmailConstruct();
                            e.ID = m.Headers.MessageId;
                            MailMessage mm   = m.ToMailMessage();
                            String      body = mm.Body;
                            e.SentFrom = mm.From.Address.Replace("@2way.co.za", "");
                            if (NewMessageEvent != null)
                            {
                                NewMessageEvent(this, new MessageArgs(e.SentFrom));
                            }
                            if (mm.To.Count > 0)
                            {
                                e.SentTo = mm.To.ToList()[0].Address;
                            }
                            e.ReceivedDate = m.Headers.DateSent;
                            e.Subject      = mm.Subject;
                            messages.Add(e.ID, new EmailConstruct());
                            if (e.Subject == "SMS to email")
                            {
                                #region SMS Emails

                                List <String> refs = References();
                                foreach (String reference in refs)
                                {
                                    if (e.Body.Contains(reference))
                                    {
                                        e.Reference = reference;
                                        e.Body      = e.Body.Replace(reference, "");
                                        break;
                                    }
                                }
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("2"));
                                }
                                e.ForwardDate = new DateTime(1900, 1, 1);
                                e.ForwardedTo = "";
                                e.HandledDate = new DateTime(1900, 1, 1);
                                e.Handled     = false;
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("Before Save"));
                                }
                                SaveMail(ref e);
                                if (NewMessageEvent != null)
                                {
                                    NewMessageEvent(this, new MessageArgs("After save"));
                                }
                                String buildingQuery = "SELECT distinct u.username, u.email, sms.customer FROM tblSMS AS sms INNER JOIN tblBuildings AS b ON sms.building = b.Code INNER JOIN";
                                buildingQuery += " tblUserBuildings AS ub ON b.id = ub.buildingid INNER JOIN tblUsers AS u ON ub.userid = u.id";
                                buildingQuery += " WHERE (sms.sender = '" + e.SentFrom + "')";
                                String  dsStatus = "";
                                DataSet dsUsers  = DataHandler.getData(buildingQuery, out dsStatus);
                                if (dsUsers != null && dsUsers.Tables.Count > 0 && dsUsers.Tables[0].Rows.Count > 0)
                                {
                                    String        msgfrom = "Astrodon Debtors System";
                                    String        subject = "New Message From - " + dsUsers.Tables[0].Rows[0]["customer"].ToString();
                                    String        message = "A new sms message has been received from the above customer.  Please check the Debtor System for more information.";
                                    List <String> toMails = new List <string>();

                                    foreach (DataRow dr in dsUsers.Tables[0].Rows)
                                    {
                                        String toMail = dr["email"].ToString();
                                        if (!String.IsNullOrEmpty(toMail))
                                        {
                                            toMails.Add(toMail);
                                        }
                                    }

                                    if (MailSender.SendMail(msgfrom, toMails, subject, message, false, null))
                                    {
                                        String sentMsg = String.Format("Message sent to {0}", String.Join(";", toMails.ToArray()));
                                        if (NewMessageEvent != null)
                                        {
                                            NewMessageEvent(this, new MessageArgs(sentMsg + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")));
                                        }
                                    }
                                }

                                #endregion SMS Emails
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                }
                for (int i = messages.Count; i > 0; i--)
                {
                    DeleteMessageOnServer(hostName, port, useSSL, username, password, i);
                }
            }
            timer.Enabled = true;
        }
Ejemplo n.º 3
0
        private void UpdateMessage(String batchID, String status, DateTime nextPolled, int pollCount)
        {
            String query = String.Format("UPDATE tblSMS SET status = '{0}', nextPolled = getDate(), pollCount = {2} WHERE batchID = '{3}'", status, nextPolled.ToString(), pollCount.ToString(), batchID);

            DataHandler.setData(query, out dataStatus);
        }
Ejemplo n.º 4
0
        private void btnRetrieve_Click(object sender, EventArgs e)
        {
            String building = String.Empty;
            String customer = String.Empty;

            if (cmbBuilding.SelectedItem != null)
            {
                building = cmbBuilding.SelectedItem.ToString();
            }
            if (cmbCustomer.SelectedItem != null)
            {
                customer = cmbCustomer.SelectedItem.ToString();
            }
            DateTime sDate     = sDatePicker.Value;
            DateTime eDate     = eDatePicker.Value;
            DateTime startDate = new DateTime(sDate.Year, sDate.Month, sDate.Day, 0, 0, 0);
            DateTime endDate   = new DateTime(eDate.Year, eDate.Month, eDate.Day, 23, 59, 59);
            String   query     = "SELECT s.building, s.customer, s.number, s.reference, s.message, s.sent, u.username, s.status FROM tblSMS AS s LEFT OUTER JOIN";

            query += " tblUsers AS u ON s.sender = u.id WHERE sent >= '" + startDate.ToString() + "' AND sent <= '" + endDate.ToString() + "'";
            if (!String.IsNullOrEmpty(building) && building == "All buildings")
            {
                if (!String.IsNullOrEmpty(customer) && customer == "All customers")
                {
                }
                else if (!String.IsNullOrEmpty(customer))
                {
                    query += " AND s.customer = '" + customer + "'";
                }
            }
            else if (!String.IsNullOrEmpty(building) && !String.IsNullOrEmpty(customer) && customer == "All customers")
            {
                query += " AND s.building = '" + building + "'";
            }
            else if (!String.IsNullOrEmpty(building) && !String.IsNullOrEmpty(customer))
            {
                query += " AND s.building = '" + building + "' AND s.customer = '" + customer + "'";
            }
            query += " ORDER BY s.sent";
            //MessageBox.Show(query);
            DataSet results = DataHandler.getData(query, out status);

            if (results != null && results.Tables.Count > 0 && results.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in results.Tables[0].Rows)
                {
                    DataRecords drec = new DataRecords();
                    drec.Building  = dr["building"].ToString();
                    drec.Customer  = dr["customer"].ToString();
                    drec.Cell      = dr["number"].ToString();
                    drec.Reference = dr["reference"].ToString();
                    drec.Message   = dr["message"].ToString();
                    drec.Sent      = DateTime.Parse(dr["sent"].ToString());
                    drec.Sender    = dr["username"].ToString();
                    drec.Status    = dr["status"].ToString();
                    bs.Add(drec);
                }
            }
            else
            {
                MessageBox.Show("No results");
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Stops data processor.
 /// </summary>
 virtual public void stop()
 {
     dp.stop();
     dh -= new DataHandler(dp.process);
     dp  = null;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts data processor.
 /// </summary>
 virtual public void start()
 {
     dp  = new DataProcess();
     dh += new DataHandler(dp.process);
     dp.start();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Stops data processor.
 /// </summary>
 public virtual void stop()
 {
     dp.stop();
     dh -= new DataHandler(dp.process);
     dp = null;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Starts data processor.
 /// </summary>
 public virtual void start()
 {
     dp = new DataProcess();
     dh += new DataHandler(dp.process);
     dp.start();
 }