using System; using System.Collections.Generic; using System.Text; using System.Data.SqlServerCe; using System.Data; namespace CrimeScene.Logic { abstract class Table : Validation { // Data members protected SqlCeConnection conn; protected SqlCeDataAdapter dataAdapter; protected DataTable dataTable; protected Action action; protected Mapper mapper; protected string exceptionMsg; protected string dateTime; protected int primaryKey; // Database not DataSet protected int selectedRecord; // Enums public enum IdType : int { // Used for switch so values matter Unknown = -1 } // Abstract abstract public int Id(); abstract protected void dataAdapter_RowUpdated(object sender, SqlCeRowUpdatedEventArgs e); // Constructor public Table(SqlCeConnection conn, SqlCeDataAdapter dataAdapter, DataTable dataTable, Action action) { this.conn = conn; this.dataAdapter = dataAdapter; this.dataTable = dataTable; this.action = action; this.mapper = new Mapper(); this.primaryKey = (int) IdType.Unknown; this.selectedRecord = -1; this.dateTime = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString(); dataAdapter.RowUpdated += new SqlCeRowUpdatedEventHandler(dataAdapter_RowUpdated); } // Functions protected void ClearRows(DataTable dataTable) { for (int i = 0; i < dataTable.Rows.Count; i++) { dataTable.Rows[i].Delete(); } } public void releaseRecord() { this.selectedRecord = -1; this.primaryKey = (int) IdType.Unknown; } public void holdRecord(int index) { if (index >= 0) { // index comes form Find, then no mapping required // Look up data position against index using Mappper this.selectedRecord = this.mapper.getMapping(index); this.primaryKey = Id(); } } public bool Open() { return this.selectedRecord >= 0; } public int Count() { return this.dataTable.Rows.Count; } } }