public ActionResult SaveForm(DeptCycleTaskEntity entity)
        {
            try
            {
                var user      = OperatorProvider.Provider.Current();
                var deptcycle = new DeptCycleTaskBLL();

                deptcycle.SaveForm(entity, user.UserId);
                return(Success("操作成功。"));
            }
            catch (Exception ex)
            {
                return(Error(ex.Message));
            }
        }
        private List <DeptCycleTaskEntity> GetData(Worksheet sheet, int titleIndex, string userid)
        {
            var userbll  = new UserBLL();
            var user     = userbll.GetEntity(userid);
            var total    = 0;
            var deptuser = userbll.GetList(user.DepartmentId, 10000, 1, out total);
            var result   = new List <DeptCycleTaskEntity>();

            for (int i = titleIndex + 1; i <= sheet.Cells.MaxDataRow; i++)

            {
                var entity = new DeptCycleTaskEntity()
                {
                    //id = Guid.NewGuid().ToString(),
                    content = sheet.Cells[i, 0].StringValue
                };
                if (string.IsNullOrEmpty(entity.content) && string.IsNullOrEmpty(sheet.Cells[i, 1].StringValue))
                {
                    break;
                }
                if (string.IsNullOrEmpty(entity.content))
                {
                    throw new Exception(string.Format("行 {0} 任务内容为空!", i + 1));
                }
                var workuser   = sheet.Cells[i, 2].StringValue;
                var ckworkuser = deptuser.FirstOrDefault(x => x.RealName == workuser);
                if (ckworkuser == null)
                {
                    throw new Exception(string.Format("行 {0} 部门不存在" + workuser + "责任人!", i + 1));
                }
                else
                {
                    entity.dutyuser   = ckworkuser.RealName;
                    entity.dutyuserid = ckworkuser.UserId;
                }
                if (!string.IsNullOrEmpty(sheet.Cells[i, 1].StringValue))
                {
                    //每年,二月、九月,15日,白班  每月,第一个、第三个,星期五,白班
                    var Cycle = sheet.Cells[i, 1].StringValue.Trim();

                    var cycleType = Cycle.Split(',');
                    if (cycleType[0] != "每天" && cycleType[0] != "每周" && cycleType[0] != "每月" && cycleType[0] != "每年")
                    {
                        throw new Exception(string.Format("行 {0} 周期规则错误!", i + 1));
                    }

                    entity.cycle = cycleType[0];
                    var ck   = false;
                    var data = string.Empty;
                    for (int j = 1; j < cycleType.Length; j++)
                    {
                        //if (cycleType[j] == "白班" || cycleType[j] == "夜班")
                        //{
                        //    entity.worksetname = cycleType[j];

                        //}
                        //else
                        if (cycleType[j] == "截止")
                        {
                            entity.isend = true;
                        }
                        else
                        if (cycleType[j] == "最后一天")
                        {
                            if (Cycle.Contains("每月") || Cycle.Contains("每年"))
                            {
                                entity.islastday = true;
                            }
                            else
                            {
                                throw new Exception(string.Format("行 {0} 周期规则错误!", i + 1));
                            }
                        }
                        else
                        if (cycleType[j].Contains("双休"))
                        {
                            if (Cycle.Contains("每月") || Cycle.Contains("每年"))
                            {
                                entity.isweek = true;
                            }
                            else if (Cycle.Contains("每天"))
                            {
                                entity.isweek = true;
                            }
                            else
                            {
                                throw new Exception(string.Format("行 {0} 周期规则错误!", i + 1));
                            }
                        }
                        else
                        {
                            data += cycleType[j].Replace('日', ' ').Trim().Replace('、', ',') + ";";
                            ck    = true;
                        }
                    }

                    if (ck)
                    {
                        data             = data.Substring(0, data.Length - 1);
                        entity.cycledate = data;
                    }
                    else
                    {
                        entity.cycledate = data;
                    }
                }
                else
                {
                    throw new Exception(string.Format("行 {0} 周期不能为空!", i + 1));
                }
                result.Add(entity);
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 新增 修改
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="userid"></param>
 public void SaveForm(DeptCycleTaskEntity entity, string userid)
 {
     dpetCycle.SaveForm(entity, userid);
 }