private void APICalls() { var functions = new functions(); if (functions.CheckForInternetConnection(storage.inUseDomain)) { jsonWorkspace = functions.APIRequest("GET", null, "workspace"); workspaces = JsonConvert.DeserializeObject <workspacesServerResponse>(jsonWorkspace); // this should get all the user's summaries, independently of the workspace jsonResponse = functions.APIRequest("GET", null, "user/" + storage.userID + "/workspace/0/summary"); } else { shouldAbortLoad = true; 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 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); } } } }