Exemple #1
0
 private void changePassword_Load(object sender, EventArgs e)
 {
     using (codeResources.loadingForm form = new codeResources.loadingForm(checkConnection))
     {
         form.ShowDialog();
     }
     this.Text       += storage.displayName;
     usernameBox.Text = storage.username;
 }
Exemple #2
0
        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 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);
                    }
                }
            }
        }