예제 #1
0
 public ActionResult New(Custodian custodian)
 {
     if (ModelState.IsValid)
     {
         try
         {
             itemMgr.CreateCustodian(custodian);
             SaveSuccessMessage("保管员创建成功。");
            // return RedirectToAction("List/" +custodian.UserCode );
             return new RedirectToRouteResult(new RouteValueDictionary { { "action", "List" }, { "controller", "Custodian" }, { "UserCode", custodian.UserCode }, { "isFromList",true } });
         }
         catch (BusinessException ex)
         {
             string messagesStr = "";
             IList<Message> messageList = ex.GetMessages();
             foreach (Message message in messageList)
             {
                 messagesStr += message.GetMessageString()+",";
             }
             SaveErrorMessage("物料"+messagesStr.Substring(0,messagesStr.Length-1));
         }
         
     }
     return View(custodian);
 }
예제 #2
0
        public override bool Equals(object obj)
        {
            Custodian another = obj as Custodian;

            if (another == null)
            {
                return(false);
            }
            else
            {
                return(this.Id == another.Id);
            }
        }
예제 #3
0
        public void CreateCustodian(Custodian custodian)
        {
            string ItemCodeStr = custodian.ItemCodes.Replace("\r\n", ",");
            string[] ItemCodeArray = ItemCodeStr.Split(',');
            BusinessException businessException = new BusinessException();
            #region 判定Item是否有效
            foreach (string itemCode in ItemCodeArray.Distinct())
            {
                if (itemCode != null && itemCode != "")
                {
                    IList<Item> items = this.genericMgr.FindAll<Item>("from Item where Code='" + itemCode + "'");
                    if (items == null || items.Count == 0)
                    {
                        businessException.AddMessage(itemCode.ToString() + ",");
                    }
                }
            }
            if (businessException.HasMessage)
            {
                businessException.AddMessage("不存在。");
                throw businessException;
            }

            #endregion

            #region 判定物料是否已经分配保管员
            string hql = string.Empty;
            IList<object> parm = new List<object>();
            foreach (string itemCode in ItemCodeArray.Distinct())
            {
                if (hql == string.Empty)
                {
                    hql = "from Custodian where Location=? and UserCode=? and item in (?";
                    parm.Add(custodian.Location);
                    parm.Add(custodian.UserCode);
                }
                else
                {
                    hql += ", ?";
                }
                parm.Add(itemCode);

            }

            hql += ")";
            IList<Custodian> CustodianList = this.genericMgr.FindAll<Custodian>(hql, parm.ToArray());

            if (CustodianList != null && CustodianList.Count > 0)
            {

                foreach (Custodian cd in CustodianList)
                {
                    businessException.AddMessage(cd.Item.ToString() + ",");
                }
                if (businessException.HasMessage)
                {
                    businessException.AddMessage("已经分配保管员。");
                    throw businessException;
                }
            }
            #endregion

            foreach (string itemCode in ItemCodeArray.Distinct())
            {
                if (itemCode != "")
                {
                    Custodian cus = new Custodian();
                    cus.Item = itemCode;
                    cus.Location = custodian.Location;
                    cus.UserCode = custodian.UserCode;

                    this.genericMgr.Create(cus);
                }
            }


        }