예제 #1
0
        /// <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);
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
        private void saveBTN_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(contentsBox.Text) || filesToAdd.Count < 1 || filesToRemove.Count < 1)
            {
                this.Close();
            }

            bool shouldAbort = false;

            if (!isEdit)
            {
                bool isInList   = false;
                bool isDateUsed = false;
                try
                {
                    //checks if summary number is in use on this workspace
                    foreach (Content content in response.contents)
                    {
                        if (content.workspaceID == workspaces.contents[workspaces.contents.FindIndex(x => x.workspaceName == workspaceComboBox.SelectedItem.ToString())].id)
                        {
                            if (content.summaryNumber == Convert.ToInt32(summaryNumberBox.Value))
                            {
                                isInList = true;
                            }

                            if (content.date == dateBox.Value.ToString("yyyy-MM-dd"))
                            {
                                isDateUsed = true;
                            }
                        }
                    }
                }
                catch (NullReferenceException)
                {
                    isInList = false;
                }


                // Checks if the summary number is already in use
                if (isInList)
                {
                    var result = MessageBox.Show(newSummaryStrings.SummaryNumberInUseQuestion, newSummaryStrings.SummaryNumberInUse, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        isEdit = true;
                        dbRow  = response.contents[Convert.ToInt32(summaryNumberBox.Value) - 1].ID;
                    }
                    else
                    {
                        shouldAbort = true;
                    }
                }

                // Checks if the selected date is already in use by another summary
                if (isDateUsed && !shouldAbort)
                {
                    var res = MessageBox.Show(newSummaryStrings.DateInUseQuestion, newSummaryStrings.DateInUse, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (res == DialogResult.Yes)
                    {
                        isEdit = true;
                        dbRow  = response.contents[response.contents.FindIndex(w => w.date == dateBox.Value.ToString("yyyy-MM-dd"))].ID;
                    }
                    else
                    {
                        shouldAbort = true;
                    }
                }
            }

            var functions = new functions();

            if (!shouldAbort)
            {
                int dayHours = (missedDayCheckBox.Checked ? 0 : Convert.ToInt32(dayHoursNumberBox.Value));
                if (isEdit)
                {
                    if ((originalText != functions.Hash(contentsBox.Text)) || (originalDate != dateBox.Value.ToString("yyyy-MM-dd")) || (originalSummaryID != summaryNumberBox.Value) || dayHours != response.contents[response.contents.FindIndex(x => x.workspaceID == storage.currentWorkspaceID && x.summaryNumber == originalSummaryID)].dayHours || filesToAdd.Count > 0 || filesToRemove.Count > 0)
                    {
                        if (filesToAdd.Count > 0 || filesToRemove.Count > 0) // Checks if there are files to add or remove
                        {
                            if (filesToAdd.Count > 0)
                            {
                                List <string> filesToAdopt = new List <string>();
                                filesToAdopt = UploadFiles(filesToAdd);
                                if (filesToAdopt != null && filesToAdopt.Count > 0)
                                {
                                    // Here it saves the basic info about the current summary and uploads the files to the server
                                    if (UpdateDB(Convert.ToInt32(summaryNumberBox.Value), dateBox.Value.ToString("yyyy-MM-dd"), contentsBox.Text, dayHours, dbRow, filesToAdopt, filesToRemove))
                                    {
                                        this.Close();
                                    }
                                    else
                                    {
                                        MessageBox.Show(newSummaryStrings.ErrorSaveLong, newSummaryStrings.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show(newSummaryStrings.ErrorUploadLong, newSummaryStrings.ErrorUpload, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                // Here it saves the basic info about the current summary and uploads the files to the server
                                if (UpdateDB(Convert.ToInt32(summaryNumberBox.Value), dateBox.Value.ToString("yyyy-MM-dd"), contentsBox.Text, dayHours, dbRow, null, filesToRemove))
                                {
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show(newSummaryStrings.ErrorSaveLong, newSummaryStrings.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else // There isn't any kind of file operation to be performed
                        {
                            if (UpdateDB(Convert.ToInt32(summaryNumberBox.Value), dateBox.Value.ToString("yyyy-MM-dd"), contentsBox.Text, dayHours, dbRow))
                            {
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show(newSummaryStrings.ErrorSaveLong, newSummaryStrings.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        this.Close();
                    }
                }
                else
                {
                    // This is a new summary

                    if (filesToAdd.Count > 0) // Cheks if there are files to add
                    {
                        List <string> filesToAdopt = new List <string>();
                        filesToAdopt = UploadFiles(filesToAdd);
                        if (filesToAdopt != null && filesToAdopt.Count > 0)
                        {
                            // Here it saves the basic info about the current summary and uploads the files to the server
                            if (UpdateDB(Convert.ToInt32(summaryNumberBox.Value), dateBox.Value.ToString("yyyy-MM-dd"), contentsBox.Text, dayHours, 0, filesToAdopt))
                            {
                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show(newSummaryStrings.ErrorSaveLong, newSummaryStrings.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        else
                        {
                            MessageBox.Show(newSummaryStrings.ErrorUploadLong, newSummaryStrings.ErrorUpload, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        // Here it saves the basic info about the current summary and uploads the files to the server
                        if (UpdateDB(Convert.ToInt32(summaryNumberBox.Value), dateBox.Value.ToString("yyyy-MM-dd"), contentsBox.Text, dayHours))
                        {
                            this.Close();
                        }
                        else
                        {
                            MessageBox.Show(newSummaryStrings.ErrorSaveLong, newSummaryStrings.ErrorSave, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }