Ejemplo n.º 1
0
        private void editSummary_Click(object sender, EventArgs e)
        {
            try
            {
                if (dataGrid.SelectedRows.Count > 0 || dataGrid.SelectedCells.Count > 0)
                {
                    int             selectedrowindex = dataGrid.SelectedCells[0].RowIndex;
                    DataGridViewRow selectedRow      = dataGrid.Rows[selectedrowindex];
                    int             selectedSummary  = Convert.ToInt32(selectedRow.Cells["summaryNumber"].Value);

                    newSummary editSummary = new newSummary(selectedSummary);
                    editSummary.ShowDialog();
                    summariesList_Load(sender, e);
                }
            }
            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, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        private void deleteSummary_Click(object sender, EventArgs e)
        {
            if (workspaceResponse.contents[workspaceResponse.contents.FindIndex(x => x.workspaceName == workspaceName)].write)
            {
                try
                {
                    if (dataGrid.SelectedRows.Count > 0 || dataGrid.SelectedCells.Count > 0)
                    {
                        DialogResult boxResponse = MessageBox.Show(summariesListStrings.DeleteSummaryQuestion, summariesListStrings.DeleteSummary, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (boxResponse == DialogResult.Yes)
                        {
                            int             selectedrowindex = dataGrid.SelectedCells[0].RowIndex;
                            DataGridViewRow selectedRow      = dataGrid.Rows[selectedrowindex];
                            int             selectedSummary  = Convert.ToInt32(selectedRow.Cells["summaryNumber"].Value);

                            string jsonResponse = functions.APIRequest("DELETE", null, "user/" + storage.userID + "/summary/" + response.contents[response.contents.FindIndex(x => x.summaryNumber == selectedSummary && x.workspaceID == storage.currentWorkspaceID)].ID);

                            simpleServerResponse serverResponse;

                            serverResponse = JsonConvert.DeserializeObject <simpleServerResponse>(jsonResponse);

                            if (serverResponse.status)
                            {
                                summariesList_Load(sender, e);
                            }
                            else
                            {
                                if (serverResponse.errors == null || serverResponse.errors.Length < 1)
                                {
                                    MessageBox.Show(summariesListStrings.RowNotExistLong, summariesListStrings.RowDoesNotExist, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    summariesList_Load(sender, e);
                                }
                                else
                                {
                                    MessageBox.Show(GlobalStrings.Error + ": " + serverResponse.errors + "\n" + jsonResponse, 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.Error + ": " + ex.Message + "\n" + ex.StackTrace + "\n" + ex.Source, GlobalStrings.CriticalError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show(summariesListStrings.ReadOnlyWorkspace, summariesListStrings.ReadOnly, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Ejemplo n.º 3
0
        private void getInformation()
        {
            var functions = new functions();

            if (functions.CheckForInternetConnection(storage.inUseDomain))
            {
                jsonResponse = functions.APIRequest("POST", POSTdata, "login");
            }
            else
            {
                shouldAbort = true;
                MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        private void requestSummaryList()
        {
            var functions = new functions();

            if (functions.CheckForInternetConnection(storage.inUseDomain))
            {
                jsonResponse = functions.APIRequest("GET", null, "user/" + storage.userID + "/workspace/" + storage.currentWorkspaceID + "/summary");
            }
            else
            {
                shouldAbort = true;
                MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Upload the specified files and adopts them
        /// </summary>
        /// <see cref="https://stackoverflow.com/questions/10237983/upload-to-php-server-from-c-sharp-client-application"/>
        /// <param name="files">List of files to upload</param>
        /// <param name="summaryNumber">Current Summary ID</param>
        /// <returns>List of files to be adopted</returns>
        private List <string> UploadFiles(List <String> filesToUpload)
        {
            var           functions    = new functions();
            List <string> filesToAdopt = new List <string>();

            try
            {
                foreach (string currentFile in filesToUpload)
                {
                    WebClient Client = new WebClient();
                    Client.Headers.Add("Content-Type", "binary/octet-stream");
                    Client.Headers.Add("HTTP-X-API-KEY", storage.AccessToken);
                    byte[] result = Client.UploadFile(storage.inUseDomain + "/summaries/api/v" + functions.GetSoftwareVersion()[0] + "/user/" + storage.userID + "/uploadfile", "POST", currentFile);

                    string response = Encoding.UTF8.GetString(result, 0, result.Length);
                    uploadResults = JsonConvert.DeserializeObject <uploadInfo>(response);

                    if (uploadResults.status)
                    {
                        filesToAdopt.Add(uploadResults.rowID);
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + uploadResults.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(null);
                    }
                }
                return(filesToAdopt);
            }
            catch (WebException ex)
            {
                if (functions.CheckForInternetConnection(storage.inUseDomain))
                {
                    using (var stream = ex.Response.GetResponseStream())
                        using (var reader = new StreamReader(stream))
                        {
                            MessageBox.Show("Response: " + reader.ReadToEnd() + "\n" +
                                            "Error: " + ex.Message, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                }
                else
                {
                    MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return(null);
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
 private void addSummary_Click(object sender, EventArgs e)
 {
     if (workspaceResponse.contents[workspaceResponse.contents.FindIndex(x => x.workspaceName == workspaceName)].write)
     {
         functions functions = new functions();
         if (!functions.CheckForInternetConnection(storage.inUseDomain))
         {
             MessageBox.Show(GlobalStrings.ConnectionToServerLost, GlobalStrings.ConnectionLost, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         else
         {
             newSummary newSummary = new newSummary();
             newSummary.ShowDialog();
             summariesList_Load(sender, e);
         }
     }
     else
     {
         MessageBox.Show(summariesListStrings.ReadOnlyWorkspace, summariesListStrings.ReadOnly, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
0
        private void loading_Shown(object sender, EventArgs e)
        {
            Local_Storage storage   = Local_Storage.Retrieve;
            var           functions = new functions();

            if (!functions.CheckForInternetConnection("http://google.com/generate_204"))
            {
                MessageBox.Show(GlobalStrings.NoInternetLong, GlobalStrings.NoInternet, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }
            else
            {
                if (String.IsNullOrEmpty(Properties.Settings.Default.serverURL) || String.IsNullOrWhiteSpace(Properties.Settings.Default.serverURL))
                {
                    ServerInput config = new ServerInput();
                    config.ShowDialog();
                }

                if (!functions.CheckForInternetConnection(Properties.Settings.Default.serverURL))
                {
                    MessageBox.Show(GlobalStrings.CannotConnectServerLong, GlobalStrings.CannotConnectServer, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
                else
                {
                    storage.inUseDomain = Properties.Settings.Default.serverURL;
                }

                Directory.CreateDirectory(@"" + Path.GetTempPath() + "summariesTemp");

                try
                {
                    using (var client = new WebClient())
                    {
                        client.DownloadFile(storage.inUseDomain + "/summaries/resources/licenses.txt", Path.GetTempPath() + "summariesTemp\\licenses.txt");
                    }

                    string        downloadURL = "";
                    Version       newVersion  = null;
                    string        xmlURL      = storage.inUseDomain + "/summaries/updater.xml";
                    XmlTextReader reader      = null;

                    reader = new XmlTextReader(xmlURL);
                    reader.MoveToContent();
                    string elementName = "";

                    try
                    {
                        if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "summariesapp"))
                        {
                            while (reader.Read())
                            {
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    elementName = reader.Name;
                                }
                                else
                                {
                                    if ((reader.NodeType == XmlNodeType.Text) && (reader.HasValue))
                                    {
                                        switch (elementName)
                                        {
                                        case "version":
                                            newVersion = new Version(reader.Value);
                                            break;

                                        case "downloadurl":
                                            downloadURL = reader.Value;
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exec)
                    {
                        throw new Exception(GlobalStrings.FailedCheckUpdates + ": " + exec.Message);
                    }
                    finally
                    {
                        if (reader != null)
                        {
                            reader.Close();
                        }
                    }

                    Version appVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
                    if (appVersion.CompareTo(newVersion) < 0)
                    {
                        var res = MessageBox.Show(GlobalStrings.NewVersionLong, GlobalStrings.NewVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (res == DialogResult.Yes)
                        {
                            System.Diagnostics.Process.Start(downloadURL);
                            Application.Exit();
                        }
                        else
                        {
                            MessageBox.Show(GlobalStrings.LaunchOnLatestVersion, GlobalStrings.Closing, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Application.Exit();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, GlobalStrings.CouldNotLoadResources, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
                login loginForm = new login();
                this.Close();
                loginForm.Show();
            }
        }
Ejemplo n.º 10
0
        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);
                    }
                }
            }
        }