private void goBtn_Click(object sender, EventArgs e) { using (MyStoreDataDataContext db = new MyStoreDataDataContext()) { purchaseList.Items.Clear(); if (dateRadio.Checked) { DateTime dFrom = dateFromPicker.Value.Date; DateTime dTo = dateToPicker.Value.Date; var orders = from order in db.ORDER_DETAILs where id == order.custID && order.order_date >= dFrom && order.order_date <= dTo select order; foreach (var o in orders) { String desc = db.ITEMs.Where(p => p.item_upc == o.item_upc).Select(p => p.item_description).First(); string[] row = { o.order_num.ToString(), o.order_date.ToString(), desc, o.order_quantity.ToString(), "$ " + o.order_price.ToString() }; var listViewItem = new ListViewItem(row); purchaseList.Items.Add(listViewItem); } } else if (priceRadio.Checked) { decimal pFrom = Convert.ToDecimal(priceFromTxt.Text); decimal pTo = Convert.ToDecimal(priceToTxt.Text); var orders = from order in db.ORDER_DETAILs where id == order.custID where order.order_price >= pFrom where order.order_price <= pTo select order; foreach (var o in orders) { String desc = db.ITEMs.Where(p => p.item_upc == o.item_upc).Select(p => p.item_description).First(); string[] row = { o.order_num.ToString(), o.order_date.ToString(), desc, o.order_quantity.ToString(), "$ " + o.order_price.ToString() }; var listViewItem = new ListViewItem(row); purchaseList.Items.Add(listViewItem); } } } }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { this.Width = 800; this.Height = 300; var senderGrid = (DataGridView)sender; if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0) { String item = (String)dataGridView1[e.ColumnIndex - 3, e.RowIndex].Value; decimal price = Convert.ToDecimal(dataGridView1[e.ColumnIndex - 2, e.RowIndex].Value); int upc = (int)dataGridView1[e.ColumnIndex - 4, e.RowIndex].Value; int quantity = 0; if (dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value != null) { quantity = Convert.ToInt32(dataGridView1[e.ColumnIndex - 1, e.RowIndex].Value); using (MyStoreDataDataContext db = new MyStoreDataDataContext()) { int creditLimit = 10000; var userBalance = db.USERs.Where(p => p.userID == id).Select(p => p.user_balance).First(); if (quantity * price > creditLimit - userBalance) { MessageBox.Show("That amount is over your credit limit!"); } else { var date = Convert.ToDateTime(DateTime.Now.Date.ToString("MM/dd/yyyy")); ORDER_DETAIL o = new ORDER_DETAIL(); o.order_date = date; o.custID = id; o.item_upc = upc; o.order_quantity = quantity; o.order_price = price * quantity; //MessageBox.Show(date + " " + id + " " + upc + " " + quantity + " " + price * quantity); db.ORDER_DETAILs.InsertOnSubmit(o); db.SubmitChanges(); MessageBox.Show("You just bought " + quantity + " " + item + " for $" + price * quantity); } } } else { MessageBox.Show("Please choose an amount greater than 0"); } } }
public Profile(int id) { this.id = id; InitializeComponent(); using (MyStoreDataDataContext db = new MyStoreDataDataContext()) { var user = from u in db.USERs where id == u.userID select u; fillName.Text = user.First().username; fillAddress.Text = user.First().user_address; } }
private void loginLbl_Click(object sender, EventArgs e) { //var conn = Singleton.Instance; using (MyStoreDataDataContext db = new MyStoreDataDataContext()) { if (db.USERs.Where(p => p.username == usernameTxt.Text && p.user_password == passTxt.Text).Count() == 1) { var id = db.USERs.Where(p => p.username == usernameTxt.Text).Select(p => p.userID).First(); Home home = new Home(id); this.Hide(); db.Dispose(); home.Show(); } else { MessageBox.Show("Wrong username or password! Please try again!"); } } }
public AllPurchases(int id) { this.id = id; InitializeComponent(); using (MyStoreDataDataContext db = new MyStoreDataDataContext()) { var orders = from order in db.ORDER_DETAILs where id == order.custID select order; foreach (var o in orders) { String desc = db.ITEMs.Where(p => p.item_upc == o.item_upc).Select(p => p.item_description).First(); string[] row = { o.order_num.ToString(), o.order_date.ToString(), desc, o.order_quantity.ToString(), "$ " + o.order_price.ToString() }; var listViewItem = new ListViewItem(row); purchaseList.Items.Add(listViewItem); } } }