示例#1
0
 internal static ResponceModel GetTermTime(string credit)
 {
     if (UserCredit.CheckUser(credit, out string username))
     {
         UserInfoSql userInfo = new UserInfoSql(username);
         if (userInfo.TryQuery())
         {
             var server = userInfo.courseserver;
             if (server == null || server == "" || server == "NONE")
             {
             }
             else if (server == "LOCAL")
             {
                 return(new ResponceModel(500, "该功能正在开发中"));
             }
             else
             {
                 var configs = App.Current.Configuration.GetTimeConfig();
                 foreach (var item in configs)
                 {
                     if (item.provider == server)
                     {
                         return(new ResponceModel(200, "获取时间成功", item.config));
                     }
                 }
             }
         }
         return(new ResponceModel(403, "需要先绑定账号或者启用本地服务"));
     }
     else
     {
         return(new ResponceModel(403, "自动登录已失效"));
     }
 }
示例#2
0
        /// <summary>
        /// 获取课表,此方法用于与外部进行交互,依赖<see cref="UserCredit"/>,<see cref="TermTime"/>,<see cref="UserInfoSql"/>。
        /// </summary>
        /// <param name="credit"></param>
        /// <returns></returns>
        internal static ResponceModel GetCourse(string credit, int year, int term)
        {
            try
            {
                if (UserCredit.CheckUser(credit, out string username))
                {
                    UserInfoSql userInfo = new UserInfoSql(username);
                    if (userInfo.TryQuery())
                    {
                        //if (userInfo.courseserver == "ZJUT")
                        //{
                        if (UserInfo.GetBindInfo(username, "jh").state != 0)
                        {
                            //说明你绑定过正方账号。
                            if (UserInfo.GetBindInfo(username, "zfedu").state != 0)
                            {
                                if (JhUser.CheckUser(userInfo.jhpid, userInfo.pwbind_jh).code == 200)
                                {
                                    //TermTimeUni time = TermTime.Get();
                                    //TermTimeUni time = new TermTimeUni(2019,3,)
                                    var result = GetZfCourse(userInfo.jhpid, userInfo.pwbind_zfedu, year, term);
                                    if (result.code == 200)
                                    {
                                        var data = (List <CourseUni>)result.data;

                                        if (data.Count > 0)
                                        {
                                            foreach (var item in data)
                                            {
                                                if (!item.Exists())
                                                {
                                                    item.Add();
                                                }
                                                userInfo.Linkedcourse = data.Map((m) => m.courseid);

                                                userInfo.UpdateLinkedCourse();
                                            }
                                        }


                                        //if (data.Count > 0)
                                        //{
                                        //    foreach (var item in data)
                                        //    {
                                        //        //在这里我们假设课表信息从不改变,虽然说绝大多数情况下是这样。
                                        //        if (!item.Exists())
                                        //        {
                                        //            item.Add();
                                        //        }
                                        //        userInfo.Linkedcourse = data.Map((m) => m.courseid).ToList();
                                        //        userInfo.UpdateLinkedCourse();
                                        //    }
                                        //}

                                        return(new ResponceModel(200, "获取课表成功", data));
                                    }
                                    else
                                    {
                                        return(new ResponceModel(403, "请重新绑定正方"));
                                    }
                                }
                                else
                                {
                                    return(new ResponceModel(403, "请重新绑定正方"));
                                }
                            }
                            else
                            {
                                //SOLVED BUG 这里曾导致未绑定账号但任然显示重新绑定的错误提示信息。
                                return(new ResponceModel(403, "你还没有绑定正方"));
                            }
                        }
                        else
                        {
                            return(new ResponceModel(403, "请重新绑定精弘账号"));
                        }
                        //}
                        //else
                        //{
                        //    return new ResponceModel(500, "暂不支持这个提供商");
                        //}
                    }
                    else
                    {
                        return(new ResponceModel(403, "请绑定精弘账号"));
                    }
                }
                else
                {
                    return(new ResponceModel(403, "自动登录失败,请重新登录"));
                }
            }
            catch (Exception ex)
            {
                return(ResponceModel.GetInstanceError(ex));
            }
        }