public Document CreateDocument(int workspaceID) { try { workspaceResponse = JsonConvert.DeserializeObject <workspaceServerResponse>(func.APIRequest("GET", null, "workspace/" + workspaceID)); if (workspaceResponse.status) { if (workspaceResponse.contents[0].hours != null) { userResponse = JsonConvert.DeserializeObject <userServerResponse>(func.APIRequest("GET", null, "user")); if (userResponse.status) { classResponse = JsonConvert.DeserializeObject <classServerResponse>(func.APIRequest("GET", null, "class")); if (classResponse.status) { workspaceHoursResponse = JsonConvert.DeserializeObject <workspaceHoursServerResponse>(func.APIRequest("GET", null, "workspace/" + workspaceID + "/summarizedHours")); if (workspaceHoursResponse.status) { // Create a new MigraDoc document. _document = new Document(); _document.Info.Title = GenerateReportStrings.DocumentType + " - " + workspaceResponse.contents[0].workspaceName; _document.Info.Author = storage.displayName + " (Summaries)"; DefineStyles(); foreach (hours item in workspaceResponse.contents[0].hours) { CreatePage(classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className); FillContent(item.classID); } return(_document); } else { throw new Exception(GlobalStrings.Error + ": " + workspaceHoursResponse.errors); } } else { throw new Exception(GlobalStrings.Error + ": " + classResponse.errors); } } else { throw new Exception(GlobalStrings.Error + ": " + userResponse.errors); } } else { throw new Exception(GlobalStrings.Error + ": " + GenerateReportStrings.NoClassesAssociated); } } else { throw new Exception(GlobalStrings.Error + ": " + workspaceResponse.errors); } } catch (Exception ex) { throw new Exception(ex.Message + "\n" + ex.StackTrace, ex.InnerException); } }
public Document CreateDocument(int?userID = null, int?classID = null, int?workspaceID = null) { if (userID == null || classID == null || workspaceID == null) { userID = storage.userID; classID = storage.classID; classID_g = storage.classID; workspaceID = storage.currentWorkspaceID; studentName_g = storage.displayName; } else { if (userID < 1 || classID < 0 || workspaceID < 0) { throw new Exception("The userID, classID and workspaceID parameters have to be greater than 0. No document was generated."); } else { userResponse = JsonConvert.DeserializeObject <userServerResponse>(func.APIRequest("GET", null, "user/" + userID)); if (userResponse.status) { classID_g = userResponse.contents[0].classID; studentName_g = userResponse.contents[0].displayName; } else { throw new Exception(GlobalStrings.Error + ": " + userResponse.errors); } } } try { summariesResponse = JsonConvert.DeserializeObject <summariesServerResponse>(func.APIRequest("GET", null, "user/" + userID + "/workspace/" + workspaceID + "/summary")); if (summariesResponse.status) { classResponse = JsonConvert.DeserializeObject <classServerResponse>(func.APIRequest("GET", null, "class/" + classID)); if (classResponse.status) { workspaceResponse = JsonConvert.DeserializeObject <workspaceServerResponse>(func.APIRequest("GET", null, "workspace/" + workspaceID)); if (workspaceResponse.status) { // Create a new MigraDoc document. _document = new Document(); _document.Info.Title = GenerateSummaryExportStrings.DocumentType + " - " + studentName_g; _document.Info.Author = storage.displayName + " (Summaries)"; DefineStyles(); CreatePage(); FillContent(); return(_document); } else { throw new Exception(GlobalStrings.Error + ": " + workspaceResponse.errors); } } else { throw new Exception(GlobalStrings.Error + ": " + classResponse.errors); } } else { throw new Exception(GlobalStrings.Error + ": " + summariesResponse.errors); } } catch (Exception ex) { throw new Exception(ex.Message, ex.InnerException); } }
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; } }