private bool InsertAvoir(AVOIR_FINANCIER avoir) { try { decimal mntAv; decimal.TryParse(textBoxMontantAv.Text, out mntAv); using (var model = new ExpFinanceEntities()) { var detail = new DetailsDossier(); //Set référence (if new avoir get the new num according to the year) if (_avoir == null) { _numAvoir = detail.GetLastAvoirId(dateAvoir.Value); } avoir.numAvoir = _numAvoir; avoir.montant = mntAv; avoir.dateAvoir = dateAvoir.Value.Date; avoir.designation = _designation; avoir.montantCheque = _cheque; avoir.montantCreance = _creance; avoir.Observation = _observation; avoir.typeAvoir = (byte)_typeAvoir; model.AVOIR_FINANCIER.AddOrUpdate(avoir); var op = new AF_OPS_LOG { instant = DateTime.Now, username = Environment.UserName, numavoir = _numAvoir, Operation = "Avoir inséré" }; model.AF_OPS_LOG.Add(op); //insert the related groups foreach (int g in _numGroupe) { var avoirGroupe = new AF_AVOIR_GROUPE { numAvoir = avoir.numAvoir, IDG = g, Libre = 0 }; model.AF_AVOIR_GROUPE.Add(avoirGroupe); } //Insert in the etat table foreach (int g in _numGroupe) { var etat = new AF_ETAT_AVOIR { numDossier = detail.GetGroupeInfo(g).NDOSSIER, numAvoir = avoir.numAvoir, IDG = g, Etat = 3, dateHeure = DateTime.Now }; model.AF_ETAT_AVOIR.Add(etat); } model.SaveChanges(); return(true); } } catch (Exception ex) { Messages.Error("Erreur insertion avoir:" + ex.Message); ErrorLog.LogError("Erreur insertion avoir", ex); return(false); } }
private bool InsertAvoir(AVOIR_FINANCIER avoir) { try { decimal mntAv; decimal.TryParse(textBoxMontantAv.Text, out mntAv); using (var model = new ExpFinanceEntities()) { var detail = new DetailsDossier(); //Set référence _numAvoir = detail.GetLastAvoirId(dateAvoir.Value); textBoxRefAvoir.Text = _numAvoir.ToString("D"); int codePromo; int.TryParse(comboBoxPromotions.SelectedValue?.ToString(), out codePromo); avoir.numAvoir = _numAvoir; avoir.montant = mntAv; avoir.dateAvoir = dateAvoir.Value.Date; avoir.designation = textBoxDesc.Text; avoir.montantCheque = _cheque; avoir.montantCreance = _creance; avoir.Observation = _observation; avoir.typeAvoir = (byte)_typeAvoir; avoir.numAvoirComptable = codePromo; var op = new AF_OPS_LOG { instant = DateTime.Now, username = Environment.UserName, numavoir = _numAvoir, Operation = "Avoir inséré" }; model.AF_OPS_LOG.Add(op); //int nac; //if (int.TryParse(textBoxNAC.Text, out nac)) //{ // avoir.numAvoirComptable = nac; //} var libre = _isFacture ? (byte)1 : (byte)2; //insert the related group var avoirGroupe = new AF_AVOIR_GROUPE { numAvoir = avoir.numAvoir, IDG = _numGroupe, Libre = libre }; model.AF_AVOIR_GROUPE.Add(avoirGroupe); //Insert in the etat table var etat = new AF_ETAT_AVOIR { numDossier = _nDossier, numAvoir = avoir.numAvoir, IDG = _numGroupe, Etat = 3, dateHeure = DateTime.Now }; model.AF_ETAT_AVOIR.Add(etat); model.AVOIR_FINANCIER.Add(avoir); model.SaveChanges(); return(true); } } catch (Exception e) { Messages.Error(@"Erreur insertion avoir financier: "); ErrorLog.LogError(@"Erreur insertion avoir financier: ", e); return(false); } }