private void txtCash_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (Convert.ToDecimal(txtCash.Text) < Convert.ToDecimal(txtTotalOrder.Text)) { MessageBox.Show("Cash not less than to the total order.", "Cash Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCash.Text = ""; } else { // enable button when TextBox Cash enter btnMinimize.Enabled = true; btnShutdown.Enabled = true; btnCalculator.Enabled = true; btnContact.Enabled = true; btnOpenSettings.Enabled = true; btnPrintTotalSales.Enabled = true; using (SqlConnection con = new SqlConnection(GlobalConfig.CnnString(db))) { for (int i = 0; i < dgvOrderProductLists.Rows.Count; i++) { SqlCommand cmd = new SqlCommand(@"INSERT INTO Orders (SKU, ProductName, Price, Quantity, Total, DatePurchased) VALUES(@SKU, @ProductName, @Price, @Quantity, @Total, @DatePurchased)", con); con.Open(); cmd.Parameters.AddWithValue("@SKU", dgvOrderProductLists.Rows[i].Cells[1].Value.ToString()); cmd.Parameters.AddWithValue("@ProductName", dgvOrderProductLists.Rows[i].Cells[2].Value.ToString()); cmd.Parameters.AddWithValue("@Price", dgvOrderProductLists.Rows[i].Cells[3].Value.ToString()); cmd.Parameters.AddWithValue("@Quantity", dgvOrderProductLists.Rows[i].Cells[4].Value.ToString()); cmd.Parameters.AddWithValue("@Total", dgvOrderProductLists.Rows[i].Cells[5].Value.ToString()); cmd.Parameters.AddWithValue("@DatePurchased", DateTime.Now.ToString("MM-dd-yyyy hh:mm tt")); cmd.ExecuteNonQuery(); con.Close(); } } productBindingSource.DataSource = null; txtTotalOrder.Text = "0.00"; txtCash.Text = "0"; txtChange.Text = "0.00"; productBindingSource.DataSource = new List <Product>(); totalOrder = 0M; txtSearchProductLists.Enabled = true; txtQuantity.Enabled = true; txtDiscount.Enabled = true; btnPrintReceipt.Enabled = false; discount = 0; lblDiscountedNumber.Text = Convert.ToString(discount); txtSearchProductLists.Focus(); } } } catch (Exception) { MessageBox.Show("Enter a valid amount or money, not include a letter or word.", "Cash Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); txtCash.Text = ""; } }
private void btnDelete_Click(object sender, EventArgs e) { if (DialogResult.Yes == MessageBox.Show("Are you sure want to delete?", "Delete Product!", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { try { Product obj = new Product(); obj.Id = productId; SqlConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)); SqlCommand cmd = new SqlCommand("spSalesProduct", connection); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", "Delete"); cmd.Parameters.AddWithValue("@ID", obj.Id); connection.Open(); cmd.ExecuteNonQuery(); connection.Close(); FillDataGridView(); txtSKU.Text = ""; txtProductName.Text = ""; txtPrice.Text = "0.00"; txtSKU.Focus(); MessageBox.Show("Deleted successfully.", "Delete Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Delete Click Information!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }