private void btnOCR_Click(object sender, EventArgs e) { return; if (!int.TryParse(cscID.Text, out int id)) { return; } OpenFileDialog d = new OpenFileDialog(); d.Title = "挑选参数图"; d.Filter = "Photos (*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp"; if (d.ShowDialog() == DialogResult.OK) { string md5 = CTHelper.GetMD5Hash(d.FileName); string f = CTHelper.CommonPath("app") + "\\" + md5 + ".pdf"; File.Copy(d.FileName, f); string r = CTHelper.UploadAPI(f, id.ToString(), "upload", "ctdb-scanpara", "iozct", CTHelper.GetConfig("userid")); Console.Write(r); if (File.Exists(f)) { File.Delete(f); } if (r == "") { //update tFile 表 } } }
//operations /// <summary> set values </summary> /// <param name="s"></param> void setDBValue(tbRef s) { s.UserId = Guid.Parse(CTHelper.GetConfig("userid")); s.title = refTitle.Text; s.url = refURL.Text; s.cite = refCite.Text; s.author = refAuthor.Text; s.year = int.Parse(refYear.Text); s.doc = refDoc.Text; if (File.Exists(s.doc)) { string md5 = CTHelper.GetMD5Hash(s.doc); string f = CTHelper.CommonPath("app") + "\\" + md5 + ".pdf"; File.Copy(s.doc, f); string r = CTHelper.UploadAPI(f, s.ref_id.ToString(), "upload", "ctdb-ref", "iozct", s.UserId.ToString()); Console.Write(r); if (File.Exists(f)) { File.Delete(f); } if (r == "") { s.doc = md5; } } }
/// <summary>add a new file to database and server</summary> /// <param name="f">source image</param> /// <param name="fpath">source path</param> /// <param name="dsid"></param> /// <param name="para_table"></param> /// <returns></returns> string addFile(string f, string fpath, string para_table, int dsid) { string r = ""; try { //upload to server this.Enabled = false; //核心上传 if (checkUploadFile.Checked) { r = CTHelper.UploadAPI(f, dsid.ToString(), "upload", para_table, "iozct", UserID); } this.Enabled = true; string md5 = CTHelper.GetMD5Hash(f); //insert to database var t = new tbFile(); t.f_path = fpath; //原名 t.f_pid = dsid; //父表记录ID t.f_table = para_table; //对应的附表参数 string pn = Path.GetFileNameWithoutExtension(fpath); if (pn.Length >= 4) { t.f_name = pn.Substring(pn.Length - 4, 4) + ".jpg"; //排序专用名 } else { t.f_name = pn + ".jpg"; } t.f_md5 = md5; //md5值 t.f_author = cdFileAuthor.Text; //版权人 copyright owner t.f_filetype = (cdFileType.SelectedItem as tbTag).tag_id; // file type, default according the file extension, most Image = 11 t.open_status = (cdFileOpenStatus.SelectedItem as tbTag).tag_id; //share method, default 11 , most = 30 t.f_fpid = 0; //?? t.sp_id = int.Parse(lbSpecimenID.Text); //specimen id t.ref_id = (cdFileRef.SelectedItem as tbRef).ref_id; // t.f_count = 1; t.date_in = DateTime.Now; t.date_up = DateTime.Now; t.UserId = Guid.Parse(UserID); CTDBEntities ct = new CTDBEntities(); ct.tbFile.Add(t); ct.SaveChanges(); //将修改保存到数据库中 return(r); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { r = dbEx.ToString(); return(r); } finally { this.Enabled = true; } }