//DeleteOB
        public bool _DeleteOb(Ob_HT_NhomNguoiDung ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From HT_NhomNguoiDung Where ID_NhomND=@ID_NhomND"
            };

            command.Parameters.Add(new SqlParameter("ID_NhomND", ob.ID_NHOMND));
            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);
        }
        //ListWhere_sp
        public List <Ob_HT_NhomNguoiDung> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_NhomNguoiDung> list = new List <Ob_HT_NhomNguoiDung>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

            command.Parameters.AddRange(ArrayParameter);
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_NhomNguoiDung ob = new Ob_HT_NhomNguoiDung();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMND = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MANHOMND = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENNHOMND = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEBY = Convert.ToString(reader[6]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
        //ListAll
        public List <Ob_HT_NhomNguoiDung> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_NhomNguoiDung> list = new List <Ob_HT_NhomNguoiDung>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_NhomND, MaNhomND, TenNhomND, ModifiedTime, ModifiedBy, CreatedTime, CreateBy From HT_NhomNguoiDung"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_NhomNguoiDung ob = new Ob_HT_NhomNguoiDung();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMND = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MANHOMND = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENNHOMND = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEBY = Convert.ToString(reader[6]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Exemplo n.º 4
0
 public Ob_HT_NhomNguoiDung(Ob_HT_NhomNguoiDung newOb)
 {
     id_nhomnd    = newOb.ID_NHOMND;
     manhomnd     = newOb.MANHOMND;
     tennhomnd    = newOb.TENNHOMND;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createby     = newOb.CREATEBY;
 }
        //UpdateOb ob
        public bool _UpdateOb(Ob_HT_NhomNguoiDung ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update HT_NhomNguoiDung Set MaNhomND=@MaNhomND, TenNhomND=@TenNhomND, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreateBy=@CreateBy Where ID_NhomND=@ID_NhomND"
            };

            command.Parameters.Add("ID_NhomND", SqlDbType.Int).Value = ob.ID_NHOMND;
            if (ob.MANHOMND.Trim() == "")
            {
                command.Parameters.Add("MaNhomND", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaNhomND", SqlDbType.VarChar).Value = ob.MANHOMND;
            }
            if (ob.TENNHOMND.Trim() == "")
            {
                command.Parameters.Add("TenNhomND", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenNhomND", SqlDbType.NVarChar).Value = ob.TENNHOMND;
            }
            if (ob.MODIFIEDTIME == DateTime.MinValue)
            {
                command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME;
            }
            if (ob.MODIFIEDBY.Trim() == "")
            {
                command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY;
            }
            if (ob.CREATEDTIME == DateTime.MinValue)
            {
                command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME;
            }
            if (ob.CREATEBY.Trim() == "")
            {
                command.Parameters.Add("CreateBy", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("CreateBy", SqlDbType.VarChar).Value = ob.CREATEBY;
            }
            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);
        }
        //InsertobGetId
        public int _InsertObGetId(Ob_HT_NhomNguoiDung ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into HT_NhomNguoiDung (MaNhomND, TenNhomND, ModifiedTime, ModifiedBy, CreatedTime, CreateBy) Values(@MaNhomND, @TenNhomND, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreateBy)Select @@IDENTITY"
                };
                if (ob.MANHOMND.Trim() == "")
                {
                    command.Parameters.Add("MaNhomND", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaNhomND", SqlDbType.VarChar).Value = ob.MANHOMND;
                }
                if (ob.TENNHOMND.Trim() == "")
                {
                    command.Parameters.Add("TenNhomND", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenNhomND", SqlDbType.NVarChar).Value = ob.TENNHOMND;
                }
                if (ob.MODIFIEDTIME == DateTime.MinValue)
                {
                    command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("ModifiedTime", SqlDbType.DateTime).Value = ob.MODIFIEDTIME;
                }
                if (ob.MODIFIEDBY.Trim() == "")
                {
                    command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("ModifiedBy", SqlDbType.VarChar).Value = ob.MODIFIEDBY;
                }
                if (ob.CREATEDTIME == DateTime.MinValue)
                {
                    command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("CreatedTime", SqlDbType.DateTime).Value = ob.CREATEDTIME;
                }
                if (ob.CREATEBY.Trim() == "")
                {
                    command.Parameters.Add("CreateBy", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("CreateBy", SqlDbType.VarChar).Value = ob.CREATEBY;
                }
                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);
        }
        //GetObWhere
        public Ob_HT_NhomNguoiDung _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_HT_NhomNguoiDung ob      = new Ob_HT_NhomNguoiDung();
            SqlCommand          command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_NhomND, MaNhomND, TenNhomND, ModifiedTime, ModifiedBy, CreatedTime, CreateBy From HT_NhomNguoiDung Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMND = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MANHOMND = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENNHOMND = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEBY = Convert.ToString(reader[6]);
                }
            }
            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);
        }