/// <summary>
        /// Controle de la nouvelle pression et de la date de peremption pour affichage dynamique
        /// </summary>
        /// <param name="reportvalue">valeur relevée à l'instant</param>
        /// <param name="continumber">Numéro Conti de la bouteille</param>
        /// <param name="lastpressure">Pression précédente</param>
        /// <param name="process">id dans la table location -> id= 1 BM ; id= 5 BR</param>
        /// <param name="expiration_date">date d'expiration</param>
        /// <returns>affichage dynamique: vert si OK, Orange si Warning, Rouge si NOK</returns>
        public ActionResult NewReport(int reportvalue, int continumber, int?lastpressure, int process, DateTime expiration_date)
        {
            tbl_607_gaz_reporting tbl_607_Gaz_Reporting = new tbl_607_gaz_reporting();
            string user     = System.Web.HttpContext.Current.User.Identity.Name.ToString();
            int    idtech   = db.tbl_607_actors.Where(t => t.id_uid == user).Select(t => t.id).FirstOrDefault();
            int    idbottle = db.tbl_607_bottle.Where(t => t.bottle_conti_number == continumber.ToString() && t.FK_ID_location == process).Select(t => t.ID).FirstOrDefault();

            //la pression précédente est supérieure à la pression relevée et la bouteille n'est pas expirée
            //on retourne le message "invalid"
            if (lastpressure <= reportvalue & expiration_date > DateTime.Now)
            {
                ViewBag.message = "invalid";
                return(View("_PartialMessageValidation"));
            }
            //la pression est inférieure à la pression précédente et est supérieure à 50 bars, et la bouteille n'est pas expirée
            //on retourne le message "ok"
            else if (lastpressure > reportvalue & reportvalue > 50 & expiration_date > DateTime.Now)
            {
                tbl_607_Gaz_Reporting.FK_ID_actors   = idtech;
                tbl_607_Gaz_Reporting.FK_ID_bottle   = idbottle;
                tbl_607_Gaz_Reporting.pressure_value = reportvalue;
                tbl_607_Gaz_Reporting.reporting_date = DateTime.Now;
                db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting);
                db.SaveChanges();
                ViewBag.message = "ok";
                return(View("_PartialMessageValidation"));
            }
            //la pression est inférieure à la pression précédente et est comprise entre 50 et 20 bars, et la bouteille n'est pas expirée
            //on retourne le message "warning"
            else if (lastpressure > reportvalue & reportvalue <= 50 && reportvalue > 20 & expiration_date > DateTime.Now)
            {
                tbl_607_Gaz_Reporting.FK_ID_actors   = idtech;
                tbl_607_Gaz_Reporting.FK_ID_bottle   = idbottle;
                tbl_607_Gaz_Reporting.pressure_value = reportvalue;
                tbl_607_Gaz_Reporting.reporting_date = DateTime.Now;
                db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting);
                db.SaveChanges();
                ViewBag.message = "warning";
                return(View("_PartialMessageValidation"));
            }
            //la bouteille est expirée
            //on retourne le message "expired"
            else if (expiration_date <= DateTime.Now)
            {
                tbl_607_Gaz_Reporting.FK_ID_actors   = idtech;
                tbl_607_Gaz_Reporting.FK_ID_bottle   = idbottle;
                tbl_607_Gaz_Reporting.pressure_value = reportvalue;
                tbl_607_Gaz_Reporting.reporting_date = DateTime.Now;
                db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting);
                db.SaveChanges();
                ViewBag.message = "expired";
                return(View("_PartialMessageValidation"));
            }
            //la pression est inférieure à la pression précédente et est inférieure à 20 bars, et la bouteille n'est pas expirée
            //on retourne le message "nok"
            else
            {
                tbl_607_Gaz_Reporting.FK_ID_actors   = idtech;
                tbl_607_Gaz_Reporting.FK_ID_bottle   = idbottle;
                tbl_607_Gaz_Reporting.pressure_value = reportvalue;
                tbl_607_Gaz_Reporting.reporting_date = DateTime.Now;
                db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting);
                db.SaveChanges();
                ViewBag.message = "nok";
                return(View("_PartialMessageValidation"));
            }
        }
