public ListEmployeesView(string animationName, TabHelper hlp)
 {
     InitializeComponent();
     TabHlp = hlp;
     employee = new Employee();
     employeeClient = new EmployeesManager();
     if (!string.IsNullOrEmpty(animationName))
     {
         Storyboard animation = (Storyboard)Application.Current.Resources[animationName];
         LayoutRoot.BeginStoryboard(animation);
     }
 }
        private void AddEmployeeBtn_Click(object sender, RoutedEventArgs e)
        {
            Employee emp = new Employee();
            EmployeesManager empc = new EmployeesManager();

            String photoPath = null;
            if (imageEdit1.Source != null && imageEdit1.Source is BitmapImage)
            {
                BitmapImage bi = (BitmapImage)imageEdit1.Source;
                FileStream stream = bi.StreamSource as FileStream;

                photoPath = stream.Name;
                emp.Photo = Validator.ConvertImageToByteArray(photoPath);

            }
            emp.PhotoPath = photoPath;

            String input = null;
            input = LastNameTxtBox.Text;
            if ( !String.IsNullOrEmpty(input))
                emp.EmployeeLastname = input;
            else { MessageBox.Show("Erreur dans le Nom de l'employée"); return; }

            input = FirstNameTxtBox.Text;
            if ( !String.IsNullOrEmpty(input))
                emp.EmployeeFirstname = input;
            else { MessageBox.Show("Erreur dans le Prenom de l'employée"); return; }

            input = TitleTxtBox.Text;
            if ( !String.IsNullOrEmpty(input))
                emp.Title = input;
            else { MessageBox.Show("Erreur dans le Titre de l'employée"); return; }

            DateTime date = BirthDayTxtBox.DateTime.Date;
            if (!String.IsNullOrEmpty(date.ToString()))
                emp.BirthDate = date;
            else { MessageBox.Show("Erreur dans la Date de naissance"); return; }

            // a savoir si un employée est déjà engagé il ya longtemps ????
            emp.HireDate = DateTime.Now;

            emp.Address = AdresseTxtBox.Text;
            emp.Country = CountryTxtBox.Text;
            emp.City = CityTxtBox.Text;
            emp.Region = RegionTxtBox.Text;

            input = ZipCodeTxtBox.Text;
            if (Validator.IsPostalCodeValid(input) || String.IsNullOrEmpty(input))
                emp.PostalCode = input;
            else { MessageBox.Show("Erreur dans le code postal"); return; }

            input = MobileTxtBox.Text;
             //   if (Validator.IsMobPhoneValid(input) || String.IsNullOrEmpty(input))
                emp.Phone1 = input;
             //   else { MessageBox.Show("Erreur dans le Telephone mobile (10 chiffres)"); return; }

            input = FixTxtBox.Text;
            if (Validator.IsFixPhoneValid(input) || String.IsNullOrEmpty(input))
                emp.HomePhone = input;
            else { MessageBox.Show("Erreur dans le Telephone Fix (09 chiffres)"); return; }

            input = EmailTxtBox.Text;
            if (Validator.IsEmailValid(input) || String.IsNullOrEmpty(input))
                emp.EmailAdress = input;
            else { MessageBox.Show("Erreur dans l'Email "); return; }

            ////      emp.ReportsTo   =   ;

            var textRange = new TextRange(NotesRichTxtArea.Document.ContentStart, NotesRichTxtArea.Document.ContentEnd);
            var note = textRange.Text;
            emp.Notes = note;

            emp.HireDate = dateEdit2.DateTime;

            Password pass = new Password();

            input = textEdit1.Text;
            if (!String.IsNullOrEmpty(input))
                pass.Login = input;
            else { MessageBox.Show("Erreur dans le login "); return; }

            input = textEdit2.Text;
            if (!String.IsNullOrEmpty(input))
                pass.Password1 = PasswordClient.CryptePassword(input);
            else { MessageBox.Show("Erreur dans le mot de passe "); return; }

            PasswordClient pc = new PasswordClient();
            pc.AddUser(pass);
            pc.ActivatUser(pass);

            emp.Password = pass;

            emp.Status = 0;
            String s = empc.AddEmployee(emp);
            MessageBox.Show(s);

            imageEdit1.Clear();
            LastNameTxtBox.Clear();
            FirstNameTxtBox.Clear();
            TitleTxtBox.Clear();
            BirthDayTxtBox.Clear();
            AdresseTxtBox.Clear();
            CountryTxtBox.Clear();
            CityTxtBox.Clear();
            RegionTxtBox.Clear();
            ZipCodeTxtBox.Clear();
            MobileTxtBox.Clear();
            FixTxtBox.Clear();
            EmailTxtBox.Clear();
            dateEdit2.Clear();
            NotesRichTxtArea.Document.Blocks.Clear();
            textEdit1.Clear();
        }
        private void EditEmployeeBtn_Click(object sender, RoutedEventArgs e)
        {
            employeeClient = new EmployeesManager();

            if (EmployeesDataGrid.VisibleRowCount == 0) return;

            if (MessageBox.Show("Êtes-vous sûr de vouloir modifier  cet employer?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.No) return;

            int rowHandle = EmployeesDataGrid.View.FocusedRowHandle;

            EmployeesManager empc = new EmployeesManager();
            Employee emp = empc.GetEmployeeByName(EmployeesDataGrid.GetCellValue(rowHandle, "employee_firstname").ToString());

            if (emp == null) return;

            String photo_path = null;

            if (imageEdit1.Source != null && imageEdit1.Source is BitmapImage)
            {
                BitmapImage bi = (BitmapImage)imageEdit1.Source;
                FileStream stream = bi.StreamSource as FileStream;
                if (stream != null)
                {
                    photo_path = stream.Name;
                    emp.Photo = Validator.ConvertImageToByteArray(photo_path);
                }
            }
            emp.PhotoPath = photo_path;

            String input = null;
            input = LastNameTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsAlphabeticValid(input) && !String.IsNullOrEmpty(input))
                emp.EmployeeLastname = input;
            else { MessageBox.Show("Erreur dans le Nom de l'employée"); return; }

            input = FirstNameTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsAlphabeticValid(input) && !String.IsNullOrEmpty(input))
                emp.EmployeeFirstname = input;
            else { MessageBox.Show("Erreur dans le Prenom de l'employée"); return; }

            input = TitleTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsAlphabeticValid(input) || String.IsNullOrEmpty(input))
                emp.Title = input;
            else { MessageBox.Show("Erreur dans le Titre de l'employée"); return; }

            if (BirthDayTxtBox!=null)
            emp.BirthDate = BirthDayTxtBox.DateTime.Date;

            // a savoir si un employée est déjà engagé il ya longtemps ????
            emp.HireDate = DateTime.Now;

            emp.Address = AdresseTxtBox.Text;
            emp.Country = CountryTxtBox.Text;
            emp.City = CityTxtBox.Text;
            emp.Region = RegionTxtBox.Text;

            input = ZipCodeTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsPostalCodeValid(input) || String.IsNullOrEmpty(input))
                emp.PostalCode = input;
            else { MessageBox.Show("Erreur dans le code postal"); return; }

            input = MobileTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            //    if (Validator.IsMobPhoneValid(input) || String.IsNullOrEmpty(input))
                emp.Phone1 = input;
            //    else { MessageBox.Show("Erreur dans le Telephone mobile (10 chiffres)"); return; }

            input = FixTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsFixPhoneValid(input) || String.IsNullOrEmpty(input))
                emp.HomePhone = input;
            else { MessageBox.Show("Erreur dans le Telephone Fix (09 chiffres)"); return; }

            input = EmailTxtBox.Text;
            if (input == null) input = "";
            input = input.Trim();
            if (Validator.IsEmailValid(input) || String.IsNullOrEmpty(input))
                emp.EmailAdress = input;
            else { MessageBox.Show("Erreur dans l'Email "); return; }

            ////      emp.ReportsTo   =   ;

            var textRange = new TextRange(NotesRichTxtArea.Document.ContentStart, NotesRichTxtArea.Document.ContentEnd);
            var note = textRange.Text;
            emp.Notes = note;

            emp.HireDate = dateEdit2.DateTime;

            input = textEdit2.Text;
            if (!input.Equals("Password"))
                emp.Password.Password1 = PasswordClient.CryptePassword(input);

            emp.Status = 0;

            String s = employeeClient.MajEmployee(emp);
            MessageBox.Show(s);

            loadGrid();

            EmployeesDataGrid.View.FocusedRowHandle = rowHandle;
        }
        private void DeleteEmployeeBtn_Click(object sender, RoutedEventArgs e)
        {
            if (EmployeesDataGrid.VisibleRowCount == 0) return;

            if (MessageBox.Show("Êtes-vous sûr de vouloir supprimer  cet employer?", "Confirmation", MessageBoxButton.YesNo) == MessageBoxResult.No) return;
            int rowHandle = EmployeesDataGrid.View.FocusedRowHandle;

            EmployeesManager empc = new EmployeesManager();
            Employee emp = empc.GetEmployeeByName(EmployeesDataGrid.GetCellValue(rowHandle, "employee_firstname").ToString());

            if (emp == null) return;
            empc.DesactivateEmployee(emp);
            loadGrid();
        }
        private void EmployeesDataTable_FocusedRowChanged(object sender, DevExpress.Xpf.Grid.FocusedRowChangedEventArgs e)
        {
            if (EmployeesDataGrid.VisibleRowCount == 0) return;
            int rowHandle = EmployeesDataGrid.View.FocusedRowHandle;
            if (rowHandle < 0) return;
            EmployeesManager empc = new EmployeesManager();
            Employee emp = empc.GetEmployeeByName(EmployeesDataGrid.GetCellValue(rowHandle, "employee_firstname").ToString());

            if (emp == null) return;
            Afficher(emp);
        }
        public static void InitSettings()
        {
            var settings = new Setting
            {
                CompanyName = "entreprise",
                Adresse = "adresse",
                PostalCode = "35000",
                RC = "11111111111",
                NF = "11111111111",
                NIS = "1111111111",
                AI = "11111111111",
                City = "Wilaya",
                Phone = "021234567",
                MobPhone = "0550123456",
                Email = "*****@*****.**",
                FirstTime = true,
                FactureNumber = "1",
                FactureProNumber = "1",
                Licence = "",
                PassWordApp = "demo",

            };

            String s = MajSettings(settings);

            PasswordClient passwordClient = new PasswordClient();
            Password admin = new Password
            {
                Login = "******",
                Password1 = PasswordClient.CryptePassword("admin"),
                Status = 2
            };

            if (passwordClient.IsUserExist(admin))passwordClient.MajUser(admin);
            else passwordClient.AddUser(admin);

            admin = passwordClient.GetPassword("admin");
            var empc = new EmployeesManager();
            var emp = new Employee
            {
                EmployeeFirstname = "admin",
                EmployeeLastname = "admin",
                Status = 1,
                Password = admin
            };
            if (!EmployeesManager.IsEmployeeExist(emp)) empc.AddEmployee(emp);
        }