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); } }
private void controlValue_Modified(object sender, EventArgs e) { F_SQLiteField fField = (F_SQLiteField)((Control)sender).Tag; if (fField == null) { return; } object newValue = null; Exception exError = null; if (sender.GetType() == typeof(TextBox)) { if (!((TextBox)sender).Modified) { return; } } if (sender.GetType() == typeof(TextBox)) { newValue = ((TextBox)sender).Text; } else if (sender.GetType() == typeof(DateTimePicker)) { newValue = ((DateTimePicker)sender).Value; } else if (sender.GetType() == typeof(CheckBox)) { newValue = ((CheckBox)sender).Checked; } // Type and Length Check switch (fField.EDbType) { case DbType.Int32: try { newValue = Convert.ToInt32(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.Int64: try { newValue = Convert.ToInt64(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.Double: try { newValue = Convert.ToDouble(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.DateTime: try { newValue = Convert.ToDateTime(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.Boolean: try { newValue = Convert.ToBoolean(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.Binary: break; case DbType.String: try { newValue = Convert.ToString(newValue); } catch (Exception ex) { exError = ex; } break; case DbType.Object: break; } F_SQLiteField fRecordField = (F_SQLiteField)sqLiteRecord.GetType().GetProperty(fField.Name).GetValue(sqLiteRecord, null); if (exError != null) // Rollback { if (sender.GetType() == typeof(TextBox)) { ((TextBox)sender).Text = fRecordField.Value == null ? string.Empty : fRecordField.Value.ToString(); } else if (sender.GetType() == typeof(DateTimePicker)) { ((DateTimePicker)sender).Value = fRecordField.Value == null ? DateTime.Today : Convert.ToDateTime(fRecordField.Value); } else if (sender.GetType() == typeof(CheckBox)) { ((CheckBox)sender).Checked = fRecordField.Value == null ? false : Convert.ToBoolean(fRecordField.Value); } MessageBox.Show(exError.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } else // Change { // Change except for Attachment, already managed if (fField.EDbType != DbType.Binary) { fRecordField.Value = newValue; } if (sender.GetType() == typeof(TextBox)) { ((TextBox)sender).Modified = false; } } Control[] arrControls = null; arrControls = this.Controls.Find("updateButton", true); if (arrControls.Length == 1) { arrControls[0].Enabled = true; } arrControls = null; }