public void Delete(AscmAllocateRule ascmAllocateRule)
 {
     try
     {
         YnDaoHelper.GetInstance().nHibernateHelper.Delete<AscmAllocateRule>(ascmAllocateRule);
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("删除失败(Delete AscmAllocateRule)", ex);
         throw ex;
     }
 }
Example #2
0
        public ContentResult LogisticsAllocateTaskRuleSave(AscmAllocateRule ascmAllocateRule_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();
            try
            {
                string userName = string.Empty;
                if (User.Identity.IsAuthenticated)
                {
                    userName = User.Identity.Name;
                }

                AscmAllocateRule ascmAllocateRule = null;
                if (id.HasValue)
                {
                    ascmAllocateRule = AscmAllocateRuleService.GetInstance().Get(id.Value);
                    if (ascmAllocateRule == null)
                        throw new Exception("保存排配规则失败!");

                    ascmAllocateRule.modifyUser = userName;
                    ascmAllocateRule.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }
                else
                {
                    ascmAllocateRule = new AscmAllocateRule();
                    int maxId = YnDaoHelper.GetInstance().nHibernateHelper.GetMaxId("select max(id) from AscmAllocateRule");
                    ascmAllocateRule.id = ++maxId;
                    ascmAllocateRule.workerName = ascmAllocateRule_Model.workerName;
                    ascmAllocateRule.createUser = userName;
                    ascmAllocateRule.createTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    ascmAllocateRule.modifyUser = userName;
                    ascmAllocateRule.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                }

                if (string.IsNullOrEmpty(ascmAllocateRule.workerName))
                    throw new Exception("领料员不能为空!");

                ascmAllocateRule.zRankerName = ascmAllocateRule_Model.zRankerName;
                ascmAllocateRule.dRankerName = ascmAllocateRule_Model.dRankerName;
                ascmAllocateRule.ruleCode = ascmAllocateRule_Model.ruleCode;
                ascmAllocateRule.other = ascmAllocateRule_Model.other;
                ascmAllocateRule.tip1 = ascmAllocateRule_Model.tip1;
                ascmAllocateRule.tip2 = ascmAllocateRule_Model.tip2;

                if (id.HasValue)
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmAllocateRule where workername = '" + ascmAllocateRule_Model.workerName + "' and id <> " + id.Value + " ");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已存在此领料员的排配规则信息【" + ascmAllocateRule.workerName + "】!");
                    AscmAllocateRuleService.GetInstance().Update(ascmAllocateRule);
                }
                else
                {
                    object object1 = YnDaoHelper.GetInstance().nHibernateHelper.GetObject("select count(*) from AscmAllocateRule where workername ='" + ascmAllocateRule_Model.workerName + "'");
                    if (object1 == null)
                        throw new Exception("查询异常!");
                    int iCount = 0;
                    if (int.TryParse(object1.ToString(), out iCount) && iCount > 0)
                        throw new Exception("已存在此领料员的排配规则信息【" + ascmAllocateRule_Model.workerName + "】!");
                    AscmAllocateRuleService.GetInstance().Save(ascmAllocateRule);
                }
                jsonObjectResult.result = true;
                jsonObjectResult.message = "";
                jsonObjectResult.id = ascmAllocateRule.id.ToString();
                jsonObjectResult.entity = ascmAllocateRule;
            }
            catch (Exception ex)
            {
                jsonObjectResult.result = false;
                jsonObjectResult.message = ex.Message;
            }

            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }
 public void Update(AscmAllocateRule ascmAllocateRule)
 {
     try
     {
         using (ITransaction tx = YnDaoHelper.GetInstance().nHibernateHelper.GetCurrentSession().BeginTransaction())
         {
             try
             {
                 YnDaoHelper.GetInstance().nHibernateHelper.Update<AscmAllocateRule>(ascmAllocateRule);
                 tx.Commit();//正确执行提交
             }
             catch (Exception ex)
             {
                 tx.Rollback();//回滚
                 YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmAllocateRule)", ex);
                 throw ex;
             }
         }
     }
     catch (Exception ex)
     {
         YnBaseClass2.Helper.LogHelper.GetLog().Error("修改失败(Update AscmAllocateRule)", ex);
         throw ex;
     }
 }
        public void SetLogisticsClass(AscmAllocateRule ascmAllocateRule)
        {
            if (ascmAllocateRule != null)
            {
                string ids = string.Empty;
                if (!string.IsNullOrEmpty(ascmAllocateRule.logisticsClassId.ToString()) && ascmAllocateRule.logisticsClassId != 0)
                    ids = ascmAllocateRule.logisticsClassId.ToString();

                if (!string.IsNullOrEmpty(ids))
                {
                    string sql = "from AscmLogisticsClassInfo where id = " + ids;

                    IList<AscmLogisticsClassInfo> ilist = YnDaoHelper.GetInstance().nHibernateHelper.Find<AscmLogisticsClassInfo>(sql);
                    if (ilist != null && ilist.Count > 0)
                    {
                        List<AscmLogisticsClassInfo> listAscmLogisticsClassInfo = YnBaseClass2.Helper.ConvertHelper.ConvertIListToList<AscmLogisticsClassInfo>(ilist);
                        ascmAllocateRule.ascmLogisticsClassInfo = listAscmLogisticsClassInfo.Find(e => e.id == ascmAllocateRule.logisticsClassId);
                    }
                }
            }
        }
        public ContentResult LogisticsWorkerSave(AscmAllocateRule ascmAllocateRule_Model, int? id)
        {
            JsonObjectResult jsonObjectResult = new JsonObjectResult();

            string userName = string.Empty;
            if (User.Identity.IsAuthenticated)
            {
                userName = User.Identity.Name;
            }

            try
            {
                if (!string.IsNullOrEmpty(ascmAllocateRule_Model.id.ToString()))
                {
                    List<AscmAllocateRule> list = AscmAllocateRuleService.GetInstance().GetList("from AscmAllocateRule where workerName = '" + ascmAllocateRule_Model.workerName + "'", false, false, false);
                    if (list == null)
                        throw new Exception("找不到匹配的领料员");

                    if (list != null && list.Count > 0)
                    {
                        foreach (AscmAllocateRule ascmAllocateRule in list)
                        {
                            ascmAllocateRule.logisticsClassId = id.Value; ;
                            ascmAllocateRule.modifyUser = userName;
                            ascmAllocateRule.modifyTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                        }

                        AscmAllocateRuleService.GetInstance().Update(list);
                    }
                    jsonObjectResult.result = true;
                    jsonObjectResult.message = "";
                }
                else
                {
                    jsonObjectResult.message = "传入参数[id=null]错误!";
                }
            }
            catch (Exception ex)
            {
                jsonObjectResult.message = ex.Message;
            }

            string sReturn = JsonConvert.SerializeObject(jsonObjectResult);
            return Content(sReturn);
        }