private void gridViewSpecifications_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.ColumnIndex == gridViewSpecifications.Columns["specificationEditButton"].Index)
     {
         DataRowView    data      = (DataRowView)gridViewSpecifications.Rows[e.RowIndex].DataBoundItem;
         ProductPriceVM productVM = MapDataRowViewToPriceVM(data);
         this.productId = productVM.ProductId;
         SetDataToPriceForm(productVM);
         this.btnSelectPriceAdd.Text = "Update";
         this.isPriceUpdate          = true;
         this.priceId    = productVM.Id;
         this.updatedRow = gridViewSpecifications.Rows[e.RowIndex];
     }
     else if (e.ColumnIndex == gridViewSpecifications.Columns["specificationDeleteButton"].Index)
     {
         using (ProductBLL product = new ProductBLL())
         {
             DataRowView    data      = (DataRowView)gridViewSpecifications.Rows[e.RowIndex].DataBoundItem;
             ProductPriceVM productVM = MapDataRowViewToPriceVM(data);
             product.DeleteProductPriceMapping(productVM.Id);
             gridViewSpecifications.Rows.Remove(gridViewSpecifications.Rows[e.RowIndex]);
             this.getProducts();
         }
     }
 }
Ejemplo n.º 2
0
 public int ManageProductPriceMap(ProductPriceVM productPrice)
 {
     using (ProductDAL productDal = new ProductDAL())
     {
         return(productDal.ManageProductPriceMap(productPrice));
     }
 }
        public static Dictionary <int, ProductPriceVM> GetAllLastPrice()
        {
            var list       = new Dictionary <int, ProductPriceVM>();
            var collection = db.GetCollection <MgPrice>("prices");
            var data       = collection.Find(o => o.isLatest).ToList();

            data = data.OrderByDescending(o => o.addDate).ToList();
            var marketGroup = data.GroupBy(o => o.marketId);

            foreach (var g in marketGroup)
            {
                var productPrice = g.OrderByDescending(o => o.addDate).First();
                var vm           = new ProductPriceVM();
                vm.AddDate     = productPrice.addDate.ToLocalTime();
                vm.Change      = CommonService.ChangePrice(productPrice.change);
                vm.LPrice      = productPrice.low;
                vm.HPrice      = productPrice.high;
                vm.ProductId   = productPrice.productId;
                vm.MarketID    = productPrice.marketId;
                vm.ProductName = productPrice.productName;
                list.Add(g.Key, vm);
            }

            return(list);
        }
        private void btnSelectPriceAdd_Click(object sender, EventArgs e)
        {
            using (ProductBLL productBll = new ProductBLL())
            {
                string         discount     = String.IsNullOrWhiteSpace(this.txtDiscount.Text) ? "0.00" : Convert.ToDecimal(this.txtDiscount.Text) == 0 ? "0.00" : this.txtDiscount.Text;
                ProductPriceVM productPrice = new ProductPriceVM()
                {
                    Id           = !isPriceUpdate ? 0 : MapDataRowViewToPriceVM((DataRowView)this.updatedRow.DataBoundItem).Id,
                    mpt_SizeEnum = Convert.ToInt32(this.cmbSelectSize.SelectedValue),
                    Price        = Convert.ToDecimal(this.lblFinalPrice.Text),
                    Discount     = Convert.ToDecimal(discount),
                    ProductId    = Convert.ToInt32(cmbSelectProduct.SelectedValue)
                };

                int response = productBll.ManageProductPriceMap(productPrice);
                if (response > 0)
                {
                    this.getProducts();
                    this.PriceFormInputReset();
                    MessageBox.Show("Item added succesfully");
                }
                else
                {
                    MessageBox.Show("Item Insert Error");
                }
            }
            this.btnSelectPriceAdd.Text = "Add";
            this.isPriceUpdate          = false;
        }
Ejemplo n.º 5
0
        private void btnProductAdd_Click(object sender, EventArgs e)
        {
            ProductVM product = (ProductVM)cmbSelectProduct.SelectedItem;

            if (product.PriceList.Count() == 0)
            {
                MessageBox.Show("Please define price before add");
                return;
            }

            ProductPriceVM productPrice    = product.PriceList.First(price => price.mpt_SizeEnum == (int)cmbSize.SelectedValue);
            decimal        discountedPrice = productPrice.Price * (100 - productPrice.Discount) / 100;
            decimal        totalPrice      = Convert.ToInt32(txtSelectQuantity.Text) * discountedPrice;
            DataRow        itemDataRow     = this.receiptTable.NewRow();

            itemDataRow[0] = product.CategoryName;
            itemDataRow[1] = product.Name;
            itemDataRow[2] = cmbSize.Text;
            itemDataRow[3] = txtSelectQuantity.Text;
            itemDataRow[4] = String.Format("{0:0.00}", productPrice.Price);
            itemDataRow[5] = productPrice.Discount;
            itemDataRow[6] = String.Format("{0:0.00}", discountedPrice);
            itemDataRow[7] = String.Format("{0:0.00}", totalPrice);
            itemDataRow[8] = JsonConvert.SerializeObject(product);
            itemDataRow[9] = JsonConvert.SerializeObject(productPrice);
            this.receiptTable.Rows.Add(itemDataRow);
            this.clearProductFormAddBtn();
        }
        private ProductPriceVM MapDataRowViewToPriceVM(DataRowView itemDataRow)
        {
            ProductPriceVM productPriceVM = new ProductPriceVM();

            productPriceVM.SizeName     = itemDataRow[0].ToString();
            productPriceVM.Price        = Convert.ToDecimal(!String.IsNullOrEmpty(itemDataRow[1].ToString()) ? itemDataRow[1] : 0);
            productPriceVM.Discount     = Convert.ToDecimal(!String.IsNullOrEmpty(itemDataRow[2].ToString()) ? itemDataRow[2] : 0);
            productPriceVM.mpt_SizeEnum = Convert.ToInt32(!String.IsNullOrEmpty(itemDataRow[4].ToString()) ? itemDataRow[4] : 0);
            productPriceVM.ProductId    = Convert.ToInt32(!String.IsNullOrEmpty(itemDataRow[5].ToString()) ? itemDataRow[5] : 0);
            productPriceVM.Id           = Convert.ToInt32(!String.IsNullOrEmpty(itemDataRow[6].ToString()) ? itemDataRow[6] : 0);
            return(productPriceVM);
        }
        //获得所有现货商品最近更新价格信息,,,,更改为mongo后,弃用了.
        //public List<ProductPriceVM> GetAllMarketLastPrice()
        public Dictionary <int, ProductPriceVM> GetAllMarketLastPrice()
        {
            //var listOrder = new List<ProductPriceVM>();
            var listDic = new Dictionary <int, ProductPriceVM>();

            using (var ctx = new ShtxSms2008Entities())
            {//ctx
                //inner join
                var listPrice = from f in
                                (from p in ctx.Prices
                                 where !ctx.Prices.Any(es => (es.MarketID == p.MarketID) && (es.ProductID == p.ProductID) && (es.AddDate > p.AddDate))
                                 orderby p.AddDate descending
                                 select p)
                                join dist in ctx.SmsProducts on new { mid = (int)f.MarketID, pid = (int)f.ProductID } equals new { mid = (int)dist.MarketId, pid = dist.ProductId }
                select new
                {
                    dist.ProductName,
                    dist.SName,
                    f.ProductID,
                    f.LPrice,
                    f.HPrice,
                    f.APrice,
                    f.AddDate,
                    f.PriceChange,
                    f.MarketID
                };

                //IEnumerable<IGrouping<int?, ProductPriceVM>> grouplist = listPrice.ToList().GroupBy(c => c.MarketID);
                //var g_Mapid = new Dictionary<int, int>();
                foreach (var product in listPrice)
                {
                    if (!listDic.ContainsKey((int)product.MarketID))
                    {
                        var vm = new ProductPriceVM
                        {
                            ProductId   = (int)product.ProductID,
                            ProductName = product.ProductName,
                        };
                        vm.AddDate  = (DateTime)product.AddDate;
                        vm.LPrice   = product.LPrice;
                        vm.HPrice   = product.HPrice;
                        vm.Change   = product.PriceChange;
                        vm.MarketID = (int)product.MarketID;
                        listDic.Add((int)product.MarketID, vm);
                        //listOrder.Add(vm);
                    }
                }

                return(listDic);
            }//ctx
        }
