示例#1
0
        private void BtnValider_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(txtMatricule.Text) ||
                    string.IsNullOrWhiteSpace(txtNomChauffeur.Text) ||
                    string.IsNullOrWhiteSpace(txtPrenomsChauffeur.Text) ||
                    string.IsNullOrWhiteSpace(txtTelephone1.Text))
                {
                    MessageBox.Show("Veuillez remplir les champs obligatoires !", "mTransport", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                else
                {
                    Chauffeur M = new Chauffeur();
                    M.Matricule           = txtMatricule.Text;
                    M.NomChauffeur        = txtNomChauffeur.Text;
                    M.PrenomChauffeur     = txtPrenomsChauffeur.Text;
                    M.AdresseChauffeur    = txtAdresse.Text;
                    M.Telephone1Chauffeur = txtTelephone1.Text;
                    M.Telephone2Chauffeur = txtTelephone2.Text;
                    M.DateEmbauche        = txtDateEmbauche.SelectedDate;
                    M.PersonneAPrevenir   = txtPersonneAPrevenir.Text;
                    if (txtImage.Source == null)
                    {
                        M.PhotoChauffeur = null;
                    }
                    else
                    {
                        M.PhotoChauffeur = Hex.ToHexString(ImageConverter.ToArray(ImageConverter.FromImage((BitmapSource)txtImage.Source)));
                    }


                    if (Id > 0)
                    {
                        M.Id = Id;
                        M.Update();
                        MessageBox.Show("Modification effectuée !", "mTransport", MessageBoxButton.OK, MessageBoxImage.Information);
                        LoadTabChauffeur();
                        GriserChamps();
                        Id = 0;
                    }
                    else
                    {
                        M.Insert();
                        ListChauffeur.Add(M);
                        TabChauffeur.Items.Refresh();
                        MessageBox.Show("Enregistrement effectué !", "mTransport", MessageBoxButton.OK, MessageBoxImage.Information);
                        GriserChamps();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
 private void BtnSupprimer_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Chauffeur T = TabChauffeur.SelectedItem as Chauffeur;
         T.Supprime = true;
         T.Update();
         ListChauffeur.Remove(T);
         TabChauffeur.Items.Refresh();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }