Beispiel #1
0
        /// <summary>
        /// Modify the selected article and save it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_SubmitModifyArticle_Click(object sender, EventArgs e)
        {
            Reference   = textBox_RefArticle.Text;
            Description = textBox_Description.Text;
            Price       = textBox_PriceHT.Text;
            Quantity    = textBox_Quantity.Text;

            Sub_Familly_Index = comboBox_SubFamily.SelectedIndex;
            Mark_Index        = comboBox_Brand.SelectedIndex;


            float Price_Float  = float.Parse(Price);
            int   Quantity_Int = int.Parse(Quantity);

            SubFamillyController Sub_Familly_Controller = new SubFamillyController();
            List <SubFamilly>    List_Sub_Familly       = Sub_Familly_Controller.GetAllSubFamilly();
            SubFamilly           Sub_Familly            = List_Sub_Familly[Sub_Familly_Index];

            MarkController Mark_Controller = new MarkController();
            List <Mark>    List_Mark       = Mark_Controller.GetAllMark();
            Mark           Mark            = List_Mark[Mark_Index];

            ArticleController Article_Controller = new ArticleController();
            Article           Article            = Article_Controller.GetArticleByRef(Reference);

            Article_Controller.UpdateArticle(Reference, Description, Sub_Familly.RefSousFamille1, Mark.RefMarque1, Price_Float, Quantity_Int);
            MessageBox.Show("Article modified successfully ;)", "Article modified", MessageBoxButtons.OK, MessageBoxIcon.Information);

            this.DialogResult = DialogResult.OK;
            this.Dispose();
            //this.Close();
        }
