//InsertobGetId public int _InsertObGetId(Ob_POS_KhuyenMaiLoaiHang ob, SqlConnection conn) { int num = 0; if (conn.ConnectionString != "") { conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Insert Into POS_KhuyenMaiLoaiHang (ID_KhuyenMai, ID_LoaiHang) Values(@ID_KhuyenMai, @ID_LoaiHang)Select @@IDENTITY" }; command.Parameters.Add("ID_KhuyenMai", SqlDbType.Int).Value = ob.ID_KHUYENMAI; command.Parameters.Add("ID_LoaiHang", SqlDbType.Int).Value = ob.ID_LOAIHANG; try { num = Convert.ToInt32(command.ExecuteScalar()); } catch (Exception exception) { MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(num); } command.Dispose(); command = null; conn.Close(); } return(num); }
//DeleteOB public bool _DeleteOb(Ob_POS_KhuyenMaiLoaiHang ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Delete From POS_KhuyenMaiLoaiHang Where ID_KhuyenMaiLoaiHang=@ID_KhuyenMaiLoaiHang" }; command.Parameters.Add(new SqlParameter("ID_KhuyenMaiLoaiHang", ob.ID_KHUYENMAILOAIHANG)); try { command.ExecuteNonQuery(); } catch (Exception exception) { MessageBox.Show("Không thể xóa dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } command.Dispose(); command = null; conn.Close(); return(true); }
//Insert ob public bool _InsertOb(Ob_POS_KhuyenMaiLoaiHang ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Insert Into POS_KhuyenMaiLoaiHang (ID_KhuyenMai, ID_LoaiHang) Values(@ID_KhuyenMai, @ID_LoaiHang)" }; command.Parameters.Add("ID_KhuyenMai", SqlDbType.Int).Value = ob.ID_KHUYENMAI; command.Parameters.Add("ID_LoaiHang", SqlDbType.Int).Value = ob.ID_LOAIHANG; try { command.ExecuteNonQuery(); } catch (Exception exception) { MessageBox.Show("Không thể thêm dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } command.Dispose(); command = null; conn.Close(); return(true); }
//GetObWhere public Ob_POS_KhuyenMaiLoaiHang _GetObWhere(string keyword, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); Ob_POS_KhuyenMaiLoaiHang ob = new Ob_POS_KhuyenMaiLoaiHang(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Select ID_KhuyenMaiLoaiHang, ID_KhuyenMai, ID_LoaiHang From POS_KhuyenMaiLoaiHang Where " + keyword + "" }; SqlDataReader reader = command.ExecuteReader(); int num = 0; while (reader.Read()) { num++; if (reader[0] != DBNull.Value) { ob.ID_KHUYENMAILOAIHANG = Convert.ToInt64(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_KHUYENMAI = Convert.ToInt32(reader[1]); } if (reader[2] != DBNull.Value) { ob.ID_LOAIHANG = Convert.ToInt32(reader[2]); } } if (num == 0) { command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(null); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(ob); }
//ListWhere_sp public List <Ob_POS_KhuyenMaiLoaiHang> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); List <Ob_POS_KhuyenMaiLoaiHang> list = new List <Ob_POS_KhuyenMaiLoaiHang>(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = StoredName }; command.Parameters.AddRange(ArrayParameter); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Ob_POS_KhuyenMaiLoaiHang ob = new Ob_POS_KhuyenMaiLoaiHang(); if (reader[0] != DBNull.Value) { ob.ID_KHUYENMAILOAIHANG = Convert.ToInt64(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_KHUYENMAI = Convert.ToInt32(reader[1]); } if (reader[2] != DBNull.Value) { ob.ID_LOAIHANG = Convert.ToInt32(reader[2]); } list.Add(ob); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(list); }
//UpdateOb ob public bool _UpdateOb(Ob_POS_KhuyenMaiLoaiHang ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Update POS_KhuyenMaiLoaiHang Set ID_KhuyenMai=@ID_KhuyenMai, ID_LoaiHang=@ID_LoaiHang Where ID_KhuyenMaiLoaiHang=@ID_KhuyenMaiLoaiHang" }; command.Parameters.Add("ID_KhuyenMaiLoaiHang", SqlDbType.BigInt).Value = ob.ID_KHUYENMAILOAIHANG; command.Parameters.Add("ID_KhuyenMai", SqlDbType.Int).Value = ob.ID_KHUYENMAI; command.Parameters.Add("ID_LoaiHang", SqlDbType.Int).Value = ob.ID_LOAIHANG; try { command.ExecuteNonQuery(); } catch (Exception exception) { MessageBox.Show("Không thể cập nhật dữ liệu. \r\n" + exception.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } if (command.ExecuteNonQuery() == 0) { MessageBox.Show("Không thể cập nhật dữ liệu. \r\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); command.Dispose(); command = null; conn.Close(); return(false); } command.Dispose(); command = null; conn.Close(); return(true); }
//ListAll public List <Ob_POS_KhuyenMaiLoaiHang> _ListAll(SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); List <Ob_POS_KhuyenMaiLoaiHang> list = new List <Ob_POS_KhuyenMaiLoaiHang>(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Select ID_KhuyenMaiLoaiHang, ID_KhuyenMai, ID_LoaiHang From POS_KhuyenMaiLoaiHang" }; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Ob_POS_KhuyenMaiLoaiHang ob = new Ob_POS_KhuyenMaiLoaiHang(); if (reader[0] != DBNull.Value) { ob.ID_KHUYENMAILOAIHANG = Convert.ToInt64(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_KHUYENMAI = Convert.ToInt32(reader[1]); } if (reader[2] != DBNull.Value) { ob.ID_LOAIHANG = Convert.ToInt32(reader[2]); } list.Add(ob); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(list); }
public Ob_POS_KhuyenMaiLoaiHang(Ob_POS_KhuyenMaiLoaiHang newOb) { id_khuyenmailoaihang = newOb.ID_KHUYENMAILOAIHANG; id_khuyenmai = newOb.ID_KHUYENMAI; id_loaihang = newOb.ID_LOAIHANG; }