private void btnSuaMon_Click(object sender, EventArgs e) { MonDTO mon = new MonDTO(); mon.MaMon = Convert.ToInt32(txtMaMon.Text); mon.TenMon = txtTenMon.Text; mon.LoaiMon = Convert.ToInt32(cmbLoaiMon.SelectedValue); if (openFileDialog1.FileName != "") { string tenFile = DateTime.Now.ToFileTime() + "_" + mon.MaMon; string extension = Path.GetExtension(openFileDialog1.SafeFileName); mon.Hinh = tenFile + extension; File.Copy(openFileDialog1.FileName, "img\\products\\" + tenFile + extension); } else { if (picHinhMon.Image != Properties.Resources.user_account) { mon.Hinh = dgvMon.CurrentRow.Cells["colHinh"].Value.ToString(); } } if (txtGiaTienMon.Text != "") { mon.GiaTien = Convert.ToDouble(txtGiaTienMon.Text); } else { mon.GiaTien = 0; } mon.TrangThai = true; if (MonBUS.SuaMon(mon)) { MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LamMoiMon(); QLM_LoadDanhSachMon(GetTimKiemMon(), Convert.ToInt32(cmbTimKiemTheoLoaiMon.SelectedValue)); dgvMon.ClearSelection(); } else { MessageBox.Show("Sửa thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); mon = null; } }
private void btnCapNhat_Click(object sender, EventArgs e) { if (txtTenMon.Text == "" || txtDonGia.Text == "" || cboLoaiMon.SelectedValue.ToString() == "" || chkTrangThai.Checked == false) { MessageBox.Show("Bạn chưa nhập đầy đủ hoặc bỏ trống thông tin món ăn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { MonDTO mon = new MonDTO(); mon.MaMon = txtMaMon.Text; mon.MaLoaiMon = cboLoaiMon.SelectedValue.ToString(); mon.TenMon = txtTenMon.Text; mon.DonGia = Convert.ToInt32(txtDonGia.Text); if (openFileDialog1.FileName != "") { string fileName = txtMaMon.Text + '_' + DateTime.Now.ToFileTime() + ".jpg"; mon.HinhAnh = fileName; File.Copy(openFileDialog1.FileName, "image\\" + fileName, true); } else { string fileName = MonBUS.LayTenHinhHienTai(txtMaMon.Text); mon.HinhAnh = fileName; } mon.TrangThai = chkTrangThai.Checked; if (MonBUS.SuaMon(mon)) { //MessageBox.Show("Cập nhật món ăn thành công","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.None); LamMoi(); LoadDSMon(); XoaForm(true); } else { MessageBox.Show("Cập nhật món ăn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); mon = null; } } }