Beispiel #1
0
        public void MakeOrder(string symbol, string account, decimal price, int lots, bool dayTrade)
        {
            //大台 TXF 小台 MXF
            string productId = ClearOrders(symbol, account);

            if (String.IsNullOrEmpty(productId))
            {
                return;
            }


            _orderActionType = OrderActionType.Create;

            string bs       = lots > 0 ? "B" : "S";
            string strPrice = price > 0 ? Convert.ToInt32(price).ToString() : "0";
            string qty      = Math.Abs(lots).ToString();
            string otype    = price > 0 ? "L" : "P";           //L:限價, M:市價, P:一定範圍市價


            string fir   = price > 0 ? "R" : "I";            //R:ROD, F:FOK, I:IOC
            string rtype = dayTrade ? "2" : "";              // "0":新倉, "1":平倉, "2":期貨當沖, "":自動


            _API.NewOrder(account, productId, bs, strPrice, qty, otype, fir, rtype);

            OnActionExecuted($"MakeOrder: {bs} {qty} {productId} , price: {strPrice} ");
        }
Beispiel #2
0
        public void ProcessOrderTest(string orderdate, OrderActionType orderactionype, bool expectedSuccess, string expectedmessage)
        {
            OrderManager manager = OrderManagerFactory.Create();
            Order        order   = new Order
            {
                OrderNumber            = 1,
                CustomerName           = "Wise Edit",
                State                  = "OH",
                TaxRate                = 6.25M,
                ProductType            = "Wood",
                Area                   = 100.00M,
                CostPerSquareFoot      = 5.15M,
                LaborCostPerSquareFoot = 4.75M,
                MaterialCost           = 515.00M,
                LaborCost              = 475.00M,
                Tax   = 61.875M,
                Total = 1051.875M
            };
            ProcessOrderResponse processorderresponse = manager.ProcessOrder(order, orderdate, orderactionype);

            Assert.AreEqual(expectedSuccess, processorderresponse.Success);
            if (processorderresponse.Success == true)
            {
                Assert.AreEqual(order, processorderresponse.order);
            }
            else
            {
                Assert.AreEqual(expectedmessage, processorderresponse.Message);
            }
        }
 internal static OrderAction CreateOrderAction(OrderActionType action)
 {
     return(new OrderAction
     {
         Action = action,
         ActionTime = DateTime.Now,
         CreateTime = DateTime.Now,
     });
 }
Beispiel #4
0
 /// <summary>
 /// 创建订单行为
 /// </summary>
 private void CreateOrderAction(int oid, OrderActionType orderActionType, string actionDes)
 {
     OrderActions.CreateOrderAction(new OrderActionInfo()
     {
         Oid        = oid,
         Uid        = WorkContext.Uid,
         RealName   = AdminUsers.GetUserDetailById(WorkContext.Uid).RealName,
         ActionType = (int)orderActionType,
         ActionTime = DateTime.Now,
         ActionDes  = actionDes
     });
 }
        public static TimeSpan?GetTimeSpan(OrderActionType actionType)
        {
            TimeSpan?timeSpane = null;

            switch (actionType)
            {
            case OrderActionType.订购:
                timeSpane = TimeSpan.FromDays(1);
                break;
            }
            return(timeSpane);
        }
Beispiel #6
0
        public string ClearOrders(string symbol, string account)
        {
            //大台 TXF 小台 MXF
            string productId = GetProductId(symbol);

            int wb = _API.GetWB(account, productId);              //買進未成交口數
            int ws = _API.GetWS(account, productId);              //賣出未成交口數

            if (wb == 0 && ws == 0)
            {
                return(productId);
            }

            _orderActionType = OrderActionType.Delete;
            QueryOrders(account);
            return(String.Empty);
        }
