Beispiel #1
0
        private void LoadTimeEnd()
        {
            string access_token = Session["access_token"].ToString();
            string ST_NUM       = access_token.Substring(0, access_token.IndexOf("_"));

            #region 获得晚点名信息
            if (HttpContext.Current.Request.Cookies["NightInfo"] != null && HttpContext.Current.Request.Cookies["NightInfo"]["UserID"] == ST_NUM)
            {
                HttpCookie _cookie = HttpContext.Current.Request.Cookies["NightInfo"];
                //晚点名请假截止时间
                if (_cookie["DeadLine"] != null)
                {
                    DateTime end_time_night = Convert.ToDateTime(_cookie["DeadLine"].ToString());

                    if (end_time_night < DateTime.Now)//小于当前是见表示尚可请假
                    {
                        label_EndTime.InnerText = "已过请假时间!";
                    }
                    else
                    {
                        label_EndTime.InnerText = end_time_night.ToString("yyyy/MM/dd HH:mm");
                    }
                }
                else
                {
                    label_EndTime.InnerText = "未设置";
                }

                //晚点名时间
                if (_cookie["BatchTime"] != null)
                {
                    DateTime call_time = Convert.ToDateTime(_cookie["BatchTime"].ToString());
                    label_CallTime.InnerText = call_time.ToString("yyyy/MM/dd HH:mm");
                }
                else
                {
                    label_CallTime.InnerText = "未设置";
                }
            }
            else
            {
                Client <NightInfo>    client_Night = new Client <NightInfo>();
                ApiResult <NightInfo> result_Night = client_Night.GetRequest("access_token=" + access_token, "/api/student/night");
                if (result_Night.result == "success")
                {
                    NightInfo nightInfo = result_Night.data;

                    #region 存入Cookie
                    if (Request.Cookies["NightInfo"] != null)
                    {
                        Response.Cookies.Remove("NightInfo");
                    }

                    HttpCookie cookie = new HttpCookie("NightInfo");                                //晚点名信息
                    cookie.Values.Add("UserID", ST_NUM);
                    cookie.Values.Add("TeacherID", nightInfo.TeacherID);                            //老师ID
                    cookie.Values.Add("TeacherName", HttpUtility.UrlEncode(nightInfo.TeacherName)); //老师姓名
                    cookie.Values.Add("BatchTime", nightInfo.BatchTime);                            //晚点名批次时间
                    cookie.Values.Add("DeadLine", nightInfo.DeadLine);                              //晚点名请假截止时间
                    cookie.Expires = DateTime.Now.AddMinutes(20);
                    HttpContext.Current.Response.Cookies.Add(cookie);
                    #endregion

                    //晚点名请假截止时间
                    if (nightInfo.DeadLine != null)
                    {
                        DateTime end_time_night = Convert.ToDateTime(nightInfo.DeadLine);

                        if (end_time_night < DateTime.Now)//小于当前是见表示尚可请假
                        {
                            label_EndTime.InnerText = "已过请假时间!";
                        }
                        else
                        {
                            label_EndTime.InnerText = end_time_night.ToString("yyyy/MM/dd HH:mm");
                        }
                    }
                    else
                    {
                        label_EndTime.InnerText = "未设置";
                    }

                    //晚点名时间
                    if (nightInfo.BatchTime != null)
                    {
                        DateTime call_time = Convert.ToDateTime(nightInfo.BatchTime);
                        label_CallTime.InnerText = call_time.ToString("yyyy/MM/dd HH:mm");
                    }
                    else
                    {
                        label_CallTime.InnerText = "未设置";
                    }
                }
                else
                {
                    label_EndTime.InnerText  = "获取数据失败!";
                    label_CallTime.InnerText = "获取数据失败!";
                }
            }
            #endregion

            #region 获得节假日信息
            if (HttpContext.Current.Request.Cookies["HolidayInfo"] != null && HttpContext.Current.Request.Cookies["HolidayInfo"]["UserID"] == ST_NUM)
            {
                HttpCookie _cookie = HttpContext.Current.Request.Cookies["HolidayInfo"];
                //节假日请假时间
                if (_cookie["DeadLine"] != null)
                {
                    DateTime end_time_holiday = Convert.ToDateTime(_cookie["DeadLine"].ToString());

                    if (end_time_holiday < DateTime.Now)//小于当前是见表示尚可请假
                    {
                        vacation_end_time.Value = "已过请假时间!";
                    }
                    else
                    {
                        Default_Vacation.Visible = true;
                        vacation_end_time.Value  = end_time_holiday.ToString("yyyy/MM/dd HH:mm");
                    }
                }
                else
                {
                    vacation_end_time.Value = "未设置";
                }
            }
            else
            {
                Client <Holiday>    client_Holiday = new Client <Holiday>();
                ApiResult <Holiday> result_Holiday = client_Holiday.GetRequest("access_token=" + access_token, "/api/student/holiday");
                if (result_Holiday.result == "success")
                {
                    Holiday holiday = result_Holiday.data;

                    #region 存入Cookie
                    if (HttpContext.Current.Request.Cookies["HolidayInfo"] != null)
                    {
                        HttpContext.Current.Response.Cookies.Remove("HolidayInfo");
                    }
                    HttpCookie cookie = new HttpCookie("HolidayInfo"); //节假日离校信息
                    cookie.Values.Add("UserID", ST_NUM);
                    cookie.Values.Add("TeacherID", holiday.TeacherID); //老师ID
                    cookie.Values.Add("DeadLine", holiday.DeadLine);   //截止时间
                    cookie.Expires = DateTime.Now.AddMinutes(20);
                    HttpContext.Current.Response.Cookies.Add(cookie);
                    #endregion

                    //节假日请假时间
                    if (holiday.DeadLine != null)
                    {
                        DateTime end_time_holiday = Convert.ToDateTime(holiday.DeadLine);

                        if (end_time_holiday < DateTime.Now)//小于当前是见表示尚可请假
                        {
                            vacation_end_time.Value = "已过请假时间!";
                        }
                        else
                        {
                            Default_Vacation.Visible = true;
                            vacation_end_time.Value  = end_time_holiday.ToString("yyyy/MM/dd HH:mm");
                        }
                    }
                    else
                    {
                        vacation_end_time.Value = "未设置";
                    }
                }
                else
                {
                    vacation_end_time.Value = "获取数据失败!";
                }
            }
            #endregion
        }
