private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                if (String.IsNullOrEmpty(cardnametb.Text))
                {
                    MessageBox.Show("Please enter card type name");
                }
                else
                {
                    ImusCityHallEntities   db   = new ImusCityHallEntities();
                    IdentificationCardType card = db.IdentificationCardTypes.Find(id);
                    card.CardType = cardnametb.Text;
                    db.SaveChanges();
                    var audit = new AuditTrailModel
                    {
                        Activity   = "Updated an item in identification card list. CARD ID : " + id.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    MessageBox.Show("Card updated successfully!");
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
 private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         ImusCityHallEntities   db   = new ImusCityHallEntities();
         IdentificationCardType card = db.IdentificationCardTypes.Find(id);
         cardnametb.Text = card.CardType;
     }
     else
     {
         MessageBox.Show(SystemClass.DBConnectionErrorMessage);
     }
 }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                if (!String.IsNullOrEmpty(cardnametb.Text))
                {
                    ImusCityHallEntities db = new ImusCityHallEntities();
                    if (db.IdentificationCardTypes.Any(m => m.CardType == cardnametb.Text))
                    {
                        MessageBox.Show("Card name is already used");
                    }
                    else
                    {
                        IdentificationCardType card = new IdentificationCardType();
                        card.CardType  = cardnametb.Text;
                        card.IsActive  = true;
                        card.DateAdded = DateTime.Now;
                        db.IdentificationCardTypes.Add(card);
                        db.SaveChanges();

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Added new identification card type in the database. CARD NAME: " + cardnametb.Text,
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);
                        MessageBox.Show("New type of card inserted in the database");
                    }
                }
                else
                {
                    MessageBox.Show("Please type in the card type name");
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Beispiel #4
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);
            }
        }