private void UserConfigForm_Load(object sender, EventArgs e) { using (loadingForm loading = new loadingForm(GetAllUsers)) { loading.ShowDialog(); } allUsersList = JsonConvert.DeserializeObject <usersServerResponse>(allUsersRequest); if (allUsersList.status) { if (sentUserID != 0) { using (loadingForm loading = new loadingForm(RequestUserData)) { loading.ShowDialog(); } try { response = JsonConvert.DeserializeObject <usersServerResponse>(request); if (response.status) { if (response.contents.Count != 1) { MessageBox.Show(GlobalStrings.GotMoreThanOneEntry, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } else { classResponse = JsonConvert.DeserializeObject <classesServerResponse>(classRequest); if (classResponse.status) { // General tab usersContent user = response.contents[0]; foreach (var x in classResponse.contents) { classCB.Items.Add(x.className); } this.Text = String.Format(UserConfigFormStrings.FormTitle, user.displayName); UsernameTOPBox.Text = user.displayName; displayNameTB.Text = user.displayName; loginNameTB.Text = user.user; classCB.SelectedItem = classResponse.contents[classResponse.contents.FindIndex(x => x.classID == user.classID)].className; classID_g = user.classID; isAdminCheck.Checked = user.isAdmin; isDeletionProtectedCheck.Checked = user.isDeletionProtected; // Workspaces tab workspacesDataGrid.Rows.Clear(); workspacesDataGrid.Columns.Clear(); workspacesDataGrid.AutoGenerateColumns = false; workspacesDataGrid.Refresh(); workspacesDataGrid.ColumnCount = 3; workspacesDataGrid.Columns[0].Name = "workspaceID"; workspacesDataGrid.Columns[0].HeaderText = "#"; workspacesDataGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; workspacesDataGrid.Columns[1].Name = "workspaceName"; workspacesDataGrid.Columns[1].HeaderText = UserConfigFormStrings.WorkspaceTab_Name; workspacesDataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; workspacesDataGrid.Columns[2].Name = "hours"; workspacesDataGrid.Columns[2].HeaderText = GenerateReportStrings.HoursWorked; workspacesDataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; workspacesDataGrid.MultiSelect = false; try { workspaceDataResponse = JsonConvert.DeserializeObject <workspacesDataResponse>(workspacesInfo); if (workspaceDataResponse.status) { if (workspaceDataResponse.contents == null) { workspacesDataGrid.Enabled = false; workspacesDataGrid.BackgroundColor = SystemColors.InactiveCaption; noDataLabel.Visible = true; } else { foreach (workspacesData data in workspaceDataResponse.contents) { string[] row = new string[] { data.workspace_ID.ToString(), data.workspace_Name.ToString(), data.hours_Completed.ToString() }; workspacesDataGrid.Rows.Add(row); } } } else { MessageBox.Show(GlobalStrings.Error + ":" + workspaceDataResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception wex) { MessageBox.Show(wex.Message + "\n" + wex.StackTrace, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(GlobalStrings.Error + ": " + classResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } } else { MessageBox.Show("Error: " + response.errors + "\n" + "ErrorCode: " + response.ErrorCode, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } catch (Exception ex) { Console.WriteLine(workspacesInfo); MessageBox.Show("Response: " + response + "\n" + "Request:" + request + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } else { this.Text = UserConfigFormStrings.NewUserProperties; UsernameTOPBox.Text = UserConfigFormStrings.NewUser; workspacesPage.Enabled = false; workspacesDataGrid.BackgroundColor = SystemColors.InactiveCaption; noDataLabel.Visible = true; using (loadingForm loading = new loadingForm(RequestClassesList)) { loading.ShowDialog(); } classResponse = JsonConvert.DeserializeObject <classesServerResponse>(classRequest); if (classResponse.status) { foreach (var x in classResponse.contents) { classCB.Items.Add(x.className); } classCB.SelectedIndex = 0; } else { MessageBox.Show(GlobalStrings.Error + ": " + classResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } } else { MessageBox.Show(GlobalStrings.Error + ": " + allUsersList.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }
private void ClassConfigForm_Load(object sender, EventArgs e) { using (loadingForm loading = new loadingForm(GetAllClasses)) { loading.ShowDialog(); } allClassesList = JsonConvert.DeserializeObject <classesServerResponse>(allClassesRequest); if (allClassesList.status) { if (sentClassID != 0) { using (loadingForm loading = new loadingForm(RequestClassData)) { loading.ShowDialog(); } try { classResponse = JsonConvert.DeserializeObject <classesServerResponse>(classRequest); if (classResponse.status) { if (classResponse.contents.Count != 1) { MessageBox.Show(GlobalStrings.GotMoreThanOneEntry, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } else { userResponse = JsonConvert.DeserializeObject <usersServerResponse>(userRequest); if (userResponse.status) { classesContent classes = classResponse.contents[0]; this.Text = String.Format(ClassConfigFormStrings.FormName, classes.className); ClassNameTOPBox.Text = classes.className; classNameTB.Text = classes.className; if (userResponse.contents != null) { usersOnThisClassGV.Enabled = true; usersOnThisClassGV.ReadOnly = true; foreach (var x in userResponse.contents) { int thisRowIndex = usersOnThisClassGV.Rows.Add(); usersOnThisClassGV.Rows[thisRowIndex].Cells["userLoginName"].Value = x.user; usersOnThisClassGV.Rows[thisRowIndex].Cells["userDisplayName"].Value = x.displayName; } } } else { MessageBox.Show(GlobalStrings.Error + ": " + userResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } } else { MessageBox.Show(GlobalStrings.Error + ": " + classResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } catch (Exception ex) { MessageBox.Show("Response: " + classResponse + "\n" + "Request:" + classRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } else { this.Text = ClassConfigFormStrings.NewClassProperties; ClassNameTOPBox.Text = ClassConfigFormStrings.NewClass; usersOnThisClassGV.Enabled = false; } } else { MessageBox.Show(GlobalStrings.Error + ": " + allClassesList.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }