private void tbxFirstName_TextChanged(object sender, EventArgs e) { EFERTDbUtility.ValidateInputs(new List <TextBox>() { this.tbxCheckInCardNumber, this.tbxFirstName }); }
private void btnCheckOut_Click(object sender, EventArgs e) { if (this.mCheckIns.Exists(checkedOut => checkedOut.CheckedIn && checkedOut.CNICNumber == this.mCNICNumber)) { CheckInAndOutInfo checkedOutInfo = this.mCheckIns.Find(checkedOut => checkedOut.CheckedIn && checkedOut.CNICNumber == this.mCNICNumber); checkedOutInfo.CheckedIn = false; checkedOutInfo.DateTimeOut = Convert.ToDateTime(this.tbxCheckInDateTimeOut.Text); try { EFERTDbUtility.mEFERTDb.Entry(checkedOutInfo).State = System.Data.Entity.EntityState.Modified; EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in returning card.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return; } this.btnCheckIn.Enabled = true; this.btnCheckOut.Enabled = false; this.Close(); } else { MessageBox.Show(this, "This user is not checked in."); } }
private void btnDelete_Click(object sender, EventArgs e) { try { List <CategoryInfo> inf = (from category in EFERTDbUtility.mEFERTDb.CategoryInfo where category != null select category).ToList(); if (string.IsNullOrEmpty(this.txtId.Text)) { return; } int id = Convert.ToInt32(this.txtId.Text); CategoryInfo catInfo = inf.Find(cat => cat.CategoryId == id); if (catInfo != null) { EFERTDbUtility.mEFERTDb.Entry(catInfo).State = System.Data.Entity.EntityState.Deleted; EFERTDbUtility.mEFERTDb.SaveChanges(); } } catch (Exception ex) { MessageBox.Show(this, "Some error occurred in deleting Cadre.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SplashScreen splash = new SplashScreen(); Task dbInitializerTask = new Task(() => { try { ToggleConnectionStringProtection(System.Windows.Forms.Application.ExecutablePath, true); EFERTDbUtility.InitializeDatabases(); splash.Invoke(new Action(() => { splash.Close(); })); } catch (Exception) { throw; } }); dbInitializerTask.Start(); splash.ShowDialog(); Application.Run(new Form1()); }
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 void btnAdd_Click(object sender, EventArgs e) { List <CategoryInfo> inf = (from category in EFERTDbUtility.mEFERTDb.CategoryInfo where category != null select category).ToList(); string categoryName = this.txtName.Text.Trim(); string blockInfo = this.cbxBlockCriteria.SelectedItem.ToString(); string location = this.cbxLoction.SelectedItem.ToString(); bool alreadyAdded = inf.Exists(cat => cat.CategoryName != null && cat.CategoryName.ToLower() == categoryName.ToLower()); if (!string.IsNullOrEmpty(categoryName) && !alreadyAdded) { try { CategoryInfo catInof = new CategoryInfo() { CategoryName = categoryName, CategoryBlockCriteria = blockInfo, CategoryLocation = location }; EFERTDbUtility.mEFERTDb.CategoryInfo.Add(catInof); EFERTDbUtility.mEFERTDb.SaveChanges(); this.dgvCategoryInfo.DataSource = (from category in EFERTDbUtility.mEFERTDb.CategoryInfo where category != null select category).ToList(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in Adding category.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } } }
private void dgvEmails_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dgvEmails.Rows[e.RowIndex]; if (row == null || (string.IsNullOrEmpty(row.Cells[1].Value as string) && string.IsNullOrEmpty(row.Cells[1].Value as string))) { this.dgvEmails.CancelEdit(); } EmailAddress email = null; string name = row.Cells[1].Value as String ?? string.Empty; string emailAddress = row.Cells[2].Value as String ?? string.Empty; if (row.Tag == null) { email = new EmailAddress() { Name = name, Email = emailAddress }; EFERTDbUtility.mEFERTDb.EmailAddresses.Add(email); } else { email = row.Tag as EmailAddress; email.Name = name; email.Email = emailAddress; EFERTDbUtility.mEFERTDb.Entry(email).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); if (row.Tag == null) { //EFERTDbUtility.mVisitingLocations.Add(cadre); row.Tag = email; } else { //EFERTDbUtility.mVisitingLocations[EFERTDbUtility.mVisitingLocations.IndexOf(cadre)] = cadre; } } catch (Exception ex) { EFERTDbUtility.RollBack(); this.dgvEmails.CancelEdit(); MessageBox.Show(this, "Some error occurred in updating visiting locations.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
private void btnDisableAlerts_Click(object sender, EventArgs e) { bool disableAlert = Convert.ToBoolean(this.btnDisableAlerts.Tag); AlertInfo alertInfo = (from alert in EFERTDbUtility.mEFERTDb.AlertInfos where alert != null && alert.CNICNumber == this.mCNICNumber select alert).FirstOrDefault(); if (alertInfo == null) { alertInfo = new AlertInfo(); alertInfo.CNICNumber = this.mCNICNumber; if (disableAlert) { alertInfo.DisableAlert = true; alertInfo.DisableAlertDate = DateTime.Now; alertInfo.EnableAlertDate = DateTime.MaxValue; } else { alertInfo.DisableAlert = false; alertInfo.EnableAlertDate = DateTime.Now; } EFERTDbUtility.mEFERTDb.AlertInfos.Add(alertInfo); } else { if (disableAlert) { alertInfo.DisableAlert = true; alertInfo.DisableAlertDate = DateTime.Now; } else { alertInfo.DisableAlert = false; alertInfo.EnableAlertDate = DateTime.Now; } EFERTDbUtility.mEFERTDb.Entry(alertInfo).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return; } }
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)); } }
private void dataGridView1_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { try { CadreInfo cadre = e.Row.Tag as CadreInfo; EFERTDbUtility.mEFERTDb.Entry(cadre).State = System.Data.Entity.EntityState.Deleted; EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { MessageBox.Show(this, "Some error occurred in deleting Cadre.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); e.Cancel = true; } }
private void btnUpdate_Click(object sender, EventArgs e) { List <CategoryInfo> inf = (from category in EFERTDbUtility.mEFERTDb.CategoryInfo where category != null select category).ToList(); //category not already exist string categoryName = this.txtName.Text.Trim(); string blockInfo = this.cbxBlockCriteria.SelectedItem.ToString(); string location = this.cbxLoction.SelectedItem.ToString(); if (string.IsNullOrEmpty(this.txtId.Text)) { return; } int id = Convert.ToInt32(this.txtId.Text); CategoryInfo catInfo = inf.Find(cat => cat.CategoryId == id); if (catInfo != null) { if (!string.IsNullOrEmpty(categoryName) && (catInfo.CategoryLocation != location || catInfo.CategoryBlockCriteria != blockInfo || catInfo.CategoryName != categoryName)) { try { catInfo.CategoryName = categoryName; catInfo.CategoryBlockCriteria = blockInfo; catInfo.CategoryLocation = location; EFERTDbUtility.mEFERTDb.Entry(catInfo).State = System.Data.Entity.EntityState.Modified; EFERTDbUtility.mEFERTDb.SaveChanges(); this.dgvCategoryInfo.DataSource = (from category in EFERTDbUtility.mEFERTDb.CategoryInfo where category != null select category).ToList(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in updating category.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } } } }
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); }
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 btnCheckIn_Click(object sender, EventArgs e) { string cardNumber = this.tbxCheckInCardNumber.Text; if (string.IsNullOrEmpty(cardNumber)) { MessageBox.Show(this, "Card number can not be empty."); return; } bool isCardNotReturned = this.mCheckIns.Any(checkInInfo => checkInInfo.CheckedIn && checkInInfo.CardNumber == cardNumber); bool cardExist = false; CCFTCentralDb.CCFTCentral ccftCentralDb = new CCFTCentralDb.CCFTCentral(); cardExist = ccftCentralDb.Cardholders.Any(card => card.LastName == cardNumber); CardHolderInfo cardHolderInfo = this.mCardHolderInfo; if (cardExist && !isCardNotReturned) { var cardAlreadyIssued = (from checkin in EFERTDbUtility.mEFERTDb.CheckedInInfos where checkin != null && checkin.CheckedIn && checkin.CardNumber == cardNumber select new { checkin.CheckedIn, checkin.CNICNumber }).FirstOrDefault(); if (cardAlreadyIssued != null && cardAlreadyIssued.CheckedIn) { MessageBox.Show(this, "This card is already issue to the person with CNIC number: " + cardAlreadyIssued.CNICNumber); return; } if (cardHolderInfo == null) { MessageBox.Show(this, "Unable to Issue Card. Some error occured in getting cardholder information."); return; } CheckInAndOutInfo checkedInInfo = new CheckInAndOutInfo(); checkedInInfo.CheckInToPlant = SearchForm.mIsPlant; checkedInInfo.CheckInToColony = !SearchForm.mIsPlant; checkedInInfo.FirstName = cardHolderInfo.FirstName; checkedInInfo.CardHolderInfos = cardHolderInfo; checkedInInfo.CNICNumber = this.mCNICNumber; checkedInInfo.CardNumber = cardNumber; checkedInInfo.VehicleNmuber = this.tbxCheckInVehicleNumber.Text; checkedInInfo.DateTimeIn = Convert.ToDateTime(this.tbxCheckInDateTimeIn.Text); checkedInInfo.DateTimeOut = DateTime.MaxValue; checkedInInfo.CheckedIn = true; try { EFERTDbUtility.mEFERTDb.CheckedInInfos.Add(checkedInInfo); EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in issuing card.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return; } this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = true; this.Close(); } else { if (!cardExist) { MessageBox.Show(this, "Please enter valid card number."); } else if (isCardNotReturned) { MessageBox.Show(this, "Card is already issued to some one else."); } } }
private void tbxSmtpPort_KeyPress(object sender, KeyPressEventArgs e) { EFERTDbUtility.AllowNumericOnly(e); }
private void dgvColonyLocations_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dgvColonyLocations.Rows[e.RowIndex]; string location = row.Cells[1].Value as string; if (row == null || string.IsNullOrEmpty(location)) { this.dgvColonyLocations.CancelEdit(); return; } if (!string.IsNullOrEmpty(location)) { location = location.Trim().ToLower(); } List <VisitingLocations> visitingLocations = EFERTDbUtility.mEFERTDb.VisitingLocations.ToList(); bool locAlradyExist = visitingLocations.Exists(c => c.Location.Trim().ToLower() == location && !c.IsOnPlant); if (locAlradyExist) { this.dgvColonyLocations.CancelEdit(); return; } VisitingLocations visitingLocation = null; if (row.Tag == null) { visitingLocation = new VisitingLocations() { Location = row.Cells[1].Value as String, IsOnPlant = false }; EFERTDbUtility.mEFERTDb.VisitingLocations.Add(visitingLocation); } else { visitingLocation = row.Tag as VisitingLocations; visitingLocation.Location = row.Cells[1].Value as String; EFERTDbUtility.mEFERTDb.Entry(visitingLocation).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); if (row.Tag == null) { EFERTDbUtility.mVisitingLocations.Add(visitingLocation); row.Tag = visitingLocation; } else { EFERTDbUtility.mVisitingLocations[EFERTDbUtility.mVisitingLocations.IndexOf(visitingLocation)] = visitingLocation; } } catch (Exception ex) { EFERTDbUtility.RollBack(); this.dgvColonyLocations.CancelEdit(); MessageBox.Show(this, "Some error occurred in updating visiting locations.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
//private void dgvPlantLocations_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) //{ // if (e.RowIndex < mLstPlantLocations.Count - 1) // { // this.dgvPlantLocations.Rows[e.RowIndex].Tag = mLstPlantLocations[e.RowIndex]; // } //} //private void dgvColonyLocations_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) //{ // if (e.RowIndex < mLstColonyLocations.Count - 1) // { // this.dgvColonyLocations.Rows[e.RowIndex].Tag = mLstColonyLocations[e.RowIndex]; // } //} //private void dgvPlantLocations_UserAddedRow(object sender, DataGridViewRowEventArgs e) //{ // try // { // string newValue = e.Row.Cells[1].Value as string; // VisitingLocations newLoacation = new VisitingLocations() // { // IsOnPlant = true, // Location = newValue // }; // EFERTDbUtility.mEFERTDb.VisitingLocations.Add(newLoacation); // EFERTDbUtility.mEFERTDb.SaveChanges(); // EFERTDbUtility.mVisitingLocations.Add(newLoacation); // e.Row.Tag = newLoacation; // } // catch (Exception ex) // { // MessageBox.Show(this, "Some error occurred in deleting location.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); // } //} private void dgvPlantLocations_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { try { VisitingLocations visitingLocations = e.Row.Tag as VisitingLocations; EFERTDbUtility.mEFERTDb.Entry(visitingLocations).State = System.Data.Entity.EntityState.Deleted; EFERTDbUtility.mEFERTDb.SaveChanges(); EFERTDbUtility.mVisitingLocations.Remove(visitingLocations); } catch (Exception ex) { MessageBox.Show(this, "Some error occurred in deleting location.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); e.Cancel = true; } }
public VisitorForm(VisitorCardHolder visitorCardHolder) { InitializeComponent(); this.cbxAreaOfVisit.Items.AddRange(EFERTDbUtility.mVisitingLocations.FindAll(location => location.IsOnPlant == SearchForm.mIsPlant).Select(l => l.Location).ToArray()); populateCategoryDropDown(); if (visitorCardHolder != null) { this.mVisitor = visitorCardHolder; this.mVisitorInfo = this.mVisitor.VisitorInfo; this.mCNICNumber = this.mVisitor.CNICNumber; this.cbxVFCategory.SelectedItem = this.mVisitorInfo; if (!string.IsNullOrEmpty(this.cbxVFCategory.SelectedItem.ToString().Trim())) { this.cbxVFCategory.BackColor = System.Drawing.Color.White; } else { this.cbxVFCategory.BackColor = System.Drawing.Color.Yellow; } this.tbxCnicNumber.Text = this.mVisitor.CNICNumber; this.cbxGender.SelectedItem = this.mVisitor.Gender; this.tbxFirstName.Text = this.mVisitor.FirstName; this.tbxLastName.Text = this.mVisitor.LastName; this.tbxAddress.Text = this.mVisitor.Address; this.tbxPostCode.Text = this.mVisitor.PostCode; this.tbxCity.Text = this.mVisitor.City; this.tbxState.Text = this.mVisitor.State; this.tbxCompanyName.Text = this.mVisitor.CompanyName; this.tbxPhoneNumber.Text = this.mVisitor.ContactNo; this.tbxEmergencyContact.Text = this.mVisitor.EmergencyContantPerson; this.tbxEmergencyContactNumber.Text = this.mVisitor.EmergencyContantPersonNumber; this.cbxVisitorType.SelectedItem = this.mVisitor.VisitorType; this.lblSchoolCollege.Visible = false; this.cbxSchoolCollege.Visible = false; if (this.mVisitor.VisitorInfo == "Education") { this.cbxSchoolCollege.SelectedItem = this.mVisitor.SchoolName; this.cbxSchoolCollege.Enabled = false; this.lblSchoolCollege.Visible = true; this.cbxSchoolCollege.Visible = true; this.Text = "Education Staff Form"; this.groupBox1.Text = "Education Staff Details"; this.mSchoolingStaff = true; } else if (this.mVisitor.VisitorInfo == "House Servant") { this.Text = "House Servant Form"; this.groupBox1.Text = "House Servant Details"; } this.mCheckIns = this.mVisitor.CheckInInfos ?? new List <CheckInAndOutInfo>(); this.mBlocks = this.mVisitor.BlockingInfos ?? new List <BlockedPersonInfo>(); this.pbxSnapShot.Image = EFERTDbUtility.ByteArrayToImage(this.mVisitor.Picture); this.btnWebCam.Enabled = false; this.btnBrowse.Enabled = false; this.tbxCnicNumber.ReadOnly = true; this.cbxVisitorType.Enabled = false; this.cbxGender.Enabled = false; this.tbxFirstName.ReadOnly = true; this.tbxLastName.ReadOnly = true; this.tbxAddress.ReadOnly = true; this.tbxPostCode.ReadOnly = true; this.tbxCity.ReadOnly = true; this.tbxState.ReadOnly = true; this.tbxCompanyName.ReadOnly = true; this.tbxPhoneNumber.ReadOnly = true; this.tbxEmergencyContact.ReadOnly = true; this.tbxEmergencyContactNumber.ReadOnly = true; this.tbxCnicNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxFirstName.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxLastName.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxAddress.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxPostCode.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxCity.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxState.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxCompanyName.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxPhoneNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxEmergencyContact.BackColor = System.Drawing.SystemColors.ButtonFace; this.tbxEmergencyContactNumber.BackColor = System.Drawing.SystemColors.ButtonFace; this.btnWebCam.Enabled = false; this.btnBrowse.Enabled = false; } this.UpdateStatus(this.mCNICNumber, false);//false passed to check is new or existing visitor }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dgvDepartments.Rows[e.RowIndex]; string depart = row.Cells[1].Value as string; if (row == null || string.IsNullOrEmpty(depart)) { this.dgvDepartments.CancelEdit(); return; } if (!string.IsNullOrEmpty(depart)) { depart = depart.Trim().ToLower(); } List <DepartmentInfo> departments = EFERTDbUtility.mEFERTDb.Departments.ToList(); bool departAlradyExist = departments.Exists(c => c.DepartmentName.Trim().ToLower() == depart); if (departAlradyExist) { this.dgvDepartments.CancelEdit(); return; } DepartmentInfo department = null; if (row.Tag == null) { department = new DepartmentInfo() { DepartmentName = row.Cells[1].Value as String }; EFERTDbUtility.mEFERTDb.Departments.Add(department); } else { department = row.Tag as DepartmentInfo; department.DepartmentName = row.Cells[1].Value as String; EFERTDbUtility.mEFERTDb.Entry(department).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); if (row.Tag == null) { //EFERTDbUtility.mVisitingLocations.Add(department); row.Tag = department; } else { //EFERTDbUtility.mVisitingLocations[EFERTDbUtility.mVisitingLocations.IndexOf(department)] = department; } } catch (Exception ex) { EFERTDbUtility.RollBack(); this.dgvDepartments.CancelEdit(); MessageBox.Show(this, "Some error occurred in updating visiting locations.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
private void tbxCheckInCardNumber_KeyPress(object sender, KeyPressEventArgs e) { EFERTDbUtility.AllowNumericOnly(e); }
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); } }
private void btnCheckIn_Click(object sender, EventArgs e) { string cardNumber = this.tbxCheckInCardNumber.Text; 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.tbxCheckInCardNumber }); if (validtated && this.cbxVFCategory.SelectedItem == null || string.IsNullOrEmpty(this.cbxVFCategory.SelectedItem.ToString().Trim())) { validtated = false; } if (!validtated) { MessageBox.Show(this, "Please fill mandatory fields first."); return; } bool isCardNotReturned = this.mCheckIns.Any(checkInInfo => checkInInfo.CheckedIn && checkInInfo.CardNumber == cardNumber); CCFTCentralDb.CCFTCentral ccftCentralDb = new CCFTCentralDb.CCFTCentral(); bool cardExist = ccftCentralDb.Cardholders.Any(card => card.LastName == cardNumber); if (cardExist && !isCardNotReturned) { var cardAlreadyIssued = (from checkin in EFERTDbUtility.mEFERTDb.CheckedInInfos where checkin != null && checkin.CheckedIn && checkin.CardNumber == cardNumber select new { checkin.CheckedIn, checkin.CNICNumber }).FirstOrDefault(); if (cardAlreadyIssued != null && cardAlreadyIssued.CheckedIn) { MessageBox.Show(this, "This card is already issue to the person with CNIC number: " + cardAlreadyIssued.CNICNumber); 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.pbxSnapShot.Image != null) { visitor.Picture = EFERTDbUtility.ImageToByteArray(this.pbxSnapShot.Image); } if (this.mSchoolingStaff) { visitor.SchoolName = this.cbxSchoolCollege.SelectedItem == null ? string.Empty : this.cbxSchoolCollege.SelectedItem as String; } visitor.VisitorInfo = this.mVisitorInfo; EFERTDbUtility.mEFERTDb.Visitors.Add(visitor); //EFERTDbUtility.mEFERTDb.SaveChanges(); this.mVisitor = visitor; } CheckInAndOutInfo checkedInInfo = new CheckInAndOutInfo(); checkedInInfo.CheckInToPlant = SearchForm.mIsPlant; checkedInInfo.CheckInToPlant = !SearchForm.mIsPlant; checkedInInfo.FirstName = this.mVisitor.FirstName; checkedInInfo.Visitors = this.mVisitor; checkedInInfo.CNICNumber = this.mCNICNumber; checkedInInfo.CardNumber = this.tbxCheckInCardNumber.Text; checkedInInfo.VehicleNmuber = this.tbxCheckInVehicleNumber.Text; checkedInInfo.NoOfMaleGuest = this.nuNoOfMaleGuest.Value; checkedInInfo.NoOfFemaleGuest = this.nuNoOfFemaleGuest.Value; checkedInInfo.DurationOfStay = this.numCheckInDurationOfStay.Value; checkedInInfo.NoOfChildren = this.nuCheckInNoOfChildren.Value; checkedInInfo.AreaOfVisit = this.cbxAreaOfVisit.SelectedItem == null ? string.Empty : this.cbxAreaOfVisit.SelectedItem as String; checkedInInfo.HostName = this.tbxCheckInHostName.Text; checkedInInfo.DateTimeIn = Convert.ToDateTime(this.tbxCheckInDateTimeIn.Text); checkedInInfo.DateTimeOut = DateTime.MaxValue; checkedInInfo.CheckedIn = true; checkedInInfo.Category = this.mVisitorInfo; try { EFERTDbUtility.mEFERTDb.CheckedInInfos.Add(checkedInInfo); EFERTDbUtility.mEFERTDb.SaveChanges(); } catch (Exception ex) { EFERTDbUtility.RollBack(); MessageBox.Show(this, "Some error occurred in issuing card.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); return; } this.btnCheckIn.Enabled = false; this.btnCheckOut.Enabled = true; this.Close(); } else { if (!cardExist) { MessageBox.Show(this, "Please enter valid card number."); } else if (isCardNotReturned) { MessageBox.Show(this, "Card is already issued to some one else."); } } }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dgvSections.Rows[e.RowIndex]; string sectionVal = row.Cells[1].Value as string; if (row == null || string.IsNullOrEmpty(sectionVal)) { this.dgvSections.CancelEdit(); return; } if (!string.IsNullOrEmpty(sectionVal)) { sectionVal = sectionVal.Trim().ToLower(); } List <SectionInfo> sections = EFERTDbUtility.mEFERTDb.Sections.ToList(); bool secAlradyExist = sections.Exists(c => c.SectionName.Trim().ToLower() == sectionVal); if (secAlradyExist) { this.dgvSections.CancelEdit(); return; } SectionInfo section = null; if (row.Tag == null) { section = new SectionInfo() { SectionName = row.Cells[1].Value as String }; EFERTDbUtility.mEFERTDb.Sections.Add(section); } else { section = row.Tag as SectionInfo; section.SectionName = row.Cells[1].Value as String; EFERTDbUtility.mEFERTDb.Entry(section).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); if (row.Tag == null) { //EFERTDbUtility.mVisitingLocations.Add(Section); row.Tag = section; } else { //EFERTDbUtility.mVisitingLocations[EFERTDbUtility.mVisitingLocations.IndexOf(Section)] = Section; } } catch (Exception ex) { EFERTDbUtility.RollBack(); this.dgvSections.CancelEdit(); MessageBox.Show(this, "Some error occurred in updating visiting locations.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
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 dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataGridViewRow row = this.dgvCadres.Rows[e.RowIndex]; string caderVal = row.Cells[1].Value as String; if (row == null || string.IsNullOrEmpty(caderVal)) { this.dgvCadres.CancelEdit(); return; } else { string str = caderVal.Replace(" ", String.Empty); if (string.IsNullOrEmpty(str)) { this.dgvCadres.CancelEdit(); return; } } if (!string.IsNullOrEmpty(caderVal)) { caderVal = caderVal.Trim().ToLower(); } List <CadreInfo> caders = EFERTDbUtility.mEFERTDb.Cadres.ToList(); bool caderAlradyExist = caders.Exists(c => c.CadreName.Trim().ToLower() == caderVal); if (caderAlradyExist) { this.dgvCadres.CancelEdit(); return; } CadreInfo cadre = null; if (row.Tag == null) { cadre = new CadreInfo() { CadreName = row.Cells[1].Value as String }; EFERTDbUtility.mEFERTDb.Cadres.Add(cadre); } else { cadre = row.Tag as CadreInfo; cadre.CadreName = row.Cells[1].Value as String; EFERTDbUtility.mEFERTDb.Entry(cadre).State = System.Data.Entity.EntityState.Modified; } try { EFERTDbUtility.mEFERTDb.SaveChanges(); if (row.Tag == null) { //EFERTDbUtility.mVisitingLocations.Add(cadre); row.Tag = cadre; } else { //EFERTDbUtility.mVisitingLocations[EFERTDbUtility.mVisitingLocations.IndexOf(cadre)] = cadre; } } catch (Exception ex) { EFERTDbUtility.RollBack(); this.dgvCadres.CancelEdit(); MessageBox.Show(this, "Some error occurred in updating visiting locations.\n\n" + EFERTDbUtility.GetInnerExceptionMessage(ex)); } }
private void SearchCardHolderCore(string searchString, bool isNicNumber, bool isTempCard = false, bool isVisitorCard = false) { EFERTDbUtility.InitializeDatabases(false); CCFTCentral ccftCentral = EFERTDbUtility.mCCFTCentral; Cardholder cardHolder = null; CardHolderInfo cardHolderInfo = null; VisitorCardHolder visitor = null; DailyCardHolder dailyCardHolder = null; bool updatedCardExist = true; if (isNicNumber) { Task <Cardholder> cardHolderByNicTask = new Task <Cardholder>(() => { Cardholder cardHolderByNic = (from pds in ccftCentral.PersonalDataStrings where pds != null && pds.PersonalDataFieldID == 5051 && pds.Value != null && pds.Value == searchString select pds.Cardholder).FirstOrDefault(); return(cardHolderByNic); }); cardHolderByNicTask.Start(); cardHolderInfo = (from card in EFERTDbUtility.mEFERTDb.CardHolders where card != null && card.CNICNumber == searchString select card).FirstOrDefault(); if (cardHolderInfo == null) { cardHolder = cardHolderByNicTask.Result; if (cardHolder == null) { dailyCardHolder = (from daily in EFERTDbUtility.mEFERTDb.DailyCardHolders where daily != null && daily.CNICNumber == searchString select daily).FirstOrDefault(); if (dailyCardHolder == null) { visitor = (from visit in EFERTDbUtility.mEFERTDb.Visitors where visit != null && visit.CNICNumber == searchString select visit).FirstOrDefault(); } } } else { if (cardHolderInfo.IsTemp) { cardHolder = cardHolderByNicTask.Result; if (cardHolder == null) { updatedCardExist = false; } } } } else { Task <Cardholder> cardHolderByCardNumberTask = new Task <Cardholder>(() => { Cardholder cardHolderByCardNumber = (from c in ccftCentral.Cardholders where c != null && c.LastName == searchString select c).FirstOrDefault(); return(cardHolderByCardNumber); }); cardHolderByCardNumberTask.Start(); cardHolderInfo = (from card in EFERTDbUtility.mEFERTDb.CardHolders where card != null && card.CardNumber == searchString select card).FirstOrDefault(); if (cardHolderInfo == null) { CheckInAndOutInfo cardIssued = (from checkIn in EFERTDbUtility.mEFERTDb.CheckedInInfos where checkIn != null && checkIn.CheckedIn && checkIn.CardNumber == searchString select checkIn).FirstOrDefault(); if (cardIssued != null) { dailyCardHolder = cardIssued.DailyCardHolders; if (dailyCardHolder == null) { visitor = cardIssued.Visitors; if (visitor == null) { cardHolderInfo = cardIssued.CardHolderInfos; if (cardHolderInfo != null && cardHolderInfo.IsTemp) { cardHolder = (from pds in ccftCentral.PersonalDataStrings where pds != null && pds.PersonalDataFieldID == 5051 && pds.Value != null && pds.Value == cardIssued.CNICNumber select pds.Cardholder).FirstOrDefault(); if (cardHolder != null) { updatedCardExist = true; } else { updatedCardExist = false; } } } } } if (visitor == null && dailyCardHolder == null && cardHolderInfo == null) { if (!isTempCard && !isVisitorCard) { cardHolder = cardHolderByCardNumberTask.Result; } } if (visitor == null && dailyCardHolder == null && cardHolder == null && cardHolderInfo == null) { if (Form.ActiveForm != null) { bool found = false; if (Form.ActiveForm is VisitorForm) { found = true; (Form.ActiveForm as VisitorForm).SetCardNumber(searchString); } else if (Form.ActiveForm is PermanentChForm) { found = true; (Form.ActiveForm as PermanentChForm).SetCardNumber(searchString); } else if (Form.ActiveForm is ContractorChForm) { found = true; (Form.ActiveForm as ContractorChForm).SetCardNumber(searchString); } if (found) { return; } } if (isTempCard) { MessageBox.Show(this, "This temporary card is not issued to any person."); } else if (isVisitorCard) { MessageBox.Show(this, "This visitor card is not issued to any visitor."); } else { MessageBox.Show(this, "Cardholder with " + searchString + " card number is not found."); } return; } } //else //{ // if (!cardHolderInfo.GallagherCardHolder) // { // cardHolder = cardHolderByNicTask.Result; // if (cardHolder == null) // { // updatedCardExist = false; // } // } //} //bool isDigitOnly = this.IsDigitsOnly(searchString); //if (isDigitOnly) //{ //cardHolder = (from c in ccftCentral.Cardholders // where c != null && c.LastName == searchString // select c).FirstOrDefault(); //} //else //{ // cardHolder = (from c in ccftCentral.Cardholders // where c != null && c.FirstName == searchString // select c).FirstOrDefault(); //} } if (cardHolder == null && cardHolderInfo == null && visitor == null && dailyCardHolder == null) { ContractorChForm npchf = new ContractorChForm(searchString); npchf.ShowDialog(this); } else { if (cardHolderInfo != null && !cardHolderInfo.IsTemp) { string cadre = cardHolderInfo.Cadre == null ? "" : cardHolderInfo.Cadre.CadreName; bool isPermanent = cadre.ToLower() == "nmpt" || cadre.ToLower() == "mpt"; if (isPermanent) { PermanentChForm permanentForm = new PermanentChForm(cardHolderInfo); permanentForm.Show(); } else { ContractorChForm contractorForm = new ContractorChForm(cardHolderInfo); contractorForm.Show(); } } else if (cardHolder != null) { Dictionary <int, string> chPds = new Dictionary <int, string>(); foreach (PersonalDataString pds in cardHolder.PersonalDataStrings) { if (pds != null) { chPds.Add(pds.PersonalDataFieldID, pds.Value); } } string cadre = (from c in chPds where c.Key == 12952 && c.Value != null select c.Value).FirstOrDefault(); if (string.IsNullOrEmpty(cadre)) { MessageBox.Show(this, "No Cadre found."); } else { bool isPermanent = cadre.ToLower() == "nmpt" || cadre.ToLower() == "mpt"; if (isPermanent) { int? pNumber = cardHolder.PersonalDataIntegers == null || cardHolder.PersonalDataIntegers.Count == 0 ? null : cardHolder.PersonalDataIntegers.ElementAt(0).Value; string strPNumber = pNumber == null ? "P-Number not found." : pNumber.ToString(); DateTime?dateOfBirth = cardHolder.PersonalDataDates == null || cardHolder.PersonalDataDates.Count == 0 ? null : cardHolder.PersonalDataDates.ElementAt(0).Value; string strDOB = dateOfBirth == null ? "Date of birth not found." : dateOfBirth.ToString(); string bloodGroup = chPds.ContainsKey(5047) && chPds[5047] != null ? chPds[5047] : string.Empty; string CNICNumber = chPds.ContainsKey(5051) && chPds[5051] != null ? chPds[5051] : string.Empty; string crew = chPds.ContainsKey(12869) && chPds[12869] != null ? chPds[12869] : string.Empty; string department = chPds.ContainsKey(5043) && chPds[5043] != null ? chPds[5043] : string.Empty; string designation = chPds.ContainsKey(5042) && chPds[5042] != null ? chPds[5042] : string.Empty; string contactNumber = chPds.ContainsKey(5053) && chPds[5053] != null ? chPds[5053] : string.Empty; string section = chPds.ContainsKey(12951) && chPds[12951] != null ? chPds[12951] : string.Empty; int cardHolderId = cardHolder.FTItemID; string companyName = chPds.ContainsKey(5059) && chPds[5059] != null ? chPds[5059] : string.Empty; CadreInfo cadreInfo = (from c in EFERTDbUtility.mEFERTDb.Cadres where c != null && c.CadreName == cadre select c).FirstOrDefault() ?? new CadreInfo() { CadreName = cadre }; CrewInfo crewInfo = string.IsNullOrEmpty(crew) ? null : ((from c in EFERTDbUtility.mEFERTDb.Crews where c != null && c.CrewName == crew select c).FirstOrDefault() ?? new CrewInfo() { CrewName = crew }); DepartmentInfo departmentInfo = string.IsNullOrEmpty(department) ? null : ((from c in EFERTDbUtility.mEFERTDb.Departments where c != null && c.DepartmentName == department select c).FirstOrDefault() ?? new DepartmentInfo() { DepartmentName = department }); DesignationInfo designationInfo = string.IsNullOrEmpty(designation) ? null : ((from c in EFERTDbUtility.mEFERTDb.Designations where c != null && c.Designation == designation select c).FirstOrDefault() ?? new DesignationInfo() { Designation = designation }); SectionInfo sectionInfo = string.IsNullOrEmpty(section) ? null : ((from c in EFERTDbUtility.mEFERTDb.Sections where c != null && c.SectionName == section select c).FirstOrDefault() ?? new SectionInfo() { SectionName = section }); CompanyInfo companyInfo = string.IsNullOrEmpty(companyName) ? null : ((from c in EFERTDbUtility.mEFERTDb.Companies where c != null && c.CompanyName == companyName select c).FirstOrDefault() ?? new CompanyInfo() { CompanyName = companyName }); if (cardHolderInfo != null && cardHolderInfo.IsTemp) { cardHolderInfo.FTItemId = cardHolderId; cardHolderInfo.FirstName = cardHolder.FirstName; cardHolderInfo.LastName = cardHolder.LastName; cardHolderInfo.BloodGroup = string.IsNullOrEmpty(bloodGroup) ? null : bloodGroup; cardHolderInfo.CardNumber = cardHolder.LastName; cardHolderInfo.CNICNumber = string.IsNullOrEmpty(CNICNumber) ? null : CNICNumber; cardHolderInfo.EmergancyContactNumber = string.IsNullOrEmpty(contactNumber) ? null : contactNumber; cardHolderInfo.PNumber = pNumber == null ? null : pNumber.ToString(); cardHolderInfo.DateOfBirth = dateOfBirth == null ? null : dateOfBirth.ToString(); cardHolderInfo.IsTemp = false; setCarholderInfo(cardHolderInfo, departmentInfo, cadreInfo, crewInfo, designationInfo, sectionInfo, companyInfo); EFERTDbUtility.mEFERTDb.Entry(cardHolderInfo).State = System.Data.Entity.EntityState.Modified; } else { cardHolderInfo = new CardHolderInfo() { FTItemId = cardHolderId, FirstName = cardHolder.FirstName, LastName = cardHolder.LastName, BloodGroup = string.IsNullOrEmpty(bloodGroup) ? null : bloodGroup, CardNumber = cardHolder.LastName, CNICNumber = string.IsNullOrEmpty(CNICNumber) ? null : CNICNumber, EmergancyContactNumber = string.IsNullOrEmpty(contactNumber) ? null : contactNumber, PNumber = pNumber == null ? null : pNumber.ToString(), DateOfBirth = dateOfBirth == null ? null : dateOfBirth.ToString(), IsTemp = false }; setCarholderInfo(cardHolderInfo, departmentInfo, cadreInfo, crewInfo, designationInfo, sectionInfo, companyInfo); EFERTDbUtility.mEFERTDb.CardHolders.Add(cardHolderInfo); } EFERTDbUtility.mEFERTDb.SaveChanges(); PermanentChForm permanentForm = new PermanentChForm(cardHolderInfo); permanentForm.Show(); } else { string companyName = chPds.ContainsKey(5059) && chPds[5059] != null ? chPds[5059] : string.Empty; string CNICNumber = chPds.ContainsKey(5051) && chPds[5051] != null ? chPds[5051] : string.Empty; string department = chPds.ContainsKey(5043) && chPds[5043] != null ? chPds[5043] : string.Empty; string designation = chPds.ContainsKey(5042) && chPds[5042] != null ? chPds[5042] : string.Empty; string emergancyContactNumber = chPds.ContainsKey(5053) && chPds[5053] != null ? chPds[5053] : string.Empty; string section = chPds.ContainsKey(12951) && chPds[12951] != null ? chPds[12951] : string.Empty; string wONumber = chPds.ContainsKey(5344) && chPds[5344] != null ? chPds[5344] : string.Empty; int cardHolderId = cardHolder.FTItemID; CadreInfo cadreInfo = (from c in EFERTDbUtility.mEFERTDb.Cadres where c != null && c.CadreName == cadre select c).FirstOrDefault() ?? new CadreInfo() { CadreName = cadre }; CrewInfo crewInfo = null; DepartmentInfo departmentInfo = string.IsNullOrEmpty(department) ? null : ((from c in EFERTDbUtility.mEFERTDb.Departments where c != null && c.DepartmentName == department select c).FirstOrDefault() ?? new DepartmentInfo() { DepartmentName = department }); DesignationInfo designationInfo = string.IsNullOrEmpty(designation) ? null : ((from c in EFERTDbUtility.mEFERTDb.Designations where c != null && c.Designation == designation select c).FirstOrDefault() ?? new DesignationInfo() { Designation = designation }); SectionInfo sectionInfo = string.IsNullOrEmpty(section) ? null : ((from c in EFERTDbUtility.mEFERTDb.Sections where c != null && c.SectionName == section select c).FirstOrDefault() ?? new SectionInfo() { SectionName = section }); CompanyInfo companyInfo = string.IsNullOrEmpty(companyName) ? null : ((from c in EFERTDbUtility.mEFERTDb.Companies where c != null && c.CompanyName == companyName select c).FirstOrDefault() ?? new CompanyInfo() { CompanyName = companyName }); if (cardHolderInfo != null && cardHolderInfo.IsTemp) { cardHolderInfo.FTItemId = cardHolderId; cardHolderInfo.FirstName = cardHolder.FirstName; cardHolderInfo.LastName = cardHolder.LastName; cardHolderInfo.CardNumber = cardHolder.LastName; cardHolderInfo.CNICNumber = string.IsNullOrEmpty(CNICNumber) ? null : CNICNumber; cardHolderInfo.EmergancyContactNumber = string.IsNullOrEmpty(emergancyContactNumber) ? null : emergancyContactNumber; cardHolderInfo.WONumber = string.IsNullOrEmpty(wONumber) ? null : wONumber; cardHolderInfo.IsTemp = false; setCarholderInfo(cardHolderInfo, departmentInfo, cadreInfo, crewInfo, designationInfo, sectionInfo, companyInfo); EFERTDbUtility.mEFERTDb.Entry(cardHolderInfo).State = System.Data.Entity.EntityState.Modified; } else { cardHolderInfo = new CardHolderInfo() { FTItemId = cardHolderId, FirstName = cardHolder.FirstName, LastName = cardHolder.LastName, CardNumber = cardHolder.LastName, CNICNumber = string.IsNullOrEmpty(CNICNumber) ? null : CNICNumber, EmergancyContactNumber = string.IsNullOrEmpty(emergancyContactNumber) ? null : emergancyContactNumber, WONumber = string.IsNullOrEmpty(wONumber) ? null : wONumber, IsTemp = false }; setCarholderInfo(cardHolderInfo, departmentInfo, cadreInfo, crewInfo, designationInfo, sectionInfo, companyInfo); EFERTDbUtility.mEFERTDb.CardHolders.Add(cardHolderInfo); } EFERTDbUtility.mEFERTDb.SaveChanges(); ContractorChForm contractorForm = new ContractorChForm(cardHolderInfo); contractorForm.Show(); } } } else if (!updatedCardExist) { ContractorChForm contractorForm = new ContractorChForm(cardHolderInfo, true); contractorForm.Show(); } else if (visitor != null) { VisitorForm vistorForm = new VisitorForm(visitor); vistorForm.Show(); } else if (dailyCardHolder != null) { ContractorChForm contractorForm = new ContractorChForm(dailyCardHolder); contractorForm.Show(); } } }