Ejemplo n.º 8
0
        public int ManageProductPriceMap(ProductPriceVM priceInformations)
        {
            SqlConnection connection = dbInstance.GetDBConnection();
            SqlCommand    cmd        = new SqlCommand("Manage_ProductPriceMappingData", connection);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@ProductPriceMappingData", JsonConvert.SerializeObject(priceInformations));
            SqlParameter RuturnValue = new SqlParameter("@Id", SqlDbType.Int);

            RuturnValue.Direction = ParameterDirection.Output;
            cmd.Parameters.Add(RuturnValue);
            cmd.ExecuteNonQuery();
            return((int)cmd.Parameters["@Id"].Value);
        }
        public List <ProductPriceVM> GetPricesByMobileAndMarketId(string mobile, int marketId)
        {
            var listOrder = new List <ProductPriceVM>();

            using (var ctx = new ShtxSms2008Entities())
            {
                CustomerBase cb = ctx.CustomerBases.FirstOrDefault(o => o.Tel.Contains(mobile) && o.SendInterFace == 102);
                if (cb != null)
                {
                    mobile = cb.Tel;
                    //change://
                    //var products = ctx.SmsProducts.Where(o => o.MarketId == marketId).OrderBy(p => p.DisplayOrder).ToList();
                    var products = CacheService.GetProductByMarketId(marketId).OrderBy(p => p.DisplayOrder).ToList();
                    var orderIds = ctx.Gps.Where(o => o.Tel == mobile && o.MarketID == marketId).Select(o => o.ProductID.Value).ToList();
                    foreach (var product in products)
                    {
                        var vm = new ProductPriceVM
                        {
                            ProductId   = product.ProductId,
                            ProductName = product.ProductName,
                            ParentName  = product.parentName,
                            Comment     = product.comment,
                            Spec        = product.spec
                        };
                        if (orderIds.Contains(product.ProductId))
                        {
                            vm.IsOrder = "YES";
                        }
                        else
                        {
                            vm.IsOrder = "NO";
                        }
                        //mongo:
                        //Price price = ctx.Prices.OrderByDescending(o => o.AddDate).FirstOrDefault(o => o.ProductID == product.ProductId);
                        Price price = MongoDBService.GetLastPricesByProductId(product.ProductId);
                        if (price != null)
                        {
                            vm.LPrice  = price.LPrice;
                            vm.HPrice  = string.IsNullOrEmpty(price.HPrice) ? price.LPrice : price.HPrice;
                            vm.Date    = price.AddDate.Value.ToString("yyyy-MM-dd");
                            vm.Change  = CommonService.ChangePrice(price.PriceChange);
                            vm.AddDate = price.AddDate.Value;
                            listOrder.Add(vm);
                        }
                    }
                }
                return(listOrder);
            }
        }
        public List <ProductPriceVM> GetHistoryPrices(int productId, DateTime start, DateTime end)
        {
            var list = new List <ProductPriceVM>();

            //mongo:
            //去mongo里取该productId对应的相应日期里的所有价格信息,下边代码为改进的,注释的是原来的代码
            var prices = MongoDBService.GetHostoryPrices(productId, start, end);

            while (start <= end)
            {
                DateTime endTime = start.AddDays(1);

                var price = prices.Where(o => o.ProductID == productId && o.AddDate < endTime && o.AddDate >= start).OrderByDescending(o => o.AddDate).FirstOrDefault();
                if (price != null && (!string.IsNullOrEmpty(price.LPrice) || !string.IsNullOrEmpty(price.HPrice)))
                {
                    ProductPriceVM vm = new ProductPriceVM();
                    vm.Date   = start.ToString("yyyy-MM-dd");
                    vm.HPrice = string.IsNullOrEmpty(price.HPrice) ? price.LPrice : price.HPrice;
                    vm.LPrice = string.IsNullOrEmpty(price.LPrice) ? price.HPrice : price.LPrice;
                    vm.Change = CommonService.ChangePrice(price.PriceChange);
                    list.Add(vm);
                }

                start = start.AddDays(1);
            }


            //using (var ctx = new ShtxSms2008Entities())
            //{
            //    while (start <= end)
            //    {
            //        DateTime endTime = start.AddDays(1);

            //        var price = ctx.Prices.Where(o => (o.ProductID ?? 0) == productId && o.AddDate < endTime && o.AddDate >= start).OrderByDescending(o => o.AddDate).FirstOrDefault();
            //        if (price != null && (!string.IsNullOrEmpty(price.LPrice) || !string.IsNullOrEmpty(price.HPrice)))
            //        {
            //            ProductPriceVM vm = new ProductPriceVM();
            //            vm.Date = start.ToString("yyyy-MM-dd");
            //            vm.HPrice = string.IsNullOrEmpty(price.HPrice) ? price.LPrice : price.HPrice;
            //            vm.LPrice = string.IsNullOrEmpty(price.LPrice) ? price.HPrice : price.LPrice;
            //            vm.Change = CommonService.ChangePrice(price.PriceChange);
            //            list.Add(vm);
            //        }
            //        start = start.AddDays(1);
            //    }
            //}
            return(list.OrderByDescending(o => o.Date).ToList());
        }
Ejemplo n.º 11
0
 public override void OnSelectedItemChanged()
 {
     if (IsAutoUpdateEnable == true)
     {
         InEditItem = SelectedItem;
         try
         {
             if (selectedItem.Id != selectedItemBeforeChange.Id)
             {
                 ProductPriceVM.GetPricesOfProduct(selectedItem);
             }
         }
         catch
         {
             ProductPriceVM.GetPricesOfProduct(selectedItem);
         }
         GoodsReceiptVM.ReceiptDetailVM.OnSelectedProductChanged(SelectedItem);
     }
 }
        private void SetDataToPriceForm(ProductPriceVM product)
        {
            decimal finalPrice;

            using (CommonServiceBLL common = new CommonServiceBLL())
            {
                finalPrice = common.GetDiscountedPrice(product.Price, product.Discount);
            }
            ProductVM selectedProduct = this.products.Find(pro => pro.Id == product.ProductId);

            if (selectedProduct != null)
            {
                this.txtPrice.Text      = product.Price.ToString();
                this.txtDiscount.Text   = product.Discount.ToString();
                this.lblFinalPrice.Text = finalPrice.ToString();
                this.cmbSelectCategory.SelectedIndex = selectedProduct.mpt_CategoryEnum - 1;
                this.cmbSelectProduct.SelectedItem   = selectedProduct;
                this.cmbSelectSize.DataSource        = this.SizeList.Where(s => s.Data == product.mpt_SizeEnum).ToList();
                this.cmbSelectSize.SelectedIndex     = 0;
            }
            this.PriceFormFieldValidation();
        }
Ejemplo n.º 13
0
        public List <SearchPriceVM> GetSearchResult(string key, string mobile)
        {
            var        list        = new List <SearchPriceVM>();
            List <int> xhmarketIds = new List <int>();

            using (var ctx = new ShtxSms2008Entities())
            {
                //change://
                //var groups = ctx.XHMarketGroups.Where(o => o.Flag == 1 && o.IsForApp).Select(o => o.GroupID).ToList();
                var          groups = CacheService.GetMarketGroupForApp(1).Select(o => o.GroupID).ToList();
                CustomerBase cb     = ctx.CustomerBases.FirstOrDefault(o => o.Tel.Contains(mobile) && o.SendInterFace == 102);
                if (cb != null)
                {
                    mobile = cb.Tel;
                    var orderIds = ctx.Gps.Where(o => o.Tel == mobile).Select(o => o.ProductID.Value).ToList();
                    foreach (var group in groups)
                    {
                        //change://
                        //xhmarketIds.AddRange(ctx.Markets.Where(o => o.GroupID == group).Select(o => o.MarketId));
                        xhmarketIds.AddRange(CacheService.GetMarketByGroupId(group).Select(o => o.MarketId));
                    }

                    var result = ctx.SmsProducts.Where(o => o.ProductName.Contains(key) && xhmarketIds.Contains(o.MarketId.Value))
                                 .Select(o => new searchProduct {
                        MarketId = o.MarketId.Value, ProductId = o.ProductId, ProductName = o.ProductName, Comment = o.comment
                    }).ToList();

                    var markets = result.Select(o => o.MarketId).Distinct();

                    foreach (var market in markets)
                    {
                        var m = ctx.Markets.FirstOrDefault(o => o.MarketId == market);
                        if (m != null)
                        {
                            SearchPriceVM priceVm = new SearchPriceVM();
                            priceVm.MarketId   = m.MarketId;
                            priceVm.MarketName = m.MarketName;
                            priceVm.prices     = new List <ProductPriceVM>();

                            var productList = result.Where(o => o.MarketId == market);
                            foreach (var product in productList)
                            {
                                var vm = new ProductPriceVM
                                {
                                    ProductId   = product.ProductId,
                                    ProductName = product.ProductName,
                                    Comment     = product.Comment
                                };
                                if (orderIds.Contains(product.ProductId))
                                {
                                    vm.IsOrder = "YES";
                                }
                                else
                                {
                                    vm.IsOrder = "NO";
                                }
                                //mongo:
                                //Price price = ctx.Prices.OrderByDescending(o => o.AddDate).FirstOrDefault(o => o.ProductID == product.ProductId);
                                Price price = MongoDBService.GetLastPricesByProductId(product.ProductId);
                                if (price != null)
                                {
                                    vm.LPrice  = price.LPrice;
                                    vm.HPrice  = string.IsNullOrEmpty(price.HPrice) ? price.LPrice : price.HPrice;
                                    vm.Date    = price.AddDate.Value.ToString("yyyy-MM-dd");
                                    vm.Change  = CommonService.ChangePrice(price.PriceChange);
                                    vm.AddDate = price.AddDate.Value;
                                    priceVm.prices.Add(vm);
                                }
                            }
                            if (priceVm.prices.Count > 0)
                            {
                                list.Add(priceVm);
                            }
                        }
                    }
                }
            }
            return(list);
        }