Click here to Skip to main content
15,946,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In a win forms application there is a grid view in the UI which should be populated with the details of branch offices of the client. There are about 50 branches. So `GetBranchDetails()` method in the `DataService` class returns a `DataSet` and the `Presenter` class passes that `DataSet` to the UI's `BindData()` method in which the `datasource` property of the grid view is set to the `DataSet` object as shown in the code.

The problem is the `DataService` is not returning a model rather it returns a `DataSet`. Can some one tell me how to use `BranchOffice` model instead of using a `DataSet` here? So that the `Model` should be returned from `DataService` and then the `presenter` will pass that `Model` to UI where the `Model` will be set as the `datasource` to the grid view. Please note that always there will be more than one branch offices!

DataService Class


C#
public DataTable GetBranchDetails()
{
    string selectStatement = "SELECT ID, branch_name + ', ' + branch_add AS Branch,       area, sm, atten_status FROM Branch WHERE Status='Active'";
    using (SqlConnection sqlConnection = new   SqlConnection(db.GetConnectionString))
    using (SqlCommand sqlCommand = new SqlCommand(selectStatement, sqlConnection))
    using (SqlDataAdapter da = new SqlDataAdapter(sqlCommand))
    using (DataSet ds = new DataSet())
    using (DataTable dt = new DataTable())
   {
      ds.Tables.Add(dt);
      sqlConnection.Open();
      da.Fill(dt);
      return dt;
   }
}



Presenter Class

C#
private void _View_ShowBranches(object sender, EventArgs e)
{
    ShowBranches();
}

private void ShowBranches()
{
    var dt = DataService.GetBranchDetails();
    this._View.BindData(dt);
}



View / UI

C#
public partial class frmAttendancePoints : Form, IView
{
    public frmAttendancePoints()
    {
        InitializeComponents();
    }

    public void BindData(DataSet dt)
    {
        dgAttendancePoints.DataSource = dt;
    }
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900