コード例 #1
0
        /// <summary>
        /// Получить список детей у пользователя или самого пользователя
        /// </summary>
        /// <returns></returns>
        public List <List <Persons> > GetMembers()
        {
            List <List <Persons> > ids = new List <List <Persons> >()
            {
                new List <Persons>()
            };
            List <string> roles = new List <string>();

            var info = ((JObject)JsonConvert.DeserializeObject(api.GetContext()))["roles"].ToObject <JArray>();

            //var classmates = ((JArray)JsonConvert.DeserializeObject(api.GetGroupPersons(group.id, (groups[i].year >= DateTime.UtcNow.Year - 1 && groups[i].year <= DateTime.UtcNow.Year) ? false : true)));

            foreach (string roleArray in info)
            {
                roles.Add(roleArray);
            }

            bool isStudent = false;

            foreach (string role in roles)
            {
                if (role == "EduStudent")
                {
                    isStudent = true;
                }
                else
                {
                    isStudent = false;
                    break;
                }
            }

            if (isStudent)
            {
                var context = api.GetContext();

                ids[0].Add(new Persons()
                {
                    userId = ((JObject)JsonConvert.DeserializeObject(context))["userId"].Value <long>(), personId = ((JObject)JsonConvert.DeserializeObject(api.GetContext()))["personId"].Value <long>(), userName = ((JObject)JsonConvert.DeserializeObject(api.GetContext()))["shortName"].Value <string>()
                });
            }
            else
            {
                var childrens = ((JArray)JsonConvert.DeserializeObject(api.GetChildren())).ToObject <JArray>();
                var context   = ((JObject)JsonConvert.DeserializeObject(api.GetContext()))["children"].ToObject <JArray>();

                int j = 0;

                foreach (JObject children in context)
                {
                    ids[0].Add(new Persons()
                    {
                        personId = children["personId"].Value <long>(), userName = children["shortName"].Value <string>(), userId = childrens[j].Value <long>()
                    });
                    j++;
                }
            }

            return(ids);
        }
コード例 #2
0
        private void AddMarksFromDnevnik_Click(object sender, EventArgs e)
        {
            LoginReturn login         = CheckLoginInDnevnik();
            bool        closedSuccess = login.closedSuccess;
            string      keyAccess     = login.keyAccess;

            if (closedSuccess)
            //try
            {
                DnevnikWork workDnevnik = new DnevnikWork((keyAccess == "" ? Properties.Settings.Default.keyAccess : keyAccess));

                if (tables[TabMarks.SelectedIndex].startEdit == true)
                {
                    DialogResult rsl = MessageBox.Show("Сохранить таблицу в файл?\nТекущая таблица будет очищена перед вставкой оценок из ЭЖ.", "Сохранить?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                    if (rsl == DialogResult.Yes)
                    {
                        saveFile.PerformClick();
                    }
                }

                ResetClass rst = new ResetClass(tables[TabMarks.SelectedIndex], tables[TabMarks.SelectedIndex].marks);
                ApiDiary   api = new ApiDiary(keyAccess == "" ? Properties.Settings.Default.keyAccess : keyAccess);

                long personId = ((JObject)JsonConvert.DeserializeObject(api.GetContext()))["personId"].Value <long>();
                var  groups   = workDnevnik.GetAllGroups(workDnevnik.GetMembers());

                using SelectDataChildren criteriaForm = new SelectDataChildren(workDnevnik.GetMembers(groups, Properties.Settings.Default.marksClassmates), workDnevnik.GetMembers(), groups);
                criteriaForm.ShowDialog();

                if (criteriaForm.closeWindow)
                {
                    Status.Visible = true;

                    loadBar.Value = 20;
                    loadBar.Style = ProgressBarStyle.Marquee;
                    loadBar.MarqueeAnimationSpeed = 45;
                    TabMarks.Enabled = false;
                    LabelLoad.Text   = "Ожидайте пока программа вставит все оценки.";
                    Tools.Enabled    = false;
                    tables[TabMarks.SelectedIndex].marks.Enabled = false;

                    int indexTab = TabMarks.SelectedIndex;

                    var test = workDnevnik.GetAllGroups(workDnevnik.GetMembers());

                    SelectChildren children = new SelectChildren()
                    {
                        table     = tables[indexTab],
                        Reset     = rst,
                        EndDate   = criteriaForm.EndDate.Value,
                        StartDate = criteriaForm.StartDate.Value,
                        Member    = workDnevnik.GetMembers(workDnevnik.GetAllGroups(workDnevnik.GetMembers()), Properties.Settings.Default.marksClassmates)[criteriaForm.indexGroup][criteriaForm.indexChild],
                        group     = workDnevnik.GetAllGroups(workDnevnik.GetMembers())[criteriaForm.indexChildGroup][criteriaForm.indexGroup]
                    };

                    WorkBack                     = new BackgroundWorker(); //WorkBack.DoWork += (obj, ea) =>
                    WorkBack.DoWork             += (obj, ea) => workDnevnik.GetMarksDiary(children);
                    WorkBack.RunWorkerCompleted += (obj, ea) => WorkBack_RunWorkerCompleted(workDnevnik);
                    WorkBack.RunWorkerAsync();
                }
            }
            //catch (Exception ex) { MessageBox.Show("Непредвиденная ошибка!\nПопробуйте повторить попытку, поменять параметры или перезапустить программу!"); Clipboard.SetText(ex.Message); }
        }