public OrderConfirmItem GetSubmitItem(OpenPositionItem openItem)
        {
            string instanceCode = string.Format("{0}-{1}-{2}", openItem.PortfolioId, openItem.TemplateId, DateFormat.Format(DateTime.Now, ConstVariable.DateFormat1));

            openItem.InstanceCode = instanceCode;

            OrderConfirmItem orderItem = null;
            //Open the dialog
            OpenPositionDialog dialog = new OpenPositionDialog();

            dialog.Owner         = this;
            dialog.StartPosition = FormStartPosition.CenterParent;
            dialog.OnLoadControl(dialog, null);
            dialog.OnLoadData(dialog, openItem);
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                orderItem = (OrderConfirmItem)dialog.GetData();
                dialog.Dispose();
            }
            else
            {
                dialog.Dispose();
            }

            return(orderItem);
        }
Пример #2
0
        public bool ValidateInstanceCode(OrderConfirmItem item)
        {
            if (!string.IsNullOrEmpty(item.InstanceCode))
            {
                return(true);
            }

            return(false);
        }
        private OpenPositionItem GetOpenPositionItem(OrderConfirmItem orderItem)
        {
            var newOpenItem = new OpenPositionItem
            {
                MonitorId       = orderItem.MonitorId,
                MonitorName     = orderItem.MonitorName,
                PortfolioId     = orderItem.PortfolioId,
                PortfolioName   = orderItem.PortfolioName,
                TemplateId      = orderItem.TemplateId,
                TemplateName    = orderItem.TemplateName,
                Copies          = orderItem.Copies,
                FuturesContract = orderItem.FuturesContract,
                InstanceCode    = orderItem.InstanceCode,
                Notes           = orderItem.Notes ?? string.Empty,
            };

            return(newOpenItem);
        }
        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);
            }
        }
Пример #5
0
        private OrderConfirmItem GetNewItem()
        {
            var newOpenItem = new OrderConfirmItem
            {
                MonitorId     = _originOpenItem.MonitorId,
                MonitorName   = _originOpenItem.MonitorName,
                PortfolioId   = _originOpenItem.PortfolioId,
                PortfolioName = _originOpenItem.PortfolioName,
                TemplateId    = _originOpenItem.TemplateId,
                TemplateName  = _originOpenItem.TemplateName,
                Copies        = _originOpenItem.Copies,
                FuturesList   = new List <string>()
                {
                    _originOpenItem.FuturesContract
                },
                Notes = rtbComment.Text ?? string.Empty,
            };

            DateTime startDate = DateTime.MinValue;
            DateTime endDate   = DateTime.MinValue;
            DateTime startTime = DateTime.MinValue;
            DateTime endTime   = DateTime.MinValue;

            DateTime dt;

            if (DateUtil.IsValidDate(this.tbStartDate.Text.Trim(), ConstVariable.DateFormat1, out dt))
            {
                startDate = dt;
            }

            if (DateUtil.IsValidDate(this.tbEndDate.Text.Trim(), ConstVariable.DateFormat1, out dt))
            {
                endDate = dt;
            }

            if (DateUtil.IsValidDate(this.tbStartTime.Text.Trim(), ConstVariable.TimeFormat1, out dt))
            {
                startTime = dt;
            }

            if (DateUtil.IsValidDate(this.tbEndTime.Text.Trim(), ConstVariable.TimeFormat1, out dt))
            {
                endTime = dt;
            }

            newOpenItem.StartDate = Convert.ToInt32(this.tbStartDate.Text.Trim());
            newOpenItem.EndDate   = Convert.ToInt32(this.tbEndDate.Text.Trim());
            newOpenItem.StartTime = Convert.ToInt32(this.tbStartTime.Text.Trim());
            newOpenItem.EndTime   = Convert.ToInt32(this.tbEndTime.Text.Trim());

            if (this.ckbInstanceCode.Checked)
            {
                var selectItem = (ComboOptionItem)this.cbInstanceCode.SelectedItem;
                if (selectItem != null)
                {
                    newOpenItem.InstanceCode = selectItem.Name;
                }
                else if (!string.IsNullOrEmpty(this.cbInstanceCode.Text))
                {
                    newOpenItem.InstanceCode = this.cbInstanceCode.Text.Trim();
                }
                else
                {
                    //do nothing
                }
            }
            else
            {
                newOpenItem.InstanceCode = _originOpenItem.InstanceCode;
            }

            return(newOpenItem);
        }