/// <summary> /// /// </summary> /// <param name="path">传入路径</param> /// <param name="keshi">科室</param> /// <param name="uid">样品源</param> /// <param name="date">日期</param> public string HandleImg(string path, string keshi, string uid, string date, ref string imgname) { string mes = ""; try { Bitmap map = new Bitmap(path); string savePathName = @"Consentimg\"; string savePath = Server.MapPath("~/Consentimg/"); //string[] geshi = this.idFile.FileName.Split('.'); string[] geshi = null; DateTime dt = Convert.ToDateTime(date); string Random = IntRandom(); imgname = keshi + "_" + uid + "-" + dt.ToString("yyyyMMdd") + "_" + Random + "." + geshi[1]; string strSaveImgpath = ""; string strhttpImgpath = "";//获取HTTP传入路径 //根据文件各级情况创建文档 if (RuRo.Common.Filehleper.DirFileHelper.IsExistDirectory(savePath))//必须传入绝对路径 { //使用委托把另外一个路径返回出来 strSaveImgpath = CreateFoloer(savePath, savePathName, dt, keshi, ref strhttpImgpath) + @"\" + imgname; } else { RuRo.Common.Filehleper.DirFileHelper.CreateDir(savePathName); strSaveImgpath = CreateFoloer(savePath, savePathName, dt, keshi, ref strhttpImgpath) + @"\" + imgname; } //map.Save(savePath); long quality = long.Parse(System.Configuration.ConfigurationManager.AppSettings["ImgQuality"]); Common.ImageHelper.ImageClass img = new Common.ImageHelper.ImageClass(); //判断图片是否存在于数据库中 Model.TB_IMGPATH imgModel = new Model.TB_IMGPATH(); imgModel.IMGNAME = imgname; imgModel.IMGPATH = mes; imgModel.KESHI = keshi; imgModel.DATE = Convert.ToDateTime(date); BLL.TB_IMGPATH imgbll = new BLL.TB_IMGPATH(); int count = imgbll.GetRecordCount("IMGNAME='" + imgname + "' and KESHI='" + keshi + "' and date='" + date + "'"); if (count > 0) { Response.Write("<script type='text/javascript'>alert('数据存在,请重新上传');</script>"); RuRo.Model.TB_SAMPLE_LOG log_model = new Model.TB_SAMPLE_LOG();//记录日志 log_model.MSG = "图片存在"; RuRo.BLL.TB_SAMPLE_LOG log_bll = new BLL.TB_SAMPLE_LOG(); log_bll.Add(log_model); } else { //压缩图片并保存 img.Compress(path, strSaveImgpath, map.Width, map.Height, quality); //map.Clone(); map.Dispose(); mes = strhttpImgpath + @"\" + imgname; //写入数据库 try { imgModel.IMGPATH = mes; imgbll.Add(imgModel); } catch (Exception ex) { RuRo.Model.TB_SAMPLE_LOG log_model = new Model.TB_SAMPLE_LOG();//记录日志 log_model.MSG = "添加图片错误:" + ex.ToString(); mes = ex.ToString(); RuRo.BLL.TB_SAMPLE_LOG log_bll = new BLL.TB_SAMPLE_LOG(); log_bll.Add(log_model); } } return mes; } catch (Exception ex) { mes = ex.ToString(); return mes; } }
//存放FTP的话把这个加到文件里面 //<add key="FTPFolder" value="192.168.1.101"/> //<add key="FTPFolder2" value="192.168.1.101:23"/> //<add key="FTPUser" value="admin"/> //<add key="FTPPWD" value="admin123"/> //<add key="FTPPort" value="23"/> public void ProcessRequest(HttpContext context) { //不知道为什么获取不到 //HttpPostedFile file = context.Request.Files["userFile"]; #region 获取基本参数 string filePath = context.Request["imgpath"]; string strUid = context.Request.Params["suid"].ToString(); string strName = context.Request.Params["spname"].ToString(); string strdate = context.Request.Params["timedate"].ToString(); string keshi = GetKeshi(); string strPy = keshicode(keshi);//将科室转化 Dictionary<string, string> dickeshi = new Dictionary<string, string>(); dickeshi.Add("keshi", keshi); dickeshi.Add("SP", strPy); //FileUpload myfile = new FileUpload(); HttpPostedFile myfile = context.Request.Files["imgpath"]; #endregion Dictionary<string, string> dicdata = new Dictionary<string, string>(); string path = @"Consentimg\"; myfile.SaveAs(path); RuRo.Common.Filehleper.DirFileHelper.CreateDir(path); string mes = ""; if (strUid == "" || strdate == "") { mes = "请检查日期是否选择"; context.Response.Write(mes); } else { #region 上传 try { #region 将图片保存到本地 生成编码 再判断是否存在 DateTime dt = new DateTime(); dt = Convert.ToDateTime(strdate); string date = dt.ToString("yyyyMMdd"); string fileName = Path.GetFileName(filePath); string[] SplitFileName = fileName.Split('.'); string mapPath = context.Server.MapPath("~"); string savePath = mapPath + @"\" + path + dickeshi["SP"].ToString() + "_" + strUid + "-" + date + "." + SplitFileName[1];//设置路径+(文件名称:path + strUid + date +"."+ SplitFileName[1]) string imgName = dickeshi["SP"].ToString() + "_" + strUid + "-" + date + "." + SplitFileName[1];//获取文件名称 string imgGuid = dickeshi["SP"].ToString() + "_" + strUid + "-" + date;//生成唯一标识 //判断数据是否存在 BLL.TB_CONSENT_FORM bll = new BLL.TB_CONSENT_FORM(); string strJson = bll.Sel_TB_CONSENT_FORM_Count_Bll(strUid, imgGuid); if (strJson == "") { try { Bitmap map = new Bitmap(filePath); //map.Save(savePath); long quality = long.Parse(System.Configuration.ConfigurationManager.AppSettings["ImgQuality"]); Common.ImageHelper.ImageClass img = new Common.ImageHelper.ImageClass(); //压缩图片并保存 img.Compress(filePath, savePath, map.Width, map.Height, quality); //map.Clone(); map.Dispose(); } catch (System.Exception ex) { Common.LogHelper.WriteError("MAP文件未找到"); } //上传到指定的FTP空间 mes = Sel_Folder(dt, savePath, imgName, dickeshi); if (mes.Contains("Download")) { //写入Freezerpro文件和数据库 dicdata = Set_dataDic(strUid, mes); mes = Import_TestData(dicdata, imgGuid, strName, dickeshi["keshi"].ToString()); //清空Consentimg目录下的图片 if (RuRo.Common.Filehleper.DirFileHelper.IsExistDirectory(mapPath + "\\" + path)) { RuRo.Common.Filehleper.DirFileHelper.DeleteDirectory(mapPath + "\\" + path); } context.Response.Write(mes); } else { //context.Response.Write(mes); //context.Response.End(); //写日志 RuRo.Model.TB_SAMPLE_LOG log_model = new Model.TB_SAMPLE_LOG(); log_model.MSG = "知情同意书管理:" + mes; RuRo.BLL.TB_SAMPLE_LOG log_bll = new BLL.TB_SAMPLE_LOG(); log_bll.Add(log_model); //返回消息 context.Response.Write(mes); context.Response.End(); } } else { mes = "该知情同意书已经存在"; context.Response.Write(mes); } #endregion //将图片保存到FTP操作 } catch (Exception e) { mes = e.ToString(); context.Response.Write(mes); } #endregion } }
protected void ImgNoOK_Click(object sender, EventArgs e) { //获取基本信息 string strUid = Request.Form["txtPatientID"].ToString(); string strName = Request.Form["txtName"].ToString(); string strdate = Request.Form["fromdate"].ToString(); string keshi = GetKeshi(); string strPy = keshicode(keshi);//将科室转化 string newimgName = ""; Dictionary<string, string> dickeshi = new Dictionary<string, string>(); dickeshi.Add("keshi", keshi); dickeshi.Add("SP", strPy); #region 判断传入日期 if (strUid == "") { Response.Write("<script type='text/javascript'>alert('患者唯一标识为空');</script>"); } else if (strName == "") { Response.Write("<script type='text/javascript'>alert('患者名称为空');</script>"); } else if (strdate == "" || !RuRo.Common.PageValidate.IsDateTime(strdate)) { Response.Write("<script type='text/javascript'>alert('日期为空或格式不正确');</script>"); } else { //创建上传的文件夹 string strpath = @"IIII\"; string newstrpath = Server.MapPath("~/IIII/"); //必须传入绝对路径 if (RuRo.Common.Filehleper.DirFileHelper.IsExistDirectory(newstrpath)) { } else { RuRo.Common.Filehleper.DirFileHelper.CreateDir(strpath); } //把图片上传到指定的文件夹,返回信息 string mes = PostImg(newstrpath); if (mes.Contains("")) { mes = ""; //读取图片处理并保存到指定的文件夹中,并返回路径和图片名称; mes = HandleImg(newstrpath + "", dickeshi["SP"], strUid, strdate, ref newimgName); //添加到Freezerpro诊断信息中 Dictionary<string, string> dicdata = new Dictionary<string, string>();//匹配传入系统的数据 if (mes.Contains(newimgName)) { //删除服务器端的存放图片文件夹 string newpath = CreatDownUrl(mes);//生成导入的路径 dicdata = Set_dataDic(strUid, strName, strdate, newpath);//添加到字典匹配 string msg = Import_TestData(dicdata, newpath, strName, dickeshi["keshi"].ToString());//提交到系统 if (msg.Contains("成功")) { RuRo.Common.Filehleper.DirFileHelper.ClearDirectory(newstrpath);//删除文件夹下面的文件 //返回消息 RuRo.Model.TB_SAMPLE_LOG log_model = new Model.TB_SAMPLE_LOG();//记录日志 log_model.MSG = "知情同意书管理:" + msg; RuRo.BLL.TB_SAMPLE_LOG log_bll = new BLL.TB_SAMPLE_LOG(); log_bll.Add(log_model); Response.Write("<script type='text/javascript'>alert('" + msg + "');</script>"); } else { RuRo.Common.Filehleper.DirFileHelper.DeleteFile(mes); RuRo.Common.Filehleper.DirFileHelper.ClearDirectory(newstrpath);//删除文件夹下面的文件 //返回消息 RuRo.Model.TB_SAMPLE_LOG log_model = new Model.TB_SAMPLE_LOG();//记录日志 log_model.MSG = "知情同意书管理:" + msg; RuRo.BLL.TB_SAMPLE_LOG log_bll = new BLL.TB_SAMPLE_LOG(); log_bll.Add(log_model); Response.Write("<script type='text/javascript'>alert('" + msg + "');</script>"); } } else { Response.Write("<script type='text/javascript'>alert('" + mes + "');</script>"); } } else { Response.Write("<script type='text/javascript'>alert('" + mes + "');</script>"); } } #endregion }