private void UpdateLayoutForBlockedPerson(BlockedPersonInfo blockedPerson) { if (blockedPerson != null) { this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = false; this.lblVisitorStatus.Text = "Blocked"; this.lblVisitorStatus.BackColor = Color.Red; this.tbxBlockedBy.Text = blockedPerson.BlockedBy; this.tbxBlockedReason.Text = blockedPerson.BlockedReason; this.tbxBlockedTime.Text = blockedPerson.BlockedTime.ToString(); this.btnBlock.Enabled = false; this.btnUnBlock.Enabled = true; this.tbxBlockedBy.ReadOnly = true; this.tbxBlockedReason.ReadOnly = true; this.tbxBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxBlockedReason.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxUnBlockedBy.ReadOnly = false; this.tbxUnblockReason.ReadOnly = false; this.tbxUnBlockedBy.Text = string.Empty; this.tbxUnblockReason.Text = string.Empty; this.tbxUnBlockedBy.BackColor = System.Drawing.Color.White; this.tbxUnblockReason.BackColor = System.Drawing.Color.White; } }
public BlockedPersonNotificationForm(BlockedPersonInfo blockedPersonInfo) { InitializeComponent(); if (blockedPersonInfo != null) { if (blockedPersonInfo.CardHolderInfos != null) { this.lblCardHolderName.Text = blockedPersonInfo.CardHolderInfos.FirstName; this.lblCNIC.Text = blockedPersonInfo.CardHolderInfos.CNICNumber; } else if (blockedPersonInfo.DailyCardHolders != null) { this.lblCardHolderName.Text = blockedPersonInfo.DailyCardHolders.FirstName; this.lblCNIC.Text = blockedPersonInfo.DailyCardHolders.CNICNumber; } else if (blockedPersonInfo.Visitors != null) { this.lblCardHolderName.Text = blockedPersonInfo.Visitors.FirstName; this.lblCNIC.Text = blockedPersonInfo.Visitors.CNICNumber; } else { this.lblCardHolderName.Text = "Not Found"; this.lblCNIC.Text = "Not Found"; } } }
private void btnBlock_Click(object sender, EventArgs e) { bool validtated = EFERTDbUtility.ValidateInputs(new List <TextBox>() { this.tbxFirstName, this.tbxCNICNumber, this.tbxBlockedBy, this.tbxBlockedReason }); if (!validtated) { MessageBox.Show(this, "Please fill mandatory fields first."); return; } DialogResult result = MessageBox.Show(this, "Are you sure you want to block this person?", "Confirmation Dialog", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } if (this.tbxBlockedBy.Text == EFERTDbUtility.CONST_SYSTEM_BLOCKED_BY) { MessageBox.Show(this, "Block by \"System\" can not be used."); return; } BlockedPersonInfo blockedPerson = this.BlockPerson(this.tbxBlockedBy.Text, this.tbxBlockedReason.Text); if (blockedPerson != null) { this.UpdateLayoutForBlockedPerson(blockedPerson); } }
private BlockedPersonInfo BlockPerson(string blockedBy, string blockedReason) { BlockedPersonInfo blockedPerson = new BlockedPersonInfo() { Blocked = true, BlockedBy = blockedBy, BlockedReason = blockedReason, CNICNumber = this.mCNICNumber, BlockedTime = DateTime.Now, UnBlockTime = DateTime.MaxValue }; blockedPerson.BlockedInPlant = SearchForm.mIsPlant; blockedPerson.BlockedInColony = !SearchForm.mIsPlant; if (this.mVisitor == null) { MessageBox.Show(this, "Unable to Block visitor. Some error occured in getting visitor information."); return(null); } else { blockedPerson.Visitors = this.mVisitor; } try { EFERTDbUtility.mEFERTDb.BlockedPersons.Add(blockedPerson); EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in blocking visitor.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return(null); } this.mBlocks = this.mVisitor.BlockingInfos; return(blockedPerson); }
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); }
private void btnUnBlock_Click(object sender, EventArgs e) { if (!this.tbxCnicNumber.MaskCompleted) { MessageBox.Show(this, "Please Enter correct CNIC NUMBER."); this.tbxCnicNumber.ReadOnly = false; this.tbxCnicNumber.BackColor = System.Drawing.Color.White; return; } bool validtated = EFERTDbUtility.ValidateInputs(new List <TextBox>() { this.tbxFirstName, this.tbxUnBlockedBy, this.tbxUnblockReason }); if (!validtated) { MessageBox.Show(this, "Please fill mandatory fields first."); return; } DialogResult result = MessageBox.Show(this, "Are you sure you want to block this person?", "Confirmation Dialog", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } if (this.mBlocks.Exists(blocked => blocked.Blocked && blocked.CNICNumber == this.mCNICNumber)) { BlockedPersonInfo blockedPerson = this.mBlocks.Find(blocked => blocked.Blocked && blocked.CNICNumber == this.mCNICNumber); blockedPerson.Blocked = false; blockedPerson.UnBlockTime = DateTime.Now; blockedPerson.UnBlockedBy = this.tbxUnBlockedBy.Text; blockedPerson.UnBlockedReason = this.tbxUnblockReason.Text; try { EFERTDbUtility.mEFERTDb.Entry(blockedPerson).State = System.Data.Entity.EntityState.Modified; EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in unblocking cardholder.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return; } if (this.mCheckIns.Exists(checkedIn => checkedIn.CheckedIn && checkedIn.CNICNumber == this.mCNICNumber)) { this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = true; } else { this.btnCheckIn.Enabled = true; this.btnCheckOut.Enabled = false; } this.mBlocks = this.mVisitor.BlockingInfos; this.tbxBlockedBy.Text = string.Empty; this.tbxBlockedReason.Text = string.Empty; this.lblVisitorStatus.Text = "Allowed"; this.lblVisitorStatus.BackColor = Color.Green; this.tbxUnBlockTime.Text = blockedPerson.UnBlockTime.ToString(); this.btnBlock.Enabled = true; this.btnUnBlock.Enabled = false; this.tbxBlockedBy.ReadOnly = false; this.tbxBlockedReason.ReadOnly = false; this.tbxBlockedBy.BackColor = System.Drawing.Color.White; this.tbxBlockedReason.BackColor = System.Drawing.Color.White; this.tbxUnBlockedBy.ReadOnly = true; this.tbxUnblockReason.ReadOnly = true; this.tbxUnBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxUnblockReason.BackColor = System.Drawing.SystemColors.ButtonFace; } else { MessageBox.Show(this, "This user is not blocked."); } }
private void btnBlock_Click(object sender, EventArgs e) { if (!this.tbxCnicNumber.MaskCompleted) { MessageBox.Show(this, "Please Enter correct CNIC NUMBER."); this.tbxCnicNumber.ReadOnly = false; this.tbxCnicNumber.BackColor = System.Drawing.Color.White; return; } bool validtated = EFERTDbUtility.ValidateInputs(new List <TextBox>() { this.tbxFirstName, this.tbxBlockedBy, this.tbxBlockedReason }); if (!validtated) { MessageBox.Show(this, "Please fill mandatory fields first."); return; } DialogResult result = MessageBox.Show(this, "Are you sure you want to block this person?", "Confirmation Dialog", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } if (this.tbxBlockedBy.Text == EFERTDbUtility.CONST_SYSTEM_BLOCKED_BY) { MessageBox.Show(this, "Block by \"System\" can not be used."); return; } if (this.mVisitor == null) { VisitorCardHolder visitor = new VisitorCardHolder(); visitor.CNICNumber = this.tbxCnicNumber.Text; visitor.Gender = this.cbxGender.SelectedItem == null ? string.Empty : this.cbxGender.SelectedItem as String; visitor.FirstName = this.tbxFirstName.Text; visitor.LastName = this.tbxLastName.Text; visitor.Address = this.tbxAddress.Text; visitor.PostCode = this.tbxPostCode.Text; visitor.City = this.tbxCity.Text; visitor.State = this.tbxState.Text; visitor.CompanyName = this.tbxCompanyName.Text; visitor.ContactNo = this.tbxPhoneNumber.Text; visitor.EmergencyContantPerson = this.tbxEmergencyContact.Text; visitor.EmergencyContantPersonNumber = this.tbxEmergencyContactNumber.Text; visitor.VisitorType = this.cbxVisitorType.SelectedItem == null ? string.Empty : this.cbxVisitorType.SelectedItem as String; visitor.IsOnPlant = SearchForm.mIsPlant; if (this.mSchoolingStaff) { visitor.SchoolName = this.cbxSchoolCollege.SelectedItem == null ? string.Empty : this.cbxSchoolCollege.SelectedItem as String; } visitor.VisitorInfo = this.mVisitorInfo; if (this.pbxSnapShot.Image != null) { visitor.Picture = EFERTDbUtility.ImageToByteArray(this.pbxSnapShot.Image); } EFERTDbUtility.mEFERTDb.Visitors.Add(visitor); //EFERTDbUtility.mEFERTDb.SaveChanges(); this.mVisitor = visitor; } BlockedPersonInfo blockedPerson = this.BlockPerson(this.tbxBlockedBy.Text, this.tbxBlockedReason.Text); if (blockedPerson != null) { this.UpdateLayoutForBlockedPerson(blockedPerson); } }
private void UpdateStatus(string cnicNumber, bool isNew = true) { bool blockedUser = false; BlockedPersonInfo blockedPerson = null; if (string.IsNullOrEmpty(cnicNumber)) { this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = false; this.tbxBlockedBy.ReadOnly = true; this.tbxBlockedReason.ReadOnly = true; this.tbxBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxBlockedReason.BackColor = System.Drawing.SystemColors.ButtonFace; this.lblVisitorStatus.Text = "Invalid User"; this.lblVisitorStatus.BackColor = Color.Red; this.btnBlock.Enabled = false; this.btnUnBlock.Enabled = false; this.cbxVFCategory.Enabled = false; return; } if (Form1.mLoggedInUser.IsAdmin) { this.cbxVFCategory.Enabled = true; this.btnBlock.Visible = true; this.btnUnBlock.Visible = true; this.tbxBlockedBy.ReadOnly = false; this.tbxBlockedReason.ReadOnly = false; this.tbxBlockedBy.BackColor = System.Drawing.Color.White; this.tbxBlockedReason.BackColor = System.Drawing.Color.White; } else { if (isNew) { this.cbxVFCategory.Enabled = true; } else { this.cbxVFCategory.Enabled = false; } this.btnBlock.Visible = false; this.btnUnBlock.Visible = false; this.tbxBlockedBy.ReadOnly = true; this.tbxBlockedReason.ReadOnly = true; this.tbxBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxBlockedReason.BackColor = System.Drawing.SystemColors.ButtonFace; } this.mCNICNumber = cnicNumber; if (this.mBlocks.Exists(blocked => blocked.Blocked && blocked.CNICNumber == this.mCNICNumber)) { blockedUser = true; blockedPerson = this.mBlocks.Find(blocked => blocked.Blocked && blocked.CNICNumber == this.mCNICNumber); this.UpdateLayoutForBlockedPerson(blockedPerson); } else { this.btnUnBlock.Enabled = false; this.tbxBlockedBy.Text = string.Empty; this.tbxBlockedReason.Text = string.Empty; this.lblVisitorStatus.Text = "Allowed"; this.lblVisitorStatus.BackColor = Color.Green; this.tbxBlockedBy.ReadOnly = false; this.tbxBlockedReason.ReadOnly = false; this.tbxBlockedBy.BackColor = System.Drawing.Color.White; this.tbxBlockedReason.BackColor = System.Drawing.Color.White; this.tbxUnBlockedBy.ReadOnly = true; this.tbxUnblockReason.ReadOnly = true; this.tbxUnBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxUnblockReason.BackColor = System.Drawing.SystemColors.ButtonFace; if (this.mBlocks.Count > 0) { BlockedPersonInfo lastBlockedInfo = this.mBlocks.Last(); this.tbxUnBlockedBy.Text = lastBlockedInfo.UnBlockedBy; this.tbxUnBlockTime.Text = lastBlockedInfo.UnBlockTime.ToString(); this.tbxUnblockReason.Text = lastBlockedInfo.UnBlockedReason; } } if (this.mCheckIns.Exists(checkedIn => checkedIn.CheckedIn && checkedIn.CNICNumber == this.mCNICNumber)) { CheckInAndOutInfo checkedInInfo = this.mCheckIns.Find(checkedIn => checkedIn.CheckedIn && checkedIn.CNICNumber == this.mCNICNumber); this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = true && !blockedUser; this.tbxCheckInCardNumber.Text = checkedInInfo.CardNumber; this.tbxCheckInVehicleNumber.Text = checkedInInfo.VehicleNmuber; this.nuNoOfMaleGuest.Value = checkedInInfo.NoOfMaleGuest; this.nuNoOfFemaleGuest.Value = checkedInInfo.NoOfFemaleGuest; this.numCheckInDurationOfStay.Value = checkedInInfo.DurationOfStay; this.nuCheckInNoOfChildren.Value = checkedInInfo.NoOfChildren; this.cbxAreaOfVisit.SelectedItem = checkedInInfo.AreaOfVisit; this.tbxCheckInHostName.Text = checkedInInfo.HostName; this.tbxCheckInDateTimeIn.Text = checkedInInfo.DateTimeIn.ToString(); this.tbxCheckInDateTimeOut.Text = DateTime.Now.ToString(); this.tbxCheckInCardNumber.ReadOnly = true; this.tbxCheckInVehicleNumber.ReadOnly = true; this.nuNoOfMaleGuest.ReadOnly = true; this.nuNoOfFemaleGuest.ReadOnly = true; this.numCheckInDurationOfStay.ReadOnly = true; this.nuCheckInNoOfChildren.ReadOnly = true; this.cbxAreaOfVisit.Enabled = false; this.tbxCheckInHostName.ReadOnly = true; this.tbxCheckInCardNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxCheckInVehicleNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.nuNoOfMaleGuest.BackColor = System.Drawing.SystemColors.ButtonFace; this.nuNoOfFemaleGuest.BackColor = System.Drawing.SystemColors.ButtonFace; this.numCheckInDurationOfStay.BackColor = System.Drawing.SystemColors.ButtonFace; this.nuCheckInNoOfChildren.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxCheckInHostName.BackColor = System.Drawing.SystemColors.ButtonFace; } else { if (!blockedUser) { List <CategoryInfo> categories = new List <CategoryInfo>(); bool isCheckLimit = true; if (this.mCheckIns.Count > 0) { string blockinfo = CategoryBlockCriteria.No.ToString(); if (SearchForm.mIsPlant) { categories = (from cat in EFERTDbUtility.mEFERTDb.CategoryInfo where cat != null && cat.CategoryBlockCriteria == blockinfo && (cat.CategoryLocation == CategoryLocation.Plant.ToString() || cat.CategoryLocation == CategoryLocation.Any.ToString()) select cat).ToList(); } else { categories = (from cat in EFERTDbUtility.mEFERTDb.CategoryInfo where cat != null && cat.CategoryBlockCriteria == blockinfo && (cat.CategoryLocation == CategoryLocation.Colony.ToString() || cat.CategoryLocation == CategoryLocation.Any.ToString()) select cat).ToList(); } CheckInAndOutInfo last = this.mCheckIns.Last(); bool catExist = categories.Exists(cat => cat.CategoryName == last.Category); if (catExist) { isCheckLimit = !catExist; } } LimitStatus limitStatus = LimitStatus.Allowed; if (isCheckLimit) { limitStatus = EFERTDbUtility.CheckIfUserCheckedInLimitReached(this.mCheckIns, this.mBlocks); } if (limitStatus == LimitStatus.LimitReached) { blockedPerson = this.BlockPerson(EFERTDbUtility.CONST_SYSTEM_BLOCKED_BY, EFERTDbUtility.CONST_SYSTEM_LIMIT_REACHED_REASON); if (blockedPerson != null) { this.UpdateLayoutForBlockedPerson(blockedPerson); blockedUser = true; } //this.btnCheckIn.Enabled = false; //this.btnCheckOut.Enabled = false; //this.tbxBlockedBy.Text = "Admin"; //this.tbxBlockedReason.Text = "You have reached maximum limit of temporary check in."; //this.lblVisitorStatus.Text = "Blocked"; //this.lblVisitorStatus.BackColor = Color.Red; //this.btnBlock.Enabled = false; //this.tbxBlockedBy.ReadOnly = true; //this.tbxBlockedReason.ReadOnly = true; //this.tbxBlockedBy.BackColor = System.Drawing.SystemColors.ButtonFace; //this.tbxBlockedReason.BackColor = System.Drawing.SystemColors.ButtonFace; } else { if (limitStatus == LimitStatus.EmailAlerted) { if (Form1.mLoggedInUser.IsAdmin) { this.btnDisableAlerts.Visible = true; this.btnDisableAlerts.Tag = true; } } else if (limitStatus == LimitStatus.EmailAlertDisabled) { if (Form1.mLoggedInUser.IsAdmin) { this.btnDisableAlerts.Visible = true; this.btnDisableAlerts.Text = "Enable Alert"; this.btnDisableAlerts.Tag = false; } } this.btnCheckIn.Enabled = true && !blockedUser; this.btnCheckOut.Enabled = false; this.tbxCheckInDateTimeIn.Text = DateTime.Now.ToString(); } } } if (blockedUser) { this.tbxCheckInCardNumber.ReadOnly = true; this.tbxCheckInVehicleNumber.ReadOnly = true; this.tbxCheckInCardNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxCheckInVehicleNumber.BackColor = System.Drawing.SystemColors.ButtonFace; BlockedPersonNotificationForm blockedForm = null; if (blockedPerson == null) { blockedForm = new BlockedPersonNotificationForm(this.mVisitor.FirstName, this.mCNICNumber); } else { blockedForm = new BlockedPersonNotificationForm(blockedPerson); } blockedForm.ShowDialog(this); } }