Example #1
0
 /// <summary>
 /// 同步商品信息
 /// </summary>
 /// <param name="clone">同步数据源</param>
 public void Sync(ProductInformation clone)
 {
     AllowMaxPrice              = clone.AllowMaxPrice;
     AllowMaxTimeDeviation      = clone.AllowMaxTimeDeviation;
     AllowMinPrice              = clone.AllowMinPrice;
     CutDownPrice               = clone.CutDownPrice;
     DepositFormula             = clone.DepositFormula;
     LossProfitSpread           = clone.LossProfitSpread;
     OrderStorageFeeFormula     = clone.OrderStorageFeeFormula;
     PendingOrderSpread         = clone.PendingOrderSpread;
     PercentageOfDeposit        = clone.PercentageOfDeposit;
     PointValue                 = clone.PointValue;
     ProductCode                = clone.ProductCode;
     ProductName                = clone.ProductName;
     RawMaterialsCode           = clone.RawMaterialsCode;
     RecovertyStorageFeeFormula = clone.RecovertyStorageFeeFormula;
     RecoveryFeeFormula         = clone.RecoveryFeeFormula;
     Spread                = clone.Spread;
     SpreadBaseValue       = clone.SpreadBaseValue;
     SpreadDigit           = clone.SpreadDigit;
     State                 = clone.State;
     StockCode             = clone.StockCode;
     TransactionFeeFormula = clone.TransactionFeeFormula;
     WeightUnit            = clone.WeightUnit;
     StartTradeTime        = clone.StartTradeTime;
     EndTradeTime          = clone.EndTradeTime;
 }
 /// <summary>
 /// 将一个商品信息从列表中移除
 /// </summary>
 /// <param name="productInfo">要删除的商品信息</param>
 private void RemoveProductInfo(ProductInformation productInfo)
 {
     if (_dpObj.CheckAccess())
         ProductInfoes.Remove(productInfo);
     else
         _dpObj.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
             new ProductInfoDelegate(item => ProductInfoes.Remove(item)),
             productInfo);
 }
        /// <summary>
        /// 验证定单基本信息的有效性
        /// </summary>
        /// <param name="newInfo">定单基本信息</param>
        /// <param name="selectedProduct">选中下单的商品</param>
        /// <param name="operateClient">该市价单定单对应的某个用户</param>
        /// <returns>ValidationResult</returns>
        private ValidationResult OrderInfoBaseValidation(NewOrderInfoBase newInfo, ProductInformation selectedProduct, ClientAccount operateClient)
        {
            //定单价验证
            if (newInfo.RealTimePrice > selectedProduct.AllowMaxPrice)
                return new ValidationResult(false, "允许的最大交易价格为:" + selectedProduct.AllowMaxPrice);
            if (newInfo.RealTimePrice < selectedProduct.AllowMinPrice)
                return new ValidationResult(false, "允许的最小交易价格为:" + selectedProduct.AllowMinPrice);

            //定单数量的验证
            if (newInfo.Count > operateClient.TransactionSettings.MaxTrade)
                return new ValidationResult(false, "允许的最大交易手数为:" + operateClient.TransactionSettings.MaxTrade);
            if (newInfo.Count < operateClient.TransactionSettings.MinTrade)
                return new ValidationResult(false, "允许的最小交易手数为:" + operateClient.TransactionSettings.MinTrade);
            ValidationResult result = ValidationHelper.OrderCountValidation(newInfo.Count, operateClient.TransactionSettings.OrderUnit);
            if (!result.IsValid)
                return result;

            //止损和止盈价验证
            if (newInfo.StopLossPrice != 0)
            {
                if (newInfo.StopLossPrice < 0)
                    return new ValidationResult(false, "止损价不能小于0");

                //进行止损价的验证
                result = ValidationHelper.StopLossPriceValidation(newInfo.StopLossPrice, selectedProduct.RealTimePrice, (int)newInfo.OrderType, selectedProduct.SpreadBaseValue, selectedProduct.LossProfitSpread);
                if (!result.IsValid)
                    return result;
            }
            if (newInfo.StopProfitPrice != 0)
            {
                if (newInfo.StopProfitPrice < 0)
                    return new ValidationResult(false, "止盈价不能小于0");

                //进行止盈价的验证
                result = ValidationHelper.StopProfitPriceValidation(newInfo.StopProfitPrice, selectedProduct.RealTimePrice, (int)newInfo.OrderType, selectedProduct.SpreadBaseValue, selectedProduct.LossProfitSpread);
                if (!result.IsValid)
                    return result;
            }

            return new ValidationResult(true, null);
        }
        /// <summary>
        /// 验证限价单定单信息的有效性
        /// </summary>
        /// <param name="newInfo">新挂单的详细信息</param>
        /// <param name="selectedProduct">选中下单的商品</param>
        /// <param name="operateClient">该市价单定单对应的某个用户</param>
        /// <returns>验证结果</returns>
        private ValidationResult PendingOrderInfoValidation(NewPendingOrderInfo newInfo, ProductInformation selectedProduct, ClientAccount operateClient)
        {
            double priceDeviation = selectedProduct.PendingOrderSpread * selectedProduct.SpreadBaseValue;
            double minPriceCaps = newInfo.RealTimePrice - priceDeviation;//最小价格上限
            double maxPriceLows = newInfo.RealTimePrice + priceDeviation;//最大价格下限

            if (newInfo.PendingOrdersPrice > minPriceCaps && newInfo.PendingOrdersPrice < maxPriceLows)
            {
                string msg = string.Format("无效的订单价!\r\n订单价必须大于等于:{0}\t或\t小于等于:{1}", maxPriceLows, minPriceCaps);
                return new ValidationResult(false, msg);
            }

            return OrderInfoBaseValidation(newInfo, selectedProduct, operateClient);
        }
 /// <summary>
 /// 验证市价单定单信息的有效性
 /// </summary>
 /// <param name="newInfo">新定单的详细信息</param>
 /// <param name="selectedProduct">选中下单的商品</param>
 /// <param name="operateClient">该市价单定单对应的某个用户</param>
 /// <returns>验证结果</returns>
 private ValidationResult MarketOrderInfoValidation(NewMarketOrderInfo newInfo, ProductInformation selectedProduct, ClientAccount operateClient)
 {
     return OrderInfoBaseValidation(newInfo, selectedProduct, operateClient);
 }
        /// <summary>
        /// 手工报价
        /// </summary>
        /// <param name="productInfo"></param>
        public void ManualPrice(ProductInformation productInfo)
        {
            ManualPriceWindow window = new ManualPriceWindow()
            {
                Owner = Application.Current.MainWindow,
                DataContext = productInfo,

            };
            window.ManualPriceChangeEvent += new ManualPriceChangeEventHander(window_ManualPriceChangeEvent);
            window.ShowDialog();
            //if (window.ShowDialog() == true)
            //{
            //    if (productInfo != null)
            //    {
            //        double min =productInfo.RealTimePrice- productInfo.SpreadBaseValue * 20;
            //        double max = productInfo.RealTimePrice + productInfo.SpreadBaseValue * 20;
            //        if (window.ManualPrice < min || window.ManualPrice > max)
            //        {
            //            string info = string.Format("实时报价必须大于等于:{0}\t且\t小于等于:{1}",min,max);
            //            MessageBox.Show(info, "提示信息",MessageBoxButton.OK,MessageBoxImage.Error);
            //            return;
            //        }
            //        _businessService.ManualPrice(_loginID, productInfo.ProductCode, window.ManualPrice);
            //    }

            //}
        }
 /// <summary>
 /// 删除指定商品
 /// </summary>
 /// <param name="productInfo">要删除的商品</param>
 public void DeleteProductInfo(ProductInformation productInfo)
 {
     MessageBoxResult mbResult = MessageBox.Show("确定要删除该商品吗?", "删除确认", MessageBoxButton.YesNo, MessageBoxImage.Question);
     if (mbResult == MessageBoxResult.Yes)
     {
         ErrType err = _businessService.DeleteProductInfo(_loginID, productInfo.ProductCode);
         if (err == GeneralErr.Success)
             RemoveProductInfo(productInfo);
         else
             MessageBox.Show(err.ErrMsg, err.ErrTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
        /// <summary>
        /// 显示商品信息
        /// </summary>
        /// <param name="productInfo">选中的某个商品信息</param>
        public void ShowProductInfo(ProductInformation productInfo)
        {
            ProductInformation clone = (ProductInformation)productInfo.Clone();
            ProductInfoWindow wnd = new ProductInfoWindow
            {
                Owner = Application.Current.MainWindow,
                DataContext = clone,
                RawMaterialsCodeList = ProductInfoes.Select(p => p.RawMaterialsCode).Distinct().ToList(),
                IsNew = false
            };

            if (wnd.ShowDialog() == true)
            {
                ErrType err = _businessService.ModifyProductInfo(_loginID, clone);
                if (err == GeneralErr.Success)
                    productInfo.Sync(clone);
                else
                    MessageBox.Show(err.ErrMsg, err.ErrTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
        public void AddProductInfoExecute()
        {
            ProductInformation newProductInfo = new ProductInformation();
            ProductInfoWindow wnd = new ProductInfoWindow
            {
                Owner = Application.Current.MainWindow,
                DataContext = newProductInfo,
                RawMaterialsCodeList = ProductInfoes.Select(p => p.RawMaterialsCode).Distinct().ToList(),

                IsNew = true
            };

            if (wnd.ShowDialog() == true)
            {
                ErrType err = _businessService.AddProductInfo(_loginID, newProductInfo);
                if (err == GeneralErr.Success)
                    AddProductInfo(newProductInfo);
                else
                    MessageBox.Show(err.ErrMsg, err.ErrTitle, MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
 /// <summary>
 /// 用新市价单的详细参数信息和选中的某个商品实例化市价单消息参数实例
 /// </summary>
 /// <param name="newOrderInfo">新市价单的详细参数信息</param>
 /// <param name="selectedProduct">选中的某个商品</param>
 public MarketOrderEventArgs( NewMarketOrderInfo newOrderInfo, ProductInformation selectedProduct ) {
     NewOrderInfo = newOrderInfo;
     SelectedProduct = selectedProduct;
 }
 /// <summary>
 /// 同步商品信息
 /// </summary>
 /// <param name="clone">同步数据源</param>
 public void Sync( ProductInformation clone ) {
     AllowMaxPrice = clone.AllowMaxPrice;
     AllowMaxTimeDeviation = clone.AllowMaxTimeDeviation;
     AllowMinPrice = clone.AllowMinPrice;
     CutDownPrice = clone.CutDownPrice;
     DepositFormula = clone.DepositFormula;
     LossProfitSpread = clone.LossProfitSpread;
     OrderStorageFeeFormula = clone.OrderStorageFeeFormula;
     PendingOrderSpread = clone.PendingOrderSpread;
     PercentageOfDeposit = clone.PercentageOfDeposit;
     PointValue = clone.PointValue;
     ProductCode = clone.ProductCode;
     ProductName = clone.ProductName;
     RawMaterialsCode = clone.RawMaterialsCode;
     RecovertyStorageFeeFormula = clone.RecovertyStorageFeeFormula;
     RecoveryFeeFormula = clone.RecoveryFeeFormula;
     Spread = clone.Spread;
     SpreadBaseValue = clone.SpreadBaseValue;
     SpreadDigit = clone.SpreadDigit;
     State = clone.State;
     StockCode = clone.StockCode;
     TransactionFeeFormula = clone.TransactionFeeFormula;
     WeightUnit = clone.WeightUnit;
     StartTradeTime = clone.StartTradeTime;
     EndTradeTime = clone.EndTradeTime;
 }
 /// <summary>
 /// 修改指定的商品信息
 /// </summary>
 /// <param name="loginID">登陆标识</param>
 /// <param name="productInfo">新的商品信息</param>
 /// <returns>ErrType</returns>
 public ErrType ModifyProductInfo(string loginID, ProductInformation productInfo)
 {
     try
     {
         TradeProduct product = MyConverter.ToTradeProduct(productInfo);
         ResultDesc result = ManagerService.ModifyTradeProduct(product, loginID);
         return result.Result ? GeneralErr.Success : new ErrType(ERR.SERVICE, result.Desc);
     }
     catch (TimeoutException te)
     {
         FileLog.WriteLog("", Assembly.GetExecutingAssembly().GetName().Name, this.GetType().Name, new StackTrace().GetFrame(0).GetMethod().Name, te.Message);
         return new ErrType(ERR.EXEPTION, ErrorText.TimeoutException);
     }
     catch (Exception ex)
     {
         FileLog.WriteLog("", Assembly.GetExecutingAssembly().GetName().Name, this.GetType().Name,
       new StackTrace().GetFrame(0).GetMethod().Name, ex.Message);
         return new ErrType(ERR.EXEPTION, ErrorText.OperationError);
     }
 }
 internal static TradeProduct ToTradeProduct(ProductInformation info)
 {
     return new TradeProduct
     {
         Maxprice = info.AllowMaxPrice,
         Maxtime = info.AllowMaxTimeDeviation,
         Minprice = info.AllowMinPrice,
         Lowerprice = info.CutDownPrice,
         Ordemoneyfee = info.DepositFormula,
         SetBase = info.LossProfitSpread,
         Buystoragefee = info.OrderStorageFeeFormula,
         Holdbase = info.PendingOrderSpread,
         Ordemoney = info.PercentageOfDeposit,
         Valuedot = info.PointValue,
         Productcode = info.ProductCode,
         ProductName = info.ProductName,
         Sellstoragefee = info.RecovertyStorageFeeFormula,
         Sellfee = info.RecoveryFeeFormula,
         Pricedot = info.Spread,
         Adjustbase = info.SpreadBaseValue,
         Adjustcount = info.SpreadDigit,
         State = ((int)info.State).ToString(),
         Pricecode = info.StockCode,
         Goodscode = info.RawMaterialsCode,
         Expressionfee = info.TransactionFeeFormula,
         Unit = info.WeightUnit,
         //Starttime = info.StartTradeTime,
         //Endtime = info.EndTradeTime,
         Starttime = "00:00:00",
         Endtime = "23:59:59",
     };
 }
        internal static ProductInformation ToProductInfo(TradeProduct product)
        {
            ProductInformation info = new ProductInformation();

            info.AllowMaxPrice = product.Maxprice;
            info.AllowMaxTimeDeviation = product.Maxtime;
            info.AllowMinPrice = product.Minprice;
            info.CutDownPrice = product.Lowerprice;
            info.DepositFormula = product.Ordemoneyfee;
            info.LossProfitSpread = product.SetBase;
            info.OrderStorageFeeFormula = product.Buystoragefee;
            info.PendingOrderSpread = product.Holdbase;
            info.PercentageOfDeposit = product.Ordemoney;
            info.PointValue = product.Valuedot;
            info.ProductCode = product.Productcode;
            info.ProductName = product.ProductName;
            info.RecovertyStorageFeeFormula = product.Sellstoragefee;
            info.RecoveryFeeFormula = product.Sellfee;
            info.Spread = product.Pricedot;
            info.SpreadBaseValue = product.Adjustbase;
            info.SpreadDigit = product.Adjustcount;
            info.State = (PRODUCT_STATE)Enum.Parse(typeof(PRODUCT_STATE), product.State);
            info.StockCode = product.Pricecode;
            info.RawMaterialsCode = product.Goodscode;
            info.TransactionFeeFormula = product.Expressionfee;
            info.WeightUnit = product.Unit;
            info.StartTradeTime = product.Starttime;
            info.EndTradeTime = product.Endtime;
            info.RealTimePrice = product.realprice;
            info.RealTimeTime = DateTimeHelper.GetDateTimeFromTimeKey(product.weektime);
            return info;

        }
 /// <summary>
 /// 用新的限价挂单的详细参数信息和选中的某个商品实例化限价单消息参数实例
 /// </summary>
 /// <param name="info">新限价挂单的详细参数信息</param>
 /// <param name="selectedProduct">选中的某个商品</param>
 public PendingOrderEventArgs( NewPendingOrderInfo info, ProductInformation selectedProduct ) {
     NewOrderInfo = info;
     SelectedProduct = selectedProduct;
 }
 private void acc_Loaded(object sender, RoutedEventArgs e)
 {
     productInformation = this.DataContext as ProductInformation;
     this.Title = productInformation.ProductName + "报价";
 }