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 dgv_ShowUp_CellClick(object sender, DataGridViewCellEventArgs e) { lb_FoodId.Text = dgv_ShowUp.CurrentRow.Cells["FoodId"].Value.ToString(); foodId = lb_FoodId.Text; lb_FoodName.Text = dgv_ShowUp.CurrentRow.Cells["FoodName"].Value.ToString(); foodName = lb_FoodName.Text; //lb_CategoryName.Text = dgv_ShowUp.CurrentRow.Cells["CategoryName"].Value.ToString(); categoryDTO dto = new categoryDTO(); dto.categoryId = dgv_ShowUp.CurrentRow.Cells["CategoryId"].Value.ToString(); foodBO bo = new foodBO(); DataSet result = bo.getCategoryNameByID(dto); lb_CategoryName.Text = result.Tables[0].Rows[0][0].ToString(); categoryName = lb_CategoryName.Text; System.Byte[] arr = (dgv_ShowUp.CurrentRow.Cells["FoodPicture"].Value) as System.Byte[]; foodPicture = arr; MemoryStream stream = new MemoryStream(arr); Image img = Image.FromStream(stream); pb_FoodPicture.Image = img; int Price = int.Parse(dgv_ShowUp.CurrentRow.Cells["FoodPrice"].Value.ToString()); lb_FoodPrice.Text = String.Format("{0:n0}", Price); foodPrice = Price; }
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 void Loading_Food() { foodBO bo = new foodBO(); DataSet result = bo.getAllFood(); dgv_ShowUp.DataSource = result.Tables[0]; lb_FoodId.Text = ""; lb_FoodName.Text = ""; lb_CategoryName.Text = ""; pb_FoodPicture.Image = null; lb_FoodPrice.Text = ""; }
private void Loading_Form() { foodBO bo = new foodBO(); DataSet result = bo.getAllCategory(); if (result.Tables[0].Rows.Count > 0 && result.Tables.Count > 0) { for (int i = 0; i < result.Tables[0].Rows.Count; i++) { //cb_CategoryName.Items.Add(result.Tables[0].Rows[i][1].ToString()); Category.Add(new categoryDTO { categoryId = result.Tables[0].Rows[i][0].ToString(), categoryName = result.Tables[0].Rows[i][1].ToString() }); cb_CategoryName.Items.Add(Category[i].categoryName); } } }
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); } }
private void loadingFood() { foodBO bo = new foodBO(); DataSet result = bo.getAllCategory(); for (int i = 0; i < result.Tables[0].Rows.Count; i++) { Category.Add(new categoryDTO { categoryId = result.Tables[0].Rows[i][0].ToString(), categoryName = result.Tables[0].Rows[i][1].ToString() }); cb_CategoryName.Items.Add(Category[i].categoryName); } txt_FoodId.Text = Food_Form.foodId; txt_FoodName.Text = Food_Form.foodName; cb_CategoryName.Text = Food_Form.categoryName; System.Byte[] arr = Food_Form.foodPicture; MemoryStream stream = new MemoryStream(arr); Image img = Image.FromStream(stream); pb_FoodPicture.Image = img; }
private void btn_Edit_Click(object sender, EventArgs e) { if (checkingBeforeClickEditOrDelete() == true) { Edit_Food_Form edit = new Edit_Food_Form(); edit.ShowDialog(); Loading_Food(); lb_FoodId.Text = dgv_ShowUp.CurrentRow.Cells["FoodId"].Value.ToString(); foodId = lb_FoodId.Text; lb_FoodName.Text = dgv_ShowUp.CurrentRow.Cells["FoodName"].Value.ToString(); foodName = lb_FoodName.Text; string categoryId = dgv_ShowUp.CurrentRow.Cells["CategoryId"].Value.ToString(); foodBO bo = new foodBO(); categoryDTO dto = new categoryDTO(); dto.categoryId = categoryId; DataSet result = bo.getCategoryNameByID(dto); lb_CategoryName.Text = result.Tables[0].Rows[0][0].ToString(); System.Byte[] arr = (dgv_ShowUp.CurrentRow.Cells["FoodPicture"].Value) as System.Byte[]; foodPicture = arr; MemoryStream stream = new MemoryStream(arr); Image img = Image.FromStream(stream); pb_FoodPicture.Image = img; int Price = int.Parse(dgv_ShowUp.CurrentRow.Cells["FoodPrice"].Value.ToString()); lb_FoodPrice.Text = String.Format("{0:n0}", Price); foodPrice = Price; } else { MessageBox.Show("Vui lòng chọn danh mục để thực hiện sửa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }; } }