Beispiel #1
0
        public string JsonStockModif()
        {
            JavaScriptSerializer ser = new JavaScriptSerializer();

            var jsonData = new StockDto()
            {
                id               = Convert.ToInt64(idStock),
                idProduit        = Convert.ToInt64(idProduitStock),
                quantite         = Convert.ToInt32(quantiteStock),
                quantiteCommande = Convert.ToInt32(quantiteStockCommande),
            };

            var result = ser.Serialize(jsonData);

            return(result);
        }
Beispiel #2
0
        public string JsonStock()
        {
            JavaScriptSerializer ser = new JavaScriptSerializer();

            var jsonData = new StockDto()
            {
                idProduit        = i,
                quantite         = 0,
                quantiteCommande = 0,
            };


            var result = ser.Serialize(jsonData);

            return(result);
        }
Beispiel #3
0
        private void button_Terminer_Commande_Click(object sender, EventArgs e)
        {
            // On créer une commande
            string url = "http://localhost:58841/api/CommandeInternes";

            prixtotaux = 0;
            foreach (KeyValuePair <string, int> entry in listSelect)
            {
                var prixLoop = entry.Value;
                prixtotaux += prixLoop;
            }

            string requestParams = JsonTCommandeInterne();

            webRequest             = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Method      = "POST";
            webRequest.ContentType = "application/json";

            byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
            webRequest.ContentLength = byteArray.Length;
            using (Stream requestStream = webRequest.GetRequestStream())
            {
                requestStream.Write(byteArray, 0, byteArray.Length);
            }

            AppelApiId();
            // on rucupère la liste des produits et leurs stocks
            url        = "http://localhost:58841/api/Stocks";
            webRequest = (HttpWebRequest)WebRequest.Create(url);
            var webResponse = (HttpWebResponse)webRequest.GetResponse();

            if ((webResponse.StatusCode == HttpStatusCode.OK))
            {
                var    reader = new StreamReader(webResponse.GetResponseStream());
                string s      = reader.ReadToEnd();
                var    arr    = JsonConvert.DeserializeObject <List <StockDto> >(s);

                // Pour chaque Article dans la commande
                foreach (KeyValuePair <long, int> entry in listSelectCmd)
                {
                    url = "http://localhost:58841/api/CommandeInterneProduits";
                    var idSelectLoop = entry.Key;
                    var quantiteLoop = entry.Value;
                    var allStockId   = from r in arr
                                       orderby r.id
                                       select r;

                    // On ajoute un le produit a la commande
                    requestParams          = JsonTCommandeInterneProduit(idSelectLoop, quantiteLoop);
                    webRequest             = (HttpWebRequest)WebRequest.Create(url);
                    webRequest.Method      = "POST";
                    webRequest.ContentType = "application/json";

                    byte[] byteArrayy = Encoding.UTF8.GetBytes(requestParams);
                    webRequest.ContentLength = byteArrayy.Length;
                    using (Stream requestStream = webRequest.GetRequestStream())
                    {
                        requestStream.Write(byteArrayy, 0, byteArrayy.Length);
                    }

                    // Mise a jours du stock commandé sur le produit
                    foreach (var std in allStockId)
                    {
                        if (std.idProduit == idSelectLoop)
                        {
                            var idStock = std.id;
                            url = "http://localhost:58841/api/Stocks/" + idStock.ToString();
                            JavaScriptSerializer ser = new JavaScriptSerializer();
                            var jsonData             = new StockDto()
                            {
                                id               = idStock,
                                idProduit        = idSelectLoop,
                                quantite         = std.quantite,
                                quantiteCommande = quantiteLoop + std.quantiteCommande,
                            };
                            requestParams = ser.Serialize(jsonData);

                            webRequest             = (HttpWebRequest)WebRequest.Create(url);
                            webRequest.Method      = "PUT";
                            webRequest.ContentType = "application/json";

                            byte[] byteArray2 = Encoding.UTF8.GetBytes(requestParams);
                            webRequest.ContentLength = byteArray2.Length;
                            using (Stream requestStream = webRequest.GetRequestStream())
                            {
                                requestStream.Write(byteArray2, 0, byteArray2.Length);
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show(string.Format("Status code == {0}", webResponse.StatusCode));
            }
            // On ferme le formulaire de commande
            this.Close();
        }
Beispiel #4
0
        private void btn_edit_commandeFournisseur_Click(object sender, EventArgs e)
        {
            if (dataGridView_Commandes.SelectedCells.Count > 0)
            {
                int selectedrowindex = dataGridView_Commandes.SelectedCells[0].RowIndex;

                DataGridViewRow selectedRow = dataGridView_Commandes.Rows[selectedrowindex];

                idCommandeFournisseur = Convert.ToString(selectedRow.Cells["id"].Value);
                prixTotalCommande     = Convert.ToString(selectedRow.Cells["prixTotal"].Value);
                dateCommandeEdit      = Convert.ToString(selectedRow.Cells["dateCommande"].Value);
                statusCommande        = Convert.ToString(selectedRow.Cells["status"].Value);
            }

            string url = "http://localhost:58841/api/commandeInternes/" + idCommandeFournisseur;

            webRequest = (HttpWebRequest)WebRequest.Create(url);
            var webResponse = (HttpWebResponse)webRequest.GetResponse();

            if ((webResponse.StatusCode == HttpStatusCode.OK))
            {
                var    reader   = new StreamReader(webResponse.GetResponseStream());
                string s        = reader.ReadToEnd();
                var    arrStock = JsonConvert.DeserializeObject <CommandeInterneDto>(s);
                oldStatus = arrStock.status;
            }

            url = "http://localhost:58841/api/commandeInternes/" + idCommandeFournisseur;
            string requestParams = JsonCommandeModif();

            webRequest = (HttpWebRequest)WebRequest.Create(url);

            webRequest.Method      = "PUT";
            webRequest.ContentType = "application/json";

            byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
            webRequest.ContentLength = byteArray.Length;
            using (Stream requestStream = webRequest.GetRequestStream())
            {
                requestStream.Write(byteArray, 0, byteArray.Length);
            }

            if (statusCommande == "Livré" && oldStatus != "Livré")
            {
                // on rucupère la liste des produits et leurs stocks
                url         = "http://localhost:58841/api/Stocks";
                webRequest  = (HttpWebRequest)WebRequest.Create(url);
                webResponse = (HttpWebResponse)webRequest.GetResponse();

                if ((webResponse.StatusCode == HttpStatusCode.OK))
                {
                    var    reader   = new StreamReader(webResponse.GetResponseStream());
                    string s        = reader.ReadToEnd();
                    var    arrStock = JsonConvert.DeserializeObject <List <StockDto> >(s);

                    var allStockId = from r in arrStock
                                     orderby r.id
                                     select r;
                    url         = "http://localhost:58841/api/CommandeInterneProduits/";
                    webRequest  = (HttpWebRequest)WebRequest.Create(url);
                    webResponse = (HttpWebResponse)webRequest.GetResponse();

                    if ((webResponse.StatusCode == HttpStatusCode.OK))
                    {
                        reader = new StreamReader(webResponse.GetResponseStream());
                        s      = reader.ReadToEnd();
                        var arrProduitCommande = JsonConvert.DeserializeObject <List <CommandeInterneProduitDto> >(s);

                        var allCommandeInterneProduitsId = from r in arrProduitCommande
                                                           orderby r.idCommandeInterne
                                                           select r;

                        // Mise a jours du stock commandé sur le produit
                        foreach (var stdStock in allStockId)
                        {
                            foreach (var stdCommande in allCommandeInterneProduitsId)
                            {
                                if (stdStock.idProduit == stdCommande.idProduit && stdCommande.idCommandeInterne.ToString() == idCommandeFournisseur)
                                {
                                    var idStock = stdStock.id;
                                    url = "http://localhost:58841/api/Stocks/" + idStock.ToString();
                                    JavaScriptSerializer ser = new JavaScriptSerializer();
                                    var jsonData             = new StockDto()
                                    {
                                        id               = idStock,
                                        idProduit        = stdCommande.idProduit,
                                        quantite         = stdStock.quantite + stdCommande.quantite,
                                        quantiteCommande = stdStock.quantiteCommande - stdCommande.quantite,
                                    };
                                    requestParams = ser.Serialize(jsonData);

                                    webRequest             = (HttpWebRequest)WebRequest.Create(url);
                                    webRequest.Method      = "PUT";
                                    webRequest.ContentType = "application/json";

                                    byte[] byteArray2 = Encoding.UTF8.GetBytes(requestParams);
                                    webRequest.ContentLength = byteArray2.Length;
                                    using (Stream requestStream = webRequest.GetRequestStream())
                                    {
                                        requestStream.Write(byteArray2, 0, byteArray2.Length);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }