private void Login_Click(object sender, EventArgs e) { try { ApiDiary api = new ApiDiary(UserName.Text, Password.Text); if (memberCred.Checked) { Properties.Settings.Default.keyAccess = api.GetAccessToken(); Properties.Settings.Default.Save(); } else { keyAccess = api.GetAccessToken(); } MessageBox.Show("Успешный вход!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); closedSuccess = true; this.Close(); } catch (Exception a) { MessageBox.Show(a.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private LoginReturn CheckLoginInDnevnik() { string keyAccess = ""; bool closedSuccess = false; if (Properties.Settings.Default.keyAccess != "") { try { ApiDiary api = new ApiDiary(Properties.Settings.Default.keyAccess); closedSuccess = true; } catch { using LoginDnevnik loginForm = new LoginDnevnik(); loginForm.ShowDialog(); keyAccess = loginForm.keyAccess; closedSuccess = loginForm.closedSuccess; } } else { using LoginDnevnik loginForm = new LoginDnevnik(); loginForm.ShowDialog(); keyAccess = loginForm.keyAccess; closedSuccess = loginForm.closedSuccess; } return(new LoginReturn() { closedSuccess = closedSuccess, keyAccess = keyAccess }); }
public Analytics(ApiDiary api) => this.api = api;
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); } }