示例#1
0
        private void filterByPrice()
        {
            decimal hiVal, lowVal;

            if (txtPriceHi.Text == "")
            {
                hiVal = (decimal)int.MaxValue;
            }
            else
            {
                hiVal = Decimal.Parse(txtPriceHi.Text);
            }


            if (txtPriceLow.Text == "")
            {
                lowVal = 0;
            }
            else
            {
                lowVal = Decimal.Parse(txtPriceLow.Text);
            }

            using (StoreDataDataContext context = new StoreDataDataContext())
            {
                grdInvoices.DataSource = context.Invoices.Where(i => i.CustID == customerID && i.TotalBal >= lowVal && i.TotalBal <= hiVal).Select(i => new { Date = i.orderDate, Invoice = i.InvoiceID, Product = i.Product.Descr, i.Qty, UnitPrice = i.Product.PricePerUnit, Total = i.TotalBal });
            }
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string usernm = txtUsrnm.Text;
            string pwd    = txtPwd.Text;

            if (usernm == "" || pwd == "")
            {
                lblError.Text = "Invalid Username or Password.";
            }
            else
            {
                using (StoreDataDataContext context = new StoreDataDataContext())
                {
                    var u = context.Customers.Where(c => c.userid == usernm && c.pword == pwd);

                    if (u.Count() == 1)
                    {
                        var user = u.First();
                        // lblError.Text = "Successful!";
                        customerID = user.CustID;
                        this.Close();
                    }
                    else
                    {
                        lblError.Text = "User not found.\nWrong username/password combination.";
                    }
                }
            }
        }
示例#3
0
 private void filterByDate()
 {
     using (StoreDataDataContext context = new StoreDataDataContext())
     {
         grdInvoices.DataSource = context.Invoices.Where(i => i.CustID == customerID && i.orderDate >= dpLow.Value && i.orderDate <= dpHi.Value).Select(i => new { Date = i.orderDate, Invoice = i.InvoiceID, Product = i.Product.Descr, i.Qty, UnitPrice = i.Product.PricePerUnit, Total = i.TotalBal });
     }
 }
示例#4
0
        private void frmAccount_Load(object sender, EventArgs e)
        {
            using (StoreDataDataContext context = new StoreDataDataContext())
            {
                grdInvoices.DataSource = context.Invoices.Where(i => i.CustID == customerID).Select(i => new { Date = i.orderDate, Invoice = i.InvoiceID, Product = i.Product.Descr, i.Qty, UnitPrice = i.Product.PricePerUnit, Total = i.TotalBal });

                Customer cstmr = context.Customers.Where(c => c.CustID == customerID).First();
                setFields(cstmr);
            }
        }
        private void refreshData()
        {
            using (StoreDataDataContext context = new StoreDataDataContext())
            {
                var products = context.Products.Where(p => p.totAvail > 0).Select(p => new { p.ProdID, Description = p.Descr, p.PricePerUnit, InStock = p.totAvail });
                grdProducts.DataSource = products;

                foreach (DataGridViewColumn c in grdProducts.Columns)
                {
                    c.Width = 115;
                }
            }
        }
        private void btnPurchase_Click(object sender, EventArgs e)
        {
            using (StoreDataDataContext context = new StoreDataDataContext())
            {
                if (c.CreditLimit >= c.Balance + Decimal.Parse(txtTotPrice.Text))
                {
                    //create Invoice (1 product per purchase)
                    Invoice i = new Invoice();
                    i.CustID    = c.CustID;
                    i.ProdID    = p.ProdID;
                    i.Qty       = (int)numQty.Value;
                    i.orderDate = DateTime.Today;
                    i.TotalBal  = Decimal.Parse(txtTotPrice.Text);

                    context.Invoices.InsertOnSubmit(i);

                    var cstmr = context.Customers.Where(c => c.CustID == this.c.CustID).First();

                    Customer customer = (Customer)cstmr;
                    //bill customer
                    customer.Balance += i.TotalBal;


                    var prdct = context.Products.Where(p => p.ProdID == this.p.ProdID).First();

                    Product product = (Product)prdct;

                    // reduce number in stock
                    product.totAvail -= (int)numQty.Value;


                    context.SubmitChanges();
                    this.Hide();
                    MessageBox.Show("Order successfully Placed.", "Purchase Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                }
                else
                {
                    MessageBox.Show("Insufficient credit balance to allow for this purchase.", "Purchase Canceled", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#7
0
        private void btnPay_Click(object sender, EventArgs e)
        {
            if (txtAmt.Text == "")
            {
                MessageBox.Show("Dollar Amount Must Be Entered.", "No Amount Specified", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                decimal amt = decimal.Parse(txtAmt.Text);
                using (StoreDataDataContext context = new StoreDataDataContext())
                {
                    Customer cstmr = context.Customers.Where(c => c.CustID == customerID).First();

                    cstmr.Balance -= amt;


                    context.SubmitChanges();

                    setFields(cstmr);
                }
            }
        }
        private void grdProducts_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            //select prod id, but hide it.
            //grdProducts.CurrentRow.Cells["ProdID"]
            int prodID = Int32.Parse(grdProducts.CurrentRow.Cells["ProdID"].Value.ToString());

            using (StoreDataDataContext context = new StoreDataDataContext()) {
                var cstmr = context.Customers.Where(c => c.CustID == customerID).First();

                var prdct = context.Products.Where(o => o.ProdID == prodID).First();

                Customer cstmr2 = (Customer)cstmr;
                Product  prdct2 = (Product)prdct;



                frmPurchase p = new frmPurchase(prdct2, cstmr2);
                this.Hide();
                p.ShowDialog();

                refreshData();
                this.Show();
            }
        }