/// <summary> /// 주문 메뉴 별 서빙 완료 여부 갱신 /// </summary> /// <param name="index">테이블 번호</param> private void OrderDetailDBUpdate(int index) { using (EATSEntities db = new EATSEntities()) { List <MenuInfo> orderList = new List <MenuInfo>(); switch (index) { case 1: orderList = menuTable1; break; case 2: orderList = menuTable2; break; case 3: orderList = menuTable3; break; case 4: orderList = menuTable4; break; } // orderList : 오더 코드, 메뉴명, 수량 foreach (var item in orderList) { db.OrderDetailtbl.FirstOrDefault(o => o.idx.Equals(item.OrderIdx)).OrderComplete = true; } db.SaveChanges(); } }
private void dataGridView3_MouseClick(object sender, MouseEventArgs e) { DialogResult result = MessageBox.Show("서빙하시겠습니까?", "서빙", MessageBoxButtons.YesNo); var orderCode = "20210802005"; if (result == DialogResult.Yes) { using (EATSEntities db = new EATSEntities()) { var results = db.OrderDetailtbl.Where(o => o.OrderCode == orderCode).ToList(); foreach (var item in results) { if (item != null) { item.OrderComplete = true; } } if (db.SaveChanges() != 0) { MessageBox.Show("서빙 완료"); DatagridRefresh(); return; } else { MessageBox.Show("데이터 입력 실패(주문 없음)"); } } } }
public static int SetMenu(Menutbl menu) { using (var ctx = new EATSEntities()) { ctx.Menutbl.AddOrUpdate(menu); return(ctx.SaveChanges()); // commit } }
public static int SetOrder(Ordertbl order) { using (var ctx = new EATSEntities()) { ctx.Ordertbl.AddOrUpdate(order); return(ctx.SaveChanges()); // commit } }
internal static int SetOrderDetail(OrderDetailtbl item) { using (var ctx = new EATSEntities()) { ctx.OrderDetailtbl.AddOrUpdate(item); return(ctx.SaveChanges()); // return 1 or 0 } }
internal static int SetMenuActive(Menutbl menuName) { using (var ctx = new EATSEntities()) { ctx.Menutbl.AddOrUpdate(menuName); return(ctx.SaveChanges()); } }
/// <summary> /// DB에 테이블 현재 사용 여부를 갱신 /// </summary> /// <param name="tblNum">테이블 번호</param> private void TableSetEmpty(int tblNum) { using (EATSEntities db = new EATSEntities()) { Ordertbl useTable = db.Ordertbl.Where(o => o.TableInUse && o.TblNum == tblNum).FirstOrDefault(); if (useTable != null) { useTable.TableInUse = false; } db.SaveChanges(); } }
// 주문 1 : 삼겹살 2인분 + 목살 2인분 + 콜라 1캔 private void btnOrderCommit1_Click(object sender, EventArgs e) { using (EATSEntities db = new EATSEntities()) { // 가장 최근 오더 번호 var lastOrder = db.Ordertbl.OrderByDescending(u => u.OrderCode).Take(1).ToList()[0].OrderCode; // 20210802005 // 최신 오더 뒤 3자리 추출하고 정수로 변환하여 + 1 int num = int.Parse(lastOrder.Substring(8)) + 1; // "20210802003" -> 4 // 오더 번호 생성 var orderCode = DateTime.Today.ToString("yyyyMMdd") + num.ToString("D3"); // Order 1 line (OrderCode, OrderTime, CustomerNum, TblNum, OrderPrice, OrderRemark) // 키오스크로부터 인원수, 테이블 번호, 결제 금액을 받아와서 입력 var order = new Ordertbl() { OrderCode = orderCode, OrderTime = DateTime.Now, CustomerNum = "4", TblNum = 4, OrderPrice = 20000, OrderRemark = null }; db.Ordertbl.Add(order); // OrderDetail 3 line (OrderCode, MenuCode, Amount) // 키오스크로부터 메뉴와 수량 받아와서 처리 (임시 입력) int menuCount = 3; // 3종류 string[] menu = { "M001", "M002", "B001" }; // 메뉴 종류 int[] amount = { 2, 2, 1 }; // 각 메뉴 수량 for (int i = 0; i < menuCount; i++) { var orderDetail = new OrderDetailtbl() { OrderCode = orderCode, MenuCode = menu[i], Amount = amount[i] }; db.OrderDetailtbl.Add(orderDetail); } db.SaveChanges(); } }
/// <summary> /// DB에 주문 내역 저장 /// </summary> /// <param name="orderCode">고유 주문 번호</param> private void SaveOrderToDB(string orderCode) { using (EATSEntities db = new EATSEntities()) { var menus = DataAccess.GetMenu(); if (db.Ordertbl.Count(o => o.OrderCode.Equals(orderCode)) == 0) { var order = new Ordertbl() { OrderCode = orderCode, OrderTime = DateTime.Now, TblNum = TableNum, OrderPrice = totalPrice, // TODO : 계산식 추가 TableInUse = true, OrderRemark = null // TODO : 주문 특이사항 이후 추가 }; db.Ordertbl.Add(order); } foreach (var item in menuList) { var orderDetail = new OrderDetailtbl() { OrderCode = orderCode, MenuCode = menus.FirstOrDefault(m => m.MenuName.Equals(item.MenuName)).MenuCode, Amount = item.Amount, OrderComplete = false }; db.OrderDetailtbl.Add(orderDetail); } if (db.SaveChanges() > 0) { MessageBox.Show("주문 완료", "Complete"); } else { MessageBox.Show("주문 실패, 관리자에게 문의!", "Fail"); } } }
/// <summary> /// 주문을 DB에 저장 /// </summary> private void SaveDB() { using (EATSEntities db = new EATSEntities()) { // DB에 저장된 가장 최신 주문 var lastOrder = db.Ordertbl.OrderByDescending(u => u.OrderCode).Take(1).ToList()[0].OrderCode; // 새로운 주문번호 생성 int num = int.Parse(lastOrder.Substring(8)) + 1; string orderCode = DateTime.Today.ToString("yyyyMMdd") + num.ToString("D3"); // 주문 객체 생성 var order = new Ordertbl() { OrderCode = orderCode, OrderTime = DateTime.Now, CustomerNum = customerNum, TblNum = tableNum, OrderPrice = price, OrderRemark = null }; // DB에 주문 추가 db.Ordertbl.Add(order); if (numMainMenu.Value > 0 && cboMainMenu.SelectedIndex > -1) { OrderDetailtbl orderDetail = new OrderDetailtbl() { OrderCode = orderCode, MenuCode = DataAccess.GetMenus().FirstOrDefault(m => m.MenuName.Equals(cboMainMenu.SelectedValue.ToString())).MenuCode, Amount = (int)numMainMenu.Value }; db.OrderDetailtbl.Add(orderDetail); } if (numSideMenu.Value > 0 && cboSideMenu.SelectedIndex > -1) { OrderDetailtbl orderDetail = new OrderDetailtbl() { OrderCode = orderCode, MenuCode = DataAccess.GetMenus().FirstOrDefault(m => m.MenuName.Equals(cboSideMenu.SelectedValue.ToString())).MenuCode, Amount = (int)numSideMenu.Value }; db.OrderDetailtbl.Add(orderDetail); } if (numBeverage.Value > 0 && cboBeverage.SelectedIndex > -1) { OrderDetailtbl orderDetail = new OrderDetailtbl() { OrderCode = orderCode, MenuCode = DataAccess.GetMenus().FirstOrDefault(m => m.MenuName.Equals(cboBeverage.SelectedValue.ToString())).MenuCode, Amount = (int)numBeverage.Value }; db.OrderDetailtbl.Add(orderDetail); } if (db.SaveChanges() > 0) { MessageBox.Show("DB 저장 성공!"); } else { MessageBox.Show("DB 저장 실패!"); } } }