Beispiel #1
0
 /// <summary>
 /// Define what to do when a keyboard key is pressed
 /// </summary>
 /// <param name="Sender">The object sending the event</param>
 /// <param name="Event">The event</param>
 private void OnListViewKeyDown(object Sender, KeyEventArgs Event)
 {
     if (Event.Handled)
     {
         return;
     }
     if (Event.KeyCode == Keys.Enter)
     {
         if (listView1.SelectedItems.Count == 1)
         {
             ListViewItem Item = listView1.SelectedItems[0];
             UpdateArticle((Article)Item.Tag);
         }
     }
     else if (Event.KeyCode == Keys.F5)
     {
         LoadDatabase();
     }
     else if (Event.KeyCode == Keys.Delete)
     {
         for (int I = 0; I < listView1.SelectedItems.Count; I++)
         {
             ListViewItem Item = listView1.SelectedItems[I];
             DbConnect.GetInstance().DeleteArticle(((Article)Item.Tag).Reference);
         }
         LoadDatabase();
     }
     Event.Handled = true;
 }
Beispiel #2
0
        /// <summary>
        /// Erase and reload the database from the selected file
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void NewButton_Click(object Sender, EventArgs Event)
        {
            if (TextBox1.Text == "")
            {
                return;
            }
            NewButton.Enabled    = false;
            UpdateButton.Enabled = false;
            XmlDocument Doc = Parser.ParseXml(TextBox1.Text);

            DbConnect.GetInstance().Clear();
            XmlNodeList NodeList = Doc.SelectNodes("/materiels/article");
            int         Added    = 0;
            int         Progress = 0;

            foreach (XmlNode Node in NodeList)
            {
                try
                {
                    if (DbConnect.GetInstance().AddArticle(Node))
                    {
                        Added++;
                    }
                }
                catch (Exception E)
                {
                    MessageBox.Show(@"Error " + E.Message);
                }
                ProgressBar1.Value = (Progress * 100) / NodeList.Count;
                Progress++;
            }
            ProgressBar1.Value = 100;
            Close();
            MessageBox.Show(@"Added " + Added + @" elements");
        }
