简体   繁体   中英

C# / SQL Server 2005 Should I use OOP for reports and datagrids?

My Web Application is separated into different layers, one of them is the business layer that works like this:

PersonBusiness pb = new PersonBusiness();
Person p = pb.GetPerson(10);

and then I load the person object into ASP.NET controls whenever viewing records, and then for saving I do something like this:

PersonBusiness pb = new PersonBusiness();
Person p = new Person();
p.Name = "Alex";
pb.SavePerson(p);

What if I need to display a report within the app that is actually the result of calling a view from the database that is actually a mix of different objects in the business layer ?. Do you recommend just bypassing the business layer and loading the dataset that comes from the view ? Does it make sense to use OOP here ? If true then I would have to create a custom Object that would only be used for that single report and nothing else.

This is more of a generic question that does not strictly apply to C# and SQL , but applies basically to any business application out there...

I hope my question makes sense,

thanks for your time and have an nice day

This is from an enterprise level application. We run a query that searches multiple tables within a database to return a dataset. We then load that dataset into a datagrid. It works very well and is easy to use. We use OOP everywhere else but this makes sense when trying to limit the amount of code you have to write and the ease of use.

// Call in program
m_Info = m_InfoDAO.GetInfo();
//Database Call
public DataSet GetInfo()
    {
        try
        {
            if (this.cnn == null)
                this.ConnectAndEnable(ref cnn);

            string sql = @" select '0' as select_id, folder_name, folder_name as hidden_folder, (to_char(mod_date,'MM/DD/YYYY hh12:mi AM') || ' ' || mod_user) as mod_date
                            from   index_info , index_patient
                            where  deleted_date is null
                            order by folder_name asc";

            OracleCommand cmd = new OracleCommand(sql, cnn);
            OracleDataAdapter da = new OracleDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds);
            cmd.Parameters.Clear();

            return ds;
        }
        catch (Exception ex)
        {
            Trace.WriteLine("Exception in InfoDAO.GetInfo:  " + ex.Message);
            throw ex;
        }
    }

//Initialize Grid
gridInfo.DataSource = m_Info;
gridInfo.ActiveRow = null;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM