简体   繁体   English

C#/ SQL Server 2005我应该对报表和数据网格使用OOP吗?

[英]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: 我的Web应用程序分为不同的层,其中之一是业务层,其工作方式如下:

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: 然后,每当查看记录时,我都会将人员对象加载到ASP.NET控件中,然后为了进行保存,请执行以下操作:

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 ? 在这里使用OOP是否有意义? If true then I would have to create a custom Object that would only be used for that single report and nothing else. 如果为true,那么我将必须创建一个自定义对象,该对象仅用于该单个报告,而不能用于其他任何报告。

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... 这更多是一个通用问题,并不严格适用于C#和SQL,但基本上适用于其中的任何业务应用程序...

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. 我们在其他任何地方都使用OOP,但这在试图限制您必须编写的代码量和易用性时很有意义。

// 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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