Esempio n. 1
0
        private void btnSystemSettings_Click(object sender, EventArgs e)
        {
            SystemSetting setting = EFERTDbUtility.mEFERTDb.SystemSetting.FirstOrDefault();

            SetSystemSettingForm systemSettingForm = new SetSystemSettingForm(setting);

            systemSettingForm.ShowDialog(this);
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            int dayToEmailNotification = Convert.ToInt32(this.nuNoEmailNotificationDays.Value);
            int daysToBlock            = Convert.ToInt32(this.nuNoOfBlockUserDays.Value);

            if (daysToBlock < dayToEmailNotification)
            {
                MessageBox.Show("Days to block can not be less than day to email notification.");
                return;
            }

            try
            {
                if (this.mSettings == null)
                {
                    this.mSettings = new SystemSetting();

                    this.mSettings.DaysToEmailNotification = Convert.ToInt32(this.nuNoEmailNotificationDays.Value);
                    this.mSettings.DaysToBlockUser         = Convert.ToInt32(this.nuNoOfBlockUserDays.Value);
                    this.mSettings.SmtpServer         = this.tbxSmtpServer.Text;
                    this.mSettings.SmtpPort           = this.tbxSmtpPort.Text;
                    this.mSettings.FromEmailAddress   = this.tbxUserName.Text;
                    this.mSettings.FromEmailPassword  = this.tbxPassword.Text;
                    this.mSettings.IsSmptSSL          = this.chbIsSSL.Checked;
                    this.mSettings.IsSmptAuthRequired = this.chbAuthReq.Checked;

                    EFERTDbUtility.mEFERTDb.SystemSetting.Add(this.mSettings);
                }
                else
                {
                    this.mSettings.DaysToEmailNotification = Convert.ToInt32(this.nuNoEmailNotificationDays.Value);
                    this.mSettings.DaysToBlockUser         = Convert.ToInt32(this.nuNoOfBlockUserDays.Value);
                    this.mSettings.SmtpServer         = this.tbxSmtpServer.Text;
                    this.mSettings.SmtpPort           = this.tbxSmtpPort.Text;
                    this.mSettings.FromEmailAddress   = this.tbxUserName.Text;
                    this.mSettings.FromEmailPassword  = this.tbxPassword.Text;
                    this.mSettings.IsSmptSSL          = this.chbIsSSL.Checked;
                    this.mSettings.IsSmptAuthRequired = this.chbAuthReq.Checked;

                    EFERTDbUtility.mEFERTDb.Entry(this.mSettings).State = System.Data.Entity.EntityState.Modified;
                }

                EFERTDbUtility.mEFERTDb.SaveChanges();
            }
            catch (Exception ex)
            {
                EFERTDbUtility.RollBack();

                MessageBox.Show(this, "Some save system settings.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex));
            }
        }
Esempio n. 3
0
        public static void SendMail(SystemSetting settings, string toAddress, string toName, string chName, string chCnic)
        {
            try
            {
                string fromaddr = settings.FromEmailAddress;
                //string toAddress = "*****@*****.**";//TO ADDRESS HERE
                string password = settings.FromEmailPassword;

                int emailNotificationDays = settings.DaysToEmailNotification;

                using (MailMessage msg = new MailMessage())
                {
                    msg.Subject = "Security Alert for continously entry of casual worker.";

                    msg.From = new MailAddress(fromaddr);
                    msg.Body = "Dear Sir,\n\nIt's for your information following worker entry limit reached at " + emailNotificationDays + " day(s) need your necessary action on it.\n\n Name: " + chName + "\n\n CNIC Number: " + chCnic + "\n\nThis is system generated email.";
                    msg.To.Add(new MailAddress(toAddress));

                    using (SmtpClient smtp = new SmtpClient())
                    {
                        smtp.Host = settings.SmtpServer;
                        smtp.Port = Convert.ToInt32(settings.SmtpPort);
                        smtp.UseDefaultCredentials = true;
                        smtp.EnableSsl             = settings.IsSmptSSL;

                        if (settings.IsSmptAuthRequired)
                        {
                            NetworkCredential nc = new NetworkCredential(fromaddr, password);
                            smtp.Credentials = nc;
                        }

                        smtp.Send(msg);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occured in sending email.\n\n" + GetInnerExceptionMessage(ex));
            }
        }
Esempio n. 4
0
        public SetSystemSettingForm(SystemSetting setting)
        {
            this.mSettings = setting;
            InitializeComponent();

            if (setting == null)
            {
                this.nuNoEmailNotificationDays.Value = 70;
                this.nuNoOfBlockUserDays.Value       = 90;
            }
            else
            {
                this.nuNoEmailNotificationDays.Value = setting.DaysToEmailNotification;
                this.nuNoOfBlockUserDays.Value       = setting.DaysToBlockUser;
                this.tbxSmtpServer.Text = setting.SmtpServer;
                this.tbxSmtpPort.Text   = setting.SmtpPort;
                this.tbxUserName.Text   = setting.FromEmailAddress;
                this.tbxPassword.Text   = setting.FromEmailPassword;
                this.chbIsSSL.Checked   = setting.IsSmptSSL;
                this.chbAuthReq.Checked = setting.IsSmptAuthRequired;
            }
        }
Esempio n. 5
0
        public static LimitStatus CheckIfUserCheckedInLimitReached(List <CheckInAndOutInfo> checkIns, List <BlockedPersonInfo> blocks, bool sendEmail = true)
        {
            LimitStatus   limitStatus = LimitStatus.Allowed;
            SystemSetting setting     = EFERTDbUtility.mEFERTDb.SystemSetting.FirstOrDefault();

            int daysToEmailNotification = setting == null ? 70 : setting.DaysToEmailNotification;
            int daysToBlock             = setting == null ? 90 : setting.DaysToBlockUser;

            if (checkIns.Count > 0)
            {
                CheckInAndOutInfo last = checkIns.Last();

                if (last.CheckedIn)
                {
                    limitStatus = LimitStatus.CurrentlyCheckIn;
                }
                else
                {
                    //system deplymenrt date is 1/jan/2017 requirement is get user yearly report
                    DateTime fromDate = new DateTime(2018, 04, 1);
                    DateTime toDate   = DateTime.Now;

                    BlockedPersonInfo lastBlockedPerson = (from block in blocks
                                                           where block != null &&
                                                           block.BlockedTime >= fromDate &&
                                                           block.BlockedTime < toDate &&
                                                           !block.Blocked &&
                                                           block.BlockedBy == CONST_SYSTEM_BLOCKED_BY
                                                           select block).LastOrDefault();

                    if (lastBlockedPerson != null)
                    {
                        fromDate = lastBlockedPerson.UnBlockTime;
                    }

                    checkIns = (from checkin in checkIns
                                where checkin != null && checkin.DateTimeIn >= fromDate && checkin.DateTimeIn < toDate
                                select checkin).ToList();

                    if (checkIns.Count == 0)
                    {
                        return(limitStatus);
                    }

                    string name, cnic = string.Empty;

                    if (last.CardHolderInfos != null)
                    {
                        name = last.CardHolderInfos.FirstName;
                        cnic = last.CardHolderInfos.CNICNumber;
                    }
                    else if (last.Visitors != null)
                    {
                        name = last.Visitors.FirstName;
                        cnic = last.Visitors.CNICNumber;
                    }
                    else
                    {
                        name = last.DailyCardHolders.FirstName;
                        cnic = last.DailyCardHolders.CNICNumber;
                    }

                    List <AlertInfo> chAlertInfos = (from alert in EFERTDbUtility.mEFERTDb.AlertInfos
                                                     where alert != null && alert.CNICNumber == cnic
                                                     select alert).ToList();

                    DateTime  alertEnableDate = DateTime.MaxValue;
                    bool      alertEnabled    = true;
                    AlertInfo lastAlertInfo   = null;

                    if (chAlertInfos != null && chAlertInfos.Count > 0)
                    {
                        lastAlertInfo = chAlertInfos.Last();

                        if (lastAlertInfo.DisableAlert)
                        {
                            alertEnabled = false;
                        }
                        else
                        {
                            alertEnableDate = lastAlertInfo.EnableAlertDate;
                        }
                    }


                    CheckInAndOutInfo previousCheckIn = checkIns[0];
                    bool isSameDay = last.DateTimeIn.Date == DateTime.Now.Date;

                    if (previousCheckIn != null)
                    {
                        int      count = 1;
                        DateTime previousDateTimeIn = previousCheckIn.DateTimeIn;

                        for (int i = 1; i < checkIns.Count; i++)
                        {
                            CheckInAndOutInfo CurrentCheckIn = checkIns[i];

                            DateTime currDateTimeIn = CurrentCheckIn.DateTimeIn;

                            TimeSpan timeDiff = currDateTimeIn.Date - previousDateTimeIn.Date;



                            //bool isContinous = timeDiff.Days == 1 || timeDiff.Days == 2 && currDateTimeIn.DayOfWeek == DayOfWeek.Monday;

                            if (timeDiff.Days >= 1)
                            {
                                count++;
                            }
                            //else
                            //{
                            //    if (currDateTimeIn.Date != previousDateTimeIn.Date)
                            //    {
                            //        count = 1;
                            //    }

                            //}

                            previousDateTimeIn = currDateTimeIn;
                        }

                        if (count >= daysToEmailNotification)
                        {
                            if (count >= daysToBlock && !isSameDay) //== to change >= when add category in checkins
                            {
                                limitStatus = LimitStatus.LimitReached;
                            }
                            else
                            {
                                if (alertEnabled)
                                {
                                    if (sendEmail)
                                    {
                                        List <EmailAddress> toAddresses = new List <EmailAddress>();

                                        if (EFERTDbUtility.mEFERTDb.EmailAddresses != null)
                                        {
                                            toAddresses = (from email in EFERTDbUtility.mEFERTDb.EmailAddresses
                                                           where email != null
                                                           select email).ToList();

                                            foreach (EmailAddress toAddress in toAddresses)
                                            {
                                                SendMail(setting, toAddress.Email, toAddress.Name, name, cnic);
                                            }
                                        }
                                    }


                                    limitStatus = LimitStatus.EmailAlerted;
                                }
                                else
                                {
                                    limitStatus = LimitStatus.EmailAlertDisabled;
                                }
                            }
                        }
                        else
                        {
                            limitStatus = LimitStatus.Allowed;
                        }
                    }
                }
            }

            return(limitStatus);
        }