Beispiel #7
0
        /// <summary>
        ///     Adds the specified order.
        ///     添加订单操作记录
        /// </summary>
        /// <param name="order">The order.</param>
        /// <param name="user">The user.操作用户</param>
        /// <param name="actionType">Type of the action.</param>
        public void Add(Order order, User user, OrderActionType actionType)
        {
            var orderAction = new OrderAction
            {
                OrderId         = order.Id,
                OrderActionType = actionType,
                ActionUserId    = user.Id
            };
            var allActionIntro  = GetAllActionIntro();
            var actionTypeIntro = allActionIntro.FirstOrDefault(r => r.Key == actionType).Value;

            orderAction.Intro = actionTypeIntro.Replace("{OrderUserName}", user.GetUserName())
                                .Replace("{AdminUserName}", user.GetUserName())
                                .Replace("{OrderAmount}", order.TotalAmount.ToString())
                                .Replace("{SellerUserName}", user.GetUserName())
                                .Replace("{ExpressAmount}", order.OrderExtension.OrderAmount.ExpressAmount.ToString());
            Add(orderAction);
        }
Beispiel #8
0

        
Beispiel #9
0
        public static string EnterState(string prompt, List <Tax> taxlist, OrderActionType orderactiontype)
        {
            string stateabbr = "";

            while (true)
            {
                Console.Write(prompt);
                stateabbr = Console.ReadLine();
                if (OrderActionType.Edit == orderactiontype && stateabbr == "")
                {
                    break;
                }
                bool exists = taxlist.Exists(tax => tax.StateAbbreviation == stateabbr);
                if (exists)
                {
                    break;
                }
                Console.WriteLine("ProductType is not sold in that State. Please enter another state or contact IT!");
            }
            return(stateabbr);
        }
Beispiel #10
0
        public static string EnterCustomerName(string prompt, OrderActionType orderactiontype)
        {
            string customername = "";
            string validchar    = "^[a-zA-Z0-9.,]+$";

            while (true)
            {
                Console.Write(prompt);
                customername = Console.ReadLine();
                if (OrderActionType.Edit == orderactiontype && customername == "")
                {
                    break;
                }
                bool IsAlphaNumericwithPeriodComma = Regex.IsMatch(customername, validchar);
                if (IsAlphaNumericwithPeriodComma)
                {
                    break;
                }
                Console.WriteLine("Invalid Customer Name Entered. Name should contain contain only the following [a-z][0-9],period,and comma.");
            }
            return(customername);
        }
Beispiel #11
0
        public static decimal EnterArea(string prompt, OrderActionType orderactiontype)
        {
            decimal area = 0.00M;

            while (true)
            {
                Console.Write(prompt);
                string areastr = Console.ReadLine();
                if (OrderActionType.Edit == orderactiontype && areastr == "")
                {
                    break;
                }
                if (decimal.TryParse(areastr, out area))
                {
                    if (area >= 100.00M)
                    {
                        break;
                    }
                }
                Console.WriteLine("Incorrect Area entered!");
            }
            return(area);
        }
Beispiel #12
0
        public static string EnterProductType(string prompt, List <Product> productlist, OrderActionType orderactiontype)
        {
            Console.WriteLine(productline, "Product Type", "CostPerSquareFoot", "LaborCostPerSquareFoot");
            Console.WriteLine("=====================================================");
            foreach (Product product in productlist)
            {
                DisplayProductDetails(product);
            }
            string producttype = "";

            while (true)
            {
                Console.Write(prompt);
                producttype = Console.ReadLine();
                if (OrderActionType.Edit == orderactiontype && producttype == "")
                {
                    break;
                }
                bool exists = productlist.Exists(product => product.ProductType == producttype);
                if (exists)
                {
                    break;
                }
                Console.WriteLine("Invalid ProductType Entered!");
            }
            return(producttype);
        }
Beispiel #13
0
        public ActionResult OperateOrder(int oid = -1, int actionType = -1, string actionDes = "")
        {
            OrderInfo orderInfo = AdminOrders.GetOrderByOid(oid);

            if (orderInfo == null)
            {
                return(PromptView("订单不存在"));
            }

            if (actionDes.Length > 125)
            {
                OperateOrderModel model = new OperateOrderModel();
                model.Oid             = oid;
                model.OrderInfo       = orderInfo;
                model.OrderActionType = (OrderActionType)actionType;
                model.ActionDes       = actionDes;

                ModelState.AddModelError("actionDes", "最多只能输入125个字");
                return(View(model));
            }

            OrderActionType orderActionType = (OrderActionType)actionType;
            OrderState      orderState      = (OrderState)orderInfo.OrderState;

            if (orderActionType == OrderActionType.Confirm)//确认订单
            {
                if (orderState != OrderState.Confirming)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "买家还未付款,不能确认订单"));
                }

                AdminOrders.ConfirmOrder(orderInfo);
                CreateOrderAction(oid, orderActionType, actionDes.Length == 0 ? "您的订单已经确认" : actionDes);
            }
            else if (orderActionType == OrderActionType.PreProduct)//备货
            {
                if (orderState != OrderState.Confirmed)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单还未确认,不能备货"));
                }

                AdminOrders.PreProduct(orderInfo);
                CreateOrderAction(oid, orderActionType, actionDes.Length == 0 ? "您的订单正在备货" : actionDes);
            }
            else if (orderActionType == OrderActionType.Send)//发货
            {
                if (orderState != OrderState.PreProducting)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单还未备货,不能发货"));
                }

                string shipSN = WebHelper.GetFormString("shipSN").Trim();
                if (shipSN.Length < 1)
                {
                    OperateOrderModel model = new OperateOrderModel();
                    model.Oid             = oid;
                    model.OrderInfo       = orderInfo;
                    model.OrderActionType = orderActionType;
                    model.ActionDes       = actionDes;

                    ModelState.AddModelError("shipSN", "请填写配送单号");
                    return(View(model));
                }
                AdminOrders.SendOrder(oid, OrderState.Sended, shipSN, DateTime.Now);
                CreateOrderAction(oid, orderActionType, actionDes.Length == 0 ? "您的订单已经发货,发货方式为:" + orderInfo.ShipFriendName + ",单号为:" + shipSN : actionDes);
            }
            else if (orderActionType == OrderActionType.Lock)//锁定订单
            {
                if (!(orderState == OrderState.WaitPaying || (orderState == OrderState.Confirming && orderInfo.PayMode == 0)))
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单当前不能锁定"));
                }

                AdminOrders.LockOrder(orderInfo);
                CreateOrderAction(oid, orderActionType, "订单已锁定:" + actionDes);
            }
            else if (orderActionType == OrderActionType.Cancel)//取消订单
            {
                if (!(orderState == OrderState.WaitPaying || (orderState == OrderState.Confirming && orderInfo.PayMode == 0)))
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单当前不能取消"));
                }

                PartUserInfo partUserInfo = Users.GetPartUserById(orderInfo.Uid);
                AdminOrders.CancelOrder(ref partUserInfo, orderInfo, WorkContext.Uid, DateTime.Now);
                CreateOrderAction(oid, orderActionType, actionDes.Length == 0 ? "订单已取消" : actionDes);
            }
            else
            {
                return(PromptView(Url.Action("orderinfo", new { oid = oid }), "当前操作不存在"));
            }

            AddAdminOperateLog("操作订单", "操作订单,订单ID为:" + oid);
            return(PromptView(Url.Action("orderinfo", new { oid = oid }), "操作已完成"));
        }