Beispiel #2
0
        public ActionResult SaveData()
        {
            try
            {
                // vérification de l'existance du BL
                // extraction des numeros de BL existants sur le contrat
                var BLBase = (db.tbl_607_shipping_delivery.Include(t => t.tbl_607_shipping_request).Include(s => s.tbl_607_shipping_request.tbl_607_order)
                              .Include(o => o.tbl_607_shipping_request.tbl_607_order.tbl_607_order_details))
                             .Where(o => o.tbl_607_shipping_request.tbl_607_order.ID == BottlereceptionWizardViewModelTemp.idcontract).Select(t => t.BL_ref).ToList();


                tbl_607_shipping_delivery tbl_607_Shipping_Delivery = new tbl_607_shipping_delivery();
                // comparaison avec le numero saisi par l'utilisateur
                var Control = BLBase.Contains(BottlereceptionWizardViewModelTemp.BL_ref);
                if (Control)
                {
                    //BL existant, nous allons donc uniquement proceder à un update
                }
                else
                {
                    //BL inexistant, creation
                    tbl_607_Shipping_Delivery.BL_ref                 = BottlereceptionWizardViewModelTemp.BL_ref;
                    tbl_607_Shipping_Delivery.reception_date         = BottlereceptionWizardViewModelTemp.reception_date;
                    tbl_607_Shipping_Delivery.FK_ID_shipping_request = BottlereceptionWizardViewModelTemp.FK_ID_shipping_request;
                    db.tbl_607_shipping_delivery.Add(tbl_607_Shipping_Delivery);
                    db.SaveChanges(); //sauvegarde
                }

                // le certificat de conformite est unique et est lie a une bouteille
                tbl_607_conformity_certificate tbl_607_Conformity_Certificate = new tbl_607_conformity_certificate();
                tbl_607_Conformity_Certificate.ID = BottlereceptionWizardViewModelTemp.conformity_certificate;
                tbl_607_Conformity_Certificate.fabrication_date = BottlereceptionWizardViewModelTemp.fabrication_date;
                tbl_607_Conformity_Certificate.expiration_date  = BottlereceptionWizardViewModelTemp.expiration_date;
                db.tbl_607_conformity_certificate.Add(tbl_607_Conformity_Certificate);
                db.SaveChanges(); //sauvegarde

                // recuperation des id des enregistrements crees
                var FK_ID_shipping_delivery = db.tbl_607_shipping_delivery.Select(t => t.ID).Max();

                // recuperation de l'id location pour stock
                var stock = db.tbl_607_location.Where(t => t.bottle_location == "STOCK").Select(t => t.ID).First();

                // enregistrement dans la table bouteille
                tbl_607_bottle tbl_607_Bottle = new tbl_607_bottle();
                tbl_607_Bottle.manufacturer_bottle_number   = BottlereceptionWizardViewModelTemp.manufacturer_bottle_number;
                tbl_607_Bottle.bottle_conti_number          = BottlereceptionWizardViewModelTemp.bottle_conti_number;
                tbl_607_Bottle.FK_ID_conformity_certificate = BottlereceptionWizardViewModelTemp.conformity_certificate;
                tbl_607_Bottle.FK_ID_shipping_delivery      = FK_ID_shipping_delivery;
                tbl_607_Bottle.FK_ID_order    = BottlereceptionWizardViewModelTemp.idcontract;
                tbl_607_Bottle.FK_ID_location = stock;
                db.tbl_607_bottle.Add(tbl_607_Bottle);
                db.SaveChanges(); //sauvegarde

                // mise à jour de la quantité recue sur le poste
                tbl_607_order_details tbl_607_Order_Detail = db.tbl_607_order_details.Where(t => t.poste_number == BottlereceptionWizardViewModelTemp.posteNumber && t.FK_ID_order == BottlereceptionWizardViewModelTemp.idcontract).First();
                tbl_607_Order_Detail.recieved_quantity = tbl_607_Order_Detail.recieved_quantity++;
                db.SaveChanges(); //sauvegarde

                // mise a jour de la quantité sur la demande de livraison
                tbl_607_shipping_request_details tbl_607_Shipping_Request_Details = db.tbl_607_shipping_request_details.Where(t => t.FK_shipping_request == BottlereceptionWizardViewModelTemp.FK_ID_shipping_request).FirstOrDefault();
                tbl_607_Shipping_Request_Details.reception_quantity = tbl_607_Shipping_Request_Details.reception_quantity++;
                db.SaveChanges(); //sauvegarde

                // Recuperation de l'ID Bottle. L'ID gaz est deja connu = key du dico
                var idBottle = db.tbl_607_bottle.Select(t => t.ID).Max();

                //Nouvelle relève: valeurs par défaut 999bars et acteur: admin
                tbl_607_gaz_reporting tbl_607_Gaz_Reporting = new tbl_607_gaz_reporting();
                tbl_607_Gaz_Reporting.pressure_value = 999;
                tbl_607_Gaz_Reporting.FK_ID_actors   = 29;
                tbl_607_Gaz_Reporting.FK_ID_bottle   = idBottle;
                tbl_607_Gaz_Reporting.reporting_date = DateTime.Now;
                db.tbl_607_gaz_reporting.Add(tbl_607_Gaz_Reporting);

                // Recuperation des reals gaz dans le dictionnaire
                foreach (KeyValuePair <int, float> value in Tbl_607_Real_Gaz_Content_temp)
                {
                    tbl_607_real_gaz_content tbl_607_Real_Gaz_Content = new tbl_607_real_gaz_content();
                    tbl_607_join_bottle_gaz  tbl_607_Join_Bottle_Gaz  = new tbl_607_join_bottle_gaz();
                    // Enregistrement des reals gaz
                    tbl_607_Real_Gaz_Content.real_content = value.Value; //force l'ecriture dans la base alors que nous sommes encore dans la boucle
                    db.tbl_607_real_gaz_content.Add(tbl_607_Real_Gaz_Content);
                    db.SaveChanges();                                    //sauvegarde

                    //// Recuperation de l'id real gaz
                    var fk_real = db.tbl_607_real_gaz_content.Select(t => t.ID).Max();

                    //Ecriture de la jointure
                    tbl_607_Join_Bottle_Gaz.FK_ID_gaz          = value.Key;
                    tbl_607_Join_Bottle_Gaz.FK_ID_bottle       = idBottle;
                    tbl_607_Join_Bottle_Gaz.FK_ID_real_content = fk_real;
                    db.tbl_607_join_bottle_gaz.Add(tbl_607_Join_Bottle_Gaz); //force l'ecriture dans la base alors que nous sommes encore dans la boucle
                    db.SaveChanges();                                        //sauvegarde
                }

                //generation de la vue
                return(View("Index"));
            }
            catch (Exception ex)
            {
                //generation de la vue affichage erreur
                return(RedirectToAction("Index", "Ooops", new { message = ex }));
            }
        }