private void btnCapNhatLoai_Click(object sender, EventArgs e) { //lay du lieu string maloaimon = txtMaLoai.Text; string tenloaimon = txtTenLoai.Text; LoaiMon_DTO loaimon = new LoaiMon_DTO(maloaimon, tenloaimon); bool kt = LoaiMon_BUS.CapNhatLoaiMon(loaimon); if (kt == false) { //khong thanh cong MessageBox.Show("Mã loại món đã tồn tại!"); return; } else { //thanh cong MessageBox.Show("Cập nhật loại món thành công!"); //load lai danh sach dataGridView1.DataSource = LoaiMon_BUS.LoadDSLoaiMon(); bingdingLoaiMon(); //do du lieu vao comboboxLoai comboBoxThuocLoai.DataSource = LoaiMon_BUS.DSMaLoaiMon(); comboBoxThuocLoai.DisplayMember = "Maloaimon"; } }
public static bool ThemLoaiMon(LoaiMon_DTO loai) { SqlConnection kt = ConnectToSQL.HamKetNoi(); string sql = "SELECT Maloaimon FROM LOAIMON WHERE Maloaimon = @Maloaimon"; SqlCommand cmd1 = new SqlCommand(sql, kt); cmd1.CommandType = CommandType.Text; cmd1.Parameters.Add("@Maloaimon", SqlDbType.VarChar, 10); cmd1.Parameters["@Maloaimon"].Value = loai.Maloai; kt.Open(); SqlDataReader reader = cmd1.ExecuteReader(); int count = 0; if (reader.Read()) { count++; string s = reader.GetString(0); } reader.Close(); if (count == 1) { //MessageBox.Show("Sinh vien da ton tai!"); return(false); } SqlConnection cnn = ConnectToSQL.HamKetNoi(); string str = "INSERT INTO LOAIMON(Maloaimon, Tenloaimon) VALUES (@Maloaimon, @Tenloaimon)"; SqlCommand cmd = new SqlCommand(str, cnn); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@Maloaimon", SqlDbType.VarChar, 10); cmd.Parameters.Add("@Tenloaimon", SqlDbType.NVarChar, 50); cmd.Parameters["@Maloaimon"].Value = loai.Maloai; cmd.Parameters["@Tenloaimon"].Value = loai.Tenloai; cnn.Open(); cmd.ExecuteNonQuery(); cnn.Close(); return(true); }
public static bool XoaLoaiMon(LoaiMon_DTO loai) { SqlConnection cnn = ConnectToSQL.HamKetNoi(); string str = "DELETE FROM LOAIMON WHERE Maloaimon = @Maloaimon"; SqlCommand cmd = new SqlCommand(str, cnn); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@Maloaimon", SqlDbType.VarChar, 10); cmd.Parameters["@Maloaimon"].Value = loai.Maloai; cnn.Open(); int count = cmd.ExecuteNonQuery(); if (count < 1) { return(false); } cnn.Close(); return(true); }
public static bool CapNhatLoaiMon(LoaiMon_DTO loai) { return(LoaiMon_DAO.CapNhatLoaiMon(loai)); }
public static bool XoaLoaiMon(LoaiMon_DTO loai) { return(LoaiMon_DAO.XoaLoaiMon(loai)); }
public static bool ThemLoaiMon(LoaiMon_DTO loai) { return(LoaiMon_DAO.ThemLoaiMon(loai)); }