private void acceptbtn_Click(object sender, RoutedEventArgs e)
 {
     if (SystemClass.CheckConnection())
     {
         ImusCityHallEntities db = new ImusCityHallEntities();
         if (db.SystemSettings.Count() >= 1)
         {
             int numberUsers = Convert.ToInt32(userstb.Text);
             ImusCityGovernmentSystem.Model.SystemSetting systemSetting = db.SystemSettings.FirstOrDefault();
             systemSetting.NumberOfUser = numberUsers;
             db.SaveChanges();
             MessageBox.Show("System setting updated successfully!");
         }
         else
         {
             if (String.IsNullOrEmpty(userstb.Text))
             {
                 MessageBox.Show("Please input number of users field");
             }
             else
             {
                 int numberUsers = Convert.ToInt32(userstb.Text);
                 ImusCityGovernmentSystem.Model.SystemSetting systemSetting = new SystemSetting
                 {
                     NumberOfUser = numberUsers
                 };
                 db.SystemSettings.Add(systemSetting);
                 db.SaveChanges();
                 MessageBox.Show("System setting updated successfully!");
             }
         }
     }
     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);
            }
        }
        private void loginbtn_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            try
            {
                if (String.IsNullOrEmpty(usernametb.Text) || String.IsNullOrEmpty(passwordpb.Password))
                {
                    MessageBox.Show("Please input your sign-in credentials");
                }
                else
                {
                    if (SystemClass.CheckConnection())
                    {
                        using (var db = new ImusCityHallEntities())
                        {
                            var    passwordHasher = new Microsoft.AspNet.Identity.PasswordHasher();
                            string pass           = "";
                            var    asp            = db.AspNetUsers.Where(m => m.UserName == usernametb.Text).FirstOrDefault();

                            if (asp != null)
                            {
                                pass = passwordHasher.VerifyHashedPassword(asp.PasswordHash, passwordpb.Password).ToString();
                            }
                            else
                            {
                                MessageBox.Show("Log-in failed!");
                                Mouse.OverrideCursor = null;
                                return;
                            }

                            if (pass == "Success")
                            {
                                Mouse.OverrideCursor = Cursors.Wait;
                                var emp = db.Employees.FirstOrDefault(m => m.EmployeeNo == usernametb.Text);
                                App.EmployeeID = emp.EmployeeID;

                                if (passwordpb.Password == "imuscitygov")
                                {
                                    Mouse.OverrideCursor = null;
                                    MessageBox.Show("Please change your default password.");
                                    ChangePasswordWindow password = new ChangePasswordWindow();
                                    password.Show();
                                }
                                else if (emp.SecurityQuestionUsers.Count < 3 && emp.EmployeeNo != "123456")
                                {
                                    Mouse.OverrideCursor = null;
                                    MessageBox.Show("Please set-up your security questions.");
                                    SecurityQuestion secquestion = new SecurityQuestion();
                                    secquestion.Show();
                                    //
                                }
                                else
                                {
                                    var audit = new AuditTrailModel
                                    {
                                        Activity   = "Log-in to the system",
                                        ModuleName = this.GetType().Name,
                                        EmployeeID = App.EmployeeID
                                    };

                                    SystemClass.InsertLog(audit);
                                    MainWindow mw = new MainWindow();
                                    mw.Password = passwordpb.Password;
                                    mw.Show();
                                    this.Close();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Log-in failed!");
                                Mouse.OverrideCursor = null;
                                return;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(SystemClass.DBConnectionErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            Mouse.OverrideCursor = null;
        }
        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);
            }
        }
Example #5
0
        public void CheckUserAccess()
        {
            CDS.IsEnabled  = false;
            EMP.IsEnabled  = false;
            CUST.IsEnabled = false;
            DEPT.IsEnabled = false;
            DIV.IsEnabled  = false;
            ID.IsEnabled   = false;
            UA.IsEnabled   = false;
            if (SystemClass.CheckConnection())
            {
                ImusCityHallEntities        db        = new ImusCityHallEntities();
                IEnumerable <SubModuleUser> submodule = db.SubModuleUsers.Where(m => m.EmployeeID == App.EmployeeID);
                if (submodule.Count() >= 1)
                {
                    foreach (var module in submodule)
                    {
                        switch (module.SubModule.Acronym)
                        {
                        case "CDS":
                            CDS.IsEnabled = module.SubModule.Acronym == CDS.Name ? true : false;
                            break;

                        case "EMP":
                            EMP.IsEnabled = module.SubModule.Acronym == EMP.Name ? true : false;
                            break;

                        case "CUST":
                            CUST.IsEnabled = module.SubModule.Acronym == CUST.Name ? true : false;
                            break;

                        case "DEPT":
                            DEPT.IsEnabled = module.SubModule.Acronym == DEPT.Name ? true : false;
                            break;

                        case "DIV":
                            DIV.IsEnabled = module.SubModule.Acronym == DIV.Name ? true : false;
                            break;

                        case "ID":
                            ID.IsEnabled = module.SubModule.Acronym == ID.Name ? true : false;
                            break;

                        case "UA":
                            UA.IsEnabled = module.SubModule.Acronym == UA.Name ? true : false;
                            break;
                        }
                    }
                }
                else
                {
                    modules.IsEnabled = false;
                }

                Employee   superAdmin = db.Employees.Find(App.EmployeeID);
                AspNetUser user       = db.AspNetUsers.FirstOrDefault(m => m.UserName == superAdmin.EmployeeNo);

                if (user.AspNetUserRoles.FirstOrDefault().RoleId == "1")
                {
                    SS.Visibility = Visibility.Visible;
                }
            }
            else
            {
                MessageBox.Show(SystemClass.DBConnectionErrorMessage);
            }
        }