コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("ID,ProductID,CategoryID,BrandID,ProductName,ProductImage,ProductWeight,ProductPrice,ProductStock,ProductSale")] CommodityManage commodityManage)
        {
            if (id != commodityManage.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(commodityManage);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CommodityManageExists(commodityManage.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(commodityManage));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("ID,ProductID,CategoryID,BrandID,ProductName,ProductImage,ProductWeight,ProductPrice,ProductStock,ProductSale")] CommodityManage commodityManage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(commodityManage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(commodityManage));
        }
コード例 #3
0
        public async Task <ActionResult <List <ProductResultModel> > > ProductAsync(string DeviceName, float ProductWeight, string PictureResult)
        {
            List <ProductResultModel> productResult = new List <ProductResultModel>();
            //Dictionary<string, int> dict_1 = JsonConvert.DeserializeObject<Dictionary<string, int>>(PictureResult);
            JObject dict_2 = (JObject)JsonConvert.DeserializeObject(PictureResult);

            System.Diagnostics.Debug.WriteLine(dict_2);
            float temp_weight = 0;
            IEnumerable <JProperty> properties = dict_2.Properties();

            foreach (JProperty item in properties)
            {
                CommodityManage product_info = await _context.CommodityManage.FirstOrDefaultAsync(m => m.ProductID == product_dict[item.Name]);

                ProductResultModel temp = new ProductResultModel(product_dict[item.Name], product_info.ProductName, product_info.ProductImage, Convert.ToSingle(product_info.ProductPrice), (int)item.Value);
                productResult.Add(temp);
                temp_weight += Convert.ToSingle(product_info.ProductWeight) * (int)item.Value;
            }
            float abs_weight_gap = Math.Abs(temp_weight - ProductWeight);

            if (temp_weight > ProductWeight)
            {
                if (abs_weight_gap < 0.5 * temp_weight)
                {
                    return(productResult);
                }
                else
                {
                    return(productResult);
                }
            }
            else
            {
                if (abs_weight_gap < 0.5 * temp_weight)
                {
                    return(productResult);
                }
                else
                {
                    int j = 1;
                    for (int i = (int)(-0.05 * (int)ProductWeight); i < 0.05 * (int)ProductWeight; i++)
                    {
                        IList <IList <int> > res            = new List <IList <int> >();
                        Compute_weight       compute_Weight = new Compute_weight();
                        res = compute_Weight.CombinationSum2(gap_weight, (int)ProductWeight + i - (int)temp_weight);
                        foreach (var item in res)
                        {
                            System.Diagnostics.Debug.WriteLine("重量可能的组合结果{0}:", j);
                            foreach (var item_2 in item)
                            {
                                System.Diagnostics.Debug.WriteLine(item_2);
                                CommodityManage product_info_2 = await _context.CommodityManage.FirstOrDefaultAsync(m => m.ProductID == product_dict_weight[item_2]);

                                ProductResultModel temp_2 = new ProductResultModel(product_dict_weight[item_2], product_info_2.ProductName, product_info_2.ProductImage, Convert.ToSingle(product_info_2.ProductPrice), item.Count(t => t == item_2));
                                productResult.Add(temp_2);
                            }
                            j++;
                        }
                    }


                    return(productResult);
                }
            }



            //return $"设备名:{DeviceName},重量:{ProductWeight},图片结果:{dict_2}";
            //return await _context.CommodityManage.ToListAsync();
        }