public void loadCustomerDatagrid() { if (tabControl1.SelectedTab == tabCustomers) { try { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { var cust = from Customer in context.Customers select Customer; dtgCustomers.DataSource = cust.ToList(); dtgCustomers.Columns[0].HeaderText = "CustID"; dtgCustomers.Columns[1].HeaderText = "First Name"; dtgCustomers.Columns[2].HeaderText = "Last Name"; dtgCustomers.Columns[3].HeaderText = "Address"; dtgCustomers.Columns[4].HeaderText = "Email"; dtgCustomers.Columns[5].HeaderText = "Phone"; } } catch (Exception g) { MessageBox.Show(g.Message); } } }
private void btnSave_Click(object sender, EventArgs e) { try { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = new Customer() { custFirstName = txtFirstName.Text, custLastName = txtLastName.Text, custAddress = txtAddress.Text, custEmail = txtEmail.Text, custPhone = txtPhone.Text }; context.Customers.Add(customer); context.SaveChanges(); this.Close(); } } catch (Exception) { MessageBox.Show("You must enter a value for each item"); } }
private void frmEditProduct_Load(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = context.Products.FirstOrDefault(c => c.Id == myId); txtProdName.Text = product.prodName; txtProdCode.Text = product.prodCode; txtProdPrice.Text = product.prodPrice.ToString(); } }
private void frmEditCustomer_Load(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = context.Customers.FirstOrDefault(c => c.Id == myId); txtFirstName.Text = customer.custFirstName; txtLastName.Text = customer.custLastName; txtAddress.Text = customer.custAddress; txtEmail.Text = customer.custEmail; txtPhone.Text = customer.custPhone; } }
private void btnSave_Click(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = context.Products.FirstOrDefault(c => c.Id == myId); product.prodName = txtProdName.Text; product.prodCode = txtProdCode.Text; product.prodPrice = decimal.Parse(txtProdPrice.Text); context.SaveChanges(); this.Close(); } }
private void btnSave_Click(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = context.Customers.FirstOrDefault(c => c.Id == myId); customer.custFirstName = txtFirstName.Text; customer.custLastName = txtLastName.Text; customer.custAddress = txtAddress.Text; customer.custEmail = txtEmail.Text; customer.custPhone = txtPhone.Text; context.SaveChanges(); this.Close(); } }
private void btnSave_Click(object sender, EventArgs e) { try { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = new Product() { prodName = txtProdName.Text, prodCode = txtProdCode.Text, prodPrice = decimal.Parse(txtProdPrice.Text) }; context.Products.Add(product); context.SaveChanges(); this.Close(); } } catch (Exception) { MessageBox.Show("You must enter a value for each item"); } }
private void loadReceipt() { if (myTyped != "") { myItems.Add(new SaleItems { name = department, price = double.Parse(myTyped) / 100 }); } rtfReceipt.Clear(); loadRTFbox(); using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { int lastId = context.Transactions.Max(p => p.Id); transId = lastId + 1; } rtfReceipt.AppendText("\n\tTransaction# " + transId + "\n\n"); runningTotal = 0; for (int i = 0; i < myItems.Count; i++) { rtfReceipt.AppendText(myItems[i].name + "\n"); rtfReceipt.AppendText("->\t\t\t" + myItems[i].price.ToString("C") + "\n"); runningTotal = runningTotal + myItems[i].price; } if (discountRate != 0) { discount = runningTotal * discountRate; double totalMinusDiscount = runningTotal - discount; rtfReceipt.AppendText("Discount:\n" + discountPercentage + " ->\t\t\t" + discount.ToString("C") + "\n"); rtfReceipt.AppendText("-----------" + "\n" + "Subtotal:\t\t\t" + totalMinusDiscount.ToString("C") + "\n"); tax = totalMinusDiscount * (taxRate / 100); rtfReceipt.AppendText("Tax:\t\t\t" + tax.ToString("C") + "\n"); finalTotal = totalMinusDiscount + tax; rtfReceipt.AppendText("Total:\t\t\t" + finalTotal.ToString("C") + "\n"); } else { tax = runningTotal * (taxRate / 100); rtfReceipt.AppendText("-----------" + "\n" + "Subtotal:\t\t\t" + runningTotal.ToString("C") + "\n"); rtfReceipt.AppendText("Tax:\t\t\t" + tax.ToString("C") + "\n"); finalTotal = (runningTotal + (runningTotal * (taxRate / 100))); rtfReceipt.AppendText("Total:\t\t\t" + finalTotal.ToString("C") + "\n"); } textBoxTotal.Text = "$0.00"; myTyped = ""; }
private void buttonCashTend_Click(object sender, EventArgs e) { double cashTendered = 0; if (myTyped != "") { cashTendered = double.Parse(myTyped) / 100; if (cashTendered >= ((runningTotal * discountRate))) { rtfReceipt.AppendText("-----------\n" + "Cash tendered:\t \t" + cashTendered.ToString("C") + "\n"); if (taxRate != 0.00) { rtfReceipt.AppendText("Change:\t \t\t" + (cashTendered - ((runningTotal + tax) - (runningTotal * discountRate))).ToString("C") + "\n"); } else { rtfReceipt.AppendText("Change:\t \t\t" + (cashTendered - (runningTotal * discountRate)).ToString("C") + "\n"); } } else { MessageBox.Show("Cash Tendered must be more than total."); cashTendered = 0; } using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Transaction transaction = new Transaction() { Id = transId, transDate = DateTime.Now, transGrossTotal = decimal.Parse(runningTotal.ToString()), transDiscount = decimal.Parse(discount.ToString()), transTax = decimal.Parse(tax.ToString()), transNetTotal = decimal.Parse(finalTotal.ToString()) }; context.Transactions.Add(transaction); context.SaveChanges(); transId = 0; runningTotal = 0; tax = 0; myItems.Clear(); } } }
private void btnSearchTransactions_Click(object sender, EventArgs e) { grossTotal = 0; taxTotal = 0; discTotal = 0; netTotal = 0; using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { var trans = context.Transactions.Where(entry => entry.transDate >= dtpFrom.Value.Date && entry.transDate <= dtpTo.Value.Date).ToList(); dtgTransactions.DataSource = trans.ToList(); List<Transaction> transAction = trans.ToList(); for (int i = 0; i < trans.Count(); i++) { grossTotal = grossTotal + transAction[i].transGrossTotal; taxTotal = taxTotal + transAction[i].transTax; discTotal = discTotal + transAction[i].transDiscount; netTotal = netTotal + transAction[i].transNetTotal; } txtGrossTotal.Text = grossTotal.ToString(); txtTaxTotal.Text = taxTotal.ToString(); txtDiscountTotal.Text = discTotal.ToString(); txtNetTotal.Text = netTotal.ToString(); } }
private void btnSearchProducts_Click(object sender, EventArgs e) { if (txtSearchProducts.Text != "") { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = new Product(); string userSelected = txtSearchProducts.Text; var data = from b in context.Products where b.prodName.Contains(userSelected) select b; dtgProducts.DataSource = data.ToList(); } } }
private void btnSearchCustomer_Click(object sender, EventArgs e) { if (txtSearchCustomer.Text != "") { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = new Customer(); string userSelected = txtSearchCustomer.Text; if (cbCustSearchOptions.Text == "First Name") { var data = from b in context.Customers where b.custFirstName.Contains(userSelected) select b; dtgCustomers.DataSource = data.ToList(); } else if (cbCustSearchOptions.Text == "Last Name") { var data = from b in context.Customers where b.custLastName.Contains(userSelected) select b; dtgCustomers.DataSource = data.ToList(); } else if (cbCustSearchOptions.Text == "Address") { var data = from b in context.Customers where b.custAddress.Contains(userSelected) select b; dtgCustomers.DataSource = data.ToList(); } else if (cbCustSearchOptions.Text == "Email") { var data = from b in context.Customers where b.custEmail.Contains(userSelected) select b; dtgCustomers.DataSource = data.ToList(); } else if (cbCustSearchOptions.Text == "Phone") { var data = from b in context.Customers where b.custPhone.Contains(userSelected) select b; dtgCustomers.DataSource = data.ToList(); } else { MessageBox.Show("Please select a search criteria"); } } } }
private void btnEditProducts_Click(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = new Product(); foreach (DataGridViewRow row in this.dtgProducts.SelectedRows) { Product prod = row.DataBoundItem as Product; if (prod != null) { frmEditProduct editProd = new frmEditProduct(prod.Id); editProd.ShowDialog(); } } loadProductDatagrid(); } }
private void btnDeleteProduct_Click(object sender, EventArgs e) { DialogResult dialog = MessageBox.Show("Are you sure you want to delete this product?", "Delete product", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog == DialogResult.Yes) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Product product = new Product(); foreach (DataGridViewRow row in this.dtgProducts.SelectedRows) { Product prod = row.DataBoundItem as Product; if (prod != null) { Product prod_to_delete = context.Products.Single(c => c.Id == prod.Id); context.Products.Remove(prod_to_delete); } } context.SaveChanges(); loadProductDatagrid(); } } }
private void btnDeleteCustomer_Click(object sender, EventArgs e) { DialogResult dialog = MessageBox.Show("Are you sure you want to delete this customer?", "Delete Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog == DialogResult.Yes) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = new Customer(); foreach (DataGridViewRow row in this.dtgCustomers.SelectedRows) { Customer cust = row.DataBoundItem as Customer; if (cust != null) { Customer cust_to_delete = context.Customers.Single(c => c.Id == cust.Id); context.Customers.Remove(cust_to_delete); } } context.SaveChanges(); loadCustomerDatagrid(); } } }
public void loadTransactionDatagrid() { grossTotal = 0; taxTotal = 0; discTotal = 0; netTotal = 0; //dtpFrom.Format = DateTimePickerFormat.Custom; //dtpFrom.CustomFormat = "M/dd/yyyy"; if (tabControl1.SelectedTab == tabTransactions) { try { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { var trans = from Transaction in context.Transactions select Transaction; dtgTransactions.DataSource = trans.ToList(); dtgTransactions.Columns[0].HeaderText = "Transaction#"; dtgTransactions.Columns[1].HeaderText = "Date"; dtgTransactions.Columns[2].HeaderText = "Gross Total"; dtgTransactions.Columns[3].HeaderText = "Tax Applied"; dtgTransactions.Columns[4].HeaderText = "Discount Applied"; dtgTransactions.Columns[5].HeaderText = "Net Total"; List<Transaction> transAction = trans.ToList(); for (int i = 0; i < trans.Count(); i++) { grossTotal = grossTotal + transAction[i].transGrossTotal; taxTotal = taxTotal + transAction[i].transTax; discTotal = discTotal + transAction[i].transDiscount; netTotal = netTotal + transAction[i].transNetTotal; } txtGrossTotal.Text = grossTotal.ToString(); txtTaxTotal.Text = taxTotal.ToString(); txtDiscountTotal.Text = discTotal.ToString(); txtNetTotal.Text = netTotal.ToString(); } } catch (Exception g) { MessageBox.Show(g.Message); } } }
public void loadProductDatagrid() { if (tabControl1.SelectedTab == tabProducts) { try { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { var prod = from Product in context.Products select Product; dtgProducts.DataSource = prod.ToList(); dtgProducts.Columns[0].Visible = false; dtgProducts.Columns[0].HeaderText = "ProdID"; dtgProducts.Columns[1].HeaderText = "Product Name"; dtgProducts.Columns[2].HeaderText = "Product Code"; dtgProducts.Columns[3].HeaderText = "Product Price"; } } catch (Exception g) { MessageBox.Show(g.Message); } } }
private void btnEditCutomer_Click(object sender, EventArgs e) { using (mCoyoteDBEntities1 context = new mCoyoteDBEntities1()) { Customer customer = new Customer(); foreach (DataGridViewRow row in this.dtgCustomers.SelectedRows) { Customer cust = row.DataBoundItem as Customer; if (cust != null) { frmEditCustomer editCust = new frmEditCustomer(cust.Id); editCust.ShowDialog(); } } loadCustomerDatagrid(); } }