Example #1
0
        //DeleteOB
        public bool _DeleteOb(Ob_HT_PhanQuyenDuLieu ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From HT_PhanQuyenDuLieu 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);
        }
 public Ob_HT_PhanQuyenDuLieu(Ob_HT_PhanQuyenDuLieu newOb)
 {
     id_nhomnd    = newOb.ID_NHOMND;
     id_chucnang  = newOb.ID_CHUCNANG;
     tenbang      = newOb.TENBANG;
     mota         = newOb.MOTA;
     xem          = newOb.XEM;
     themmoi      = newOb.THEMMOI;
     sua          = newOb.SUA;
     xoa          = newOb.XOA;
     xuatbaocao   = newOb.XUATBAOCAO;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
Example #3
0
        //ListAll
        public List <Ob_HT_PhanQuyenDuLieu> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_HT_PhanQuyenDuLieu> list = new List <Ob_HT_PhanQuyenDuLieu>();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_HT_PhanQuyenDuLieu ob = new Ob_HT_PhanQuyenDuLieu();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_NHOMND = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.ID_CHUCNANG = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENBANG = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.MOTA = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.XEM = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.THEMMOI = Convert.ToBoolean(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.SUA = Convert.ToBoolean(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.XOA = Convert.ToBoolean(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.XUATBAOCAO = Convert.ToBoolean(reader[8]);
                }
                if (reader[9] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[9]);
                }
                if (reader[10] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[10]);
                }
                if (reader[11] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[11]);
                }
                if (reader[12] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[12]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Example #4
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_HT_PhanQuyenDuLieu ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update HT_PhanQuyenDuLieu Set ID_ChucNang=@ID_ChucNang, TenBang=@TenBang, MoTa=@MoTa, Xem=@Xem, ThemMoi=@ThemMoi, Sua=@Sua, Xoa=@Xoa, XuatBaoCao=@XuatBaoCao, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_ChucNang=@ID_ChucNang and ID_NhomND=@ID_NhomND and TenBang=@TenBang"
            };

            command.Parameters.Add("ID_NhomND", SqlDbType.Int).Value   = ob.ID_NHOMND;
            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;
            }
            command.Parameters.Add("Xem", SqlDbType.Bit).Value        = ob.XEM;
            command.Parameters.Add("ThemMoi", SqlDbType.Bit).Value    = ob.THEMMOI;
            command.Parameters.Add("Sua", SqlDbType.Bit).Value        = ob.SUA;
            command.Parameters.Add("Xoa", SqlDbType.Bit).Value        = ob.XOA;
            command.Parameters.Add("XuatBaoCao", SqlDbType.Bit).Value = ob.XUATBAOCAO;
            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.CREATEDBY.Trim() == "")
            {
                command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY;
            }
            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);
        }
Example #5
0
        //InsertobGetId
        public int _InsertObGetId(Ob_HT_PhanQuyenDuLieu ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into HT_PhanQuyenDuLieu (ID_NhomND, ID_ChucNang, TenBang, MoTa, Xem, ThemMoi, Sua, Xoa, XuatBaoCao, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@ID_NhomND, @ID_ChucNang, @TenBang, @MoTa, @Xem, @ThemMoi, @Sua, @Xoa, @XuatBaoCao, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                command.Parameters.Add("ID_NhomND", SqlDbType.Int).Value   = ob.ID_NHOMND;
                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;
                }
                command.Parameters.Add("Xem", SqlDbType.Bit).Value        = ob.XEM;
                command.Parameters.Add("ThemMoi", SqlDbType.Bit).Value    = ob.THEMMOI;
                command.Parameters.Add("Sua", SqlDbType.Bit).Value        = ob.SUA;
                command.Parameters.Add("Xoa", SqlDbType.Bit).Value        = ob.XOA;
                command.Parameters.Add("XuatBaoCao", SqlDbType.Bit).Value = ob.XUATBAOCAO;
                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.CREATEDBY.Trim() == "")
                {
                    command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("CreatedBy", SqlDbType.VarChar).Value = ob.CREATEDBY;
                }
                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);
        }
Example #6
0
        //GetObWhere
        public Ob_HT_PhanQuyenDuLieu _GetObWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            Ob_HT_PhanQuyenDuLieu ob      = new Ob_HT_PhanQuyenDuLieu();
            SqlCommand            command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_NhomND, ID_ChucNang, TenBang, MoTa, Xem, ThemMoi, Sua, Xoa, XuatBaoCao, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From HT_PhanQuyenDuLieu 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.ID_CHUCNANG = Convert.ToInt32(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENBANG = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.MOTA = Convert.ToString(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.XEM = Convert.ToBoolean(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.THEMMOI = Convert.ToBoolean(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.SUA = Convert.ToBoolean(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.XOA = Convert.ToBoolean(reader[7]);
                }
                if (reader[8] != DBNull.Value)
                {
                    ob.XUATBAOCAO = Convert.ToBoolean(reader[8]);
                }
                if (reader[9] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[9]);
                }
                if (reader[10] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[10]);
                }
                if (reader[11] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[11]);
                }
                if (reader[12] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[12]);
                }
            }
            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);
        }