Beispiel #1
0
        /// <summary>
        /// Remove the current row
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks></remarks>
        private void RemoveCurrentCustomerButton_Click(object sender, EventArgs e)
        {
            if (_bsCustomers.DataSource == null)
            {
                MessageBox.Show("Please select some data");
                return;
            }

            if (Question("Remove " + _bsCustomers.CurrentRow().CompanyName()))
            {
                if (!_dataOperations.RemoveCustomer(_bsCustomers.CurrentRow().Identifier()))
                {
                    if (!_dataOperations.IsSuccessFul)
                    {
                        MessageBox.Show($"Failed to remove customer{Environment.NewLine}{_dataOperations.LastExceptionMessage}");
                    }
                }
                else
                {
                    //
                    // Only remove row if removed successfully from the database table
                    //
                    _bsCustomers.RemoveCurrent();
                }
            }
        }
        public void EditCurrentRecoedInDataGridViewFromBindingSource()
        {
            var        row = BindingSource.CurrentRow();
            EditorForm f   = new EditorForm(row, mContactList);

            try
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    if (!Operations.FakeUpdateCustomer(row))
                    {
                        row.RejectChanges();

                        /*
                         * We landed here because there was an exception raised. Since
                         * the DataRow has been updated we use RejectChanges to undue
                         * the changes in our DataGridView.
                         */
                    }
                    else
                    {
                        /*
                         * Landing here means the DataRow has been updated in the
                         * DataGridView and the database table has been updated too.
                         */
                    }
                }
            }
            finally
            {
                f.Dispose();
            }
        }
Beispiel #3
0
        private void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
        {
            if (e.Column.ColumnName == "Available")
            {
                Int32 CurrentRow = DataGridView1.CurrentCell.RowIndex;
                Int32 CurrentCol = DataGridView1.CurrentCell.ColumnIndex;

                bool Checker = false;

                if (bool.TryParse(e.ProposedValue.ToString(), out Checker))
                {
                    if (Checker)
                    {
                        string    ID = bsRooms.CurrentRow("Identifier");
                        DataTable dt = (DataTable)bsRooms.DataSource;

                        foreach (DataRow row in dt.Rows)
                        {
                            string ThisId = row["Identifier"].ToString();
                            if (!(row["Identifier"].ToString() == ID))
                            {
                                row.SetField <bool>("Available", false);
                            }
                        }

                        dt.AcceptChanges();
                    }

                    bsRooms.ResetCurrentItem();
                    DataGridView1.CurrentCell = DataGridView1[CurrentCol, CurrentRow];
                }
            }
        }
        /// <summary>
        /// Promot user to deactivate the currently selected customer record.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bindingNavigatorMakeInActive_Click(object sender, EventArgs e)
        {
            if (_bsCustomers.CurrentIsValid())
            {
                if (Question($"Remove '{_bsCustomers.CurrentRow().Field<string>("CompanyName")}'"))
                {
                    var ops = new SqlServerOperations();

                    if (ops.InactivateCustomer(_bsCustomers.CurrentRow().Field <int>("CustomerIdentifier")))
                    {
                        _bsCustomers.RemoveCurrent();
                        cmdGetInactiveCustomers.Enabled = true;
                    }
                    else
                    {
                        MessageBox.Show(ops.LastExceptionMessage);
                    }
                }
            }
        }
 public void PromptToRemoveCurrentRecordInDataGridViewFromBindingSource()
 {
     if (DataGridView.IsValidDataGridViewButton(RemoveButtonName))
     {
         if (KarenDialogs.Question($"Remove '{BindingSource.CurrentRow().Field<string>("CompanyName")}'"))
         {
             if (Operations.FakeRemoveCustomer(BindingSource.CurrentRow().Field <int>("CustomerIdentifier")))
             {
                 BindingSource.RemoveCurrent();
             }
         }
     }
 }
 public void UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     if (KarenDialogs.Question($"Remove '{BindingSource.CurrentRow().Field<string>("CompanyName")}'"))
     {
         if (Operations.FakeRemoveCustomer(BindingSource.CurrentRow().Field <int>("CustomerIdentifier")))
         {
             BindingSource.RemoveCurrent();
         }
     }
     else
     {
         e.Cancel = true;
     }
 }