Esempio n. 1
0
        /// <summary>
        /// Events that occur when the window first loads.
        /// Checks against the header name exist and should be considered
        /// when changes occur in the stored procedure.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditWindow_Load(object sender, EventArgs e)
        {
            Console.Write("Loading EditWindow...");
            // Centers the window when using "Show()"
            this.CenterToParent();

            // Set the window display name
            this.Text = this.Text + MainWindowHelper.GetCellData("clmClaimNumber");

            // Fill the fields with the proper data that was selected
            List <string> headers = MainWindowHelper.GetHeaders();

            try
            {
                // Create the form and its elements
                ClaimForm.Controls.Clear();

                Console.Write("...");
                foreach (string header in headers)
                {
                    // If the first header, don't create the extra row
                    if (ClaimForm.Controls.Count <= 0)
                    {
                        ClaimForm.RowStyles[0].Height = 24F;
                    }
                    else
                    {
                        ClaimForm.RowStyles.Add(new RowStyle(SizeType.Absolute, 24F));
                    }

                    // Declare and setup the form elements
                    #region HeaderLabel
                    Label headerLabel = new Label();
                    headerLabel.AutoSize  = true;
                    headerLabel.Font      = new System.Drawing.Font("Microsoft Sans Serif", 10.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                    headerLabel.Size      = new System.Drawing.Size(45, 20);
                    headerLabel.Margin    = new System.Windows.Forms.Padding(0, 4, 3, 0);
                    headerLabel.Location  = new Point(0, 0);
                    headerLabel.TextAlign = ContentAlignment.BottomLeft;
                    headerLabel.TabIndex  = 0;
                    headerLabel.Text      = header + ":";
                    headerLabel.Name      = "headerLabel" + ClaimForm.RowStyles.Count;
                    #endregion
                    #region TextBox
                    TextBox textBox = new TextBox();
                    textBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top
                                                                            | System.Windows.Forms.AnchorStyles.Left)
                                                                           | System.Windows.Forms.AnchorStyles.Right)));
                    textBox.Name     = "textBox" + ClaimForm.RowStyles.Count;
                    textBox.Size     = new System.Drawing.Size(10, 20);
                    textBox.TabIndex = 0;
                    // Set these columns to be greyed out
                    if (header.Equals("clmClaimNumber") || header.Equals("trxAmount"))
                    {
                        textBox.Enabled = false;
                    }
                    List <string> dataConstraints = ApplicationHelper.GetValidationData(header);
                    if (dataConstraints != null)
                    {
                        textBox.MaxLength = int.Parse(dataConstraints[0]);
                    }
                    #endregion
                    #region DropDown
                    ComboBox comboBox = new ComboBox();
                    if (header.Equals("trxAmount"))
                    {
                        comboBox.Cursor            = System.Windows.Forms.Cursors.Hand;
                        comboBox.DropDownStyle     = System.Windows.Forms.ComboBoxStyle.DropDownList;
                        comboBox.FormattingEnabled = true;
                        comboBox.MaxDropDownItems  = 2;
                        comboBox.MaxLength         = 1;
                        comboBox.Name     = "comboBox" + ClaimForm.RowStyles.Count;
                        comboBox.Size     = new System.Drawing.Size(32, 21);
                        comboBox.TabIndex = 0;
                        comboBox.Items.Add("+");
                        comboBox.Items.Add("-");
                        // Determine the sign
                        comboBox.SelectedItem = (float.Parse(MainWindowHelper.GetCellData(header)) < 0) ? "-" : "+";
                    }
                    #endregion

                    // Add the elements to the display
                    // The dropbox only applies to trxAmount
                    ClaimForm.Controls.Add(headerLabel, 0, ClaimForm.RowStyles.Count - 1);
                    if (header.Equals("trxAmount"))
                    {
                        ClaimForm.Controls.Add(comboBox, 1, ClaimForm.RowStyles.Count - 1);
                    }
                    ClaimForm.Controls.Add(textBox, 2, ClaimForm.RowStyles.Count - 1);

                    // Get the data into the textBox (done here as a rounding occurs if put in TextBox above)
                    Control claimFormTextBox = ClaimForm.Controls[ClaimForm.Controls.Count - 1];
                    claimFormTextBox.Text = MainWindowHelper.GetCellData(header);
                    if (claimFormTextBox.Text.StartsWith("-"))
                    {
                        claimFormTextBox.Text = claimFormTextBox.Text.Remove(0, 1);
                    }
                }
                Console.Write("...");

                // Resize the window and add the scroll bars as need be
                // The width is +20 to offset for the scrollbar if its added
                // If not done, a horizontal scrollbar appears
                // Note: the ClaimForm in the designer has 20px space to the right to handle this
                if (ClaimForm.Controls.Count > 16)
                {
                    ClaimForm.AutoScroll = true;
                }
                ClaimForm.Size = new Size(ClaimForm.Size.Width + 20, ClaimForm.Size.Height);

                Console.WriteLine("...Done");
            }
            catch (Exception ex)
            {
                Console.WriteLine("...Failed");
                string errorMsg = ((ex.InnerException == null) ? ex.Message : ex.InnerException.Message) + Environment.NewLine + ex.StackTrace;
                MessageBox.Show(errorMsg, "Error");
                Console.WriteLine(errorMsg);
            }
        }