Beispiel #1
0
        //ListAll
        public List <Ob_DM_KhuVuc> _ListAll_sp(string StoredName, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_KhuVuc> list    = new List <Ob_DM_KhuVuc>();
            SqlCommand          command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = StoredName
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DM_KhuVuc ob = new Ob_DM_KhuVuc();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KHUVUC = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAKHUVUC = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENKHUVUC = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.ID_CHINHANH = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Beispiel #2
0
        //DeleteOB
        public bool _DeleteOb(Ob_DM_KhuVuc ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Delete From DM_KhuVuc Where ID_KhuVuc=@ID_KhuVuc"
            };

            command.Parameters.Add(new SqlParameter("ID_KhuVuc", ob.ID_KHUVUC));
            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);
        }
Beispiel #3
0
        //ListWhere
        public List <Ob_DM_KhuVuc> _ListWhere(string keyword, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(null);
            }
            conn.Open();
            List <Ob_DM_KhuVuc> list    = new List <Ob_DM_KhuVuc>();
            SqlCommand          command = new SqlCommand
            {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Select ID_KhuVuc, MaKhuVuc, TenKhuVuc, ID_ChiNhanh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy From DM_KhuVuc Where " + keyword + ""
            };
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Ob_DM_KhuVuc ob = new Ob_DM_KhuVuc();
                if (reader[0] != DBNull.Value)
                {
                    ob.ID_KHUVUC = Convert.ToInt32(reader[0]);
                }
                if (reader[1] != DBNull.Value)
                {
                    ob.MAKHUVUC = Convert.ToString(reader[1]);
                }
                if (reader[2] != DBNull.Value)
                {
                    ob.TENKHUVUC = Convert.ToString(reader[2]);
                }
                if (reader[3] != DBNull.Value)
                {
                    ob.ID_CHINHANH = Convert.ToInt32(reader[3]);
                }
                if (reader[4] != DBNull.Value)
                {
                    ob.MODIFIEDTIME = Convert.ToDateTime(reader[4]);
                }
                if (reader[5] != DBNull.Value)
                {
                    ob.MODIFIEDBY = Convert.ToString(reader[5]);
                }
                if (reader[6] != DBNull.Value)
                {
                    ob.CREATEDTIME = Convert.ToDateTime(reader[6]);
                }
                if (reader[7] != DBNull.Value)
                {
                    ob.CREATEDBY = Convert.ToString(reader[7]);
                }
                list.Add(ob);
            }
            command.Dispose();
            command = null;
            reader.Dispose();
            reader = null;
            conn.Close();
            return(list);
        }
Beispiel #4
0
 public Ob_DM_KhuVuc(Ob_DM_KhuVuc newOb)
 {
     id_khuvuc    = newOb.ID_KHUVUC;
     makhuvuc     = newOb.MAKHUVUC;
     tenkhuvuc    = newOb.TENKHUVUC;
     id_chinhanh  = newOb.ID_CHINHANH;
     modifiedtime = newOb.MODIFIEDTIME;
     modifiedby   = newOb.MODIFIEDBY;
     createdtime  = newOb.CREATEDTIME;
     createdby    = newOb.CREATEDBY;
 }
Beispiel #5
0
        //UpdateOb ob
        public bool _UpdateOb(Ob_DM_KhuVuc ob, SqlConnection conn)
        {
            if (conn.ConnectionString == "")
            {
                return(false);
            }
            conn.Open();
            SqlCommand command = new SqlCommand {
                Connection  = conn,
                CommandType = CommandType.Text,
                CommandText = @"Update DM_KhuVuc Set MaKhuVuc=@MaKhuVuc, TenKhuVuc=@TenKhuVuc, ID_ChiNhanh=@ID_ChiNhanh, ModifiedTime=@ModifiedTime, ModifiedBy=@ModifiedBy, CreatedTime=@CreatedTime, CreatedBy=@CreatedBy Where ID_KhuVuc=@ID_KhuVuc"
            };

            command.Parameters.Add("ID_KhuVuc", SqlDbType.Int).Value = ob.ID_KHUVUC;
            if (ob.MAKHUVUC.Trim() == "")
            {
                command.Parameters.Add("MaKhuVuc", SqlDbType.VarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("MaKhuVuc", SqlDbType.VarChar).Value = ob.MAKHUVUC;
            }
            if (ob.TENKHUVUC.Trim() == "")
            {
                command.Parameters.Add("TenKhuVuc", SqlDbType.NVarChar).Value = DBNull.Value;
            }
            else
            {
                command.Parameters.Add("TenKhuVuc", SqlDbType.NVarChar).Value = ob.TENKHUVUC;
            }
            command.Parameters.Add("ID_ChiNhanh", SqlDbType.Int).Value = ob.ID_CHINHANH;
            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);
        }
Beispiel #6
0
        //InsertobGetId
        public int _InsertObGetId(Ob_DM_KhuVuc ob, SqlConnection conn)
        {
            int num = 0;

            if (conn.ConnectionString != "")
            {
                conn.Open();
                SqlCommand command = new SqlCommand
                {
                    Connection  = conn,
                    CommandType = CommandType.Text,
                    CommandText = @"Insert Into DM_KhuVuc (MaKhuVuc, TenKhuVuc, ID_ChiNhanh, ModifiedTime, ModifiedBy, CreatedTime, CreatedBy) Values(@MaKhuVuc, @TenKhuVuc, @ID_ChiNhanh, @ModifiedTime, @ModifiedBy, @CreatedTime, @CreatedBy)Select @@IDENTITY"
                };
                if (ob.MAKHUVUC.Trim() == "")
                {
                    command.Parameters.Add("MaKhuVuc", SqlDbType.VarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("MaKhuVuc", SqlDbType.VarChar).Value = ob.MAKHUVUC;
                }
                if (ob.TENKHUVUC.Trim() == "")
                {
                    command.Parameters.Add("TenKhuVuc", SqlDbType.NVarChar).Value = DBNull.Value;
                }
                else
                {
                    command.Parameters.Add("TenKhuVuc", SqlDbType.NVarChar).Value = ob.TENKHUVUC;
                }
                command.Parameters.Add("ID_ChiNhanh", SqlDbType.Int).Value = ob.ID_CHINHANH;
                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);
        }