private void readTable(T_SQLiteTable tTable) { dbListView.BeginUpdate(); dbListView.Items.Clear(); ListViewItem lvBackItem = new ListViewItem("..", 0); ListViewItem.ListViewSubItem[] lvBackSubItems = new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem(lvBackItem, "Back to"), new ListViewItem.ListViewSubItem(lvBackItem, "Parent") }; lvBackItem.SubItems.AddRange(lvBackSubItems); dbListView.Items.Add(lvBackItem); MethodInfo readLabelDescriptionMethod = typeof(SQLite806xDB).GetMethod("ReadLabelDescription"); if (readLabelDescriptionMethod == null) { return; } MethodInfo readLabelDescriptionTypeMethod = readLabelDescriptionMethod.MakeGenericMethod(tTable.Type); Dictionary <int, string[]> dResult = (Dictionary <int, string[]>)readLabelDescriptionTypeMethod.Invoke(sqlDB806x, null); if (dResult != null) { foreach (int rowId in dResult.Keys) { string[] arrLabelDescription = dResult[rowId]; ListViewItem lvItem = new ListViewItem(arrLabelDescription[0], 1); lvItem.Name = rowId.ToString(); lvItem.Tag = rowId; lvItem.ToolTipText = arrLabelDescription[1]; ListViewItem.ListViewSubItem[] lvSubItems = new ListViewItem.ListViewSubItem[] { new ListViewItem.ListViewSubItem(lvItem, "Record"), new ListViewItem.ListViewSubItem(lvItem, arrLabelDescription[1]) }; lvItem.SubItems.AddRange(lvSubItems); dbListView.Items.Add(lvItem); } } dbListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); dbListView.EndUpdate(); this.Text = tTable.Label + " - " + (dbListView.Items.Count - 1).ToString() + " record(s)"; }
public SQLite806xRecordForm(ref SQLite806xDB db806x, ref T_SQLiteTable tTable, ref object rRecord) { sqlDB806x = db806x; sqLiteTable = tTable; sqLiteRecord = rRecord; if (sqLiteRecord != null) { this.Tag = sqLiteTable.Name + "." + ((R_SQLite_Core)sqLiteRecord).RowId.ToString(); } InitializeComponent(); try { Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); } catch { } this.Load += new EventHandler(Form_Load); this.FormClosing += new FormClosingEventHandler(Form_FormClosing); }
private void openRecord(T_SQLiteTable tTable, int rowId) { object rRecord = null; int iFirstFreeFormIndex = -1; // Searching for free/opened form for (int iForm = 0; iForm < arrRecordForms.Length; iForm++) { if (arrRecordForms[iForm] == null) { if (iFirstFreeFormIndex < 0) { iFirstFreeFormIndex = iForm; } continue; } if (arrRecordForms[iForm].Tag.ToString() == tTable.Name + "." + rowId.ToString()) { arrRecordForms[iForm].Show(); arrRecordForms[iForm].Focus(); return; } } if (iFirstFreeFormIndex < 0) { return; } System.Collections.IList lstResult = null; if (rowId < 0) { MethodInfo newRowMethod = typeof(SQLite806xDB).GetMethod("newRow"); if (newRowMethod == null) { return; } MethodInfo newRowTypeMethod = newRowMethod.MakeGenericMethod(tTable.Type); lstResult = new List <object>() { newRowTypeMethod.Invoke(sqlDB806x, null) }; } else { MethodInfo readMethod = null; foreach (MethodInfo mInfo in typeof(SQLite806xDB).GetMethods()) { if (mInfo.Name != "Read") { continue; } if (mInfo.GetParameters().Length == 0) { continue; } readMethod = mInfo; break; } if (readMethod == null) { return; } MethodInfo readTypeMethod = readMethod.MakeGenericMethod(tTable.Type); lstResult = (System.Collections.IList)readTypeMethod.Invoke(sqlDB806x, new object[] { rowId, new List <string>() { }, string.Empty, string.Empty }); } if (lstResult.Count != 1) { return; } rRecord = lstResult[0]; lstResult = null; arrRecordForms[iFirstFreeFormIndex] = new SQLite806xRecordForm(ref sqlDB806x, ref tTable, ref rRecord); arrRecordForms[iFirstFreeFormIndex].FormClosed += new FormClosedEventHandler(recordForm_FormClosed); arrRecordForms[iFirstFreeFormIndex].RecordUpdated += new EventHandler(recordForm_RecordUpdated); arrRecordForms[iFirstFreeFormIndex].RecordRemoved += new EventHandler(recordForm_RecordRemoved); arrRecordForms[iFirstFreeFormIndex].Show(); arrRecordForms[iFirstFreeFormIndex].Focus(); }
private void removeRecord(T_SQLiteTable tTable, int rowId) { // Searching for opened form for (int iForm = 0; iForm < arrRecordForms.Length; iForm++) { if (arrRecordForms[iForm] == null) { continue; } if (arrRecordForms[iForm].Tag.ToString() == tTable.Name + "." + rowId.ToString()) { arrRecordForms[iForm].Close(); break; } } MethodInfo newRowMethod = typeof(SQLite806xDB).GetMethod("newRow"); if (newRowMethod == null) { return; } MethodInfo newRowTypeMethod = newRowMethod.MakeGenericMethod(tTable.Type); object recordForRowId = newRowTypeMethod.Invoke(sqlDB806x, null); F_SQLiteField recordRowIdField = (F_SQLiteField)recordForRowId.GetType().GetProperty("RowId").GetValue(recordForRowId, null); recordRowIdField.Value = rowId; recordRowIdField = null; MethodInfo deleteMethod = null; foreach (MethodInfo mInfo in typeof(SQLite806xDB).GetMethods()) { if (mInfo.Name != "Delete") { continue; } if (mInfo.GetParameters().Length != 1) { continue; } deleteMethod = mInfo; break; } if (deleteMethod == null) { return; } MethodInfo deleteTypeMethod = deleteMethod.MakeGenericMethod(tTable.Type); try { System.Collections.IList rList = (System.Collections.IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(recordForRowId.GetType())); rList.Add(recordForRowId); bool bResult = (bool)deleteTypeMethod.Invoke(sqlDB806x, new object[] { rList }); rList = null; if (!bResult) { throw new Exception("Removal has failed."); } } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } // Refresh if (tTable == (T_SQLiteTable)dbListView.Tag) { readTable(tTable); } }