/// <summary>
        /// Simple example to add rows to our child table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// This has already been executed running this again would
        /// duplicate the row. So we could run the following (super simple)
        ///
        ///   SELECT id FROM EventAttachments WHERE FileBaseName = 'CPR'
        ///
        /// To ensure it does not exists, of course we would do more conditions
        /// in the WHERE for a real app.
        /// </remarks>
        private void button3_Click(object sender, EventArgs e)
        {
            if (KarenDialogs.Question("You might want to read comments first, continue?"))
            {
                var ops = new DataOperations();

                var fileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EventFiles", "CPR_2.docx");
                // new identifier returned
                var Identifier = 0;
                // existing row in parent table
                var EventIdentifier = 1;

                if (ops.FilePutForEvents(fileName, ref Identifier, EventIdentifier))
                {
                    MessageBox.Show("Success");
                }
                else
                {
                    MessageBox.Show($"Failed: {ops.ExceptionMessage}");
                }
            }
        }
Beispiel #2
0
 private void cmdAddNewRow_Click(object sender, EventArgs e)
 {
     if (!(string.IsNullOrWhiteSpace(txtCompanyName.Text)))
     {
         DataOperations DataOps = new DataOperations();
         int            NewId   = 0;
         if (DataOps.AddNewCustomer(txtCompanyName.Text, ref NewId))
         {
             ((DataTable)bsCustomers.DataSource).Rows.Add(new object[] { NewId, txtCompanyName.Text });
             bsCustomers.Position = bsCustomers.Find("Identifier", NewId);
         }
         else
         {
             MessageBox.Show("Failed to add new company");
         }
     }
     else
     {
         MessageBox.Show("Enter data into the textbox to add a row");
         ActiveControl = txtCompanyName;
     }
 }
Beispiel #3
0
        /// <summary>
        /// Simple example to add rows to our child table
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// This has already been executed running this again would
        /// duplicate the row. So we could run the following (super simple)
        ///
        ///   SELECT id FROM EventAttachments WHERE FileBaseName = 'CPR'
        ///
        /// To ensure it does not exists, of course we would do more conditions
        /// in the WHERE for a real app.
        /// </remarks>
        private void InsertToChildTableButton_Click(object sender, EventArgs e)
        {
            if (Question("You might want to read comments first, continue?"))
            {
                var ops = new DataOperations();

                var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EventFiles", "CPR_2.docx");

                // new identifier returned
                var identifier = 0;

                // existing row in parent table
                var eventIdentifier = 1;

                if (ops.InsertNewEvent(fileName, ref identifier, eventIdentifier))
                {
                    MessageBox.Show("Success");
                }
                else
                {
                    MessageBox.Show($"Failed: {ops.ExceptionMessage}");
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            /*
             * Since our Microsoft database does not have a reference table
             * for contact titles we build one outside of our typed data classes
             * generated in NorthWindDataSet.xsd and do it with SqlClient data
             * provider. In a well structured database design we would of had
             * a reference table for contact titles
             */
            var ops = new DataOperations();

            contactTitles = ops.ContactTitles();
            standings     = ops.Standings();

            this.ordersTableAdapter.Fill(this.northWindDataSet.Orders);
            this.customersTableAdapter.Fill(this.northWindDataSet.Customers);

            /*
             * Manually added, next two lines so we have the master and details
             * working together.
             */
            this.ordersBindingSource.DataSource = customersBindingSource;
            ordersBindingSource.DataMember      = northWindDataSet.Relations[0].RelationName;

            /*
             * DataGridViewColumns to hide in the master DataGridView
             */
            var columns = new DataGridViewColumn[]
            {
                orderIDDataGridViewTextBoxColumn,
                customerIdentifierDataGridViewTextBoxColumn
            };

            foreach (var col in columns)
            {
                col.Visible = false;
            }

            /*
             * Split Header text by upper-case characters in the master DataGridView
             */
            foreach (DataGridViewColumn col in customersDataGridView.Columns)
            {
                col.HeaderText = System.Text.RegularExpressions.Regex.Replace(col.HeaderText, "([a-z])([A-Z])", "$1 $2");
            }

            /*
             * Standard resize columns in master DataGridView
             */
            customersDataGridView.AutoResizeColumns();

            /*
             * The company column is an odd one that does not comply so set the header width manually
             */
            companyNameColumn.Width = companyNameColumn.Width + 20;

            /*
             * Repeat what we just did for the master DataGridView
             */
            foreach (DataGridViewColumn col  in ordersDataGridView.Columns)
            {
                col.HeaderText = System.Text.RegularExpressions.Regex.Replace(col.HeaderText, "([a-z])([A-Z])", "$1 $2");
            }



            /*
             * The postal code column is an odd one that does not comply so set the header width manually
             */
            shipPostalCodeDataGridViewTextBoxColumn.Width = shipPostalCodeDataGridViewTextBoxColumn.Width + 15;

            /*
             * The user is here to browse data so set the master DataGridView as the active control.
             */
            ActiveControl = customersDataGridView;


            /*
             * Yes we can do a find and position when found!!!
             */
            var postion = customersBindingSource.Find("CompanyName", "Around the Horn");

            if (postion > -1)
            {
                customersBindingSource.Position = postion;
            }
        }