Exemplo n.º 1
0
        private void TryToConnect()
        {
            string passwordEntered = passwordTextBox.Text;

            LoginTools.Login          = userTextBox.Text;
            LoginTools.HashedPassword = LoginTools.Sha256_hash(passwordEntered);
            try
            {
                if (LoginTools.CheckConnection())
                {
                    if (LoginTools.Employee.EstLicencie)
                    {
                        throw new UnauthorizedAccessException("Cet utilisateur n'a pas la permission d'accéder à l'application");
                    }
                    _appWindow.Login();
                }
                else
                {
                    errorLabel.Visible   = true;
                    passwordTextBox.Text = "";
                }
            }
            catch (UnauthorizedAccessException exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 2
0
        public MapUserControl(HomeUserControl home)
        {
            InitializeComponent();
            LoginTools.CheckConnection();
            HomeUserControl = home;
            _db             = new DataBase();

            _cursorAction = CursorAction.Default;
            _moving       = false;
            _offsetMoving = new Point();

            FillListsControlsDromDb();

            LoadLocationsFromDb();

            if (!_db.App.Any(m => m.Fond_Image != null))
            {
                _mode = MapMode.LoadImage;
            }
            else
            {
                MemoryStream ms        = new MemoryStream(_db.App.FirstOrDefault().Fond_Image);
                var          imageJpeg = Image.FromStream(ms);
                _image = new Bitmap(imageJpeg);
                ms.Close();
                pictureBox.Image = _image;
                _mode            = MapMode.Normal;
            }
            ChangeMode(_mode);
        }
Exemplo n.º 3
0
        private void CreateNewLocation(Type_Emplacement type, int x = 30, int y = 30)
        {
            LoginTools.CheckConnection();
            Emplacement newLocation = new Emplacement();

            _db.Emplacement.Add(newLocation);
            newLocation.Taille_X = 10;
            newLocation.Taille_Y = 10;
            int i = _locationsList.Count;

            while (_db.Emplacement.Any(a => a.Nom_Emplacement.Equals("Emplacement " + i)))
            {
                i++;
            }
            foreach (GraphicLocation graphicLocation in _locationsList)
            {
                if (graphicLocation.Location.Nom_Emplacement.Equals("Emplacement " + i))
                {
                    i++;
                }
            }
            newLocation.Nom_Emplacement  = "Emplacement " + i;
            newLocation.Type_Emplacement = type;
            GraphicLocation newGraphicLocation = new GraphicLocation(newLocation);

            newGraphicLocation.Move(new Point(x, y), pictureBox);
            _locationsList.Add(newGraphicLocation);
            SelectedLocation = newGraphicLocation;
            Refresh();
        }
Exemplo n.º 4
0
 private void LoadLocationsFromDb()
 {
     LoginTools.CheckConnection();
     _locationsList = new List <GraphicLocation>();
     foreach (Emplacement loc in _db.Emplacement)
     {
         _locationsList.Add(new GraphicLocation(loc));
     }
     SelectedLocation = null;
     pictureBox.Refresh();
 }
Exemplo n.º 5
0
        private void ValidateChangesButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            LoginTools.CheckConnection();

            foreach (GraphicLocation location in _locationsList)
            {
                if (location.Location.Code_Emplacement == 0)
                {
                    _db.Emplacement.Add(location.Location);
                }
            }
            var toDelete = new List <int>();

            foreach (Emplacement location in _db.Emplacement)
            {
                bool exist = _locationsList.Any(graphicLocation => location.Code_Emplacement
                                                == graphicLocation.Location.Code_Emplacement);
                if (!exist)
                {
                    toDelete.Add(location.Code_Emplacement);
                }
            }

            foreach (int id in toDelete)
            {
                foreach (Incident incident in _db.Incident.Where(a => a.Code_Emplacement == id))
                {
                    _db.Incident.Remove(incident);
                }
                foreach (Loge loge in _db.Loge.Where(a => a.Code_Emplacement == id))
                {
                    _db.Loge.Remove(loge);
                }
                _db.Emplacement.Remove(_db.Emplacement.FirstOrDefault(a => a.Code_Emplacement == id));
            }
            try
            {
                _db.SaveChanges();
                Cursor.Current = Cursors.Default;
            }
            catch (DbUpdateException exception)
            {
                if (exception.InnerException?.InnerException != null)
                {
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show(Resources.db_save_error + exception.InnerException.InnerException.Message);
                }
                _db = new DataBase();
                FillListsControlsDromDb();
                LoadLocationsFromDb();
            }
        }
Exemplo n.º 6
0
        private void OkButton_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (surnameTextBox.Text == "" || nameTextBox.Text == "" || emailTextBox.Text == "" ||
                    phoneTextBox.Text == "" || loginTextBox.Text == "" || passwordTextBox.Text == "")
                {
                    throw new Exception(Resources.compulsary_values_exception);
                }

                if (surnameTextBox.Text.Any(char.IsDigit))
                {
                    throw new Exception("Le prénom ne peut contenir de valeur numérique.");
                }

                if (nameTextBox.Text.Any(char.IsDigit))
                {
                    throw new Exception("Le nom ne peut contenir de valeur numérique.");
                }

                try
                {
                    _newEmployee.Personne.Email = new MailAddress(emailTextBox.Text).ToString();
                }
                catch (FormatException)
                {
                    throw new Exception(Resources.unrecognized_email);
                }


                _newEmployee.Personne.Nom_Personne    = surnameTextBox.Text;
                _newEmployee.Personne.Prenom_Personne = nameTextBox.Text;
                _newEmployee.Personne.Date_Naissance  = birthDateTimePicker.Value.Date;
                _newEmployee.Personne.Telephone       = phoneTextBox.Text;
                _newEmployee.Personne.Adresse         = addressTextBox.Text;
                _newEmployee.Personne.Email           = emailTextBox.Text;
                _newEmployee.Login    = loginTextBox.Text;
                _newEmployee.Password = LoginTools.Sha256_hash(passwordTextBox.Text);

                _db.Employe.Add(_newEmployee);
                _db.SaveChanges();
                Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Exemplo n.º 7
0
        private void TypePanel_MouseDown(object sender, MouseEventArgs e)
        {
            Panel panel = getParentTypePanel(sender);

            if (e.Clicks == 2)
            {
                LoginTools.CheckConnection();
                Label            typeLabel    = (Label)panel.Controls.Find("typeLabel", true).First();
                Type_Emplacement typeLocation = _db.Type_Emplacement.FirstOrDefault(a => a.Libelle_Type.Equals(typeLabel.Text));
                CreateNewLocation(typeLocation);
            }
            else
            {
                panel.DoDragDrop(panel, DragDropEffects.Move);
            }
        }
Exemplo n.º 8
0
 private void ImportMapButton_Click(object sender, EventArgs e)
 {
     using (FileDialog fd = new OpenFileDialog())
     {
         fd.Title  = Resources.select_background_image;
         fd.Filter = Resources.images_files_formats;
         if (fd.ShowDialog() == DialogResult.OK)
         {
             try
             {
                 importMapPanel.Visible = false;
                 _image = new Bitmap(fd.FileName);
                 _image.SetResolution(800, 600);
                 LoginTools.CheckConnection();
                 App app = _db.App.FirstOrDefault();
                 if (app == null)
                 {
                     app = new App();
                     _db.App.Add(app);
                 }
                 MemoryStream jpegStream = new MemoryStream();
                 _image.Save(jpegStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                 if (_image == null)
                 {
                     throw new FileLoadException();
                 }
                 app.Fond_Image = jpegStream.ToArray();
                 _db.SaveChanges();
                 pictureBox.Image = _image;
                 _mode            = MapMode.Normal;
                 ChangeMode(_mode);
             }
             catch (FileNotFoundException)
             {
                 MessageBox.Show(Resources.file_not_found_please_retry);
             }
             catch (FileLoadException)
             {
                 MessageBox.Show(Resources.error_when_opening_the_file_please_retry);
             }
         }
     }
 }
Exemplo n.º 9
0
 private void OkButton_Click(object sender, EventArgs e)
 {
     if (oldPasstextBox.Text == "" || newPassTextBox.Text == "" || confirmPassTextBox.Text == "")
     {
         MessageBox.Show(Resources.some_not_filled);
     }
     else if (LoginTools.Sha256_hash(oldPasstextBox.Text) != _concernedEmployee.Password)
     {
         MessageBox.Show(Resources.old_pass_incorrect);
     }
     else if (newPassTextBox.Text != confirmPassTextBox.Text)
     {
         MessageBox.Show(Resources.not_corresponding_messages);
     }
     else
     {
         _concernedEmployee.Password = LoginTools.Sha256_hash(newPassTextBox.Text);
         Close();
     }
 }
Exemplo n.º 10
0
        private void AddEmployeePhotoPictureBox_Click(object sender, EventArgs e)
        {
            using (FileDialog fd = new OpenFileDialog())
            {
                fd.Title  = Resources.select_background_image;
                fd.Filter = Resources.images_files_formats;
                if (fd.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;
                    try
                    {
                        Bitmap image = new Bitmap(fd.FileName);
                        image.SetResolution(50, 70);
                        LoginTools.CheckConnection();

                        int code     = int.Parse(employeesListView.SelectedItems[0].Name);
                        var employee = Db.Employe.Find(code);

                        if (employee != null)
                        {
                            MemoryStream jpegStream = new MemoryStream();
                            image.Save(jpegStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            employee.Photo = jpegStream.ToArray();
                            Db.SaveChanges();
                            pictureBox.Image = image;
                        }
                    }
                    catch (FileNotFoundException)
                    {
                        MessageBox.Show(Resources.file_not_found_please_retry);
                    }
                    catch (FileLoadException)
                    {
                        MessageBox.Show(Resources.error_when_opening_the_file_please_retry);
                    }
                    Cursor.Current = Cursors.Default;
                }
            }
        }
Exemplo n.º 11
0
        private void UpdateRightMenu()
        {
            if (SelectedLocation == null)
            {
                nullSelectionPanel.Visible = true;
                nullSelectionPanel.BringToFront();
                return;
            }
            nullSelectionPanel.Visible = false;
            _updatingRightMenu         = true;
            LoginTools.CheckConnection();
            if (SelectedLocation.Location.Type_Emplacement.Est_Reservable)
            {
                reserveButton.Enabled = true;
                if (
                    _db.Reservation.Where(r => r.Date_Debut < dateTimePicker.Value && dateTimePicker.Value < r.Date_Fin)
                    .SelectMany(a => a.Loge)
                    .Any(l => l.Code_Emplacement == SelectedLocation.Location.Code_Emplacement))
                {
                    resStateLabel.Text = Resources.booked;
                    reserveButton.Text = Resources.unbook;
                }
                else
                {
                    resStateLabel.Text = Resources.free;
                    reserveButton.Text = Resources.book;
                }
            }
            else
            {
                reserveButton.Enabled = false;
                reserveButton.Text    = Resources.book;
                resStateLabel.Text    = Resources.not_bookable;
            }

            locationNameLabel.Text = SelectedLocation.Location.Nom_Emplacement;

            catLocationLabel.Text = SelectedLocation.Location.Type_Emplacement.Libelle_Type;
            catLocationListView.Items.Clear();

            foreach (int i in carCheckedListBox.CheckedIndices)
            {
                carCheckedListBox.SetItemCheckState(i, CheckState.Unchecked);
            }

            foreach (Caracteristique_Emplacement car in SelectedLocation.Location.Caracteristique_Emplacement)
            {
                catLocationListView.Items.Add(car.Description);
                carCheckedListBox.SetItemChecked(carCheckedListBox.Items.IndexOf(car), true);
            }

            locationIssuesListBox.Items.Clear();
            foreach (var issue in _db.Incident.Where(
                         a => a.Code_Emplacement == SelectedLocation.Location.Code_Emplacement &&
                         a.Date_Resolution == null))
            {
                var item = new ListViewItem(new[] { issue.Type_Incident.Type_Incident1 })
                {
                    Name = issue.Code_Incident.ToString()
                };
                locationIssuesListBox.Items.Add(item);
            }


            locationNameTextBox.DataBindings.Clear();
            locationNameTextBox.DataBindings.Add("Text", SelectedLocation.Location, "Nom_Emplacement", false, DataSourceUpdateMode.OnPropertyChanged);

            typeLocationComboBox.DataBindings.Clear();
            Binding typeLocationBinding =
                typeLocationComboBox.DataBindings.Add("SelectedItem", SelectedLocation.Location, "Type_Emplacement", true, DataSourceUpdateMode.OnPropertyChanged);

            typeLocationBinding.BindingComplete += (sender, args) => pictureBox.Refresh();

            rightPanel.Refresh();
            _updatingRightMenu = false;
        }
Exemplo n.º 12
0
 public void Sha256FailedTest()
 {
     Assert.IsFalse(LoginTools.Sha256_hash("unpremiersha").Equals(LoginTools.Sha256_hash("unautresha")));
 }
Exemplo n.º 13
0
 public void Sha256SuccessfulTest()
 {
     Assert.IsTrue(LoginTools.Sha256_hash("lesha").Equals(LoginTools.Sha256_hash("lesha")));
 }
Exemplo n.º 14
0
 public void CheckConnectionFailedWithoutPermissionTest()
 {
     LoginTools.Login          = "******";
     LoginTools.HashedPassword = LoginTools.Sha256_hash("1234");
     Assert.IsFalse(LoginTools.CheckConnection());
 }
Exemplo n.º 15
0
 public void CheckConnectionFailedTest()
 {
     LoginTools.Login          = "******";
     LoginTools.HashedPassword = LoginTools.Sha256_hash("false");
     Assert.IsFalse(LoginTools.CheckConnection());
 }
Exemplo n.º 16
0
 public void CheckConnectionSuccessfulTest()
 {
     LoginTools.Login          = "******";
     LoginTools.HashedPassword = LoginTools.Sha256_hash("success");
     Assert.IsTrue(LoginTools.CheckConnection());
 }