/// <summary> /// Updates the database with the new information /// </summary> /// <param name="summaryNumber">The number of the summary</param> /// <param name="date">The date of the summary</param> /// <param name="text">The text of the summary</param> /// <param name="dbRowID">(Optional) The sumary ID in the database to be updated</param> /// <param name="filesToAdopt">(Optional) The list of files to be adopted</param> /// <param name="filesToRemove">(Optional) The list of files to be removed</param> /// <returns>The final status of the update.</returns> private bool UpdateDB(int summaryNumber, string date, string text, int dayHours, int dbRowID = 0, List <string> filesToAdopt = null, List <string> filesToRemove = null) { var functions = new functions(); string filesLoad = ""; this.summaryNumber = summaryNumber; if (filesToAdopt != null) { filesLoad = "&filesToAdopt=" + functions.Hash(JsonConvert.SerializeObject(filesToAdopt)); } if (filesToRemove != null) { filesLoad += "&filesToRemove=" + functions.Hash(JsonConvert.SerializeObject(filesToRemove)); } if (dbRowID > 0) { //editing a summary savePOSTdata += "&summaryID=" + dbRowID + "&workspaceID=" + storage.currentWorkspaceID + "&summaryNumber=" + summaryNumber + "&date=" + functions.Hash(date) + "&bodyText=" + functions.Hash(text) + "&dayHours=" + dayHours + filesLoad; using (loadingForm loadForm = new loadingForm(APISave)) { loadForm.ShowDialog(); } } else { // new summary savePOSTdata += "&summaryNumber=" + summaryNumber + "&date=" + functions.Hash(date) + "&bodyText=" + functions.Hash(text) + "&dayHours=" + dayHours + filesLoad; using (loadingForm loadForm = new loadingForm(APICreateSummary)) { loadForm.ShowDialog(); } } simpleServerResponse serverResponse; try { serverResponse = JsonConvert.DeserializeObject <simpleServerResponse>(jsonSaveResponse); } catch (Exception ex) { MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n " + jsonSaveResponse, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } if (!serverResponse.status && (serverResponse.errors != null || serverResponse.errors.Length > 0)) { MessageBox.Show(GlobalStrings.Error + ": " + serverResponse.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(serverResponse.status); }
private void userSettings_Load(object sender, EventArgs e) { Text = String.Format(GlobalStrings.UserSettings, storage.displayName); nameBox.Text = storage.displayName; using (loadingForm form = new loadingForm(getClass)) { form.ShowDialog(); } try { classResponse = JsonConvert.DeserializeObject <ClassInfo>(classRequest); if (classResponse.status) { foreach (ClassList list in classResponse.contents) { if (list.classID == storage.classID) { classNameBox.Text = list.className; break; } } } else { MessageBox.Show(GlobalStrings.CantGetClassInfo, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { } if (storage.isAdmin) { userTypeBox.Text = GlobalStrings.Administrator; } else { userTypeBox.Text = GlobalStrings.Student; } bigBarCheckBox.Checked = Properties.Settings.Default.bigBar; }
private void loginBTN_Click(object sender, EventArgs e) { simpleServerResponse response; userInfo userInfo; var functions = new functions(); try { if (string.IsNullOrEmpty(usernameBox.Text) || string.IsNullOrEmpty(passwordBox.Text)) { credentialsWarningLB.Visible = true; } else { string username = functions.Hash(usernameBox.Text); string password = functions.Hash(passwordBox.Text); POSTdata = "usrnm=" + username + "&psswd=" + password; using (loadingForm loading = new loadingForm(getInformation)) { loading.ShowDialog(); } if (shouldAbort) { passwordBox.Clear(); password = ""; } else { response = JsonConvert.DeserializeObject <simpleServerResponse>(jsonResponse); if (response.status) { userInfo = JsonConvert.DeserializeObject <userInfo>(jsonResponse); storage.AccessToken = userInfo.AccessToken; storage.userID = userInfo.userID; storage.username = userInfo.username; storage.classID = userInfo.classID; storage.displayName = userInfo.displayName; storage.isAdmin = userInfo.adminControl; main form = new main(); this.Hide(); form.Show(); } else { if (response.errors == "Authentication Failed") { credentialsWarningLB.Visible = true; } else { MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } catch (Exception ex) { if (functions.CheckForInternetConnection(storage.inUseDomain)) { MessageBox.Show(GlobalStrings.CriticalError + ": " + ex.Message + "\n" + ex.StackTrace, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void WorkspaceConfigForm_Load(object sender, EventArgs e) { DataGridViewTextBoxColumn className = new DataGridViewTextBoxColumn(); className.Name = "className"; className.HeaderText = AdministrationMenuStrings.ClassName; className.ReadOnly = true; hoursDataGridView.Columns.Add(className); NumericUpDownColumn column = new NumericUpDownColumn(); column.Name = "totalHours"; column.HeaderText = WorkspaceConfigFormStrings.TotalHours; column.ReadOnly = false; hoursDataGridView.Columns.Add(column); DataGridViewButtonColumn removeBTN = new DataGridViewButtonColumn(); removeBTN.HeaderText = ""; removeBTN.Name = "removeBTN"; hoursDataGridView.Columns.Add(removeBTN); using (loadingForm loading = new loadingForm(RequestAllData)) { loading.ShowDialog(); } try { classResponse = JsonConvert.DeserializeObject <classServerResponse>(classRequest); allWorkspacesList = JsonConvert.DeserializeObject <workspacesServerResponse>(allWorkspacesRequest); if (classResponse.status) { if (classResponse.contents.Count < 1) { MessageBox.Show(WorkspaceConfigFormStrings.ClassesNotFound, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } else { if (allWorkspacesList.status) { foreach (classContent Class in classResponse.contents) { classesCB.Items.Add(Class.className); } } else { MessageBox.Show(GlobalStrings.Error + ": " + allWorkspacesList.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(); } if (sentWorkspaceID != 0) { using (loadingForm loading = new loadingForm(RequestWorkspaceData)) { loading.ShowDialog(); } try { workspaceResponse = JsonConvert.DeserializeObject <workspacesServerResponse>(workspaceRequest); if (workspaceResponse.status) { if (workspaceResponse.contents.Count != 1) { MessageBox.Show(GlobalStrings.GotMoreThanOneEntry, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } else { this.Text = String.Format(WorkspaceConfigFormStrings.FormTitle, workspaceResponse.contents[0].workspaceName); WorkspaceNameTOPBox.Text = workspaceResponse.contents[0].workspaceName; workspaceNameTB.Text = workspaceResponse.contents[0].workspaceName; readCheck.Checked = workspaceResponse.contents[0].read; writeCheck.Checked = workspaceResponse.contents[0].write; if (workspaceResponse.contents[0].hours != null) { foreach (hoursContent item in workspaceResponse.contents[0].hours) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell TBcell = new DataGridViewTextBoxCell(); TBcell.Value = classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className; classesCB.Items.Remove(classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className); NumericUpDownCell NumUpDownCell = new NumericUpDownCell(); NumUpDownCell.Value = item.totalHours; DataGridViewButtonCell BTNCell = new DataGridViewButtonCell(); BTNCell.Tag = classResponse.contents.FindIndex(x => x.classID == item.classID); BTNCell.Value = WorkspaceConfigFormStrings.RemoveBTN; row.Cells.Add(TBcell); row.Cells.Add(NumUpDownCell); row.Cells.Add(BTNCell); hoursDataGridView.Rows.Add(row); } } } } else { MessageBox.Show(GlobalStrings.Error + ": " + workspaceResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } catch (Exception ex) { MessageBox.Show("Workspace Response: " + workspaceResponse + "\n" + "Workspace Request:" + workspaceRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } } else { this.Text = WorkspaceConfigFormStrings.NewWorkspaceTitle; WorkspaceNameTOPBox.Text = WorkspaceConfigFormStrings.NewWorkspace; } }
private void okBTN_Click(object sender, EventArgs e) { if (!isAnyFieldEmpty()) { if (hoursDataGridView.Rows.Count == 0) { MessageBox.Show(WorkspaceConfigFormStrings.NoClassHoursAssignedWarning, WorkspaceConfigFormStrings.NoClassHours, MessageBoxButtons.OK, MessageBoxIcon.Information); readCheck.Checked = false; writeCheck.Checked = false; } craftData = "workspaceName=" + workspaceNameTB.Text + "&readMode=" + readCheck.Checked.ToString() + "&writeMode=" + writeCheck.Checked.ToString() + "&JSONString=" + functions.Hash(JsonConvert.SerializeObject(hoursControl)); if (!allWorkspacesList.contents.Exists(x => x.workspaceName == workspaceNameTB.Text && x.id != sentWorkspaceID)) { if (sentWorkspaceID != 0) // 0 -> new class. != 0 -> class being edited { if (wasAnyFieldModified()) { using (loadingForm loading = new loadingForm(UpdateWorkspaceData)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { changesHandled = true; cancelBTN_Click(sender, e); } } else { using (loadingForm loading = new loadingForm(CreateNewWorkspace)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(WorkspaceConfigFormStrings.WorkspaceNameInUse, WorkspaceConfigFormStrings.WorkspaceNameInUseShort, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void summariesList_Load(object sender, EventArgs e) { summarizedHoursHolder.Text = "0"; // must set it to 0 here otherwise, if the workspace is clear, the number of summarized hours will be the last loaded one // Requests the Workspace list, showing the loading screen to the user using (loadingForm form = new loadingForm(requestWorkpaceList)) { form.ShowDialog(); } if (shouldAbort) { this.Close(); } else { try { workspaceResponse = JsonConvert.DeserializeObject <workspacesServerResponse>(jsonResponse); if (workspaceResponse.status) { if (workspaceResponse.contents == null || !workspaceResponse.contents.Exists(x => x.hours.Exists(y => y.classID == storage.classID))) { storage.currentWorkspaceID = 0; MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); } else { workspaceComboBox.Items.Clear(); foreach (workspacesContent row in workspaceResponse.contents) { if (row.hours != null) { if (row.read && row.hours.Exists(x => x.classID == storage.classID)) { workspaceComboBox.Items.Add(row.workspaceName); } } } if (workspaceComboBox.Items.Count == 0) { // If there are no workspaces with read permission, show warning to user and close dialog storage.currentWorkspaceID = 0; MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); } else { int totalWorkspaceHours = 0; if (workspaceName == null || workspaceName == string.Empty || workspaceName == "") { int index = workspaceResponse.contents.FindIndex(x => x.read == true && x.hours.Exists(c => c.classID == storage.classID)); workspaceSelectedID = workspaceResponse.contents[index].id; workspaceName = workspaceResponse.contents[index].workspaceName; workspaceComboBox.SelectedItem = workspaceName; totalWorkspaceHours = workspaceResponse.contents[index].hours[workspaceResponse.contents[index].hours.FindIndex(x => x.classID == storage.classID)].totalHours; totalHoursHolder.Text = totalWorkspaceHours.ToString(); } else { int workspaceIndex = workspaceResponse.contents.FindIndex(x => x.workspaceName == workspaceName); workspaceSelectedID = workspaceResponse.contents[workspaceIndex].id; totalWorkspaceHours = workspaceResponse.contents[workspaceIndex].hours[workspaceResponse.contents[workspaceIndex].hours.FindIndex(x => x.classID == storage.classID)].totalHours; totalHoursHolder.Text = totalWorkspaceHours.ToString(); workspaceComboBox.SelectedItem = workspaceName; } storage.currentWorkspaceID = workspaceSelectedID; try { using (loadingForm form = new loadingForm(requestSummaryList)) { form.ShowDialog(); } response = JsonConvert.DeserializeObject <serverResponse>(jsonResponse); if (response.status) { int summarizedHours = 0; dataGrid.Rows.Clear(); dataGrid.Refresh(); if (response.contents != null) { dataGrid.ColumnCount = 3; dataGrid.Columns[0].Name = "date"; dataGrid.Columns[0].HeaderText = summariesListStrings.Date; dataGrid.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGrid.Columns[1].Name = "summaryNumber"; dataGrid.Columns[1].HeaderText = "#"; dataGrid.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; dataGrid.Columns[2].Name = "contents"; dataGrid.Columns[2].HeaderText = summariesListStrings.Summary; dataGrid.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGrid.AllowUserToDeleteRows = false; dataGrid.AllowUserToAddRows = false; dataGrid.MultiSelect = false; //just to reinforce var rows = new List <string[]>(); foreach (Content content in response.contents) { string[] row1 = new string[] { content.date.ToString(), content.summaryNumber.ToString(), content.bodyText.ToString() }; summarizedHours += content.dayHours; rows.Add(row1); } foreach (string[] rowArray in rows) { dataGrid.Rows.Add(rowArray); } dataGrid.Sort(this.dataGrid.Columns[0], Properties.Settings.Default.summaryOrderDate); double daysLeft = 0; daysLeft = (totalWorkspaceHours - summarizedHours) / 7; summarizedHoursHolder.Text = summarizedHours.ToString(); hoursRemainingHolder.Text = (totalWorkspaceHours - summarizedHours).ToString() + " " + String.Format(GlobalStrings.DaysRemaining, Math.Round(daysLeft)); } else { hoursRemainingHolder.Text = totalWorkspaceHours.ToString() + " " + String.Format(GlobalStrings.DaysRemaining, Math.Round((double)totalWorkspaceHours / 7)); } } else { MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { functions functions = new functions(); if (!functions.CheckForInternetConnection(storage.inUseDomain)) { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(GlobalStrings.CriticalError + ": " + ex.Message + "\n" + jsonResponse + "\n" + ex.StackTrace, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } else { MessageBox.Show(GlobalStrings.Error + ": " + workspaceResponse.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } } catch (Exception ex) { functions functions = new functions(); if (!functions.CheckForInternetConnection(storage.inUseDomain)) { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + jsonResponse + "\n" + ex.StackTrace, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void okBTN_Click(object sender, EventArgs e) { if (!isAnyFieldEmpty()) { craftData = "username="******"&displayName=" + displayNameTB.Text + "&classID=" + classResponse.contents[classResponse.contents.FindIndex(x => x.className == classCB.SelectedItem.ToString())].classID + "&isAdmin=" + isAdminCheck.Checked.ToString() + "&isDeletionProtected=" + isDeletionProtectedCheck.Checked.ToString(); if (!allUsersList.contents.Exists(x => x.user == loginNameTB.Text && x.userid != sentUserID)) { if (sentUserID != 0) // 0 -> new user. != 0 -> user being edited { if (wasAnyFieldModified()) { using (loadingForm loading = new loadingForm(UpdateUserData)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { changesHandled = true; cancelBTN_Click(sender, e); } } else { using (loadingForm loading = new loadingForm(CreateNewUser)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(UserConfigFormStrings.LoginNameInUse, UserConfigFormStrings.LoginNameInUseShort, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
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 okBTN_Click(object sender, EventArgs e) { errorProvider.SetError(classNameTB, ""); // Clears errors if (!string.IsNullOrEmpty(classNameTB.Text) || !string.IsNullOrWhiteSpace(classNameTB.Text)) { craftData = "className=" + classNameTB.Text; if (!allClassesList.contents.Exists(x => x.className == classNameTB.Text && x.classID != sentClassID)) { if (sentClassID != 0) // 0 -> new class. != 0 -> class being edited { if (classNameTB.Text != classResponse.contents[0].className) { using (loadingForm loading = new loadingForm(UpdateClassData)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { changesHandled = true; cancelBTN_Click(sender, e); } } else { using (loadingForm loading = new loadingForm(CreateNewClass)) { loading.ShowDialog(); } try { saveResponse = JsonConvert.DeserializeObject <simpleServerResponse>(saveRequest); if (saveResponse.status) { changesHandled = true; cancelBTN_Click(sender, e); } else { MessageBox.Show(GlobalStrings.Error + ": " + saveResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Response: " + saveResponse + "\n" + "Request:" + saveRequest + "\n" + "Error: " + ex.Message + "\n" + "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(ClassConfigFormStrings.ClassNameInUse, ClassConfigFormStrings.ClassNameInUseShort, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { errorProvider.SetIconPadding(classNameTB, -20); errorProvider.SetError(classNameTB, GlobalStrings.MandatoryField); } }
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(); } }