private void button1_Click(object sender, EventArgs e) { if (checkem()) { eQues mcq = new eQues(); // mcq.answ = comboBox4.SelectedIndex + 1; mcq.con = Convert.ToInt16(comboBox2.Text); mcq.diff = Convert.ToInt16(comboBox3.Text); mcq.objective = Convert.ToInt16(comboBox1.Text); mcq.courseid = cid; mcq.teacherid = pp.teacher.teacherid; mcq.emnum = comboBox4.SelectedIndex + 1; ////////////write richtext System.IO.MemoryStream mstream = new System.IO.MemoryStream(); this.rquestion.SaveFile(mstream, RichTextBoxStreamType.RichText); mcq.question = mstream.ToArray(); mcq.answ = textBox1.Text; if (mcq.answ.Length < pp.maxsize) { context.AddToeQues(mcq); context.SaveChanges(); rquestion.Text = ""; } else { MessageBox.Show("请使用小一点的图片,建议不使用"); } } else { MessageBox.Show("Please complete the data"); } }
private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e) { // MessageBox.Show("sdfds"); ctf = lTF[e.RowIndex]; System.IO.MemoryStream mstream = new System.IO.MemoryStream(ctf.question, false); this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText); comboBox5.Text = ctf.emnum.ToString(); textBox2.Text = ctf.answ; loadcom2(); comboBox8.Text = ctf.con.ToString(); comboBox7.Text = ctf.objective.ToString(); comboBox6.Text = ctf.diff.ToString(); }
private void display(int a, bool bb) { int c0 = -1; int c1 = -1; int c2 = -1; int c3 = -1; bool b0 = false; bool b1 = false; bool b2 = false; bool b3 = false; if (textBox1.Text != "") { c0 = int.Parse(textBox1.Text); } else { b0 = true; } if (comboBox3.Text != "") { c1 = int.Parse(comboBox3.Text); } else { b1 = true; } if (comboBox2.Text != "") { c2 = int.Parse(comboBox2.Text); } else { b2 = true; } if (comboBox4.Text != "") { c3 = int.Parse(comboBox4.Text); } else { b3 = true; } if (dataGridView1.DataSource != null) { DataTable dt = (DataTable)dataGridView1.DataSource; dt.Rows.Clear(); dataGridView1.DataSource = dt; } else { dataGridView1.Rows.Clear(); } if (a == 2) { lTF = null; ctf = null; var questionQuery3 = (from o in pp.context.eQues where (b1 || o.objective == c1) && (b2 || o.con == c2) && (b3 || o.diff == c3) && (b0 || o.id == c0) && (o.courseid == lvtc[comboBox1.SelectedIndex].couseid) select o).Skip(pageNum * pagesize).Take(pagesize); if (questionQuery3.Count <eQues>() > 0) { lTF = questionQuery3.ToList <eQues>(); foreach (eQues mcq in lTF) { System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); DataGridViewRow dgvr = new DataGridViewRow(); dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView1.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[1].Value = richTextBox1.Rtf; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 6); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView1.Rows.Add(dgvr); ////////////////////////////// ///////////////////////////////////////////// } } else { pageNum--; MessageBox.Show("没有了啊!"); } } }
private void button7_Click(object sender, EventArgs e) { int irow = -1; if (dataGridView1.CurrentCell != null) { irow = dataGridView1.CurrentCell.RowIndex; } DialogResult result = MessageBox.Show("确定删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes && irow >= 0) { helpsimilar ths = hsl[irow]; if (ths.sim != -1) { if (ths.type1 == 0) { var q1 = from o in pp.context.mchoiceQues where o.id == ths.qid select o; mchoiceQues m1 = q1.First(); pp.context.DeleteObject(m1); var q2 = from o in pp.context.exerDetail where o.qid == ths.qid && o.typeq == 0 select o; List <exerDetail> tl = null; if (q2.Count() > 0) { tl = q2.ToList(); foreach (exerDetail ed in tl) { ed.qid = ths.sim; pp.context.UpdateObject(ed); MessageBox.Show("updata:" + ed.id); EXtools.checkd(pp, ed.lid); } } } try { if (ths.type1 == 1) { var q1 = from o in pp.context.TFQues where o.id == ths.qid select o; TFQues m1 = q1.First(); pp.context.DeleteObject(m1); var q2 = from o in pp.context.exerDetail where o.qid == ths.qid && o.typeq == 1 select o; List <exerDetail> tl = null; if (q2.Count() > 0) { tl = q2.ToList(); foreach (exerDetail ed in tl) { ed.qid = ths.sim; pp.context.UpdateObject(ed); MessageBox.Show("updata:" + ed.id); EXtools.checkd(pp, ed.lid); } } } } catch (InvalidOperationException e1) { MessageBox.Show(e1.Message.ToString()); } catch (ArgumentNullException e1) { MessageBox.Show(e1.Message.ToString()); } catch (Exception e1) { MessageBox.Show(e1.Message.ToString()); } if (ths.type1 == 2) { var q1 = from o in pp.context.eQues where o.id == ths.qid select o; eQues m1 = q1.First(); pp.context.DeleteObject(m1); var q2 = from o in pp.context.exerDetail where o.qid == ths.qid && o.typeq == 2 select o; List <exerDetail> tl = null; if (q2.Count() > 0) { tl = q2.ToList(); foreach (exerDetail ed in tl) { ed.qid = ths.sim; pp.context.UpdateObject(ed); MessageBox.Show("updata:" + ed.id); EXtools.checkd(pp, ed.lid); } } } if (ths.type1 == 3) { var q1 = from o in pp.context.SQues where o.id == ths.qid select o; SQues m1 = q1.First(); pp.context.DeleteObject(m1); var q2 = from o in pp.context.exerDetail where o.qid == ths.qid && o.typeq == 3 select o; List <exerDetail> tl = null; if (q2.Count() > 0) { tl = q2.ToList(); foreach (exerDetail ed in tl) { ed.qid = ths.sim; pp.context.UpdateObject(ed); MessageBox.Show("updata:" + ed.id); EXtools.checkd(pp, ed.lid); } } } if (ths.type1 == 4) { var q1 = from o in pp.context.AQues where o.id == ths.qid select o; AQues m1 = q1.First(); pp.context.DeleteObject(m1); var q2 = from o in pp.context.exerDetail where o.qid == ths.qid && o.typeq == 4 select o; List <exerDetail> tl = null; if (q2.Count() > 0) { tl = q2.ToList(); foreach (exerDetail ed in tl) { ed.qid = ths.sim; pp.context.UpdateObject(ed); MessageBox.Show("updata:" + ed.id); EXtools.checkd(pp, ed.lid); } } } //del question over updata over //del theinformation try { var q3 = from o in pp.context.featurehelp where o.id == ths.id select o; featurehelp fp2 = q3.First(); pp.context.DeleteObject(fp2); pp.context.SaveChanges(); dataGridView1.DataSource = null; hsl.Remove(ths); dataGridView1.DataSource = hsl; } catch (Exception e1) { MessageBox.Show(e1.ToString()); } } else { MessageBox.Show("Can not be deleted"); } } }
/////////////////////////////// private void reload2(int a) { if (dataGridView2.DataSource != null) { DataTable dt = (DataTable)dataGridView2.DataSource; dt.Rows.Clear(); dataGridView2.DataSource = dt; } else { dataGridView2.Rows.Clear(); } if (a == 0) { var questionQuery1 = from o in pp.context.exerDetail where o.lid == el.id && o.typeq == 0 orderby o.lorder select o; ell = questionQuery1.ToList <exerDetail>(); //add lorder int fflag = 0; foreach (exerDetail tel in ell) { if (tel.lorder == null) { fflag = 1; } } if (fflag == 1) { int ilorder = 1; foreach (exerDetail tel in ell) { tel.lorder = ilorder;; pp.context.UpdateObject(tel); ilorder++; } pp.context.SaveChanges(); } //end lorder foreach (exerDetail tel in ell) { var questionQuery2 = from o in pp.context.mchoiceQues where o.id == tel.qid select o; if (questionQuery2.Count() > 0) { mchoiceQues mcq = questionQuery2.First <mchoiceQues>(); System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); // rrtf.Add(richTextBox1.Rtf); DataGridViewRow dgvr = new DataGridViewRow(); // dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[2].Value = richTextBox1.Rtf; dgvr.Cells[1].Value = mcq.objective; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 8); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView2.Rows.Add(dgvr); } else { MessageBox.Show("有问题联系管理员" + tel.qid.ToString()); } } }//end0 if (a == 1) { var questionQuery1 = from o in pp.context.exerDetail where o.lid == el.id && o.typeq == 1 orderby o.lorder select o; ell = questionQuery1.ToList <exerDetail>(); //add lorder int fflag = 0; foreach (exerDetail tel in ell) { if (tel.lorder == null) { fflag = 1; } } if (fflag == 1) { int ilorder = 1; foreach (exerDetail tel in ell) { tel.lorder = ilorder;; pp.context.UpdateObject(tel); ilorder++; } pp.context.SaveChanges(); } //end lorder foreach (exerDetail tel in ell) { var questionQuery2 = from o in pp.context.TFQues where o.id == tel.qid select o; if (questionQuery2.Count() > 0) { TFQues mcq = questionQuery2.First <TFQues>(); System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); // rrtf.Add(richTextBox1.Rtf); DataGridViewRow dgvr = new DataGridViewRow(); // dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[2].Value = richTextBox1.Rtf; dgvr.Cells[1].Value = mcq.objective; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 8); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView2.Rows.Add(dgvr); } else { MessageBox.Show("有问题联系管理员" + tel.qid.ToString()); } } } //end1 if (a == 2 && el.pub == 3) { var questionQuery1 = from o in pp.context.exerDetail where o.lid == el.id && o.typeq == 2 orderby o.lorder select o; ell = questionQuery1.ToList <exerDetail>(); //add lorder int fflag = 0; foreach (exerDetail tel in ell) { if (tel.lorder == null) { fflag = 1; } } if (fflag == 1) { int ilorder = 1; foreach (exerDetail tel in ell) { tel.lorder = ilorder;; pp.context.UpdateObject(tel); ilorder++; } pp.context.SaveChanges(); } //end lorder foreach (exerDetail tel in ell) { var questionQuery2 = from o in pp.context.eQues where o.id == tel.qid select o; if (questionQuery2.Count() > 0) { eQues mcq = questionQuery2.First <eQues>(); System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); // rrtf.Add(richTextBox1.Rtf); DataGridViewRow dgvr = new DataGridViewRow(); // dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[2].Value = richTextBox1.Rtf; dgvr.Cells[1].Value = mcq.objective; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 8); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView2.Rows.Add(dgvr); } else { pp.context.DeleteObject(tel); pp.context.SaveChanges(); MessageBox.Show("有问题联系管理员" + tel.qid.ToString()); } } } //end2 if (a == 3) { var questionQuery1 = from o in pp.context.exerDetail where o.lid == el.id && o.typeq == 3 orderby o.lorder select o; ell = questionQuery1.ToList <exerDetail>(); //add lorder int fflag = 0; foreach (exerDetail tel in ell) { if (tel.lorder == null) { fflag = 1; } } if (fflag == 1) { int ilorder = 1; foreach (exerDetail tel in ell) { tel.lorder = ilorder;; pp.context.UpdateObject(tel); ilorder++; } pp.context.SaveChanges(); } //end lorder foreach (exerDetail tel in ell) { var questionQuery2 = from o in pp.context.SQues where o.id == tel.qid select o; if (questionQuery2.Count() > 0) { SQues mcq = questionQuery2.First <SQues>(); System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); // rrtf.Add(richTextBox1.Rtf); DataGridViewRow dgvr = new DataGridViewRow(); // dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[2].Value = richTextBox1.Rtf; dgvr.Cells[1].Value = mcq.objective; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 8); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView2.Rows.Add(dgvr); } else { MessageBox.Show("有问题联系管理员" + tel.qid.ToString()); } } } //end3 if (a == 4) { var questionQuery1 = from o in pp.context.exerDetail where o.lid == el.id && o.typeq == 4 orderby o.lorder select o; ell = questionQuery1.ToList <exerDetail>(); //add lorder int fflag = 0; foreach (exerDetail tel in ell) { if (tel.lorder == null) { fflag = 1; } } if (fflag == 1) { int ilorder = 1; foreach (exerDetail tel in ell) { tel.lorder = ilorder;; pp.context.UpdateObject(tel); ilorder++; } pp.context.SaveChanges(); } //end lorder foreach (exerDetail tel in ell) { var questionQuery2 = from o in pp.context.AQues where o.id == tel.qid select o; if (questionQuery2.Count() > 0) { AQues mcq = questionQuery2.First <AQues>(); System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false); this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); // rrtf.Add(richTextBox1.Rtf); DataGridViewRow dgvr = new DataGridViewRow(); // dataGridView2.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; foreach (DataGridViewColumn c in this.dataGridView2.Columns) { dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell); } dgvr.Cells[2].Value = richTextBox1.Rtf; dgvr.Cells[1].Value = mcq.objective; dgvr.Cells[0].Value = mcq.id; int hh = (int)(richTextBox1.Rtf.Length / 8); if (hh > 300) { hh = 300; } dgvr.Height = hh; this.dataGridView2.Rows.Add(dgvr); } else { MessageBox.Show("有问题联系管理员" + tel.qid.ToString()); } } } //end4 markselected(); }//end sub