コード例 #1
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");
                }
            }
        }
コード例 #2
0
        //CheckTrung
        public bool CheckTrungTD(string tenMon, BUS_ThucDon td)
        {
            DataTable getTD = td.DanhSachThucDonAll();

            foreach (DataRow row in getTD.Rows)
            {
                if (string.Compare(tenMon, row[1].ToString(), true) == 0)
                {
                    return(true);
                }
            }
            return(false);
        }