Exemple #1
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                context.Response.ContentType = "text/plain";
                string mode = context.Request["mode"].ToLower();


                ResourceTypeManager typeManager = new ResourceTypeManager();
                //ResourceDetailEntity entity=new ResourceDetailEntity();
                string dir  = context.Request["dir"];
                string name = context.Request["name"];
                string peo  = context.Request["peo"];
                string memo = context.Request["memo"];
                string id   = context.Request["id"];
                ResourceDetailEntity entity = new ResourceDetailEntity();
                entity.Memo = memo;
                entity.Name = name;
                entity.Type = new SpareResourceTypeEntity()
                {
                    Id        = CommonDBCheck.ToInt(dir),
                    Name      = typeManager.GetInfo(CommonDBCheck.ToInt(dir)).Name,
                    Directory = typeManager.GetInfo(CommonDBCheck.ToInt(dir)).Directory
                };

                entity.UploadPeople = peo;
                entity.Url          = ConfigurationSettings.AppSettings["UploadFilePath"];
                entity.insert_user  = entity.update_user = context.Session["user"] as UserEntity;

                switch (mode)
                {
                case "add":
                    context.Response.Write(Add(entity));
                    break;

                case "update":
                    entity.Id = CommonDBCheck.ToInt(id);
                    context.Response.Write(Update(entity));
                    break;
                }
            }
            catch (Exception e)
            {
                context.Response.Write("error");
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Charset     = "utf-8";

            HttpPostedFile file = context.Request.Files["Filedata"];
            string         id   = context.Request["id"];
            string         dir  = context.Request["dir"];
            string         name = context.Request["name"];
            string         peo  = context.Request["peo"];


            ResourceTypeManager typeManager = new ResourceTypeManager();

            string uploadPath = HttpContext.Current.Server.MapPath(ConfigurationSettings.AppSettings["UploadFilePath"] + typeManager.GetInfo(CommonDBCheck.ToInt(dir)).Directory + "/");

            // HttpContext.Current.Server.MapPath(@context.Request["folder"]) + "\\";

            if (file != null)
            {
                if (!Directory.Exists(uploadPath))
                {
                    Directory.CreateDirectory(uploadPath);
                }
                string fileName = file.FileName.Substring(0, file.FileName.IndexOf('.')) + "_" + name + "_" + peo + "_" +
                                  DateTime.Now.ToString("yyyyMMddHHmmssfff") +
                                  file.FileName.Substring(file.FileName.IndexOf('.'), file.FileName.Length - file.FileName.IndexOf('.'));
                file.SaveAs(uploadPath + fileName);
                //下面这句代码缺少的话,上传成功后上传队列的显示不会自动消失
                ResourceDetailUploadEntity uploadEntity = new ResourceDetailUploadEntity();
                uploadEntity.Resource_detail_id = CommonDBCheck.ToInt(id);
                uploadEntity.Files_name         = fileName;
                uploadEntity.FilesDir           = typeManager.GetInfo(CommonDBCheck.ToInt(dir)).Directory;
                ResourceUploadBussiness uploadBussiness = new ResourceUploadBussiness();
                uploadBussiness.Add(uploadEntity);
                context.Response.Write("1");
            }
            else
            {
                context.Response.Write("0");
            }
        }