예제 #1
0
파일: FormScan.cs 프로젝트: wjn99wjn/CTDB
        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 表
                }
            }
        }
예제 #2
0
파일: FormRef.cs 프로젝트: wjn99wjn/CTDB
        //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;
                }
            }
        }
예제 #3
0
파일: FormUpload.cs 프로젝트: wjn99wjn/CTDB
        /// <summary>upload specimen file / example /demo </summary>
        /// <param name="specimenid"></param>
        /// <param name="lll"></param>
        /// <param name="filetablep"></param>
        /// <param name="choose_number"></param>
        void uploadSpecimenFile(int specimenid, List <tbFile> lll, string filetablep, int choose_number)
        {
            //从slice表中随机找出10张图
            List <string> fl = new List <string>();

            int[] fr = CTHelper.RandomIntArray(choose_number, 0, lll.Count - 1);
            for (int i = 0; i < fr.Length; i++)
            {
                string url = CTHelper.GetConfig("downloadurl") + "ct/" + filetablep + "/" + lll[fr[i]].f_pid + "/";
                string fn  = Path.GetFileName(lll[fr[i]].f_path.Trim());
                fl.Add(url + fn);
            }

            Application.DoEvents();
            string ftmpd = CTHelper.CommonPath("app") + "\\" + "d.jpg";
            string ftmp  = "";

            //对每张图进行上传操作  同 Add功能
            note(fl.Count);
            for (int i = 0; i < fr.Length; i++)
            {
                notep();
                if (File.Exists(ftmpd))
                {
                    File.Delete(ftmpd);
                }
                CTHelper.DownloadFile(fl[i], ftmpd); //download source image
                string fn = CTHelper.GetMD5Hash(ftmpd) + ".jpg";
                if (File.Exists(ftmpd))
                {
                    Bitmap b = CTHelper.CreateDemoImage(ftmpd, 150, 150);
                    ftmp = CTHelper.CommonPath("app") + "\\" + fn;
                    b.Save(ftmp, System.Drawing.Imaging.ImageFormat.Jpeg);

                    if (File.Exists(ftmp))
                    {
                        cdFileAuthor.Text = "selected from " + filetablep;
                        string r = addFile(ftmp, ftmp, "ctdb-specimen", specimenid);
                        if (r != "")
                        {
                            MessageBox.Show(r);
                        }
                    }
                }
                if (File.Exists(ftmpd))
                {
                    File.Delete(ftmpd);
                }
                if (File.Exists(ftmp))
                {
                    File.Delete(ftmp);
                }
            }
        }
예제 #4
0
파일: FormUpload.cs 프로젝트: wjn99wjn/CTDB
        /// <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;
            }
        }
예제 #5
0
파일: FormUpload.cs 프로젝트: wjn99wjn/CTDB
        private void miUpload_Click(object sender, EventArgs e)
        {
            //阻止休眠
            CTHelper.PreventSleep();

            //upload files
            pbar1.Maximum = lboxFile.Items.Count;
            pbar1.Value   = 0;

            lbNote.Text = "开始上传文件";
            string logl = CTHelper.CommonPath("app") + "\\upload.log";
            int    countOK = 0, countError = 0;

            foreach (string fileSrc in lboxFile.Items)
            {
                pbar1.Value++;
                lbNote.Text = pbar1.Value + "/" + lboxFile.Items.Count + ", " + countOK + " OK," + countError + " Fail";

                if (checkSkipSameFile.Checked) //重复检查
                {
                    string checkfilename = Path.GetFileName(fileSrc);
                    using (CTDBEntities ct = new CTDBEntities())
                    {
                        var q = from c in ct.tbFile
                                where c.f_pid == ParaDatasetID && c.f_table == ParaTable && c.f_path.Contains(checkfilename)
                                select c;
                        if (q.ToList <tbFile>().Count > 0)
                        {
                            continue;
                        }
                    }
                }

                //check names before upload上传前检测,名称检测
                string fileDes = CTHelper.CommonPath("app") + "\\" + Path.GetFileName(fileSrc).Replace(" ", "");
                if (File.Exists(fileDes))
                {
                    File.Delete(fileDes);
                }
                File.Copy(fileSrc, fileDes, true);
                string md5 = CTHelper.GetMD5Hash(fileDes);
                string fn  = md5 + System.IO.Path.GetExtension(fileDes);

                /////////begin to upload开始上传
                if (File.Exists(fileDes))
                {
                    addFile(fileDes, fileSrc, ParaTable, ParaDatasetID); /////核心上传函数
                }
                ///////////////////

                File.Delete(fileDes);
                this.Enabled = true;
                Application.DoEvents();
            }

            this.Enabled = true;

            //finished
            refreshdb();
            MessageBox.Show("Finishe upload. Error number:" + countError.ToString());
            lbNote.Text = "Finish Upload.";

            //恢复休眠
            CTHelper.RestoreSleep();
        }