Beispiel #2
0
        public ApiBaseResult Nigth(string access_token)
        {
            ApiBaseResult result = Check(access_token);

            if (result == null)
            {
                result = new ApiBaseResult();

                #region 获取数据

                string UserID = access_token.Substring(0, access_token.IndexOf("_"));

                NightInfo nightInfo = new NightInfo();

                var studentInfo = from vw_Student in db.vw_Student where (vw_Student.ST_Num == UserID) select vw_Student;
                if (studentInfo.Any())
                {
                    string className = studentInfo.ToList().First().ST_Class;
                    string TeacherID = studentInfo.ToList().First().ST_TeacherID;
                    nightInfo.TeacherID   = TeacherID;
                    nightInfo.TeacherName = studentInfo.ToList().First().ST_Teacher;

                    var batchList = from vw_ClassBatch in db.vw_ClassBatch where (vw_ClassBatch.ClassName == className) select vw_ClassBatch;
                    if (batchList.Any())
                    {
                        nightInfo.BatchTime = batchList.ToList().First().Datetime.ToString();
                    }
                    else
                    {
                        result.result   = "error";
                        result.messages = "未设置晚点名时间!";
                    }

                    T_Deadline deadLine = new T_Deadline();
                    try
                    {
                        deadLine           = (from T_Deadline in db.T_Deadline where ((T_Deadline.TeacherID == TeacherID) && (T_Deadline.TypeID == 2)) select T_Deadline).ToList().First();
                        nightInfo.DeadLine = deadLine.Time.ToString();
                        result.result      = "success";
                        result.data        = nightInfo;
                    }
                    catch
                    {
                        result.result   = "error";
                        result.messages = "未设置晚点名请假截止时间";
                    }
                }
                else
                {
                    result.result   = "error";
                    result.messages = "出现未知错误、请联系管理员";
                }

                #endregion

                return(result);
            }
            else
            {
                return(result);
            }
        }