public void PositionUpdate()
        {
            if (SystemClass.CheckConnection())
            {
                try
                {
                    using (var db = new ImusCityHallEntities())
                    {
                        var find = db.EmployeePositions.Find(PositionID);
                        find.EmployeePositionName = txtName.Text;
                        find.Description          = txtDesc.Text;
                        find.EmployeeRankID       = Convert.ToInt32(cbRank.SelectedValue);

                        if (chkActive.IsChecked == true)
                        {
                            find.Active = true;
                        }
                        else
                        {
                            find.Active = false;
                        }
                        db.SaveChanges();

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Updated an item in employee position list. POS ID: " + PositionID.ToString(),
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);
                        MessageBox.Show("Position updated successfully", "System Success!", MessageBoxButton.OK, MessageBoxImage.Information);
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong." + Environment.NewLine + ex.Message, "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Пример #2
0
 private void savebtn_Click(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         ImusCityHallEntities db = new ImusCityHallEntities();
         int result;
         if (int.TryParse(checknumbertb.Text, out result))
         {
             string formatted = result.ToString("D10");
             if (db.Checks.Where(m => m.Disbursement.FundBankID == fundBankId && m.CheckNo == formatted).Count() >= 1)
             {
                 MessageBox.Show("The check number that you are trying to add with the corresponding fund is already used");
             }
             else if (db.DamageChecks.Where(m => m.FundBankID == fundBankId && m.CheckNumber == formatted).Count() >= 1)
             {
                 MessageBox.Show("The check number that you are trying to add with the corresponding fund is already in the list of damaged check");
             }
             else if (String.IsNullOrEmpty(checknumbertb.Text))
             {
                 MessageBox.Show("Please input check number");
             }
             else
             {
                 DamageCheck damageCheck = new DamageCheck();
                 damageCheck.FundBankID  = fundBankId;
                 damageCheck.CheckNumber = formatted;
                 damageCheck.CreatedDate = DateTime.Now;
                 damageCheck.CreatedBy   = App.EmployeeID;
                 db.DamageChecks.Add(damageCheck);
                 db.SaveChanges();
                 MessageBox.Show("Damage check entry added successfuly");
                 checknumbertb.Clear();
             }
         }
         else
         {
             MessageBox.Show("Please input numbers only");
         }
     }
     else
     {
         MessageBox.Show(SystemClass.DBConnectionErrorMessage);
     }
 }
        public void RankAdd()
        {
            if (SystemClass.CheckConnection())
            {
                try
                {
                    using (var db = new ImusCityHallEntities())
                    {
                        if (!String.IsNullOrEmpty(txtName.Text))
                        {
                            Model.EmployeeRank er = new Model.EmployeeRank();
                            er.EmployeeRankName = txtName.Text;
                            er.RankCode         = txtCode.Text;
                            db.EmployeeRanks.Add(er);
                            db.SaveChanges();

                            var audit = new AuditTrailModel
                            {
                                Activity   = "Added new employee rank in the database. RANK NAME: " + txtName.Text,
                                ModuleName = this.GetType().Name,
                                EmployeeID = App.EmployeeID
                            };

                            SystemClass.InsertLog(audit);

                            MessageBox.Show("Rank added successfully", "System Success!", MessageBoxButton.OK, MessageBoxImage.Information);
                            TextClear();
                        }
                        else
                        {
                            MessageBox.Show("Fill up necessary fields.", "System Information!", MessageBoxButton.OK, MessageBoxImage.Information);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong." + Environment.NewLine + ex.Message, "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                int      id             = (int)accountslistlb.SelectedValue;
                FundBank account        = db.FundBanks.Find(id);
                account.FundID        = (int)fundcb.SelectedValue;
                account.BankID        = (int)bankcb.SelectedValue;
                account.AccountNumber = accountnumbertb.Text;
                account.AmountLimit   = Convert.ToDecimal(flooramounttb.Text);
                db.SaveChanges();

                var audit = new AuditTrailModel
                {
                    Activity   = "Updated bank account in the database. FUND BANK ID: " + id.ToString(),
                    ModuleName = this.GetType().Name,
                    EmployeeID = App.EmployeeID
                };

                SystemClass.InsertLog(audit);
                MessageBox.Show("Account updated succesfully");

                fundcb.IsEnabled          = false;
                bankcb.IsEnabled          = false;
                accountnumbertb.IsEnabled = false;
                flooramounttb.IsEnabled   = false;
                savebtn.IsEnabled         = false;
                editbtn.IsEnabled         = true;


                db = new ImusCityHallEntities();
                accountslistlb.ItemsSource       = db.FundBanks.Where(m => m.IsActive == true).OrderByDescending(m => m.FundBankID).ToList();
                accountslistlb.DisplayMemberPath = "AccountNumber";
                accountslistlb.SelectedValuePath = "FundBankID";
                accountslistlb.SelectedValue     = id;
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            if (SystemClass.CheckConnection())
            {
                if (String.IsNullOrEmpty(bankcodetb.Text) || String.IsNullOrEmpty(banknametb.Text))
                {
                    MessageBox.Show("Please input bank code and bank name!");
                }
                else if (String.IsNullOrEmpty(branchtb.Text))
                {
                    MessageBox.Show("Please enter branch name");
                }
                else
                {
                    ImusCityHallEntities db = new ImusCityHallEntities();
                    ImusCityGovernmentSystem.Model.Bank bank = db.Banks.Find(BankID);
                    bank.BankCode = bankcodetb.Text;
                    bank.BankName = banknametb.Text;
                    bank.Branch   = branchtb.Text;
                    db.SaveChanges();
                    Mouse.OverrideCursor = null;
                    var audit = new AuditTrailModel
                    {
                        Activity   = "Updated an item in bank list. BANK ID: " + BankID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    MessageBox.Show("Bank updated successfully!");
                }
            }
            else
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }

            Mouse.OverrideCursor = null;
        }
        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);
            }
        }
Пример #7
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            if (SystemClass.CheckConnection())
            {
                if (String.IsNullOrEmpty(fundcodetb.Text) || String.IsNullOrEmpty(fundnametb.Text))
                {
                    MessageBox.Show("Please input fund code and fund name!");
                }
                else if (String.IsNullOrEmpty(voucherprefixtb.Text))
                {
                    MessageBox.Show("Please enter voucher prefix");
                }
                else
                {
                    ImusCityHallEntities db = new ImusCityHallEntities();
                    ImusCityGovernmentSystem.Model.Fund fund = db.Funds.Find(FundID);
                    fund.FundCode   = fundcodetb.Text;
                    fund.FundName   = fundnametb.Text;
                    fund.FundPrefix = voucherprefixtb.Text;
                    db.SaveChanges();
                    Mouse.OverrideCursor = null;
                    var audit = new AuditTrailModel
                    {
                        Activity   = "Updated an item in fund list. FUND ID: " + FundID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    MessageBox.Show("Fund updated successfully!");
                }
            }
            else
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }

            Mouse.OverrideCursor = null;
        }
        public static void InsertLog(AuditTrailModel model)
        {
            using (var db = new ImusCityHallEntities())
            {
                Employee employee = db.Employees.Find(model.EmployeeID);
                var      audit    = new AuditTrail()
                {
                    LogDate      = DateTime.Now,
                    IPAddress    = GetLocalIPAddress(),
                    ComputerName = Environment.MachineName,
                    ModuleName   = model.ModuleName,
                    Activity     = model.Activity,
                    UserID       = model.EmployeeID,
                    FirstName    = employee.FirstName,
                    LastName     = employee.LastName
                };

                db.AuditTrails.Add(audit);
                db.SaveChanges();
            }
        }
        private void deletebtn_Click(object sender, RoutedEventArgs e)
        {
            if (damgecheckdg.SelectedValue == null)
            {
                MessageBox.Show("Please select an item");
            }
            else
            {
                if (SystemClass.CheckConnection())
                {
                    ImusCityHallEntities db       = new ImusCityHallEntities();
                    int         damageCheckId     = (int)damgecheckdg.SelectedValue;
                    DamageCheck damageCheckDelete = db.DamageChecks.Find(damageCheckId);
                    db.DamageChecks.Remove(damageCheckDelete);
                    db.SaveChanges();
                    MessageBox.Show("Deleted damage check");
                    db = new ImusCityHallEntities();
                    List <DamageCheck> damageCheckList = new List <DamageCheck>();
                    foreach (var item in db.DamageChecks.Where(m => m.FundBankID == fundBankId))
                    {
                        var damageCheck = new DamageCheck()
                        {
                            DamageCheckId = item.DamageCheckId,
                            CheckNumber   = item.CheckNumber,
                            CreatedDate   = item.CreatedDate
                        };

                        damageCheckList.Add(damageCheck);
                    }
                    damgecheckdg.ItemsSource       = damageCheckList.OrderBy(m => m.CheckNumber);
                    damgecheckdg.SelectedValuePath = "DamageCheckId";
                }
                else
                {
                    MessageBox.Show(SystemClass.DBConnectionErrorMessage);
                }
            }
        }
Пример #10
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);
         }
     }
 }
