public void Recherche()
        {
            try
            {
                SelectedCommande = null;
                var commande = new Commande()
                                   {
                                       Id = (int)numericUpDown1.Value,
                                       DateCommande = (dateTimePicker.Value == DateTime.MinValue) ? (DateTime?)null : dateTimePicker.Value,
                                       IsLivree = _toInclue,
                                       NomPrenomClient = txtClient.Text.Trim()
                                   };

                SortableBindingList<Commande> commandes = _commandeservice.Recherche(commande);
                commandeBindingSource.DataSource = commandes;
                ligneCommandeBindingSource.DataSource = commandeBindingSource;
                dgvCommandes.AutoResizeColumns();
                dgvLigneCommande.AutoResizeColumns();
                OnChangeSelectedCommande();
            }
            catch (Exception exception)
            {
                GestionException.TraiterException(exception, "Recherche commande");
            }
        }
示例#2
0
        public void Delete(Commande commande)
        {
            BaseData.BeginTransaction();
            try
            {
                bool isDeleted = _commandeData.DeleteTransaction(commande);

                if (isDeleted)
                {
                    bool isligneDeleted = _ligneCommandeService.DeleteTransaction(commande);
                    if (!isligneDeleted)
                        throw new Exception("Une erreur s'est produite lors de la suppression de la ligne commande");
                }
                else
                {
                    throw new Exception("Une erreur s'est produite lors de la suppression de la commande");
                }

                BaseData.Commit();
            }
            catch (Exception)
            {
                BaseData.RollBack();
                throw;
            }
        }
 public void Reset()
 {
     SelectedCommande = null;
     dateTimePicker.Value = DateTime.MinValue;
     txtClient.Text = string.Empty;
     numericUpDown1.Text = string.Empty;
     numericUpDown1.Value = 0;
     commandeBindingSource.DataSource = new List<Commande>();
     OnChangeSelectedCommande();
 }
示例#4
0
        public bool DeleteTransaction(Commande commande)
        {
            bool isDeleted;

            using (Helper)
            {
                Helper.PrepareCommand("DELETE FROM Commande WHERE Id = @Id");
                Helper.AddInParameter("Id", DbType.Int32, commande.Id);

                isDeleted = Helper.ExecuteNonQuery();
            }

            return isDeleted;
        }
