Beispiel #1
0
        public IActionResult UomConversionDelete(int uomConversionSk)
        {
            System.Console.WriteLine("-----------------------------------UomConversionDelete--------------------------------------");
            if (HttpContext.Session.GetInt32("LoggedIn") != 1)
            {
                return(RedirectToAction("Login", "Login"));
            }

            bool          isDeleteOk        = true;
            UomConversion uomConversionInDb = uomConversionHelper.GetUomConversionBySk(uomConversionSk);

            if (uomConversionInDb == null)
            {
                // Uom not found in Db.  This is an exception...
                isDeleteOk = false;
            }

            if (isDeleteOk)
            {
                System.Console.WriteLine("-----------------------------------UomConversionDelete-IsDeleteId=true-------------------------------------");

                // Delete Uom
                dbContext.UomConversion.Remove(uomConversionInDb);
                dbContext.SaveChanges();
            }
            else
            {
                System.Console.WriteLine("-----------------------------------UomConversionDelete-IsDeleteId=false-------------------------------------");
            }
            return(RedirectToAction("UomConversionNewListView"));
        }
Beispiel #2
0
        public ActionResult _UomConvertEdit(UomConversion uomConv)
        {
            if (uomConv.ItemCode != null)
            {
                Item item = base.genericMgr.FindById <Item>(uomConv.ItemCode);
                uomConv.Item = item;
            }
            else
            {
                uomConv.Item = null;
            }


            ModelState.Remove("Item.Code");
            ModelState.Remove("Item.Description");
            if (ModelState.IsValid)
            {
                base.genericMgr.Update(uomConv);
                SaveSuccessMessage(Resources.MD.UomConvert.UomConvert_Updated);
            }
            ////return new RedirectToRouteResult(new RouteValueDictionary
            ////                                       {
            ////                                           { "action", "_UomConvertEdit" },
            ////                                           { "controller", "Uom" },
            ////                                           { "id", uomConv.Id }
            ////                                       });

            return(PartialView(uomConv));
        }
Beispiel #3
0
    protected void ODS_GV_UomConversion_OnDeleting(object sender, ObjectDataSourceMethodEventArgs e)
    {
        UomConversion uomConversion    = (UomConversion)e.InputParameters[0];
        UomConversion delUomConversion = TheUomConversionMgr.LoadUomConversion(uomConversion.Id);

        itemMessage[0] = delUomConversion.Item == null ? string.Empty : delUomConversion.Item.Code;
        itemMessage[1] = delUomConversion.BaseQty.ToString();
        itemMessage[2] = delUomConversion.BaseUom.Code;
        itemMessage[3] = delUomConversion.AlterQty.ToString();
        itemMessage[4] = delUomConversion.AlterUom.Code;
    }
        protected override void DeleteObject(object obj)
        {
            UomConversion uomConversion = (UomConversion)obj;

            UomConversion newUomConversion = this.uomConversionMgr.LoadUomConversion(uomConversion.Item.Code, uomConversion.AlterUom.Code, uomConversion.BaseUom.Code);

            if (newUomConversion != null)
            {
                this.uomConversionMgr.DeleteUomConversion(newUomConversion.Id);
            }
        }
Beispiel #5
0
        public IActionResult UomNewSave(Uom uom)
        {
            System.Console.WriteLine("-----------------------------------UomNewSave--------------------------------------");

            bool isValid = ModelState.IsValid;

            if (isValid)
            {
                var uomIdInDb = dbContext.Uom.FirstOrDefault(u => u.UomId == uom.UomId);
                if (uomIdInDb != null)
                {
                    ModelState.AddModelError("UomId", "Uom Id already exists.");
                    isValid = false;
                }
                else
                {
                    var uomNameInDb = dbContext.Uom.FirstOrDefault(u => u.UomName == uom.UomName);
                    if (uomNameInDb != null)
                    {
                        ModelState.AddModelError("UomName", "Uom Name already exists.");
                        isValid = false;
                    }
                }
            }

            if (isValid)
            {
                // Add new Uom
                DateTime now = DateTime.Now;
                uom.CreatedAt = now;
                uom.UpdatedAt = now;
                dbContext.Add(uom);
                dbContext.SaveChanges();

                // Add the 1-1 Uom Conversion row for the new Uom
                var           uomInDb       = dbContext.Uom.FirstOrDefault(u => u.UomId == uom.UomId);
                UomConversion uomConversion = new UomConversion {
                    UomTypeSk = uomInDb.UomTypeSk, ConvertFromUomSk = uomInDb.UomSk, ConvertToUomSk = uomInDb.UomSk, ConversionFactor = 1, CreatedAt = now, UpdatedAt = now
                };
                dbContext.Add(uomConversion);
                dbContext.SaveChanges();

                return(RedirectToAction("UomNewListView"));
            }
            else
            {
                // New was invalid, route back to Uom New / List view
                setLayoutViewBag();
                ViewBag.AllUoms     = uomHelper.GetAllUomsByUomIdAsc();
                ViewBag.AllUomTypes = uomTypeHelper.GetAllUomTypes();

                return(View("UomNewListView", uom));
            }
        }
Beispiel #6
0
    protected void ODS_UomConversion_Inserting(object source, ObjectDataSourceMethodEventArgs e)
    {
        UomConversion uomConversion = (UomConversion)e.InputParameters[0];

        string itemCode = ((Controls_TextBox)(this.FV_UomConversion.FindControl("tbItemCode"))).Text;
        string altUom   = ((Controls_TextBox)(this.FV_UomConversion.FindControl("tbAltUom"))).Text;
        string baseUom  = ((Controls_TextBox)(this.FV_UomConversion.FindControl("tbBaseUom"))).Text;

        itemMessage[0] = itemCode;
        itemMessage[1] = uomConversion.BaseQty.ToString();
        itemMessage[2] = baseUom;
        itemMessage[3] = uomConversion.AlterQty.ToString();
        itemMessage[4] = altUom;

        //if (itemCode == null || itemCode.Trim() == string.Empty)
        //{
        //    ShowWarningMessage("MasterData.UomConversion.Required.itemCode", "");
        //    e.Cancel = true;
        //    return;
        //}
        if (altUom == null || altUom.Trim() == string.Empty)
        {
            ShowWarningMessage("MasterData.UomConversion.Required.altUom", "");
            e.Cancel = true;
            return;
        }
        if (altUom == baseUom)
        {
            ShowWarningMessage("MasterData.UomConversion.Same.Uom", baseUom);
            e.Cancel = true;
            return;
        }
        if (baseUom == null || baseUom.Trim() == string.Empty)
        {
            ShowWarningMessage("MasterData.UomConversion.Required.baseUom", "");
            e.Cancel = true;
            return;
        }
        if (TheUomConversionMgr.LoadUomConversion(itemCode, altUom, baseUom) == null && TheUomConversionMgr.LoadUomConversion(itemCode, baseUom, altUom) == null)
        {
            uomConversion.Item     = TheItemMgr.LoadItem(itemCode);
            uomConversion.AlterUom = TheUomMgr.LoadUom(altUom);
            uomConversion.BaseUom  = TheUomMgr.LoadUom(baseUom);
            ShowSuccessMessage("MasterData.UomConversion.AddUomConversion.Successfully", itemMessage);
        }
        else
        {
            e.Cancel = true;
            ShowErrorMessage("MasterData.UomConversion.AddUomConversion.Error", itemMessage);
            return;
        }
    }
        //--------------------------------------------------------------
        // Select and return the UomConversion related to the passed uomConversionSk
        public UomConversion GetUomConversionBySk(int uomConversionSk)
        {
            System.Console.WriteLine("------------------------------------------GetUomConversionBySk------------------------------------------");
            UomConversion uomConversion = (from u in dbContext.UomConversion
                                           where u.UomConversionSk == uomConversionSk
                                           select u)
                                          .Include("UomType")
                                          .Include("ConvertFromUom")
                                          .Include("ConvertToUom")
                                          .FirstOrDefault();

            return(uomConversion);
        }
Beispiel #8
0
        public ActionResult _UomConvertNew(UomConversion uomConversion)
        {
            if (ModelState.IsValid)
            {
                if (base.genericMgr.FindAll <long>(uomConvertDuiplicateVerifyStatement, new object[] { uomConversion.Id })[0] > 0)
                {
                    SaveErrorMessage(Resources.ErrorMessage.Errors_Existing_Code);
                }
                else if (uomConversion.BaseUom == uomConversion.AlterUom)
                {
                    SaveErrorMessage(Resources.MD.UomConvert.Errors_Existing_Uom);
                }
                else if (uomConversion.ItemCode == null)
                {
                    if (base.genericMgr.FindAll <long>(uomConvertIsExistAndItemIsNull, new object[] { uomConversion.BaseUom, uomConversion.AlterUom })[0] > 0)
                    {
                        SaveErrorMessage(Resources.MD.UomConvert.Errors_Existing_UomConv);
                    }
                    else
                    {
                        base.genericMgr.Create(uomConversion);
                        SaveSuccessMessage(Resources.MD.UomConvert.UomConvert_Added);
                        return(RedirectToAction("_UomConvertEdit/" + uomConversion.Id));
                    }
                }
                else
                {
                    if (base.genericMgr.FindAll <Item>("from Item where Code=?", uomConversion.ItemCode).Count < 1)
                    {
                        SaveErrorMessage(Resources.MD.UomConvert.Errors_NotExisting_Item);
                    }
                    else
                    {
                        if (base.genericMgr.FindAll <long>(uomConvertIsExist, new object[] { uomConversion.ItemCode, uomConversion.BaseUom, uomConversion.AlterUom })[0] > 0)
                        {
                            SaveErrorMessage(Resources.MD.UomConvert.Errors_Existing_UomConv);
                        }
                        else
                        {
                            Item item = base.genericMgr.FindById <Item>(uomConversion.ItemCode);
                            uomConversion.Item = item;
                            base.genericMgr.Create(uomConversion);
                            SaveSuccessMessage(Resources.MD.UomConvert.UomConvert_Added);
                            return(RedirectToAction("_UomConvertEdit/" + uomConversion.Id));
                        }
                    }
                }
            }

            return(PartialView(uomConversion));
        }
Beispiel #9
0
        public IActionResult UomConversionNewSave(UomConversion uomConversion)
        {
            System.Console.WriteLine("-----------------------------------UomConversionNewSave(UomConversion uomConversion):1--------------------------------------");

            bool isValid = ModelState.IsValid;

            if (isValid)
            {
                var uomConversionInDb = (from u in dbContext.UomConversion
                                         where u.ConvertFromUomSk == uomConversion.ConvertFromUomSk
                                         where u.ConvertToUomSk == uomConversion.ConvertToUomSk
                                         select u).FirstOrDefault();
                if (uomConversionInDb != null)
                {
                    ModelState.AddModelError("ConvertFromUomSK", "From / To Uom conversion already exists.");
                    isValid = false;
                }
            }

            if (isValid)
            {
                // Add new UomConversion
                DateTime now = DateTime.Now;
                uomConversion.CreatedAt = now;
                uomConversion.UpdatedAt = now;
                dbContext.Add(uomConversion);
                dbContext.SaveChanges();
                dbContext.SaveChanges();

                return(RedirectToAction("UomConversionNewListview"));
            }
            else
            {
                System.Console.WriteLine("-----------------------------------UomConversionNewSave(UomConversion uomConversion):2--------------------------------------");
                System.Console.WriteLine($"{uomConversion.UomTypeSk}");

                // New was invalid, route back to UomConversion New / List view
                setLayoutViewBag();
                ViewBag.AllUomConversions = uomConversionHelper.GetUomConversionsByTypeFromToAsc();
                ViewBag.AllUomTypes       = uomTypeHelper.GetAllUomTypes();
                UomType uomType = uomTypeHelper.GetUomTypeBySk(uomConversion.UomTypeSk);

                System.Console.WriteLine($"{uomType.UomTypeName}");

                ViewBag.AllUoms = uomHelper.GetAllUomsByUomIdAsc(uomType.UomTypeName);

                return(View("UomConversionNewListView", uomConversion));
            }
        }
        private object Deserialize(DssImportHistory dssImportHistory, bool isUpdate)
        {
            UomConversion uomConversion = new UomConversion();

            uomConversion.BaseUom  = this.uomMgr.CheckAndLoadUom(dssImportHistory[1]);   //基本单位
            uomConversion.AlterUom = this.uomMgr.CheckAndLoadUom(dssImportHistory[2]);   //替代单位
            uomConversion.Item     = this.itemMgr.CheckAndLoadItem(dssImportHistory[3]); //零件号
            if (isUpdate)
            {
                //基本单位:G,替代单位:KG,换算因子:1000 => 1 KG = 1000 G
                uomConversion.BaseQty  = decimal.Parse(dssImportHistory[4]);//换算因子
                uomConversion.AlterQty = 1;
            }

            return(uomConversion);
        }
        protected override void CreateOrUpdateObject(object obj)
        {
            UomConversion uomConversion = (UomConversion)obj;

            UomConversion newUomConversion = this.uomConversionMgr.LoadUomConversion(uomConversion.Item.Code, uomConversion.AlterUom.Code, uomConversion.BaseUom.Code);

            if (newUomConversion == null)
            {
                this.uomConversionMgr.CreateUomConversion(uomConversion);
            }
            else
            {
                CloneHelper.CopyProperty(uomConversion, newUomConversion, this.fields);
                this.uomConversionMgr.UpdateUomConversion(newUomConversion);
            }
        }
Beispiel #12
0
    protected void ODS_GV_UomConversion_OnUpdating(object source, ObjectDataSourceMethodEventArgs e)
    {
        UomConversion uomConversion = (UomConversion)e.InputParameters[0];
        UomConversion oldConversion = TheUomConversionMgr.LoadUomConversion(uomConversion.Id);

        uomConversion.BaseUom  = oldConversion.BaseUom;
        uomConversion.AlterUom = oldConversion.AlterUom;
        uomConversion.Item     = oldConversion.Item;

        itemMessage[0] = oldConversion.Item == null ? string.Empty : oldConversion.Item.Code;
        itemMessage[1] = uomConversion.BaseQty.ToString();
        itemMessage[2] = oldConversion.BaseUom.Code;
        itemMessage[3] = uomConversion.AlterQty.ToString();
        itemMessage[4] = oldConversion.AlterUom.Code;
        ShowSuccessMessage("MasterData.UomConversion.UpdateUomConversion.Successfully", itemMessage);
    }
Beispiel #13
0
        public ActionResult _UomConvertEdit(int?id)
        {
            if (!id.HasValue)
            {
                return(HttpNotFound());
            }
            else
            {
                UomConversion uomConv = base.genericMgr.FindById <UomConversion>(id);
                if (uomConv.Item != null)
                {
                    uomConv.ItemCode = uomConv.Item.Code;
                }

                return(PartialView(uomConv));
            }
        }
Beispiel #14
0
        public IActionResult UomConversionEdit(int uomConversionSk)
        {
            System.Console.WriteLine("-----------------------------------UomConversionEdit(int uomConversionSk):1--------------------------------------");
            System.Console.WriteLine($"uomConversionSk: {uomConversionSk}");

            if (HttpContext.Session.GetInt32("LoggedIn") != 1)
            {
                return(RedirectToAction("Login", "Login"));
            }

            setLayoutViewBag();
            UomConversion uomConversion = uomConversionHelper.GetUomConversionBySk(uomConversionSk);

            ViewBag.AllUomConversions = uomConversionHelper.GetUomConversionsByTypeFromToAsc();
            ViewBag.AllUomTypes       = uomTypeHelper.GetAllUomTypes();
            ViewBag.AllUoms           = uomHelper.GetAllUomsByUomIdAsc(uomConversion.UomType.UomTypeName);

            return(View("UomConversionEdit", uomConversion));
        }
Beispiel #15
0
        public decimal ConvertUomQty(string itemCode, string sourceUomCode, decimal sourceQty, string targetUomCode)
        {
            if (sourceUomCode == targetUomCode)
            {
                return(sourceQty);
            }

            UomConversion uomConversion = this.LoadUomConversion(itemCode, sourceUomCode, targetUomCode);

            if (uomConversion != null)
            {
                return(sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
            }
            else
            {
                uomConversion = this.LoadUomConversion(itemCode, targetUomCode, sourceUomCode);
                if (uomConversion != null)
                {
                    return(sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                }
                else
                {
                    uomConversion = this.LoadUomConversion(null, sourceUomCode, targetUomCode);
                    if (uomConversion != null)
                    {
                        return(sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
                    }
                    else
                    {
                        uomConversion = this.LoadUomConversion(null, targetUomCode, sourceUomCode);
                        if (uomConversion != null)
                        {
                            return(sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                        }
                        else
                        {
                            throw new BusinessErrorException("UomConversion.Error.NotFound", itemCode, sourceUomCode, targetUomCode);
                        }
                    }
                }
            }
        }
Beispiel #16
0
        public IActionResult UomConversionNewListView(UomConversion uomConversion)
        {
            System.Console.WriteLine("-----------------------------------Post:UomConversionNewListView(UomConversion uomConversion):1--------------------------------------");
            if (HttpContext.Session.GetInt32("LoggedIn") != 1)
            {
                return(RedirectToAction("Login", "Login"));
            }

            System.Console.WriteLine("-----------------------------------Post:UomConversionNewListView(UomConversion uomConversion):2--------------------------------------");

            UomType uomType    = uomTypeHelper.GetUomTypeBySk(uomConversion.UomTypeSk);
            string  filterText = uomType.UomTypeName;

            setLayoutViewBag();
            ViewBag.AllUomConversions = uomConversionHelper.GetUomConversionsByTypeFromToAsc();
            ViewBag.AllUomTypes       = uomTypeHelper.GetAllUomTypes();
            ViewBag.AllUoms           = uomHelper.GetAllUomsByUomIdAsc(filterText);

            return(View("UomConversionNewListView", uomConversion));
        }
Beispiel #17
0
        public IActionResult UomConversionNewListView()
        {
            System.Console.WriteLine("-----------------------------------Get:UomConversionNewListView():1--------------------------------------");
            if (HttpContext.Session.GetInt32("LoggedIn") != 1)
            {
                return(RedirectToAction("Login", "Login"));
            }

            setLayoutViewBag();
            UomConversion uomConversion = new UomConversion {
                UomTypeSk = 2, ConversionFactor = 1
            };

            ViewBag.AllUomConversions = uomConversionHelper.GetUomConversionsByTypeFromToAsc();
            ViewBag.AllUomTypes       = uomTypeHelper.GetAllUomTypes();
            UomType uomType = uomTypeHelper.GetUomTypeBySk(2);

            ViewBag.AllUoms = uomHelper.GetAllUomsByUomIdAsc(uomType.UomTypeName);

            return(View("UomConversionNewListView", uomConversion));
        }
Beispiel #18
0
 public virtual void DeleteUomConversion(UomConversion entity)
 {
     Delete(entity);
 }
Beispiel #19
0
 public virtual void UpdateUomConversion(UomConversion entity)
 {
     Update(entity);
 }
Beispiel #20
0
 public virtual void CreateUomConversion(UomConversion entity)
 {
     Create(entity);
 }
Beispiel #21
0
        public decimal ConvertItemUomQty(string itemCode, string sourceUomCode, decimal sourceQty, string targetUomCode)
        {
            if (sourceUomCode == targetUomCode || sourceQty == 0)
            {
                return(sourceQty);
            }

            #region 第一次转换单位,使用Item定义的单位转换
            DetachedCriteria criteria = DetachedCriteria.For <UomConversion>();
            criteria.Add(Expression.Eq("Item.Code", itemCode));

            IList <UomConversion> SpecifiedItemUomConversionList = genericMgr.FindAll <UomConversion>(criteria);

            UomConversion uomConversion = (from conv in SpecifiedItemUomConversionList
                                           where (conv.BaseUom == sourceUomCode && conv.AlterUom == targetUomCode) ||
                                           (conv.BaseUom == targetUomCode && conv.AlterUom == sourceUomCode)
                                           select conv).FirstOrDefault();

            if (uomConversion != null)
            {
                if (uomConversion.BaseUom == sourceUomCode)
                {
                    return(sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                }
                else
                {
                    return(sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
                }
            }
            #endregion

            #region 第二次转换单位,使用通用的单位转换
            criteria = DetachedCriteria.For <UomConversion>();
            criteria.Add(Expression.IsNull("Item"));

            IList <UomConversion> genericItemUomConversionList = genericMgr.FindAll <UomConversion>(criteria);

            uomConversion = (from conv in genericItemUomConversionList
                             where (conv.BaseUom == sourceUomCode && conv.AlterUom == targetUomCode) ||
                             (conv.BaseUom == targetUomCode && conv.AlterUom == sourceUomCode)
                             select conv).FirstOrDefault();

            if (uomConversion != null)
            {
                if (uomConversion.BaseUom == sourceUomCode)
                {
                    return(sourceQty * uomConversion.AlterQty / uomConversion.BaseQty);
                }
                else
                {
                    return(sourceQty * uomConversion.BaseQty / uomConversion.AlterQty);
                }
            }
            #endregion

            #region 无级单位转换
            List <UomConversion> mergedItemUomConversionList = new List <UomConversion>();
            mergedItemUomConversionList.AddRange(SpecifiedItemUomConversionList);
            mergedItemUomConversionList.AddRange(genericItemUomConversionList);

            //思路:用sourceUomCode、targetUomCode分别和uomConversion.BaseUom、uomConversion.AlterUom匹配
            //总共4种情况,循环嵌套往下查找。
            //每次嵌套需要过滤掉已经用过得uomConversion来防止死循环。
            decimal?targetQty = NestConvertItemUomQty(mergedItemUomConversionList, sourceUomCode, targetUomCode, sourceQty, false);

            if (!targetQty.HasValue)
            {
                targetQty = NestConvertItemUomQty(mergedItemUomConversionList, targetUomCode, sourceUomCode, sourceQty, true);
            }

            if (targetQty.HasValue)
            {
                return(targetQty.Value);
            }
            else
            {
                throw new BusinessException(Resources.ErrorMessage.Errors_Item_UomConvertionNotFound, itemCode, sourceUomCode, targetUomCode);
            }
            #endregion
        }
Beispiel #22
0
 public virtual void DeleteUomConversion(UomConversion entity)
 {
     entityDao.DeleteUomConversion(entity);
 }
Beispiel #23
0
 public virtual void UpdateUomConversion(UomConversion entity)
 {
     entityDao.UpdateUomConversion(entity);
 }
Beispiel #24
0
 public virtual void CreateUomConversion(UomConversion entity)
 {
     entityDao.CreateUomConversion(entity);
 }