Ejemplo n.º 1
0
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            this.dataGridView1.CurrentCell = null;
            if (this.dataGridView1.RowCount == 0)
            {
                MessageBox.Show("请添加数据!");
                return;
            }
            CheckListModel obj = new CheckListModel();

            obj.user    = PropertyClass.UserId;
            obj.list_sm = new List <StockMateriel>();
            for (int i = this.dataGridView1.RowCount; i > 0; i--)
            {
                StockMateriel sm = new StockMateriel();
                if (this.dataGridView1.Rows[i - 1].Cells["batchnum"].Value != DBNull.Value)
                {
                    sm.batchnum = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["batchnum"].Value);
                }
                sm.materiel = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["materiel"].Value);
                if (this.dataGridView1.Rows[i - 1].Cells["position"].Value != DBNull.Value)
                {
                    sm.position = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["position"].Value);
                }
                sm.warehouse    = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["warehouse"].Value);
                sm.truequantity = Convert.ToDouble(this.dataGridView1.Rows[i - 1].Cells["avaquantity"].Value);
                sm.supplier     = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["supplierId"].Value);
                if (this.dataGridView1.Rows[i - 1].Cells["combination"].Value != DBNull.Value)
                {
                    sm.combination = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["combination"].Value);
                }
                obj.list_sm.Add(sm);
            }

            var msg = ctrl.add(obj);

            if (msg.Code == 0)
            {
                System.Data.DataTable dtcheck = ctrl.getlastinsert(PropertyClass.UserId);
                if (dtcheck.Rows.Count > 0)
                {
                    label2.Visible   = true;
                    label3.Text      = dtcheck.Rows[0]["num"].ToString();
                    label4.Visible   = true;
                    label5.Text      = dtcheck.Rows[0]["date"].ToString();
                    this.label6.Text = dtcheck.Rows[0]["id"].ToString();
                }


                toolStripButton1.Enabled = false;
                toolStripButton2.Enabled = false;
                toolStripButton3.Enabled = false;
                toolStripButton4.Enabled = true;
                MessageBox.Show(msg.Msg);
            }
            else
            {
                MessageBox.Show(msg.Msg);
            }
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                string ErrorMessage = "Id Stock matériel manquant";
                return(RedirectToAction("Index", new { MessageErreur = ErrorMessage }));
            }
            StockMateriel unStock = this.stockMaterielService.GetStockMaterielById(id);

            if (unStock == null)
            {
                return(HttpNotFound());
            }

            StockMaterielFormViewModel formModel = this.GetFormStock(true, unStock);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_AjaxEditStock", formModel));
            }
            else
            {
                return(View(formModel));
            }
        }
Ejemplo n.º 3
0
        private ActionControllerResult executeSortieStock(int stockSortieID, int stockEntreeID, int quantite, string userId)
        {
            ActionControllerResult result;
            SortieStockMateriel    uneSortie = new SortieStockMateriel();

            try
            {
                StockMateriel stockSortie = this.stockService.GetStockMaterielById(stockSortieID);
                StockMateriel stockSource = this.stockService.GetStockMaterielById(stockEntreeID);

                if (stockSortie.TypeMaterielID == stockSource.TypeMaterielID)
                {
                    //Suppression de la quantité du stock
                    result = this.stockService.UtilisationStockMateriel(stockSortie, quantite, userId);

                    if (result == ActionControllerResult.SUCCESS)
                    {
                        //Transfert du stock source vers le stock de sortie
                        StockMateriel tempSortieStock = new StockMateriel();
                        tempSortieStock.MaterielID     = stockSortie.MaterielID;
                        tempSortieStock.Quantite       = quantite;
                        tempSortieStock.TypeMaterielID = stockSortie.TypeMaterielID;

                        result = this.stockService.TransfertStockMateriel(stockSource.ID, tempSortieStock);

                        if (result == ActionControllerResult.SUCCESS)
                        {
                            //Si tout est ok, on créer la Sortie de Matériel
                            uneSortie.UsedStockMaterielID = stockSortieID;
                            uneSortie.IdSourceStock       = stockEntreeID;
                            uneSortie.Quantite            = quantite;
                            uneSortie.Utilisateur         = this.userService.GetUserById(userId);
                            uneSortie.DateSortie          = DateTime.Now;
                            uneSortie.TypeSortie          = MATERIEL_TYPE_SORTIE.Intervention;
                            uneSortie.Raison = MATERIEL_RAISON_SORTIE.Intervention;
                            this.sortieStockRepository.Insert(uneSortie);
                            this.unitOfWork.Save();
                            result = ActionControllerResult.SUCCESS;
                        }
                        else
                        {
                            result = ActionControllerResult.FAILURE;
                        }
                    }
                }
                else
                {
                    result = ActionControllerResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                this.logService.LogErreur(LOG_TYPE_OBJECT.SortieStockMateriel, null, "Erreur Lors de la création d'une Sortie de Stock", ex.Message, userId);
                result = ActionControllerResult.FAILURE;
            }

            return(result);
        }
Ejemplo n.º 4
0
        public ActionControllerResult InsertStockMateriel(StockMateriel unStock, string userId = null)
        {
            ActionControllerResult result;

            try
            {
                Materiel unMateriel = this.materielRepository.GetByID(unStock.MaterielID);
                if (unMateriel != null)
                {
                    if (unMateriel.TypeMaterielID > 0)
                    {
                        unStock.TypeMaterielID = Convert.ToInt32(unMateriel.TypeMaterielID);
                    }
                    else
                    {
                        unStock.TypeMaterielID = 0;
                    }
                }
                else
                {
                    unStock.TypeMaterielID = 0;
                }

                StockMateriel stockDejaExistant = this.stockMaterielRepository.Get(
                    filter: f => f.MaterielID == unStock.MaterielID && f.DatePeremption == unStock.DatePeremption && f.Supprime == false
                    ).SingleOrDefault();

                if (stockDejaExistant != null)
                {
                    stockDejaExistant.Quantite        += unStock.Quantite;
                    stockDejaExistant.DateModification = DateTime.Now;
                    this.stockMaterielRepository.Update(stockDejaExistant);
                }
                else
                {
                    unStock.DateCreation     = DateTime.Now;
                    unStock.DateModification = DateTime.Now;
                    this.stockMaterielRepository.Insert(unStock);
                }

                this.unitOfWork.Save();
                result = ActionControllerResult.SUCCESS;
            }
            catch (Exception ex)
            {
                this.logService.LogErreur(LOG_TYPE_OBJECT.StockMateriel, null, "Erreur Lors de la création d'un Stock Materiel", ex.Message, userId);
                result = ActionControllerResult.FAILURE;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public ActionControllerResult UtilisationStockMateriel(StockMateriel stockSortie, int quantite, string userId = null)
        {
            ActionControllerResult result;

            try
            {
                //si quantité ne suffit pas alors on recherche un autre stock similaire
                if (stockSortie.Quantite < quantite)
                {
                    quantite            -= stockSortie.Quantite;
                    stockSortie.Quantite = 0;
                    this.unitOfWork.Save();

                    StockMateriel autreStock = this.stockMaterielRepository.Get(
                        filter: f => f.ID != stockSortie.ID && f.MaterielID == stockSortie.MaterielID && f.Supprime == false,
                        orderBy: u => u.OrderBy(o => o.DatePeremption)
                        ).ToList().FirstOrDefault();

                    if (autreStock != null)
                    {
                        autreStock.Quantite -= quantite;
                        if (autreStock.Quantite <= 0)
                        {
                            autreStock.Supprime = true;
                            autreStock.Quantite = 0;
                        }
                        autreStock.DateModification = DateTime.Now;
                    }
                }
                else
                {
                    stockSortie.Quantite -= quantite;
                }

                if (stockSortie.Quantite == 0)
                {
                    stockSortie.Supprime = true;
                }

                stockSortie.DateModification = DateTime.Now;
                this.unitOfWork.Save();
                result = ActionControllerResult.SUCCESS;
            }
            catch (Exception ex)
            {
                this.logService.LogErreur(LOG_TYPE_OBJECT.StockMateriel, null, "Erreur Lors du transfert d'un Stock Materiel", ex.Message, userId);
                result = ActionControllerResult.FAILURE;
            }
            return(result);
        }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                string ErrorMessage = "Id Stock Materiel manquant";
                return(RedirectToAction("Index", new { MessageErreur = ErrorMessage }));
            }
            StockMateriel unStockMateriel = this.stockMaterielService.GetStockMaterielById(id);

            if (unStockMateriel == null)
            {
                return(HttpNotFound());
            }
            return(View(unStockMateriel));
        }
        public ActionResult AjaxEdit([Bind(Include = "ID,Quantite,DatePeremption,Supprime,DateCreation,DateModification,MaterielID,TypeMaterielID")] StockMateriel unStock)
        {
            StockMaterielFormViewModel formModel = this.GetFormStock(true, unStock);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.stockMaterielService.UpdateStockMateriel(unStock, User.Identity.GetUserId());
                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(PartialView("_FormContenuStock", formModel));
                }
                this.logService.LogEvenement(LOG_TYPE_EVENT.Edit, LOG_TYPE_OBJECT.StockMateriel, unStock.ID, "Création d'un Stock Materiel", null, User.Identity.GetUserId());
                return(Json(string.Empty));
            }
            return(PartialView("_FormContenuStock", formModel));
        }
        public ActionResult Edit([Bind(Include = "ID,Quantite,DatePeremption,Supprime,DateCreation,DateModification,MaterielID,TypeMaterielID")] StockMateriel unStock)
        {
            StockMaterielFormViewModel formModel = this.GetFormStock(true, unStock);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.stockMaterielService.UpdateStockMateriel(unStock, User.Identity.GetUserId());

                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(View(formModel));
                }
                return(RedirectToAction("Index"));
            }
            return(View(formModel));
        }
        public ActionResult AjaxCreate(StockMateriel unStock)
        {
            StockMaterielFormViewModel formModel = this.GetFormStock(false, unStock);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.stockMaterielService.InsertStockMateriel(unStock, User.Identity.GetUserId());
                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(PartialView("_FormContenuStock", formModel));
                }
                this.logService.LogEvenement(LOG_TYPE_EVENT.Create, LOG_TYPE_OBJECT.StockMateriel, null, "Création d'un Stock Materiel", null, User.Identity.GetUserId());
                return(Json(string.Empty));
            }
            return(PartialView("_FormContenuStock", formModel));
        }
        public ActionResult Create([Bind(Include = "ID,Quantite,DatePeremption,Supprime,MaterielID")] StockMateriel unStock)
        {
            StockMaterielFormViewModel formModel = this.GetFormStock(false, unStock);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.stockMaterielService.InsertStockMateriel(unStock, User.Identity.GetUserId());
                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(View(formModel));
                }
                this.logService.LogEvenement(LOG_TYPE_EVENT.Create, LOG_TYPE_OBJECT.StockMateriel, null, "Création d'un Stock Materiel", null, User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
            return(View(formModel));
        }
Ejemplo n.º 11
0
        public ActionControllerResult UpdateStockMateriel(StockMateriel unStock, string userId = null)
        {
            ActionControllerResult result;

            try
            {
                unStock.DateModification = DateTime.Now;
                this.stockMaterielRepository.Update(unStock);
                this.unitOfWork.Save();
                result = ActionControllerResult.SUCCESS;
            }
            catch (Exception ex)
            {
                this.logService.LogErreur(LOG_TYPE_OBJECT.StockMateriel, null, "Erreur Lors de la modification d'un Stock Materiel", ex.Message, userId);
                result = ActionControllerResult.FAILURE;
            }
            return(result);
        }
Ejemplo n.º 12
0
        private ActionControllerResult TakeFromSource(StockMateriel stockTransfert, StockMateriel stockSource)
        {
            ActionControllerResult result;

            int quantiteRestante = 0;

            stockSource.Quantite -= stockTransfert.Quantite;
            if (stockSource.Quantite <= 0)
            {
                stockSource.Supprime = true;
                quantiteRestante     = stockSource.Quantite * -1;
                stockSource.Quantite = 0;
            }
            result = this.UpdateStockMateriel(stockSource);

            //S'il reste une quantité à enlever
            if (quantiteRestante > 0)
            {
                StockMateriel stockPourQuantiteRestante = this.stockMaterielRepository.Get(
                    filter: f => f.MaterielID == stockSource.MaterielID && f.Supprime == false,
                    orderBy: u => u.OrderBy(o => o.DatePeremption)
                    )
                                                          .SingleOrDefault();

                if (stockPourQuantiteRestante != null)
                {
                    stockPourQuantiteRestante.Quantite -= quantiteRestante;
                    if (stockPourQuantiteRestante.Quantite <= 0)
                    {
                        stockPourQuantiteRestante.Supprime = true;
                        stockPourQuantiteRestante.Quantite = 0;
                    }
                    result = this.UpdateStockMateriel(stockPourQuantiteRestante);
                }
            }
            return(result);
        }
        private StockMaterielFormViewModel GetFormStock(bool isEdit, StockMateriel unStock = null, int?materielId = null)
        {
            //Gestion de la récupératio des ID
            Materiel unMateriel     = null;
            int?     IdInventaire   = null;
            int?     IdBloc         = null;
            int?     IdMateriel     = null;
            int?     IdTypeMateriel = null;

            if (unStock == null)
            {
                unStock = new StockMateriel();
            }

            if (unStock.MaterielID > 0)
            {
                unMateriel = this.materielService.GetMaterielById(unStock.MaterielID);
                IdMateriel = unStock.MaterielID;
            }
            else if (materielId != null)
            {
                unMateriel = this.materielService.GetMaterielById(materielId);
                IdMateriel = materielId;
            }

            if (IdMateriel != null)
            {
                IdInventaire       = unMateriel.BlocInventaire.InventaireID;
                IdBloc             = unMateriel.BlocInventaireID;
                unStock.MaterielID = Convert.ToInt32(IdMateriel);
                IdTypeMateriel     = unStock.TypeMaterielID;
            }


            //Création Form
            StockMaterielFormViewModel formModel = new StockMaterielFormViewModel();

            formModel.unStock = unStock;

            //Gestion des listes
            formModel.listInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.inventaireService.GetInventaires(), "ID", "Nom"), IdInventaire, "Sélectionner");

            if (IdInventaire != null)
            {
                formModel.listBlocInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.blocInventaireService.GetBlocsInventaireByInventaire(Convert.ToInt32(IdInventaire)), "ID", "Nom"), IdBloc, "Sélectionner");
            }
            else
            {
                formModel.listBlocInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(Enumerable.Empty <SelectListItem>(), "ID", "Nom"), IdBloc, "Aucun");
            }

            if (IdInventaire != null)
            {
                IEnumerable <Materiel>      listMateriel   = this.materielService.GetMaterielsByBlocInventaire(Convert.ToInt32(IdBloc));
                Dictionary <string, string> dictionaryItem = new Dictionary <string, string>();

                foreach (Materiel unMat in listMateriel)
                {
                    if (unMat.TypeMateriel != null)
                    {
                        dictionaryItem.Add(unMat.ID.ToString(), unMat.TypeMateriel.Nom);
                    }
                    else
                    {
                        dictionaryItem.Add(unMat.ID.ToString(), unMat.Nom);
                    }
                }
                formModel.listMateriel = this.selectListHelper.AddFirstItemSelectList(this.selectListHelper.CreateSelectList(dictionaryItem), IdMateriel, "Sélectionner");
            }
            else
            {
                formModel.listMateriel = this.selectListHelper.AddFirstItemSelectList(new SelectList(Enumerable.Empty <SelectListItem>(), "ID", "Nom"), IdMateriel, "Aucun");
            }

            formModel.ListTypeMateriel = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.typeMaterielService.GetTypeMateriels(), "ID", "Nom"), IdTypeMateriel, "Sélectionner");

            //Gestion du mode Edit et du mode Ajax
            formModel.isEdit = isEdit;
            return(formModel);
        }
        private sortieStockMaterielViewModel GetSortieStockForm(SortieStockMateriel uneSortie, int?idMaterielParametre = null)
        {
            //Gestion de la récupératio des ID
            Materiel unMateriel   = null;
            int?     IdInventaire = null;
            int?     IdBloc       = null;
            int?     IdMateriel   = null;
            int?     IdStock      = null;

            if (uneSortie == null)
            {
                uneSortie = new SortieStockMateriel();

                //Initialisation des listes si un matériel est passer en paramètre (formulaireAjax)
                if (idMaterielParametre != null && idMaterielParametre > 0)
                {
                    unMateriel = GetIdsForList(idMaterielParametre, ref IdInventaire, ref IdBloc, ref IdMateriel);
                }
            }
            else if (uneSortie.UsedStockMaterielID > 0)
            {
                StockMateriel unStock = this.stockService.GetStockMaterielById(uneSortie.UsedStockMaterielID);
                if (unStock != null)
                {
                    IdMateriel   = unStock.MaterielID;
                    IdBloc       = unStock.Materiel.BlocInventaireID;
                    IdInventaire = unStock.Materiel.BlocInventaire.InventaireID;
                }
            }
            else if (uneSortie != null && idMaterielParametre > 0)
            {
                unMateriel = GetIdsForList(idMaterielParametre, ref IdInventaire, ref IdBloc, ref IdMateriel);
            }


            //Création Form
            sortieStockMaterielViewModel formModel = new sortieStockMaterielViewModel();

            formModel.uneSortieStock = uneSortie;

            //Gestion des listes
            formModel.listInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.inventaireService.GetInventaires(), "ID", "Nom"), IdInventaire, "Sélectionner");

            if (IdInventaire != null)
            {
                formModel.listBlocInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.blocInventaireService.GetBlocsInventaireByInventaire(Convert.ToInt32(IdInventaire)), "ID", "Nom"), IdBloc, "Sélectionner");
            }
            else
            {
                formModel.listBlocInventaire = this.selectListHelper.AddFirstItemSelectList(new SelectList(Enumerable.Empty <SelectListItem>(), "ID", "Nom"), IdBloc, "Aucun");
            }

            if (IdInventaire != null)
            {
                IEnumerable <Materiel>      listMateriel   = this.materielService.GetMaterielsByBlocInventaire(Convert.ToInt32(IdBloc));
                Dictionary <string, string> dictionaryItem = new Dictionary <string, string>();

                foreach (Materiel unMat in listMateriel)
                {
                    if (unMat.TypeMateriel != null)
                    {
                        dictionaryItem.Add(unMat.ID.ToString(), unMat.TypeMateriel.Nom);
                    }
                    else
                    {
                        dictionaryItem.Add(unMat.ID.ToString(), unMat.Nom);
                    }
                }
                formModel.listMateriel = this.selectListHelper.AddFirstItemSelectList(this.selectListHelper.CreateSelectList(dictionaryItem), IdMateriel, "Sélectionner");
            }
            else
            {
                formModel.listMateriel = this.selectListHelper.AddFirstItemSelectList(new SelectList(Enumerable.Empty <SelectListItem>(), "ID", "Nom"), IdMateriel, "Aucun");
            }

            if (IdMateriel == null)
            {
                formModel.listStock = this.selectListHelper.AddFirstItemSelectList(new SelectList(Enumerable.Empty <SelectListItem>(), "ID", "Nom"), IdStock, "Aucun");
            }
            else
            {
                formModel.listStock = this.selectListHelper.AddFirstItemSelectList(this.selectListHelper.CreateSelectList(this.stockService.CreateListStockByMaterielId(Convert.ToInt32(IdMateriel))), IdStock, "Sélectionner");
            }


            return(formModel);
        }
