public partial class formTeamTypes : Form, IDBTableEditorView
{
private IDBTableEditorController theTeamTypesController = new classDBTableEditorController();
private IDBTableEditorModel theTeamTypeModel = new classTeamTypesModel("Test");
public formTeamTypes()
{
InitializeComponent();
this.initialize(theTeamTypesController, theTeamTypeModel);
}
public void initialize(IDBTableEditorController inTeamTypesController, IDBTableEditorModel inTeamTypesModel)
{
if (theTeamTypeModel != null)
{
}
theTeamTypeModel = inTeamTypesModel;
theTeamTypesController = inTeamTypesController;
theTeamTypesController.setModel(theTeamTypeModel);
theTeamTypesController.setView(this);
theTeamTypeModel.addObserverView(this);
}
public void addObserver(IDBTableEditorController inTeamTypesController)
{
this.theTeamTypesController = inTeamTypesController;
}
public void updateUserInterface(IDBTableEditorModel inTeamTypeModel) { this.dataGridTeamTypes.Update(); }
private void formTeamTypes_Load(object sender, EventArgs e) { //When Form is called, the data for Team Types are read from DB dataGridTeamTypes.DataSource = theTeamTypesController.onView_Load(); dataGridTeamTypes.Columns[0].HeaderText = "Type ID"; dataGridTeamTypes.Columns[1].HeaderText = "Type Description"; dataGridTeamTypes.Columns[2].Visible = false; //Add a fourth virtual column for a marker flag to mark changed rows dataGridTeamTypes.Columns.Add("ChangedFlag", "Changed Flag"); dataGridTeamTypes.Columns[3].Visible = false; }
private void buttonSave_Click(object sender, EventArgs e) { DataTable lt_RowsForUpdate = new DataTable(); DataRow ls_DataRow; //Build internal table with rows for update lt_RowsForUpdate.Columns.Add("TeamTypeID"); lt_RowsForUpdate.Columns.Add("TeamTypeDesc"); lt_RowsForUpdate.Columns.Add("TeamTypeNumber");
lt_RowsForUpdate.Columns.Add("Changed");
//Check for Changes and write to DB
for (int i = 0; i < dataGridTeamTypes.Rows.Count; i++) { if (dataGridTeamTypes.Rows[i].Cells[3].Value != null && dataGridTeamTypes.Rows[i].Cells[3].Value.ToString() == "C") { ls_DataRow = lt_RowsForUpdate.NewRow(); ls_DataRow[0] = dataGridTeamTypes.Rows[i].Cells[0].Value; ls_DataRow[1] = dataGridTeamTypes.Rows[i].Cells[1].Value; ls_DataRow[2] = dataGridTeamTypes.Rows[i].Cells[2].Value; lt_RowsForUpdate.Rows.Add(ls_DataRow); } } theTeamTypesController.onButtonSave_Click(lt_RowsForUpdate); }
private void dataGridTeamTypes_CellValueChanged(object sender, DataGridViewCellEventArgs e) { //Mark rows which have been changed if (e.RowIndex >= 0) { dataGridTeamTypes.Rows[e.RowIndex].Cells[3].Value = "C"; } } } |