コード例 #1
0
ファイル: UpLoadPage.ashx.cs プロジェクト: wenlei456/CPCAR
        public void ProcessRequest(HttpContext context)
        {
            // -999
            context.Response.ContentType = "text/plain";
            HttpPostedFile file = context.Request.Files["FileData"];

            string tid = HttpUtility.HtmlEncode(context.Request.QueryString["pid"]);

            if (file != null)
            {
                string path  = context.Request["folder"] + "/Porduct/" + string.Format("{0:yyyyMMdd}", DateTime.Now) + "/";
                string apath = context.Request["folder"] + "/" + string.Format("{0:yyyyMMdd}", DateTime.Now) + "/";
                string uploadpath;
                if (tid == "-999")
                {
                    uploadpath = context.Server.MapPath(apath);
                }
                else
                {
                    uploadpath = context.Server.MapPath(path);
                }
                if (!Directory.Exists(uploadpath))
                {
                    Directory.CreateDirectory(uploadpath);
                }
                string fileNew = CreateRandomCode(22) + file.FileName.Substring(file.FileName.LastIndexOf("."));//  file.FileName;

                if (tid == "-999")
                {
                    DAO.ActiveImg img = new DAO.ActiveImg();
                    img.ActiveID   = -1;
                    img.ImgPath    = apath + fileNew;
                    img.Status     = 1;
                    img.UploadDate = DateTime.Now;
                    abll.AddActiveImg(img);
                }
                else
                {
                    DAO.ImgStock img = new DAO.ImgStock();
                    img.ImgPath    = path + fileNew;
                    img.PartID     = int.Parse(tid);
                    img.UploadDate = DateTime.Now;
                    bll.Add(img);
                }
                //DownRes upfiles = new DownRes();
                //upfiles.DT = Convert.ToInt32(tid);
                //upfiles.FileName = fileNew;
                //upfiles.FileSize = GetSize(file.ContentLength) ;
                //upfiles.UpDate = DateTime.Now;
                //upfiles.Add();
                file.SaveAs(uploadpath + fileNew);

                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }
        }
コード例 #2
0
        public bool AddActiveImg(DAO.ActiveImg m)
        {
            db.ActiveImg.Add(m);
            int i = db.SaveChanges();

            if (i > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }