コード例 #1
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());
            }
        }