Exemplo n.º 1
0
        public virtual bool AddProductPrice(ProductPriceInfo entity)
        {
            string    SqlAdd = null;
            DataTable DtAdd  = null;
            DataRow   DrAdd  = null;

            SqlAdd = "SELECT TOP 0 * FROM Product_Price";
            DtAdd  = DBHelper.Query(SqlAdd);
            DrAdd  = DtAdd.NewRow();

            DrAdd["Product_Price_ID"]            = entity.Product_Price_ID;
            DrAdd["Product_Price_ProcutID"]      = entity.Product_Price_ProcutID;
            DrAdd["Product_Price_MemberGradeID"] = entity.Product_Price_MemberGradeID;
            DrAdd["Product_Price_Price"]         = entity.Product_Price_Price;

            DtAdd.Rows.Add(DrAdd);
            try
            {
                DBHelper.SaveChanges(SqlAdd, DtAdd);
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DtAdd.Dispose();
            }
        }
Exemplo n.º 2
0
        public void UpdateProductPrice(int productSysNo, ProductPriceInfo productPriceInfo)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("UpdateProductPrice");

            cmd.SetParameterValue("@ProductSysNo", productSysNo);
            cmd.SetParameterValue("@BasicPrice", productPriceInfo.BasicPrice);
            cmd.SetParameterValue("@CurrentPrice", productPriceInfo.CurrentPrice);
            cmd.SetParameterValue("@CashRebate", productPriceInfo.CashRebate);
            cmd.SetParameterValue("@Point", productPriceInfo.Point);
            cmd.SetParameterValue("@IsWholeSale", productPriceInfo.ProductWholeSalePriceInfo.Any(p => p.Qty != null) ? 1 : 0);
            cmd.SetParameterValue("@Discount", productPriceInfo.BasicPrice == 0?0:(productPriceInfo.CurrentPrice / productPriceInfo.BasicPrice).Round(2));
            cmd.SetParameterValue("@IsExistRankPrice", productPriceInfo.ProductRankPrice.Any(rankPrice => rankPrice.Status == ProductRankPriceStatus.Active) ? 1 : 0);
            cmd.SetParameterValue("@MinCommission", productPriceInfo.MinCommission);
            for (int i = 0; i < Enum.GetValues(typeof(WholeSaleLevelType)).Cast <WholeSaleLevelType>().Count(); i++)
            {
                if (productPriceInfo.ProductWholeSalePriceInfo.Count > i)
                {
                    cmd.SetParameterValue("@Q" + (i + 1), productPriceInfo.ProductWholeSalePriceInfo[i].Qty);
                    cmd.SetParameterValue("@P" + (i + 1), productPriceInfo.ProductWholeSalePriceInfo[i].Price);
                }
                else
                {
                    cmd.SetParameterValue("@Q" + (i + 1), null);
                    cmd.SetParameterValue("@P" + (i + 1), null);
                }
            }

            cmd.ExecuteNonQuery();
            DeleteProductRankPrice(productSysNo);
            InsertProductRankPrice(productSysNo, productPriceInfo);
            UpdateProductVipPrice(productSysNo, productPriceInfo);
        }
Exemplo n.º 3
0
        public void GetCartBriefInfo(Hashtable ht, ref int cartProductCount, ref decimal cartMoneyTotal)
        {
            DataSet ds = OnlineListManager.GetInstance().GetCartDs(ht);

            if (!Util.HasMoreRow(ds))
            {
                return;
            }

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ProductPriceInfo oProductPrice = new ProductPriceInfo();

                oProductPrice.ProductSysNo = Util.TrimIntNull(dr["ProductSysNo"]);
                oProductPrice.CurrentPrice = Util.TrimDecimalNull(dr["CurrentPrice"]);
                oProductPrice.PointType    = Util.TrimIntNull(dr["PointType"]);
                oProductPrice.IsWholeSale  = Util.TrimIntNull(dr["IsWholeSale"]);
                oProductPrice.Q1           = Util.TrimIntNull(dr["Q1"]);
                oProductPrice.P1           = Util.TrimDecimalNull(dr["P1"]);
                oProductPrice.Q2           = Util.TrimIntNull(dr["Q2"]);
                oProductPrice.P2           = Util.TrimDecimalNull(dr["P2"]);
                oProductPrice.Q3           = Util.TrimIntNull(dr["Q3"]);
                oProductPrice.P3           = Util.TrimDecimalNull(dr["P3"]);

                CartInfo oCart = ht[oProductPrice.ProductSysNo] as CartInfo;

                cartProductCount += oCart.Quantity;
                cartMoneyTotal   += oCart.Quantity * oProductPrice.GetRealPrice(oCart.Quantity);
            }
        }
Exemplo n.º 4
0
        public void SetFinish(int sysno)
        {
            //必须是Running
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                CountdownInfo oCountdown = Load(sysno);

                if (oCountdown.Status != (int)AppEnum.CountdownStatus.Running)
                {
                    throw new BizException("the current status not allow such opertion");
                }

                oCountdown.Status = (int)AppEnum.CountdownStatus.Finish;

                ProductPriceInfo oPrice = ProductManager.GetInstance().LoadPrice(oCountdown.ProductSysNo);

                oPrice.CurrentPrice = oCountdown.SnapShotCurrentPrice;
                oPrice.CashRebate   = oCountdown.SnapShotCashRebate;
                oPrice.Point        = oCountdown.SnapShotPoint;

                InventoryManager.GetInstance().SetVirtualQty(oCountdown.ProductSysNo, oCountdown.AffectedVirtualQty);
                ProductManager.GetInstance().UpdatePriceInfo(oPrice);
                new CountdownDac().Update(oCountdown);

                scope.Complete();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 在修改库存以前完成,否则当前库存数就不对了。
        /// </summary>
        /// <param name="productSysNo">商品编号</param>
        /// <param name="hereQty">本次数量</param>
        /// <param name="hereCost">本次成本</param>
        public void SetCost(int productSysNo, int hereQty, decimal hereCost)
        {
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //获取该商品的当前成本
                InventoryManager.GetInstance().InitInventory(productSysNo);
                InventoryInfo    oInv   = InventoryManager.GetInstance().LoadInventory(productSysNo);
                ProductPriceInfo oPrice = ProductManager.GetInstance().LoadPrice(productSysNo);

                int     curQty  = oInv.AccountQty;
                decimal curCost = oPrice.UnitCost;

                //如果当前成本等于本次成本不用更新了
                if (curCost == hereCost)
                {
                    scope.Complete();
                    return;
                }

                decimal newCost = AppConst.DecimalNull;

                //如果数量为零或者计算出来的成本为负,用本次成本更新
                if (curQty + hereQty == 0)
                {
                    newCost = hereCost;
                }
                else
                {
                    newCost = Decimal.Round((curQty * curCost + hereQty * hereCost) / (curQty + hereQty) * 1.0M, 2);
                    if (newCost < 0)
                    {
                        newCost = hereCost;
                    }
                }

                //如果计算出来相等也不用更新
                if (newCost == curCost)
                {
                    scope.Complete();
                    return;
                }

                if (newCost == AppConst.DecimalNull)
                {
                    throw new BizException("calc cost error");
                }

                //更新成本到数据库
                if (1 != new ProductPriceDac().UpdateCost(productSysNo, newCost))
                {
                    throw new BizException("expected one-row update failed, cancel verify failed ");
                }
                scope.Complete();
            }
        }
