private void LoadData() { using (var supermarket = new SuperEntities()) { customerBindingSource.DataSource = supermarket.Customers.ToList(); } }
private void GetTransNo() { try { string sdate = DateTime.Now.ToString("yyyyMMdd"); string transno; int count; using (var context = new SuperEntities()) { var order = (from ord in context.Orders where ord.TransNo.Contains(sdate) orderby ord.Id descending select ord).FirstOrDefault(); if (order != null) { transno = order.TransNo; count = int.Parse(transno.Substring(8, 4)); lblTransno.Text = sdate + (count + 1); } else { transno = sdate + "1001"; lblTransno.Text = transno; } } } catch (Exception ex) { MessageBox.Show(ex.Message, stitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void btnCancel_Click(object sender, EventArgs e) { using (var supermarket = new SuperEntities()) { panel1.Enabled = false; customerBindingSource.ResetBindings(false); foreach (DbEntityEntry entry in supermarket.ChangeTracker.Entries()) { switch (entry.State) { case EntityState.Added: entry.State = System.Data.Entity.EntityState.Detached; break; case EntityState.Modified: entry.State = EntityState.Unchanged; break; case EntityState.Deleted: entry.Reload(); break; } } } }
private void Customer_Load(object sender, EventArgs e) { //panel1.Enabled = false; using (var supermarket = new SuperEntities()) { customerBindingSource.DataSource = supermarket.Customers.ToList(); } }
private void dataGridView_KeyDown(object sender, KeyEventArgs e) { using (var supermarket = new SuperEntities()) { if (e.KeyCode == Keys.Delete) { if (MessageBox.Show("Are you sure want to delete this record?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { supermarket.Customers.Remove(customerBindingSource.Current as Customer); customerBindingSource.RemoveCurrent(); } } } }
private void btnSearch_Click(object sender, EventArgs e) { try { using (var supermarket = new SuperEntities()) { var customer_id = txtCustomerID.Text; var st = from s in supermarket.Customers where s.CustomerID == customer_id select s; dataGridView1.DataSource = st.ToList(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); customerBindingSource.ResetBindings(false); } }
private void btnSave_Click(object sender, EventArgs e) { try { using (var supermarket = new SuperEntities()) { customerBindingSource.EndEdit(); supermarket.SaveChangesAsync(); panel1.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); customerBindingSource.ResetBindings(false); } }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure to delete ?", "Delete record", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (var supermarket = new SuperEntities()) { var customer_id = txtCustomerID.Text; var fullname = txtFullName.Text; var email = txtEmail.Text; var address = txtAddress.Text; var st = (from s in supermarket.Customers where s.CustomerID == customer_id select s).First(); supermarket.Customers.Remove(st); supermarket.SaveChanges(); MessageBox.Show("Successfully deleted."); LoadData(); } } }
private void btnExport_Click(object sender, EventArgs e) { using (var db = new SuperEntities()) { var list_data = (from s in db.Customers select s); var csv = new StringBuilder(); var newLine = string.Format("{0},{1},{2},{3}", "Customer ID", "Fullname", "Email", "Address"); csv.AppendLine(newLine); foreach (var data in list_data) { var newLine2 = string.Format("{0},{1},{2},{3}", data.CustomerID, data.FullName, data.Email, data.Address); csv.AppendLine(newLine2); } File.WriteAllText("customerresult.csv", csv.ToString()); } }
private void gridProduct_CellContentClick(object sender, DataGridViewCellEventArgs e) { string colName = gridProduct.Columns[e.ColumnIndex].Name; if (colName == "Action") { var product_id = Convert.ToInt32(gridProduct.Rows[e.RowIndex].Cells[0].Value.ToString()); var item_name = gridProduct.Rows[e.RowIndex].Cells[1].Value.ToString(); var category = gridProduct.Rows[e.RowIndex].Cells[2].Value.ToString(); var price = Convert.ToInt32(gridProduct.Rows[e.RowIndex].Cells[3].Value.ToString()); //gridOrder.Rows.Add(product_id, item_name, 0, 0, 0); frmQty frm = new frmQty(this); frm.ProductDetails(product_id, item_name, price); frm.ShowDialog(); } using (var context = new SuperEntities()) { } }
private void btnUpdate_Click(object sender, EventArgs e) { // Update var customer_id = txtCustomerID.Text; var fullname = txtFullName.Text; var email = txtEmail.Text; var address = txtAddress.Text; using (var supermarket = new SuperEntities()) { var st = (from s in supermarket.Customers where s.CustomerID == customer_id select s).First(); st.CustomerID = customer_id; st.FullName = fullname; st.Email = email; st.Address = address; supermarket.SaveChanges(); MessageBox.Show("Successfully Updated."); LoadData(); } }
private void btnShow_Click(object sender, EventArgs e) { var timespan = new TimeSpan(23, 59, 59); var expired = dtmExpired.Value; expired = expired.Date + timespan; //Declare Datatable DataTable order = new DataTable(); order.Columns.Add("ProductID", typeof(string)); order.Columns.Add("ItemName", typeof(string)); order.Columns.Add("Price", typeof(int)); order.Columns.Add("Category", typeof(string)); order.Columns.Add("ExpiryDate", typeof(DateTime));; //Insert Test Rows using (var context = new SuperEntities()) { var list_product = context.ProductInfo_Tab.Where(o => o.ExpiryDate <= expired).ToList(); foreach (var data in list_product) { //var product_name = context.ProductInfo_Tab.FirstOrDefault(o => o.ProductID == data.ProductId).itemName; //var price_total = data.Price * data.Qty; order.Rows.Add(data.ProductID, data.itemName, data.Price, data.Categories, data.ExpiryDate); } //order.Rows.Add(1, "1", "Satu", 10000, 1, 100000, DateTime.Now); //order.Rows.Add(2, "2", "Dua", 10003, 1, 100000, DateTime.Now); //order.Rows.Add(3, "3", "Tiga", 10002, 1, 100000, DateTime.Now); //order.Rows.Add(4, "4", "Empat", 10004, 1, 100000, DateTime.Now); //order.Rows.Add(5, "5", "Lima", 100005, 1, 100000, DateTime.Now); } crptProduct crpt = new crptProduct(); crpt.Database.Tables["product"].SetDataSource(order); crvProduct.ReportSource = null; crvProduct.ReportSource = crpt; }
private void btnShow_Click(object sender, EventArgs e) { var transno = txtTransNo.Text; //Declare Datatable DataTable order = new DataTable(); order.Columns.Add("TransNo", typeof(string)); order.Columns.Add("ProductId", typeof(string)); order.Columns.Add("ProductName", typeof(string)); order.Columns.Add("Price", typeof(int)); order.Columns.Add("Quantity", typeof(int)); order.Columns.Add("Total", typeof(int)); order.Columns.Add("Tanggal", typeof(DateTime)); //Insert Test Rows using (var context = new SuperEntities()) { var list_order = context.Orders.Where(o => o.TransNo == transno).ToList(); foreach (var data in list_order) { var product_name = context.ProductInfo_Tab.FirstOrDefault(o => o.ProductID == data.ProductId).itemName; var price_total = data.Price * data.Qty; order.Rows.Add(data.TransNo, data.ProductId, product_name, data.Price, data.Qty, price_total, data.SDate); } //order.Rows.Add(1, "1", "Satu", 10000, 1, 100000, DateTime.Now); //order.Rows.Add(2, "2", "Dua", 10003, 1, 100000, DateTime.Now); //order.Rows.Add(3, "3", "Tiga", 10002, 1, 100000, DateTime.Now); //order.Rows.Add(4, "4", "Empat", 10004, 1, 100000, DateTime.Now); //order.Rows.Add(5, "5", "Lima", 100005, 1, 100000, DateTime.Now); } crptOrderList crpt = new crptOrderList(); crpt.Database.Tables["Order"].SetDataSource(order); crvList.ReportSource = null; crvList.ReportSource = crpt; }
private void btnInsert_Click(object sender, EventArgs e) { try { //panel1.Enabled = true; //txtCustomerID.Focus(); //Customer c = new Customer(); //supermarket.Customers.Add(c); //customerBindingSource.MoveLast(); using (var supermarket = new SuperEntities()) { var customer_id = txtCustomerID.Text; var fullname = txtFullName.Text; var email = txtEmail.Text; var address = txtAddress.Text; var st = new SupermarketFIX.Customer { CustomerID = customer_id, FullName = fullname, Email = email, Address = address }; supermarket.Customers.Add(st); supermarket.SaveChanges(); MessageBox.Show("Succesfully Inserted"); LoadData(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LoadRecords() { using (var context = new SuperEntities()) { gridCustomer.Rows.Clear(); var customers = (from s in context.Customers select s); var products = (from p in context.ProductInfo_Tab select p); //int index = 0; foreach (var customer in customers) { //++index; gridCustomer.Rows.Add(customer.CustomerID, customer.FullName, customer.Email, customer.Address); } //index = 0; foreach (var product in products) { //++index; gridProduct.Rows.Add(product.ProductID, product.itemName, product.Categories, product.Price, "Select"); } } }
/// <summary> /// Login Application /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { using (var context = new SuperEntities()) { var user = from login in context.tbl_Login where login.username.Equals(txtUsername.Text.Trim().ToLower()) && login.password.Equals(txtPassword.Text.Trim()) select login; if (user.Count() > 0) { Form1 objForm1 = new Form1(); this.Hide(); objForm1.Show(); } else { MessageBox.Show("Check your username and password"); } } //SqlConnection sqlcon = new SqlConnection(@"Data Source=MIILENOVO\SQLEXPRESS;Initial Catalog=Supermarket;Integrated Security=True"); //string query = "Select*from tbl_Login where username ='******' and password = '******'"; //SqlDataAdapter sda = new SqlDataAdapter(query, sqlcon); //DataTable dtbl = new DataTable(); //sda.Fill(dtbl); //if (dtbl.Rows.Count == 1) //{ // Form1 objForm1 = new Form1(); // this.Hide(); // objForm1.Show(); //} //else //{ // MessageBox.Show("Check your username and password"); //} }
private void btnSave_Click(object sender, EventArgs e) { var transno = lblTransno.Text; var customerid = gridCustomer.CurrentRow.Cells[0]; using (var context = new SuperEntities()) { foreach (DataGridViewRow row in gridOrder.Rows) { if (row.IsNewRow) { continue; } var product_id = row.Cells[0].Value.ToString(); var item_name = row.Cells[1].Value.ToString(); var price = row.Cells[2].Value.ToString(); var quantity = row.Cells[3].Value.ToString(); var price_total = row.Cells[4].Value.ToString(); var order = new Order(); order.TransNo = transno; order.ProductId = int.Parse(product_id); order.Price = int.Parse(price); order.Qty = int.Parse(quantity); order.Total = int.Parse(price_total); order.SDate = DateTime.Now; context.Orders.Add(order); context.SaveChanges(); } } gridOrder.Rows.Clear(); gridOrder.Refresh(); GetTransNo(); }