Beispiel #3
0
        /// <summary>
        /// Define what to do when a keyboard key is pressed on an element
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void OnListViewKeyDown(object Sender, KeyEventArgs Event)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (Event.KeyCode)
            {
            case Keys.Enter:
                if (listView1.SelectedItems.Count == 1)
                {
                    ListViewItem Item = listView1.SelectedItems[0];
                    UpdateBrand((Brand)Item.Tag);
                }

                break;

            case Keys.F5:
                LoadDatabase();
                break;

            case Keys.Delete:
                for (int I = 0; I < listView1.SelectedItems.Count; I++)
                {
                    ListViewItem Item = listView1.SelectedItems[I];
                    DbConnect.GetInstance().DeleteBrand(((Brand)Item.Tag).Reference);
                }

                LoadDatabase();
                break;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Validate the creation (or editing)
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void ButtonOK_Click(object Sender, EventArgs Event)
        {
            DialogResult = DialogResult.OK;
            Family Family = GetFamily();

            if (Family != null)
            {
                DbConnect.GetInstance().UpdateOrCreateFamily(Family);
            }
            Close();
        }
Beispiel #5
0
        /// <summary>
        /// Validate the creation (or editing)
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void ButtonOK_Click(object Sender, EventArgs Event)
        {
            DialogResult = DialogResult.OK;
            Brand Brand = GetBrand();

            if (Brand != null)
            {
                DbConnect.GetInstance().UpdateOrCreateBrand(Brand);
            }
            Close();
        }
Beispiel #6
0
        /// <summary>
        /// Put the attributes of the given subfamily in the corresponding fields
        /// </summary>
        /// <param name="SubFamily">The subfamily (or null for empty window)</param>
        private void Construct(SubFamily SubFamily)
        {
            //Do not allow resizing
            StartPosition   = FormStartPosition.CenterParent;
            DialogResult    = DialogResult.Cancel;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            MaximizeBox     = false;
            MinimizeBox     = false;

            // Filling the combobox
            SQLiteConnection Connection          = DbConnect.GetInstance().GetConnection();
            SQLiteCommand    CommandSelectBrands = new SQLiteCommand("SELECT * FROM Familles", Connection);
            SQLiteDataReader ResultFamilies      = CommandSelectBrands.ExecuteReader();

            if (ResultFamilies != null)
            {
                while (ResultFamilies.Read())
                {
                    object ObjId   = ResultFamilies["RefFamille"];
                    long   BrandId = 0;
                    if (ObjId != DBNull.Value)
                    {
                        BrandId = Convert.ToInt64(ObjId);
                    }
                    object ObjName   = ResultFamilies["Nom"];
                    string BrandName = "";
                    if (ObjName != DBNull.Value)
                    {
                        BrandName = Convert.ToString(ObjName);
                    }
                    ComboBoxFamily.Items.Add(new ComboBoxItem {
                        Name = BrandName, Value = BrandId
                    });
                }
                ResultFamilies.Close();
            }
            else
            {
                throw new FieldAccessException("Getting families failed");
            }

            if (SubFamily != null)
            {
                SetSubFamily(SubFamily);
            }
            else
            {
                _Id = -1;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Define what to do when a click occurs on a element in the list of the articles
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void OnClickArticle(object Sender, MouseEventArgs Event)
        {
            if (Event.Clicks == 2)
            {
                if (listView1.SelectedItems.Count == 1)
                {
                    ListViewItem Item = listView1.SelectedItems[0];
                    UpdateArticle((Article)Item.Tag);
                }
            }
            else if (Event.Button == MouseButtons.Right)
            {
                ContextMenu ContextMenu1 = new ContextMenu();

                if (listView1.SelectedItems.Count == 1)
                {
                    //Create context menu
                    ListViewItem Item    = listView1.SelectedItems[0];
                    MenuItem     MenuAdd = new MenuItem("Add article");
                    MenuAdd.Click += (Sender2, Event2) =>
                    {
                        UpdateArticle(null);
                    };
                    MenuItem MenuMod = new MenuItem("Edit article");
                    MenuMod.Click += (Sender2, Event2) =>
                    {
                        UpdateArticle((Article)Item.Tag);
                    };
                    MenuItem MenuDel = new MenuItem("Delete article");
                    MenuDel.Click += (Sender2, Event2) =>
                    {
                        DbConnect.GetInstance().DeleteArticle(((Article)Item.Tag).Reference);
                        LoadDatabase();
                    };

                    ContextMenu1.MenuItems.Add(MenuAdd);
                    ContextMenu1.MenuItems.Add(MenuMod);
                    ContextMenu1.MenuItems.Add(MenuDel);
                }

                MenuItem MenuRfh = new MenuItem("Refresh");
                MenuRfh.Click += (Sender2, Event2) => LoadDatabase();
                ContextMenu1.MenuItems.Add(MenuRfh);

                ContextMenu1.Show(this, Event.Location);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Validate the creation (or editing)
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void ButtonOK_Click(object Sender, EventArgs Event)
        {
            Article Article = GetArticle();

            if (!Regex.IsMatch(Article.Reference, @"^F[0-9]{7}$"))
            {
                MessageBox.Show(@"Wrong reference");
                return;
            }
            DialogResult = DialogResult.OK;

            if (Article != null)
            {
                DbConnect.GetInstance().UpdateOrCreateArticle(Article);
            }
            Close();
        }
Beispiel #9
0
        /// <summary>
        /// Reload all the items in the view from the database
        /// </summary>
        private void LoadDatabase()
        {
            listView1.Columns.Clear();
            listView1.Items.Clear();
            SQLiteDataAdapter Adapter = new SQLiteDataAdapter("SELECT RefFamille, Nom FROM Familles",
                                                              DbConnect.GetInstance().GetConnection());
            DataTable Dt = new DataTable();

            Adapter.Fill(Dt);

            listView1.KeyDown           += OnListViewKeyDown;
            listView1.Sorting            = SortOrder.Ascending;
            listView1.ColumnClick       += OnColumnClick;
            listView1.ListViewItemSorter = new ListViewItemComparer();

            //Create columns
            listView1.Columns.Add("RefFamille");
            listView1.Columns.Add("Nom");

            //Add items
            for (int I = 0; I < Dt.Rows.Count; I++)
            {
                DataRow      Dr       = Dt.Rows[I];
                ListViewItem ListItem = new ListViewItem(Dr["RefFamille"].ToString());
                ListItem.SubItems.Add(Dr["Nom"].ToString());
                ListItem.Tag = new Family(
                    Convert.ToInt64(Dr["RefFamille"].ToString()),
                    Dr["Nom"].ToString()
                    );
                listView1.Items.Add(ListItem);
            }

            //Resize columns
            listView1.Columns[0].Width = -2;
            listView1.Columns[1].Width = -2;

            Adapter.Dispose();
        }
Beispiel #10
0
 /// <summary>
 /// Close the database when the application is closed
 /// </summary>
 /// <param name="Sender"></param>
 /// <param name="Event"></param>
 private static void MainWindow_FormClosing(object Sender, EventArgs Event)
 {
     DbConnect.GetInstance().Close();
 }
Beispiel #11
0
        /// <summary>
        /// Reload (or not) the database, then group the data
        /// </summary>
        /// <param name="ShouldReloadData"></param>
        private void LoadDatabase(bool ShouldReloadData = true)
        {
            if (ShouldReloadData)
            {
                listView1.Columns.Clear();
                listView1.Items.Clear();
                SQLiteDataAdapter Adapter = new SQLiteDataAdapter("SELECT Marques.RefMarque AS RefMarque, SousFamilles.RefSousFamille AS RefSousFamille, Articles.RefArticle AS RefArticle, Articles.Description AS Description, Articles.PrixHT AS PrixHT, Articles.Quantite AS Quantite, SousFamilles.Nom AS SousFamille, Familles.Nom AS Famille, Marques.Nom AS Marque FROM Articles LEFT JOIN Marques ON Articles.RefMarque = Marques.RefMarque LEFT JOIN SousFamilles ON Articles.RefSousFamille = SousFamilles.RefSousFamille LEFT JOIN Familles ON SousFamilles.RefFamille = Familles.RefFamille", DbConnect.GetInstance().GetConnection());
                DataTable         Dt      = new DataTable();
                Adapter.Fill(Dt);

                listView1.KeyDown           += OnListViewKeyDown;
                listView1.Sorting            = SortOrder.Ascending;
                listView1.ColumnClick       += OnColumnClick;
                listView1.ListViewItemSorter = new ListViewItemComparer();

                //Create columns
                listView1.Columns.Add("RefArticle");
                listView1.Columns.Add("Description");
                listView1.Columns.Add("Family");
                listView1.Columns.Add("Sub Family");
                listView1.Columns.Add("Brand");
                listView1.Columns.Add("Price excluding VAT (€)");
                listView1.Columns.Add("Quantity");

                //Add items
                for (int I = 0; I < Dt.Rows.Count; I++)
                {
                    DataRow      Dr       = Dt.Rows[I];
                    ListViewItem ListItem = new ListViewItem(Dr["RefArticle"].ToString());
                    ListItem.SubItems.Add(Dr["Description"].ToString());
                    ListItem.SubItems.Add(Dr["Famille"].ToString());
                    ListItem.SubItems.Add(Dr["SousFamille"].ToString());
                    ListItem.SubItems.Add(Dr["Marque"].ToString());
                    ListItem.SubItems.Add(Dr["PrixHT"].ToString());
                    ListItem.SubItems.Add(Dr["Quantite"].ToString());
                    ListItem.Tag = new Article(
                        Dr["RefArticle"].ToString(),
                        Dr["Description"].ToString(),
                        Convert.ToInt64(Dr["RefSousFamille"].ToString()),
                        Convert.ToInt64(Dr["RefMarque"].ToString()),
                        double.Parse(Dr["PrixHT"].ToString()),
                        Convert.ToInt64(Dr["Quantite"].ToString())
                        );
                    listView1.Items.Add(ListItem);
                }
                Adapter.Dispose();
            }
            else
            {
                listView1.Groups.Clear();
            }

            //Resize columns
            listView1.Columns[0].Width = -2;
            listView1.Columns[1].Width = -2;
            listView1.Columns[2].Width = -2;
            listView1.Columns[3].Width = -2;
            listView1.Columns[4].Width = -2;
            listView1.Columns[5].Width = -2;
            listView1.Columns[6].Width = -2;

            if (_SortColumn == 0 || _SortColumn == 1) //Hide or show groups
            {
                listView1.ShowGroups = false;
            }
            else
            {
                listView1.ShowGroups = true;
                foreach (ListViewItem ListItem in listView1.Items) //Set group for each item
                {
                    ListItem.Group = null;
                    ListViewGroup Group = null;
                    foreach (ListViewGroup GroupTest in listView1.Groups)
                    {
                        if (GroupTest.Header == ListItem.SubItems[_SortColumn].Text)
                        {
                            Group = GroupTest;
                            break;
                        }
                    }

                    if (Group == null)
                    {
                        Group        = new ListViewGroup();
                        Group.Name   = ListItem.SubItems[_SortColumn].Text;
                        Group.Header = ListItem.SubItems[_SortColumn].Text;
                        listView1.Groups.Add(Group);
                    }

                    Group = listView1.Groups[ListItem.SubItems[_SortColumn].Text];
                    Group.Items.Add(ListItem);
                    ListItem.Group = Group;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Reload (or not) the database, then group the data
        /// </summary>
        /// <param name="ShouldReloadData"></param>
        private void LoadDatabase(bool ShouldReloadData = true)
        {
            if (ShouldReloadData)
            {
                listView1.Columns.Clear();
                listView1.Items.Clear();
                SQLiteDataAdapter Adapter = new SQLiteDataAdapter(
                    "SELECT RefSousFamille, RefFamille, Nom FROM SousFamilles",
                    DbConnect.GetInstance().GetConnection());
                DataTable Dt = new DataTable();
                Adapter.Fill(Dt);

                listView1.KeyDown           += OnListViewKeyDown;
                listView1.Sorting            = SortOrder.Ascending;
                listView1.ColumnClick       += OnColumnClick;
                listView1.ListViewItemSorter = new ListViewItemComparer();

                //Create columns
                listView1.Columns.Add("RefSousFamille");
                listView1.Columns.Add("RefFamille");
                listView1.Columns.Add("Nom");

                //Add items
                for (int I = 0; I < Dt.Rows.Count; I++)
                {
                    DataRow      Dr       = Dt.Rows[I];
                    ListViewItem ListItem = new ListViewItem(Dr["RefSousFamille"].ToString());
                    ListItem.SubItems.Add(Dr["RefFamille"].ToString());
                    ListItem.SubItems.Add(Dr["Nom"].ToString());
                    ListItem.Tag = new SubFamily(
                        Convert.ToInt64(Dr["RefSousFamille"].ToString()),
                        Convert.ToInt64(Dr["RefFamille"].ToString()),
                        Dr["Nom"].ToString()
                        );
                    listView1.Items.Add(ListItem);
                }

                Adapter.Dispose();
            }
            else
            {
                listView1.Groups.Clear();
            }

            //Resize columns
            listView1.Columns[0].Width = -2;
            listView1.Columns[1].Width = -2;
            listView1.Columns[2].Width = -2;

            if (_SortColumn == 0 || _SortColumn == 2) //If should group or not
            {
                listView1.ShowGroups = false;
            }
            else
            {
                //Create groups
                listView1.ShowGroups = true;
                foreach (ListViewItem ListItem in listView1.Items)
                {
                    ListItem.Group = null;
                    ListViewGroup Group = null;
                    foreach (ListViewGroup GroupTest in listView1.Groups)
                    {
                        if (GroupTest.Header == ListItem.SubItems[_SortColumn].Text)
                        {
                            Group = GroupTest;
                            break;
                        }
                    }

                    if (Group == null)
                    {
                        Group        = new ListViewGroup();
                        Group.Name   = ListItem.SubItems[_SortColumn].Text;
                        Group.Header = ListItem.SubItems[_SortColumn].Text;
                        listView1.Groups.Add(Group);
                    }

                    Group = listView1.Groups[ListItem.SubItems[_SortColumn].Text];
                    Group.Items.Add(ListItem);
                    ListItem.Group = Group;
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Put the attributes of the given article in the corresponding fields
        /// </summary>
        /// <param name="Article">The article (or null for empty window)</param>
        private void Construct(Article Article)
        {
            //Do not allow resizing
            StartPosition   = FormStartPosition.CenterParent;
            DialogResult    = DialogResult.Cancel;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            MaximizeBox     = false;
            MinimizeBox     = false;

            //Filling the comboboxes
            SQLiteConnection Connection          = DbConnect.GetInstance().GetConnection();
            SQLiteCommand    CommandSelectBrands = new SQLiteCommand("SELECT * FROM Marques", Connection);
            SQLiteDataReader ResultBrands        = CommandSelectBrands.ExecuteReader();

            if (ResultBrands != null)
            {
                while (ResultBrands.Read())
                {
                    object ObjId   = ResultBrands["RefMarque"];
                    long   BrandId = 0;
                    if (ObjId != DBNull.Value)
                    {
                        BrandId = Convert.ToInt64(ObjId);
                    }
                    object ObjName   = ResultBrands["Nom"];
                    string BrandName = "";
                    if (ObjName != DBNull.Value)
                    {
                        BrandName = Convert.ToString(ObjName);
                    }
                    ComboBoxBrand.Items.Add(new ComboBoxItem {
                        Name = BrandName, Value = BrandId
                    });
                }
                ResultBrands.Close();
            }
            else
            {
                throw new FieldAccessException("Getting brands failed");
            }
            SQLiteCommand    CommandSelectSf = new SQLiteCommand("SELECT * FROM SousFamilles ORDER BY RefFamille", Connection);
            SQLiteDataReader ResultSf        = CommandSelectSf.ExecuteReader();

            if (ResultSf != null)
            {
                while (ResultSf.Read())
                {
                    object ObjId = ResultSf["RefSousFamille"];
                    long   SfId  = 0;
                    if (ObjId != DBNull.Value)
                    {
                        SfId = Convert.ToInt64(ObjId);
                    }
                    object ObjName = ResultSf["Nom"];
                    string SfName  = "";
                    if (ObjName != DBNull.Value)
                    {
                        SfName = Convert.ToString(ObjName);
                    }
                    ComboBoxSubFamily.Items.Add(new ComboBoxItem {
                        Name = SfName, Value = SfId
                    });
                }
                ResultSf.Close();
            }
            else
            {
                throw new FieldAccessException("Getting subfamily failed");
            }

            if (Article != null)
            {
                SetArticle(Article);
            }
        }