public static void WriteToDb(Record record) { try { var logsRs = new IMRecordset(MD.SysLogs.TableName, IMRecordset.Mode.ReadWrite); using (var logsRsScope = logsRs.OpenForAdd( MD.SysLogs.Fields.Id, MD.SysLogs.Fields.Event, MD.SysLogs.Fields.TableName, MD.SysLogs.Fields.Count, MD.SysLogs.Fields.Info, MD.SysLogs.Fields.Who, MD.SysLogs.Fields.When )) { var currentTime = DateTime.Now; var currentUser = IM.ConnectedUser(); logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: {record.Message}"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); if (record.Duration > 0) { logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: Duration {record.Duration}ms"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); } if (!string.IsNullOrEmpty(record.Data)) { logsRs.AddNew(MD.SysLogs.TableName, MD.SysLogs.Fields.Id); logsRs.Put(MD.SysLogs.Fields.Event, record.Type.ToString()); logsRs.Put(MD.SysLogs.Fields.TableName, MD.SysLogs.TableName); logsRs.Put(MD.SysLogs.Fields.Count, 1); logsRs.Put(MD.SysLogs.Fields.Info, $"{record.Process}: {record.Data}"); logsRs.Put(MD.SysLogs.Fields.Who, currentUser); logsRs.Put(MD.SysLogs.Fields.When, currentTime); logsRs.Update(); } } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString(), "Logger.WriteToDb", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } }
public static void CreateEntity <T>(T entity) where T : class, IRepositoryEntity, IRepositoryCreatedEntity, new() { var entityDbName = entity.GetTableName(); var idFieldName = entity.GetIdFieldName(); var fields = entity.GetFieldNames(); var source = new IMRecordset(entityDbName, IMRecordset.Mode.ReadWrite); source.Select(fields); source.SetWhere(idFieldName, IMRecordset.Operation.Eq, -1); using (source.OpenWithScope()) { source.AddNew(); entity.SaveToRecordset(source); source.Update(); } }
public static void AddNew(this IMRecordset recordset, string tableNmae, string fieldName) { recordset.AddNew(); recordset.PutNextId(tableNmae, fieldName); }