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
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
private void _View_ShowBranches(object sender, EventArgs e)
{
ShowBranches();
}
private void ShowBranches()
{
var dt = DataService.GetBranchDetails();
this._View.BindData(dt);
}
View / UI
public partial class frmAttendancePoints : Form, IView
{
public frmAttendancePoints()
{
InitializeComponents();
}
public void BindData(DataSet dt)
{
dgAttendancePoints.DataSource = dt;
}
}