Esempio n. 1
0
        //private void textBoxNAC_KeyPress(object sender, KeyPressEventArgs e)
        //{
        //    if ((sender as TextBox) == null) return;
        //    if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
        //    {
        //        e.Handled = true;
        //    }
        //}


        private void buttonValider_Click(object sender, EventArgs e)
        {
            if (!FormValidation())
            {
                return;
            }

            var avoir   = new AVOIR_FINANCIER();
            var success = InsertAvoir(avoir);

            if (!success)
            {
                return;
            }

            if (_chequesList.Count > 0)
            {
                _chequesList.ForEach(c => c.numAvoir = avoir.numAvoir);
                success = InsertCheques(_chequesList);
            }

            if (success)
            {
                Messages.Success("Données insérées avec succès !");
            }
            Close();
        }
Esempio n. 2
0
 public EditAvoirForm(int numAvoir)
 {
     InitializeComponent();
     AvoirFinancier = GetAvoirInfo(numAvoir);
     _creance       = AvoirFinancier.montantCreance;
     _cheque        = AvoirFinancier.montantCheque;
     _reste         = 0;
 }
Esempio n. 3
0
        private void LoadAvoir(AVOIR_FINANCIER avoir)
        {
            try
            {
                using (var model = new ExpFinanceEntities())
                {
                    var detail = new DetailsDossier();
                    //Set références
                    _numAvoir            = avoir.numAvoir;
                    textBoxRefAvoir.Text = _numAvoir.ToString("D");
                    _montant             = avoir.montant;
                    _cheque                 = avoir.montantCheque;
                    _creance                = avoir.montantCreance;
                    _observation            = avoir.Observation;
                    textBoxDesc.Text        = avoir.designation;
                    textBoxObservation.Text = avoir.Observation;
                    dateAvoir.Value         = avoir.dateAvoir;

                    //Get cheques
                    _chequesList = (from c in model.CHEQUE where c.numAvoir == avoir.numAvoir select c).ToList();
                    RebindListBoxCheque();
                    TotalCheque();

                    //Set type
                    switch (avoir.typeAvoir)
                    {
                    case 1:
                        _isCheque  = true;
                        _isCreance = false;
                        break;

                    case 2:
                        _isCreance = true;
                        _isCheque  = false;
                        break;

                    case 3:
                        _isCheque = _isCreance = true;
                        break;

                    default:
                        _isCheque = _isCreance = false;
                        break;
                    }


                    //Get Groupe Factures related to the avoir
                    _numGroupe = (from afg in model.AF_AVOIR_GROUPE
                                  where afg.numAvoir == _numAvoir
                                  select afg.IDG).ToList();


                    // ReSharper disable once ConstantNullCoalescingCondition
                    if (_numGroupe.Count == 0)
                    {
                        throw new NullReferenceException("Les groupse factures liés à cette avoir n'existe plus !");
                    }

                    // var factures = detail.GetFactures(_numGroupe);
                    var factures = new List <FACTURE>();

                    //Get factures of each groupe then put them all in one list
                    _numGroupe.ForEach(g =>
                    {
                        var groupeFactures = detail.GetFactures(g);
                        //add each groupe factures to the global list
                        groupeFactures.ForEach(factures.Add);
                    });

                    PopulateFacutresListView(factures);

                    //disable facture item check
                    listViewFactures.ItemCheck -= listViewFactures_ItemCheck;
                    foreach (ListViewItem item in listViewFactures.Items)
                    {
                        item.Checked = true;
                    }



                    //set totals values
                    decimal t, m;
                    TotalFactures(out t, out m);

                    //set reste
                    _reste = _montant - (_creance + _cheque);

                    textBoxMontantAv.Text = $"{_montant:#,##0.00}";
                    textBoxCreance.Text   = $"{_creance:#,##0.00}";

                    //enable facture item check
                    listViewFactures.ItemCheck += listViewFactures_ItemCheck;

                    CheckType();
                }
            }
            catch (Exception e)
            {
                Messages.Error("Error Loading avoir :" + e.Message);
                ErrorLog.LogError("Error Loading avoir", e);
                Close();
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
 public AvoirForm(AVOIR_FINANCIER avoir)
 {
     InitializeComponent();
     _avoir  = avoir;
     Editing = true;
 }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
        private void buttonValider_Click(object sender, EventArgs e)
        {
            if (!FormValidation())
            {
                return;
            }

            //Insert factures et groupe factures
            var listeCode = ReadFactures();


            if (!_isEf)
            {
                var success = InsertFactures(listeCode);

                if (!success)
                {
                    return;
                }
                //Insert Avoir
                var avoir = new AVOIR_FINANCIER();
                success = InsertAvoir(avoir);

                if (_chequesList.Count > 0)
                {
                    //Insert CHEQUE if so
                    _chequesList.ForEach(c => c.numAvoir = avoir.numAvoir);
                    success = InsertCheques(_chequesList);
                }
                if (success)
                {
                    Messages.Success("Données insérées avec succès !");
                }
                Close();
            }
            else
            {
                // ReSharper disable once RedundantAssignment
                var success = InsertFacturesEf(listeCode);

                if (!success)
                {
                    return;
                }
                //Insert Avoir
                var avoir = new AVOIR_FINANCIER();
                success = InsertAvoirEf(avoir);

                if (_chequesList.Count > 0)
                {
                    //Insert CHEQUE if so
                    _chequesList.ForEach(c => c.numAvoir = avoir.numAvoir);
                    success = InsertCheques(_chequesList);
                }
                if (success)
                {
                    Messages.Success("Données insérées avec succès !");
                }
                Close();
            }
        }