Esempio n. 1
0
        private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                ImusCityGovernmentSystem.Model.Customer customer = db.Customers.Find(id);
                this.Title = string.Join(" ", customer.FirstName, customer.LastName, "Transactions");
                List <CustomerTransactionsEntity> transactionlist = new List <CustomerTransactionsEntity>();
                var result = db.GetCustomerTransactions(id);
                foreach (var item in result)
                {
                    var transaction = new CustomerTransactionsEntity
                    {
                        Activity        = item.Activity,
                        TransactionDate = item.TransactionDate.Value.ToShortDateString()
                    };

                    transactionlist.Add(transaction);
                }
                customernamelbl.Content           = string.Join(" ", customer.FirstName, customer.LastName);
                customerTransactiondg.ItemsSource = transactionlist;
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
 private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         ImusCityHallEntities db = new ImusCityHallEntities();
         ImusCityGovernmentSystem.Model.Customer customer = db.Customers.Find(id);
         firstnametb.Text    = customer.FirstName;
         middlenamebt.Text   = customer.MiddleName;
         lastnametb.Text     = customer.LastName;
         bdaydp.SelectedDate = customer.Birthdate;
         compaddresstb.Text  = customer.CompleteAddress;
         LoadIdentificationCards(customer.CustomerID);
     }
     else
     {
         MessageBox.Show(SystemClass.DBConnectionErrorMessage);
     }
 }
Esempio n. 4
0
 private void deletebtn_Click(object sender, RoutedEventArgs e)
 {
     if (customerdg.SelectedValue == null)
     {
         MessageBox.Show("Please select a customer from the list");
     }
     else
     {
         if (SystemClass.CheckConnection())
         {
             int id = (int)customerdg.SelectedValue;
             ImusCityHallEntities db = new ImusCityHallEntities();
             ImusCityGovernmentSystem.Model.Customer customer = db.Customers.Find(id);
             customer.IsActive = false;
             db.SaveChanges();
             MessageBox.Show("Customer removed");
             LoadCustomer(searchtb.Text);
         }
         else
         {
             MessageBox.Show(SystemClass.DBConnectionErrorMessage);
         }
     }
 }
Esempio n. 5
0
        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);
            }
        }