/// <summary> /// /// </summary> /// <param name="OnlineCommandID"></param> /// <returns></returns> internal bool DeleteOnlineCommand(int OnlineCommandID) { bool Result = false; System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adap = new DSTableAdapters.OnlineCommandTableAdapter(); try { conn.Open(); adap.Connection = conn; int NumberDelete = adap.DeleteOnlineCommandByID(OnlineCommandID); if (NumberDelete > 0) Result = true; } catch (Exception ex) { return false; } finally { adap.Connection.Close(); conn.Close(); } return Result; }
/// <summary> /// /// </summary> /// <param name="listOpenTrade"></param> /// <returns></returns> internal bool MultipleCloseOpenTrade(List<TradingServer.Business.OpenTrade> listOpenTrade) { bool result = false; System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(DBConnection.DBConnection.Connection); DSTableAdapters.OnlineCommandTableAdapter adapOnline = new DSTableAdapters.OnlineCommandTableAdapter(); DSTableAdapters.CommandHistoryTableAdapter adapHistory = new DSTableAdapters.CommandHistoryTableAdapter(); SqlTransaction tran; conn.Open(); adapOnline.Connection = conn; adapHistory.Connection = conn; tran = conn.BeginTransaction(); adapOnline.Transaction = tran; adapHistory.Transaction = tran; try { if (listOpenTrade != null) { int count = listOpenTrade.Count; for (int i = 0; i < count; i++) { int ResultHistory = -1; //Add Command To Command History ResultHistory = int.Parse(adapHistory.AddNewCommandHistory(listOpenTrade[i].Investor.InvestorID, listOpenTrade[i].Type.ID, listOpenTrade[i].OpenTime, listOpenTrade[i].OpenPrice, listOpenTrade[i].CloseTime, listOpenTrade[i].ClosePrice, listOpenTrade[i].Profit, listOpenTrade[i].Swap, listOpenTrade[i].Commission, listOpenTrade[i].ExpTime, listOpenTrade[i].Size, listOpenTrade[i].StopLoss, listOpenTrade[i].TakeProfit, listOpenTrade[i].ClientCode, listOpenTrade[i].CommandCode, listOpenTrade[i].Symbol.SymbolID, listOpenTrade[i].Taxes, listOpenTrade[i].AgentCommission, listOpenTrade[i].Comment, listOpenTrade[i].TotalSwap, false, listOpenTrade[i].RefCommandID, listOpenTrade[i].AgentRefConfig, false, false).ToString()); if (ResultHistory > 0) { //Update Command In Database int deleteOpenTrade = adapOnline.DeleteOnlineCommandByID(listOpenTrade[i].ID); if (deleteOpenTrade < 1) { tran.Rollback(); return false; } } else { tran.Rollback(); return false; } bool removeDataOnline = listOpenTrade[0].Investor.MultipleCloseCommand(listOpenTrade[i]); if (!removeDataOnline) { tran.Rollback(); return false; } } } if (listOpenTrade != null) { int countCommand = listOpenTrade.Count; for (int i = 0; i < countCommand; i++) { //Send Notify to Manager TradingServer.Facade.FacadeSendNoticeManagerRequest(2, listOpenTrade[i]); } } tran.Commit(); result = true; } catch (Exception ex) { tran.Rollback(); return false; } finally { tran.Dispose(); adapOnline.Connection.Close(); adapHistory.Connection.Close(); conn.Close(); } return result; }