/// <summary> /// 添加期货交易记录 /// 成交记录只在委托完成后记录,如果委托未完成,就等它完成 /// 因此这张表只会增加,不会删除或者修改 /// --2015.12.25 /// </summary> /// <param name="ret"></param> public static void CreateFutureDLRecord(object ret) { if (DBAccessLayer.DBEnable == false) { return; } RecordItem record = (RecordItem)ret; if (record != null) { lock (DLtableLock) { var selected = (from row in DbEntity.DL_TAOLI_TABLE where (row.DL_STRATEGY == record.StrategyId && row.DL_CODE == record.Code && row.DL_TYPE == "f") select row); if (selected.Count() > 0) { foreach (var i in selected.ToList()) { DbEntity.DL_TAOLI_TABLE.Remove(i); } } DL_TAOLI_TABLE item = new DL_TAOLI_TABLE() { DL_GUID = Guid.NewGuid(), DL_STRATEGY = record.StrategyId, DL_DIRECTION = Convert.ToInt16(record.Orientation), DL_CODE = record.Code, DL_NAME = record.Code, DL_STATUS = record.Status.ToString(), DL_TYPE = "f", DL_STOCK_AMOUNT = record.VolumeTraded, DL_BARGAIN_PRICE = Convert.ToDouble(record.Price), DL_BARGAIN_MONEY = Convert.ToDouble(record.Price) * record.VolumeTraded, DL_BARGAIN_TIME = record.OrderTime_Start.ToString(), DL_NO = record.OrderSysID.Trim() }; DbEntity.DL_TAOLI_TABLE.Add(item); Dbsavechage("CreateFutureDLRecord"); Thread.Sleep(10); } } }
/// <summary> /// 尝试数据库的访问和修改 /// </summary> public static void CheckDB() { MoneyEntityEntities1 DbEntity = new MoneyEntityEntities1(); SG_TAOLI_OPEN_TABLE record = new SG_TAOLI_OPEN_TABLE() { SG_GUID = Guid.NewGuid(), SG_ID = "Test", SG_Contract = "test", SG_OP_POINT = 0, SG_HAND_NUM = 0, SG_INDEX = 0, SG_WEIGHT_LIST = "test", SG_INIT_TRADE_LIST = "test", SG_STATUS = 0, SG_CREATE_TIME = DateTime.Now, SG_LATEST_TRADE_LIST = "test", SG_USER = "******", }; DbEntity.SG_TAOLI_OPEN_TABLE.Add(record); DbEntity.SaveChanges(); Thread.Sleep(10); var _selectedItem = (from item in DbEntity.SG_TAOLI_OPEN_TABLE where item.SG_ID == "Test" select item); DbEntity.SG_TAOLI_OPEN_TABLE.Remove((SG_TAOLI_OPEN_TABLE)_selectedItem.ToList()[0]); DbEntity.SaveChanges(); Thread.Sleep(10); SG_TAOLI_CLOSE_TABLE item2 = new SG_TAOLI_CLOSE_TABLE() { SG_GUID = Guid.NewGuid(), SG_ID = "test", SG_OPEN_ID = "test", SG_INIT_POSITION_LIST = "test", SG_LATEST_POSITION_LIST = "test", SG_FUTURE_CONTRACT = "test", SG_SHORT_POINT = 0, SG_HAND = 0, SG_COE = 0, SG_SD = 0, SG_SA = 0, SG_PE = 0, SG_BAS = 0, SG_STATUS = 0, SG_CREATE_TIME = DateTime.Now, SG_USER = "******" }; DbEntity.SG_TAOLI_CLOSE_TABLE.Add(item2); DbEntity.SaveChanges(); var _selectedItem2 = (from item in DbEntity.SG_TAOLI_CLOSE_TABLE where item.SG_ID == "test" && item.SG_STATUS == 0 select item); DbEntity.SG_TAOLI_CLOSE_TABLE.Remove(_selectedItem2.ToList()[0]); DbEntity.SaveChanges(); SG_TAOLI_STATUS_TABLE item3 = new SG_TAOLI_STATUS_TABLE() { SG_GUID = Guid.NewGuid(), SG_ID = "test", SG_STATUS = 0, SG_UPDATE_TIME = DateTime.Now }; DbEntity.SG_TAOLI_STATUS_TABLE.Add(item3); DbEntity.SaveChanges(); var _selectedItem3 = (from item in DbEntity.SG_TAOLI_STATUS_TABLE where item.SG_ID == "test" select item); DbEntity.SG_TAOLI_STATUS_TABLE.Remove(_selectedItem3.ToList()[0]); DbEntity.SaveChanges(); Thread.Sleep(10); OL_TAOLI_LIST_TABLE item4 = new OL_TAOLI_LIST_TABLE() { OL_GUID = Guid.NewGuid(), SG_ID = "test", OL_LIST = "test", OL_TIME = DateTime.Now }; DbEntity.OL_TAOLI_LIST_TABLE.Add(item4); DbEntity.SaveChanges(); Thread.Sleep(10); var selected4 = (from item in DbEntity.OL_TAOLI_LIST_TABLE where item.SG_ID == "test" select item); DbEntity.OL_TAOLI_LIST_TABLE.Remove(selected4.ToList()[0]); DbEntity.SaveChanges(); Thread.Sleep(10); ER_TAOLI_TABLE record5 = new ER_TAOLI_TABLE() { ER_GUID = Guid.NewGuid(), ER_ID = "test", //ER_STRATEGY = entrust.StrategyId, ER_ORDER_TYPE = "test", ER_ORDER_EXCHANGE_ID = "test", //ER_CODE = entrust.Code, //ER_DIRECTION = entrust.Direction }; DbEntity.ER_TAOLI_TABLE.Add(record5); DbEntity.SaveChanges(); Thread.Sleep(10); var selected5 = (from item in DbEntity.ER_TAOLI_TABLE where item.ER_ID == "test" select item); DbEntity.ER_TAOLI_TABLE.Remove(selected5.ToList()[0]); DbEntity.SaveChanges(); Thread.Sleep(10); DL_TAOLI_TABLE item6 = new DL_TAOLI_TABLE() { DL_GUID = Guid.NewGuid(), DL_STRATEGY = "test", DL_DIRECTION = 0, DL_CODE = "test", DL_NAME = "test", DL_STATUS = "test", DL_TYPE = "test", DL_STOCK_AMOUNT = 0, DL_BARGAIN_PRICE = 0, DL_BARGAIN_MONEY = 0, DL_BARGAIN_TIME = "test", DL_NO = "test", DL_LOAD = true }; DbEntity.DL_TAOLI_TABLE.Add(item6); DbEntity.SaveChanges(); Thread.Sleep(10); var _selecteditem6 = (from item in DbEntity.DL_TAOLI_TABLE where item.DL_STRATEGY == "test" select item); DbEntity.DL_TAOLI_TABLE.Remove(_selecteditem6.ToList()[0]); DbEntity.SaveChanges(); Thread.Sleep(10); CC_TAOLI_TABLE item7 = new CC_TAOLI_TABLE() { CC_CODE = "test", CC_TYPE = "test", CC_AMOUNT = 0, CC_BUY_PRICE = 0, CC_USER = "******" }; DbEntity.CC_TAOLI_TABLE.Add(item7); DbEntity.SaveChanges(); Thread.Sleep(10); var _selecteditem7 = (from item in DbEntity.CC_TAOLI_TABLE where item.CC_CODE == "test" select item); DbEntity.CC_TAOLI_TABLE.Remove(_selecteditem7.ToList()[0]); DbEntity.SaveChanges(); }
/// <summary> /// 添加股票交易记录 /// 成交记录只在委托完成后记录,如果委托未完成,就等它完成 /// 因此这张表只会增加,不会删除或者修改 /// --2015.08-07 /// </summary> /// <param name="ret"></param> public static void CreateDLRecord(object ret) { if (DBAccessLayer.DBEnable == false) { return; } managedBargainreturnstruct record = (managedBargainreturnstruct)ret; if (record != null) { lock (DLtableLock) { string type = "s"; if (record.OrderType == 115) type = "s"; else if (record.OrderType == 102) type = "f"; string bargin_time = DateTime.Now.ToString(); DL_TAOLI_TABLE item = new DL_TAOLI_TABLE() { DL_GUID = Guid.NewGuid(), DL_STRATEGY = record.strategyId, DL_DIRECTION = record.direction, DL_CODE = record.Security_code, DL_NAME = record.Security_name, DL_STATUS = record.OrderStatus.ToString(), DL_TYPE = type, DL_STOCK_AMOUNT = record.stock_amount, DL_BARGAIN_PRICE = record.bargain_price / 1000, DL_BARGAIN_MONEY = record.bargain_money, DL_BARGAIN_TIME =bargin_time, DL_NO = record.OrderSysID.ToString(), DL_LOAD = true }; DbEntity.DL_TAOLI_TABLE.Add(item); Dbsavechage("CreateDLRecord"); Thread.Sleep(10); } } }