Пример #1
0
        private void btRemove1_Click(object sender, EventArgs e)
        {
            if (dgvHDCT.Rows.Count > 1)
            {
                dgvHDCT.CurrentRow.Selected = true;
                int rowindex = dgvHDCT.SelectedRows[0].Index;

                DTO_ThucDon selectTD = busTD.curTD(dgvHDCT.Rows[rowindex].Cells["Column1"].FormattedValue.ToString());
                if (busBan.DeleteCTHDSoluong(lbMaHD.Text, selectTD.MaTD, 1))
                {
                    try
                    {
                        DTO_CTHD curCTHD = busBan.curCTHD(lbMaHD.Text, selectTD.MaTD);
                        if (!(curCTHD is null))
                        {
                            dgvHDCT.ReadOnly = false;
                            dgvHDCT.SelectedRows[0].Cells["Column2"].Value = curCTHD.SoLuong;
                            dgvHDCT.ReadOnly = true;
                        }
                        else
                        {
                            LoadCTHD();
                            if (dgvHDCT.Rows.Count > 1)
                            {
                                dgvHDCT.CurrentRow.Selected = true;
                                selectTD = busTD.curTD(dgvHDCT.SelectedRows[0].Cells[0].FormattedValue.ToString());
                            }
                        }
                    }
Пример #2
0
        public bool ThemThucDon(DTO_ThucDon td)
        {
            try
            {
                _conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = _conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Sp_InsertTD";
                cmd.Parameters.AddWithValue("tenTD", td.TenTD);
                cmd.Parameters.AddWithValue("GiaBan", td.GiaBan);
                cmd.Parameters.AddWithValue("hinhAnh", td.Hinh);
                cmd.Parameters.AddWithValue("nhom", td.Nhom);
                cmd.Parameters.AddWithValue("mota", td.MoTa);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }

            finally
            {
                _conn.Close();
            }
            return(false);
        }
Пример #3
0
        public bool CapNhatThucDon(string maThucDon, DTO_ThucDon td)
        {
            try
            {
                _conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection  = _conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "Sp_UpdateTD";
                cmd.Parameters.AddWithValue("maTD", maThucDon);
                cmd.Parameters.AddWithValue("tenTD", td.TenTD);
                cmd.Parameters.AddWithValue("GiaBan", td.GiaBan);
                cmd.Parameters.AddWithValue("hinhAnh", td.Hinh);
                cmd.Parameters.AddWithValue("nhom", td.Nhom);
                cmd.Parameters.AddWithValue("mota", td.MoTa);

                if (cmd.ExecuteNonQuery() > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                _conn.Close();
            }
            return(false);
        }
Пример #4
0
        private void btEnable_Click(object sender, EventArgs e)
        {
            DTO_ThucDon  td     = busThucDon.curTD(DgvThucDon.CurrentRow.Cells["TenTD"].Value.ToString());
            DialogResult result = MessageBox.Show("Bạn có chắc chắn muốn cập nhật trạng thái của thực đơn không?", "Cập nhật", MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                if (busThucDon.CapNhatTrangThaiTD(td.MaTD))
                {
                    MessageBox.Show(td.TenTD + " đã được hoạt động lại");
                    DgvThucDon.DataSource = busThucDon.DanhSachThucDonAll();

                    foreach (DataGridViewRow dr in DgvThucDon.Rows)
                    {
                        if (!string.IsNullOrWhiteSpace(dr.Cells[5].FormattedValue.ToString()))
                        {
                            if (!(string.Compare(dr.Cells[5].Value.ToString(), "Enable", true) == 0))
                            {
                                dr.DefaultCellStyle.BackColor = Color.Red;
                                dr.DefaultCellStyle.ForeColor = Color.White;
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Cập nhật thất bại");
                }
            }
            else
            {
            }
        }
Пример #5
0
        private void btXoa_Click(object sender, EventArgs e)
        {
            DTO_ThucDon  td = busThucDon.curTD(DgvThucDon.CurrentRow.Cells["TenTD"].Value.ToString());
            DialogResult re = MessageBox.Show("Bạn có chắc chắn muốn xóa " + td.TenTD + " không ?", "Xóa thực đơn", MessageBoxButtons.YesNo);

            if (re == DialogResult.Yes)
            {
                if (busThucDon.XoaThucDon(td.MaTD))
                {
                    MessageBox.Show("Xóa món thành công", "Thông báo");
                    DgvThucDon.DataSource          = busThucDon.DanhSachThucDon_1();
                    DgvThucDon.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

                    CheckBoxDanhSach.Checked = false;

                    Disable_Textbox_Button();
                }
                else
                {
                    MessageBox.Show("Xóa món thất bại", "Thông báo");
                }
            }
            else
            {
            }
        }
Пример #6
0
        private void btCapNhat_Click(object sender, EventArgs e)
        {
            DialogResult re = MessageBox.Show("Bạn có chắc chắn muốn cập nhật không ?", "Cập nhật", MessageBoxButtons.YesNo);

            if (re == DialogResult.Yes)
            {
                if (string.IsNullOrEmpty(txtTenMon.Text) || string.IsNullOrWhiteSpace(txtTenMon.Text))
                {
                    MessageBox.Show("Bạn chưa nhập tên món", "Thông báo");
                }
                else if (string.IsNullOrEmpty(txtDonGia.Text) || string.IsNullOrWhiteSpace(txtDonGia.Text))
                {
                    MessageBox.Show("Bạn chưa nhập đơn giá", "Thông báo");
                }
                else if (!IsNumber(txtDonGia.Text))
                {
                    MessageBox.Show("Đơn giá phải là số và lớn hơn 0");
                }
                else if (float.Parse(txtDonGia.Text) < 0)
                {
                    MessageBox.Show("Đơn giá phải là một số lớn hơn 0");
                }
                else if (string.IsNullOrEmpty(txtNhom.Text) || string.IsNullOrWhiteSpace(txtNhom.Text))
                {
                    MessageBox.Show("Bạn chưa nhập nhóm", "Thông báo");
                }

                else
                {
                    Image          img = ptbThucDon.BackgroundImage;
                    byte[]         arr;
                    ImageConverter converter = new ImageConverter();
                    arr = (byte[])converter.ConvertTo(img, typeof(byte[]));
                    DTO_ThucDon td    = busThucDon.curTD(DgvThucDon.CurrentRow.Cells["TenTD"].Value.ToString());
                    DTO_ThucDon curTD = new DTO_ThucDon(txtTenMon.Text, float.Parse(txtDonGia.Text), txtMoTa.Text, txtNhom.Text, arr);

                    if (busThucDon.CapNhatThucDon(td.MaTD, curTD))
                    {
                        MessageBox.Show("Cập nhật thành công");
                        DgvThucDon.DataSource          = busThucDon.DanhSachThucDon_1();
                        DgvThucDon.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                    }
                    else
                    {
                        MessageBox.Show("Cập nhật thất bại");
                    }
                }
            }
            else
            {
            }
        }
Пример #7
0
        private void btLuu_Click(object sender, EventArgs e)
        {
            BUS_ThucDon td = new BUS_ThucDon();

            if (string.IsNullOrEmpty(txtTenMon.Text) || string.IsNullOrWhiteSpace(txtTenMon.Text))
            {
                MessageBox.Show("Bạn chưa nhập tên món", "Thông báo");
            }
            else if (CheckTrungTD(txtTenMon.Text, td))
            {
                MessageBox.Show("Đã tồn tại");
            }
            else if (!IsNumber(txtDonGia.Text))
            {
                MessageBox.Show("Đơn giá phải là số và lớn hơn 0");
            }
            else if (float.Parse(txtDonGia.Text) < 0)
            {
                MessageBox.Show("Đơn giá phải là một số lớn hơn 0");
            }
            else if (string.IsNullOrEmpty(txtDonGia.Text) || string.IsNullOrWhiteSpace(txtDonGia.Text))
            {
                MessageBox.Show("Bạn chưa nhập đơn giá", "Thông báo");
            }
            else if (string.IsNullOrEmpty(txtNhom.Text) || string.IsNullOrWhiteSpace(txtNhom.Text))
            {
                MessageBox.Show("Bạn chưa nhập nhóm", "Thông báo");
            }
            else
            {
                Image          img = ptbThucDon.BackgroundImage;
                byte[]         arr;
                ImageConverter converter = new ImageConverter();
                arr = (byte[])converter.ConvertTo(img, typeof(byte[]));
                DTO_ThucDon curTD = new DTO_ThucDon(txtTenMon.Text, float.Parse(txtDonGia.Text), txtMoTa.Text, txtNhom.Text, arr);

                if (busThucDon.insertThucDon(curTD))
                {
                    MessageBox.Show("Thêm món vào thực đơn thành công");
                    DgvThucDon.DataSource          = busThucDon.DanhSachThucDon_1();
                    DgvThucDon.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                    Disable_Textbox_Button();

                    ptbThucDon.BackgroundImage       = Image.FromFile(startupPath + @"\image\logo.jpg");
                    ptbThucDon.BackgroundImageLayout = ImageLayout.Stretch;
                }
                else
                {
                    MessageBox.Show("Thêm món vào thực đơn thất bại");
                }
            }
        }
Пример #8
0
        private void dgvThucDon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvThucDon.Rows.Count > 1)
            {
                if (dgvThucDon.CurrentRow.Index < dgvThucDon.Rows.Count - 1)
                {
                    TD = busTD.curTD(dgvThucDon.CurrentRow.Cells[0].FormattedValue.ToString());

                    lbTenMon.Text     = TD.TenTD;
                    btThem.Enabled    = true;
                    btAdd1.Enabled    = true;
                    btRemove1.Enabled = true;
                    dgvHDCT.Enabled   = true;
                }
            }
        }
Пример #9
0
        public DTO_ThucDon curTD(string TenTD)
        {
            DTO_ThucDon curTD = (from DataRow dr in dalThucDon.DanhSachThucDonAll().Rows
                                 //where string.Compare(dr[1].ToString(), TenTD, true) == 0
                                 where TenTD.Contains(dr[1].ToString())
                                 select new DTO_ThucDon
            {
                MaTD = dr[0].ToString(),
                TenTD = dr[1].ToString(),
                GiaBan = float.Parse(dr[2].ToString()),

                Nhom = dr[3].ToString(),
                MoTa = dr[4].ToString(),
                TrangThai = string.Compare(dr[5].ToString(), "Enable", true) == 0 ? 1 : 0
            }).FirstOrDefault();

            return(curTD);
        }
Пример #10
0
        private void DgvThucDon_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (DgvThucDon.Rows.Count > 1)
            {
                if (DgvThucDon.CurrentRow.Index < DgvThucDon.Rows.Count - 1)
                {
                    btOpenDialog.Enabled = true;
                    btLuu.Enabled        = false;
                    btXoa.Enabled        = true;
                    btCapNhat.Enabled    = true;
                    btBoQua.Enabled      = true;
                    txtTenMon.Enabled    = true;
                    txtDonGia.Enabled    = true;
                    txtNhom.Enabled      = true;
                    txtMoTa.Enabled      = true;
                    txtTenMon.Focus();

                    DTO_ThucDon td = busThucDon.curTD(DgvThucDon.CurrentRow.Cells["TenTD"].Value.ToString());
                    txtTenMon.Text = td.TenTD;
                    txtDonGia.Text = td.GiaBan.ToString();
                    txtNhom.Text   = td.Nhom;
                    txtMoTa.Text   = td.MoTa;

                    MemoryStream mem = new MemoryStream(busThucDon.getHinhTD(td.MaTD));
                    ptbThucDon.BackgroundImage       = Image.FromStream(mem);
                    ptbThucDon.BackgroundImageLayout = ImageLayout.Stretch;

                    if (td.TrangThai == 1)
                    {
                        btEnable.Enabled = false;
                    }
                    else
                    {
                        btEnable.Enabled = true;
                    }
                }
            }
        }
Пример #11
0
 public bool CapNhatThucDon(string maTD, DTO_ThucDon td)
 {
     return(dalThucDon.CapNhatThucDon(maTD, td));
 }
Пример #12
0
 public bool insertThucDon(DTO_ThucDon td)
 {
     return(dalThucDon.ThemThucDon(td));
 }