Пример #11
0
        public void DivisionUpdate()
        {
            if (SystemClass.CheckConnection())
            {
                try
                {
                    using (var db = new ImusCityHallEntities())
                    {
                        var find = db.Divisions.Find(DivisionID);
                        find.DivisionCode = txtCode.Text;
                        find.DivisionName = txtName.Text;
                        find.DepartmentID = (int)departmentcb.SelectedValue;
                        db.SaveChanges();

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Updated an item in division list. DIV ID: " + DivisionID.ToString(),
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);
                        MessageBox.Show("Division updated successfully", "System Success!", MessageBoxButton.OK, MessageBoxImage.Information);
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong." + Environment.NewLine + ex.Message, "System Warning!", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Пример #12
0
 private void resetpasswordbtn_Click(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         ImusCityHallEntities db = new ImusCityHallEntities();
         if (employeelistlb.SelectedValue == null)
         {
             MessageBox.Show("Please select an employee");
         }
         else
         {
             var        employee       = db.Employees.Find((int)employeelistlb.SelectedValue);
             AspNetUser aspuser        = db.AspNetUsers.FirstOrDefault(m => m.UserName == employee.EmployeeNo);
             var        passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
             aspuser.PasswordHash = passwordHasher.HashPassword("imuscitygov");
             db.SaveChanges();
             MessageBox.Show("Employee account has been reset to" + Environment.NewLine + "Default Password: imuscitygov");
         }
     }
     else
     {
         MessageBox.Show(SystemClass.DBConnectionErrorMessage);
     }
 }
Пример #13
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                Mouse.OverrideCursor = Cursors.Wait;
                try
                {
                    ImusCityHallEntities db       = new ImusCityHallEntities();
                    Employee             employee = db.Employees.Find(EmployeeID);

                    if (String.IsNullOrEmpty(fnametb.Text))
                    {
                        MessageBox.Show("Please enter first name");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(lnametb.Text))
                    {
                        MessageBox.Show("Please enter last name");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(permaddtb.Text))
                    {
                        MessageBox.Show("Please enter permanent address");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(primaryemailtb.Text))
                    {
                        MessageBox.Show("Please enter primary email");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(employeenotb.Text))
                    {
                        MessageBox.Show("Please enter employee number");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(datehiredp.Text))
                    {
                        MessageBox.Show("Please enter date hired");
                        Mouse.OverrideCursor = null;
                    }
                    else if (divisioncb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee division");
                        Mouse.OverrideCursor = null;
                    }
                    else if (positioncb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee position");
                        Mouse.OverrideCursor = null;
                    }
                    else if (statuscb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee status");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(birthdatedp.Text))
                    {
                        MessageBox.Show("Please enter birthday");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(birthplacetb.Text))
                    {
                        MessageBox.Show("Please enter birthplace");
                        Mouse.OverrideCursor = null;
                    }
                    else if (genderdp.SelectedValue == null)
                    {
                        MessageBox.Show("Please select gender");
                        Mouse.OverrideCursor = null;
                    }
                    else if (civilstatuscb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select civil status");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(mobilenotb.Text))
                    {
                        MessageBox.Show("Please enter mobile number");
                        Mouse.OverrideCursor = null;
                    }
                    else
                    {
                        employee.EmployeeNo = employeenotb.Text;

                        int DeptID, PosID, StatID;

                        //Employee Information
                        employee.EmployeeDivisionID = Int32.TryParse(divisioncb.SelectedValue.ToString(), out DeptID) ? DeptID : (int?)null;
                        employee.EmployeePositionID = Int32.TryParse(positioncb.SelectedValue.ToString(), out PosID) ? PosID : (int?)null;
                        employee.EmployeeStatusID   = Int32.TryParse(positioncb.SelectedValue.ToString(), out StatID) ? StatID : (int?)null;
                        employee.DateHired          = String.IsNullOrEmpty(datehiredp.Text) ? null : datehiredp.SelectedDate;
                        employee.DatePermanency     = String.IsNullOrEmpty(datepermanetdp.Text) ? null : datepermanetdp.SelectedDate;
                        employee.DateEndContract    = String.IsNullOrEmpty(dateendodp.Text) ? null : dateendodp.SelectedDate;
                        employee.DateResigned       = String.IsNullOrEmpty(dateresignationdp.Text) ? null : dateresignationdp.SelectedDate;

                        //Personal Information
                        employee.FirstName   = fnametb.Text;
                        employee.MiddleName  = mnametb.Text;
                        employee.LastName    = lnametb.Text;
                        employee.NameSuffix  = namesuffixtb.Text;
                        employee.Birthday    = birthdatedp.SelectedDate;
                        employee.Birthplace  = birthplacetb.Text;
                        employee.Sex         = genderdp.SelectionBoxItem.ToString().Substring(0, 1);
                        employee.Nationality = citizenshiptb.Text;
                        employee.CivilStatus = civilstatuscb.SelectionBoxItem.ToString();
                        employee.Religion    = religiontb.Text;
                        employee.TIN         = tinnotb.Text;
                        employee.SSS         = sssnotb.Text;
                        employee.PhilHealth  = philhealthnotb.Text;
                        employee.PAG_IBIG    = pagibignotb.Text;

                        //Contact Information
                        employee.PermanentAddress = permaddtb.Text;
                        employee.CurrentAddress   = currentadd.Text;
                        employee.TelephoneNo      = landlinenotb.Text;
                        employee.MobileNo         = mobilenotb.Text;
                        employee.PrimaryEmail     = primaryemailtb.Text;
                        employee.SecondaryEmail   = secondaryemailtb.Text;

                        employee.Archive = activechk.IsChecked;
                        if (!String.IsNullOrEmpty(newimage))
                        {
                            FileStream fStream  = File.OpenRead(newimage);
                            byte[]     contents = new byte[fStream.Length];
                            fStream.Read(contents, 0, (int)fStream.Length);
                            fStream.Close();
                            employee.Photo = contents;
                        }
                        else
                        {
                        }
                        employee.DateEncoded = DateTime.Now;
                        db.SaveChanges();
                        Mouse.OverrideCursor = null;

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Updated an employee EMP ID: " + EmployeeID.ToString(),
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);

                        MessageBox.Show("Employee was updated to the database succesfully!");
                    }
                }
                catch (Exception ex)
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Пример #14
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);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            if (SystemClass.CheckConnection())
            {
                if (String.IsNullOrEmpty(payeenotb.Text) || String.IsNullOrEmpty(companynametb.Text) || String.IsNullOrEmpty(companyaddresstb.Text))
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("Please input company name, company address and payee number");
                }
                else if (gd.Where(m => m.IsSelected == true).Count() == 0)
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("Please select at least one representative for the payee!");
                }
                else
                {
                    ImusCityHallEntities db = new ImusCityHallEntities();
                    if (db.Payees.FirstOrDefault(m => m.PayeeNo == payeenotb.Text) != null)
                    {
                        Mouse.OverrideCursor = null;
                        MessageBox.Show("Payee number already exist!");
                    }
                    else
                    {
                        ImusCityGovernmentSystem.Model.Payee payee = new Model.Payee();
                        payee.PayeeNo        = payeenotb.Text;
                        payee.CompanyName    = companynametb.Text;
                        payee.CompanyAddress = companyaddresstb.Text;
                        payee.TIN            = tinnotb.Text;
                        payee.LandlineNo     = contactnotb.Text;
                        payee.IsActive       = true;
                        db.Payees.Add(payee);
                        db.SaveChanges();


                        foreach (var list in gd.Where(m => m.IsSelected == true))
                        {
                            PayeeRepresentative pr = db.PayeeRepresentatives.Find(list.Id);
                            pr.PayeeID = payee.PayeeID;
                            db.SaveChanges();
                        }
                        Mouse.OverrideCursor = null;

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Added new payee in the database. PAYEE NO." + payeenotb.Text,
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);
                        MessageBox.Show("Payee added successfully!");
                        SystemClass.ClearTextBoxes(this);
                        LoadPayeeRepresentative();
                    }
                }
            }
            else
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
            Mouse.OverrideCursor = null;
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                if (dgControlNumberList.SelectedValue != null)
                {
                    ImusCityHallEntities db = new ImusCityHallEntities();
                    int id = (int)dgControlNumberList.SelectedValue;

                    addbtn.IsEnabled  = false;
                    savebtn.IsEnabled = true;

                    var x = db.ControlNumbers.Find(id);

                    if (x != null)
                    {
                        int accountID = Convert.ToInt32(accountcb.SelectedValue);
                        if (String.IsNullOrEmpty(controlnobegintb.Value.ToString()))
                        {
                            MessageBox.Show("Control Number Start cannot be empty.");
                            return;
                        }
                        if (String.IsNullOrEmpty(controlnoendtb.Value.ToString()))
                        {
                            MessageBox.Show("Control Number End cannot be empty.");
                            return;
                        }
                        if (String.IsNullOrEmpty(controlnocurrenttb.Value.ToString()))
                        {
                            MessageBox.Show("Control Number Current cannot be empty.");
                            return;
                        }

                        int start = Convert.ToInt32(controlnobegintb.Value.Value);
                        int end   = Convert.ToInt32(controlnoendtb.Value.Value);
                        int next  = Convert.ToInt32(controlnocurrenttb.Value.Value);

                        if (IsWithin(next, start, end) != true)
                        {
                            MessageBox.Show("Next control number is not within the range.");
                            return;
                        }


                        x.FundBankID        = accountID;
                        x.BeginingControlNo = start;
                        x.EndingControlNo   = end;
                        x.NextControlNo     = next;
                        //x.Date = DateTime.Now;
                        if (activechk.IsChecked == true)
                        {
                            x.Active = true;
                        }
                        else
                        {
                            x.Active = false;
                        }
                        db.SaveChanges();
                        MessageBox.Show("Control Number has successfully edited.");
                        ResetState();
                        GetList();
                    }
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Пример #17
0
 private void savebtn_Click(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         try
         {
             ImusCityHallEntities db          = new ImusCityHallEntities();
             CDSSignatory         signatories = db.CDSSignatories.FirstOrDefault();
             if (payeecb.SelectedValue == null && optionpayeecb.IsChecked == false)
             {
                 MessageBox.Show("Please select payee from the dropdown list");
             }
             else if (optionpayeecb.IsChecked == true && String.IsNullOrEmpty(optionalpayee.Text))
             {
                 MessageBox.Show("Please enter payee name");
             }
             else if (paymenttypecb.SelectedValue == null)
             {
                 MessageBox.Show("Please select payment type");
             }
             else if (signatories == null)
             {
                 Mouse.OverrideCursor = null;
                 MessageBox.Show("Please add report signatories");
             }
             else if (String.IsNullOrEmpty(vouchernotb.Text))
             {
                 MessageBox.Show("Please enter voucher number");
             }
             else if (voucherList.Count() == 0)
             {
                 MessageBox.Show("Please input at least one voucher item");
             }
             else
             {
                 Disbursement disbursement = new Disbursement();
                 disbursement.PayeeID      = optionpayeecb.IsChecked == true ? null : payeecb.SelectedValue == null ? (int?)null : (int)payeecb.SelectedValue;
                 disbursement.PayeeName    = optionalpayee.Text.ToUpper();
                 disbursement.PayeeRepID   = payeerepcb.SelectedValue == null ? (int?)null : (int)payeerepcb.SelectedValue;
                 disbursement.DepartmentID = departmentcb.SelectedValue == null ? null : (int?)departmentcb.SelectedValue;
                 disbursement.PaymentType  = paymenttypecb.Text;
                 disbursement.VoucherNo    = voucherprefixtb.Text + vouchernotb.Text;
                 disbursement.DateCreated  = DateTime.Now;
                 disbursement.ProjectName  = projectnametb.Text;
                 disbursement.Obligated    = obligatedcb.IsChecked;
                 disbursement.DocCompleted = documentcb.IsChecked;
                 disbursement.CreatedBy    = App.EmployeeID;
                 foreach (var voucherItem in voucherList)
                 {
                     var item = new DisbursementItem()
                     {
                         Explanation = voucherItem.Explanation,
                         Amount      = Convert.ToDecimal(voucherItem.Amount)
                     };
                     disbursement.DisbursementItems.Add(item);
                 }
                 var x = db.Disbursements.Add(disbursement);
                 db.SaveChanges();
                 var audit = new AuditTrailModel
                 {
                     Activity   = "Created disbursement document",
                     ModuleName = this.GetType().Name,
                     EmployeeID = App.EmployeeID
                 };
                 SystemClass.InsertLog(audit);
                 MessageBox.Show("Check Disbursement Created!");
                 Print(x.DisbursementID);
                 this.Close();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.ToString());
         }
     }
     else
     {
         MessageBox.Show(SystemClass.DBConnectionErrorMessage);
     }
 }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                ImusCityGovernmentSystem.Model.Check check = db.Checks.Find(CheckID);
                check.Status = checkstatuscb.SelectedIndex;


                if (checkstatuscb.SelectedIndex == (int)CheckStatus.Cancelled)
                {
                    check.CancelledBy   = App.EmployeeID;
                    check.CancelledDate = DateTime.Now;

                    ImusCityGovernmentSystem.Model.BankTrail    banktrail    = new BankTrail();
                    ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(check.DisbursementID);
                    banktrail.DebitCredit = "C";
                    banktrail.FundBankID  = disbursement.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(check.Amount);
                    banktrail.EntryName   = nameof(BankTrailEntry.CheckCancelled);
                    banktrail.CheckID     = check.CheckID;
                    banktrail.EntryNameID = (int)BankTrailEntry.CheckCancelled;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(disbursement.FundBankID);
                    account.CurrentBalance += Convert.ToDecimal(check.Amount);
                }
                else if (checkstatuscb.SelectedIndex == (int)CheckStatus.Deleted)
                {
                    check.DeletedBy   = App.EmployeeID;
                    check.DeletedDate = DateTime.Now;

                    ImusCityGovernmentSystem.Model.BankTrail    banktrail    = new BankTrail();
                    ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(check.DisbursementID);
                    banktrail.DebitCredit = "C";
                    banktrail.FundBankID  = disbursement.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(check.Amount);
                    banktrail.EntryName   = nameof(BankTrailEntry.CheckDeleted);
                    banktrail.CheckID     = check.CheckID;
                    banktrail.EntryNameID = (int)BankTrailEntry.CheckDeleted;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(disbursement.FundBankID);
                    account.CurrentBalance += Convert.ToDecimal(check.Amount);
                }


                db.SaveChanges();

                var audit = new AuditTrailModel
                {
                    Activity   = "Updated check in the database. CHECK NUMBER: " + check.CheckNo,
                    ModuleName = this.GetType().Name,
                    EmployeeID = App.EmployeeID
                };

                SystemClass.InsertLog(audit);

                MessageBox.Show("Check entry updated successfully");
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Mouse.OverrideCursor = Cursors.Wait;
                if (SystemClass.CheckConnection())
                {
                    if (fundcb.SelectedValue == null)
                    {
                        Mouse.OverrideCursor = null;
                        MessageBox.Show("Please select fund");
                    }
                    else
                    {
                        ImusCityHallEntities db = new ImusCityHallEntities();
                        int fundBankId          = (int)fundcb.SelectedValue;
                        var fundBank            = db.FundBanks.Find(fundBankId);
                        ImusCityGovernmentSystem.Model.Disbursement disbursement = db.Disbursements.Find(DisbursementID);

                        var controlNumber = db.ControlNumbers.OrderByDescending(m => m.ControlNoID).FirstOrDefault(m => m.FundBankID == fundBankId && m.Active == true);

                        if (String.IsNullOrEmpty(checknotb.Text))
                        {
                            MessageBox.Show("Please provide the check number");
                            this.Close();
                        }
                        else if (String.IsNullOrEmpty(checkdesctb.Text))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Please provide check description");
                        }
                        else if (checkamounttb.Text.Equals("0.00"))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Please enter check amount");
                        }
                        else if (db.Checks.Any(m => m.CheckNo == checknotb.Text && m.Status != (int)CheckStatus.Deleted && m.Disbursement.FundBankID == fundBankId))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check number is already been used");
                        }
                        else if (db.FundBanks.Find(fundBankId).CurrentBalance < Convert.ToDecimal(checkamounttb.Text))
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check cannot be created, you have insufficients funds");
                        }
                        else if (controlNumber == null)
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Selected fund have no available check number");
                        }
                        else if (db.DamageChecks.Where(m => m.FundBankID == fundBankId && m.CheckNumber == checknotb.Text).Count() >= 1)
                        {
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("The current check number is in the list of damage checks");
                        }
                        else
                        {
                            Check check = new Check();
                            check.DisbursementID   = DisbursementID;
                            check.CheckNo          = checknotb.Text;
                            check.CheckDescription = checkdesctb.Text;
                            check.Amount           = Convert.ToDecimal(checkamounttb.Text);
                            check.EmployeeID       = App.EmployeeID;
                            check.DateCreated      = DateTime.Now;
                            check.Status           = (int)CheckStatus.Created;

                            //Increment of the Check Number.
                            if (controlNumber.EndingControlNo == controlNumber.NextControlNo)
                            {
                                controlNumber.Active = false;
                            }
                            else
                            {
                                controlNumber.NextControlNo++;
                            }

                            check.ControlNo = checknotb.Text;
                            var savedCheck = db.Checks.Add(check);


                            ImusCityGovernmentSystem.Model.BankTrail banktrail = new BankTrail();
                            banktrail.DebitCredit = "D";
                            banktrail.FundBankID  = fundBankId;
                            banktrail.Amount      = Convert.ToDecimal(checkamounttb.Text);
                            banktrail.EntryName   = nameof(BankTrailEntry.CheckCreated);
                            banktrail.CheckID     = savedCheck.CheckID;
                            banktrail.EntryNameID = (int)BankTrailEntry.CheckCreated;
                            banktrail.EmployeeID  = App.EmployeeID;
                            banktrail.DateCreated = DateTime.Now;
                            db.BankTrails.Add(banktrail);

                            ImusCityGovernmentSystem.Model.FundBank account = db.FundBanks.Find(fundBankId);
                            account.CurrentBalance -= Convert.ToDecimal(checkamounttb.Text);

                            disbursement.VoucherNo  = string.Join("-", fundBank.Fund.FundPrefix, disbursement.VoucherNo);
                            disbursement.FundBankID = fundBankId;

                            db.SaveChanges();

                            var audit = new AuditTrailModel
                            {
                                Activity   = "Created new check entry DIS ID: " + DisbursementID.ToString(),
                                ModuleName = this.GetType().Name,
                                EmployeeID = App.EmployeeID
                            };

                            SystemClass.InsertLog(audit);
                            Mouse.OverrideCursor = null;
                            MessageBox.Show("Check created successfully!");
                            PrintReport(check.CheckID);

                            checknotb.Clear();
                            checkdesctb.Clear();
                            checkamounttb.Clear();
                            currentbalancetb.Text = "";
                            LoadFund();
                        }
                    }
                }
                else
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show(SystemClass.DBConnectionErrorMessage);
                }
            }
            catch (Exception ex)
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(ex.ToString());
            }
        }
