Пример #1
0
 public SpecificationToRun(spec specification, string reason, Exception exception, MemberInfo foundOn)
 {
     FoundOn       = foundOn;
     Specification = specification;
     Exception     = exception;
     Reason        = reason;
     IsRunnable    = false;
 }
Пример #2
0
 public SpecificationToRun(spec specification, MemberInfo foundOn)
 {
     IsRunnable    = true;
     Reason        = "";
     Exception     = null;
     Specification = specification;
     FoundOn       = foundOn;
 }
Пример #3
0
        async public Task <IActionResult> get_specification_id()
        {
            string ram    = (HttpContext.Request.Query["ram"]);
            string screen = (HttpContext.Request.Query["screen"]);
            string conn   = (HttpContext.Request.Query["connec"]);
            string stor   = (HttpContext.Request.Query["storage"]);
            await Db.Connection.OpenAsync();

            var result = new spec(Db);
            var data   = await result.getSpecificationId(ram, screen, conn, stor);

            return(new OkObjectResult(data));
        }
Пример #4
0
        public Spec(spec spec)
        {
            this.id = spec.id;
            List <SpecDetail> sd = new List <SpecDetail>();

            foreach (specdetail sds in spec.specdetails)

            {
                sd.Add(new SpecDetail(sds));
            }

            this.specdetails = sd;
        }
