Example #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (mon == null)
            {
                if (txtTenMon.Text == "" || txtDonGia.Text == "" || cboLoaiMon.SelectedValue.ToString() == "" || chkTrangThai.Checked == false || picHinh.Image == null)
                {
                    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;
                    if (txtDonGia.Text == "")
                    {
                        mon.DonGia = 0;
                    }
                    else
                    {
                        mon.DonGia = Convert.ToInt32(txtDonGia.Text);
                    }

                    mon.TrangThai = chkTrangThai.Checked;
                    if (openFileDialog1.FileName != "") // Kiểm tra chọn file chưa
                    {
                        string fileName  = txtMaMon.Text + "_" + DateTime.Now.ToFileTime();
                        string extension = Path.GetExtension(openFileDialog1.FileName);
                        mon.HinhAnh = fileName + extension;
                    }

                    if (MonBUS.ThemMon(mon))
                    {
                        File.Copy(openFileDialog1.FileName, "image\\" + mon.HinhAnh, true);
                        //MessageBox.Show("Thêm món ăn mới thành công","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.None);
                        LamMoi();
                        LoadDSMon();
                        XoaForm(true);
                    }
                    else
                    {
                        MessageBox.Show("Thêm món ăn thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        mon = null;
                    }
                }
            }
        }
        private void btnThemMon_Click(object sender, EventArgs e)
        {
            if (txtTenMon.Text == "")
            {
                MessageBox.Show("Vui lòng nhập đủ thông tin!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            MonDTO mon = new MonDTO();

            mon.TenMon  = txtTenMon.Text;
            mon.LoaiMon = Convert.ToInt32(cmbLoaiMon.SelectedValue);
            if (openFileDialog1.FileName != "")
            {
                string tenFile   = DateTime.Now.ToFileTime() + "_" + (MonBUS.LayMaMonMoiNhat() + 1).ToString();
                string extension = Path.GetExtension(openFileDialog1.SafeFileName);
                mon.Hinh = tenFile + extension;
                File.Copy(openFileDialog1.FileName, "img\\products\\" + tenFile + extension, true);
            }
            if (txtGiaTienMon.Text != "")
            {
                mon.GiaTien = Convert.ToDouble(txtGiaTienMon.Text);
            }
            else
            {
                mon.GiaTien = 0;
            }
            mon.TrangThai = true;

            if (MonBUS.ThemMon(mon))
            {
                MessageBox.Show("Thêm 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("Thêm thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                mon = null;
            }
        }