public void BtnOk_Click(object sender, EventArgs e)//当点击确定的时候,页面上的数据,要保存在caseInfo中,然后将caseInfo写回到数据库中 { Console.WriteLine("编辑案件:"); this.Case.Path = Program.m_mainform.g_workPath; this.Case.CaseName = textBox1.Text; this.Case.CaseSerialNum = textBox2.Text; this.Case.CaseType = comboBox1.Text; this.Case.Collecter = textBox3.Text; this.Case.CollecterNum = textBox4.Text; this.Case.CollecterDepartMent = comboBox2.Text; this.Case.InspectionPersonName = textBox5.Text; this.Case.InspectionPersonDepartMent = textBox6.Text; this.Case.OrganizationCode = textBox7.Text; this.Case.Note = textBox8.Text; //向数据库中写回更改之后的数据 AppConfig ac = AppConfig.getAppConfig(); using (CaseContext caseContext = new CaseContext()) { var caseInfo = this.Case; var entry = caseContext.Entry(caseInfo); caseContext.Set <Case>().Attach(entry.Entity); entry.State = System.Data.Entity.EntityState.Modified; caseContext.SaveChanges(); } Program.m_mainform.AddNewGjalAj(); MessageBox.Show("编辑案件成功!"); this.Close(); }
private void button11_Click(object sender, EventArgs e)//对某一个案件的证据进行删除 { ArrayList selectedProofIds = new ArrayList(); int rc = dataGridView2.RowCount; AppConfig ac = AppConfig.getAppConfig(); int once = 0; string st = ""; for (int i = 0; i < rc; i++) { bool selected = Convert.ToBoolean(this.dataGridView2.Rows[i].Cells[0].Value); if (selected) { if (once == 0) { st = string.Format("是否要删除编号为:{0}", i + 1); once = 1; } else { st += string.Format("、{0}", i + 1); } //selectedProofIds.Add(this.dataGridView2.Rows[i].Cells[1].Value);//添加真正的证据的编号 selectedProofIds.Add(ac.aEvidenceList[i]);//添加真正的证据的编号 } } st += " 的证据?"; int deleteAmount = selectedProofIds.Count; if (deleteAmount == 0) { MessageBox.Show("请在你想要删除的证据前面打勾!"); } else { DialogResult RSS = MessageBox.Show(this, st, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (RSS == DialogResult.Yes) {//开始访问数据库 using (CaseContext caseContext = new CaseContext()) { for (int i = 0; i < deleteAmount; i++) { int proofId = Convert.ToInt32(selectedProofIds[i]); //Console.WriteLine(proofId+"--------------------------"); var ProofInfo = caseContext.Proofs.FirstOrDefault(p => p.ProofId == proofId); if (ProofInfo != null) { caseContext.Proofs.Remove(ProofInfo); } } caseContext.SaveChanges(); } Program.m_mainform.AddNewGjalAj(); MessageBox.Show("删除证据成功!"); } } }
private void button4_Click(object sender, EventArgs e)//删除案件(每个被删除案件的前面的复选框要打勾) { ArrayList selectedCaseIds = new ArrayList(); int rc = dataGridView1.RowCount; string st = ""; int once = 0; for (int i = 0; i < rc; i++) { bool selected = Convert.ToBoolean(this.dataGridView1.Rows[i].Cells[0].Value); if (selected) { if (once == 0) { st = string.Format("是否要删除编号为:{0}", i + 1); once = 1; } else { st += string.Format("、{0}", i + 1); } selectedCaseIds.Add(AppConfig.getAppConfig().aList[i]); } } st += " 的案件?"; int deleteAmount = selectedCaseIds.Count; if (deleteAmount == 0) { MessageBox.Show("请在你想要删除的案件前面打勾!"); } else { DialogResult RSS = MessageBox.Show(this, st, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (RSS == DialogResult.Yes) {//开始访问数据库 using (CaseContext caseContext = new CaseContext()) { for (int i = 0; i < deleteAmount; i++) { int caseId = Convert.ToInt32(selectedCaseIds[i]); var Caseinfo = caseContext.Cases.FirstOrDefault(c => c.CaseId == caseId); if (Caseinfo != null) { caseContext.Cases.Remove(Caseinfo); var proofs = caseContext.Proofs.Where(p => p.CaseID == caseId); caseContext.Proofs.RemoveRange(proofs);//删除案件的同时,级联删除该案件对应的所有证据 } } caseContext.SaveChanges(); } Program.m_mainform.AddNewGjalAj(); MessageBox.Show("删除案件成功!"); } } }
public HttpStatusCode DeleteCase(int id) { using (var context = new CaseContext()) { try { var cases = context.Cases.Find(id); context.Cases.Remove(cases); context.SaveChanges(); return(HttpStatusCode.OK); } catch (Exception ex) { return(HttpStatusCode.NotFound); } } }
public HttpStatusCode SaveCase(Case cases) { using (var context = new CaseContext()) { try { context.Cases.Add(cases); context.SaveChanges(); return(HttpStatusCode.Created); } catch (Exception ex) { Console.WriteLine(ex.Message); return(HttpStatusCode.BadRequest); } } }
private void Button3_Click(object sender, EventArgs e) { Program.m_mainform.AddNewGjalZs(); using (var context = new CaseContext()) { Case @case = context.Cases.Find(AppConfig.getAppConfig().caseId_selected_working); Proof proof = new Proof() { Case = @case, }; @case.Proofs.Add(proof); context.SaveChanges(); } this.Close(); AppConfig.AppConfigAddAdvinceClear(); AppContext.setInstanceNull(); }
public HttpStatusCode UpdateCase(Case cases) { using (var context = new CaseContext()) { try { var original = context.Cases.Find(cases.ID); if (original != null) { original.attachment = cases.attachment; original.kind = cases.kind; } context.SaveChanges(); return(System.Net.HttpStatusCode.OK); } catch (Exception ex) { Console.WriteLine(ex.Message); return(System.Net.HttpStatusCode.NotFound); } } }
private void Button2_Click(object sender, EventArgs e) { //新建案件 FormGjglNewAj form = new FormGjglNewAj(); string s = form.ShowDialog().ToString(); if (s == "Cancel") { return; } Case @case = form.Case; using (var context = new CaseContext()) { context.Cases.Add(@case); context.SaveChanges(); AppContext.CaseID = @case.CaseId; } Program.m_mainform.AddNewGjalAj(); // MessageBox.Show("案件添加成功!"); }
private void button1_Click(object sender, EventArgs e) { this.Proof.ProofName = textBox1.Text; this.Proof.ProofSerialNum = textBox2.Text; this.Proof.PhoneNum = textBox6.Text; this.Proof.phoneNum2 = textBox3.Text; this.Proof.Holder = textBox4.Text; this.Proof.ProofType = comboBox2.Text; this.Proof.note = textBox8.Text; //向数据库中写回更改之后的数据 AppConfig ac = AppConfig.getAppConfig(); using (CaseContext caseContext = new CaseContext()) { var proofInfo = this.Proof; var entry = caseContext.Entry(proofInfo); caseContext.Set <Proof>().Attach(entry.Entity); entry.State = System.Data.Entity.EntityState.Modified; caseContext.SaveChanges(); } Program.m_mainform.AddNewGjalAj(); MessageBox.Show("编辑证据成功!"); this.Close(); }
public bool Save() { return(_context.SaveChanges() >= 0); }
private void Button3_Click(object sender, EventArgs e) { ////方法1修改config的数据库路径 //XmlDocument doc = new XmlDocument(); ////获得配置文件的全路径 //string strFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName+".config"; //MessageBox.Show(strFileName); //doc.Load(strFileName); ////找出名称为“add”的所有元素 //XmlNodeList nodes = doc.GetElementsByTagName("add"); //XmlAttribute att; //for (int i = 0; i < nodes.Count; i++) //{ // //获得将当前元素的key属性 // att = nodes[i].Attributes["name"]; // //根据元素的第一个属性来判断当前的元素是不是目标元素 // if (att != null && att.Value == "sqlite_connection_string") // { // //对目标元素中的第二个属性赋值 // att = nodes[i].Attributes["connectionString"]; // string strConn = "Data Source=" + Program.m_mainform.g_workPath + "\\midwxtrans.db;Pooling=true;FailIfMissing=false"; // att.Value = strConn; // break; // } //} ////保存上面的修改 //doc.Save(strFileName); //FieldInfo fieldInfo = typeof(ConfigurationManager).GetField("sqlite_connection_string", BindingFlags.NonPublic | BindingFlags.Static); //if (fieldInfo != null) fieldInfo.SetValue(null, 0); ////方法2修改config的数据库路径,均不能正常工作 ////读app.config中的connectionStrings //ModifyAppConfig mac = new ModifyAppConfig(); //string strConnStrings = mac.GetConnectionStringsConfig("sqlite_connection_string"); ////重写app.config中的connectionStrings //ModifyAppConfig mac1 = new ModifyAppConfig();//"D:\手机取证工作路径设置\案件20190707093739\HONORV2020190701094546\AppData\Weixin\ca9529dc14475dbcc7e8553e77ad7d0b" //string strConn = "Data Source=" + Program.m_mainform.g_workPath + "\\midwxtrans.db;Pooling=true;FailIfMissing=false"; //mac1.UpdateConnectionStringsConfig("sqlite_connection_string", strConn, "System.Data.SQLite.EF6"); //strConnStrings = mac1.GetConnectionStringsConfig("sqlite_connection_string"); Program.m_mainform.AddNewGjalZs(); using (var context = new CaseContext()) { Case @case = context.Cases.Find(AppConfig.getAppConfig().caseId_selected_working); Proof proof = new Proof() { Case = @case, ProofName = textBox1.Text, ProofSerialNum = textBox2.Text, PhoneNum = textBox6.Text, phoneNum2 = textBox3.Text, Holder = textBox4.Text, ProofType = comboBox2.Text, note = textBox8.Text, }; @case.Proofs.Add(proof); context.SaveChanges(); } this.Close(); AppConfig.AppConfigAddAdvinceClear(); AppContext.setInstanceNull(); }