public static bool addOrder(List <Order_Received> listOrder_Received) { try { string conn = @"Data Source=LAPTOP\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; POSDBDataContext DB = new POSDBDataContext(conn); Order order = new Order(); order.Date = DateTime.Now; foreach (var item in listOrder_Received) { Order_Detail details = new Order_Detail(); //{ Product_ID = item.Product_ID, Quantity = item.Quantity, Order = order };\ details.Product_ID = item.Product_ID; details.Quantity = item.Quantity; details.Order = order; DB.Order_Details.InsertOnSubmit(details); } DB.SubmitChanges(); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static bool addFood(Product product) { try { string conn = @"Data Source=LAPTOP\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; POSDBDataContext DB = new POSDBDataContext(conn); DB.Products.InsertOnSubmit(product); DB.SubmitChanges(); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
public static int getLastFilename() { try { string conn = @"Data Source=LAPTOP\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; POSDBDataContext DB = new POSDBDataContext(conn); int result = (from t in DB.Products orderby t.ID descending select t.ID).First(); return(result); } catch (Exception ex) { throw new Exception(ex.Message); } }
private void BindGrid() { Response.Write(date.Text); string datet = DateTime.Now.ToShortDateString(); Response.Write(DateTime.Parse(datet)); POSDBDataContext DB = new POSDBDataContext(Cache["ConnectionString"].ToString()); var showOrder = (from orders in DB.Orders join orderDetails in DB.Order_Details on orders.ID equals orderDetails.Order_ID join pro in DB.Products on orderDetails.Product_ID equals pro.ID where orders.Date.Value.Date.Equals(DateTime.Parse(date.Text)) select new { OrderDetailsID = orderDetails.ID, Name = pro.Name, Sale = pro.Sale_Price, Quantity = orderDetails.Quantity, SubTotal = pro.Sale_Price * orderDetails.Quantity }); var sum = showOrder.Select(x => x.SubTotal).Sum(); totalSalesAmount.Text = sum.ToString(); gridView.DataSource = showOrder; gridView.DataBind(); }
private void GridBind() { List <Order> list = (List <Order>)Cache["orders"]; int selectedIndex = (int)ViewState["selectedIndex"]; Order ord = list.ElementAt(selectedIndex); POSDBDataContext DB = new POSDBDataContext(Cache["ConnectionString"].ToString()); var query = (from orders in DB.Orders join orderDetails in DB.Order_Details on orders.ID equals orderDetails.Order_ID join pro in DB.Products on orderDetails.Product_ID equals pro.ID where orderDetails.Order_ID.Equals(ord.ID) select new { OrderID = orders.ID, Name = pro.Name, Sale = pro.Sale_Price, Quantity = orderDetails.Quantity, SubTotal = pro.Sale_Price * orderDetails.Quantity }); //Response.Write(query.Count()); var sum = query.Select(x => x.SubTotal).Sum(); totalAmount.Text = sum.ToString(); gridView.DataSource = query; gridView.DataBind(); }
private void Image_Click(object sender, ImageClickEventArgs e) { if (ViewState["listOrder_Received"] != null) { listOrder_Received = (List <Order_Received>)ViewState["listOrder_Received"]; } POSDBDataContext DB = new POSDBDataContext(Cache["ConnectionString"].ToString()); ImageButton image = sender as ImageButton; int productID = int.Parse(image.ID); bool flag = false; if (listOrder_Received.Count > 0) { foreach (var item in listOrder_Received) { if (item.Product_ID == productID) { item.Quantity++; item.SubTotal = item.Quantity * item.Price; // flag = true; break; } } } if (flag == false) { var product = (from ee in DB.Products where ee.Status.Equals(true) && ee.ID == productID select ee).FirstOrDefault(); //Order_Detail orderDetails = new Order_Detail() { Product = product, Quantity =1 }; int serial = (int)ViewState["orderSerial"]; ViewState["orderSerial"] = ++serial; Order_Received obj = new Order_Received() { Price = (double)product.Sale_Price, Product_ID = product.ID, Name = product.Name, SL = serial, Quantity = 1, SubTotal = (double)product.Sale_Price }; listOrder_Received.Add(obj); } //Response.Write(listOrder_Received.Count); ViewState["listOrder_Received"] = listOrder_Received; BindGrid(); }
public static bool removeFood(int productID) { try { POSDBDataContext DB = new POSDBDataContext(conn); var pro = (from ee in DB.Products where ee.ID == productID select ee).ToList(); if (pro.Count == 1) { DB.Products.DeleteOnSubmit(pro.First()); DB.SubmitChanges(); } return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
private void orderList() { Response.Write(date.Text); POSDBDataContext DB = new POSDBDataContext(Cache["ConnectionString"].ToString()); var orders = (from ee in DB.Orders where ee.Date.Value.Date.Equals(DateTime.Parse(date.Text)) select ee).ToList(); //Response.Write(orders.Count); if (orders.Count <= 0) { msg.Visible = true; return; } else { msg.Visible = false; Cache["orders"] = orders; ViewState["selectedIndex"] = orders.Count - 1; GridBind(); } }
protected void Page_Load(object sender, EventArgs e) { string connStr = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; string connectionString = @"Data Source=LAPTOP\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; Cache["ConnectionString"] = connectionString; POSDBDataContext db = new POSDBDataContext(connectionString); var query = (from ee in db.Products where ee.Status.Equals(true) select ee).ToList(); int rowCount = query.Count(); double numbeofSubTables = (rowCount / 4.0); bool isInt = numbeofSubTables % 1 == 0; //checking int or not if (!isInt) //if not int then add 1 to make table { numbeofSubTables += 1; } numbeofSubTables = (int)numbeofSubTables; int numberOfLastSubTableColumn = rowCount % 4; int imageCount = 0; int imageNameCount = 0; for (int i = 1; i <= numbeofSubTables; i++) { Table subTable = new Table(); subTable.CellSpacing = 10; //subTable.CellPadding = 10; //subTable.BorderWidth = 1; TableRow row1 = new TableRow(); row1.HorizontalAlign = HorizontalAlign.Center; subTable.Rows.Add(row1); for (int j = 0; j < 4; j++) { TableCell cell = new TableCell(); row1.Cells.Add(cell); ImageButton image = new ImageButton(); image.ID = query[imageCount].ID.ToString(); image.ImageUrl = "~/Pictures/" + query[imageCount].Image; image.Width = 170; image.Click += Image_Click; cell.Controls.Add(image); imageCount++; if (i == numbeofSubTables && j == numberOfLastSubTableColumn - 1) { break; } } TableRow row2 = new TableRow(); row2.HorizontalAlign = HorizontalAlign.Center; subTable.Rows.Add(row2); for (int j = 0; j < 4; j++) { TableCell cell = new TableCell(); row2.Cells.Add(cell); Label label = new Label(); label.Text = query[imageNameCount].Name; cell.Controls.Add(label); imageNameCount++; if (i == numbeofSubTables && j == numberOfLastSubTableColumn - 1) { break; } } foodSelectionPanel.Controls.Add(subTable); } if (!IsPostBack) { //listOrder_Received = new List<Order_Received>(); ViewState["orderSerial"] = 0; //ViewState["listOrder_Received"] = listOrder_Received; orderGridView.DataSource = listOrder_Received; orderGridView.DataBind(); } }