예제 #1
0
 private void HyperlinkToStudent(JToken j)
 {
     NavigatorPage.NavigatorGoto("student-other-document", new Dictionary <string, object>()
     {
         { "id", j["id"].ToString() }
     });
 }
        public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs)
        {
            base.NavigatedToEvent(sender, kwargs);
            if (kwargs != null)
            {
                ID = kwargs["id"] as string;
            }
            if (ID != null)
            {
                template.Args.instance = ID;
                template.UpdateData();

                //修改按钮。
                template.Args.custombutton = new CustomButton[0];
                if (User.Get().HasAuthorityOrRoot(Authority.UserManage))
                {
                    template.Args.custombutton = template.Args.custombutton.append(new CustomButton("", () => {
                        NavigatorPage.NavigatorGoto("basic-manager-document", new Dictionary <string, object>()
                        {
                            { "id", ID }
                        });
                    }));
                }
                template.ConstructCustomButton();
            }
        }
        private void update_data(JArray datas)
        {
            var brush_white = new SolidColorBrush(Colors.White);
            var brush_gray  = new SolidColorBrush(Colors.LightGray);

            Items.Clear();
            int index = 0;

            foreach (var data in datas)
            {
                //构造每一个条目的记录。
                var row     = new ListTemplateItem();
                var objects = new UIElement[args.columns.Count];
                for (int i = 0; i < objects.Length; ++i)  //构造一条记录的每一个项。
                {
                    var c    = args.columns[i];
                    var item = new TextBlock();
                    item.HorizontalAlignment = HorizontalAlignment.Left;
                    item.VerticalAlignment   = VerticalAlignment.Center;
                    item.FontSize            = c.fontsize ?? args.fontsize;
                    item.Margin = c.margin ?? args.margin;
                    JToken jdata = data[c.name];
                    //按类型创建UI内容。
                    if (c.type == "text")
                    {
                        item.Text = jdata.ToString();
                    }
                    else if (c.type == "custom")
                    {
                        item.Text = (c.data as Func <JToken, string>)(jdata);
                    }
                    else if (c.type == "choice")
                    {
                        item.Text = (c.data as IDictionary <string, string>)[jdata.ToString()];
                    }
                    if (c.customaction != null)
                    {
                        item.PreviewMouseLeftButtonDown += (s, e) => {
                            c.customaction(data);
                        };
                    }
                    if (c.hyperlink != null)
                    {
                        var goal = c.hyperlink(data);                  //局部闭包
                        item.PreviewMouseLeftButtonDown += (s, e) => { //点击超链接事件。
                            NavigatorPage.NavigatorGoto(goal.Item1, goal.Item2);
                        };
                    }
                    objects[i] = item;
                }
                row.SetChildren(gridlength, objects);
                row.Background = index % 2 == 0 ? brush_gray : brush_white;
                //itemlist[index] = row;
                Items.Add(row);
                ++index;
            }
        }
예제 #4
0
        public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs)
        {
            base.NavigatedToEvent(sender, kwargs);
            if (ID != null)
            {
                template.Args.instance = ID;
                template.UpdateData();
                //更新按钮。
                template.Args.custombutton = new CustomButton[0];
                if (User.Get().HasAuthorityOrRoot(Authority.CourseManage))
                {
                    template.Args.custombutton = template.Args.custombutton.append(new CustomButton("", () => {//[pencil]
                        NavigatorPage.NavigatorGoto("course-modify", new Dictionary <string, object>()
                        {
                            { "id", ID }
                        });
                    }, Tips: "修改"));
                }
                if (User.Get().BelongQuery("course", ID) == BelongRelation.Parent ||
                    User.Get().HasAuthorityOrRoot(Authority.CourseManage))
                {
                    template.Args.custombutton = template.Args.custombutton.append(new CustomButton("", () => {//[people]
                        NavigatorPage.NavigatorGoto("course-detail", new Dictionary <string, object>()
                        {
                            { "id", ID }
                        });
                    }, Tips: "出勤记录"));
                }
                template.ConstructCustomButton();

                //更新学生列表。
                var res = User.Api["api/courses/basic/"][ID].Retrieve();
                if (res.statuslike("2**"))
                {
                    var data = res.instance;
                    //构建有关学生的列表。
                    var datas   = new JArray();
                    var idset   = data["as_student_set"].map(j => j.ToString()) as string[];
                    var nameset = data["student_name_related"].map(j => j.ToString()) as string[];
                    for (int i = 0; i < idset.Length && i < nameset.Length; ++i)
                    {
                        var jo = new JObject();
                        jo["id"]   = new JValue(idset[i]);
                        jo["name"] = new JValue(nameset[i]);
                        datas.Add(jo);
                    }
                    list_temp.UpdateData(datas);
                }
            }
        }
        public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs)
        {
            base.NavigatedToEvent(sender, kwargs);
            if (kwargs != null)
            {
                ID = kwargs["id"] as string;
            }
            if (ID != null)
            {
                template.Args.instance = ID;
                template.UpdateData();
                template2.Args.instance = ID;
                template2.UpdateData();

                //修改按钮。
                template.Args.custombutton = new CustomButton[0];
                if (User.Get().HasAuthorityOrRoot(Authority.StudentManage))
                {
                    template.Args.custombutton = template.Args.custombutton.append(new CustomButton("", () => {
                        NavigatorPage.NavigatorGoto("student-manager-document", new Dictionary <string, object>()
                        {
                            { "id", ID }
                        });
                    }));
                }
                template.ConstructCustomButton();

                //列出学习的课程。
                var res = User.Api["api/auth/students/"][ID].Retrieve();
                if (res.statuslike("2**"))
                {
                    var idset   = res.instance["course_set"].map(j => j.ToString()) as string[];
                    var nameset = res.instance["course_name_related"].map(j => j.ToString()) as string[];
                    var jdata   = new JArray();
                    for (int i = 0; i < idset.Length && i < nameset.Length; ++i)
                    {
                        var jo = new JObject();
                        jo["id"]   = new JValue(idset[i]);
                        jo["name"] = new JValue(nameset[i]);
                        jdata.Add(jo);
                    }
                    list_temp.UpdateData(jdata);
                }
                else
                {
                    NavigatorPage.MsgSystem.Show(null, "错误", res.content);
                }
            }
        }
예제 #6
0
 public override void NavigatedToEvent(object sender, IDictionary <string, object> kwargs)
 {
     base.NavigatedToEvent(sender, kwargs);
     if (kwargs != null)
     {
         ID = kwargs["id"] as string;
     }
     if (ID != null)
     {
         template.Args.instance = ID;
         template.UpdateData();
         //更新按钮。
         template.Args.custombutton = new CustomButton[0];
         if (User.Get().HasAuthorityOrRoot(Authority.ClassroomManage))
         {
             template.Args.custombutton = template.Args.custombutton.append(new CustomButton("", () => {//[pencil]
                 NavigatorPage.NavigatorGoto("classroom-modify", new Dictionary <string, object>()
                 {
                     { "id", ID }
                 });
             }, Tips: "修改"));
             list_temp.Args.filter("classroom_manage", ID);
             //如果是管理者,那么还可以查看到教室使用记录。
             list_temp.UpdateData();
             if (ListGrid.Children.Count <= 0)
             {
                 ListGrid.Children.Add(list_temp);
             }
         }
         else if (ListGrid.Children.Count > 0)
         {
             ListGrid.Children.Clear();
         }
         template.ConstructCustomButton();
     }
 }
        /// <summary>
        /// 链接生成最新内容,伴随查询参数。
        /// </summary>
        public void UpdateData()
        {
            itemlist = null;
            var search = SearchBox.Text;

            if (search == "")
            {
                search = null;
            }
            Task.Run(() => {
                var res = new Response[args.urls.Length];
                for (int i = 0; i < res.Length; ++i)
                {
                    res[i] = args.api[args.urls[i].url].List(args.getFilter(), getorderings(), search);
                }
                var flag = true;
                foreach (var i in res)
                {
                    if (!i.statuslike("2**"))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    var datas = res.map(t => t.list) as JArray[];
                    Dispatcher.Invoke(() => {
                        //var Items = this.Items;
                        var brush_white = new SolidColorBrush(Colors.White);
                        var brush_gray  = new SolidColorBrush(Colors.LightGray);
                        Items.Clear();
                        int index = 0;
                        foreach (var data in datas[0])
                        {
                            //构造每一个条目的记录。
                            var row     = new ListTemplateItem();
                            var objects = new UIElement[args.columns.Count];
                            for (int i = 0; i < objects.Length; ++i) //构造一条记录的每一个项。
                            {
                                var c = args.columns[i];

                                var item = new TextBlock();
                                item.HorizontalAlignment = HorizontalAlignment.Left;
                                item.VerticalAlignment   = VerticalAlignment.Center;
                                item.FontSize            = c.fontsize ?? args.fontsize;
                                item.Margin = c.margin ?? args.margin;
                                //首先过滤名称,检查是主键内容还是副URL的内容。
                                JToken jdata = null;
                                if (c.name.Contains("/"))  //这表示使用斜线分割的url's name和json's name。
                                {
                                    var sp        = c.name.Split('/');
                                    var url_index = args.urls.firstAt(u => u.name == sp[0]);//得知这是第几条URL。
                                    if (url_index < 0)
                                    {
                                        throw new Exception("找不到对应的URL。Column的name书写错误。");
                                    }
                                    var second_url = args.urls[url_index];//获得副url的引用。

                                    foreach (var seconddata in datas[url_index])
                                    {
                                        if (seconddata[second_url.primarykey].ToString() == data[args.urls[0].primarykey].ToString())  //这个标志相当于二者对等。
                                        {
                                            jdata = seconddata[sp[1]];
                                            break;
                                        }
                                    }
                                }
                                else   //这表示是主键的内容。
                                {
                                    jdata = data[c.name];
                                }
                                //按类型创建UI内容。
                                if (c.type == "text")
                                {
                                    item.Text = jdata.ToString();
                                }
                                else if (c.type == "custom")
                                {
                                    item.Text = (c.data as Func <JToken, string>)(jdata);
                                }
                                else if (c.type == "choice")
                                {
                                    item.Text = (c.data as IDictionary <string, string>)[jdata.ToString()];
                                }
                                if (c.customaction != null)
                                {
                                    item.PreviewMouseLeftButtonDown += (s, e) => {
                                        c.customaction(data);
                                    };
                                }
                                if (c.hyperlink != null)
                                {
                                    var goal = c.hyperlink(data);                  //局部闭包
                                    item.PreviewMouseLeftButtonDown += (s, e) => { //点击超链接事件。
                                        NavigatorPage.NavigatorGoto(goal.Item1, goal.Item2);
                                    };
                                }
                                objects[i] = item;
                            }
                            row.SetChildren(gridlength, objects);
                            row.Background = index % 2 == 0 ? brush_gray : brush_white;
                            //itemlist[index] = row;
                            Items.Add(row);
                            ++index;
                        }
                    });
                }
                else   //抛出错误,存在不能正确连接的url。
                {
                    NavigatorPage.MsgSystem.Show(null, "错误", res[0].content);
                }
            });
        }