Пример #1
0
        //DeleteOB
        public bool _DeleteOb(Ob_HT_DuLieuChucNang ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From HT_DuLieuChucNang Where ID_ChucNang=@ID_ChucNang"
            };

            command.Parameters.Add(new SqlParameter("ID_ChucNang", ob.ID_CHUCNANG));
            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);
        }
Пример #2
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_HT_DuLieuChucNang ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update HT_DuLieuChucNang Set TenBang=@TenBang, MoTa=@MoTa Where ID_ChucNang=@ID_ChucNang and TenBang=@TenBang"
            };

            command.Parameters.Add("ID_ChucNang", SqlDbType.Int).Value = ob.ID_CHUCNANG;
            if (ob.TENBANG.Trim() == "")
            {
                command.Parameters.Add("TenBang", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenBang", SqlDbType.VarChar).Value = ob.TENBANG;
            }
            if (ob.MOTA.Trim() == "")
            {
                command.Parameters.Add("MoTa", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MoTa", SqlDbType.NVarChar).Value = ob.MOTA;
            }
            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);
        }
Пример #3
0
        //GetObWhere
        public Ob_HT_DuLieuChucNang _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_HT_DuLieuChucNang ob      = new Ob_HT_DuLieuChucNang();
            SqlCommand           command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_ChucNang, TenBang, MoTa From HT_DuLieuChucNang Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();
            int           num    = 0;

            while (reader.Read())
            {
                num++;
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHUCNANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENBANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.MOTA = Convert.ToString(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);
        }
Пример #4
0
        //InsertobGetId
        public int _InsertObGetId(Ob_HT_DuLieuChucNang ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into HT_DuLieuChucNang (ID_ChucNang, TenBang, MoTa) Values(@ID_ChucNang, @TenBang, @MoTa)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_ChucNang", SqlDbType.Int).Value = ob.ID_CHUCNANG;
                if (ob.TENBANG.Trim() == "")
                {
                    command.Parameters.Add("TenBang", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenBang", SqlDbType.VarChar).Value = ob.TENBANG;
                }
                if (ob.MOTA.Trim() == "")
                {
                    command.Parameters.Add("MoTa", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MoTa", SqlDbType.NVarChar).Value = ob.MOTA;
                }
                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);
        }
Пример #5
0
        //ListWhere_sp
        public List <Ob_HT_DuLieuChucNang> _ListWhere_sp(string StoredName, SqlParameter[] ArrayParameter, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_DuLieuChucNang> list = new List <Ob_HT_DuLieuChucNang>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };

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

            while (reader.Read())
            {
                Ob_HT_DuLieuChucNang ob = new Ob_HT_DuLieuChucNang();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHUCNANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENBANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.MOTA = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Пример #6
0
        //ListAll
        public List <Ob_HT_DuLieuChucNang> _ListAll(SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_DuLieuChucNang> list = new List <Ob_HT_DuLieuChucNang>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_ChucNang, TenBang, MoTa From HT_DuLieuChucNang"
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_DuLieuChucNang ob = new Ob_HT_DuLieuChucNang();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_CHUCNANG = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.TENBANG = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.MOTA = Convert.ToString(reader[2]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Пример #7
0
 public Ob_HT_DuLieuChucNang(Ob_HT_DuLieuChucNang newOb)
 {
     id_chucnang = newOb.ID_CHUCNANG;
     tenbang     = newOb.TENBANG;
     mota        = newOb.MOTA;
 }