Пример #5
0
        private FilesStatus upload(Stream inputStream, string fileName, HttpContext context)
        {
            var statu = new FilesStatus();

            var filename     = RIPP.Web.Chem.Tools.Common.GetRnd(10, true, true, false) + Path.GetExtension(fileName);
            var tempfullName = Path.Combine(StorageRoot, filename);

            statu.progress = "1.0";
            statu.size     = (int)inputStream.Length;
            statu.name     = fileName;
            try
            {
                //先保存在服务器一个临时文件
                using (var fs = new FileStream(tempfullName, FileMode.Append, FileAccess.Write))
                {
                    var buffer = new byte[1024];
                    var l      = inputStream.Read(buffer, 0, 1024);
                    while (l > 0)
                    {
                        fs.Write(buffer, 0, l);
                        l = inputStream.Read(buffer, 0, 1024);
                    }
                    fs.Flush();
                    fs.Close();
                }
            }
            catch
            {
                statu.error = "服务器错误,上传文件失败!";
                return(statu);
            }

            //根据文件后缀尝试打开文件
            var   ftype   = BindModel.CheckType(tempfullName);
            model dbmodel = new model();
            spec  sp      = new spec();

            try
            {
                statu.type   = ftype.GetDescription();
                dbmodel.path = Path.Combine(RIPP.Web.Chem.Tools.Common.GetUploadPath(), filename);
                sp.path      = dbmodel.path;
                switch (ftype)
                {
                case FileExtensionEnum.Allmethods:
                    var mBind = BindModel.ReadModel <BindModel>(tempfullName);
                    statu.description  = mBind.ToString();
                    dbmodel.createtime = mBind.CreateTime;
                    dbmodel.name       = mBind.Name;
                    // ;
                    // dbmodel.type = (int)ftype;
                    //  dbmodel.
                    break;

                case FileExtensionEnum.PLSBind:
                    var mPLS = BindModel.ReadModel <PLSModel>(tempfullName);
                    statu.description  = mPLS.ToString();
                    dbmodel.createtime = mPLS.CreateTime;
                    dbmodel.name       = mPLS.Name;
                    break;

                case FileExtensionEnum.IdLib:
                    var mId = BindModel.ReadModel <IdentifyModel>(tempfullName);
                    statu.description  = mId.ToString();
                    dbmodel.createtime = mId.CreateTime;
                    dbmodel.name       = mId.Name;
                    break;

                case FileExtensionEnum.FitLib:
                    var mFitting = BindModel.ReadModel <FittingModel>(tempfullName);
                    statu.description  = mFitting.ToString();
                    dbmodel.createtime = mFitting.CreateTime;
                    dbmodel.name       = mFitting.Name;
                    break;

                case FileExtensionEnum.PLS1:
                case FileExtensionEnum.PLSANN:
                    var mPLS1 = BindModel.ReadModel <PLSSubModel>(tempfullName);
                    statu.description  = mPLS1.ToString();
                    dbmodel.createtime = mPLS1.CreateTime;
                    dbmodel.name       = mPLS1.Name;
                    break;

                case FileExtensionEnum.ItgBind:
                    var itgSub = BindModel.ReadModel <IntegrateModel>(tempfullName);
                    statu.description  = itgSub.ToString();
                    dbmodel.createtime = itgSub.CreateTime;
                    dbmodel.name       = itgSub.Name;
                    break;

                case FileExtensionEnum.Spec:
                default:
                    var s = new Spectrum(tempfullName);
                    ftype             = FileExtensionEnum.Spec;
                    sp.Spec           = s;
                    sp.name           = Path.GetFileName(fileName);
                    statu.description = "光谱文件";
                    break;
                }
            }
            catch (Exception ex)//读取文件失败
            {
                statu.error = "上传的文件类型有误,服务器无法识别,上传文件失败!";

                if (File.Exists(tempfullName))
                {
                    File.Delete(tempfullName);
                }
                return(statu);
            }


            //根据文件类型保存数据库
            using (var db = new RIPPWebEntities())
            {
                if (ftype != FileExtensionEnum.Unkown)
                {
                    var user = RIPP.Web.Chem.Tools.Common.Get_User;
                    if (user == null)
                    {
                        var uid = Convert.ToInt32(context.Request["uid"]);
                        user = db.S_User.Where(d => d.ID == uid).FirstOrDefault();
                    }

                    if (ftype == FileExtensionEnum.Spec)//光谱
                    {
                        if (RIPP.Web.Chem.Tools.Common.UserCanPredict(user))
                        {
                            sp.addtime = DateTime.Now;
                            sp.ext     = Path.GetExtension(fileName).Substring(1);
                            sp.uid     = user.ID;
                            sp.gid     = user.GroupID;
                            db.spec.Add(sp);
                            db.SaveChanges();
                            statu.deleteType = "DELETE";
                            statu.deleteUrl  = "/upload/UploadHandler.ashx?t=s&id=" + sp.id;
                            statu.url        = "/admin/spec/detail/" + sp.id;
                            statu.id         = sp.id;

                            File.Move(tempfullName, Path.Combine(HttpContext.Current.Server.MapPath("~/"), sp.path));//移动刚才上传的临时文件
                        }
                        else
                        {
                            statu.error = "您无权上传光谱文件,请与管理员联系。";
                            if (File.Exists(tempfullName))
                            {
                                File.Delete(tempfullName);
                            }
                        }
                    }
                    else//模型
                    {
                        if (user.HasRole(RoleEnum.Administrator) || user.HasRole(RoleEnum.Engineer))
                        {
                            dbmodel.addtime = DateTime.Now;
                            dbmodel.type    = (int)ftype;
                            dbmodel.uid     = user.ID;
                            dbmodel.gid     = user.GroupID;
                            db.model.Add(dbmodel);
                            db.SaveChanges();
                            statu.deleteType = "DELETE";
                            statu.deleteUrl  = "/upload/UploadHandler.ashx?t=m&id=" + dbmodel.id;
                            statu.url        = "/admin/model/detail/" + dbmodel.id;
                            statu.id         = dbmodel.id;
                            File.Move(tempfullName, Path.Combine(HttpContext.Current.Server.MapPath("~/"), dbmodel.path));//移动刚才上传的临时文件
                        }
                        else
                        {
                            statu.error = "您无权上传模型文件,请与管理员联系。";
                            if (File.Exists(tempfullName))
                            {
                                File.Delete(tempfullName);
                            }
                        }
                    }
                }
            }

            return(statu);
        }
