Example #1
0
        /// <summary>
        /// Handles a save request from the user by going to the
        /// ApplicationHelper with all the parameters and calling
        /// the save stored procedure.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveClaim_Button_Click(object sender, EventArgs e)
        {
            try
            {
                Console.WriteLine("Saving claim...");

                // Get the data into a list
                List <string> parameters = new List <string>()
                {
                    ApplicationHelper.GetCurrentUserName()
                };
                bool   raiseError   = false;
                string errorMessage = "";

                // Insert the PrimaryKey if it's being used
                if (!string.IsNullOrEmpty(MainWindowHelper.GetCellData("PMSPrimaryKey")))
                {
                    parameters.Add(MainWindowHelper.GetCellData("PMSPrimaryKey"));
                }

                foreach (Control control in ClaimForm.Controls)
                {
                    // If we are not looking at the data, move on
                    if (ClaimForm.GetColumn(control) != 2)
                    {
                        continue;
                    }

                    // Clear any highlights
                    control.BackColor = Color.White;

                    // Parameter to add
                    string parameter = "";

                    // Add all the parameters to the list
                    // Handle the positive negative dropdown of trxAmount
                    Control previousControl = ClaimForm.Controls[ClaimForm.Controls.IndexOf(control) - 1];
                    if (ClaimForm.GetColumn(previousControl) == 1 && previousControl.Text.Equals("-"))
                    {
                        parameter = previousControl.Text + control.Text;
                    }
                    else if (ClaimForm.GetColumn(previousControl) == 1)
                    {
                        parameter       = control.Text;
                        previousControl = ClaimForm.Controls[ClaimForm.Controls.IndexOf(control) - 2];
                    }
                    else
                    {
                        parameter = control.Text;
                    }
                    parameters.Add(parameter);

                    // Validate input
                    if (!string.IsNullOrWhiteSpace(parameter))
                    {
                        List <string> validationCheck = ApplicationHelper.GetValidationData(previousControl.Text.Substring(0, previousControl.Text.Length - 1));
                        if (validationCheck != null && int.Parse(validationCheck[1]) > 0)
                        {
                            if (control.Text.Length != int.Parse(validationCheck[0]))
                            {
                                // Tell to raise an error and inform the user about the error and where it is
                                raiseError        = true;
                                errorMessage     += Environment.NewLine + "  - " + previousControl.Text + " needs to be of length " + validationCheck[0];
                                control.BackColor = Color.LightPink;
                            }
                        }
                    }
                }

                // Confirm that the data entered is valid (above)
                Console.Write("...IsValidData: ");
                if (raiseError)
                {
                    Console.WriteLine("false");
                    throw new Exception("Errors with input were found: " + errorMessage);
                }
                Console.WriteLine("true");

                // Confirm that there is new data (if NOT new data)
                //Console.Write("...IsNewData: ");
                //if (!MainWindowHelper.IsNewData(parameters))
                //{
                //    Console.WriteLine("false");
                //    throw new Exception("No new data was entered.");
                //}
                //Console.WriteLine("true");

                // Prompt user as a double-check
                if (DialogResult.No == MessageBox.Show("Transaction will be saved and re-uploaded to the mainframe." + Environment.NewLine + "Do you wish to continue?", "Continue?", MessageBoxButtons.YesNo))
                {
                    Console.WriteLine("...Canceled by user");
                    return;
                }

                // Tell the user to wait
                this.Enabled = false;

                ApplicationHelper.SaveClaim(parameters);

                Console.WriteLine("...Done");
            }
            catch (Exception ex)
            {
                Console.WriteLine("...Failed to save");
                string errorMsg = "Claim failed to save!" + Environment.NewLine + ((ex.InnerException == null) ? ex.Message : ex.InnerException.Message);
                MessageBox.Show(errorMsg, "Failed to save");
                Console.WriteLine(errorMsg);
            }
            finally
            {
                // Close EditWindow when done
                this.Dispose();
            }
        }