private void loadingFoodByCategoryId(object sender, EventArgs e, string categoryId) { flp_Food.Controls.Clear(); foodBO bo = new foodBO(); foodDTO dto = new foodDTO(); dto.categoryId = categoryId; DataSet result = bo.getFoodByCategoryId(dto); for (int i = 0; i < result.Tables[0].Rows.Count; i++) { Food foodUC = new Food(); foodUC.CATEGORYID = categoryId; foodUC.FOODID = result.Tables[0].Rows[i][0].ToString(); foodUC.FOODNAME = result.Tables[0].Rows[i][1].ToString(); foodUC.FOODPRICE = int.Parse(result.Tables[0].Rows[i][4].ToString()); System.Byte[] arr = (result.Tables[0].Rows[i][3]) as System.Byte[]; foodUC.FOODPICTURE = arr; flp_Food.Controls.Add(foodUC); foreach (Control control in foodUC.Controls) { control.Click += (sender1, e1) => { addFood(sender1, e1, foodUC.FOODID, foodUC.FOODPRICE); }; } } }
private void btn_Delete_Click(object sender, EventArgs e) { if (checkingBeforeClickEditOrDelete() == true) { DialogResult result = MessageBox.Show("Bạn có muốn xóa danh mục " + lb_CategoryName.Text + " này không ?, Việc này không thể khôi phục lại dữ liệu, Bạn chắc chứ ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { foodDTO dto = new foodDTO(); dto.foodId = lb_FoodId.Text; foodBO bo = new foodBO(); int result1 = bo.deleteFood(dto); if (result1 != -1) { MessageBox.Show("Đã xóa thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Loading_Food(); } else { MessageBox.Show("Đã có lỗi trong quá trình xóa, vui lòng kiểm tra lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Vui lòng chọn trước khi xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public DataSet getFoodByCategoryId(foodDTO dto) { DataSet result = new DataSet(); string query = "SELECT * FROM Food WHERE CategoryId=@categoryId"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@categoryId", dto.categoryId) }; DataAccess data = new DataAccess(); result = data.GetDataSet(query, para); return(result); }
public DataSet getFoodByFoodId(foodDTO dto) { DataSet result = new DataSet(); string query = @"SELECT FoodName FROM Food WHERE FoodId = @FoodId "; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@FoodId", dto.foodId), }; DataAccess data = new DataAccess(); result = data.GetDataSet(query, para); return(result); }
public int deleteFood(foodDTO dto) { int result = -1; string query = @"DELETE FROM Food Where foodId = @FoodId"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@FoodId", dto.foodId), }; DataAccess data = new DataAccess(); result = data.Execute(query, para); return(result); }
private void btn_Add_Click(object sender, EventArgs e) { if (checkingBeforeEdit() == true) { foodDTO dto = new foodDTO(); dto.foodId = txt_FoodId.Text; dto.foodName = txt_FoodName.Text; dto.categoryId = getIdFromList(cb_CategoryName.Text); if (fileFoodName == "") { System.Byte[] arr = Food_Form.foodPicture; dto.foodPicture = arr; } else { Image img = Image.FromFile(fileFoodName); MemoryStream stream = new MemoryStream(); img.Save(stream, ImageFormat.Jpeg); stream.Seek(0, SeekOrigin.Begin); byte[] imgByte = System.IO.File.ReadAllBytes(fileFoodName); int sizeImg = imgByte.Length; stream.Read(imgByte, 0, sizeImg); //done dto.foodPicture = imgByte; } foodBO bo = new foodBO(); int result = bo.editFood(dto); if (result == -1) { MessageBox.Show("Có lỗi xảy ra, vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { MessageBox.Show("Vui lòng điền đầy đủ thông tin", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public int addFood(foodDTO dto) { int result = -1; string query = @"INSERT INTO Food VALUES(@FoodId, @FoodName, @CategoryId, @FoodPicture, @FoodPrice)"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@FoodId", dto.foodId), new SqlParameter("@FoodName", dto.foodName), new SqlParameter("@CategoryId", dto.categoryId), new SqlParameter("@FoodPicture", dto.foodPicture), new SqlParameter("@FoodPrice", dto.foodPrice), }; DataAccess data = new DataAccess(); result = data.Execute(query, para); return(result); }
public int editFood(foodDTO dto) { int result = -1; string query = @"UPDATE Food SET foodName = @foodName, foodPicture = @foodPicture, categoryId = @categoryId, foodPrice = @foodPrice WHERE foodId = @foodId"; SqlParameter[] para = new SqlParameter[] { new SqlParameter("@foodId", dto.foodId), new SqlParameter("@foodName", dto.foodName), new SqlParameter("@foodPicture", dto.foodPicture), new SqlParameter("@categoryId", dto.categoryId), new SqlParameter("@foodPrice", dto.foodPrice), }; DataAccess data = new DataAccess(); result = data.Execute(query, para); return(result); }
private void btn_Add_Click(object sender, EventArgs e) { if (checkingBeforeSubmit() == true) { foodDTO dto = new foodDTO(); dto.foodId = txt_FoodId.Text; dto.foodName = txt_FoodName.Text; dto.categoryId = getIdFromList(cb_CategoryName.Text); dto.foodPrice = changingStringToInt(mtxt_FoodPrice.Text); //image processing Image img = Image.FromFile(fileFoodName); MemoryStream stream = new MemoryStream(); img.Save(stream, ImageFormat.Jpeg); stream.Seek(0, SeekOrigin.Begin); byte[] imgByte = System.IO.File.ReadAllBytes(fileFoodName); int sizeImg = imgByte.Length; stream.Read(imgByte, 0, sizeImg); //done dto.foodPicture = imgByte; // foodBO bo = new foodBO(); int result = bo.addFood(dto); if (result == -1) { MessageBox.Show("Có lỗi xảy ra, vui lòng kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); Reset(); } } else { MessageBox.Show("Vui lòng điền thông tin đầy đủ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void loadingBillDetails() { lb_NAME.Text = userlogin.NAME; lb_BillId.Text = billid; billDTO dto = new billDTO(); dto.billId = billid; billBO bo = new billBO(); DataSet result = new DataSet(); result = bo.getBillInfoByBillId(dto); string tableId = ""; // Point initPoint = new Point(0, 0); if (result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0) { for (int i = 0; i < result.Tables[0].Rows.Count; i++) { foodDTO fooddto = new foodDTO(); fooddto.foodId = result.Tables[0].Rows[i][2].ToString(); foodBO foodbo = new foodBO(); DataSet foodTable = new DataSet(); foodTable = foodbo.getFoodByFoodId(fooddto); BillInfo info = new BillInfo(); info.FOODNAME = foodTable.Tables[0].Rows[0][0].ToString(); info.FOODPRICE = int.Parse(result.Tables[0].Rows[i][5].ToString()); info.QUANTITY = int.Parse(result.Tables[0].Rows[i][4].ToString()); int y = 50 * i; info.Location = new Point(0, y); this.pl_BillDetals.Controls.Add(info); } tableId = result.Tables[0].Rows[0][6].ToString().Trim(); Label lb_characters = new Label(); Label lb_TotalText = new Label(); Label lb_Total = new Label(); lb_characters.Text = "--------------------------------------------------------------------------"; lb_characters.Font = new Font("Times New Roman", 11.0f, FontStyle.Bold); lb_characters.Location = new Point(32, pl_BillDetals.Location.Y + pl_BillDetals.Size.Height + 20); lb_characters.AutoSize = true; this.Controls.Add(lb_characters); lb_TotalText.Text = "Tổng cộng:"; lb_TotalText.Font = new Font("Times New Roman", 15.0f, FontStyle.Bold); lb_TotalText.Location = new Point(210, lb_characters.Location.Y + 20); lb_TotalText.AutoSize = true; this.Controls.Add(lb_TotalText); lb_Total.Text = String.Format("{0:n0}", total); lb_Total.Font = new Font("Times New Roman", 15.0f, FontStyle.Bold); lb_Total.Location = new Point(310, lb_TotalText.Location.Y); lb_Total.AutoSize = true; this.Controls.Add(lb_Total); //Payment Button Button btn_Payment = new Button(); btn_Payment.Text = "Thanh toán"; btn_Payment.Font = new Font("Times New Roman", 15.0f, FontStyle.Bold); btn_Payment.Location = new Point(32, lb_TotalText.Location.Y - 10); btn_Payment.Size = new Size(150, 50); //btn_Payment.AutoSize = true; btn_Payment.BackColor = Color.Blue; this.Controls.Add(btn_Payment); //Handle Button Payment click btn_Payment.Click += (sender, e) => { if (userlogin.POSITION == "QUANLY" || userlogin.POSITION == "THUNGAN") { paymentEvent(sender, e, billid, tableId); } else { MessageBox.Show("Bạn không có quyền này", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }; } }