private void idtypecb_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (SystemClass.CheckConnection()) { ImusCityHallEntities db = new ImusCityHallEntities(); if (idtypecb.SelectedValue == null) { return; } int cardId = (int)idtypecb.SelectedValue; CustomerIdentificationCard custCard = db.CustomerIdentificationCards.FirstOrDefault(m => m.CustomerID == customerId && m.IdentificationCardTypeID == cardId); if (custCard == null) { idcardnumbertb.Text = string.Empty; } else { idcardnumbertb.Text = custCard.IdentificationNumber; } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }
public void LoadCustomer(int id) { if (SystemClass.CheckConnection()) { ImusCityHallEntities db = new ImusCityHallEntities(); ImusCityGovernmentSystem.Model.Customer customer = db.Customers.Find(id); firstnametb.Text = customer.FirstName; middlenametb.Text = customer.MiddleName; lastnametb.Text = customer.LastName; birthdatedp.SelectedDate = customer.Birthdate; completeaddresstb.Text = customer.CompleteAddress; if (db.CheckReleases.Any(m => m.CustomerID == customer.CustomerID)) { CheckRelease releasedCheck = db.CheckReleases.Where(m => m.CustomerID == customer.CustomerID).OrderByDescending(m => m.CheckReleaseID).FirstOrDefault(); CustomerIdentificationCard customerCard = db.CustomerIdentificationCards.FirstOrDefault(m => m.IdentificationCardTypeID == releasedCheck.IdentificationCardTypeID && m.CustomerID == customer.CustomerID && m.IdentificationCardType.IsActive == true); if (customerCard != null) { idtypecb.SelectedValue = customerCard.IdentificationCardTypeID; idcardnumbertb.Text = customerCard.IdentificationNumber; } else { idtypecb.SelectedValue = releasedCheck.IdentificationCardTypeID; idcardnumbertb.Text = releasedCheck.IdentificationCardNumber; } } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }
public void SaveCheckReleased(int Id, int checkId) { if (SystemClass.CheckConnection()) { ImusCityHallEntities db = new ImusCityHallEntities(); ImusCityGovernmentSystem.Model.CheckRelease released = new CheckRelease(); released.CustomerID = Id; released.ReleasedDate = DateTime.Now; released.CheckID = checkId; released.Photo = ConvertImageSourceToByte(imagecapture); released.DigitalSignature = ConvertImageSourceToByte(digitalsignatureimg); released.ReleasedBy = App.EmployeeID; released.IdentificationCardNumber = idcardnumbertb.Text; released.IdentificationCardTypeID = (int)idtypecb.SelectedValue; db.CheckReleases.Add(released); ImusCityGovernmentSystem.Model.Check check = db.Checks.Find(checkId); check.Status = (int)CheckStatus.Released; int cardId = (int)idtypecb.SelectedValue; CustomerIdentificationCard customerCard = db.CustomerIdentificationCards.FirstOrDefault(m => m.IdentificationCardTypeID == cardId && m.CustomerID == Id && m.IdentificationCardType.IsActive == true); if (customerCard != null) { customerCard.IdentificationNumber = idcardnumbertb.Text; db.SaveChanges(); } else { CustomerIdentificationCard custCard = new CustomerIdentificationCard(); custCard.CustomerID = Id; custCard.IdentificationCardTypeID = (int)idtypecb.SelectedValue; custCard.IdentificationNumber = idcardnumbertb.Text; db.CustomerIdentificationCards.Add(custCard); } db.SaveChanges(); MessageBox.Show("Check has been successfully released"); LoadIdentificationCardType(); var audit = new AuditTrailModel { Activity = "Released check to CUSTOMER ID: " + released.CustomerID.ToString() + " with CHECK NUMBER: " + released.Check.CheckNo, ModuleName = this.GetType().Name, EmployeeID = App.EmployeeID }; SystemClass.InsertLog(audit); ResetFields(); } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }
public void CreateCustomer() { if (SystemClass.CheckConnection()) { if (idtypecb.SelectedValue == null || String.IsNullOrEmpty(idcardnumbertb.Text)) { MessageBox.Show("Please select identification card presented and id number"); } else { ImusCityHallEntities db = new ImusCityHallEntities(); ImusCityGovernmentSystem.Model.Customer customer = new Customer(); customer.FirstName = firstnametb.Text; customer.MiddleName = middlenametb.Text; customer.LastName = lastnametb.Text; customer.DateAdded = DateTime.Now; customer.AddedBy = App.EmployeeID; customer.Birthdate = birthdatedp.SelectedDate; customer.CompleteAddress = completeaddresstb.Text; customer.IsActive = true; db.Customers.Add(customer); CustomerIdentificationCard custCard = new CustomerIdentificationCard(); custCard.CustomerID = customer.CustomerID; custCard.IdentificationCardTypeID = (int)idtypecb.SelectedValue; custCard.IdentificationNumber = idcardnumbertb.Text; db.CustomerIdentificationCards.Add(custCard); db.SaveChanges(); MessageBox.Show("Data is saved. Please click the save button to continue the transaction"); customerId = customer.CustomerID; var audit = new AuditTrailModel { Activity = "Adde new customer in the database CUSTOMER NAME: " + string.Join(" ", customer.FirstName, customer.MiddleName, customer.LastName), ModuleName = this.GetType().Name, EmployeeID = App.EmployeeID }; SystemClass.InsertLog(audit); } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }
private void savebtn_Click(object sender, RoutedEventArgs e) { if (SystemClass.CheckConnection()) { if (String.IsNullOrEmpty(firstnametb.Text)) { MessageBox.Show("Please enter firs name"); } else if (String.IsNullOrEmpty(lastnametb.Text)) { MessageBox.Show("Please enter last name"); } else if (String.IsNullOrEmpty(bdaydp.Text)) { MessageBox.Show("Please enter birthdate"); } else if (String.IsNullOrEmpty(compaddresstb.Text)) { MessageBox.Show("Please enter complete address"); } else { ImusCityHallEntities db = new ImusCityHallEntities(); ImusCityGovernmentSystem.Model.Customer customer = db.Customers.Find(id); customer.FirstName = firstnametb.Text; customer.MiddleName = string.IsNullOrEmpty(middlenamebt.Text) ? null : middlenamebt.Text; customer.LastName = lastnametb.Text; customer.DateAdded = DateTime.Now; customer.AddedBy = App.EmployeeID; customer.CompleteAddress = compaddresstb.Text; customer.Birthdate = bdaydp.SelectedDate; customer.IsActive = true; foreach (var list in gd.Where(m => m.IsSelected == true)) { if (db.CustomerIdentificationCards.Any(m => m.CustomerID == customer.CustomerID && m.IdentificationCardTypeID == list.Id)) { CustomerIdentificationCard custCard = db.CustomerIdentificationCards.FirstOrDefault(m => m.CustomerID == customer.CustomerID && m.IdentificationCardTypeID == list.Id); custCard.IdentificationNumber = list.CardNumber; db.SaveChanges(); } else { CustomerIdentificationCard custCard = new CustomerIdentificationCard(); IdentificationCardType card = db.IdentificationCardTypes.Find(list.Id); custCard.CustomerID = customer.CustomerID; custCard.IdentificationCardTypeID = list.Id; custCard.IdentificationNumber = list.CardNumber; db.CustomerIdentificationCards.Add(custCard); db.SaveChanges(); } } foreach (var list in gd.Where(m => m.IsSelected == false)) { if (db.CustomerIdentificationCards.Any(m => m.CustomerID == customer.CustomerID && m.IdentificationCardTypeID == list.Id)) { CustomerIdentificationCard custCard = db.CustomerIdentificationCards.FirstOrDefault(m => m.CustomerID == customer.CustomerID && m.IdentificationCardTypeID == list.Id); db.CustomerIdentificationCards.Remove(custCard); db.SaveChanges(); } } db.SaveChanges(); MessageBox.Show("Customer updated"); var audit = new AuditTrailModel { Activity = "Updated customer in the database. CUSTOMER ID: " + id.ToString(), ModuleName = this.GetType().Name, EmployeeID = App.EmployeeID }; SystemClass.InsertLog(audit); } } else { MessageBox.Show(SystemClass.DBConnectionErrorMessage); } }