Beispiel #14
0
        public ActionResult OperateOrder(int oid = -1, int actionType = -1)
        {
            OrderInfo orderInfo = AdminOrders.GetOrderByOid(oid);

            if (orderInfo == null)
            {
                return(PromptView("订单不存在"));
            }

            OrderActionType orderActionType = (OrderActionType)actionType;
            OrderState      orderState      = (OrderState)orderInfo.OrderState;

            if (orderActionType == OrderActionType.Confirm)//确认订单
            {
                if (orderState != OrderState.Confirming)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "买家还未付款,不能确认订单"));
                }
            }
            else if (orderActionType == OrderActionType.PreProduct)//备货
            {
                if (orderState != OrderState.Confirmed)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单还未确认,不能备货"));
                }
            }
            else if (orderActionType == OrderActionType.Send)//发货
            {
                if (orderState != OrderState.PreProducting)
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单还未备货,不能发货"));
                }
            }
            else if (orderActionType == OrderActionType.Lock)//锁定订单
            {
                if (!(orderState == OrderState.WaitPaying || (orderState == OrderState.Confirming && orderInfo.PayMode == 0)))
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单当前不能锁定"));
                }
            }
            else if (orderActionType == OrderActionType.Cancel)//取消订单
            {
                if (!(orderState == OrderState.WaitPaying || (orderState == OrderState.Confirming && orderInfo.PayMode == 0)))
                {
                    return(PromptView(Url.Action("orderinfo", new { oid = oid }), "订单当前不能取消"));
                }
            }
            else
            {
                return(PromptView(Url.Action("orderinfo", new { oid = oid }), "当前操作不存在"));
            }

            OperateOrderModel model = new OperateOrderModel();

            model.Oid             = oid;
            model.OrderInfo       = orderInfo;
            model.OrderActionType = orderActionType;
            model.ActionDes       = "";

            return(View(model));
        }
Beispiel #15
0
 private void CreateOrderAction(int oid, OrderActionType orderActionType, string actionDes)
 {
     OrderActions.CreateOrderAction(new OrderActionInfo()
     {
         Oid = oid,
         Uid = WorkContext.Uid,
         RealName = AdminUsers.GetUserDetailById(WorkContext.Uid).RealName,
         ActionType = (int)orderActionType,
         ActionTime = DateTime.Now,
         ActionDes = actionDes
     });
 }
        public ProcessOrderResponse ProcessOrder(Order order, string orderdate, OrderActionType orderactiontype)
        {
            if (orderactiontype == OrderActionType.Add || orderactiontype == OrderActionType.Edit)
            {
                if (order.CustomerName.Contains(","))
                {
                    order.CustomerName = order.CustomerName.Replace(",", "|");
                }
            }
            ProcessOrderResponse  processorderresponse = new ProcessOrderResponse();
            OrderDateFileResponse orderdatefile        = _orderRepository.GetPath(orderdate);

            if (string.IsNullOrEmpty(orderdatefile.path))
            {
                processorderresponse.Success = false;
                processorderresponse.Message = $"File not found for Order date {orderdate} or some problem. Please contact IT.";
            }
            else
            {
                switch (orderactiontype)
                {
                case OrderActionType.Add:
                    processorderresponse.order = _orderRepository.AddOrderToExistingOrderDateFile(order, orderdatefile.path);
                    break;

                case OrderActionType.Edit:
                    processorderresponse.order = _orderRepository.EditOrder(order, orderdatefile.path);
                    break;

                case OrderActionType.Remove:
                    processorderresponse.order = _orderRepository.RemoveOrder(order, orderdatefile.path);
                    break;

                default:
                    throw new Exception("Order Action Type is not supported!");
                }
                if (processorderresponse.order == null)
                {
                    processorderresponse.Success = false;
                    processorderresponse.Message = "New order save (to existing order date file) unsuccessful.";
                }
                else
                {
                    processorderresponse.Success = true;
                }
            }

            if (orderactiontype == OrderActionType.Add && string.IsNullOrEmpty(orderdatefile.path))
            {
                OrderDateFileResponse neworderdatefile = _orderRepository.BuildPath(orderdate);
                if (string.IsNullOrEmpty(neworderdatefile.path))
                {
                    processorderresponse.Success = false;
                    processorderresponse.Message = $"Problem creating a new order date file for Order date {orderdate}. Please contact IT.";
                }
                else
                {
                    processorderresponse.order = _orderRepository.AddOrderToNewOrderDateFile(order, neworderdatefile.path);
                    if (processorderresponse.order == null)
                    {
                        processorderresponse.Success = false;
                        processorderresponse.Message = "New order save (to new order date file) unsuccessful.";
                    }
                    else
                    {
                        processorderresponse.Success = true;
                    }
                }
            }
            return(processorderresponse);
        }