Пример #20
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                if (fundcb.SelectedValue == null)
                {
                    MessageBox.Show("Please select fund");
                }
                else if (bankcb.SelectedValue == null)
                {
                    MessageBox.Show("Please select bank");
                }
                else if (String.IsNullOrEmpty(accountnumbertb.Text))
                {
                    MessageBox.Show("Please input account number");
                }
                else if (db.FundBanks.Any(m => m.AccountNumber == accountnumbertb.Text))
                {
                    MessageBox.Show("The account number is already used");
                }
                else if (String.IsNullOrEmpty(startingbalancetb.Text))
                {
                    MessageBox.Show("Please input starting balance");
                }
                else if (String.IsNullOrEmpty(advicenumbertb.Text))
                {
                    MessageBox.Show("Please input advice number");
                }
                else if (String.IsNullOrEmpty(flooramounttb.Text))
                {
                    MessageBox.Show("Please input floor amount");
                }
                else
                {
                    ImusCityGovernmentSystem.Model.FundBank account = new FundBank();
                    account.FundID          = (int)fundcb.SelectedValue;
                    account.BankID          = (int)bankcb.SelectedValue;
                    account.AccountNumber   = accountnumbertb.Text;
                    account.CurrentBalance  = Convert.ToDecimal(startingbalancetb.Text);
                    account.StartingBalance = Convert.ToDecimal(startingbalancetb.Text);
                    account.IsActive        = true;
                    account.DateAdded       = DateTime.Now;
                    account.AdviceNo        = Convert.ToInt32(advicenumbertb.Text);
                    account.IsProcessed     = true;
                    account.AmountLimit     = Convert.ToDecimal(flooramounttb.Text);
                    db.FundBanks.Add(account);

                    ImusCityGovernmentSystem.Model.BankTrail banktrail = new BankTrail();
                    banktrail.DebitCredit = "D";
                    banktrail.FundBankID  = account.FundBankID;
                    banktrail.Amount      = Convert.ToDecimal(startingbalancetb.Text);
                    banktrail.EntryName   = nameof(BankTrailEntry.FundCreation);
                    banktrail.CheckID     = null;
                    banktrail.EntryNameID = (int)BankTrailEntry.FundCreation;
                    banktrail.EmployeeID  = App.EmployeeID;
                    banktrail.DateCreated = DateTime.Now;
                    db.BankTrails.Add(banktrail);

                    db.SaveChanges();

                    var audit = new AuditTrailModel
                    {
                        Activity   = "Added new bank account in the database. FUNDBANK ID: " + account.FundBankID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);

                    MessageBox.Show("Account added successfully");
                    SystemClass.ClearTextBoxes(this);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
Пример #21
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                if (gd.Where(m => m.IsSelected == true).Count() == 0)
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("Please select at least representative for the payee!");
                }
                else if (String.IsNullOrEmpty(payeenotb.Text) || String.IsNullOrEmpty(companynametb.Text) || String.IsNullOrEmpty(companyaddresstb.Text))
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show("Please input company name, company address and payee number");
                }
                else
                {
                    ImusCityGovernmentSystem.Model.Payee payee = db.Payees.Find(PayeeID);
                    payee.PayeeNo        = payeenotb.Text;
                    payee.CompanyName    = companynametb.Text;
                    payee.CompanyAddress = companyaddresstb.Text;
                    payee.TIN            = tinnotb.Text;
                    payee.LandlineNo     = contactnotb.Text;
                    db.SaveChanges();

                    foreach (var list in gd)
                    {
                        if (list.IsSelected == true)
                        {
                            PayeeRepresentative pr = db.PayeeRepresentatives.Find(list.Id);
                            pr.PayeeID = payee.PayeeID;
                            db.SaveChanges();
                        }
                        else
                        {
                            PayeeRepresentative pr = db.PayeeRepresentatives.Find(list.Id);
                            pr.PayeeID = null;
                            db.SaveChanges();
                        }
                    }
                    Mouse.OverrideCursor = null;

                    var audit = new AuditTrailModel
                    {
                        Activity   = "Updated an item in payee list. PAYEE ID: " + PayeeID.ToString(),
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);

                    MessageBox.Show("Payee updated successfully!");
                }
            }
            else
            {
                Mouse.OverrideCursor = null;
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
            Mouse.OverrideCursor = null;
        }
