Пример #1
0
        /// <summary>
        /// 更新一条是数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        private int Update(ResourceDetailEntity info)
        {
            try
            {
                //先删除原来的主表数据
                ResourceDetailManager bll = new ResourceDetailManager();
                bll.Delete(info.Id);
                //增加新的数据到主表
                //bll.Add(info);
                //修改剩余的原来的数据
                ResourceUploadBussiness resourceUpload = new ResourceUploadBussiness();
                DataTable dtUpload = resourceUpload.GetInfosByDetailId(info.Id);
                bll.DeleteUpload(0, info.Id);

                ResourceDetailUploadEntity detailEntity = new ResourceDetailUploadEntity();

                int id = bll.Add(info);
                if (dtUpload != null)
                {
                    foreach (DataRow dataRow in dtUpload.Rows)
                    {
                        detailEntity.Files_name         = CommonDBCheck.ToString(dataRow["files_name"]);
                        detailEntity.FilesDir           = CommonDBCheck.ToString(dataRow["files_dir"]);
                        detailEntity.Resource_detail_id = id;
                        resourceUpload.Add(detailEntity);
                    }
                }
                return(id);
            }
            catch (Exception e)
            {
                throw;
            }
        }
        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");
            }
        }