Beispiel #1
0
 /// <summary>
 /// 修改数据到表TblCommodity
 /// </summary>
 /// <param name="name" Commodity的U_nam名字</param>
 /// <param name="commodity">更新成的表</param>
 public bool UpdataCommoditys(string id, Commodity commodity, string path)
 {
     using (WarehouseERPDAL dB = new WarehouseERPDAL())
     {
         try
         {
             var model = dB.commoditys.Where(c => c.Co_Id.ToString() == id).FirstOrDefault();
             if (model != null && !model.Equals(new Commodity()))
             {
                 BarCode barCode = new BarCode();
                 if (model.Co_bar_code != commodity.Co_bar_code)
                 {
                     barCode.DeleteFile(path + model.Co_bar_code + ".jdg");
                     barCode.Code(commodity.Co_bar_code, path);
                 }
                 Change(ref model, commodity);
             }
             dB.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
        public ActionResult searchAttrbutetes(string Select, string name, string BtnSubmit, int?page)
        {
            if (BtnSubmit != "Attributes")
            {
                RedirectToAction("view");
            }
            if (name == null || name == "")
            {
                return(RedirectToAction("Attributes"));
            }
            //如果BtnSubmit是触发的搜索按键
            AttributesViewModel attributesViewModel = new AttributesViewModel();

            attributesViewModel.IsSearch = true;
            attributesViewModel.UserName = Session["User"].ToString();//继承的,显示右边的用户名

            CommodityBusinessLayer commodityBusinessLayer = new CommodityBusinessLayer();

            //第几页
            int pageNumber = page ?? 1;
            //每页显示多少条
            int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);

            //attributesViewModel.commodities = commodityBusinessLayer.GetCommodity(Select, name).ToPagedList(pageNumber, pageSize);
            List <Commodity>         commodities        = commodityBusinessLayer.GetCommodity(Select, name);
            List <CommPathViewModel> commPathViewModels = new List <CommPathViewModel>();
            string path;

            foreach (var com in commodities)
            {
                path = Server.MapPath("/image/");
                if (!System.IO.File.Exists(path))
                {
                    //如果不存在这个文件,则创建
                    BarCode barCode = new BarCode();
                    barCode.Code(com.Co_bar_code, path);
                }
                commPathViewModels.Add(new CommPathViewModel()
                {
                    commodity = com, path = "/image/" + com.Co_bar_code + ".jpg"
                });
            }
            attributesViewModel.commPathViewModels = commPathViewModels.ToPagedList(pageNumber, pageSize);

            attributesViewModel.commoditie = new Commodity();

            return(View("Attributes", attributesViewModel));
        }
Beispiel #3
0
        /// <summary>
        /// 插入数据到表Tbl Commodity
        /// </summary>
        /// <param name="commodity">插入的数据</param>
        /// <returns></returns>
        public bool InsertCommodity(Commodity commodity, string path)
        {
            //dB.commoditys.Add(commodity);
            //dB.SaveChanges();
            //return commodity;
            using (WarehouseERPDAL dB = new WarehouseERPDAL())
            {
                try
                {
                    dB.commoditys.Add(commodity);
                    dB.SaveChanges();
                    BarCode barcode = new BarCode();
                    barcode.Code(commodity.Co_bar_code, path);

                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
        }
        //[HttpGet]
        public ActionResult Attributes(int?page)
        {
            AttributesViewModel attributesViewModel = new AttributesViewModel();

            attributesViewModel.IsSearch = false;
            attributesViewModel.UserName = Session["User"].ToString();

            CommodityBusinessLayer commodityBusinessLayer = new CommodityBusinessLayer();

            //第几页
            int pageNumber = page ?? 1;
            //每页显示多少条
            int pageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]);

            List <Commodity>         commodities        = commodityBusinessLayer.GetCommodity();
            List <CommPathViewModel> commPathViewModels = new List <CommPathViewModel>();
            string path;

            foreach (var com in commodities)
            {
                path = Server.MapPath("/image/");
                if (!System.IO.File.Exists(path))
                {
                    //如果不存在这个文件,则创建
                    BarCode barCode = new BarCode();
                    barCode.Code(com.Co_bar_code, path);
                }
                commPathViewModels.Add(new CommPathViewModel()
                {
                    commodity = com, path = "/image/" + com.Co_bar_code + ".jpg"
                });
            }
            attributesViewModel.commPathViewModels = commPathViewModels.ToPagedList(pageNumber, pageSize);
            //attributesViewModel.commodities = commodities.ToPagedList(pageNumber, pageSize);

            attributesViewModel.commoditie = new Commodity();

            return(View("Attributes", attributesViewModel));
        }