Exemplo n.º 1
0
 public Form2(string mode, ProductXML product)
 {
     InitializeComponent();
     this.mode    = mode;
     this.product = product;
     if (mode.Equals("EDIT"))
     {
         titleTxt.Text   = product.Title;
         countryTxt.Text = product.Country;
         priceTxt.Text   = product.Price.ToString();
     }
 }
Exemplo n.º 2
0
 private void delBtn_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedItem != null)
     {
         ProductXML del = (ProductXML)listBox1.SelectedItem;
         listBox1.Items.RemoveAt(listBox1.SelectedIndex);
         string res = Connect.DeleteProduct(del);   // Delete from Database
     }
     else
     {
         MessageBox.Show("You didn't select any element", "This has failed...",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Exemplo n.º 3
0
 private void editBtn_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedItem != null)
     {
         ProductXML selectedProd = (ProductXML)listBox1.SelectedItem; // listBox1.SelectedItem as ProductXML
         f2       = new Form2("EDIT", selectedProd);
         f2.Owner = this;
         f2.Text  = "Editing The Product";
         f2.ShowDialog();
     }
     else
     {
         MessageBox.Show("You didn't select any element", "This has failed...",
                         MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        public static List <ProductXML> Read_Products_From_DB()
        {
            List <ProductXML> products = new List <ProductXML>();
            string            query    = "SELECT Id, Title, Country, Price from dbo.Products";
            SqlConnection     conn     = null;
            SqlCommand        cmd      = null;
            SqlDataReader     dReader  = null;

            try
            {
                using (conn = new SqlConnection(Connect.ConnectionString))
                {
                    using (cmd = new SqlCommand(query, conn))
                    {
                        conn.Open();
                        dReader = cmd.ExecuteReader();

                        while (dReader.Read())
                        {
                            ProductXML p = new ProductXML();
                            p.Id      = Convert.ToInt32(dReader["id"]);
                            p.Title   = dReader["title"].ToString();
                            p.Country = dReader["country"].ToString();
                            p.Price   = Convert.ToInt32(dReader["price"]);

                            products.Add(p);
                        }
                    }
                }
            }
            catch (DataException ex)
            {
                MessageBox.Show(ex.Message, "failed...Something went wrong..",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                dReader.Close();
                conn.Close();
            }

            return(products);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Sérialize, c'est à dire met les informations souhaitées au format XML.
        /// On utilise les références using System.IO pour l'écriture de fichier (de C# vers Editix)
        /// et System.Xml.Serialization pour les méthodes relatives à la mise au format XML
        /// </summary>
        public void SerializerXML()
        {
            DaoProvider daoProvider = new DaoProvider();
            //On récupère tous les fournisseurs de la base de données dont au moins un des produits qu'il fournissent ont
            //leur stock actuel inférieur à leur stock minimal
            List <Provider> providers = daoProvider.ReadAllWithProductToRestock();
            //On crée la liste des Fournisseur que l'on mettra dans le fichier XML.
            //Elle a comme attributs le nom du fournisseur et les produits à réapprovisionner
            //qui ont aussi une classe dédiée (Nom du produit et la quantité à commander [stock max - stock actuel])
            List <ProviderXML> providersXML = new List <ProviderXML>();

            //On parcourt chaque fournisseur de la liste
            foreach (Provider provider in providers)
            {
                //On récupère la liste des produits fournis par ce fournisseur dont leur stock actuel est inférieur à leur
                //stock minimal

                //On crée la liste des ProduitXML (classe définie en dessous)
                List <ProductXML> productsXML = new List <ProductXML>();

                //On parcourt chaque produit de la liste de produits à réapprovisionner de chaque fournisseur
                foreach (Product product in provider.Products)
                {
                    ProductXML productXML = new ProductXML
                    {
                        Nom = product.Name,
                        Quantite_A_Commander = product.QuantityToOrder
                    };
                    productsXML.Add(productXML);
                }
                ProviderXML providerXML = new ProviderXML(provider);
                providerXML.Produits = productsXML;
                providersXML.Add(providerXML);
            }
            // Instanciation des outils ( StreamWriter et Serializer )
            XmlSerializer xs = new XmlSerializer(typeof(List <ProviderXML>)); // l'outil de sérialisation
            StreamWriter  wr = new StreamWriter("Fournisseurs.xml");          // accès en écriture d'un fichier ( texte )

            //On veut récupérer seulement certains attributs de nos classes produits et fournisseurs
            xs.Serialize(wr, providersXML); // action de sérialiser en XML l'objet Fxml
            wr.Close();
        }
        public Laptops ParseProductToXMLData(Product[] data)
        {
            var elements = new List <ProductXML>();

            foreach (Product element in data)
            {
                ProductXML laptop = new ProductXML();
                laptop.screen       = new Screen();
                laptop.disc         = new Disc();
                laptop.graphic_card = new GraphicCard();
                laptop.processor    = new Processor();

                laptop.@id                      = element.Id;
                laptop.manufacturer             = element.Producent;
                laptop.screen.size              = element.Matryca;
                laptop.screen.resolution        = element.Rozdzielczosc;
                laptop.screen.type              = element.TypMatrycy;
                laptop.screen.@touch            = element.DotykowyEkran;
                laptop.processor.name           = element.CPU;
                laptop.processor.physical_cores = element.IloscRdzeni;
                laptop.processor.clock_speed    = element.MHZ;
                laptop.ram                      = element.RAM;
                laptop.disc.storage             = element.PojemnoscDysku;
                laptop.disc.@type               = element.RodzajDysku;
                laptop.graphic_card.name        = element.GPU;
                laptop.graphic_card.memory      = element.VRAM;
                laptop.os          = element.SystemOperacyjny;
                laptop.disc_reader = element.NapedOptyczny;
                elements.Add(laptop);
            }
            Laptops XMLData = new Laptops();

            XMLData.laptops        = new Laptop();
            XMLData.laptops.laptop = new List <ProductXML>();
            XMLData.laptops.laptop = elements;
            return(XMLData);
        }
Exemplo n.º 7
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            if (mode.Equals("ADD"))
            {
                string result = string.Empty;
                try
                {
                    try
                    {
                        if (titleTxt.Text == "" && countryTxt.Text == "" && priceTxt.Text == "")
                        {
                            MessageBox.Show("All Fields is Empty!! Try To Fill it!", "All fields Empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else if (titleTxt.Text == "" || countryTxt.Text == "" || priceTxt.Text == "")
                        {
                            MessageBox.Show("Some of Field is Empty!! Try To Fill it!", "Some field Empty", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                        else
                        {
                            ProductXML product = new ProductXML(titleTxt.Text, countryTxt.Text, Convert.ToInt32(priceTxt.Text));
                            result = Connect.AddProduct(product);

                            if (result == "Product was added successfully")
                            {
                                //List<ProductXML> products = new List<ProductXML>();
                                (this.Owner as productForm).listBox1.Items.Add(product);
                                MessageBox.Show("Add to List & Xml File & Database!", result, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                                titleTxt.Text   = "";
                                countryTxt.Text = "";
                                priceTxt.Text   = "";
                            }
                            else
                            {
                                MessageBox.Show(result, "failed...", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    catch { }
                }
                catch (DataException de)
                {
                    MessageBox.Show(de.Message, "System of an Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else if (mode.Equals("EDIT"))
            {
                int        price  = Convert.ToInt32(priceTxt.Text);
                int        index  = (this.Owner as productForm).listBox1.Items.IndexOf(this.product);
                ProductXML update = new ProductXML(titleTxt.Text, countryTxt.Text, price);
                int        id     = product.Id;
                (this.Owner as productForm).listBox1.Items.RemoveAt(index);
                (this.Owner as productForm).listBox1.Items.Insert(index, update);
                // (this.Owner as productForm).listBox1.DisplayMember = "";
                (this.Owner as productForm).Text = $"{Connect.UpdateProduct(id, update)}";

                this.Close();
            }
            else
            {
                MessageBox.Show("Something went wrong...", "..failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }