private void bTagAdd_Click(object sender, EventArgs e) { var s = new tbTag(); s.tag_tag = ctagTag.Text; s.tag_tagCN = ctagCHN.Text; s.tag_note = ctagNote.Text; s.tag_type = 0; s.tag_pid = 8; s.date_in = DateTime.Now; ct.tbTag.Add(s); ct.SaveChanges(); //将修改保存到数据库中 refreshdata(); }
private void btnDelete_Click(object sender, EventArgs e) { try { int id = int.Parse(clID.Text); if (FormUpload.HasFiles("ctdb-slice", id)) { MessageBox.Show("Files related, can't delete!"); return; } if (CTHelper.AlertYes("Delete " + id.ToString() + "?")) { using (var db = new CTDBEntities()) { var student = db.tbSlice.FirstOrDefault(s => s.slice_id == id); db.tbSlice.Remove(student); //删除萝莉 db.SaveChanges(); refreshdata(null, null); } } } catch { MessageBox.Show("记录有关联,删除失败"); } }
private void mitClearAll_Click(object sender, EventArgs e) { //int id = int.Parse(clbID.Text); ArrayList sl = dataGridView1.DataSource as ArrayList; if (sl.Count > 0) { if (MessageBox.Show("确认删除" + sl.Count + " records?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (var db = new CTDBEntities()) { foreach (tbLabel ts in sl) { try { //MessageBox.Show(ts.label_id.ToString()); var student = db.tbLabel.FirstOrDefault(s => s.label_id == ts.label_id); db.tbLabel.Remove(student); //删除萝莉 db.SaveChanges(); } catch { MessageBox.Show("记录有关联,删除失败"); } } refreshdata(null, null); } } } }
//scan private void btnAdd_Click(object sender, EventArgs e) { var s = new tbScan(); setDBValue(s); using (CTDBEntities ct = new CTDBEntities()) { ct.tbScan.Add(s); ct.SaveChanges(); //将修改保存到数据库中 } //refreshDatagridview(dataGridView1.Rows.Count.ToString()); int rowid = dataGridView1.Rows.Count; refreshdata(null, null); dataGridView1.Rows[rowid].Selected = true; //return; //级联添加一个slice using (CTDBEntities ct = new CTDBEntities()) { tbSlice sl = new tbSlice(); sl.scan_id = int.Parse(cscID.Text); sl.slice_para_ReconstructionProgram = "NRecon"; sl.slice_para_ResultFileType = "BMP"; sl.slice_para_SliceNumber = 0; sl.slice_para_PixelSize = s.scan_para_ImagePixelSize; sl.open_status = 30; sl.UserId = Guid.Parse(CTHelper.GetConfig("userid")); sl.Abstract = FormSpecimen.CutString(cscSpecimen.Text, 40) + "-" + FormSpecimen.CutString(cscTagSpecimenParty.Text, 7); ct.tbSlice.Add(sl); ct.SaveChanges(); //将修改保存到数据库中 } }
private void mitAddFile_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count <= 0) { return; } FormUpload dlg = new FormUpload(); int id = int.Parse(csliceID.Text); dlg.ParaDatasetID = id; dlg.ParaTable = "ctdb-slice"; dlg.ShowDialog(); using (CTDBEntities ct = new CTDBEntities()) { var q = from c in ct.tbFile where c.f_pid == id && c.f_table == dlg.ParaTable select c; //clNumberSlice.Text = q.Count<tbFile>().ToString(); //更新文件数量 var s = ct.tbSlice.FirstOrDefault(st => st.slice_id == id); s.slice_para_SliceNumber = q.Count <tbFile>(); ct.SaveChanges(); } //refreshDatagridview(id.ToString()); //refreshdata(); }
private void bsmAddBatch_Click(object sender, EventArgs e) { FolderBrowserDialog fd = new FolderBrowserDialog(); if (fd.ShowDialog() == DialogResult.OK) { string[] fds = Directory.GetDirectories(fd.SelectedPath); for (int i = 0; i < fds.Length; i++) { //clbNote.Text = fds[i]; clbSrcFolder.Text = fds[i]; fds[i] = fds[i].Replace(fd.SelectedPath + "\\", ""); clbTitle.Text = fds[i]; var s = new tbLabel(); setDBValue(s); s.label_structure = ParseStructure(s.label_title); CTDBEntities ct = new CTDBEntities(); ct.tbLabel.Add(s); ct.SaveChanges(); //将修改保存到数据库中 } MessageBox.Show(fds.Length + " OK"); refreshdata(sender, e); } }
private void btnAdd_Click(object sender, EventArgs e) { var s = new tbSlice(); setDBValue(s); CTDBEntities ct = new CTDBEntities(); ct.tbSlice.Add(s); ct.SaveChanges(); //将修改保存到数据库中 refreshdata(null, null); }
private void bsmAdd_Click(object sender, EventArgs e) { var s = new tbSpecimen(); setDBValue(s); CTDBEntities ct = new CTDBEntities(); ct.tbSpecimen.Add(s); ct.SaveChanges(); //将修改保存到数据库中 refreshdata(dataGridView1.RowCount); }
private void bSpeciesAdd_Click(object sender, EventArgs e) { tbRef s = new tbRef(); setDBValue(s); CTDBEntities ct = new CTDBEntities(); ct.tbRef.Add(s); ct.SaveChanges(); //将修改保存到数据库中 refreshdata(null, null); }
private void btnUpdate_Click(object sender, EventArgs e) { int id = int.Parse(clID.Text); using (var ct = new CTDBEntities()) { var s = ct.tbSlice.FirstOrDefault(st => st.slice_id == id); setDBValue(s); ct.SaveChanges(); refreshdata(null, null); } }
private void bsmUpdate_Click(object sender, EventArgs e) { int id = int.Parse(csmID.Text); using (var ct = new CTDBEntities()) { var s = ct.tbSpecimen.FirstOrDefault(st => st.sp_id == id); setDBValue(s); ct.SaveChanges(); refreshdata(dataGridView1.SelectedRows[0].Index); } }
private void btnUpdate_Click(object sender, EventArgs e) { int rowid = CTHelper.GetRowIndex(dataGridView1); int id = int.Parse(cscID.Text); using (var ct = new CTDBEntities()) { var s = ct.tbScan.FirstOrDefault(st => st.scan_id == id); setDBValue(s); ct.SaveChanges(); refreshdata(null, null, rowid); } }
private void ucFileInfo1_UpdateFile(object sender, EventArgs e) { this.Show(); using (CTDBEntities ct = new CTDBEntities()) { //更新文件数量 var s = ct.tbLabel.FirstOrDefault(st => st.label_id == ucFileInfo1.ParaDatasetID); if (s != null) { s.label_file_number = ucFileInfo1.ValueFileCount; ct.SaveChanges(); } } }
private void ucFileInfo1_UpdateFile(object sender, EventArgs e) { this.Show(); int id = int.Parse(cscID.Text); using (CTDBEntities ct = new CTDBEntities()) { //更新文件数量 var s = ct.tbScan.FirstOrDefault(st => st.scan_id == id); s.scan_para_FilesNumber = ucFileInfo1.ValueFileCount;// q.Count<tbFile>(); ct.SaveChanges(); } refreshDatagridview(id.ToString()); }
private void bSpeciesUpdate_Click(object sender, EventArgs e) { int rowid = CTHelper.GetRowIndex(dataGridView1); int id = int.Parse(refID.Text); using (var db = new CTDBEntities()) { var s = db.tbRef.FirstOrDefault(st => st.ref_id == id); setDBValue(s); db.SaveChanges(); refreshdata(null, null, rowid); } }
private void bSpeciesDel_Click(object sender, EventArgs e) { int id = int.Parse(refID.Text); if (MessageBox.Show("Delete " + id.ToString(), "Alert", MessageBoxButtons.YesNo) == DialogResult.Yes) { using (var db = new CTDBEntities()) { var student = db.tbRef.FirstOrDefault(s => s.ref_id == id); db.tbRef.Remove(student); //删除萝莉 db.SaveChanges(); refreshdata(null, null); } } }
private void beUpdate_Click(object sender, EventArgs e) { int id = int.Parse(ceID.Text); CTDBEntities db = new CTDBEntities(); var s = db.tbEquipment.FirstOrDefault(st => st.e_id == id); s.e_nameA = ceNameA.Text; s.e_name = ceName.Text; s.e_note = ceNote.Text; s.e_location = ceLocation.Text; s.e_type = ceType.Text; s.e_description = ceDescription.Text; s.e_contact = ceContact.Text; s.UserId = Guid.Parse(CTHelper.GetConfig("userid")); db.SaveChanges(); refrashDataGridview(null, null); }
private void bSpeciesAdd_Click(object sender, EventArgs e) { tbSpecies s = new tbSpecies(); setDBValue(s); CTDBEntities ct = new CTDBEntities(); ct.tbSpecies.Add(s); ct.SaveChanges(); //将修改保存到数据库中 if ((dataGridView1.DataSource as List <tbSpecies>) != null) { refreshdata(null, null, (dataGridView1.DataSource as List <tbSpecies>).Count); } else { refreshdata(null, null); } }
private void btDelete_Click(object sender, EventArgs e) { try { int id = int.Parse(ceID.Text); if (CTHelper.AlertYes("Delete " + id.ToString())) { using (var db = new CTDBEntities()) { var student = db.tbEquipment.FirstOrDefault(s => s.e_id == id); db.tbEquipment.Remove(student); //删除 db.SaveChanges(); refrashDataGridview(null, null); } } } catch { MessageBox.Show("Fail to delete, there is related data in database!"); } }
private void btnDelete_Click(object sender, EventArgs e) { int id = int.Parse(cscID.Text); if (MessageBox.Show("确认删除" + id.ToString(), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { using (var db = new CTDBEntities()) { var student = db.tbScan.FirstOrDefault(s => s.scan_id == id); db.tbScan.Remove(student); //删除萝莉 db.SaveChanges(); } } catch { MessageBox.Show("删除失败,可能有关联数据"); } } refreshdata(null, null); }
//=======remote / server========= ///remove from database private void btnDelete_Click(object sender, EventArgs e) { //if (MessageBox.Show("Delete " + lboxDB.SelectedItems.Count.ToString() + " files", "Alert", MessageBoxButtons.YesNo) == DialogResult.Yes) if (CTHelper.AlertYes("Delete " + lboxDB.SelectedItems.Count + " files")) { using (var db = new CTDBEntities()) { note(lboxDB.Items.Count); foreach (tbFile f in lboxDB.SelectedItems) { var student = db.tbFile.FirstOrDefault(s => s.f_id == f.f_id); db.tbFile.Remove(student); //删除 db.SaveChanges(); notep(); } } } refreshdb(); }
private void bTagDel_Click(object sender, EventArgs e) { int id = int.Parse(ctagID.Text); if (MessageBox.Show("确认删除" + id.ToString(), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { using (var db = new CTDBEntities()) { var student = db.tbTag.FirstOrDefault(s => s.tag_id == id); db.tbTag.Remove(student); //删除 db.SaveChanges(); refreshdata(); } } catch (Exception eeee) { MessageBox.Show("Error." + eeee.ToString()); } } }
//equipment private void beAdd_Click(object sender, EventArgs e) { var s = new tbEquipment(); s.e_nameA = ceNameA.Text; s.e_name = ceName.Text; s.e_note = ceNote.Text; s.e_location = ceLocation.Text; s.e_type = ceType.Text; s.e_description = ceDescription.Text; s.date_in = DateTime.Now; s.e_contact = ceContact.Text; s.UserId = Guid.Parse(CTHelper.GetConfig("userid")); CTDBEntities ct = new CTDBEntities(); ct.tbEquipment.Add(s); ct.SaveChanges(); //将修改保存到数据库中 refrashDataGridview(null, null); }
private void bsmDelete_Click(object sender, EventArgs e) { try { int id = int.Parse(csmID.Text); //if (MessageBox.Show("确认删除" + id.ToString(), "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) if (CTHelper.AlertYes("Delete " + id.ToString() + "?")) { using (var db = new CTDBEntities()) { var student = db.tbSpecimen.FirstOrDefault(s => s.sp_id == id); db.tbSpecimen.Remove(student); db.SaveChanges(); } refreshdata(0); } } catch { MessageBox.Show("记录有关联,删除失败"); } }
private void btnSliceFileAdd_Click(object sender, EventArgs e) { FormUpload dlg = new FormUpload(); int id = int.Parse(clID.Text); dlg.ParaDatasetID = id; dlg.ParaTable = "ctdb-slice"; dlg.ParaFileType = 12; if (sender is ToolStripMenuItem) { if ((sender as ToolStripMenuItem).Name == "cmitAddFileStack") { dlg.ParaFileType = 93; } } dlg.ShowDialog(); using (CTDBEntities ct = new CTDBEntities()) { var q = from c in ct.tbFile where c.f_pid == id && c.f_table == dlg.ParaTable select c; // clNumberSlice.Text = q.Count<tbFile>().ToString(); //更新文件数量 var s = ct.tbSlice.FirstOrDefault(st => st.slice_id == id); s.slice_para_SliceNumber = q.Count <tbFile>(); if (s.slice_para_SliceNumber > 0) { tbFile t = q.ToList <tbFile>()[0]; // clResultFileType.Text = System.IO.Path.GetExtension(t.f_path); // s.slice_para_ResultFileType = clResultFileType.Text; } ct.SaveChanges(); } refreshDatagridview(id.ToString()); }
/// <summary>record user information if the user first login, else update </summary> void updateUserInfo() { Guid uid = Guid.Parse(CTHelper.GetConfig("userid")); string username = CTHelper.GetConfig("username"); string mail = CTHelper.GetConfig("mail"); CTDBEntities ct = new CTDBEntities(); tbUser tu = null; try { tu = ct.tbUser.Where(c => c.UserId == uid).Single(); } catch (Exception ex) { Console.Write(ex.ToString()); } if (tu == null) { tu = ct.tbUser.Create(); tu.UserId = uid; tu.date_in = DateTime.Now; ct.tbUser.Add(tu); } tu.UserName = username; tu.mail = mail; tu.date_up = DateTime.Now; ct.SaveChanges(); this.Text = "Insect 3D Database Clicent -- " + username; btnMDTag.Enabled = FormLogin.HasAuthorty(""); }
/// <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; } }
//add private void btnAdd_Click(object sender, EventArgs e) { CTDBEntities ct = new CTDBEntities(); //create species var s1 = new tbSpecies(); s1.species_note = cspeciesNote.Text; s1.species_Order = cspeciesOrder.Text; s1.date_in = DateTime.Now; s1.UserId = Guid.Parse(CTHelper.GetConfig("userid")); ct.tbSpecies.Add(s1); ct.SaveChanges(); //将修改保存到数据库中 //create specimen var s2 = new tbSpecimen(); s2.species_id = s1.species_id; s2.sp_spid = csmSPID.Text; //实际标本号-不是必须字段 s2.specimen_sex = (csmSex.SelectedItem as tbTag).tag_id; s2.specimen_age = csmAge.Text; s2.sp_note = csmNote.Text; s2.specimen_dry_save_path = csmSavePosition.Text; s2.sp_collector = csmCollector.Text; s2.sp_collect_place = csmCollectPlace.Text; s2.sp_collect_time = csmCollectTime.Text; s2.sp_dehydrant = csmDehydrant.Text; s2.sp_drycirletime = int.Parse(GetStringNumber(csmDryCycleTime.Text)); //s2.sp_dryinstrument = "-"; s2.Abstract = s1.species_note + "-" + s2.sp_id; s2.date_in = DateTime.Now; s2.UserId = Guid.Parse(CTHelper.GetConfig("userid")); s2.sp_preserve_status = "-"; ct.tbSpecimen.Add(s2); ct.SaveChanges(); //将修改保存到数据库中 //create scan record var s3 = new tbScan(); s3.sp_id = s2.sp_id; s3.e_id = (int)cscanEquipment.SelectedValue; s3.scan_specimen_Body = cscanTagSpecimenParty.Text; s3.scan_source_save_path = cscanPath.Text; //s3.scan_timebegin = DateTime.Parse(cscanTimeBegin.Text); s3.scan_date = cscanTimeBegin.Text; s3.scan_para_CameraBinning = cscanCameraBinning.Text; s3.scan_para_SourceVoltage = double.Parse(GetStringNumber(cscanSourceVoltage.Text)); s3.scan_para_SourceCurrent = double.Parse(GetStringNumber(cscanSourceCurrent.Text)); s3.scan_para_Exposure = double.Parse(GetStringNumber(cscanExposure.Text)); s3.Abstract = s2.Abstract + "-" + s3.scan_specimen_Body; s3.date_in = DateTime.Now; s3.UserId = Guid.Parse(CTHelper.GetConfig("userid")); ct.tbScan.Add(s3); ct.SaveChanges(); //将修改保存到数据库中 //create slice record var s4 = new tbSlice(); s4.scan_id = s3.scan_id; s4.slice_save_path = csliceSavePath.Text; s4.date_in = DateTime.Now; s4.UserId = Guid.Parse(CTHelper.GetConfig("userid")); s4.Abstract = s3.Abstract; ct.tbSlice.Add(s4); ct.SaveChanges(); //将修改保存到数据库中 refreshdata(null, null); }