Beispiel #2
0
        /// <summary>
        /// Add article listner
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Add_Article_Click(object sender, EventArgs e)
        {
            String Reference   = Text_Box_Reference.Text;
            String Description = Text_Box_Description.Text;
            String Price       = Text_Box_Price.Text;
            String Quantity    = Text_Box_Quantity.Text;

            int Sub_Familly_Index = Combo_Box_Sous_Famille.SelectedIndex;
            int Mark_Index        = Combo_Box_Marque.SelectedIndex;

            if (Mark_Index > -1 && Sub_Familly_Index > -1 && !Reference.Equals("") && !Description.Equals("") && !Price.Equals("") && !Quantity.Equals(""))
            {
                try
                {
                    float Price_Float  = float.Parse(Price);
                    int   Quantity_Int = int.Parse(Quantity);

                    SubFamillyController Sub_Familly_Controller = new SubFamillyController();
                    List <SubFamilly>    List_Sub_Familly       = Sub_Familly_Controller.GetAllSubFamilly();
                    SubFamilly           Sub_Familly            = List_Sub_Familly[Sub_Familly_Index];

                    MarkController Mark_Controller = new MarkController();
                    List <Mark>    List_Mark       = Mark_Controller.GetAllMark();
                    Mark           Mark            = List_Mark[Mark_Index];


                    //Article article = new Article(Reference, Description, Price, Quantity, sousFamille.Ref_Sous_Famille, marque.Ref_Marque);
                    ArticleController Article_Controller = new ArticleController();
                    Article           Article            = Article_Controller.GetArticleByRef(Reference);

                    if (Article == null)
                    {
                        Article_Controller.InsertArticle(Reference, Description, Sub_Familly.RefSousFamille1, Mark.RefMarque1, Price_Float, Quantity_Int);
                        MessageBox.Show("Article added successfully ;)", "Article added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Article exists already in DataBase", "Error Add Article", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    this.DialogResult = DialogResult.OK;
                    this.Dispose();
                }
                catch (FormatException e1)
                {
                    //Message de l'exception pour notifier l'utilisateur
                    MessageBox.Show(e1.Message, "Error Add Article", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please fill in all the fields", "Error Add Article", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// get the infomations of the selected item
        /// </summary>
        /// <param name="SelectedSubFamily"></param>
        public void GetSubFamilyToModify(ListViewItem SelectedSubFamily)
        {
            SubFamillyController SubFamController  = new SubFamillyController();
            SubFamilly           SubFamilyToModify = new SubFamilly();

            SubFamilyToModify = SubFamController.GetSubFamillyByRef(int.Parse(SelectedSubFamily.Text));
            //Console.WriteLine("列表中选中的sub id"+SelectedSubFamily.Text);

            this.textBox_RefSF.Text  = SubFamilyToModify.RefSousFamille1.ToString();
            this.textBox_NameSF.Text = SubFamilyToModify.Nom1.ToString();
            this.comboBox_F.Text     = SubFamilyToModify.RefFamille1.Nom1.ToString();
        }
Beispiel #4
0
        public SubFamilly MakeSubFamilly(int RefSub, int RefFamilly, string Name)
        {
            SubFamilly SubFamilly = new SubFamilly();

            SubFamilly.RefSousFamille1 = RefSub;
            SubFamilly.Nom1            = Name;

            //insert familly
            FamillyDAO FamillyDAO = new FamillyDAO();

            SubFamilly.RefFamille1 = FamillyDAO.SelectFamillyByRef(RefFamilly);

            return(SubFamilly);
        }
Beispiel #5
0
        /// <summary>
        /// Update SubFamilly
        /// </summary>
        /// <param name="SubFamilly">Object SubFamilly</param>
        /// <returns>Number of row</returns>
        public int UpdateSubFamilly(SubFamilly SubFamilly)
        {
            int           Count         = 0;
            SQLiteCommand InsertCommand = new SQLiteCommand(Connection);

            using (SQLiteTransaction Tran = Connection.BeginTransaction())
            {
                InsertCommand.CommandText = "UPDATE SousFamilles SET Nom = @Nom, RefFamille = @RefFamille WHERE RefSousFamille = @Ref";
                InsertCommand.Parameters.AddRange(new[] {
                    new SQLiteParameter("@Nom", SubFamilly.Nom1),
                    new SQLiteParameter("@RefFamille", SubFamilly.RefFamille1.RefFamille1),
                    new SQLiteParameter("@Ref", SubFamilly.RefSousFamille1),
                });
                Count = InsertCommand.ExecuteNonQuery();
                Tran.Commit();
            }
            return(Count);
        }
Beispiel #6
0
        /// <summary>
        /// Select all SubFamilly
        /// </summary>
        /// <returns>List of subfamilly</returns>
        public List <SubFamilly> SelectAllSubFamilly()
        {
            List <SubFamilly> L_SubFamilly  = new List <SubFamilly>();
            SQLiteCommand     SelectCommand = new SQLiteCommand(Connection);

            using (SQLiteTransaction Tran = Connection.BeginTransaction())
            {
                SelectCommand.CommandText = "SELECT * FROM SousFamilles";

                SQLiteDataReader reader = SelectCommand.ExecuteReader();
                Tran.Commit();
                while (reader.Read())
                {
                    SubFamilly SubFamilly = this.MakeSubFamilly(int.Parse(reader["RefSousFamille"].ToString()), int.Parse(reader["RefFamille"].ToString()), reader["Nom"].ToString());
                    L_SubFamilly.Add(SubFamilly);
                }
            }
            return(L_SubFamilly);
        }
Beispiel #7
0
        /// <summary>
        /// add subfamily
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Add_Sous_Famille_Click(object sender, EventArgs e)
        {
            String Reference = Text_Box_Reference.Text;
            String Name      = Text_Box_Name.Text;

            int Familly_Index = Combo_Box_Famille.SelectedIndex;

            if (Familly_Index > -1 && !Reference.Equals("") && !Name.Equals(""))
            {
                try
                {
                    int Reference_Int = int.Parse(Reference);

                    SubFamillyController Sub_Familly_Controller = new SubFamillyController();
                    SubFamilly           Sub_Familly            = Sub_Familly_Controller.GetSubFamillyByRef(Reference_Int);

                    List <Familly> List_Familly      = new FamillyController().GetAllFamilly();
                    int            Reference_Familly = List_Familly[Familly_Index].RefFamille1;


                    if (Sub_Familly == null)
                    {
                        Sub_Familly_Controller.InsertSubFamilly(Reference_Int, Reference_Familly, Name);
                        MessageBox.Show("Sub Familly added successfully ;)", "Sub Familly Added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Sub Familly exists already in database", "Error Add Sub Familly", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Dispose();
                }
                catch (FormatException e1)
                {
                    MessageBox.Show(e1.Message, "Error Add Sub Familly", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please fill in all the fields", "Error Add Sub Familly", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Insert One subfamilly
        /// </summary>
        /// <param name="RefSubFamilly">SubFamilly reference</param>
        /// <param name="RefFamilly">Familly reference</param>
        /// <param name="Name">Subfamilly name</param>
        /// <returns>Response object</returns>
        public Response InsertSubFamilly(int RefSub, int RefFamilly, string Name)
        {
            Response Response = new Response();

            try
            {
                int        Count      = 0;
                SubFamilly SubFamilly = this.SubFamillyDAO.MakeSubFamilly(RefSub, RefFamilly, Name);
                Count             = SubFamillyDAO.InsertSubFamilly(SubFamilly);
                Response.State1   = true;
                Response.Message1 = Count.ToString();
            }
            catch (Exception E)
            {
                Response.State1   = false;
                Response.Message1 = E.Message;
            }
            return(Response);
        }
Beispiel #9
0
        public int InsertSubFamilly(SubFamilly SubFamilly)
        {
            int           Count         = 0;
            SQLiteCommand InsertCommand = new SQLiteCommand(Connection);

            using (SQLiteTransaction Tran = Connection.BeginTransaction())
            {
                if (this.SelectSubFamillyByRef(SubFamilly.RefSousFamille1) == null)
                {
                    InsertCommand.CommandText = "INSERT INTO SousFamilles VALUES(@RefSUB,@RefF,@Nom)";
                    InsertCommand.Parameters.AddRange(new[] {
                        new SQLiteParameter("@RefSUB", SubFamilly.RefSousFamille1),
                        new SQLiteParameter("@RefF", SubFamilly.RefFamille1.RefFamille1),
                        new SQLiteParameter("@Nom", SubFamilly.Nom1)
                    });
                    Count = InsertCommand.ExecuteNonQuery();
                    Tran.Commit();
                }
            }
            return(Count);
        }
Beispiel #10
0
        public SubFamilly SelectSubFamillyByRef(int Ref)
        {
            SubFamilly    SubFamilly    = null;
            SQLiteCommand SelectCommand = new SQLiteCommand(Connection);

            using (SQLiteTransaction Tran = Connection.BeginTransaction())
            {
                SelectCommand.CommandText = "SELECT * FROM SousFamilles WHERE RefSousFamille = @Ref";
                SelectCommand.Parameters.AddRange(new[] {
                    new SQLiteParameter("@Ref", Ref)
                });

                SQLiteDataReader reader = SelectCommand.ExecuteReader();
                Tran.Commit();
                if (reader.HasRows)
                {
                    reader.Read();
                    SubFamilly = this.MakeSubFamilly(int.Parse(reader["RefSousFamille"].ToString()), int.Parse(reader["RefFamille"].ToString()), reader["Nom"].ToString());
                }


                return(SubFamilly);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Parse the article to be readable
        /// </summary>
        /// <returns></returns>
        public List <Article> ParseArticle()
        {
            // data structures


            int Mark_Count   = 1;
            int SubFam_Count = 1;
            int Fam_Count    = 1;

            foreach (OriArticle OriArc in this.List_Ori_Ari)
            {
                // set articles
                Article Art = new Article();
                Art.RefArticle1  = OriArc.RefArticle1;
                Art.Description1 = OriArc.Description1;
                Art.PriceHT1     = float.Parse(OriArc.PrixHT1);
                Art.Quantity1    = 1;
                //try catch here

                // set mark
                Mark Mark = new Mark();
                Mark.RefMarque1 = Mark_Count;
                Mark.Nom1       = OriArc.Marque1;
                if (L_Mark.Contains(Mark))
                {
                    int Id = L_Mark.IndexOf(Mark);
                    Mark = L_Mark.ElementAt(Id);
                }
                else
                {
                    Mark_Count++;
                    L_Mark.Add(Mark);
                }
                Art.RefMark1 = Mark;

                // set familly
                Familly Familly = new Familly();
                Familly.Nom1        = OriArc.Famille1;
                Familly.RefFamille1 = Fam_Count;

                if (L_Familly.Contains(Familly))
                {
                    int Id = L_Familly.IndexOf(Familly);
                    Familly = L_Familly.ElementAt(Id);
                }
                else
                {
                    Fam_Count++;
                    L_Familly.Add(Familly);
                }


                // set subfamilly
                SubFamilly SubFamilly = new SubFamilly();
                SubFamilly.Nom1            = OriArc.SousFamille1;
                SubFamilly.RefSousFamille1 = SubFam_Count;
                SubFamilly.RefFamille1     = Familly;
                if (L_SubFamilly.Contains(SubFamilly))
                {
                    int Id = L_SubFamilly.IndexOf(SubFamilly);
                    SubFamilly = L_SubFamilly.ElementAt(Id);
                }
                else
                {
                    SubFam_Count++;
                    L_SubFamilly.Add(SubFamilly);
                }

                Art.RefSubFamilly1 = SubFamilly;

                // add to list
                L_Article.Add(Art);
            }
            return(L_Article);
        }