//InsertobGetId public int _InsertObGetId(Ob_HT_NguoiDung_CuaHang ob, SqlConnection conn) { int num = 0; if (conn.ConnectionString != "") { conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Insert Into HT_NguoiDung_CuaHang (ID_NguoiDung, ID_CuaHang) Values(@ID_NguoiDung, @ID_CuaHang)Select @@IDENTITY" }; command.Parameters.Add("ID_NguoiDung", SqlDbType.Int).Value = ob.ID_NGUOIDUNG; command.Parameters.Add("ID_CuaHang", SqlDbType.Int).Value = ob.ID_CUAHANG; 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_HT_NguoiDung_CuaHang ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Delete From HT_NguoiDung_CuaHang Where ID_NguoiDung=@ID_NguoiDung" }; command.Parameters.Add(new SqlParameter("ID_NguoiDung", ob.ID_NGUOIDUNG)); 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_HT_NguoiDung_CuaHang ob, SqlConnection conn) { if (conn.ConnectionString == "") { return(false); } conn.Open(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Insert Into HT_NguoiDung_CuaHang (ID_NguoiDung, ID_CuaHang) Values(@ID_NguoiDung, @ID_CuaHang)" }; command.Parameters.Add("ID_NguoiDung", SqlDbType.Int).Value = ob.ID_NGUOIDUNG; command.Parameters.Add("ID_CuaHang", SqlDbType.Int).Value = ob.ID_CUAHANG; 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_HT_NguoiDung_CuaHang _GetObWhere(string keyword, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); Ob_HT_NguoiDung_CuaHang ob = new Ob_HT_NguoiDung_CuaHang(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Select ID_NguoiDung, ID_CuaHang From HT_NguoiDung_CuaHang Where " + keyword + "" }; SqlDataReader reader = command.ExecuteReader(); int num = 0; while (reader.Read()) { num++; if (reader[0] != DBNull.Value) { ob.ID_NGUOIDUNG = Convert.ToInt32(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_CUAHANG = Convert.ToInt32(reader[1]); } } 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_HT_NguoiDung_CuaHang> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); List <Ob_HT_NguoiDung_CuaHang> list = new List <Ob_HT_NguoiDung_CuaHang>(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = StoredName }; command.Parameters.AddRange(ArrayParameter); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Ob_HT_NguoiDung_CuaHang ob = new Ob_HT_NguoiDung_CuaHang(); if (reader[0] != DBNull.Value) { ob.ID_NGUOIDUNG = Convert.ToInt32(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_CUAHANG = Convert.ToInt32(reader[1]); } list.Add(ob); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(list); }
//ListAll public List <Ob_HT_NguoiDung_CuaHang> _ListAll(SqlConnection conn) { if (conn.ConnectionString == "") { return(null); } conn.Open(); List <Ob_HT_NguoiDung_CuaHang> list = new List <Ob_HT_NguoiDung_CuaHang>(); SqlCommand command = new SqlCommand { Connection = conn, CommandType = CommandType.Text, CommandText = @"Select ID_NguoiDung, ID_CuaHang From HT_NguoiDung_CuaHang" }; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { Ob_HT_NguoiDung_CuaHang ob = new Ob_HT_NguoiDung_CuaHang(); if (reader[0] != DBNull.Value) { ob.ID_NGUOIDUNG = Convert.ToInt32(reader[0]); } if (reader[1] != DBNull.Value) { ob.ID_CUAHANG = Convert.ToInt32(reader[1]); } list.Add(ob); } command.Dispose(); command = null; reader.Dispose(); reader = null; conn.Close(); return(list); }
public Ob_HT_NguoiDung_CuaHang(Ob_HT_NguoiDung_CuaHang newOb) { id_nguoidung = newOb.ID_NGUOIDUNG; id_cuahang = newOb.ID_CUAHANG; }