private void tbxQuantity_Leave(object sender, EventArgs e) { int a; if (!int.TryParse(tbxQuantity.Text, out a)) { return; } int oldQuantity = dtgListMember.RowCount; int newQuantity = int.Parse(tbxQuantity.Text); if (newQuantity > dtgListMember.RowCount) { for (int i = 0; i < (newQuantity - oldQuantity); i++) { DataRow newRow = listMember.NewRow(); newRow[1] = listMember.Rows.Count + 1; listMember.Rows.InsertAt(newRow, listMember.Rows.Count); } } else { for (int i = 0; i < (oldQuantity - newQuantity); i++) { listMember.Rows.RemoveAt(listMember.Rows.Count - 1); } } dtgListMember.DataSource = listMember; formatDtgListMember(); updatingContract.QuantityDiscount = contractModel.getQuantityDiscout(newQuantity); tbxQuantityDiscount.Text = updatingContract.QuantityDiscount.ToString(); dtgListMember.CurrentCell = dtgListMember.Rows[0].Cells[1]; calculateMoney(); }
private void tbxQuantity_Leave(object sender, EventArgs e) { int a; if (!int.TryParse(tbxQuantity.Text, out a)) { return; } contract.Quantity = int.Parse(tbxQuantity.Text); contract.QuantityDiscount = contractModel.getQuantityDiscout(contract.Quantity); tbxQuantityDiscount.Text = contract.QuantityDiscount.ToString(); dtgListMember.ColumnCount = 6; dtgListMember.RowCount = contract.Quantity; formatDtgListMember(); for (int i = 0; i < contract.Quantity; i++) { dtgListMember.Rows[i].Cells[0].Value = i + 1; } dtgListMember.CurrentCell = dtgListMember.Rows[0].Cells[1]; calculateMoney(); }