public ActionResult SaveForm(string WorksetType, WorkSettingEntity entity)
        {
            var user = OperatorProvider.Provider.Current();
            List <WorkSettingEntity> entityList = new List <WorkSettingEntity>();

            if (WorksetType != "update")
            {
                //获取班制类别
                var data = sysBll.GetList().FirstOrDefault(row => row.Id == WorksetType);
                //是否已经存在
                var one = workset.GetList(user.DeptId).FirstOrDefault(row => row.WorkSetName == data.SystemName);
                if (one != null)
                {
                    return(Success("已经存在该班次。"));
                }
                else
                {
                    //初始化班制
                    entityList = SaveDate(data);
                }
            }
            else
            {
                var one = workset.GetList(user.DeptId).FirstOrDefault(row => row.WorkSettingId == entity.WorkSettingId);
                one.TimeLength    = entity.TimeLength;
                one.Name          = entity.Name;
                one.StartTimeSpan = entity.StartTimeSpan;
                one.EndTimeSpan   = entity.EndTimeSpan;
                DateTime markTime = new DateTime(2000, 01, 02);
                if (entity.EndTime <= entity.StartTime)
                {
                    //跨天
                    entity.EndTime   = markTime.AddDays(1).AddHours(entity.EndTime.Hour).AddMinutes(entity.EndTime.Minute);
                    entity.StartTime = markTime.AddHours(entity.StartTime.Hour).AddMinutes(entity.StartTime.Minute);
                }
                else
                {
                    //没有跨天
                    entity.EndTime   = markTime.AddHours(entity.EndTime.Hour).AddMinutes(entity.EndTime.Minute);
                    entity.StartTime = markTime.AddHours(entity.StartTime.Hour).AddMinutes(entity.StartTime.Minute);
                }
                one.EndTime   = entity.EndTime;
                one.StartTime = entity.StartTime;
                entityList.Add(one);
            }
            workset.saveForm(entityList);
            return(Success("操作成功。"));
        }
        /// <summary>
        /// 计算班制初始数据
        /// </summary>
        /// <returns></returns>
        private List <WorkSettingEntity> SaveDate(WorkSetTypeEntity data)
        {
            List <WorkSettingEntity> entityList = new List <WorkSettingEntity>();
            int      typeNum   = Convert.ToInt32(data.SystemType);
            DateTime markTime  = new DateTime(2000, 01, 02);
            string   randomNum = CommonHelper.RndNum(8);
            var      user      = OperatorProvider.Provider.Current();

            for (int i = 0; i < typeNum; i++)
            {
                int hourNum = 24 / typeNum;
                WorkSettingEntity entity = new WorkSettingEntity();
                entity.DeparMentId = user.DeptId;
                entity.BookMarks   = randomNum;
                entity.StartTime   = data.SystemName == "常白班" ? markTime.AddHours(8).AddMinutes(30) : data.SystemName == "一班制" ? markTime : markTime.AddHours(hourNum * i);
                if (i == typeNum - 1)
                {
                    entity.EndTime = data.SystemName == "常白班" ? markTime.AddHours(17).AddMinutes(30) : data.SystemName == "一班制" ? markTime.AddDays(1).AddMinutes(-1) : markTime.AddHours(hourNum * (i + 1)).AddMinutes(-1);
                }
                else
                {
                    entity.EndTime = data.SystemName == "常白班" ? markTime.AddHours(17).AddMinutes(30) : data.SystemName == "一班制" ? markTime.AddDays(1).AddMinutes(-1) : markTime.AddHours(hourNum * (i + 1));
                }
                var timeSpan = (entity.EndTime - entity.StartTime);
                entity.TimeLength = timeSpan.Hours < 10 ? "0" + timeSpan.Hours + "时" + (timeSpan.Minutes < 10 ? "0" + timeSpan.Minutes.ToString() + "分" : timeSpan.Minutes.ToString() + "分")
                    : timeSpan.Hours.ToString() + "时" + (timeSpan.Minutes < 10 ? "0" + timeSpan.Minutes.ToString() + "分" : timeSpan.Minutes.ToString() + "分");
                entity.WorkSetType = typeNum;
                entity.WorkSetupId = data.Id;
                entity.WorkSetName = data.SystemName;
                #region  班次名称
                switch (data.SystemName)
                {
                case "常白班":
                    entity.Name = "常白班";
                    break;

                case "一班制":
                    entity.Name = "通宵班";
                    break;

                case "两班制":
                    switch (i)
                    {
                    case 0:
                        entity.Name = "白班";
                        break;

                    default:
                        entity.Name = "夜班";
                        break;
                    }
                    break;

                case "三班制":
                    switch (i)
                    {
                    case 0:
                        entity.Name = "前夜";
                        break;

                    case 1:
                        entity.Name = "白班";
                        break;

                    default:
                        entity.Name = "后夜";
                        break;
                    }
                    break;

                case "四班制":
                    switch (i)
                    {
                    case 0:
                        entity.Name = "A班";
                        break;

                    case 1:
                        entity.Name = "B班";
                        break;

                    case 2:
                        entity.Name = "C班";
                        break;

                    default:
                        entity.Name = "D班";
                        break;
                    }
                    break;

                default:
                    entity.Name = "班制";
                    break;
                }
                #endregion
                entityList.Add(entity);
            }
            return(entityList);
        }