Пример #6
0
        // GET: ProductDetail
        public ActionResult ProductDetail(int id)
        {
            product product = db.products.Find(id);

            if (product != null)
            {
                ICollection <productdetail> productdetails    = product.productdetails;
                List <productdetail>        listProductDetail = new List <productdetail>();
                List <voucher> listVoucher = product.vouchers1.ToList();
                ViewBag.listVoucher = listVoucher;

                if (product.category.parentId == 1)
                {
                    HashSet <spec> specs = new HashSet <spec>();
                    HashSet <spec> got   = new HashSet <spec>();


                    foreach (productdetail pd in productdetails)
                    {
                        Console.WriteLine("PD: " + pd.color.name + " " + pd.price);
                        if (!got.Contains(pd.spec))
                        {
                            pd.spec.getValueByName("Bộ nhớ trong");
                            pd.spec.GotPriceMin = this.getMinValue(pd.spec.id);
                            Console.WriteLine("Capa" + pd.spec.GotValue);
                            specs.Add(pd.spec);
                        }
                        got.Add(pd.spec);
                        listProductDetail.Add(pd);
                    }

                    //lay spec cua capacity nho nhat
                    spec spec = listProductDetail[0].spec;
                    for (int i = 1; i < listProductDetail.Count; i++)
                    {
                        if (int.Parse(spec.GotValue) > int.Parse(listProductDetail[i].spec.GotValue))
                        {
                            spec = listProductDetail[i].spec;
                        }
                    }

                    // lay tat ca product detail theo cai spec do
                    List <productdetail> productdetailsBySpec = new List <productdetail>();
                    foreach (productdetail pd in listProductDetail)
                    {
                        if (pd.spec.id == spec.id)
                        {
                            productdetailsBySpec.Add(pd);
                        }
                    }

                    // ban đầu khi hiển thị trang detail, sẽ chọn Product detail có capacity nhỏ nhất đầu tiên(phải còn hàng)
                    int firstPDId = 0;
                    foreach (productdetail pd in productdetailsBySpec)
                    {
                        if (checkProductInStorage(pd.id) > 0)
                        {
                            firstPDId = pd.id;
                            break;
                        }
                    }



                    ViewBag.firstPDId   = firstPDId;
                    ViewBag.firstSpecId = spec.id;
                    List <spec> listSpec = specs.ToList();
                    listSpec.Sort();
                    ViewBag.specs          = listSpec;
                    ViewBag.productdetails = productdetails.ToList();
                    ViewBag.product        = product;
                    ViewBag.Comment        = productDAO.comments();


                    System.Diagnostics.Debug.WriteLine("ccc");
                    foreach (voucher v in listVoucher)
                    {
                        System.Diagnostics.Debug.WriteLine("kkk" + v.name);
                    }
                    return(PartialView("~/Views/ProductDetail/ProductDetail.cshtml"));
                }
                else
                {
                    int firstPDId = 0;
                    int status    = 0;
                    foreach (productdetail pd in productdetails)
                    {
                        if (checkProductInStorage(pd.id) > 0)
                        {
                            status    = 1;
                            pd.status = status;
                            firstPDId = pd.id;
                            break;
                        }
                    }
                    ViewBag.productdetails = productdetails.ToList();
                    ViewBag.product        = product;
                    ViewBag.firstPDId      = firstPDId;

                    return(PartialView("~/Views/ProductDetail/AccessoryDetail.cshtml"));
                }
            }



            return(PartialView("~/Views/ProductDetail/AccessoryDetail.cshtml"));
        }
Пример #7
0
        public ActionResult Add([Bind(Include = "id,activeFlag,createDate,updateDate")] productdetail productdetail, int productId, int colorId, decimal price, HttpPostedFileBase imgUrl)
        {
            string fileName = System.IO.Path.GetFileName(imgUrl.FileName);
            String date     = DateTime.Now.ToString();

            System.Diagnostics.Debug.WriteLine("date " + date);
            string urlImage = Server.MapPath("~/Content/client/img/product/" + fileName);

            imgUrl.SaveAs(urlImage);
            productdetail.imgUrl = fileName;
            int countSpec = Convert.ToInt32(Request.Form["countSpec"]);

            System.Diagnostics.Debug.WriteLine("product id " + productId);
            System.Diagnostics.Debug.WriteLine("color id " + colorId);
            System.Diagnostics.Debug.WriteLine("price " + price);
            System.Diagnostics.Debug.WriteLine("file name " + fileName);

            System.Diagnostics.Debug.WriteLine("count " + countSpec);

            spec spec = new spec();

            spec.activeFlag = 1;
            spec.createDate = DateTime.Now;
            spec.updateDate = DateTime.Now;
            db.specs.Add(spec);
            db.SaveChanges();

            for (int i = 0; i < countSpec; i++)
            {
                specdetail sd = new specdetail();
                sd.spec = db.specs.Find(spec.id);
                String paramName  = "name_" + i;
                String paramValue = "value_" + i;
                String name       = Convert.ToString(Request.Form[paramName]);
                String value      = Convert.ToString(Request.Form[paramValue]);

                sd.name       = name;
                sd.value      = value;
                sd.activeFlag = 1;
                sd.createDate = DateTime.Now;
                sd.updateDate = DateTime.Now;

                db.specdetails.Add(sd);
                db.SaveChanges();
            }


            productdetail.product    = db.products.Find(productId);
            productdetail.spec       = db.specs.Find(spec.id);
            productdetail.color      = db.colors.Find(colorId);
            productdetail.price      = price;
            productdetail.activeFlag = 1;
            productdetail.createDate = DateTime.Now;
            productdetail.updateDate = DateTime.Now;

            db.productdetails.Add(productdetail);
            db.SaveChanges();


            return(RedirectToAction("productDetailList", "AdminProductDetail", new { productId = productId }));
        }