Exemplo n.º 6
0
        public virtual bool EditProductPrice(ProductPriceInfo entity)
        {
            string    SqlAdd = null;
            DataTable DtAdd  = null;
            DataRow   DrAdd  = null;

            SqlAdd = "SELECT * FROM Product_Price WHERE Product_Price_ID = " + entity.Product_Price_ID;
            DtAdd  = DBHelper.Query(SqlAdd);
            try
            {
                if (DtAdd.Rows.Count > 0)
                {
                    DrAdd = DtAdd.Rows[0];
                    DrAdd["Product_Price_ID"]            = entity.Product_Price_ID;
                    DrAdd["Product_Price_ProcutID"]      = entity.Product_Price_ProcutID;
                    DrAdd["Product_Price_MemberGradeID"] = entity.Product_Price_MemberGradeID;
                    DrAdd["Product_Price_Price"]         = entity.Product_Price_Price;

                    DBHelper.SaveChanges(SqlAdd, DtAdd);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                DtAdd.Dispose();
            }
            return(true);
        }
Exemplo n.º 7
0
        public virtual ProductPriceInfo GetProductPriceByID(int ID)
        {
            ProductPriceInfo entity  = null;
            SqlDataReader    RdrList = null;

            try
            {
                string SqlList;
                SqlList = "SELECT * FROM Product_Price WHERE Product_Price_ID = " + ID;
                RdrList = DBHelper.ExecuteReader(SqlList);
                if (RdrList.Read())
                {
                    entity = new ProductPriceInfo();

                    entity.Product_Price_ID            = Tools.NullInt(RdrList["Product_Price_ID"]);
                    entity.Product_Price_ProcutID      = Tools.NullInt(RdrList["Product_Price_ProcutID"]);
                    entity.Product_Price_MemberGradeID = Tools.NullInt(RdrList["Product_Price_MemberGradeID"]);
                    entity.Product_Price_Price         = Tools.NullDbl(RdrList["Product_Price_Price"]);
                }

                return(entity);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (RdrList != null)
                {
                    RdrList.Close();
                    RdrList = null;
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// ////////////////////////////////
        /// </summary>
        /// <param name="productSysNo"></param>
        /// <returns></returns>
        public static ProductPriceInfo QueryProductPriceInfo(int productSysNo)
        {
            ProductPriceInfo result = new ProductPriceInfo();
            DataCommand      cmd    = DataCommandManager.GetDataCommand("GetProductPriceById");

            cmd.SetParameterValue("@SysNo", productSysNo);
            cmd.SetParameterValue("@CompanyCode", Settings.CompanyCode);

            using (DataTable drs = cmd.ExecuteDataSet().Tables[0])
            {
                foreach (DataRow dr in drs.Rows)
                {
                    //result.Id = dr["ProductID"].ToString();
                    result.SysNo = (int)dr["SysNo"];
                    if (dr["CurrentPrice"] != null && dr["CurrentPrice"].ToString() != "")
                    {
                        result.CurrentPrice = (decimal)dr["CurrentPrice"];
                    }
                    if (dr["ItemPoint"] != null && dr["ItemPoint"].ToString() != "")
                    {
                        result.Point = Convert.ToDecimal(dr["ItemPoint"]);
                    }
                    if (dr["Category3SysNo"] != null && dr["Category3SysNo"].ToString() != "")
                    {
                        result.C3SysNo = Convert.ToInt32(dr["Category3SysNo"]);
                    }
                    if (dr["UnitCost"] != null && dr["UnitCost"].ToString() != "")
                    {
                        result.UnitCost = Convert.ToInt32(dr["UnitCost"]);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 保存商品价格信息
        /// </summary>
        /// <param name="priceInfo">价格信息</param>
        /// <returns></returns>
        public static bool SaveProductPriceInfo(ProductPriceInfo priceInfo)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SaveProductPriceInfo");

            cmd.SetParameterValue <ProductPriceInfo>(priceInfo);
            cmd.ExecuteNonQuery();
            return(true);
        }
Exemplo n.º 10
0
        private void UpdateProductVipPrice(int productSysNo, ProductPriceInfo productPriceInfo)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("UpdateProductVipPrice");

            cmd.SetParameterValue("@ProductSysNo", productSysNo);
            cmd.SetParameterValue("@IsUseAlipayVipPrice", productPriceInfo.IsUseAlipayVipPrice);
            cmd.SetParameterValue("@AlipayVipPrice", productPriceInfo.AlipayVipPrice);
            cmd.ExecuteNonQuery();
        }
Exemplo n.º 11
0
        private static ProductPriceInfo ProductPriceFromrdr(NullableDataReader rdr)
        {
            ProductPriceInfo info = new ProductPriceInfo();

            info.Id            = rdr.GetInt32("ID");
            info.GroupId       = rdr.GetInt32("GroupID");
            info.Price         = rdr.GetDecimal("Price");
            info.PropertyValue = rdr.GetString("PropertyValue");
            return(info);
        }
Exemplo n.º 12
0
        public bool Update(int productId, string tableName, ProductPriceInfo productPriceInfo)
        {
            Parameters cmdParams = new Parameters();

            cmdParams.AddInParameter("@TableName", DbType.String, tableName);
            cmdParams.AddInParameter("@ProductID", DbType.Int32, productId);
            cmdParams.AddInParameter("@GroupID", DbType.Int32, productPriceInfo.GroupId);
            cmdParams.AddInParameter("@Price", DbType.Currency, productPriceInfo.Price);
            cmdParams.AddInParameter("@PropertyValue", DbType.String, productPriceInfo.PropertyValue);
            return(DBHelper.ExecuteProc("PR_Shop_ProductPrice_Update", cmdParams));
        }
Exemplo n.º 13
0
        public bool Add(int productId, string tableName, ProductPriceInfo priceInfo)
        {
            Parameters cmdParams = new Parameters();

            cmdParams.AddInParameter("@TableName", DbType.String, tableName);
            cmdParams.AddInParameter("@ProductID", DbType.Int32, productId);
            cmdParams.AddInParameter("@GroupID", DbType.Int32, priceInfo.GroupId);
            cmdParams.AddInParameter("@Price", DbType.Currency, priceInfo.Price);
            cmdParams.AddInParameter("@PropertyValue", DbType.String, priceInfo.PropertyValue);
            return(DBHelper.ExecuteSql("INSERT INTO PE_ProductPrice(TableName, ProductID, GroupID, Price, PropertyValue) VALUES (@TableName, @ProductID, @GroupID, @Price, @PropertyValue)", cmdParams));
        }
Exemplo n.º 14
0
        private static decimal?CalculateProductRate(POItem item)
        {
            decimal          rate  = 0m;
            ProductPriceInfo price = QueryProductPriceInfo(item.ProductSysNo);

            if ((price != null) && (price.CurrentPrice - price.Point * 0.10m) != 0)
            {
                rate = (price.CurrentPrice.Value - price.Point.Value * 0.10m - item.OrderPrice.Value) / (price.CurrentPrice.Value - price.Point.Value * 0.10m);
            }

            return(rate);
        }
Exemplo n.º 15
0
 private void InsertProductRankPrice(int productSysNo, ProductPriceInfo productPriceInfo)
 {
     foreach (var rankPrice in productPriceInfo.ProductRankPrice.Where(rankPrice => rankPrice.RankPrice.HasValue && rankPrice.Status.HasValue))
     {
         DataCommand cmd = DataCommandManager.GetDataCommand("InsertProductRankPrice");
         cmd.SetParameterValue("@ProductSysNo", productSysNo);
         cmd.SetParameterValue("@CustomerRank", rankPrice.Rank);
         cmd.SetParameterValue("@RankPrice", rankPrice.RankPrice);
         cmd.SetParameterValue("@Status", rankPrice.Status);
         cmd.SetParameterValue("@EditUserSysNo", ServiceContext.Current.UserSysNo);
         cmd.ExecuteNonQuery();
     }
 }
Exemplo n.º 16
0
        public void OutStock(int masterSysNo, int userSysNo)
        {
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                AdjustInfo masterInfo = Load(masterSysNo);

                //必须是已审核
                if (masterInfo.Status != (int)AppEnum.AdjustStatus.Verified)
                {
                    throw new BizException("status is not verify now,  outstock failed");
                }


                //设置 单号、状态
                Hashtable ht = new Hashtable(4);
                ht.Add("SysNo", masterInfo.SysNo);
                ht.Add("Status", (int)AppEnum.AdjustStatus.OutStock);
                ht.Add("OutTime", DateTime.Now);
                ht.Add("OutUserSysNo", userSysNo);
                if (1 != new AdjustDac().UpdateMaster(ht))
                {
                    throw new BizException("expected one-row update failed, outstock failed ");
                }


                foreach (AdjustItemInfo item in masterInfo.itemHash.Values)
                {
                    //cost设定
                    ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(item.ProductSysNo);
                    item.AdjustCost = priceInfo.UnitCost;
                    new AdjustDac().UpdateItemCost(item.SysNo, item.AdjustCost);
                    //库存设定
                    if (item.AdjustQty < 0)
                    {
                        InventoryManager.GetInstance().SetOutStockQty(masterInfo.StockSysNo, item.ProductSysNo, -1 * item.AdjustQty);
                    }
                    else
                    {
                        InventoryManager.GetInstance().SetInStockQty(masterInfo.StockSysNo, item.ProductSysNo, item.AdjustQty);
                    }
                }

                scope.Complete();
            }
        }
Exemplo n.º 17
0
        public void UpdateProductBasicPrice(int productSysNo, ProductPriceInfo productPriceInfo)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("UpdateProductBasicPrice");

            cmd.SetParameterValue("@ProductSysNo", productSysNo);
            cmd.SetParameterValue("@BasicPrice", productPriceInfo.BasicPrice);
            cmd.SetParameterValue("@PointType", productPriceInfo.PayType);
            cmd.SetParameterValue("@MaxPerOrder", productPriceInfo.MaxCountPerDay);
            cmd.SetParameterValue("@MinCountPerOrder", productPriceInfo.MinCountPerOrder);
            cmd.SetParameterValue("@MinCommission", productPriceInfo.MinCommission);
            cmd.SetParameterValue("@Discount",
                                  productPriceInfo.BasicPrice != 0
                                      ? (productPriceInfo.CurrentPrice / productPriceInfo.BasicPrice).Round(2)
                                      : 0m);
            cmd.ExecuteNonQuery();
        }
Exemplo n.º 18
0
        public bool SetRunning(int sysno)
        {
            //必须是Ready状态,切换价格和库存
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                CountdownInfo oCountdown = Load(sysno);

                if (oCountdown.Status != (int)AppEnum.CountdownStatus.Ready)
                {
                    throw new BizException("the current status not allow such opertion");
                }

                oCountdown.Status = (int)AppEnum.CountdownStatus.Running;

                ProductPriceInfo oPrice = ProductManager.GetInstance().LoadPrice(oCountdown.ProductSysNo);

                oCountdown.SnapShotCurrentPrice = oPrice.CurrentPrice;
                oCountdown.SnapShotCashRebate   = oPrice.CashRebate;
                oCountdown.SnapShotPoint        = oPrice.Point;

                oPrice.CurrentPrice = oCountdown.CountDownCurrentPrice;
                oPrice.CashRebate   = oCountdown.CountDownCashRebate;
                oPrice.Point        = oCountdown.CountDownPoint;

                InventoryInfo oInventory = InventoryManager.GetInstance().LoadInventory(oCountdown.ProductSysNo);

                //oCountdown.AffectedVirtualQty = oInventory.AvailableQty + oInventory.VirtualQty + oInventory.ConsignQty - oCountdown.CountDownQty;
                oCountdown.AffectedVirtualQty = oInventory.AvailableQty + oInventory.VirtualQty + -oCountdown.CountDownQty;
                if (oCountdown.AffectedVirtualQty < 0)
                {
                    scope.Complete();
                    return(false);
                }

                InventoryManager.GetInstance().SetVirtualQty(oCountdown.ProductSysNo, -1 * oCountdown.AffectedVirtualQty);
                ProductManager.GetInstance().UpdatePriceInfo(oPrice);
                new CountdownDac().Update(oCountdown);

                scope.Complete();
                return(true);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// 根据PriceRequestSysNo获取商品价格变动信息
        /// </summary>
        /// <param name="productPriceRequest"></param>
        /// <returns></returns>
        private void UpdateProductPriceByRequestInfoSysNo(ProductPriceRequestInfo productPriceRequest)
        {
            if (productPriceRequest == null || productPriceRequest.SysNo == null || productPriceRequest.SysNo <= 0)
            {
                return;
            }
            InitProductPriceRequestInfo(productPriceRequest);
            var productSysNo = GetProductSysNoBySysNo(productPriceRequest.SysNo.Value);
            var productPrice = new ProductPriceInfo();

            EntityCopy.CopyProperties(productPriceRequest, productPrice);
            productPrice.ProductWholeSalePriceInfo = productPriceRequest.ProductWholeSalePriceInfo;
            productPrice.ProductRankPrice          = productPriceRequest.ProductRankPrice;
            var productPriceDA = ObjectFactory <IProductPriceDA> .Instance;

            productPriceDA.UpdateProductPrice(productSysNo, productPrice);
        }
Exemplo n.º 20
0
        private static void FillCart(IProductCart cart)
        {
            var candyProductInfo = new ProductPriceInfo(new Candy("Vanilla", 50, 10, 5));

            candyProductInfo.SetQty(4);

            var productCoupon = new DiscountProductCoupon(0.25M, 3);

            candyProductInfo.SetProductCoupon(productCoupon);

            cart.AddProduct(candyProductInfo);

            var juiceProductInfo = new ProductPriceInfo(new Juice("Orange", 25, 50, "red"));

            juiceProductInfo.SetQty(2);
            cart.AddProduct(juiceProductInfo);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 更新数量和成本
        /// 如果是souce, 成本从当前数据库重新取
        /// </summary>
        /// <param name="masterInfo"></param>
        /// <param name="itemInfo"></param>
        public void UpdateItem(TransferInfo masterInfo, TransferItemInfo itemInfo)
        {
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //必须是初始
                if (getCurrentStatus(masterInfo.SysNo) != (int)AppEnum.TransferStatus.Origin)
                {
                    throw new BizException("status is not origin now,  update item qty failed");
                }

                //获取数量差值
                TransferItemInfo oldItemInfo = masterInfo.itemHash[itemInfo.ProductSysNo] as TransferItemInfo;
                int deltQty = itemInfo.TransferQty - oldItemInfo.TransferQty;

                //更新表单明细 ( 如果增加表单明细项的属性,需要在这里处理一下)
                itemInfo.SysNo         = oldItemInfo.SysNo;
                itemInfo.TransferSysNo = oldItemInfo.TransferSysNo;
                itemInfo.TransferType  = oldItemInfo.TransferType;

                //更新source的成本更新库存
                if (itemInfo.TransferType == (int)AppEnum.TransferItemType.Source)
                {
                    ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(itemInfo.ProductSysNo);
                    itemInfo.TransferCost = priceInfo.UnitCost;
                    InventoryManager.GetInstance().SetAvailableQty(masterInfo.StockSysNo, itemInfo.ProductSysNo, deltQty);
                }

                //更新item到数据库
                if (1 != new TransferDac().UpdateItem(itemInfo.SysNo, deltQty, itemInfo.TransferCost))
                {
                    throw new BizException("expected one-row update failed, update item qty failed");
                }

                //更新 itemInfo 到 masterInfo 注:数据库更新成功以后才更新类
                masterInfo.itemHash.Remove(itemInfo.ProductSysNo);
                masterInfo.itemHash.Add(itemInfo.ProductSysNo, itemInfo);

                scope.Complete();
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 如果没有修改Request,则赋原值
        /// </summary>
        private void ProcessNoRequestPrice(ProductPriceRequestInfo requestInfo, ProductPriceInfo priceInfo)
        {
            if (!requestInfo.CurrentPrice.HasValue)
            {
                requestInfo.CurrentPrice = priceInfo.CurrentPrice;
            }
            if (!requestInfo.CashRebate.HasValue)
            {
                requestInfo.CashRebate = priceInfo.CashRebate;
            }
            if (!requestInfo.Point.HasValue)
            {
                requestInfo.Point = priceInfo.Point;
            }

            requestInfo.UnitCost = priceInfo.UnitCost;

            requestInfo.ProductRankPrice.Where(rankPrice => !rankPrice.RankPrice.HasValue).ForEach(
                rankPrice =>
                rankPrice.RankPrice =
                    priceInfo.ProductRankPrice.First(p => p.Rank == rankPrice.Rank).RankPrice);

            requestInfo.ProductWholeSalePriceInfo.ForEach(
                delegate(ProductWholeSalePriceInfo volumePrice)
            {
                var f = priceInfo.ProductWholeSalePriceInfo.FirstOrDefault(
                    p => p.Level == volumePrice.Level);
                int?qty       = f != null ? f.Qty : default(int?);
                decimal?price = f != null ? f.Price : default(decimal?);

                volumePrice.Qty = volumePrice.Qty.HasValue
                                          ? volumePrice.Qty.Value
                                          : qty;

                volumePrice.Price = volumePrice.Price.HasValue
                                            ? volumePrice.Price
                                            : price;
            });
            if (!requestInfo.AlipayVipPrice.HasValue)
            {
                requestInfo.AlipayVipPrice = priceInfo.AlipayVipPrice;
            }
        }
Exemplo n.º 23
0
        public void Create(TransferInfo oParam)
        {
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                oParam.SysNo      = SequenceDac.GetInstance().Create("St_Transfer_Sequence");
                oParam.TransferID = getTransferID(oParam.SysNo);
                //建立主表记录
                int rowsAffected = new TransferDac().InsertMaster(oParam);
                if (rowsAffected != 1)
                {
                    throw new BizException("insert transfer master error");
                }
                foreach (TransferItemInfo item in oParam.itemHash.Values)
                {
                    item.TransferSysNo = oParam.SysNo;

                    //更新source的成本
                    if (item.TransferType == (int)AppEnum.TransferItemType.Source)
                    {
                        ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(item.ProductSysNo);
                        item.TransferCost = priceInfo.UnitCost;
                    }

                    rowsAffected = new TransferDac().InsertItem(item);
                    if (rowsAffected != 1)
                    {
                        throw new BizException("insert transfer item error");
                    }
                    if (item.TransferType == (int)AppEnum.TransferItemType.Source)
                    {                    //需要占用库存
                        InventoryManager.GetInstance().SetAvailableQty(oParam.StockSysNo, item.ProductSysNo, item.TransferQty);
                    }
                }

                scope.Complete();
            }
        }
Exemplo n.º 24
0
        public void InsertItem(AdjustInfo masterInfo, AdjustItemInfo itemInfo)
        {
            if (masterInfo.itemHash.ContainsKey(itemInfo.ProductSysNo))
            {
                throw new BizException("item duplicated!");
            }

            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //必须是初始
                if (getCurrentStatus(masterInfo.SysNo) != (int)AppEnum.AdjustStatus.Origin)
                {
                    throw new BizException("status is not origin now,  add item failed");
                }

                //获取成本,主要的打印和浏览用,因为出库的时候还是会更新的
                ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(itemInfo.ProductSysNo);
                itemInfo.AdjustCost = priceInfo.UnitCost;

                //更新item
                if (1 != new AdjustDac().InsertItem(itemInfo))
                {
                    throw new BizException("expected one-row update failed, add item failed");
                }

                //更新库存
                if (itemInfo.AdjustQty < 0)
                {
                    InventoryManager.GetInstance().SetAvailableQty(masterInfo.StockSysNo, itemInfo.ProductSysNo, -1 * itemInfo.AdjustQty);
                }

                //更新 itemInfo 到 masterInfo
                masterInfo.itemHash.Add(itemInfo.ProductSysNo, itemInfo);

                scope.Complete();
            }
        }
Exemplo n.º 25
0
        public virtual IList <ProductPriceInfo> GetProductPrices(int Product_ID)
        {
            string SqlList;
            IList <ProductPriceInfo> entitys = null;
            ProductPriceInfo         entity  = null;
            SqlDataReader            RdrList = null;

            try
            {
                SqlList = "SELECT * FROM Product_Price WHERE Product_Price_ProcutID = " + Product_ID;
                RdrList = DBHelper.ExecuteReader(SqlList);
                if (RdrList.HasRows)
                {
                    entitys = new List <ProductPriceInfo>();
                    while (RdrList.Read())
                    {
                        entity = new ProductPriceInfo();
                        entity.Product_Price_ID            = Tools.NullInt(RdrList["Product_Price_ID"]);
                        entity.Product_Price_ProcutID      = Tools.NullInt(RdrList["Product_Price_ProcutID"]);
                        entity.Product_Price_MemberGradeID = Tools.NullInt(RdrList["Product_Price_MemberGradeID"]);
                        entity.Product_Price_Price         = Tools.NullDbl(RdrList["Product_Price_Price"]);

                        entitys.Add(entity);
                        entity = null;
                    }
                }
                return(entitys);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (RdrList != null)
                {
                    RdrList.Close();
                    RdrList = null;
                }
            }
        }
Exemplo n.º 26
0
        public int Update(ProductPriceInfo oParam)
        {
            string     sql = @"UPDATE product_price SET 
                            BasicPrice=@BasicPrice, CurrentPrice=@CurrentPrice, 
                            Discount=@Discount, PointType=@PointType, 
                            IsWholeSale=@IsWholeSale, Q1=@Q1, 
                            P1=@P1, Q2=@Q2, 
                            P2=@P2, Q3=@Q3, 
                            P3=@P3, CashRebate=@CashRebate, Point=@Point ,
                            ClearanceSale=@ClearanceSale, LastOrderPrice=@LastOrderPrice, LastMarketLowestPrice=@LastMarketLowestPrice,
                            LimitedQty=@LimitedQty 
                            WHERE SysNo=@SysNo";
            SqlCommand cmd = new SqlCommand(sql);

            SqlParameter paramSysNo                 = new SqlParameter("@SysNo", SqlDbType.Int, 4);
            SqlParameter paramBasicPrice            = new SqlParameter("@BasicPrice", SqlDbType.Decimal, 9);
            SqlParameter paramCurrentPrice          = new SqlParameter("@CurrentPrice", SqlDbType.Decimal, 9);
            SqlParameter paramDiscount              = new SqlParameter("@Discount", SqlDbType.Decimal, 9);
            SqlParameter paramPointType             = new SqlParameter("@PointType", SqlDbType.Int, 4);
            SqlParameter paramIsWholeSale           = new SqlParameter("@IsWholeSale", SqlDbType.Int, 4);
            SqlParameter paramQ1                    = new SqlParameter("@Q1", SqlDbType.Int, 4);
            SqlParameter paramP1                    = new SqlParameter("@P1", SqlDbType.Decimal, 9);
            SqlParameter paramQ2                    = new SqlParameter("@Q2", SqlDbType.Int, 4);
            SqlParameter paramP2                    = new SqlParameter("@P2", SqlDbType.Decimal, 9);
            SqlParameter paramQ3                    = new SqlParameter("@Q3", SqlDbType.Int, 4);
            SqlParameter paramP3                    = new SqlParameter("@P3", SqlDbType.Decimal, 9);
            SqlParameter paramCashRebate            = new SqlParameter("@CashRebate", SqlDbType.Decimal, 9);
            SqlParameter paramPoint                 = new SqlParameter("@Point", SqlDbType.Int, 4);
            SqlParameter paramClearanceSale         = new SqlParameter("@ClearanceSale", SqlDbType.Int, 4);
            SqlParameter paramLastOrderPrice        = new SqlParameter("@LastOrderPrice", SqlDbType.Decimal, 9);
            SqlParameter paramLastMarketLowestPrice = new SqlParameter("@LastMarketLowestPrice", SqlDbType.Decimal, 9);
            SqlParameter paramLimitedQty            = new SqlParameter("@LimitedQty", SqlDbType.Int, 4);

            if (oParam.SysNo != AppConst.IntNull)
            {
                paramSysNo.Value = oParam.SysNo;
            }
            else
            {
                paramSysNo.Value = System.DBNull.Value;
            }
            if (oParam.BasicPrice != AppConst.DecimalNull)
            {
                paramBasicPrice.Value = oParam.BasicPrice;
            }
            else
            {
                paramBasicPrice.Value = System.DBNull.Value;
            }
            if (oParam.CurrentPrice != AppConst.DecimalNull)
            {
                paramCurrentPrice.Value = oParam.CurrentPrice;
            }
            else
            {
                paramCurrentPrice.Value = System.DBNull.Value;
            }
            if (oParam.Discount != AppConst.DecimalNull)
            {
                paramDiscount.Value = oParam.Discount;
            }
            else
            {
                paramDiscount.Value = System.DBNull.Value;
            }
            if (oParam.PointType != AppConst.IntNull)
            {
                paramPointType.Value = oParam.PointType;
            }
            else
            {
                paramPointType.Value = System.DBNull.Value;
            }
            if (oParam.IsWholeSale != AppConst.IntNull)
            {
                paramIsWholeSale.Value = oParam.IsWholeSale;
            }
            else
            {
                paramIsWholeSale.Value = System.DBNull.Value;
            }
            if (oParam.Q1 != AppConst.IntNull)
            {
                paramQ1.Value = oParam.Q1;
            }
            else
            {
                paramQ1.Value = System.DBNull.Value;
            }
            if (oParam.P1 != AppConst.DecimalNull)
            {
                paramP1.Value = oParam.P1;
            }
            else
            {
                paramP1.Value = System.DBNull.Value;
            }
            if (oParam.Q2 != AppConst.IntNull)
            {
                paramQ2.Value = oParam.Q2;
            }
            else
            {
                paramQ2.Value = System.DBNull.Value;
            }
            if (oParam.P2 != AppConst.DecimalNull)
            {
                paramP2.Value = oParam.P2;
            }
            else
            {
                paramP2.Value = System.DBNull.Value;
            }
            if (oParam.Q3 != AppConst.IntNull)
            {
                paramQ3.Value = oParam.Q3;
            }
            else
            {
                paramQ3.Value = System.DBNull.Value;
            }
            if (oParam.P3 != AppConst.DecimalNull)
            {
                paramP3.Value = oParam.P3;
            }
            else
            {
                paramP3.Value = System.DBNull.Value;
            }
            if (oParam.CashRebate != AppConst.DecimalNull)
            {
                paramCashRebate.Value = oParam.CashRebate;
            }
            else
            {
                paramCashRebate.Value = System.DBNull.Value;
            }
            if (oParam.PointType != AppConst.IntNull)
            {
                paramPoint.Value = oParam.Point;
            }
            else
            {
                paramPoint.Value = System.DBNull.Value;
            }
            if (oParam.ClearanceSale != AppConst.IntNull)
            {
                paramClearanceSale.Value = oParam.ClearanceSale;
            }
            else
            {
                paramClearanceSale.Value = System.DBNull.Value;
            }

            if (oParam.LastOrderPrice != AppConst.IntNull)
            {
                paramLastOrderPrice.Value = oParam.LastOrderPrice;
            }
            else
            {
                paramLastOrderPrice.Value = 0;
            }

            if (oParam.LastMarketLowestPrice != AppConst.IntNull)
            {
                paramLastMarketLowestPrice.Value = oParam.LastMarketLowestPrice;
            }
            else
            {
                paramLastMarketLowestPrice.Value = 0;
            }

            if (oParam.LimitedQty != AppConst.IntNull)
            {
                paramLimitedQty.Value = oParam.LimitedQty;
            }
            else
            {
                paramLimitedQty.Value = 999;
            }

            cmd.Parameters.Add(paramSysNo);
            cmd.Parameters.Add(paramBasicPrice);
            cmd.Parameters.Add(paramCurrentPrice);
            cmd.Parameters.Add(paramDiscount);
            cmd.Parameters.Add(paramPointType);
            cmd.Parameters.Add(paramIsWholeSale);
            cmd.Parameters.Add(paramQ1);
            cmd.Parameters.Add(paramP1);
            cmd.Parameters.Add(paramQ2);
            cmd.Parameters.Add(paramP2);
            cmd.Parameters.Add(paramQ3);
            cmd.Parameters.Add(paramP3);
            cmd.Parameters.Add(paramCashRebate);
            cmd.Parameters.Add(paramPoint);
            cmd.Parameters.Add(paramClearanceSale);
            cmd.Parameters.Add(paramLastOrderPrice);
            cmd.Parameters.Add(paramLastMarketLowestPrice);
            cmd.Parameters.Add(paramLimitedQty);

            return(SqlHelper.ExecuteNonQuery(cmd));
        }
Exemplo n.º 27
0
 public static bool Update(int productId, string tableName, ProductPriceInfo productPriceInfo)
 {
     return(dal.Update(productId, tableName, productPriceInfo));
 }
Exemplo n.º 28
0
 public static bool Add(int productId, string tableName, ProductPriceInfo priceInfo)
 {
     return(dal.Add(productId, tableName, priceInfo));
 }
        public override ProductPriceInfoList GetProductPricesWild(long productid, string isoCurrency, string culture)
        {
            ProductPriceInfoList res = new ProductPriceInfoList();
            using (MySqlConnection conn = new MySqlConnection(GetConnectionString()))
            {
                using (MySqlCommand cmd = new MySqlCommand(QRY_GET_PRODUCTPRICE_BY_PRODUCT_ID_CURRENCY_COUNTRY_WILD, conn))
                {
                    cmd.Parameters.Add("@product_id", MySqlDbType.Int64).Value = productid;
                    cmd.Parameters.Add("@iso_currency", MySqlDbType.VarChar, 10).Value = isoCurrency;
                    //cmd.Parameters.Add("@iso2_country", MySqlDbType.VarChar, 2).Value = culture.Substring(3);
                    cmd.Parameters.Add("@iso2_country", MySqlDbType.VarChar, 2).Value = culture.Substring(3);

                    DataTable tbl = new DataTable("productprice");
                    using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                    {
                        try
                        {
                            conn.Open();

                            da.Fill(tbl);
                            foreach (DataRow row in tbl.Rows)
                            {
                                long productPriceId = Convert.ToInt64(row["productprice_id"]);
                                decimal price = Convert.ToDecimal(row["price"]);
                                string isoCurreny = Convert.ToString(row["iso_currency"]);
                                string iso2Country = Convert.ToString(row["iso2_country"]);
                                long productId = Convert.ToInt64(row["product_id"]);
                                ProductPriceInfo ppi = new ProductPriceInfo(productPriceId, price, isoCurreny, iso2Country, productId);
                                res.Add(ppi);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Write(LogLevel.Error, ex, "GetProductPricesWild<Exception>");
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
            }
            return res;
        }
        public override TransactionResult UpdateTransaction(string orderId, string result, string status, string statusCode,
                                               string merchant, string paymentid, string reference, string transid,
                                               string paymentmethod, decimal amount, ProductInfo productInfo,
                                               string currencyIso, string countryIso2)
        {
            long userId = -1;
            ProductPriceInfo ppi = null;
            string oldStatusCode = string.Empty;
            using (MySqlConnection conn = new MySqlConnection(GetConnectionString()))
            {
                using (MySqlCommand cmd = new MySqlCommand(QRY_GET_PRODUCTPRICE_BY_PRODUCT_ID_CURRENCY_COUNTRY_WILD, conn))
                {
                    cmd.Parameters.Add("@product_id", MySqlDbType.Int64).Value = productInfo.ProductId;
                    cmd.Parameters.Add("@iso_currency", MySqlDbType.VarChar, 10).Value = currencyIso;
                    cmd.Parameters.Add("@iso2_country", MySqlDbType.VarChar, 2).Value = countryIso2;

                    try
                    {
                        conn.Open();
                        using (MySqlDataReader rdr = cmd.ExecuteReader())
                        {
                            if (rdr.HasRows)
                            {
                                while (rdr.Read())
                                {
                                    long productPriceId = rdr.GetInt64(0);
                                    decimal price = rdr.GetDecimal(1);
                                    string isoCurrency = rdr.GetString(2);
                                    string iso2Country = rdr.GetString(3);
                                    ppi = new ProductPriceInfo(productPriceId, price, isoCurrency, iso2Country,
                                                               productInfo.ProductId);
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Write(
                            LogLevel.Error, ex,
                            "UpdateTransaction<Exception:Get ProductPriceInfo>");
                        conn.Close();
                        return TransactionResult.NotFound;
                    }
                }

                long transactionId;
                if (!long.TryParse(orderId, out transactionId))
                    transactionId = 0;
                using (MySqlCommand cmd = new MySqlCommand(QRY_GET_TRANSACTION_STATUS, conn))
                {
                    cmd.Parameters.Add("@transaction_id", MySqlDbType.Int64).Value = transactionId;
                    try
                    {
                        object obj = cmd.ExecuteScalar();
                        if (obj != null)
                        {
                            string currStatus = Convert.ToString(obj);
                            if (currStatus.ToLower() == "ok" || currStatus.ToLower() == "err")
                                return TransactionResult.AlreadyCompleted;
                        }
                        else
                        {
                            return TransactionResult.NotFound;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Write(LogLevel.Error, ex, "UpdateTransaction<exception>[check status]");
                        return TransactionResult.NotFound;
                    }
                }

                using (MySqlCommand cmd = new MySqlCommand(QRY_GET_TRANSACTION_STATUSCODE, conn))
                {
                    cmd.Parameters.Add("@transaction_id", MySqlDbType.Int64).Value = transactionId;
                    try
                    {
                        object obj = cmd.ExecuteScalar();
                        if (obj != null)
                        {
                            oldStatusCode = Convert.ToString(obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Write(LogLevel.Error, ex, "UpdateTransaction<exception>[check status]");
                        return TransactionResult.NotFound;
                    }
                }

                using (MySqlCommand cmd = new MySqlCommand(QRY_UPDATE_TRANSACTION, conn))
                {
                    //cmd.Parameters.Add("@result", MySqlDbType.VarChar, 100).Value			= result;
                    cmd.Parameters.Add("@status", MySqlDbType.VarChar, 100).Value = status;
                    cmd.Parameters.Add("@statuscode", MySqlDbType.VarChar, 100).Value = statusCode;
                    cmd.Parameters.Add("@merchant", MySqlDbType.VarChar, 50).Value = merchant;
                    cmd.Parameters.Add("@paymentid", MySqlDbType.VarChar, 100).Value = paymentid;
                    cmd.Parameters.Add("@transid", MySqlDbType.VarChar, 100).Value = transid;
                    cmd.Parameters.Add("@paymentmethod", MySqlDbType.VarChar, 100).Value = paymentmethod;
                    cmd.Parameters.Add("@transaction_id", MySqlDbType.Int64).Value = transactionId;

                    try
                    {
                        cmd.ExecuteNonQuery();
                    }
                    catch (MySqlException ex)
                    {
                        Logger.Instance.Write(LogLevel.Error, ex, "UpdateTransaction<MySqlException>");
                        return TransactionResult.NotFound;
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.Write(LogLevel.Error, ex, "UpdateTransaction<Exception>");
                        return TransactionResult.NotFound;
                    }
                }

                if (status == "OK" && paymentmethod.ToUpper() != "COUPON")	// Valid, completed transaction
                {
                    Util.CreateInvoice(Util.UserId, status, transid, paymentmethod, productInfo, ppi);
                    if (string.Compare(productInfo.Extra, "subscription", true) == 0)
                    {
                        // Customer bought a subscription, check whether we have to update
                        // his management rights.
                        using (MySqlCommand cmd = new MySqlCommand(QRY_GET_TRANSACTION_USERID, conn))
                        {
                            cmd.Parameters.Add("@transaction_id", MySqlDbType.Int64).Value = transactionId;
                            try
                            {
                                object obj = cmd.ExecuteScalar();
                                if (obj != null)
                                    userId = (long)obj;
                            }
                            catch (Exception ex)
                            {
                                Logger.Instance.Write(LogLevel.Error, ex, "UpdateTransaction<exception>[check user id]");
                            }
                        }
                        if (!string.IsNullOrEmpty(oldStatusCode))
                        {
                            if (oldStatusCode.StartsWith("SUB"))
                            {
                                int credits;
                                oldStatusCode = oldStatusCode.Substring(3);
                                oldStatusCode = oldStatusCode.Trim('(', ')');
                                string[] parts = oldStatusCode.Split(':');
                                if (parts.Length > 1)
                                {
                                    if (int.TryParse(parts[1], out credits))
                                        productInfo.Credits = credits;
                                }
                            }
                        }
                    }
                }
            }
            if (userId > -1)
                RegisterUserRights(userId, 100, 100);

            return TransactionResult.Success;
        }
 public ProductPriceInfoList GetProductPrices(int productid)
 {
     ProductPriceInfoList res = new ProductPriceInfoList();
     using (NpgsqlConnection conn = new NpgsqlConnection(GetConnectionString()))
     {
         string query = string.Format(
             QRY_GET_PRODUCTPRICES_BY_PRODUCT_ID,
             productid);
         using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn))
         {
             DataTable tbl = new DataTable("productprice");
             using (NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd))
             {
                 try
                 {
                     da.Fill(tbl);
                     foreach (DataRow row in tbl.Rows)
                     {
                         int productPriceId	= Convert.ToInt32(row["productprice_id"]);
                         decimal price		= Convert.ToDecimal(row["price"]);
                         string isoCurreny	= Convert.ToString (row["iso_currency"]);
                         string iso2Country	= Convert.ToString (row["iso2_country"]);
                         int productId		= Convert.ToInt32(row["product_id"]);
                         ProductPriceInfo ppi = new ProductPriceInfo(productPriceId, price, isoCurreny, iso2Country, productId);
                         res.Add(ppi);
                     }
                 }
                 catch (Exception ex)
                 {
                     Logger.Instance.Write(TrackProtect.Logging.LogLevel.Error, ex, "GetProductPrices<Exception>");
                 }
                 finally
                 {
                     conn.Close();
                 }
             }
         }
     }
     return res;
 }
        public override ProductPriceInfoList GetProductPricesExact(long productid, string iso_currency, string culture)
        {
            if (iso_currency == null)
                throw new ArgumentNullException("iso_currency");
            string workCulture = "nl-NL";
            if (!string.IsNullOrEmpty(culture))
                workCulture = culture;
            string isoCurrency = "EUR";
            string isoCountry = "NL";
            if (!string.IsNullOrEmpty(iso_currency))
                isoCurrency = iso_currency;
            if (!string.IsNullOrEmpty(culture))
            {
                isoCountry = culture.Length == 2 ? culture : culture.Substring(3);
            }

            ProductPriceInfoList res = new ProductPriceInfoList();
            using (MySqlConnection conn = new MySqlConnection(GetConnectionString()))
            {
                using (MySqlCommand cmd = new MySqlCommand(QRY_GET_PRODUCTPRICE_BY_PRODUCT_ID_CURRENCY_COUNTRY_EXACT, conn))
                {
                    cmd.Parameters.Add("@product_id", MySqlDbType.Int64).Value = productid;
                    cmd.Parameters.Add("@iso_currency", MySqlDbType.VarChar, 10).Value = isoCurrency;
                    cmd.Parameters.Add("@iso2_country", MySqlDbType.VarChar, 2).Value = isoCountry;

                    DataTable tbl = new DataTable("productprice");
                    using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                    {
                        conn.Open();
                        try
                        {
                            da.Fill(tbl);
                            foreach (DataRow row in tbl.Rows)
                            {
                                long productPriceId = Convert.ToInt64(row["productprice_id"]);
                                decimal price = Convert.ToDecimal(row["price"]);
                                string isoCurreny = Convert.ToString(row["iso_currency"]);
                                string iso2Country = Convert.ToString(row["iso2_country"]);
                                long productId = Convert.ToInt64(row["product_id"]);
                                ProductPriceInfo ppi = new ProductPriceInfo(productPriceId, price, isoCurreny, iso2Country, productId);
                                res.Add(ppi);
                            }
                        }
                        catch (Exception ex)
                        {
                            Logger.Instance.Write(LogLevel.Error, ex, "GetProductPricesExact<Exception>");
                        }
                        finally
                        {
                            conn.Close();
                        }
                    }
                }
            }
            return res;
        }
Exemplo n.º 33
0
        internal static string CreateInvoice(long userId, string status, string transid, string paymentmethod, ProductInfo productInfo, ProductPriceInfo ppi)
        {
            string companyName = string.Empty;
            string userPath = String.Empty;
            string password = HttpContext.Current.Session["access"] as string;
            UserInfo userInfo = null;
            ClientInfo clientInfo = null;
            using (Database db = new MySqlDatabase())
            {
                userPath = db.GetUserDocumentPath(userId, password);

                userPath = userPath.Replace("\\", "/");

                if (!Directory.Exists(userPath))
                    Directory.CreateDirectory(userPath);

                userInfo = db.GetUser(userId, password);
                clientInfo = db.GetClientInfo(userId);

                companyName = clientInfo.CompanyName;
            }
            // complete userPath with document name
            string filename = String.Format("INV{0}.pdf", transid);
            userPath = Path.Combine(userPath, filename);

            // Get the invoice template from the proper location
            string templatePath = Resource.InvoiceTemplate;
            string invoiceTemplate = HttpContext.Current.Server.MapPath(templatePath);
            try
            {
                InvoiceForm form = new InvoiceForm(invoiceTemplate);
                string culture = "nl-NL";
                if (HttpContext.Current.Session["culture"] != null)
                    culture = HttpContext.Current.Session["culture"] as string;
                CultureInfo cultureInfo = new CultureInfo(culture);

                List<string> fields = new List<string>();
                fields.Add(clientInfo.GetFullName());
                fields.Add(clientInfo.AddressLine1);
                if (!string.IsNullOrEmpty(clientInfo.AddressLine2))
                    fields.Add(clientInfo.AddressLine2);
                string tmpResidence = clientInfo.ZipCode + " " + clientInfo.City.ToUpper();
                if (!string.IsNullOrEmpty(tmpResidence))
                    fields.Add(tmpResidence);
                if (!string.IsNullOrEmpty(clientInfo.Country))
                    fields.Add(clientInfo.Country);
                while (fields.Count < 5)
                    fields.Add(" ");

                form.ClientAddress = fields.ToArray();
                form.InvoiceDate = DateTime.Now.ToString("d", cultureInfo);
                form.InvoiceNumber = transid;
                using (Database db = new MySqlDatabase())
                {
                    Transaction transaction = db.GetTransaction(Util.UserId, transid);
                    foreach (TransactionLine tl in transaction.TransactionLines)
                    {
                        form.InvoiceLines.Add(new PdfInvoiceLine()
                        {
                            Description = tl.Description,
                            Quantity = tl.Quantity,
                            UnitPrice = tl.Price,
                            VatRate = tl.VatPercentage
                        });
                    }
                }
                form.GenerateInvoice(userPath, companyName);
            }
            catch (Exception ex)
            {
                Logger.Instance.Write(LogLevel.Error, ex, "[CreateInvoice]");
            }

            SendInvoice(userId, userPath);

            return userPath;
        }
Exemplo n.º 34
0
 public ReceiptRecord(string itemName, ProductPriceInfo priceInfo)
 {
     ItemName = itemName;
     PriceInfo = priceInfo;
 }
Exemplo n.º 35
0
 internal static void TestInvoice()
 {
     ProductInfo pi = new ProductInfo(1, "Product 1", "Product 1 description", 10, string.Empty);
     ProductPriceInfo ppi = new ProductPriceInfo(1, 12.5m, "EUR", "NL", 1);
     CreateInvoice(1, "OK", DateTime.Now.ToString("HHmmss"), "IDEAL", pi, ppi);
 }
Exemplo n.º 36
0
        /// <summary>
        /// 计算商品最终售价
        /// 原则:取最优客户价格
        /// </summary>
        /// <param name="soInfo"></param>
        public virtual void CalculateItemPrice(SOInfo soInfo)
        {
            //礼品卡订单不获取价格
            if (soInfo.BaseInfo.SOType == SOType.ElectronicCard ||
                soInfo.BaseInfo.SOType == SOType.PhysicalCard)
            {
                soInfo.Items.ForEach(item =>
                {
                    item.GainAveragePoint = 0;
                    item.PayType          = ProductPayType.MoneyOnly;
                });

                return;
            }

            //获取商品价格信息
            List <int> itemSysNos = soInfo.Items.Where(item => item.ProductType == SOProductType.Accessory ||
                                                       item.ProductType == SOProductType.Award ||
                                                       item.ProductType == SOProductType.Gift ||
                                                       item.ProductType == SOProductType.Product ||
                                                       item.ProductType == SOProductType.SelfGift)
                                    .Select <SOItemInfo, int>(item => item.ProductSysNo.Value).ToList <int>();

            List <ProductInfo> productInfoList = ExternalDomainBroker.GetProductInfoListByProductSysNoList(itemSysNos);

            if (productInfoList != null && productInfoList.Count > 0)
            {
                foreach (var item in soInfo.Items)
                {
                    //普通商品处理逻辑
                    if (item.ProductType == SOProductType.Product)
                    {
                        ProductPriceInfo priceInfo       = null;
                        ProductInfo      productInfoTemp = productInfoList.Find(x => x.SysNo == item.ProductSysNo);
                        if (productInfoTemp != null)
                        {
                            priceInfo = productInfoTemp.ProductPriceInfo;
                        }
                        if (priceInfo != null)
                        {
                            item.CostPrice        = priceInfo.UnitCost;
                            item.PayType          = priceInfo.PayType;//Vantal Update 属性名称修改
                            item.GainAveragePoint = priceInfo.Point;
                            item.OriginalPrice    = priceInfo.CurrentPrice;

                            CustomerRank customerRank = ExternalDomainBroker.GetCustomerRank(soInfo.BaseInfo.CustomerSysNo.Value);

#warning 批发与手动修改价格逻辑需要再处理, 更新订单逻辑也需要考虑

                            decimal tempWholeSalePrice = 0.00M;
                            decimal tempMemberPrice    = 0.00M;
                            //如果商品支持批发价,商品售价取最优批发价格
                            if (priceInfo.ProductWholeSalePriceInfo != null && priceInfo.ProductWholeSalePriceInfo.Count > 0)
                            {
                                //取最优批发价
                                priceInfo.ProductWholeSalePriceInfo.OrderBy(l => l.Level)
                                .ToList()
                                .ForEach(w =>
                                {
                                    if (item.Quantity >= w.Qty)
                                    {
                                        tempWholeSalePrice = w.Price.Value;
                                    }
                                });
                            }

                            //优先使用会员价
                            priceInfo.ProductRankPrice.OrderBy(r => r.Rank)
                            .ToList()
                            .ForEach(r =>
                            {
                                if (r.Status.HasValue &&
                                    r.Status == ProductRankPriceStatus.Active &&
                                    customerRank >= r.Rank)
                                {
                                    tempMemberPrice = r.RankPrice.Value;
                                }
                            });
                            if (tempWholeSalePrice != 0)
                            {
                                item.OriginalPrice = Math.Min(tempWholeSalePrice, item.OriginalPrice.Value);
                                item.PriceType     = SOProductPriceType.WholeSale;
                            }
                            if (tempMemberPrice != 0)
                            {
                                if (tempMemberPrice <= tempWholeSalePrice)
                                {
                                    item.OriginalPrice = Math.Min(tempMemberPrice, item.OriginalPrice.Value);
                                    item.PriceType     = SOProductPriceType.Member;
                                }
                            }
                            if (item.PriceType == SOProductPriceType.WholeSale)
                            {
                                //批发无积分
                                item.GainAveragePoint = 0;
                            }

                            if (m_isManualPrice)
                            {
                                //重新计算Discount
                                if (item.Price_End > 0)
                                {
                                    item.AdjustPrice = item.OriginalPrice.Value - item.Price_End;
                                    //初始化调价
                                    item.Price_End = 0;
                                }
                                item.OriginalPrice = item.OriginalPrice - item.AdjustPrice;
                            }

                            //更新状态购物车的单件商品没有修改数量按原始价格计算
                            if (IsUpdate)
                            {
                                var originalItem = OriginalSOInfo.Items.Find(oitem => oitem.ProductSysNo == item.ProductSysNo);
                                if (originalItem != null && item.Quantity == originalItem.Quantity)
                                {
                                    //如果手动改价
                                    if (item.AdjustPrice != originalItem.AdjustPrice)
                                    {
                                        item.OriginalPrice = (originalItem.OriginalPrice ?? 0) + originalItem.AdjustPrice - item.AdjustPrice;
                                        //continue;
                                    }
                                }
                            }
                            item.Price = item.OriginalPrice;
                        }
                    }
                    //优惠券和延保不赠积分
                    else if (item.ProductType == SOProductType.Coupon)
                    {
                        item.GainAveragePoint = 0;
                        item.PayType          = ProductPayType.All;
                    }
                    else if (item.ProductType == SOProductType.ExtendWarranty)
                    {
                        item.OriginalPrice    = item.Price;
                        item.GainAveragePoint = 0;
                        item.PayType          = ProductPayType.All;
                        //数量
                        var masterProduct = soInfo.Items.First(p => p.ProductSysNo.ToString() == item.MasterProductSysNo);
                        item.Quantity = masterProduct.Quantity;
                    }
                    //是赠品,附件,奖品则价格为0, 积分为0
                    else
                    {
                        ProductPriceInfo priceInfo       = null;
                        ProductInfo      productInfoTemp = productInfoList.Find(x => x.SysNo == item.ProductSysNo);
                        if (productInfoTemp != null)
                        {
                            priceInfo = productInfoTemp.ProductPriceInfo;
                        }
                        if (priceInfo != null)
                        {
                            item.CostPrice = priceInfo.UnitCost;
                        }
                        item.OriginalPrice = 0;
                        item.Price         = 0;
                        item.PayType       = ProductPayType.All;
                    }
                }
            }

            if (m_isManualPrice)
            {
                if (IsUpdate)
                {
                    foreach (var item in soInfo.Items)
                    {
                        SOItemInfo oldSOItem = OriginalSOInfo.Items.Find(oldItem => oldItem.ProductSysNo == item.ProductSysNo);

                        if (oldSOItem != null)
                        {
                            if (!(item.PromotionAmount == 0 && string.IsNullOrEmpty(item.AdjustPriceReason)) && !(item.Price_End != item.Price))
                            {
                                item.OriginalPrice = item.OriginalPrice + oldSOItem.PromotionAmount - item.PromotionAmount;
                            }
                        }
                        item.Price = item.OriginalPrice;
                    }
                }
                else if (soInfo.BaseInfo.SOType == SOType.Gift)
                {
                    //赠品订单做补偿时使用
                    soInfo.Items.ForEach(item =>
                    {
                        item.PromotionAmount   = item.OriginalPrice;
                        item.AdjustPriceReason = "赠品订单自动调整";
                        item.OriginalPrice     = 0;
                        item.Price             = 0;
                    });
                }
            }
        }
Exemplo n.º 37
0
        public void UpdateItemQty(AdjustInfo masterInfo, AdjustItemInfo itemInfo)
        {
            TransactionOptions options = new TransactionOptions();

            options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
            options.Timeout        = TransactionManager.DefaultTimeout;

            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, options))
            {
                //必须是初始
                if (getCurrentStatus(masterInfo.SysNo) != (int)AppEnum.AdjustStatus.Origin)
                {
                    throw new BizException("status is not origin now,  update item qty failed");
                }

                //获取数量差值
                AdjustItemInfo oldItemInfo = masterInfo.itemHash[itemInfo.ProductSysNo] as AdjustItemInfo;


                /*
                 * old     new
                 * >0      >0    不需要处理
                 * <0      <0    new - old = delt
                 * <0      >0    0 - old = delt
                 * >0      <0    new - 0 = delt
                 */
                int newAllocatedQty = 0;
                int oldQty          = oldItemInfo.AdjustQty;
                int newQty          = itemInfo.AdjustQty;
                int deltQty         = newQty - oldQty;

                if (oldQty < 0 && newQty < 0)
                {
                    newAllocatedQty = newQty - oldQty;
                }
                else if (oldQty < 0 && newQty > 0)
                {
                    newAllocatedQty = 0 - oldQty;
                }
                else if (oldQty > 0 && newQty < 0)
                {
                    newAllocatedQty = newQty - 0;
                }


                //更新表单明细 ( 如果增加表单明细项的属性,需要在这里处理一下)
                itemInfo.SysNo       = oldItemInfo.SysNo;
                itemInfo.AdjustSysNo = oldItemInfo.AdjustSysNo;
                //获取成本,主要的打印和浏览用,因为出库的时候还是会更新的
                ProductPriceInfo priceInfo = ProductManager.GetInstance().LoadPrice(itemInfo.ProductSysNo);
                itemInfo.AdjustCost = priceInfo.UnitCost;

                if (1 != new AdjustDac().UpdateItemQtyCost(itemInfo.SysNo, deltQty, itemInfo.AdjustCost))
                {
                    throw new BizException("expected one-row update failed, update item qty failed");
                }


                //更新占用和可用库存
                //////////////////////////////////////////////////////////////////////////
                if (newAllocatedQty != 0)
                {
                    InventoryManager.GetInstance().SetAvailableQty(masterInfo.StockSysNo, itemInfo.ProductSysNo, -1 * newAllocatedQty);
                }

                //更新 itemInfo 到 masterInfo 注:数据库更新成功以后才更新类
                masterInfo.itemHash.Remove(itemInfo.ProductSysNo);
                masterInfo.itemHash.Add(itemInfo.ProductSysNo, itemInfo);

                scope.Complete();
            }
        }