private void dgvGroup_CellClick(object sender, DataGridViewCellEventArgs e) { currentDiscountCell = (sender as DataGridView).Rows[e.RowIndex].Cells["discountName"]; currentRow = discounts.FindBydiscountId((int)(sender as DataGridView).Rows[e.RowIndex].Cells["discountId"].Value); tbxDiscount.Text = (sender as DataGridView).Rows[e.RowIndex].Cells["discountName"].Value.ToString(); vdisDa.Fill(DBclass.DS.v_discount, currentRow.discountId); var dgv = sender as DataGridView; if (dgv.Columns[e.ColumnIndex] is DataGridViewButtonColumn) { switch (dgv.Name) { case "dgvGroup": switch (dgv.Columns[e.ColumnIndex].Name) { case "colBtn": ProdList prodlist = new ProdList(); if (prodlist.ShowDialog() == DialogResult.OK) { DataSetTpos.v_discountRow[] vDisRow = (DataSetTpos.v_discountRow[])DBclass.DS.v_discount.Select("productId" + prodlist.id); if (vDisRow.Length > 0 || vDisRow[0].discountId != currentRow.discountId) { DataSetTpos.discountproductsRow dpr = discountpr.NewdiscountproductsRow(); dpr.discount = 0; dpr.productId = Convert.ToInt32(prodlist.id); dpr.discountId = currentRow.discountId; discountpr.AdddiscountproductsRow(dpr); discountpDa.Update(discountpr); vdisDa.Fill(DBclass.DS.v_discount, currentRow.discountId); } } break; case "colBtnDel": if (MessageBox.Show("Вы действительно хотите удалить группу скидок?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { discountpDa.DeleteDiscount(currentRow.discountId); currentRow.Delete(); discountDA.Update(currentRow); if (discounts.Rows.Count > 0) { dgv.Rows[0].Cells["discountName"].Selected = true; dgvGroup_CellClick(dgv, new DataGridViewCellEventArgs(1, 0)); } } break; } break; } } }
private void dgvDiscount_CellEndEdit(object sender, DataGridViewCellEventArgs e) { DataSetTpos.discountproductsRow dprRow = discountpr.FindBydiscountproductId((int)(sender as DataGridView).Rows[e.RowIndex].Cells["discountproductId"].Value); if (dprRow != null) { dprRow.discount = (int)(sender as DataGridView).Rows[e.RowIndex].Cells["discount"].Value; discountpDa.Update(dprRow); } }