示例#5
0
        public bool Deliver(Commande commande)
        {
            bool isUpdated;

            using (var helper = new SqliteHelper("UPDATE Commande set IsLivree = @IsLivree, DateLivraison = @DateLivraison WHERE Id = @Id"))
            {
                helper.AddInParameter("Id", DbType.Int32, commande.Id);
                helper.AddInParameter("IsLivree", DbType.Int32, true);
                helper.AddInParameter("DateLivraison", DbType.Date, DateTime.Now.Date);

                isUpdated = helper.ExecuteNonQuery();
            }

            return isUpdated;
        }
        public void LoadAll()
        {
            try
            {
                if (SelectedCommande != null)
                {
                    this.Text = string.Format("GsCommande - Modification de la commande N° {0}", SelectedCommande.Id);
                    toolStripStatusLabel1.Text = this.Text;
                    SelectedCommande = _commandeService.Get(SelectedCommande.Id);
                    var liste = _ligneCommandeService.ListByCommande(SelectedCommande);
                    SelectedCommande.LigneCommande = new List<LigneCommande>(liste);
                    ucCommandeAjouter1.LigneCommandes = new List<LigneCommande>(liste);
                    ucCommandeAjouter1.CommandeForUpdate = SelectedCommande;
                    ucCommandeAjouter1.LoadForUpdate();

                    if (SelectedCommande.IsLivree)
                    {
                       // btnLivrer.Enabled = false;
                        btnSave.Enabled = false;
                        btnSupprimer.Enabled = false;
                       //a btnAnnulerLivraison.Visible = true;
                        label1.Text =
                            string.Format("Cette Commande a été livrée le {0}. \n \t Il n'est pas possible de la modifier.",
                            SelectedCommande.DateLivraison.Value.ToShortDateString());
                        pnlCommandeLivree.Visible = true;
                        ucCommandeAjouter1.Enabled = false;
                    }
                    else
                    {
                        pnlCommandeLivree.Visible = false;
                        //btnAnnulerLivraison.Visible = false;
                        ucCommandeAjouter1.Enabled = true;
                    }
                }
                else
                {
                    MessageBox.Show(@"Vous devez séléctionner une commande pour la modifier",
                            @"Modification de la commande", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception exception)
            {
                GestionException.TraiterException(exception, "Modification de la commande");
            }
        }
示例#7
0
        public Commande CreateTransaction(Commande commande)
        {
            using (Helper)
            {

                Helper.PrepareCommand("INSERT INTO Commande (DateCommande,NomPrenomClient,IsLivree,DateLivraison) "
                    + " VALUES(@DateCommande, @NomPrenomClient, @IsLivree, @DateLivraison); Select last_insert_rowid();");

                Helper.AddInParameter("DateCommande", DbType.Date, commande.DateCommande.Value.Date);
                Helper.AddInParameter("NomPrenomClient", DbType.String, commande.NomPrenomClient);
                Helper.AddInParameter("IsLivree", DbType.Boolean, false);
                Helper.AddInParameter("DateLivraison", DbType.Date, DBNull.Value);

                commande.Id = Helper.ExecuteCreateQuery();

            }
            return commande;
        }
示例#8
0
        public List<LigneCommande> ListByCommande(Commande selectedCommande)
        {
            var sb = new StringBuilder();
            sb.Append("SELECT p.Id ProduitId, p.Code, p.Libelle LibelleProduit,");
            sb.Append(" f.Id FamilleId ,f.Libelle LibelleFamille,");
            sb.Append(" l.QteKilo, l.QteDemiKilo FROM LigneCommande l, Produit p, Famille f  ");
            sb.Append(" WHERE l.produitId = p.Id AND p.FamilleId = f.Id AND l.CommandeId = @CommandeId");
            sb.Append(" Order by FamilleId, Code");

            var ligneCommandes = new List<LigneCommande>();

            using (var helper = new SqliteHelper(sb.ToString()))
            {
                helper.AddInParameter("CommandeId", DbType.Int32, selectedCommande.Id);
                using (var reader = helper.ExecuteQuery())
                {

                    while (reader.Read())
                    {
                        ligneCommandes.Add(new LigneCommande
                        {
                            Commande = selectedCommande,
                            Qtekilo = reader.GetIntFromReader("QteKilo"),
                            QteDemiKilo = reader.GetIntFromReader("QteDemiKilo"),
                            Produit = new Produit()
                                          {
                                              Id = reader.GetIntFromReader("ProduitId"),
                                              Code = reader.GetIntFromReader("Code"),
                                              Libelle = reader.GetStringFromReader("LibelleProduit"),
                                              Famille = new Famille()
                                                            {
                                                                Id = reader.GetIntFromReader("FamilleId"),
                                                                Libelle = reader.GetStringFromReader("LibelleFamille")
                                                            }
                                          }
                        });
                    }
                }
            }

            return ligneCommandes;
        }
示例#9
0
        public Commande Get(int id)
        {
            var commande = new Commande() { Id = id };

            using (var helper = new SqliteHelper("SELECT Id, DateCommande, NomPrenomClient, IsLivree, DateLivraison FROM Commande WHERE Id = @Id"))
            {
                helper.AddInParameter("Id", DbType.Int32, id);

                using (var reader = helper.ExecuteQuery())
                {
                    if (reader.Read())
                    {
                        commande.NomPrenomClient = reader.GetStringFromReader("NomPrenomClient");
                        commande.DateCommande = reader.GetDateTimeFromReader("DateCommande");
                        commande.IsLivree = reader.GetBoolFromReader("IsLivree");
                        commande.DateLivraison = reader.GetDateTimeNullableFromReader("DateLivraison");
                    }
                }
            }

            return commande;
        }
示例#10
0
        public Commande Create(Commande commande)
        {
            BaseData.BeginTransaction();

            try
            {
                int nextCode = GetNextId();

                if (commande.Id != nextCode)
                    _commandeData.UpdateCommandeSeqTransaction(commande.Id - 1);

                commande = _commandeData.CreateTransaction(commande);
                if (commande.Id > 0)
                {
                    foreach (var ligneCommande in commande.LigneCommande)
                    {
                        ligneCommande.Commande = commande;
                        bool isCreated = _ligneCommandeService.CreateTransaction(ligneCommande);
                        if (!isCreated)
                            throw new Exception("Ligne Commande non créer");
                    }
                }
                else
                {
                    throw new Exception("Commande non créer");
                }

                BaseData.Commit();
            }
            catch (Exception)
            {
                BaseData.RollBack();
                throw;
            }

            return commande;
        }
 public List<LigneCommande> ListByCommande(Commande selectedCommande)
 {
     return _ligneCommandeData.ListByCommande(selectedCommande);
 }
示例#12
0
        public bool UpdateTransaction(Commande commande)
        {
            bool isUpdated;

            using (Helper)
            {
                Helper.PrepareCommand("UPDATE Commande set DateCommande = @DateCommande, NomPrenomClient = @NomPrenomClient WHERE Id = @Id");
                Helper.AddInParameter("Id", DbType.Int32, commande.Id);
                Helper.AddInParameter("DateCommande", DbType.DateTime, commande.DateCommande);
                Helper.AddInParameter("NomPrenomClient", DbType.String, commande.NomPrenomClient);

                isUpdated = Helper.ExecuteNonQuery();
            }

            return isUpdated;
        }
示例#13
0
        public SortableBindingList<Commande> Recherche(Commande commande)
        {
            var sb = new StringBuilder("SELECT Id, DateCommande, NomPrenomClient, IsLivree, DateLivraison FROM Commande WHERE 1 = 1");

            if (commande.DateCommande.HasValue)
                sb.Append(" AND DateCommande = @DateCommande");

            if (!string.IsNullOrEmpty(commande.NomPrenomClient.Trim()))
                sb.Append(" AND upper(NomPrenomClient) like upper('%' || @NomPrenomClient || '%') ");

            if (commande.Id > 0)
                sb.Append(" AND Id = @Id");

            if (!commande.IsLivree)
                sb.Append(" AND IsLivree = @IsLivree");

            sb.Append(" ORDER BY Id ");

            var commandes = new SortableBindingList<Commande>();

            using (var helper = new SqliteHelper(sb.ToString()))
            {
                if (commande.DateCommande.HasValue)
                    helper.AddInParameter("DateCommande", DbType.DateTime, commande.DateCommande.Value.Date);

                if (!string.IsNullOrEmpty(commande.NomPrenomClient.Trim()))
                    helper.AddInParameter("NomPrenomClient", DbType.String, commande.NomPrenomClient);

                if (commande.Id > 0)
                    helper.AddInParameter("Id", DbType.Int32, commande.Id);

                if (!commande.IsLivree)
                    helper.AddInParameter("IsLivree", DbType.Boolean, false);

                using (var reader = helper.ExecuteQuery())
                {
                    while (reader.Read())
                    {
                        commandes.Add(new Commande()
                                          {
                                              Id = reader.GetIntFromReader("Id"),
                                              DateCommande = reader.GetDateTimeFromReader("DateCommande"),
                                              NomPrenomClient = reader.GetStringFromReader("NomPrenomClient"),
                                              IsLivree = reader.GetBoolFromReader("IsLivree"),
                                              DateLivraison = reader.GetDateTimeNullableFromReader("DateLivraison")
                                          });
                    }
                }
            }

            return commandes;
        }
示例#14
0
 public SortableBindingList<Commande> Recherche(Commande commande)
 {
     var commandes = _commandeData.Recherche(commande);
     foreach (var cmd in commandes)
     {
         cmd.LigneCommande = _ligneCommandeService.ListByCommande(cmd);
     }
     return commandes;
 }
示例#15
0
        public void UpdateTransaction(Commande commande)
        {
            BaseData.BeginTransaction();
            try
            {
                var isUpdated = _commandeData.UpdateTransaction(commande);

                if (isUpdated)
                {
                    foreach (var ligneCommande in commande.LigneCommande)
                    {
                        ligneCommande.Commande = commande;
                        var isexecuted = _ligneCommandeService.UpdateTransactionByState(ligneCommande);
                        if (!isexecuted)
                            throw new Exception("Une erreur s'est produite lors du traitement sur de la ligne commande");
                    }
                }
                else
                {
                    throw new Exception("Une erreur s'est produite lors de la mise à jour de la commande");
                }

                BaseData.Commit();
            }
            catch (Exception)
            {
                BaseData.RollBack();
                throw;
            }
        }
示例#16
0
 private void dgvCommandes_RowHeaderMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
 {
     if (dgvCommandes.SelectedRows.Count > 0)
     {
         SelectedCommande = dgvCommandes.SelectedRows[0].DataBoundItem as Commande;
         OnChangeSelectedCommande();
         OpenCommandeDetail();
     }
 }
 public bool DeleteTransaction(Commande commande)
 {
     return _ligneCommandeData.DeleteTransaction(commande);
 }
示例#18
0
 public void Deliver(Commande commande)
 {
     bool isDelivred = _commandeData.Deliver(commande);
     if (!isDelivred)
         throw new Exception("Une erreur s'est produite lors de la livraison de la commande");
 }
示例#19
0
 public void CancelDelivery(Commande commande)
 {
     bool isCanceled = _commandeData.CancelDelivery(commande);
     if (!isCanceled)
         throw new Exception("Une erreur s'est produite lors de la livraison de la commande");
 }
示例#20
0
        public void SaveCommande()
        {
            try
            {
                if (LigneCommandes.Count == 0)
                {
                    MessageBox.Show(@"Vous devez ajouter des produits à la commande pour continuer",
                        @"Ajout commande", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                var commande = new Commande()
                                   {
                                       Id = Convert.ToInt32(lblIdCommande.Text),
                                       DateCommande = dateTimePicker.Value,
                                       NomPrenomClient = txtClient.Text,
                                       IsLivree = false,
                                       LigneCommande = LigneCommandes
                                   };

                commande = _commandeService.Create(commande);

                Reset();

                MessageBox.Show(string.Format("La commande numéro {0}  a été ajouter avec succès", commande.Id),
                                @"Ajout commande", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch (Exception exception)
            {
                GestionException.TraiterException(exception, "Ajout commande");
            }
        }
示例#21
0
 private void dataGridView1_SelectionChanged(object sender, EventArgs e)
 {
     if (dgvCommandes.SelectedRows.Count > 0)
     {
         SelectedCommande = dgvCommandes.SelectedRows[0].DataBoundItem as Commande;
         OnChangeSelectedCommande();
     }
 }