Пример #22
0
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                if (db.CDSSignatories.Any())
                {
                    ImusCityGovernmentSystem.Model.CDSSignatory signatory = db.CDSSignatories.FirstOrDefault();
                    signatory.CityMayor = mayorcb.SelectedValue == null ? null : (int?)mayorcb.SelectedValue;
                    switch (mayorrb.IsChecked)
                    {
                    case true:
                        signatory.UseActingMayor = false;
                        break;

                    case false:
                        signatory.UseActingMayor = true;
                        break;
                    }

                    signatory.CityTreasurer            = treasurercb.SelectedValue == null ? null : (int?)treasurercb.SelectedValue;
                    signatory.CityAccountant           = accountantcb.SelectedValue == null ? null : (int?)accountantcb.SelectedValue;
                    signatory.AccountantRepresentative = accountantrepcb.SelectedValue == null ? null : (int?)accountantrepcb.SelectedValue;
                    signatory.CityAdministrator        = administratorcb.SelectedValue == null ? null : (int?)administratorcb.SelectedValue;
                    signatory.DisbursingOfficer        = disbursingcb.SelectedValue == null ? null : (int?)disbursingcb.SelectedValue;
                    db.SaveChanges();
                    MessageBox.Show("Signatories for CDS was updated");

                    var audit = new AuditTrailModel
                    {
                        Activity   = "Updated CDS signatories",
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                }
                else
                {
                    ImusCityGovernmentSystem.Model.CDSSignatory signatory = new CDSSignatory();
                    switch (mayorrb.IsChecked)
                    {
                    case true:
                        signatory.UseActingMayor = false;
                        break;

                    case false:
                        signatory.UseActingMayor = true;
                        break;
                    }
                    signatory.CityMayor                = mayorcb.SelectedValue == null ? null : (int?)mayorcb.SelectedValue;
                    signatory.CityTreasurer            = treasurercb.SelectedValue == null ? null : (int?)treasurercb.SelectedValue;
                    signatory.CityAccountant           = accountantcb.SelectedValue == null ? null : (int?)accountantcb.SelectedValue;
                    signatory.AccountantRepresentative = accountantrepcb.SelectedValue == null ? null : (int?)accountantrepcb.SelectedValue;
                    signatory.CityAdministrator        = administratorcb.SelectedValue == null ? null : (int?)administratorcb.SelectedValue;
                    signatory.DisbursingOfficer        = disbursingcb.SelectedValue == null ? null : (int?)disbursingcb.SelectedValue;
                    db.CDSSignatories.Add(signatory);
                    db.SaveChanges();
                    MessageBox.Show("Signatories for CDS was updated");

                    var audit = new AuditTrailModel
                    {
                        Activity   = "Added new CDS Signatories",
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void acceptbtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();
                var licenseList         = from p in db.LicensingCodes
                                          select new
                {
                    p.LicenseId,
                    p.ExpirationDate,
                    p.SubModule,
                    LicenseKey = p.LicenseKey.Replace("\r\n", string.Empty)
                };


                if (String.IsNullOrEmpty(licensekey.Text))
                {
                    MessageBox.Show("The license key field is empty");
                    return;
                }
                var           licenseCode = licenseList.FirstOrDefault(m => m.LicenseKey == licensekey.Text);
                LicensingCode license     = new LicensingCode()
                {
                    LicenseId      = licenseCode.LicenseId,
                    LicenseKey     = licenseCode.LicenseKey,
                    ExpirationDate = licenseCode.ExpirationDate,
                    SubModule      = licenseCode.SubModule
                };


                if (license != null && license.ExpirationDate > DateTime.Now.Date && license.SubModule.Acronym == subModuleCode && license.LicenseKey == App.LicenseKey)
                {
                    LicensingCode dbLicense = db.LicensingCodes.Find(license.LicenseId);
                    //license.MachineName = Environment.MachineName;
                    //license.UserID = App.EmployeeID;
                    dbLicense.ActivatedDate = DateTime.Now;
                    db.SaveChanges();
                    MessageBox.Show("License key applied");
                    this.Close();
                }
                else if (String.IsNullOrEmpty(licensekey.Text))
                {
                    MessageBox.Show("The license key field is empty");
                }
                else if (license == null)
                {
                    MessageBox.Show("Please enter a valid license key.");
                }
                else if (license.ExpirationDate < DateTime.Now)
                {
                    MessageBox.Show("The license that youve entering is expired!");
                }
                else if (licensekey.Text != App.LicenseKey)
                {
                    MessageBox.Show("Please enter a valid license key.");
                }
                else if (license.SubModule.Acronym != subModuleCode && license != null)
                {
                    MessageBox.Show("The license that you are applying is not meant for the specified module");
                }
                //else if (license.LicenseKey == licensekey.Text && license.UserID == App.EmployeeID)
                //{
                //    MessageBox.Show("This license is associated with another user");
                //}
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        //Insertion of new employee information
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                Mouse.OverrideCursor = Cursors.Wait;
                try
                {
                    ImusCityHallEntities db       = new ImusCityHallEntities();
                    Employee             employee = new Employee();

                    string   birthdateInput = birthdatedp.Text;
                    DateTime returnBirthDate;

                    string   dateHiredInput = datehiredp.Text;
                    DateTime returnDateHired;

                    if (db.Employees.Where(m => m.EmployeeNo == employeenotb.Text).FirstOrDefault() != null)
                    {
                        MessageBox.Show("Employee number already exists!", "System Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        Mouse.OverrideCursor = null;
                        return;
                    }
                    else if (String.IsNullOrEmpty(fnametb.Text))
                    {
                        MessageBox.Show("Please enter first name");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(lnametb.Text))
                    {
                        MessageBox.Show("Please enter last name");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(permaddtb.Text))
                    {
                        MessageBox.Show("Please enter permanent address");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(primaryemailtb.Text))
                    {
                        MessageBox.Show("Please enter primary email");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(employeenotb.Text))
                    {
                        MessageBox.Show("Please enter employee number");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(datehiredp.Text))
                    {
                        MessageBox.Show("Please enter date hired");
                        Mouse.OverrideCursor = null;
                    }
                    else if (divisioncb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee division");
                        Mouse.OverrideCursor = null;
                    }
                    else if (positioncb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee position");
                        Mouse.OverrideCursor = null;
                    }
                    else if (statuscb.SelectedValue == null)
                    {
                        MessageBox.Show("Please select employee status");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(birthdatedp.Text))
                    {
                        MessageBox.Show("Please enter birthday");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(birthplacetb.Text))
                    {
                        MessageBox.Show("Please enter birthplace");
                        Mouse.OverrideCursor = null;
                    }
                    else if (genderdp.SelectedValue == null)
                    {
                        MessageBox.Show("Please select gender");
                        Mouse.OverrideCursor = null;
                    }
                    else if (String.IsNullOrEmpty(mobilenotb.Text))
                    {
                        MessageBox.Show("Please enter mobile number");
                        Mouse.OverrideCursor = null;
                    }
                    else if (!DateTime.TryParse(birthdateInput, out returnBirthDate))
                    {
                        MessageBox.Show("Please enter valid date format for birthdate (mm/dd/yyyy)");
                    }
                    else if (!DateTime.TryParse(dateHiredInput, out returnDateHired))
                    {
                        MessageBox.Show("Please enter valid date format for date hired (mm/dd/yyyy)");
                    }
                    else if (CheckNumberOfUser())
                    {
                        Mouse.OverrideCursor = null;
                        MessageBox.Show("Maximum number of users already reached. Please contact your vendor");
                    }
                    else
                    {
                        employee.EmployeeNo = employeenotb.Text;

                        int DivID, PosID, StatID;

                        //Employee Information
                        employee.EmployeeDivisionID = Int32.TryParse(divisioncb.SelectedValue.ToString(), out DivID) ? DivID : (int?)null;
                        employee.EmployeePositionID = Int32.TryParse(positioncb.SelectedValue.ToString(), out PosID) ? PosID : (int?)null;
                        employee.EmployeeStatusID   = Int32.TryParse(statuscb.SelectedValue.ToString(), out StatID) ? StatID : (int?)null;
                        employee.DateHired          = String.IsNullOrEmpty(datehiredp.Text) ? null : datehiredp.SelectedDate;
                        employee.DatePermanency     = String.IsNullOrEmpty(datepermanetdp.Text) ? null : datepermanetdp.SelectedDate;
                        employee.DateEndContract    = String.IsNullOrEmpty(dateendodp.Text) ? null : dateendodp.SelectedDate;
                        employee.DateResigned       = String.IsNullOrEmpty(dateresignationdp.Text) ? null : dateresignationdp.SelectedDate;

                        //Personal Information
                        employee.FirstName   = fnametb.Text;
                        employee.MiddleName  = mnametb.Text;
                        employee.LastName    = lnametb.Text;
                        employee.NameSuffix  = namesuffixtb.Text;
                        employee.Birthday    = birthdatedp.SelectedDate;
                        employee.Birthplace  = birthplacetb.Text;
                        employee.Sex         = genderdp.SelectionBoxItem.ToString().Substring(0, 1);
                        employee.Nationality = citizenshiptb.Text;
                        employee.CivilStatus = civilstatuscb.SelectionBoxItem.ToString();
                        employee.Religion    = religiontb.Text;
                        employee.TIN         = tinnotb.Text;
                        employee.SSS         = sssnotb.Text;
                        employee.PhilHealth  = philhealthnotb.Text;
                        employee.PAG_IBIG    = pagibignotb.Text;

                        //Contact Information
                        employee.PermanentAddress = permaddtb.Text;
                        employee.CurrentAddress   = currentadd.Text;
                        employee.TelephoneNo      = landlinenotb.Text;
                        employee.MobileNo         = mobilenotb.Text;
                        employee.PrimaryEmail     = primaryemailtb.Text;
                        employee.SecondaryEmail   = secondaryemailtb.Text;

                        employee.Archive     = false;
                        employee.Photo       = newimage == null ? null : File.ReadAllBytes(newimage);
                        employee.DateEncoded = DateTime.Now;


                        db.Employees.Add(employee);
                        db.SaveChanges();
                        Mouse.OverrideCursor = null;

                        MessageBox.Show("Employee was added to the database succesfully!");

                        db = new ImusCityHallEntities();
                        var newemp = db.Employees.Where(m => m.EmployeeNo == employeenotb.Text).FirstOrDefault();
                        if (db.AspNetUsers.Where(m => m.UserName == employee.EmployeeNo).FirstOrDefault() != null)
                        {
                            MessageBox.Show("User account for this person already exists!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        else if (db.AspNetUsers.Where(m => m.Email == primaryemailtb.Text && m.Email != "").FirstOrDefault() != null)
                        {
                            MessageBox.Show("Email already exists!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        else
                        {
                            string roleid = "2";
                            if (String.IsNullOrEmpty(roleid))
                            {
                                MessageBox.Show("Role is not specified", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                                return;
                            }
                            else
                            {
                                AspNetUser     aspuser     = new AspNetUser();
                                AspNetUserRole asproleuser = new AspNetUserRole();
                                aspuser.Id                   = Guid.NewGuid().ToString();
                                aspuser.UserName             = newemp.EmployeeNo;
                                aspuser.Email                = newemp.PrimaryEmail;
                                aspuser.EmailConfirmed       = true;
                                aspuser.PhoneNumberConfirmed = false;
                                aspuser.TwoFactorEnabled     = false;
                                aspuser.LockoutEnabled       = true;
                                aspuser.AccessFailedCount    = 0;
                                aspuser.SecurityStamp        = Guid.NewGuid().ToString();
                                var passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
                                aspuser.PasswordHash = passwordHasher.HashPassword("imuscitygov");
                                var adduser = db.AspNetUsers.Add(aspuser);
                                asproleuser.UserId = adduser.Id;
                                asproleuser.RoleId = roleid;
                                db.AspNetUserRoles.Add(asproleuser);
                            }
                        }
                        db.SaveChanges();

                        var audit = new AuditTrailModel
                        {
                            Activity   = "Added new employee in the database. EMP NO: " + employeenotb.Text,
                            ModuleName = this.GetType().Name,
                            EmployeeID = App.EmployeeID
                        };

                        SystemClass.InsertLog(audit);

                        MessageBox.Show("Employee user account created" + Environment.NewLine + "Default Password: imuscitygov");
                        ClearTextBoxes();
                    }
                }
                catch (Exception ex)
                {
                    Mouse.OverrideCursor = null;
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void savebtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                using (var db = new ImusCityHallEntities())
                {
                    QList = new List <QuestionList>();
                    if (!String.IsNullOrEmpty(cbSecurityQuestion1.Text) && !String.IsNullOrEmpty(txtAnswer1.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID1 = Convert.ToInt32(cbSecurityQuestion1.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID1;
                        ql.Answer     = txtAnswer1.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }
                    if (!String.IsNullOrEmpty(cbSecurityQuestion2.Text) && !String.IsNullOrEmpty(txtAnswer2.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID2 = Convert.ToInt32(cbSecurityQuestion2.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID2;
                        ql.Answer     = txtAnswer2.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }
                    if (!String.IsNullOrEmpty(cbSecurityQuestion3.Text) && !String.IsNullOrEmpty(txtAnswer3.Text))
                    {
                        QuestionList ql          = new QuestionList();
                        int          QuestionID3 = Convert.ToInt32(cbSecurityQuestion3.SelectedValue);
                        ql.EmployeeID = App.EmployeeID;
                        ql.QuestionID = QuestionID3;
                        ql.Answer     = txtAnswer3.Text;
                        QList.Add(ql);
                    }
                    else
                    {
                        MessageBox.Show("Please answer security questions.");
                        return;
                    }

                    foreach (var x in QList)
                    {
                        SecurityQuestionUser squ = new SecurityQuestionUser();
                        squ.EmployeeID         = x.EmployeeID;
                        squ.SecurityQuestionID = x.QuestionID;
                        squ.Answer             = x.Answer;
                        db.SecurityQuestionUsers.Add(squ);
                        db.SaveChanges();
                    }

                    MessageBox.Show("Security Questions set-up succesfully!");
                    var audit = new AuditTrailModel
                    {
                        Activity   = "User set-up security questions.",
                        ModuleName = this.GetType().Name,
                        EmployeeID = App.EmployeeID
                    };

                    SystemClass.InsertLog(audit);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }
        private void addbtn_Click(object sender, RoutedEventArgs e)
        {
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities db = new ImusCityHallEntities();

                int accountID = Convert.ToInt32(accountcb.SelectedValue);

                var fundbank = db.FundBanks.Find(accountID);
                if (fundbank != null)
                {
                    if (db.ControlNumbers.Where(m => m.FundBankID == accountID && m.Active == true) == null)
                    {
                        MessageBox.Show("There is an active series for this Account.");
                        return;
                    }
                    if (String.IsNullOrEmpty(controlnobegintb.Value.ToString()))
                    {
                        MessageBox.Show("Control Number Start cannot be empty.");
                        return;
                    }
                    if (String.IsNullOrEmpty(controlnoendtb.Value.ToString()))
                    {
                        MessageBox.Show("Control Number End cannot be empty.");
                        return;
                    }
                    if (String.IsNullOrEmpty(controlnocurrenttb.Value.ToString()))
                    {
                        MessageBox.Show("Control Number Current cannot be empty.");
                        return;
                    }
                    Model.ControlNumber cn = new Model.ControlNumber();

                    int start = Convert.ToInt32(controlnobegintb.Value.Value);
                    int end   = Convert.ToInt32(controlnoendtb.Value.Value);
                    int next  = Convert.ToInt32(controlnocurrenttb.Value.Value);

                    if (IsWithin(next, start, end) != true)
                    {
                        MessageBox.Show("Next control number is not within the range.");
                        return;
                    }
                    cn.FundBankID        = accountID;
                    cn.BeginingControlNo = next;
                    cn.EndingControlNo   = end;
                    cn.NextControlNo     = next;
                    cn.Date = DateTime.Now;
                    if (activechk.IsChecked == true)
                    {
                        cn.Active = true;
                    }
                    else
                    {
                        cn.Active = false;
                    }
                    db.ControlNumbers.Add(cn);
                    db.SaveChanges();
                    MessageBox.Show("Control Number has successfully added.");
                    ResetState();
                    GetList();
                }
                else
                {
                    MessageBox.Show("Select an account to be process.");
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }