private void ToolStripButton_CopyTemplate_Click(object sender, EventArgs e) { StockTemplate template = GetSelectTemplate(); if (template == null) { return; } string templateName = string.Format("copy_{0}", template.TemplateName); StockTemplate temp = new StockTemplate { TemplateName = templateName, FutureCopies = template.FutureCopies, MarketCapOpt = template.MarketCapOpt, EReplaceType = template.EReplaceType, EWeightType = template.EWeightType, Benchmark = template.Benchmark, CreatedUserId = LoginManager.Instance.GetUserId(), EStatus = template.EStatus, DCreatedDate = DateTime.Now, CanEditUsers = template.CanEditUsers, CanViewUsers = template.CanViewUsers, Permissions = template.Permissions, }; int newTemplateId = _templateBLL.Copy(template.TemplateId, temp); if (newTemplateId > 0) { temp.TemplateId = newTemplateId; _tempDataSource.Add(temp); //如果需要切换到新的模板,可以在此处理 } else { MessageDialog.Fail(this, msgCopyFail); } this.tempGridView.Invalidate(); }
private void GiveOrder() { List <OrderConfirmItem> orderItemList = new List <OrderConfirmItem>(); var selectedItems = _monitorDataSource.Where(p => p.Selection).ToList(); if (selectedItems.Count == 1) { var openItem = selectedItems[0]; var orderItem = GetSubmitItem(openItem); if (orderItem == null) { string format = ConfigManager.Instance.GetLabelConfig().GetLabelText(msgSubmitFail); string msg = string.Format(format, openItem.MonitorName); MessageDialog.Fail(this, msg); return; } else { orderItemList.Add(orderItem); } } else if (selectedItems.Count > 1) { DateTime startDate = DateUtil.OpenDate; DateTime endDate = DateUtil.CloseDate; var orderItems = new List <OrderConfirmItem>(); foreach (var openItem in selectedItems) { OrderConfirmItem orderItem = new OrderConfirmItem { MonitorId = openItem.MonitorId, MonitorName = openItem.MonitorName, PortfolioId = openItem.PortfolioId, PortfolioName = openItem.PortfolioName, PortfolioCode = openItem.PortfolioCode, TemplateId = openItem.TemplateId, TemplateName = openItem.TemplateName, InstanceCode = string.Format("{0}-{1}-{2}", openItem.PortfolioId, openItem.TemplateId, DateFormat.Format(DateTime.Now, ConstVariable.DateFormat1)), Copies = openItem.Copies, FuturesList = new List <string>() { openItem.FuturesContract }, StartDate = DateUtil.GetIntDate(startDate), EndDate = DateUtil.GetIntDate(endDate), StartTime = DateUtil.GetIntTime(startDate), EndTime = DateUtil.GetIntTime(endDate), }; orderItems.Add(orderItem); } OpenMultiPositionDialog dialog = new OpenMultiPositionDialog(_gridConfig); dialog.Owner = this; dialog.StartPosition = FormStartPosition.CenterParent; dialog.OnLoadControl(dialog, null); dialog.OnLoadData(dialog, orderItems); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { orderItemList = (List <OrderConfirmItem>)dialog.GetData(); dialog.Dispose(); } else { dialog.Dispose(); } } if (orderItemList.Count == 0) { return; } List <OrderConfirmItem> successItems = new List <OrderConfirmItem>(); List <OrderConfirmItem> failItems = new List <OrderConfirmItem>(); foreach (var orderItem in orderItemList) { var newOpenItem = GetOpenPositionItem(orderItem); var selectedSecuItems = _securityDataSource.Where(p => p.Selection && p.MonitorId == newOpenItem.MonitorId).ToList(); DateTime startDate = DateUtil.GetDateTimeFromInt(orderItem.StartDate, orderItem.StartTime); DateTime endDate = DateUtil.GetDateTimeFromInt(orderItem.EndDate, orderItem.EndTime); startDate = DateUtil.GetStartDate(startDate); endDate = DateUtil.GetEndDate(endDate, startDate); int ret = _tradeCommandBLL.SubmitOpenPosition(newOpenItem, selectedSecuItems, startDate, endDate); if (ret > 0) { successItems.Add(orderItem); } else { failItems.Add(orderItem); } } if (successItems.Count == orderItemList.Count) { MessageDialog.Info(this, msgCommandSuccess); } else if (failItems.Count == orderItemList.Count) { MessageDialog.Fail(this, msgCommandFail); } else { StringBuilder sbSuccess = new StringBuilder(); StringBuilder sbFail = new StringBuilder(); successItems.ForEach(p => sbSuccess.AppendFormat("{0}|", p.MonitorId)); failItems.ForEach(p => sbFail.AppendFormat("{0}|", p.MonitorId)); string format = ConfigManager.Instance.GetLabelConfig().GetLabelText(msgCommandSuccessFail); string msg = string.Format(format, sbSuccess.ToString().TrimEnd('|'), sbFail.ToString().TrimEnd('|')); MessageDialog.Warn(this, msg); } }
private void ToolStripButton_Click_Modify(object sender, System.EventArgs e) { var selectedItems = _dataSource.Where(p => p.Selection).ToList(); if (selectedItems.Count == 0) { MessageDialog.Warn(this, msgNoSelected); return; } if (selectedItems.Count > 1) { MessageDialog.Warn(this, msgCanEditOnlyOne); return; } var invalidItems = selectedItems.Where(p => p.ECommandStatus != Model.EnumType.CommandStatus.Effective && p.ECommandStatus != Model.EnumType.CommandStatus.Modified).ToList(); if (invalidItems.Count > 0) { MessageDialog.Warn(this, msgInvalidSelected); return; } var selectedItem = selectedItems.First(); ModifyCommandDialog dialog = new ModifyCommandDialog(_gridConfig); dialog.Owner = this; dialog.StartPosition = FormStartPosition.CenterParent; dialog.OnLoadControl(dialog, null); dialog.OnLoadData(dialog, selectedItem); var dialogResult = dialog.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { //object resData = dialog.GetData(); //if (resData != null && resData is List<ModifySecurityItem>) //{ // var secuItems = resData as List<ModifySecurityItem>; // //TODO: update the tradeinstance item // if (UpdateItem(selectedItem, secuItems) > 0) // { MessageDialog.Info(this, msgModifySuccess); // } // else // { // MessageDialog.Fail(this, msgModifyFailure); // } //} dialog.Dispose(); } else if (dialogResult == System.Windows.Forms.DialogResult.No) { //do nothing MessageDialog.Fail(this, msgModifyFailure); dialog.Dispose(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var log4net = ConfigurationManager.AppSettings["log4net"]; string logFilePath = Path.Combine(Application.StartupPath, log4net); //XmlConfigurator.Configure(); XmlConfigurator.Configure(new Uri(logFilePath)); logger.Info("Log4net initialize...: " + logFilePath); //XmlConfigurator.ConfigureAndWatch("log4net.config"); //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); //var setting = SettingManager.Instance.Get(); var settingConfig = ConfigManager.Instance.GetDefaultSettingConfig(); //var buttonConfig = ConfigManager.Instance.GetButtonConfig(); //TODO:每个交易日开始时初始化???? //清算交易实例 var tradeInstanceSecuBLL = new TradeInstanceSecurityBLL(); tradeInstanceSecuBLL.SettlePosition(); uint timeOut = (uint)settingConfig.DefaultSetting.Timeout; T2SDKWrap t2SDKWrap = new T2SDKWrap(timeOut); var conRet = t2SDKWrap.Connect(); if (conRet != Model.ConnectionCode.Success) { glExitApp = true; MessageDialog.Fail(null, "一般业务连接UFX失败!"); return; } T2Subscriber t2Subscriber = new T2Subscriber(timeOut); conRet = t2Subscriber.Connect(); if (conRet != Model.ConnectionCode.Success) { t2SDKWrap.Close(); glExitApp = true; MessageDialog.Fail(null, "主推业务连接UFX失败!"); return; } UFXBLLManager.Instance.Init(t2SDKWrap); UFXBLLManager.Instance.Subscriber = t2Subscriber; //TODO: subscribe the message after getting login information LoginController loginController = new LoginController(new LoginForm(), t2SDKWrap); Application.Run(loginController.LoginForm); if (_s_mainfrmController != null) { Application.Run(_s_mainfrmController.MainForm); } //realloc the connection and service loginController.Logout(); t2SDKWrap.Close(); t2Subscriber.Close(); glExitApp = true; }