Ejemplo n.º 15
0
        public ActionControllerResult TransfertStockMateriel(int stockMaterielSourceId, StockMateriel stockTransfert, string userId = null)
        {
            ActionControllerResult result;

            try
            {
                //Récupération du stockSource
                StockMateriel stockSource         = this.GetStockMaterielById(stockMaterielSourceId);
                Materiel      materielDestination = this.materielRepository.GetByID(stockTransfert.MaterielID);

                if (stockSource != null && materielDestination != null)
                {
                    //Si le type matériel est le meme
                    if (stockSource.Materiel.TypeMaterielID == materielDestination.TypeMaterielID)
                    {
                        //Recherche de l'existance d'un stock similaire à la destination données
                        StockMateriel stockSimilaireDestination = this.stockMaterielRepository.Get(
                            filter: f => f.MaterielID == stockTransfert.MaterielID && f.DatePeremption == stockSource.DatePeremption && f.Supprime == false
                            )
                                                                  .SingleOrDefault();

                        if (stockSimilaireDestination != null)
                        {
                            //Si oui, transfert de la quantité donnée à la destinations donnée
                            //Update du stock Source
                            result = TakeFromSource(stockTransfert, stockSource);

                            //Mise à jour Stock de destination si Update source Réussi
                            if (result == ActionControllerResult.SUCCESS)
                            {
                                stockSimilaireDestination.Quantite        += stockTransfert.Quantite;
                                stockSimilaireDestination.DateModification = DateTime.Now;

                                result = this.UpdateStockMateriel(stockSimilaireDestination);
                            }
                        }
                        else
                        {
                            //Si non, Création d'un nouveau stock à la destination
                            //Update du stock Source
                            result = TakeFromSource(stockTransfert, stockSource);

                            //Creation du nouveau stock si Update source Réussi
                            if (result == ActionControllerResult.SUCCESS)
                            {
                                StockMateriel newStock = new StockMateriel();
                                newStock.MaterielID       = stockTransfert.MaterielID;
                                newStock.DatePeremption   = stockSource.DatePeremption;
                                newStock.Quantite         = stockTransfert.Quantite;
                                newStock.TypeMaterielID   = stockSource.TypeMaterielID;
                                newStock.Supprime         = false;
                                newStock.DateCreation     = DateTime.Now;
                                newStock.DateModification = DateTime.Now;

                                result = this.InsertStockMateriel(newStock, userId);
                            }
                        }
                    }
                    else
                    {
                        result = ActionControllerResult.FAILURE;
                    }
                }
                else
                {
                    result = ActionControllerResult.FAILURE;
                }
            }
            catch (Exception ex)
            {
                this.logService.LogErreur(LOG_TYPE_OBJECT.StockMateriel, null, "Erreur Lors du transfert d'un Stock Materiel", ex.Message, userId);
                result = ActionControllerResult.FAILURE;
            }
            return(result);
        }