/// <summary> /// /// </summary> /// <param name="objVirtualDealer"></param> /// <returns></returns> internal string AddNewVirtualDealer(Business.VirtualDealer objVirtualDealer) { string result = "-1"; System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); System.Data.SqlClient.SqlTransaction trans = null; DSTableAdapters.VirtualDealerTableAdapter virtualDealerAdap = new DSTableAdapters.VirtualDealerTableAdapter(); DSTableAdapters.VirtualDealerConfigTableAdapter dealerConfigAdap = new DSTableAdapters.VirtualDealerConfigTableAdapter(); DSTableAdapters.IVirtualDealerTableAdapter iVirtualDealerAdap = new DSTableAdapters.IVirtualDealerTableAdapter(); try { conn.Open(); trans = conn.BeginTransaction(); virtualDealerAdap.Connection = conn; virtualDealerAdap.Transaction = trans; int id = int.Parse(virtualDealerAdap.AddNewVirtualDealer(objVirtualDealer.Name, "").ToString()); result = id.ToString(); if (id == -1) { throw new Exception("Data error"); } dealerConfigAdap.Connection = conn; dealerConfigAdap.Transaction = trans; DateTime DateValue = DateTime.Parse("1753-01-01 00:00:00.000"); dealerConfigAdap.Insert(null, "Profit max pip", id, "VD01", -1, "NaN", objVirtualDealer.ProfitMaxPip.ToString(), DateValue); dealerConfigAdap.Insert(null, "Loss max pip", id, "VD02", -1, "NaN", objVirtualDealer.LossMaxPip.ToString(), DateValue); dealerConfigAdap.Insert(null, "Min volume", id, "VD03", -1, "NaN", objVirtualDealer.StartVolume.ToString(), DateValue); dealerConfigAdap.Insert(null, "Max volume", id, "VD04", -1, "NaN", objVirtualDealer.EndVolume.ToString(), DateValue); dealerConfigAdap.Insert(null, "Delay", id, "VD05", -1, "NaN", objVirtualDealer.Delay.ToString(), DateValue); dealerConfigAdap.Insert(null, "Additional pip", id, "VD06", -1, "NaN", objVirtualDealer.AdditionalPip.ToString(), DateValue); dealerConfigAdap.Insert(null, "Mode", id, "VD07", -1, "NaN", objVirtualDealer.Mode.ToString(), DateValue); dealerConfigAdap.Insert(null, "IsEnable", id, "VD08", objVirtualDealer.IsEnable ? 1 : 0, "NaN", "NaN", DateValue); dealerConfigAdap.Insert(null, "IsLimitAuto", id, "VD09", objVirtualDealer.IsLimitAuto ? 1 : 0, "NaN", "NaN", DateValue); dealerConfigAdap.Insert(null, "IsStopAuto", id, "VD10", objVirtualDealer.IsStopAuto ? 1 : 0, "NaN", "NaN", DateValue); dealerConfigAdap.Insert(null, "IsStopSlippage", id, "VD11", objVirtualDealer.IsStopSlippage ? 1 : 0, "NaN", "NaN", DateValue); dealerConfigAdap.Insert(null, "GroupCondition", id, "VD12", -1, objVirtualDealer.GroupCondition, "NaN", DateValue); dealerConfigAdap.Insert(null, "SymbolCodition", id, "VD13", -1, objVirtualDealer.SymbolCondition, "NaN", DateValue); iVirtualDealerAdap.Connection = conn; iVirtualDealerAdap.Transaction = trans; for (int i = 0; i < objVirtualDealer.IVirtualDealer.Count; i++) { iVirtualDealerAdap.Insert(objVirtualDealer.IVirtualDealer[i].InvestorGroupID, objVirtualDealer.IVirtualDealer[i].SymbolID, id); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); return "Data error"; } finally { virtualDealerAdap.Connection.Close(); dealerConfigAdap.Connection.Close(); iVirtualDealerAdap.Connection.Close(); conn.Close(); } return result; }
/// <summary> /// /// </summary> /// <param name="objVirtualDealer"></param> /// <returns></returns> internal string UpdateVirtualSymbol(Business.VirtualDealer objVirtualDealer) { string result = ""; System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.IVirtualDealerTableAdapter iVirtualDealerAdap = new DSTableAdapters.IVirtualDealerTableAdapter(); System.Data.SqlClient.SqlTransaction trans = null; try { conn.Open(); trans = conn.BeginTransaction(); iVirtualDealerAdap.Connection = conn; iVirtualDealerAdap.Transaction = trans; int rowEffect = iVirtualDealerAdap.DeleteByVirtualDealerID(objVirtualDealer.ID); for (int i = 0; i < objVirtualDealer.IVirtualDealer.Count; i++) { rowEffect = iVirtualDealerAdap.Insert(objVirtualDealer.IVirtualDealer[i].InvestorGroupID, objVirtualDealer.IVirtualDealer[i].SymbolID, objVirtualDealer.ID); if (rowEffect == 0) { throw new Exception("Can't insert IDealer"); } } result = "1"; trans.Commit(); } catch (Exception ex) { trans.Rollback(); result = "Data error"; } finally { iVirtualDealerAdap.Connection.Close(); conn.Close(); } return result; }