private void btnAdd_Click(object sender, EventArgs e) { if (cboContBy.SelectedIndex > -1) { if (txtAmount.Text.Trim().Length > 0) { int contBy; double cash; int.TryParse(cboContBy.SelectedValue.ToString(), out contBy); double.TryParse(txtAmount.Text.Trim(), out cash); if (contBy > 0 && cash > 0) { StartCash startCash = new StartCash(); startCash.saleId = SaleId; startCash.sellerId = contBy; startCash.cashAmount = cash; if (startCash.IsValid) { StartCashController startCashController = new StartCashController(); startCashController.Add(startCash); if (!KeepOpenOnAdd) { this.Close(); } else { ClearFields(); } } else { MessageBox.Show(startCash.Validator().ErrorMessage, "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Please enter a valid amount.", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Please enter an amount.", "Invalid Amount", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.SelectAll(); txtAmount.Focus(); } } else { MessageBox.Show("Please select a valid seller.", "Invalid Seller", MessageBoxButtons.OK, MessageBoxIcon.Information); cboContBy.Focus(); } }
private void btnSave_Click(object sender, EventArgs e) { if (cboContBy.SelectedIndex > -1) { if (txtAmount.Text.Trim().Length > 0) { StartCash startCash = new StartCash(); double amount; int sellerId; double.TryParse(txtAmount.Text.Replace("$", ""), out amount); int.TryParse(cboContBy.SelectedValue.ToString(), out sellerId); startCash.cashAmount = amount; startCash.sellerId = sellerId; startCash.id = Id; if (startCash.IsValid) { StartCashController startCashController = new StartCashController(); startCashController.Edit(startCash); this.Close(); } else { MessageBox.Show(startCash.Validator().ErrorMessage, "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Please enter an amount.", "Invalid Data", MessageBoxButtons.OK, MessageBoxIcon.Information); txtAmount.SelectAll(); txtAmount.Focus(); } } else { MessageBox.Show("Please select a valid seller.", "Invalid Seller", MessageBoxButtons.OK, MessageBoxIcon.Information); cboContBy.Focus(); } }
private void ToolStripDeleteButton_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Are you sure you wish to delete this contribution?", "Cofirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { if (CashGrid.SelectedRows != null && CashGrid.SelectedRows.Count > 0) { int id; int.TryParse(CashGrid.SelectedRows[0].Cells[3].Value.ToString(), out id); if (id > 0) { StartCashController startCashController = new StartCashController(); startCashController.Remove(id); LoadStartCashData(); } } } }
private void LoadStartCashData() { int currentRow = 0; if (CashGrid.CurrentRow != null) { currentRow = CashGrid.CurrentRow.Index; } StartCashController startCashController = new StartCashController(); CashGrid.DataSource = startCashController.GetAllBySaleId(_saleId); SetUpGrid(); if (CashGrid.Rows.Count > 0) { if (CashGrid.Rows.Count > currentRow) { CashGrid.CurrentCell = CashGrid.Rows[currentRow].Cells[0]; } else { CashGrid.CurrentCell = CashGrid.Rows[0].Cells[0]; } ToolStripEditButton.Enabled = true; ToolStripDeleteButton.Enabled = true; EditToolStripMenuItem.Enabled = true; DeleteToolStripMenuItem.Enabled = true; } else { ToolStripEditButton.Enabled = false; ToolStripDeleteButton.Enabled = false; EditToolStripMenuItem.Enabled = false; DeleteToolStripMenuItem.Enabled = false; } }