Exemplo n.º 1
0
        private void btThem_Click(object sender, EventArgs e)
        {
            if (flagThem == 0) // chọn thêm
            {
                flagThem       = 1;
                btThem.Text    = "Lưu";
                tbTen.ReadOnly = false;
                tbDG.ReadOnly  = false;
                cbDV.Enabled   = true;
                cbLoai.Enabled = true;
                btXoa.Enabled  = false;
                btSua.Enabled  = false;
                btHuy.Enabled  = true;
                tbTen.Text     = "";
                tbDG.Text      = "";
            }
            else
            {
                if (tbTen.Text.Trim() != "" && tbDG.Text.Trim() != "")
                {
                    if (Food_BUS.isExistedFood(tbTen.Text.Trim()) == 0) // Chọn lưu
                    {
                        flagThem       = 0;
                        btThem.Text    = "Thêm";
                        tbTen.ReadOnly = true;
                        tbDG.ReadOnly  = true;
                        cbDV.Enabled   = false;
                        cbLoai.Enabled = false;
                        btXoa.Enabled  = true;
                        btSua.Enabled  = true;
                        btHuy.Enabled  = false;
                        Food_DTO food = new Food_DTO(tbTen.Text, FoodCategory_BUS.getIdCategoryByName(cbLoai.Text), FoodUnit_BUS.getIdUnitByName(cbDV.Text), float.Parse(tbDG.Text));
                        try
                        {
                            Food_BUS.AddFood(food);
                            MessageBox.Show("Thêm thành công");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Thêm thất bại");
                        }

                        dgvMenu.DataSource = Food_BUS.LoadFood();
                        bindingData();
                    }
                    else
                    {
                        MessageBox.Show("Món này đã tồn tại.");
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập đầy đủ thông tin.");
                }
            }
        }
Exemplo n.º 2
0
        private void btSua_Click(object sender, EventArgs e)
        {
            if (flagSua == 0)     // chọn sửa
            {
                flagSua        = 1;
                btSua.Text     = "Lưu";
                tbTen.ReadOnly = false;
                tbDG.ReadOnly  = false;
                cbDV.Enabled   = true;
                cbLoai.Enabled = true;
                btXoa.Enabled  = false;
                btThem.Enabled = false;
                btHuy.Enabled  = true;
            }
            else
            {
                if (tbTen.Text.Trim() != "" && tbDG.Text.Trim() != "")
                {
                    if (flagSua == 1)     // Chọn lưu
                    {
                        flagSua        = 0;
                        btSua.Text     = "Sửa";
                        tbTen.ReadOnly = true;
                        tbDG.ReadOnly  = true;
                        cbDV.Enabled   = false;
                        cbLoai.Enabled = false;
                        btXoa.Enabled  = true;
                        btThem.Enabled = true;
                        btHuy.Enabled  = false;
                        Food_DTO food = new Food_DTO(Int32.Parse(tbMa.Text), tbTen.Text, FoodCategory_BUS.getIdCategoryByName(cbLoai.Text), FoodUnit_BUS.getIdUnitByName(cbDV.Text), float.Parse(tbDG.Text));
                        try
                        {
                            Food_BUS.EditFood(food);
                            MessageBox.Show("Cập nhật hoàn tất");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Cập nhật thất bại");
                        }

                        dgvMenu.DataSource = Food_BUS.LoadFood();
                        bindingData();
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng nhập đầy đủ thông tin.");
                }
            }
        }
Exemplo n.º 3
0
        public static void AddFood(Food_DTO food)
        {
            SqlConnection cnn = ConnectToSQL.Connect();
            SqlCommand    cmd = new SqlCommand("AddFood", cnn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 100);
            cmd.Parameters.Add("@IdCategory", SqlDbType.Int);
            cmd.Parameters.Add("@IdUnit", SqlDbType.Int);
            cmd.Parameters.Add("@Price", SqlDbType.Float);
            cmd.Parameters["@Name"].Value       = food.Name;
            cmd.Parameters["@IdCategory"].Value = food.IdCategory;
            cmd.Parameters["@IdUnit"].Value     = food.IdUnit;
            cmd.Parameters["@Price"].Value      = food.Price;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
Exemplo n.º 4
0
 public static void EditFood(Food_DTO food)
 {
     Food_DAO.EditFood(food);
 }
Exemplo n.º 5
0
 public static void AddFood(Food_DTO food)
 {
     Food_DAO.AddFood(food);
 }