Exemple #1
0
        public ApiBaseResult LeaveSchool([FromBody] LeaveSchoolModel data)
        {
            ApiBaseResult result;

            if (data != null)
            {
                if (data.Check())
                {
                    result = Check(data.access_token);
                    if (result == null)
                    {
                        return(leaveSchool(data));
                    }
                    else
                    {
                        return(result);
                    }
                }
                else
                {
                    result          = new ApiBaseResult();
                    result.result   = "error";
                    result.messages = "参数格式错误或缺少参数!";
                    return(result);
                }
            }
            else
            {
                result          = new ApiBaseResult();
                result.result   = "error";
                result.messages = "参数错误!";
                return(result);
            }
        }
Exemple #2
0
        //是否可以请假 存在bug
        #region 学生请假操作

        private ApiBaseResult leaveSchool(LeaveSchoolModel data)
        {
            ApiBaseResult result = new ApiBaseResult();

            try
            {
                #region 请假操作
                string access_token = data.access_token;
                string ST_Num       = access_token.Substring(0, access_token.IndexOf("_"));
                string LL_Type      = data.leave_type;
                string leaveDate    = data.leave_date;
                string leaveTime    = data.leave_time;
                string backDate     = data.back_date;
                string backTime     = data.back_time;
                string leaveReason  = data.leave_reason;
                string leaveWay     = data.leave_way;
                string backWay      = data.back_way;
                string address      = data.leave_reason;
                string holidayType  = data.leave_reason;//节假日请假的原因只能为三种

                //节假日请假时,请假原因为节假日请假的类型
                if (LL_Type == "节假日请假")
                {
                    leaveReason = data.leave_reason;
                }

                //string LV_Time_Go = leaveDate + " " + leaveTime + ":00";
                //string LV_Time_Back = backDate + " " + backTime + ":00";
                string LV_Time_Go   = leaveDate + " " + leaveTime;
                string LV_Time_Back = backDate + " " + backTime;

                if (Convert.ToDateTime(LV_Time_Go) < Convert.ToDateTime(LV_Time_Back))
                {
                    DateTime time_go   = Convert.ToDateTime(LV_Time_Go);
                    DateTime time_back = Convert.ToDateTime(LV_Time_Back);
                    TimeSpan time_days = time_back - time_go;
                    int      days      = time_days.Days;

                    if (LL_Type == "短期请假")
                    {
                        if (days < 3)//短期请假小于三天
                        {
                            //生成请假单号
                            string LV_NUM = DateTime.Now.ToString("yyMMdd");
                            var    exist  = from T_LeaveList in db.T_LeaveList where (T_LeaveList.StudentID == ST_Num) && (((T_LeaveList.TimeLeave >= time_go) && (T_LeaveList.TimeLeave <= time_back)) || ((T_LeaveList.TimeBack >= time_go) && (T_LeaveList.TimeBack <= time_back)) || ((T_LeaveList.TimeLeave <= time_go) && (T_LeaveList.TimeBack >= time_back))) select T_LeaveList;

                            if (exist.Any())
                            {
                                bool flag = true;
                                foreach (qingjia_MVC.Models.T_LeaveList leaveList in exist.ToList())
                                {
                                    if (leaveList.StateBack == "0")
                                    {
                                        flag = false;
                                        break;
                                    }
                                }
                                if (flag)
                                {
                                    //插入数据库操作
                                    if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                                    {
                                        result.result   = "success";
                                        result.messages = "请假申请成功!";
                                    }
                                    else
                                    {
                                        result.result   = "error";
                                        result.messages = "数据库提交失败,请重新尝试!";
                                    }
                                }
                                else
                                {
                                    result.result   = "error";
                                    result.messages = "您已提交过此时间段的请假申请,请不要重复提交!";
                                }
                            }
                            else
                            {
                                //插入数据库操作
                                if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                                {
                                    result.result   = "success";
                                    result.messages = "请假申请成功!";
                                }
                                else
                                {
                                    result.result   = "error";
                                    result.messages = "数据库提交失败,请重新尝试!";
                                }
                            }
                        }
                        else
                        {
                            result.result   = "error";
                            result.messages = "短期请假不能超过3天!";
                        }
                    }
                    else if (LL_Type == "长期请假")
                    {
                        if (days >= 3)//长期请假
                        {
                            //生成请假单号
                            string LV_NUM = DateTime.Now.ToString("yyMMdd");
                            var    exist  = from T_LeaveList in db.T_LeaveList where (T_LeaveList.StudentID == ST_Num) && (((T_LeaveList.TimeLeave >= time_go) && (T_LeaveList.TimeLeave <= time_back)) || ((T_LeaveList.TimeBack >= time_go) && (T_LeaveList.TimeBack <= time_back)) || ((T_LeaveList.TimeLeave <= time_go) && (T_LeaveList.TimeBack >= time_back))) select T_LeaveList;

                            if (exist.Any())
                            {
                                bool flag = true;
                                foreach (qingjia_MVC.Models.T_LeaveList leaveList in exist.ToList())
                                {
                                    if (leaveList.StateBack == "0")
                                    {
                                        flag = false;
                                        break;
                                    }
                                }
                                if (flag)
                                {
                                    //插入数据库操作
                                    if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                                    {
                                        result.result   = "success";
                                        result.messages = "请假申请成功!";
                                    }
                                    else
                                    {
                                        result.result   = "error";
                                        result.messages = "数据库提交失败,请重新尝试!";
                                    }
                                }
                                else
                                {
                                    result.result   = "error";
                                    result.messages = "您已提交过此时间段的请假申请,请不要重复提交!";
                                }
                            }
                            else
                            {
                                //插入数据库操作
                                if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                                {
                                    result.result   = "success";
                                    result.messages = "请假申请成功!";
                                }
                                else
                                {
                                    result.result   = "error";
                                    result.messages = "数据库提交失败,请重新尝试!";
                                }
                            }
                        }
                        else
                        {
                            result.result   = "error";
                            result.messages = "长期请假短期请假不能少于3天!";
                        }
                    }
                    else if (LL_Type == "节假日请假")
                    {
                        //生成请假单号
                        string LV_NUM = DateTime.Now.ToString("yyMMdd");
                        var    exist  = from T_LeaveList in db.T_LeaveList where (T_LeaveList.StudentID == ST_Num) && (((T_LeaveList.TimeLeave >= time_go) && (T_LeaveList.TimeLeave <= time_back)) || ((T_LeaveList.TimeBack >= time_go) && (T_LeaveList.TimeBack <= time_back)) || ((T_LeaveList.TimeLeave <= time_go) && (T_LeaveList.TimeBack >= time_back))) select T_LeaveList;

                        if (exist.Any())
                        {
                            bool flag = true;
                            foreach (qingjia_MVC.Models.T_LeaveList leaveList in exist.ToList())
                            {
                                if (leaveList.StateBack == "0")
                                {
                                    flag = false;
                                    break;
                                }
                            }
                            if (flag)
                            {
                                //插入数据库操作
                                if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                                {
                                    result.result   = "success";
                                    result.messages = "请假申请成功!";
                                }
                                else
                                {
                                    result.result   = "error";
                                    result.messages = "数据库提交失败,请重新尝试!";
                                }
                            }
                            else
                            {
                                result.result   = "error";
                                result.messages = "您已提交过此时间段的请假申请,请不要重复提交!";
                            }
                        }
                        else
                        {
                            //插入数据库操作
                            if (Insert_LeaveList(LV_NUM, ST_Num, LL_Type, time_go, time_back, leaveReason, leaveWay, backWay, address, holidayType, null, null, null) == 1)
                            {
                                result.result   = "success";
                                result.messages = "请假申请成功!";
                            }
                            else
                            {
                                result.result   = "error";
                                result.messages = "数据库提交失败,请重新尝试!";
                            }
                        }
                    }
                    else
                    {
                        //非离校请假类型
                    }
                }
                else
                {
                    result.result   = "error";
                    result.messages = "请假开始时间不能小于结束时间!";
                }
                #endregion
            }
            catch
            {
                result.result   = "error";
                result.messages = "请假失败,请检查参数格式是否符合要求!";
            }

            return(result);
        }