/// <summary> /// SEND REPORT IN MONTH /// </summary> /// <param name="TargetName"></param> internal void SendReportMonth(string TargetName, Business.TimeEvent timeEvent) { return; #region GET END OF DAY string endOfDay = string.Empty; DateTime timeCurrent = DateTime.Now; DateTime timeEndDay = new DateTime(); DateTime timeStartDay = new DateTime(); bool IsReportWeekend = false; string pathStatement = string.Empty; if (Business.Market.MarketConfig != null) { int count = Business.Market.MarketConfig.Count; for (int i = 0; i < count; i++) { if (Business.Market.MarketConfig[i].Code == "C12") { endOfDay = Business.Market.MarketConfig[i].StringValue; } if (Business.Market.MarketConfig[i].Code == "C26") { if (Business.Market.MarketConfig[i].BoolValue == 1) IsReportWeekend = true; } if (Business.Market.MarketConfig[i].Code == "C35") { pathStatement = Business.Market.MarketConfig[i].StringValue; } } } if (DateTime.Now.Hour < 10) timeCurrent = timeCurrent.AddDays(-1); timeEndDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day, 23, 59, 59); timeStartDay = new DateTime(timeCurrent.Year, timeCurrent.Month, 1, 00, 00, 00); #region COMMEND CODE BECAUSE DON'T NEED CHECK END OF DAY ALLWAY LAST DAY OF MONTH(03/05/2013->DD/MM/YYYY) //switch (endOfDay) //{ // case "Last day of month": // { // if (DateTime.Now.Hour < 10) // timeCurrent = timeCurrent.AddDays(-1); // timeEndDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day, 23, 59, 59); // timeStartDay = new DateTime(timeCurrent.Year, timeCurrent.Month, 1, 00, 00, 00); // } // break; // case "First day of month": // { // if (DateTime.Now.Hour > 10) // timeCurrent = timeCurrent.AddDays(1); // timeCurrent = timeCurrent.AddMonths(-1); // timeEndDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day, 0, 0, 0); // timeStartDay = new DateTime(timeCurrent.Year, timeCurrent.Month, 1, 00, 00, 00); // } // break; //} #endregion #endregion #region CHECK Generate statements at weekends if (timeStartDay.DayOfWeek == DayOfWeek.Sunday || timeStartDay.DayOfWeek == DayOfWeek.Saturday) { if (!IsReportWeekend) return; } #endregion #region SEND MAIL TO INVESTOR if (Business.Market.InvestorList != null && Business.Market.InvestorList.Count > 0) { int count = Business.Market.InvestorList.Count; for (int i = 0; i < count; i++) { List<Business.OpenTrade> listOpenTrade = new List<OpenTrade>(); List<Business.OpenTrade> listPendingOrder = new List<OpenTrade>(); List<Business.OpenTrade> listCommandHistory = new List<OpenTrade>(); #region GET ONLINE COMMAND OF INVESTOR if (Business.Market.CommandExecutor != null) { int countCommand = Business.Market.CommandExecutor.Count; for (int j = 0; j < countCommand; j++) { if (Business.Market.CommandExecutor[j].Investor.InvestorID == Business.Market.InvestorList[i].InvestorID) { bool isPending = TradingServer.Model.TradingCalculate.Instance.CheckIsPendingPosition(Business.Market.CommandExecutor[j].Type.ID); if (!isPending) { double tempProfit = Math.Round(Business.Market.CommandExecutor[j].Profit, 2); Business.Market.CommandExecutor[j].Profit = tempProfit; listOpenTrade.Add(Business.Market.CommandExecutor[j]); } else { double tempProfit = Math.Round(Business.Market.CommandExecutor[j].Profit, 2); Business.Market.CommandExecutor[j].Profit = tempProfit; listPendingOrder.Add(Business.Market.CommandExecutor[j]); } } } } #endregion #region GET COMMAND HISTORY OF INVESTOR listCommandHistory = TradingServer.Facade.FacadeGetCommandHistoryWithTime(Business.Market.InvestorList[i].InvestorID, timeStartDay, timeEndDay); #endregion Model.MailConfig newMailConfig = new Model.MailConfig(); newMailConfig = this.GetMailConfig(Business.Market.InvestorList[i]); #region SEND REPORT IF COMMAND > 0 if (listOpenTrade != null && listOpenTrade.Count > 0 || listPendingOrder != null && listPendingOrder.Count > 0 || listCommandHistory != null && listCommandHistory.Count > 0) { StringBuilder content = new StringBuilder(); Business.StatementTemplate newTemplate = new StatementTemplate(); content = newTemplate.GetStatementReport(listOpenTrade, listCommandHistory, listPendingOrder, Business.Market.InvestorList[i], timeEndDay); content.Replace("[ReportDay]", timeStartDay.ToShortDateString()); string tempContent = content.ToString(); #region CHECK SCALPER INVESTOR bool isScalper = this.CheckScalperInvestor(listCommandHistory); #endregion if (Business.Market.InvestorList[i].SendReport) { if (newMailConfig.isEnable) { if (!string.IsNullOrEmpty(newMailConfig.SmtpHost) && !string.IsNullOrEmpty(newMailConfig.MessageFrom) && !string.IsNullOrEmpty(newMailConfig.PasswordCredential)) { if (!string.IsNullOrEmpty(Business.Market.InvestorList[i].Email)) { content = content.Replace("[ScalperName]", ""); content = content.Replace("[Scalper]", ""); Model.TradingCalculate.Instance.SendMailMonthAsync(Business.Market.InvestorList[i].Email, "Monthly Statement", content.ToString(), newMailConfig); } } } } if (!string.IsNullOrEmpty(pathStatement) && pathStatement != "NaN") { //STREAM FILE SAVE CONTENT SEND MAIL TradingServer.Model.TradingCalculate.Instance.StreamMonthFile(content.ToString(), Business.Market.InvestorList[i].Code, timeStartDay, 0, pathStatement, isScalper); } if (!string.IsNullOrEmpty(content.ToString())) { Business.Statement newStatement = new Statement(); newStatement.Content = content.ToString(); newStatement.Email = Business.Market.InvestorList[i].Email; newStatement.InvestorCode = Business.Market.InvestorList[i].Code; newStatement.StatementType = 2; newStatement.TimeStatement = timeStartDay; Business.Market.ListStatement.Add(newStatement); } } #endregion } } #endregion if (!string.IsNullOrEmpty(pathStatement) && pathStatement != "NaN") { TradingServer.Model.TradingCalculate.Instance.StreamMonthFile(Business.Market.LogContentSendMailMonth, "", timeStartDay, 1, pathStatement); string folder = timeStartDay.Year.ToString() + timeStartDay.Month.ToString(); TradingServer.Model.TradingCalculate.Instance.ZipFolder(pathStatement + @"\" + folder, folder + ".zip", pathStatement + @"\" + folder + ".zip"); } }
/// <summary> /// SEND REPORT IN DAY /// </summary> /// <param name="TargetName"></param> internal void SendReportDay(string TargetName, Business.TimeEvent timeEvent) { return; string total = string.Empty; Business.Market.LogContentSendMail = string.Empty; #region GET END OF DAY DateTime timeCurrent = DateTime.Now; DateTime timeEndDay = new DateTime(); DateTime timeStartDay = new DateTime(); bool IsReportWeekends = false; string pathStatements = string.Empty; string serverName = string.Empty; #region GET MARKET CONFIG if (Business.Market.MarketConfig != null) { int count = Business.Market.MarketConfig.Count; for (int i = 0; i < count; i++) { if (Business.Market.MarketConfig[i].Code == "C02") { serverName = Business.Market.MarketConfig[i].StringValue; } if (Business.Market.MarketConfig[i].Code == "C26") { if (Business.Market.MarketConfig[i].BoolValue == 1) IsReportWeekends = true; } if (Business.Market.MarketConfig[i].Code == "C35") { pathStatements = Business.Market.MarketConfig[i].StringValue; } } } #endregion if (string.IsNullOrEmpty(pathStatements)) pathStatements = Environment.CurrentDirectory + DateTime.Now.Ticks + "_" + serverName; if (DateTime.Now.Hour < 10) timeCurrent = timeCurrent.AddDays(-1); timeStartDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day , 00, 00, 00); timeEndDay = new DateTime(timeCurrent.Year, timeCurrent.Month, timeCurrent.Day, 23, 59, 59); #endregion #region CHECK Generate statements at weekends if (timeStartDay.DayOfWeek == DayOfWeek.Saturday || timeStartDay.DayOfWeek == DayOfWeek.Sunday) { if (!IsReportWeekends) return; } #endregion //CLEAR LIST END OF DAY AGENT Business.Market.ListEODAgent.Clear(); #region SEND MAIL TO INVESTOR if (Business.Market.InvestorList != null && Business.Market.InvestorList.Count > 0) { int count = Business.Market.InvestorList.Count; for (int i = 0; i < count; i++) { List<Business.OpenTrade> listOpenTrade = new List<OpenTrade>(); List<Business.OpenTrade> listPendingOrder = new List<OpenTrade>(); List<Business.OpenTrade> listCommandHistory = new List<OpenTrade>(); #region GET ONLINE COMMAND OF INVESTOR if (Business.Market.InvestorList[i].CommandList != null) { int countCommand = Business.Market.InvestorList[i].CommandList.Count; for (int j = 0; j < countCommand; j++) { bool isPending = TradingServer.Model.TradingCalculate.Instance.CheckIsPendingPosition(Business.Market.InvestorList[i].CommandList[j].Type.ID); if (!isPending) { double tempProfit = Math.Round(Business.Market.InvestorList[i].CommandList[j].Profit, 2); Business.Market.InvestorList[i].CommandList[j].Profit = tempProfit; listOpenTrade.Add(Business.Market.InvestorList[i].CommandList[j]); } else { double tempProfit = Math.Round(Business.Market.InvestorList[i].CommandList[j].Profit, 2); Business.Market.InvestorList[i].CommandList[j].Profit = tempProfit; listPendingOrder.Add(Business.Market.InvestorList[i].CommandList[j]); } } } #endregion #region GET COMMAND HISTORY OF INVESTOR listCommandHistory = TradingServer.Facade.FacadeGetCommandHistoryWithTime(Business.Market.InvestorList[i].InvestorID, timeStartDay, timeEndDay); #endregion #region DATA > 0 if (listOpenTrade != null && listOpenTrade.Count > 0 || listPendingOrder != null && listPendingOrder.Count > 0 || listCommandHistory != null && listCommandHistory.Count > 0) { Model.MailConfig newMailConfig = new Model.MailConfig(); newMailConfig = this.GetMailConfig(Business.Market.InvestorList[i]); double tempBalance = Business.Market.InvestorList[i].PreviousLedgerBalance; StringBuilder content = new StringBuilder(); Business.ReportItem contentOpenPosition = new ReportItem(); Business.ReportItem contentClosePosition = new ReportItem(); StringBuilder contentPendingPosition = new StringBuilder(); Business.StatementTemplate newTemplate = new StatementTemplate(); content = newTemplate.GetStatementReport(listOpenTrade, listCommandHistory, listPendingOrder, Business.Market.InvestorList[i], timeEndDay); content.Replace("[ReportDay]", timeEndDay.ToShortDateString()); string tempContent = content.ToString(); #region CHECK SCALPER INVESTOR bool isScalper = this.CheckScalperInvestor(listCommandHistory); #endregion if (Business.Market.InvestorList[i].SendReport) { #region GET MAIL CONFIG AND SEND REPORT if (newMailConfig != null) { if (newMailConfig.isEnable) { if (!string.IsNullOrEmpty(newMailConfig.SmtpHost) && !string.IsNullOrEmpty(newMailConfig.MessageFrom) && !string.IsNullOrEmpty(newMailConfig.PasswordCredential)) { if (!string.IsNullOrEmpty(Business.Market.InvestorList[i].Email)) { content = content.Replace("[ScalperName]", ""); content = content.Replace("[Scalper]", ""); if (timeStartDay.DayOfWeek == DayOfWeek.Sunday || timeStartDay.DayOfWeek == DayOfWeek.Saturday) { if (IsReportWeekends) { Model.TradingCalculate.Instance.SendMailAsync(Business.Market.InvestorList[i].Email, "Daily Confirmation", content.ToString(), newMailConfig); } } else { Model.TradingCalculate.Instance.SendMailAsync(Business.Market.InvestorList[i].Email, "Daily Confirmation", content.ToString(), newMailConfig); } } } } } #endregion } if (!string.IsNullOrEmpty(pathStatements) && pathStatements != "NaN") { //STREAM FILE SAVE CONTENT SEND MAIL REPORT TradingServer.Model.TradingCalculate.Instance.StreamFile(tempContent.ToString(), Business.Market.InvestorList[i].Code, timeStartDay, 0, pathStatements, isScalper); } if (!string.IsNullOrEmpty(content.ToString())) { Business.Statement newStatement = new Statement(); newStatement.InvestorCode = Business.Market.InvestorList[i].Code; newStatement.StatementType = 1; newStatement.TimeStatement = timeStartDay; newStatement.Email = Business.Market.InvestorList[i].Email; newStatement.Content = tempContent.ToString(); Business.Market.ListStatement.Add(newStatement); } } #endregion #region UPDATE PREVIOUS LEDGER BALANCE TradingServer.Facade.FacadeUpdatePreviousLedgerBalance(Business.Market.InvestorList[i].InvestorID, Business.Market.InvestorList[i].PreviousLedgerBalance); #endregion #region PROCESS LAST ACCOUNT Business.SumLastAccount newSumLastAccount = new SumLastAccount(); newSumLastAccount.InvestorAccount = Business.Market.InvestorList[i]; newSumLastAccount.ListHistory = listCommandHistory; if (newSumLastAccount.ListOpenTrade == null) newSumLastAccount.ListOpenTrade = new List<OpenTrade>(); if (listOpenTrade != null) { int countOpenTrade = listOpenTrade.Count; for (int j = 0; j < countOpenTrade; j++) { Business.OpenTrade newOpenTrade = new OpenTrade(); newOpenTrade.AgentCommission = listOpenTrade[j].AgentCommission; newOpenTrade.ClientCode = listOpenTrade[j].ClientCode; newOpenTrade.ClosePrice = listOpenTrade[j].ClosePrice; newOpenTrade.CloseTime = listOpenTrade[j].CloseTime; newOpenTrade.CommandCode = listOpenTrade[j].CommandCode; newOpenTrade.Comment = listOpenTrade[j].Comment; newOpenTrade.Commission = listOpenTrade[j].Commission; newOpenTrade.ExpTime = listOpenTrade[j].ExpTime; newOpenTrade.FreezeMargin = listOpenTrade[j].FreezeMargin; newOpenTrade.ID = listOpenTrade[j].ID; newOpenTrade.IGroupSecurity = listOpenTrade[j].IGroupSecurity; newOpenTrade.Investor = listOpenTrade[j].Investor; newOpenTrade.IsClose = listOpenTrade[j].IsClose; newOpenTrade.IsHedged = listOpenTrade[j].IsHedged; newOpenTrade.Margin = listOpenTrade[j].Margin; newOpenTrade.MaxDev = listOpenTrade[j].MaxDev; newOpenTrade.NumberUpdate = listOpenTrade[j].NumberUpdate; newOpenTrade.OpenPrice = listOpenTrade[j].OpenPrice; newOpenTrade.OpenTime = listOpenTrade[j].OpenTime; double tempProfit = listOpenTrade[j].Profit; newOpenTrade.Profit = tempProfit; newOpenTrade.Size = listOpenTrade[j].Size; newOpenTrade.SpreaDifferenceInOpenTrade = listOpenTrade[j].SpreaDifferenceInOpenTrade; newOpenTrade.StopLoss = listOpenTrade[j].StopLoss; newOpenTrade.Swap = listOpenTrade[j].Swap; newOpenTrade.Symbol = listOpenTrade[j].Symbol; newOpenTrade.TakeProfit = listOpenTrade[j].TakeProfit; newOpenTrade.Taxes = listOpenTrade[j].Taxes; newOpenTrade.TotalSwap = listOpenTrade[j].TotalSwap; newOpenTrade.Type = listOpenTrade[j].Type; newSumLastAccount.ListOpenTrade.Add(newOpenTrade); } } newSumLastAccount.TimeEndDay = timeEndDay; Business.Market.ListLastAccount.Add(newSumLastAccount); #endregion } } #endregion #region SAVE FILE TO HARD DRIVE if (!string.IsNullOrEmpty(pathStatements) && pathStatements != "NaN") { TradingServer.Model.TradingCalculate.Instance.StreamFile(Business.Market.LogContentSendMail, "", timeStartDay, 1, pathStatements); string folder = timeStartDay.Year.ToString() + timeStartDay.Month.ToString() + timeStartDay.Day.ToString(); TradingServer.Model.TradingCalculate.Instance.ZipFolder(pathStatements + @"\" + folder, folder + ".zip", pathStatements + @"\" + folder + ".zip"); } #endregion }