コード例 #1
0
        public void SaveSector()
        {
            try
            {
                if (SectorList.Count == 15)
                {
                    MessageBox.Show("Maximum number of sectors is reached!\nPlease delete some of the existing \nsector if you want to add a new one!");
                    addNewSector.Close();
                }
                else
                {
                    if (Sector.SectorId == 0)
                    {
                        if (Sector.Description == null)
                        {
                            Sector.Description = "";
                        }
                        bool uniqueSectorName = service.CheckSectorName(Sector.Name);
                        if (!uniqueSectorName)
                        {
                            MessageBoxResult result = MessageBox.Show("Are you sure you want to add the new sector", "Add New Sector", MessageBoxButton.YesNo);
                            if (result == MessageBoxResult.Yes)
                            {
                                int sectorId = service.AddSector(Sector);
                                if (sectorId != 0)
                                {
                                    MessageBox.Show("You have successfully added new sector");
                                    Logging.LoggAction("AddNewSectorViewModel", "Info", "Succesfull add new sector");
                                    addNewSector.Close();
                                }
                            }
                            else
                            {
                                addNewSector.Close();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Name is not unique!");
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
コード例 #2
0
        public void SaveExecute()
        {
            try
            {
                User.GenderId   = selectedGender.GenderId;
                User.LocationId = selectedLocation.LocationId;
                int sectorId = service.CheckSectorName(User.SectorName);
                if (sectorId == 0)
                {
                    sectorId = service.AddSector(User.SectorName);
                }
                User.SectorId = sectorId;
                if (User.UserId == 0)
                {
                    bool uniqueJmbg     = service.CheckJmbg(User.Jmbg);
                    bool uniqueIdNumber = service.CheckIDNumber(User.IDNumber);

                    if (!uniqueIdNumber && !uniqueJmbg)
                    {
                        if (selectedMenager == null)
                        {
                            User.MenagerId = 0;
                        }
                        else
                        {
                            User.MenagerId = selectedMenager.UserId;
                        }
                        if (service.AddUser(User) != 0)
                        {
                            MessageBox.Show("You have successfully added new employee");
                            Thread t = new Thread(() => { Logging.LoggAction("Add new emplyee", "Success", "Succesfully added new emplyee"); });
                            t.IsBackground = true;
                            t.Start();
                        }
                    }
                    else if (uniqueJmbg)
                    {
                        MessageBox.Show("Jmbg is not unique!");
                    }
                    else if (uniqueIdNumber)
                    {
                        MessageBox.Show("ID number is not unique!");
                    }
                }
                else
                {
                    bool uniqueJmbg     = service.Check_JMBG_Update(User.Jmbg, User.UserId);
                    bool uniqueIdNumber = service.Check_IDNumber_Update(User.IDNumber, User.UserId);
                    User.MenagerId = selectedMenagerForEdit.UserId;
                    if (uniqueIdNumber && uniqueJmbg)
                    {
                        service.UpdateUser(User);
                        MessageBox.Show("You have successfully changed employee data");
                        Thread t = new Thread(() => { Logging.LoggAction("Update emplyee", "Success", "Succesfully updated emplyee"); });
                        t.IsBackground = true;
                        t.Start();
                    }
                    else if (!uniqueJmbg)
                    {
                        MessageBox.Show("Jmbg is not match with user!");
                    }
                    else if (!uniqueIdNumber)
                    {
                        MessageBox.Show("ID number is not not match with user!");
                    }
                }
                MainWindow main = new MainWindow();
                main.Show();
                addEditUserView.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }