public ActionResult SaveOccupationName(string OccpationNameId, string OccpationName, string classId, string standardId)
        {
            IOccupationBLL bLL = new OccupationBLL();

            ISalaryBLL salaryBLL = new SalaryBLL();

            OccupationName occupationName = new OccupationName {
                Id = Convert.ToInt32(OccpationNameId), Name = OccpationName, ClassId = Convert.ToInt32(classId)
            };

            if (bLL.SaveOccupationName(occupationName))
            {
                occupationName = bLL.GetOccupationNameByNameAndClass(OccpationName, Convert.ToInt32(classId));

                StandardMapOccupationName mapOcc = new StandardMapOccupationName {
                    OccupationNameId = occupationName.Id, StandardId = Convert.ToInt32(standardId)
                };

                if (salaryBLL.SaveMapOcc(mapOcc))
                {
                    TempData["info"] = "保存成功";
                    return(Redirect("/Settings/OccupationSettings"));
                }
                else
                {
                    TempData["error"] = "保存失败";
                    return(Redirect(Request.UrlReferrer.AbsoluteUri));
                }
            }
            else
            {
                TempData["error"] = "保存失败";
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
        }
예제 #2
0
        /// <summary>
        /// 保存薪酬标准和职位的映射关系
        /// </summary>
        /// <param name="standardMapOccupationName">需要保存的映射关系</param>
        /// <returns>是否成功</returns>
        public bool SaveMapOcc(StandardMapOccupationName standardMapOccupationName)
        {
            //throw new NotImplementedException();

            IStandardMapOccupationNameDAL dAL = new StandardMapOccupationNameDAL();

            StandardMapOccupationName tempMap = dAL.QueryById(standardMapOccupationName.Id);

            if (tempMap != null)
            {
                standardMapOccupationName.Id = tempMap.Id;
                if (dAL.Update(standardMapOccupationName) > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                if (dAL.Add(standardMapOccupationName) > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
        /// <summary>
        /// 保存薪酬标准,编辑或添加
        /// </summary>
        /// <param name="formCollection">表单值容器</param>
        /// <returns>成功则重定向到刚刚保存的薪酬标准的详情页,否则回到源URL</returns>
        public ActionResult SaveStandard(FormCollection formCollection)
        {
            //薪酬管理的业务层
            ISalaryBLL salaryBLL = new SalaryBLL();

            //薪酬项目的业务层
            ISalaryItemBLL bLL = new SalaryItemBLL();

            //数据层Model的薪酬标准
            SalaryStandard salaryStandard = new SalaryStandard();

            Type type = salaryStandard.GetType();

            var props = type.GetProperties();

            //反射,遍历,把表单数据装载到对象的属性中
            foreach (var p in props)
            {
                if (p.Name != "StandardState" && p.Name != "Id")
                {
                    p.SetValue(salaryStandard, Convert.ChangeType(formCollection[p.Name], p.PropertyType));
                }
            }

            //装载id,因为当添加薪酬标准时,id为空,null类型不能转换
            salaryStandard.Id = Convert.ToInt32(formCollection["Id"]);

            //装载状态,枚举类型不能转换
            if (formCollection["StandardChecked"] == "Checked")
            {
                salaryStandard.StandardState = EnumState.StandardStateEnum.Checked;
            }
            else
            {
                salaryStandard.StandardState = EnumState.StandardStateEnum.WaitCheck;
            }

            //先保存该薪酬标准,否则,无法insert映射记录
            salaryBLL.SaveSalaryStandard(salaryStandard);

            //根据全局唯一的编号获取刚刚保存的薪酬标准的id
            salaryStandard.Id = salaryBLL.GetSalaryStandardIdByfileNumber(salaryStandard.StandardFileNumber);

            var itemcheckbox = formCollection["ItemCheckbox"];

            decimal total = 0;

            //遍历复选框,只有复选框勾选,下面对应的输入框的数值才有效
            foreach (var i in itemcheckbox.Split(','))
            {
                StandardMapItem tempMap = new StandardMapItem {
                    StandardId = salaryStandard.Id, ItemId = Convert.ToInt32(i), Amout = Convert.ToDecimal(formCollection["value" + i])
                };
                salaryBLL.SaveMapItem(tempMap);
                total += tempMap.Amout;
            }

            //更新总金额
            salaryStandard.Total = total;

            //判断该薪酬标准在映射表中有没有记录
            if (salaryBLL.GetAllStandardMapOccByStandardId(salaryStandard.Id) != null)
            {
                if (!salaryBLL.DeleteAllOccMapByStandardId(salaryStandard.Id))
                {
                    TempData["error"] = "保存失败";
                    return(Redirect(Request.UrlReferrer.AbsoluteUri));
                }
            }
            //往数据库添加未存在的映射关系
            for (int i = Convert.ToInt32(formCollection["eCount"]); i < 3; i++)
            {
                if (Convert.ToInt32(formCollection["occName" + i]) != 0)
                {
                    StandardMapOccupationName standardMapOccupationName = new StandardMapOccupationName {
                        StandardId = salaryStandard.Id, OccupationNameId = Convert.ToInt32(formCollection["occName" + i])
                    };
                    salaryBLL.SaveMapOcc(standardMapOccupationName);
                }
            }

            //重新保存一次薪酬标准
            if (salaryBLL.SaveSalaryStandard(salaryStandard))
            {
                TempData["info"] = "保存成功";
                return(RedirectToAction("DetailSalaryStandard", new { id = salaryStandard.Id }));
            }
            else
            {
                TempData["error"] = "保存失败";
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
        }