Esempio n. 1
0
        private void btnDeleteDealer_Click(object sender, EventArgs e)
        {
            if (dgvDealer.Rows.Count > 0)
            {
                int    DealerId   = Convert.ToInt32(dgvDealer.CurrentRow.Cells[0].Value.ToString());
                string DealerName = dgvDealer.CurrentRow.Cells[1].Value.ToString();

                if (MessageBox.Show("Are you sure you want to delete the Main Dealer: " + DealerName.ToString() + "?", "Delete Main Dealer", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var dealerList = new List <DealerBranch>();
                    dealerList = DALHelpers.GetDealerBranchByDealerId(DealerId);

                    if (dealerList.Count == 0)
                    {
                        Dealer dealer = new Dealer();

                        dealer.DealerId    = Convert.ToInt32(dgvDealer.CurrentRow.Cells[0].Value.ToString());
                        dealer.CountryName = dgvDealer.CurrentRow.Cells[1].Value.ToString();
                        dealer.CountryId   = Convert.ToInt32(dgvDealer.CurrentRow.Cells[2].Value.ToString());

                        DALHelpers.DeleteMainDealer(DealerId);

                        ActivityLog.DealerLogger(dealer, "DELETE", "Main Dealer", Environment.UserName);

                        Validation.LocalDatabaseConfig(true);
                        //databaseViewModel = Services.GetDataFromDatabase();
                        dealerlList = loadDealers();
                    }
                    else
                    {
                        MessageBox.Show("Unable to Delete the Main Dealer: " + DealerName.ToString() + ". Found " + dealerList.Count + " Dealer Branches created for this Main Dealer", "Unable to Delete the Main Dealer!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }

                dgvDealer.ClearSelection();
                txtSearchDealer.Clear();
                btnEditDealer.Enabled   = false;
                btnDeleteDealer.Enabled = false;
            }
        }