public CreateManagerViewModel(CreateManager cmOpen) { createManagerWindow = cmOpen; SectorList = GetSectors(); LevelList = GetLevels(); Employe = new tblEmploye(); Sector = new tblSector(); Level = new tblLevel(); }
public AddEmployeViewModel(AddEmploye addEmployeOpen) { addEmploye = addEmployeOpen; LocationList = GetLocations(); GenderList = GetGenders(); Location = new tblLOCATION(); Gender = new tblGender(); Employe = new tblEmploye(); Sector = new tblSector(); }
private void SaveExecute() { try { tblEmploye newEmploye = new tblEmploye(); newEmploye.FirstName = Employe.FirstName; newEmploye.Surname = Employe.Surname; newEmploye.JMBG = Employe.JMBG; newEmploye.Salary = Convert.ToInt32(Employe.Salary); newEmploye.Account = Employe.Account; newEmploye.Pasword = Employe.Pasword; newEmploye.Username = Employe.Username; newEmploye.Position = Employe.Position; newEmploye.Email = Employe.Email; string birthdate = cmvm.CalculateBirth(Employe.JMBG); if (KeyCheck(newEmploye.JMBG) == true && PasswordCheck(newEmploye.Pasword) == true && UsernameCheck(newEmploye.Username) == true && NumbersOnly(newEmploye.JMBG) == true) { newEmploye.DateOfBirth = cmvm.CalculateBirth(Employe.JMBG); context.tblEmployes.Add(newEmploye); context.SaveChanges(); MessageBox.Show("Employe is created"); ListEmploye = EmpList(); } else { MessageBox.Show("JMBG or password or username already exist"); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException MessageBox.Show(message); raise = new InvalidOperationException(message, raise); } } throw raise; } }
private void SaveExecute() { try { tblEmploye newEmploye = new tblEmploye(); newEmploye.FirstName = Employe.FirstName; newEmploye.Surname = Employe.Surname; newEmploye.JMBG = Employe.JMBG; newEmploye.Salary = Convert.ToInt32(Employe.Salary); newEmploye.Account = Employe.Account; newEmploye.Pasword = Employe.Pasword; newEmploye.Username = Employe.Username; newEmploye.Position = Employe.Position; newEmploye.Email = Employe.Email; string birthdate = CalculateBirth(Employe.JMBG); newEmploye.DateOfBirth = DateTime.ParseExact(CalculateBirth(Employe.JMBG), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); context.tblEmployes.Add(newEmploye); context.SaveChanges(); tblManager newManager = new tblManager(); newManager.EmployeID = newEmploye.EmployeID; newManager.SectorID = Sector.SectorID; newManager.LevelID = Level.LevelID; context.tblManagers.Add(newManager); context.SaveChanges(); MessageBox.Show("Manager is created."); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException MessageBox.Show(message); raise = new InvalidOperationException(message, raise); } } throw raise; } }
private void CreateEmployeExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; tblEmploye newEmploye = new tblEmploye(); newEmploye.Gender = Gender; newEmploye.EmployeFlor = Floor; if (CheckCredentials(newAll.Username, newAll.Pasword) == true && CheckGender(newEmploye.Gender) == true && CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == true) { newAll.DateOfBirth = All.DateOfBirth.ToString(); context.tblAlls.Add(newAll); context.SaveChanges(); newEmploye.AllIDemp = newAll.All_ID; newEmploye.Citizenship = Citizen; newEmploye.Engagment = Engagment.engName; context.tblEmployes.Add(newEmploye); context.SaveChanges(); MessageBox.Show("Employe is created"); } else { MessageBox.Show("Possible errors:\nPasword or username already exists\nInvalid gender input\nSelected floor can not be chosen\nbecause it does not have manager"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void DeleteUserExecute() { try { if (Employe != null) { using (context context = new context()) { //taking registration number from selected user string IdNumber = Employe.IdNumber; //inserting message box that will be shown when delete button is pressed MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure that you want to delete employe?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { //finding user and card that needs to be deleted, finding them with registration number tblEmploye employeToDelete = (from r in context.tblEmployes where r.IdNumber == IdNumber select r).First(); //removing from database=> both user and his ID card context.tblEmployes.Remove(employeToDelete); // saving changes in database context.SaveChanges(); // writing action into file //Write.Writer.WriteDelete(userToDelete); //// refreshing => getting new state from database ListEmploye = GetAllEmployes(); } // in case "No" is clicked in line 77 else { MessageBox.Show("Deleting proccess is stoped"); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void DeleteExecute() { try { using (Entity2 context = new Entity2()) { tblEmploye employeToDelete = (from x in context.tblEmployes where x.EmployeID == Employe.EmployeID select x).First(); List <int> foreignKeysList = new List <int>(); List <tblManager> managersList = context.tblManagers.ToList(); for (int i = 0; i < managersList.Count; i++) { foreignKeysList.Add(managersList[i].EmployeID.GetValueOrDefault()); } MessageBoxResult mbr = MessageBox.Show("Are you sure you want to delete employe?", "Delete confirmation", MessageBoxButton.YesNo); if (mbr == MessageBoxResult.Yes) { if (foreignKeysList.Contains(employeToDelete.EmployeID)) { tblManager managerToDelete = (from x in context.tblManagers where x.EmployeID == Employe.EmployeID select x).First(); context.tblManagers.Remove(managerToDelete); } context.tblEmployes.Remove(employeToDelete); context.SaveChanges(); MessageBox.Show("Employe is deleted"); ListEmploye = EmpList(); Employe = new tblEmploye(); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void SaveExecute() { try { tblEmploye newEmploye = new tblEmploye(); newEmploye.FirstName = Employe.FirstName; newEmploye.Surname = Employe.Surname; newEmploye.JMBG = Employe.JMBG; newEmploye.Salary = Convert.ToInt32(Employe.Salary); newEmploye.Account = Employe.Account; newEmploye.Pasword = Employe.Pasword; newEmploye.Username = Employe.Username; newEmploye.Position = Employe.Position; newEmploye.Email = Employe.Email; string birthdate = CalculateBirth(Employe.JMBG); CreateManager cm = new CreateManager(); cm.tbJMBG.Text = ""; //method checks if jmbg already exists in database AND ONLY IF NOT proceeds to save employe if (KeyCheck(newEmploye.JMBG) == true && PasswordCheck(newEmploye.Pasword) == true && UsernameCheck(newEmploye.Username) == true && NumbersOnly(newEmploye.JMBG) == true) { newEmploye.DateOfBirth = CalculateBirth(Employe.JMBG); context.tblEmployes.Add(newEmploye); context.SaveChanges(); tblManager newManager = new tblManager(); newManager.EmployeID = newEmploye.EmployeID; newManager.SectorID = Sector.SectorID; newManager.LevelID = Level.LevelID; context.tblManagers.Add(newManager); context.SaveChanges(); MessageBox.Show("Manager is created."); if (!worker.IsBusy) { worker.RunWorkerAsync(); } } else { MessageBox.Show("JMBG or password or username already exists"); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException MessageBox.Show(message); raise = new InvalidOperationException(message, raise); } } throw raise; } }
private void LoginExecute() { try { if (Password == "WPFadmin" && Username == "WPFadmin") { CreateManager createManager = new CreateManager(); createManager.ShowDialog(); } List <String> UsernameList = new List <string>(); List <tblEmploye> EmployeList = context.tblEmployes.ToList(); foreach (tblEmploye item in EmployeList) { UsernameList.Add(item.Username); } List <string> PasswordList = new List <string>(); foreach (tblEmploye item in EmployeList) { PasswordList.Add(item.Pasword); } if (!PasswordList.Contains(Password) || !UsernameList.Contains(Username)) { MessageBox.Show("Username or password does not exist."); } else { tblEmploye employeID1 = (from r in context.tblEmployes where r.Pasword == Password select r).First(); tblEmploye employeID2 = (from r in context.tblEmployes where r.Username == Username select r).First(); if (employeID1.EmployeID != employeID2.EmployeID) { MessageBox.Show("Parametres exist but they are not matched."); } //ulogovan ali ne zna se ko je if (employeID1.EmployeID == employeID2.EmployeID) { List <int> employeInManagerList = new List <int>(); List <tblManager> managerList = context.tblManagers.ToList(); foreach (tblManager item in managerList) { employeInManagerList.Add(item.EmployeID.GetValueOrDefault()); } //menager loged in if (employeInManagerList.Contains(employeID1.EmployeID)) { tblManager manager = (from r in context.tblManagers where r.EmployeID == employeID1.EmployeID select r).First(); //modify mendager if (manager.LevelID == 1) { ModifyMenager ms = new ModifyMenager(); ms.ShowDialog(); } //readonly menager if (manager.LevelID == 2) { MessageBox.Show("ReadOnly manager"); } } //user if (!employeInManagerList.Contains(employeID1.EmployeID)) { MessageBox.Show("User"); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public ModifyManagerViewModel(ModifyMenager mmOpen) { modifyMenagerWindow = mmOpen; Employe = new tblEmploye(); ListEmploye = EmpList(); }
private void SaveExecute() { try { tblEmploye newEmploye = new tblEmploye(); newEmploye.UserName = Employe.UserName; newEmploye.Surname = Employe.Surname; newEmploye.IdNumber = Employe.IdNumber; newEmploye.Number = Employe.Number; newEmploye.JMBG = Employe.JMBG; newEmploye.DateOfBirth = CalculateBirth(Employe.JMBG); //for sector string newSector = Sector.SectorName; tblSector newSectorObject = new tblSector(); newSectorObject.SectorName = newSector; List <tblSector> sectorList = context.tblSectors.ToList(); List <string> sectorNames = new List <string>(); for (int i = 0; i < sectorList.Count; i++) { sectorNames.Add(sectorList[i].SectorName); } if (sectorNames.Contains(newSectorObject.SectorName)) { tblSector sectorToFind = new tblSector(); sectorToFind = (from r in context.tblSectors where r.SectorName == newSectorObject.SectorName select r).First(); newEmploye.SectorID = sectorToFind.SectorID; context.SaveChanges(); } else { context.tblSectors.Add(newSectorObject); context.SaveChanges(); newEmploye.SectorID = newSectorObject.SectorID; context.SaveChanges(); } newEmploye.GenderID = Gender.GenderID; string adress = Location.Adress; if (Location.Adress == "Adresa1") { Location.LocationID = 1; } if (Location.Adress == "Adresa2") { Location.LocationID = 1; } if (Location.Adress == "Adresa3") { Location.LocationID = 3; } if (Location.Adress == "Adresa4") { Location.LocationID = 4; } if (Location.Adress == "Adresa5") { Location.LocationID = 5; } newEmploye.LocationID = Location.LocationID; context.tblEmployes.Add(newEmploye); context.SaveChanges(); addEmploye.Close(); } catch (Exception ex) { MessageBox.Show("Error occured. Make sure that you have provided valid JMBG. Please fix the problems and try again." + ex.ToString()); } }
private void CreateEmployeExecute() { try { using (Entity context = new Entity()) { CreateManager cm = new CreateManager(); tblAll newAll = new tblAll(); //collecting data from text boxes including validations newAll.FirstName = Name; newAll.Surname = Surname; newAll.Email = Mail; newAll.Username = Username; newAll.Pasword = Password; tblEmploye newEmploye = new tblEmploye(); newEmploye.Gender = Gender; newEmploye.EmployeFlor = Floor; newAll.DateOfBirth = All.DateOfBirth; //email must be unique if (CheckMail(newAll.Email) == false) { MessageBox.Show("E-mail already exists"); } //username must be unique else if (CheckCredentials(newAll.Username) == false) { MessageBox.Show("Username already exists"); } //if everything is ok than proced with saving else if (CheckCredentials(newAll.Username) == true && CheckGender(newEmploye.Gender) == true && CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == true && newAll.DateOfBirth < DateTime.Now.AddYears(-18) && CheckMail(newAll.Email) == true) { context.tblAlls.Add(newAll); context.SaveChanges(); //give ID from user table to foreign key in employe table newEmploye.AllIDemp = newAll.All_ID; newEmploye.Citizenship = Citizen; newEmploye.Engagment = Engagment.engName; context.tblEmployes.Add(newEmploye); context.SaveChanges(); MessageBox.Show("Employe is created"); Name = ""; Surname = ""; Mail = ""; Username = ""; Password = ""; Gender = ""; Floor = 0; Citizen = ""; } //NOTE: look at message boxes and you will realise what is the problem else if (CheckFloor(newEmploye.EmployeFlor.GetValueOrDefault()) == false) { MessageBox.Show("Input for floor must be changed because selected floor does not have manager"); } else if (CheckGender(newEmploye.Gender) == false) { MessageBox.Show("Invalid gender input"); } else if (newAll.DateOfBirth > DateTime.Now.AddYears(-18)) { MessageBox.Show("Employe must be at least 18 years old"); } else { MessageBox.Show("Make sure that all fields contain valid values"); } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public void DeleteUserExecute() { try { if (Employe != null) { using (Entity context = new Entity()) { //taking registration number from selected user int IdNumber = Employe.EmployeID; //inserting message box that will be shown when delete button is pressed MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure that you want to delete employe?", "Delete Confirmation", MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { List <int> employeInManagerList = new List <int>(); List <tblManager> managerList = context.tblManagers.ToList(); foreach (tblManager item in managerList) { employeInManagerList.Add(item.EmployeID.GetValueOrDefault()); } //menager loged in if (employeInManagerList.Contains(IdNumber)) { tblManager managerToDelete = (from r in context.tblManagers where r.EmployeID == IdNumber select r).First(); context.tblManagers.Remove(managerToDelete); context.SaveChanges(); } List <int> employeInReportList = new List <int>(); List <tblReport> reportList = context.tblReports.ToList(); foreach (tblReport item in reportList) { employeInReportList.Add(item.EmployeID.GetValueOrDefault()); } if (employeInReportList.Contains(IdNumber)) { tblReport reportToDelete = (from r in context.tblReports where r.EmployeID == IdNumber select r).First(); context.tblReports.Remove(reportToDelete); context.SaveChanges(); } //finding user and card that needs to be deleted, finding them with registration number tblEmploye employeToDelete = (from r in context.tblEmployes where r.EmployeID == IdNumber select r).First(); //removing from database=> both user and his ID card context.tblEmployes.Remove(employeToDelete); // saving changes in database context.SaveChanges(); // writing action into file //Write.Writer.WriteDelete(userToDelete); //// refreshing => getting new state from database ListEmploye = context.tblEmployes.ToList(); } // in case "No" is clicked in line 77 else { MessageBox.Show("Deleting proccess is stoped"); } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }