private void menuAboutLicenses_Click(object sender, EventArgs e) { try { System.Diagnostics.Process.Start(Path.GetTempPath() + "summariesTemp\\licenses.txt"); } catch (System.ComponentModel.Win32Exception) { try { using (var client = new WebClient()) { client.DownloadFile(storage.inUseDomain + "/summaries/resources/licenses.txt", Path.GetTempPath() + "summariesTemp\\licenses.txt"); } menuAboutLicenses_Click(sender, e); } catch (Exception ex) { var functions = new codeResources.functions(); 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 APISave() { var functions = new codeResources.functions(); try { jsonSaveResponse = functions.APIRequest("PUT", savePOSTdata, "user/" + storage.userID + "/summary/" + response.contents[response.contents.FindIndex(x => x.workspaceID == storage.currentWorkspaceID && x.summaryNumber == summaryNumber)].ID); } catch { // Work arround if the user is trying to save a summary with a different number on a date that is already in-use jsonSaveResponse = functions.APIRequest("PUT", savePOSTdata, "user/" + storage.userID + "/summary/" + response.contents[response.contents.FindIndex(x => x.workspaceID == storage.currentWorkspaceID && x.date == dateBox.Value.ToString("yyyy-MM-dd"))].ID); } }
private void menuSummaryNew_Click(object sender, EventArgs e) { var functions = new codeResources.functions(); if (functions.CheckForInternetConnection(storage.inUseDomain)) { newSummary newSummary = new newSummary(); newSummary.ShowDialog(); } else { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void menuOptionsAdministration_Panel_Click(object sender, EventArgs e) { var functions = new codeResources.functions(); if (functions.CheckForInternetConnection(storage.inUseDomain)) { administration.AdministrationMenu panel = new administration.AdministrationMenu(); panel.ShowDialog(); } else { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void checkConnection() { var functions = new codeResources.functions(); if (functions.CheckForInternetConnection(storage.inUseDomain)) { POSTdata = "oldpasswd=" + functions.Hash(currentPasswordBox.Text) + "&newpasswd=" + functions.Hash(newPasswordBox.Text); jsonResponse = functions.APIRequest("PUT", POSTdata, "user/" + storage.userID + "/changepassword"); } else { shouldAbort = true; MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void changeBTN_Click(object sender, EventArgs e) { if (currentPasswordBox.Text.Length < 1 || newPasswordBox.Text.Length < 1 || confirmPasswordBox.Text.Length < 1) { MessageBox.Show(GlobalStrings.EmptyFieldsText, GlobalStrings.EmptyFields, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (newPasswordBox.Text == confirmPasswordBox.Text) { if (newPasswordBox.Text != currentPasswordBox.Text) { var functions = new codeResources.functions(); try { using (codeResources.loadingForm form = new codeResources.loadingForm(checkConnection)) { form.ShowDialog(); } if (shouldAbort) { this.Close(); } else { response = JsonConvert.DeserializeObject <simpleServerResponse>(jsonResponse); if (!response.status) { if ((response.errors == null) || (response.errors.Length < 1)) { currentPasswordBox.Clear(); MessageBox.Show(GlobalStrings.IncorrectCurrentPassword, GlobalStrings.PasswordIncorrect, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(GlobalStrings.PasswordChangedSuccess, GlobalStrings.PasswordChanged, MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace + "\n" + jsonResponse, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { resetFields(); MessageBox.Show(GlobalStrings.OldPasswordSameAsNew, GlobalStrings.CannotChangeSamePassword, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { resetFields(); MessageBox.Show(GlobalStrings.NewPasswordMismatch, GlobalStrings.PasswordsDontMatch, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void attachmentsGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { var functions = new codeResources.functions(); try { // https://stackoverflow.com/questions/3577297/how-to-handle-click-event-in-button-column-in-datagridview var senderGrid = (DataGridView)sender; bool done = false; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { string fileName = attachmentsGridView.Rows[e.RowIndex].Cells[e.ColumnIndex - 1].Value.ToString(); DialogResult response = MessageBox.Show(String.Format(newSummaryStrings.RemoveFileQuestion, fileName), newSummaryStrings.RemoveFile, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (response == DialogResult.Yes) { // Checks if he file is in the filesToAdd list. If the file is in there, it means that it was added just now and it is not on the server // If the file is not there, it means that the file is already on the server and has to be removed from there foreach (var file in filesToAdd) { if (file.Split('\\')[file.Split('\\').Length - 1] == fileName) { filesToAdd.Remove(file); done = true; break; } } if (!done) { filesToRemove.Add(fileName); } attachmentsGridView.Rows.RemoveAt(e.RowIndex); } } else { if (e.ColumnIndex == 0 && e.RowIndex >= 0) { // https://stackoverflow.com/questions/525364/how-to-download-a-file-from-a-website-in-c-sharp try { string cell = senderGrid.Rows[e.RowIndex].Cells[0].Value.ToString(); bool inServer = true; foreach (var file in filesToAdd) { if (file.Split('\\')[file.Split('\\').Length - 1] == cell) { inServer = false; break; } } if (inServer) { string fileExtension = cell.Substring(cell.Length - cell.Split('.')[cell.Split('.').Length - 1].Length); string finalPath = Path.GetTempPath() + "summariesTemp\\~summariestemp" + Path.GetRandomFileName().Replace('.', 'a') + "." + fileExtension; string inServerPath = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].attachments.Find(x => x.filename == cell).path; string inServerName = inServerPath.Split('/')[inServerPath.Split('/').Length - 1]; using (WebClient client = new WebClient()) { // https://stackoverflow.com/questions/6397235/write-bytes-to-file client.Headers.Add("HTTP-X-API-KEY", storage.AccessToken); byte[] response = client.DownloadData(storage.inUseDomain + "/summaries/api/v" + functions.GetSoftwareVersion()[0] + "/user/" + storage.userID + "/summary/" + this.response.contents[this.response.contents.FindIndex(x => x.workspaceID == storage.currentWorkspaceID && x.summaryNumber == summaryNumber)].ID + "/files/" + inServerName); try { var parse = JsonConvert.DeserializeObject <simpleServerResponse>(Encoding.UTF8.GetString(response)); if (parse.status == false) { MessageBox.Show(newSummaryStrings.ErrorDownloadingFile + "\n" + parse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch { // If we got here, it is probably because it is actually a file, so we'll just save it var fs = new FileStream(@"" + finalPath, FileMode.Create, FileAccess.Write); fs.Write(response, 0, response.Length); Process.Start(@"" + finalPath); } } } else { int index = filesToAdd.FindIndex(x => x.Contains(cell)); // finds the full path of the specifeid file. Returns an index to be used below Process.Start(@"" + filesToAdd[index]); } } catch (Exception ex) { MessageBox.Show(newSummaryStrings.CouldNotOpenFile + ": " + ex.Message + "\n" + ex.InnerException, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch { } }
private void newSummary_Load(object sender, EventArgs e) { contentsBox.Focus(); workspaceComboBox.Items.Clear(); var functions = new codeResources.functions(); using (codeResources.loadingForm form = new codeResources.loadingForm(APICalls)) { form.ShowDialog(); } if (shouldAbortLoad) { this.Close(); } else { try { response = JsonConvert.DeserializeObject <serverResponse>(jsonResponse); if (workspaces.contents == null) { storage.currentWorkspaceID = 0; MessageBox.Show(summariesListStrings.NoAvailableWorkspacesLong, summariesListStrings.NoAvailableWorkspaces, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); this.Close(); } else { foreach (workspacesContent content in workspaces.contents) { if (content.hours != null) { if (content.read && content.hours.Exists(x => x.classID == storage.classID)) { workspaceComboBox.Items.Add(content.workspaceName); } } } try { if (response.status) { //******* just to reinforce dateBox.CustomFormat = "yyyy-MM-dd"; dateBox.Format = DateTimePickerFormat.Custom; //******* just to reinforce if (summaryNumber != 0) { isEdit = true; } if (storage.currentWorkspaceID == 0) { // Workspace not defined yet workspaceComboBox.SelectedIndex = 0; storage.currentWorkspaceID = workspaces.contents[workspaces.contents.FindIndex(z => z.workspaceName == workspaceComboBox.Text)].id; } else { workspaceComboBox.SelectedItem = workspaces.contents[workspaces.contents.FindIndex(c => c.id == storage.currentWorkspaceID)].workspaceName; } if (isEdit) { this.Text = newSummaryStrings.EditSummary; summaryNumberBox.Value = summaryNumber; dateBox.Value = DateTime.ParseExact(response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].date, "yyyy-MM-dd", new CultureInfo("pt")); contentsBox.Text = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].bodyText; if (response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].dayHours == 0) { missedDayCheckBox.Checked = true; } else { dayHoursNumberBox.Value = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].dayHours; } originalText = functions.Hash(response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].bodyText); originalDate = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].date; originalWorkspaceID = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].workspaceID; originalSummaryID = summaryNumber; dbRow = response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].ID; if (response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].attachments != null) { foreach (var attach in response.contents[response.contents.FindIndex(x => x.summaryNumber == summaryNumber && x.workspaceID == storage.currentWorkspaceID)].attachments) { attachmentsGridView.Rows.Add(attach.filename, newSummaryStrings.RemoveBTN); } } } else { if (response.contents != null) { List <Content> workspaceRelated = new List <Content>(); foreach (Content row in response.contents) { if (row.workspaceID == storage.currentWorkspaceID) { workspaceRelated.Add(row); } } if (workspaceRelated.Count > 0) { summaryNumberBox.Value = workspaceRelated[workspaceRelated.Count - 1].summaryNumber + 1; } else { summaryNumberBox.Value = 1; } } else { summaryNumberBox.Value = 1; } dateBox.Value = DateTime.ParseExact(DateTime.Today.ToString("yyyy-MM-dd"), "yyyy-MM-dd", new CultureInfo("pt")); } if (!workspaces.contents[workspaces.contents.FindIndex(x => x.id == storage.currentWorkspaceID)].write) { readOnlyMode = true; workspaceComboBox.Enabled = false; summaryNumberBox.Enabled = false; dateBox.Enabled = false; contentsBox.ReadOnly = true; attachmentsGridView.ReadOnly = true; addAttachmentBTN.Enabled = false; saveBTN.Enabled = false; } } else { MessageBox.Show(GlobalStrings.Error + ": " + response.errors, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + ex.StackTrace + "\n" + jsonResponse, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { if (!functions.CheckForInternetConnection(storage.inUseDomain)) { MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(GlobalStrings.Error + ": " + ex.Message + "\n" + jsonWorkspace + "\n" + ex.StackTrace + "\n" + ex.InnerException, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void APICreateSummary() { var functions = new codeResources.functions(); jsonSaveResponse = functions.APIRequest("POST", savePOSTdata, "user/" + storage.userID + "/workspace/" + storage.currentWorkspaceID + "/summary"); }