Esempio n. 1
0
        void SetDetails(int row)
        {
            try
            {
                //getting details
                var details = new DetailsDossier();
                var idg     = TableGetID_GF(row);
                if (idg == 0)
                {
                    return;
                }

                var groupe = details.GetGroupeInfo(idg);

                if (groupe == null)
                {
                    return;
                }

                var promotion = details.GetPromoInfo(groupe.ID_LIGNE ?? 0);

                //getting invoices nums
                var factures      = details.GetFactures(idg);
                var listeFactures = "";
                factures.ForEach(x => listeFactures += x.NUM_FACT + @" | ");
                listeFactures = listeFactures.Remove(listeFactures.Length - 2);
                tableFactures.Controls.Clear();
                int i = 0, l = 0;
                factures.ForEach(f =>
                {
                    if (i > 5)
                    {
                        i = 0;
                        l++;
                    }
                    var linkFacture = new LinkLabel {
                        Text = ((int)f.NUM_FACT).ToString("D"), LinkColor = Color.DimGray, Font = new Font("Segoe UI Semibold", 8.5F, FontStyle.Bold, GraphicsUnit.Point, ((0)))
                    };
                    linkFacture.Click += (sender, args) => ViewFacture(f.NUM_FACT, f.CODE_CLIENT, f.ENTITE);
                    tableFactures.Controls.Add(linkFacture, i, l);
                    i++;
                });


                //Setting details to the view
                textBoxPromotion.Text = promotion.NOM_PROMOTION;
                NomClient             = textBoxClient.Text = TableGetClientName(row);
                textBoxFactures.Text  = listeFactures;
                textBoxDateD.Text     = groupe.DATE_DOSSIER != null?groupe.DATE_DOSSIER.Value.ToShortDateString() : default(string);


                decimal txRest = 0;
                decimal.TryParse(groupe.REF_RISTOURNE, out txRest);
                if (groupe.MONTANT_RISTOURNE > 0)
                {
                    decimal.TryParse(groupe.REF_RISTOURNE, out txRest);
                }
                else
                {
                    txRest = groupe.TX_REST ?? 0;
                }

                textBoxNumDossier.Text = groupe.NDOSSIER;
                textBoxMarge.Text      = string.Format("{0:#,##0.00 Da}", groupe.MARGE);
                textBoxMarge.Text     += @" ( " + string.Format("{0:P2}", groupe.MARGE / groupe.MNT_TTC) + @" )";
                textBoxMargeRest.Text  = string.Format("{0:#,##0.00 Da}", groupe.MARGE_REST - groupe.MONTANT_RISTOURNE ?? 0);
                textBoxMargeRest.Text += @" ( " + string.Format("{0:P2}", txRest / 100) + @" )";
                textBoxTypePromo.Text  = groupe.TYPE_PROMOTION;
            }
            catch (Exception ex)
            {
                Messages.Error("Erreur lecture de données");
                ErrorLog.LogError("set details", ex);
                Close();
            }
        }
Esempio n. 2
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);
            }
        }