Example #1
0
        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);
            }
        }
Example #2
0
        private bool SetEtat(IEnumerable <int> idg, byte state)
        {
            try
            {
                if (idg == null)
                {
                    return(false);
                }
                idg = idg.ToList();
                if (!idg.Any())
                {
                    return(false);
                }

                using (var model = new ExpFinanceEntities())
                {
                    //If reject treat only one entry
                    if (state == 1)
                    {
                        var g = idg.LastOrDefault();

                        var oldState = (from e in model.AF_ETAT_AVOIR
                                        where e.IDG == g
                                        orderby e.dateHeure descending
                                        select e.Etat).FirstOrDefault();

                        //return if already rejected or if validated
                        if (oldState == state || oldState == 3)
                        {
                            Cursor.Current = Cursors.Default;
                            return(false);
                        }

                        var obs = Prompt.ShowDialog("Motif de rejet", "Observation");

                        var etat = new AF_ETAT_AVOIR
                        {
                            IDG         = g,
                            Etat        = state,
                            dateHeure   = DateTime.Now,
                            observation = obs
                        };

                        var op = new AF_OPS_LOG
                        {
                            instant   = DateTime.Now,
                            Operation = $"Etat mis à {state}",
                            username  = Environment.UserName,
                            idg       = g
                        };

                        model.AF_OPS_LOG.Add(op);
                        model.AF_ETAT_AVOIR.Add(etat);
                        model.SaveChanges();
                        return(true);
                    }

                    Cursor.Current = Cursors.WaitCursor;
                    foreach (int g in idg)
                    {
                        //Check the last state
                        var oldState = (from e in model.AF_ETAT_AVOIR
                                        where e.IDG == g
                                        orderby e.dateHeure descending
                                        select e.Etat).FirstOrDefault();

                        if (oldState == state)
                        {
                            continue;
                        }
                        //return if validated
                        if (oldState == 3)
                        {
                            Cursor.Current = Cursors.Default;
                            return(false);
                        }

                        var etat = new AF_ETAT_AVOIR
                        {
                            IDG       = g,
                            Etat      = state,
                            dateHeure = DateTime.Now
                        };

                        var op = new AF_OPS_LOG
                        {
                            instant   = DateTime.Now,
                            Operation = $"Etat mis à {state}",
                            username  = Environment.UserName,
                            idg       = g
                        };

                        model.AF_OPS_LOG.Add(op);
                        model.AF_ETAT_AVOIR.Add(etat);
                    }

                    model.SaveChanges();
                    Cursor.Current = Cursors.Default;
                    return(true);
                }
            }
            catch (Exception e)
            {
                Messages.Error("Error edit etat: " + e.Message);
                return(false);
            }
        }
Example #3
0
        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);
            }
        }