private void BtnNouveauFournisseurServ_Click(object sender, EventArgs e) { try { bool fournisseurExiste = !db.AgeFournisseursServicesFournitures .Any(serf => serf.NomFournisseurServiceFourniture == txtNomFournServ.Text && serf.Localite == txtLocaliteFournServ.Text); bool nomValide = Validation.ChampsVide(txtNomFournServ.Text); bool localiteValide = Validation.ChampsVide(txtLocaliteFournServ.Text); bool soldeValide = Validation.EstUnChiffre(txtSoldeInitialeDetteFournServ.Text); AgeFournisseursServicesFourniture fsf = new AgeFournisseursServicesFourniture { NomFournisseurServiceFourniture = txtNomFournServ.Text, Localite = txtLocaliteFournServ.Text, SoldeDette = int.Parse(txtSoldeInitialeDetteFournServ.Text) }; db.AgeFournisseursServicesFournitures.Add(fsf); db.SaveChanges(); MessageBox.Show("Une nouveau fournisseur de services ou de fournitures a été ajouté avec succès"); txtNomFournServ.Text = ""; txtLocaliteFournServ.Text = ""; txtSoldeInitialeDetteFournServ.Text = "00"; LoadData(); } catch (Exception) { MessageBox.Show("Veuillez vérifier les données à enregistrer."); } }
private void BtnAchatServiceFourniture_Click(object sender, EventArgs e) { try { bool respAchatPresent = db.AgeEmployes.Any(em => em.PrenomNom == cbxRespServFourn.Text); bool fournPresent = db.AgeFournisseursServicesFournitures .Any(fs => fs.NomFournisseurServiceFourniture == cbxNomFournServFourn.Text); bool descriptionAjoutee = !string.IsNullOrEmpty(txtDescription.Text); AgeEmploye tresoriere; if (int.Parse(txtMontantPayeServFourn.Text) > 0) { bool montantValide = Validation.VerifierChampsMontant(txtMontantPayeServFourn.Text); bool tresorierePresente = db.AgeEmployes.Any(em => em.PrenomNom == cbxTresoriere.Text); } AgeEmploye emp = db.AgeEmployes.First(em => em.PrenomNom == cbxRespServFourn.Text); AgeFournisseursServicesFourniture fsf = db.AgeFournisseursServicesFournitures.First ( fs => fs.NomFournisseurServiceFourniture == cbxNomFournServFourn.Text ); ResComptesTresorerie cpte = db.ResComptesTresoreries.FirstOrDefault(c => c.NomCompte == cbxComptePaiement.Text); ResServicesFourniture sf = db.ResServicesFournitures.FirstOrDefault(s => s.NomServiceFourniture == cbxNomServFourniture.Text); if (Validation.VerifierChampsMontant(txtMontantServFourn.Text)) { EveAcquisitionServicesFourniture asf = new EveAcquisitionServicesFourniture { Date = DateTime.Parse(dtpDateAchatServFourn.Text), Description = txtDescription.Text, Montant = int.Parse(txtMontantServFourn.Text), CodeServiceFourniture = sf.CodeServiceFourniture, CodeFournisseurServiceFourniture = fsf.CodeFournisseurServiceFourniture, CodeEmploye = emp.CodeEmploye, }; db.EveAcquisitionServicesFournitures.Add(asf); db.SaveChanges(); if (int.Parse(txtMontantPayeServFourn.Text) > 0 && Validation.VerifierChampsMontant(txtMontantPayeServFourn.Text)) { if (Tresorerie.IlYaAssezDeFondsDansLeCompte(cbxComptePaiement, txtMontantPayeServFourn)) { tresoriere = db.AgeEmployes.First(em => em.PrenomNom == cbxTresoriere.Text); EveDecaissement decaiss = new EveDecaissement { CodeAcquisitionServiceFourniture = asf.CodeAcquisitionServiceFourniture, Description = sf.NomServiceFourniture, DateDecaissement = asf.Date, CodeEmploye = tresoriere.CodeEmploye, CodeCompte = cpte.CodeCompte, Montant = int.Parse(txtMontantPayeServFourn.Text), CodeFournisseurService = fsf.CodeFournisseurServiceFourniture, }; db.EveDecaissements.Add(decaiss); db.SaveChanges(); } } MessageBox.Show("Le nouvel achat de service ou de fourniture a été enregistré avec succès!"); txtMontantServFourn.Text = ""; txtMontantPayeServFourn.Text = ""; } } catch (Exception) { MessageBox.Show("Erreur: La transaction n'a pas été enregistré."); } }
private void BtnEnregistrerDecaissement_Click(object sender, EventArgs e) { if (Tresorerie.IlYaAssezDeFondsDansLeCompte(cbxCompte, txtMontantPaye)) { ResComptesTresorerie cpte = db.ResComptesTresoreries.FirstOrDefault(c => c.NomCompte == cbxCompte.Text); AgeEmploye em = db.AgeEmployes.FirstOrDefault(emp => emp.PrenomNom == cbxTresoriere.Text); if (cbxTypeFournisseur.Text == "Fournisseur de matière première") { AgeFournisseursMatieresPremiere typeFournisseur = db.AgeFournisseursMatieresPremieres.FirstOrDefault(f => f.Nom == cbxNomFournisseur.Text); var codeFourniseur = typeFournisseur.CodeFournisseurMatierePremiere; EveDecaissement decaiss = new EveDecaissement { DateDecaissement = DateTime.Parse(dtpDateDecaissement.Text), CodeFournisseurMatierePremiere = codeFourniseur, CodeEmploye = em.CodeEmploye, Description = "Paiement dette fournisseur matière première", Montant = int.Parse(txtMontantPaye.Text), CodeCompte = cpte.CodeCompte, }; db.EveDecaissements.Add(decaiss); db.SaveChanges(); txtMontantPaye.Clear(); } else if (cbxTypeFournisseur.Text == "Fournisseur d'équipement ou entrepreneur") { AgeAutreFournisseur typeFournisseur = db.AgeAutreFournisseurs.FirstOrDefault(f => f.NomAutreFournisseur == cbxNomFournisseur.Text); var codeFourniseur = typeFournisseur.CodeAutreFournisseur; EveDecaissement decaiss = new EveDecaissement { DateDecaissement = DateTime.Parse(dtpDateDecaissement.Text), CodeAutreFournisseur = codeFourniseur, CodeEmploye = em.CodeEmploye, Description = "Paiement dette fournisseur équipements et infrastructures", Montant = int.Parse(txtMontantPaye.Text), CodeCompte = cpte.CodeCompte, }; db.EveDecaissements.Add(decaiss); db.SaveChanges(); txtMontantPaye.Clear(); } else if (cbxTypeFournisseur.Text == "Fournisseur de services ou fournitures") { AgeFournisseursServicesFourniture typeFournisseur = db.AgeFournisseursServicesFournitures.FirstOrDefault(f => f.NomFournisseurServiceFourniture == cbxNomFournisseur.Text); var codeFourniseur = typeFournisseur.CodeFournisseurServiceFourniture; EveDecaissement decaiss = new EveDecaissement { DateDecaissement = DateTime.Parse(dtpDateDecaissement.Text), CodeFournisseurService = codeFourniseur, CodeEmploye = em.CodeEmploye, Description = "Paiement dette fournisseur services et fournitures", Montant = int.Parse(txtMontantPaye.Text), CodeCompte = cpte.CodeCompte, }; db.EveDecaissements.Add(decaiss); db.SaveChanges(); txtMontantPaye.Clear(); } MessageBox.Show("Le paiement du fournisseur a été effectué avec succès."); } }