public bool insert(List <mTag> items) { FIX_STAN789_T ent = new FIX_STAN789_T(); try { foreach (var p in ent.GetType().GetProperties()) { if (items.Any(k => k.NameInDb == p.Name)) { mTag t = items.First(k => k.NameInDb == p.Name); var targetType = IsNullableType(p.PropertyType) ? Nullable.GetUnderlyingType(p.PropertyType) : p.PropertyType; //Returns an System.Object with the specified System.Type and whose value is //equivalent to the specified object. object propertyVal = Convert.ChangeType(t.Value, targetType); //Set the value of the property p.SetValue(ent, propertyVal, null); } } } catch (Exception ex) { } ent.INCOMIN_DATE = DateTime.Now; // ! change!!! ent.WHEN = DateTime.Now; return(AddRecord(ent)); }
public bool AddRecord(FIX_STAN789_T data) { bool result = false; try { decimal maxID = context.FIX_STAN789_T.First(x => x.ID == context.FIX_STAN789_T.Max(i => i.ID)).ID; data.ID = maxID + 1; context.FIX_STAN789_T.Add(data); context.SaveChanges(); isConnectionOK = true; OnReportMessage("Remote DB, inserted with id=" + data.ID.ToString()); result = true; } catch (Exception ex) { OnReportMessage("Insert fail for remote DB"); OnReportMessage(ex.Message.ToString()); isConnectionOK = false; if (ex.InnerException != null) { OnReportMessage(ex.InnerException.Message.ToString()); } result = false; } return(result); }
/// <summary> /// Get list of names of database table fields /// </summary> /// <returns></returns> public List <string> GetFields() { FIX_STAN789_T ent = new FIX_STAN789_T(); List <string> list = new List <string>(); foreach (var prop in ent.GetType().GetProperties()) { if (prop.PropertyType != typeof(DateTime) & !prop.Name.Equals("id", StringComparison.OrdinalIgnoreCase)) { string s = prop.Name; list.Add(s); } } return(list); }
private FIX_STAN789_T generateRecord(decimal id) { FIX_STAN789_T r = new FIX_STAN789_T(); int i = Decimal.ToInt32(id); r.ID = id; r.COUNTER = i * 2; r.BREAK = true; r.ERASE = true; r.INCOMIN_DATE = DateTime.Now; r.N_STAN = id + 2; r.REPLAC = false; r.START_STOP = true; r.WHEN = DateTime.Now; r.G_UCHASTOK = "s"; return(r); }