Exemple #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            // try
            // {
            // Instantiate the DataServiceContext.
            if (checkem())
            {
                SQues mcq = new SQues();
                // 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;
                ////////////write richtext

                System.IO.MemoryStream mstream = new System.IO.MemoryStream();
                this.rquestion.SaveFile(mstream, RichTextBoxStreamType.RichText);
                System.IO.MemoryStream mstream2 = new System.IO.MemoryStream();
                this.richTextBox1.SaveFile(mstream2, RichTextBoxStreamType.RichText);
                //将流转换成数组
                //  byte[] bWrite = mstream.ToArray();
                mcq.question = mstream.ToArray();
                mcq.answ     = mstream2.ToArray();;

                if ((mcq.question.Length + mcq.answ.Length) < pp.maxsize)
                {
                    context.AddToSQues(mcq);
                    //////end write richtext

                    context.SaveChanges();
                    rquestion.Text    = "";
                    richTextBox1.Text = "";
                }
                else
                {
                    MessageBox.Show("请使用小一点的图片,建议不使用");
                }

                // Make the DataServiceCollection<T> the binding source for the Grid.
                //  }
                //  catch (Exception ex)
                // {
                //     MessageBox.Show(ex.ToString());
                // }
            }
            else
            {
                MessageBox.Show("请把数据填完整");
            }
        }
Exemple #2
0
 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);
     System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(ctf.answ, false);
     this.richTextBox3.LoadFile(mstream2, RichTextBoxStreamType.RichText);
     loadcom2();
     comboBox8.Text = ctf.con.ToString();
     comboBox7.Text = ctf.objective.ToString();
     comboBox6.Text = ctf.diff.ToString();
 }
        ////////////////////endexerdetail

        //////////////////////startexerdetail
        private void reloadd2(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  context.exerDetail
                                     where o.lid == pp.exerl1 && o.typeq == 0
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;
                foreach (exerDetail el in ell)
                {
                    var questionQuery2 = from o in context.mchoiceQues
                                         where o.id == el.qid
                                         select o;
                    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.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    int hh = (int)(richTextBox1.Rtf.Length / 10);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView2.Rows.Add(dgvr);
                }
            }
            if (a == 1)
            {
                var questionQuery1 = from o in context.exerDetail
                                     where o.lid == pp.exerl1 && o.typeq == 1
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;
                foreach (exerDetail el in ell)
                {
                    var questionQuery2 = from o in context.TFQues
                                         where o.id == el.qid
                                         select o;
                    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.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    int hh = (int)(richTextBox1.Rtf.Length / 10);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView2.Rows.Add(dgvr);
                }
            }

            /*
             * var questionQuery3 = from o in context.exerDetail
             *                   join cc in context. on o.qid equals cc.id
             *                   where (o.lid == pp.exerl1 && o.typeq == 0)
             *                   select o;
             */
            if (a == 3)
            {
                var questionQuery1 = from o in context.exerDetail
                                     where o.lid == pp.exerl1 && o.typeq == 3
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;
                foreach (exerDetail el in ell)
                {
                    var questionQuery2 = from o in context.SQues
                                         where o.id == el.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.id;
                        numm++;
                        dgvr.Cells[0].Value = numm;
                        int hh = (int)(richTextBox1.Rtf.Length / 10);
                        if (hh > 300)
                        {
                            hh = 300;
                        }
                        dgvr.Height = hh;
                        this.dataGridView2.Rows.Add(dgvr);
                    }
                }
            }
            if (a == 4)
            {
                var questionQuery1 = from o in context.exerDetail
                                     where o.lid == pp.exerl1 && o.typeq == 4
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;
                foreach (exerDetail el in ell)
                {
                    var questionQuery2 = from o in context.AQues
                                         where o.id == el.qid
                                         select o;
                    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.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    int hh = (int)(richTextBox1.Rtf.Length / 10);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView2.Rows.Add(dgvr);
                }
            }
        }
Exemple #4
0
        private void button4_Click(object sender, EventArgs e)
        {
            //导出联习

            if (sel2 >= 0)
            {
                // sel1 = comboBox1.SelectedIndex;
                // classinfo cin = lclinfo[sel1];
                //lce = getclexerl(cin);
                // erl = getexerl2(cin);
                //  persons.Join(cities, p => p.CityID, c => c.ID, (p, c) => new { PersonName = p.Name, CityName = c.Name });
                // var q1 = lce.Join(erl, p => p.eid, c => c.id, (p, c) => new { eid = p.eid, ename = c.name, stime = p.starttime, etime = p.endtime });
                //////////
                List <int> numofquestion = new List <int>(5);
                for (int i = 0; i < 5; i++)
                {
                    numofquestion.Add(0);
                }
                int biaoti = 1;
                /////////
                richTextBox2.Text = "";
                int   selid3 = int.Parse(dataGridView1.Rows[sel2].Cells[0].Value.ToString());
                exerL tel1   = null;
                tel1 = erl.Where(o => o.id == selid3).First();
                //exerL tel1 = erl[sel2];
                List <exerDetail> led = null;
                var q11 = from o in pp.context.exerDetail
                          where o.lid == tel1.id
                          orderby o.typeq, o.id
                select o;
                if (q11 != null)
                {
                    saveFileDialog1.DefaultExt = ".docx";
                    saveFileDialog1.Filter     = "WORD file|*.docx";

                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        Document doc = new Document();
                        Section  s   = doc.AddSection();



                        led = q11.ToList <exerDetail>();
                        foreach (exerDetail ed1 in led)
                        {
                            //get question
                            if (ed1.typeq == 0)
                            {
                                this.richTextBox2.Rtf = null;
                                var q12 = from o in pp.context.mchoiceQues
                                          where o.id == ed1.qid
                                          select o;
                                mchoiceQues            mcq     = q12.First <mchoiceQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                richTextBox1.Text = "";
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                //  this.richTextBox2.AppendText(richTextBox1.Rtf);
                                //get student answervar


                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == pp.st.studentid && o.did == ed1.id
                                          select o;

                                studAnsw tsa  = null;
                                String   key1 = "Question not being attemped";;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    tsa = q13.First <studAnsw>();
                                    if (tsa.answ1 == 0)
                                    {
                                        key1 = "A";
                                    }
                                    if (tsa.answ1 == 1)
                                    {
                                        key1 = "B";
                                    }
                                    if (tsa.answ1 == 2)
                                    {
                                        key1 = "C";
                                    }
                                    if (tsa.answ1 == 3)
                                    {
                                        key1 = "D";
                                    }
                                }
                                this.richTextBox2.AppendText("\n(" + key1 + ")_____________________________\n");
                                // this.richTextBox2.AppendText("_____________________________\n");


                                if (numofquestion[0] == 0)
                                {
                                    Paragraph para3 = s.AddParagraph();
                                    para3.AppendText(biaoti + ".选择题");
                                    biaoti++;
                                }
                                Paragraph para1 = s.AddParagraph();
                                numofquestion[0] = numofquestion[0] + 1;
                                para1.AppendRTF(numofquestion[0] + "." + richTextBox2.Rtf);
                            }
                            if (ed1.typeq == 1)
                            {
                                this.richTextBox2.Rtf = null;
                                var q12 = from o in pp.context.TFQues
                                          where o.id == ed1.qid
                                          select o;
                                TFQues mcq = q12.First <TFQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                richTextBox1.Text = "";
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                // this.richTextBox2.AppendText(richTextBox1.Rtf);
                                //get student answervar


                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == pp.st.studentid && o.did == ed1.id
                                          select o;

                                studAnsw tsa  = null;
                                String   key1 = "Question not being attemped";;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    tsa = q13.First <studAnsw>();
                                    if (tsa.answ2 == true)
                                    {
                                        key1 = "True";
                                    }
                                    if (tsa.answ2 == false)
                                    {
                                        key1 = "False";
                                    }
                                }
                                this.richTextBox2.AppendText("\n(" + key1 + ")_____________________________\n");
                                // this.richTextBox2.AppendText("\n_____________________________\n");
                                // Section s = doc.AddSection();
                                //  Paragraph para1 = s.AddParagraph();
                                // para1.AppendRTF(richTextBox2.Rtf);

                                if (numofquestion[1] == 0)
                                {
                                    Paragraph para3 = s.AddParagraph();
                                    para3.AppendText(biaoti + ".判断题");
                                    biaoti++;
                                }
                                Paragraph para1 = s.AddParagraph();
                                numofquestion[1] = numofquestion[1] + 1;
                                para1.AppendRTF(numofquestion[1] + "." + richTextBox2.Rtf);
                            }

                            if (ed1.typeq == 2)
                            {
                            }

                            if (ed1.typeq == 3)
                            {
                                this.richTextBox2.Rtf = null;

                                var q12 = from o in pp.context.SQues
                                          where o.id == ed1.qid
                                          select o;
                                SQues mcq = q12.First <SQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                //this.richTextBox2.AppendText(richTextBox1.Rtf );
                                //get student answervar
                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == pp.st.studentid && o.did == ed1.id
                                          select o;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    studAnsw tsa = q13.First <studAnsw>();
                                    //  String key1 = null;
                                    // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                    //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                    Byte[] mybyte = tsa.answ3;
                                    // MessageBox.Show(mybyte.Length.ToString());
                                    System.IO.MemoryStream ms = null;
                                    if (mybyte != null)
                                    {
                                        ms = new System.IO.MemoryStream(mybyte);
                                    }
                                    Image im = Image.FromStream(ms);
                                    int   w  = im.Size.Width;
                                    int   h  = im.Size.Height;
                                    //Section s = doc.AddSection();
                                    // Paragraph para1 = s.AddParagraph();
                                    // para1.AppendRTF(richTextBox2.Rtf);


                                    if (numofquestion[3] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".简答题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[3] = numofquestion[3] + 1;
                                    para1.AppendRTF(numofquestion[3] + "." + richTextBox2.Rtf);

                                    //  para1.AppendPicture(im);
                                    Paragraph  para2   = s.AddParagraph();
                                    DocPicture picture = para2.AppendPicture(im);
                                    //设置图片大小

                                    if (w < 450)
                                    {
                                        picture.Width  = w;
                                        picture.Height = h;
                                    }
                                    else
                                    {
                                        picture.Width  = 450;
                                        picture.Height = h * 450 / w;
                                        if (h * 450 / w > 450)
                                        {
                                            picture.Height = 450;
                                        }
                                    }
                                }
                                else
                                {
                                    this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                    this.richTextBox2.AppendText("\n_____________________________\n");
                                    // Paragraph para1 = s.AddParagraph();
                                    // para1.AppendRTF(richTextBox2.Rtf);

                                    if (numofquestion[3] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".简答题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[3] = numofquestion[3] + 1;
                                    para1.AppendRTF(numofquestion[3] + "." + richTextBox2.Rtf);
                                }
                            }
                            //////////////////////////////////////end3
                            if (ed1.typeq == 4)
                            {
                                this.richTextBox2.Rtf = null;

                                var q12 = from o in pp.context.AQues
                                          where o.id == ed1.qid
                                          select o;
                                AQues mcq = q12.First <AQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                //this.richTextBox2.AppendText(richTextBox1.Rtf );
                                //get student answervar
                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == pp.st.studentid && o.did == ed1.id
                                          select o;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    studAnsw tsa = q13.First <studAnsw>();
                                    //  String key1 = null;
                                    // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                    //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                    Byte[] mybyte = tsa.answ3;
                                    // MessageBox.Show(mybyte.Length.ToString());
                                    System.IO.MemoryStream ms = null;
                                    if (mybyte != null)
                                    {
                                        ms = new System.IO.MemoryStream(mybyte);
                                    }
                                    Image im = Image.FromStream(ms);
                                    int   w  = im.Size.Width;
                                    int   h  = im.Size.Height;
                                    //Section s = doc.AddSection();
                                    // Paragraph para1 = s.AddParagraph();
                                    // para1.AppendRTF(richTextBox2.Rtf);

                                    if (numofquestion[4] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".分析题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[4] = numofquestion[4] + 1;
                                    para1.AppendRTF(numofquestion[4] + "." + richTextBox2.Rtf);

                                    //  para1.AppendPicture(im);
                                    Paragraph  para2   = s.AddParagraph();
                                    DocPicture picture = para2.AppendPicture(im);
                                    //设置图片大小

                                    if (w < 450)
                                    {
                                        picture.Width  = w;
                                        picture.Height = h;
                                    }
                                    else
                                    {
                                        picture.Width  = 450;
                                        picture.Height = h * 450 / w;
                                        if (h * 450 / w > 450)
                                        {
                                            picture.Height = 450;
                                        }
                                    }
                                }
                                else
                                {
                                    this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                    this.richTextBox2.AppendText("\n_____________________________\n");
                                    // Paragraph para1 = s.AddParagraph();
                                    //para1.AppendRTF(richTextBox2.Rtf);
                                    if (numofquestion[4] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".分析题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[4] = numofquestion[4] + 1;
                                    para1.AppendRTF(numofquestion[4] + "." + richTextBox2.Rtf);
                                }
                            }

                            ////end4
                        }



                        //////////////////savertf//////////////////////


                        // richTextBox2.SaveFile(saveFileDialog1.FileName);
                        try
                        {
                            doc.SaveToFile(saveFileDialog1.FileName, FileFormat.Docx2013);
                            MessageBox.Show("WORD文件已生成!");
                        }
                        catch (Exception Err)
                        {
                            MessageBox.Show("WORD文件保存操作失败!" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                //////////////////////
            }
            else
            {
                MessageBox.Show("Please select an exercise!");
            }
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ////
            Global gb = Session["gb"] as Global;;;

            pp          = gb.pp;
            Label1.Text = Session["Lexserise"] as String;
            exeriseid   = Session["Lexserise"] as String;
            st          = Session["user"] as StudInfo;

            var questionQuery1 = from o in pp.context.exerDetail
                                 where o.lid == int.Parse(exeriseid) && o.typeq == 3
                                 orderby o.id
                                 select o;

            ell = questionQuery1.ToList <exerDetail>();

            int numm = 0;
            ///////////////////////////////////////////////////////////
            List <extime> ltemp = Session["ltemp"] as List <extime>;
            DateTime      dtnow = DateTime.Now;
            // DateTime stime = new DateTime();
            // DateTime etime = new DateTime();
            //"{ eid = 3164, ename = 20-21绪论, stime = 2020/10/12 0:00:00, etime = 2020/11/6 0:00:00 }
            bool benable = true;

            foreach (extime o in ltemp)
            {
                int lexid = o.eid;
                if (lexid == int.Parse(exeriseid))
                {
                    DateTime stime = (DateTime)o.stime;
                    DateTime etime = (DateTime)o.etime;
                    if (dtnow < stime || dtnow > etime)
                    {
                        benable = false;
                    }
                }
            }
            // if (!benable) Button1.Enabled = false;
            ////////////////////////////////////

            foreach (exerDetail eld in ell)
            {
                var questionQuery2 = from o in pp.context.SQues
                                     where o.id == eld.qid
                                     select o;
                SQues mcq = questionQuery2.First <SQues>();
                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                StreamReader           rt      = new StreamReader(mstream);
                RtfSource rs    = new RtfSource(rt);
                int       no    = numm + 1;
                var       html2 = Rtf.ToHtml(rs);
                //  viewDiv.InnerHtml  = no+"."+html2;
                HtmlGenericControl Div2 = new HtmlGenericControl();
                Div2.ID = "div" + numm;
                HtmlGenericControl Div3 = new HtmlGenericControl();
                Div3.ID = "div" + (numm + 1000);
                HtmlGenericControl Div4 = new HtmlGenericControl();
                Div4.ID = "pdiv" + numm;
                Button rbl = new Button();
                if (!benable)
                {
                    rbl.Enabled = false;
                }
                rbl.Click          += new System.EventHandler(this.but_Click);
                rbl.CommandArgument = numm.ToString();
                HtmlInputFile fbutton = new HtmlInputFile();
                fbutton.Accept = "image/*";
                fbutton.ID     = numm.ToString();
                lfb.Add(fbutton);
                // CommandArgument = "Descending"
                // OnCommand = "CommandBtn_Click"
                rbl.Text = "上传图片";
                rbl.ID   = "rbl" + numm;
                Image Image1            = new Image();
                HtmlGenericControl Div5 = new HtmlGenericControl();
                Div5.InnerHtml = "</br>" + "</br>";
                if (numm % 2 == 0)
                {
                    Div2.Style.Add("lcs", "OVERFLOW: auto; WIDTH: 400px; HEIGHT: 400px;color:blue;font-size:16px");
                }
                else
                {
                    Div2.Style.Add("lcs", "OVERFLOW: auto; WIDTH: 400px; HEIGHT: 400px;color: balck;font-size:16px");
                }

                ///读取答案
                var questionQuery3 = from o in pp.context.studAnsw
                                     where o.did == eld.id && o.lid == eld.lid && o.stid == st.studentid
                                     select o;
                if (questionQuery3.Count <studAnsw>() > 0)
                {
                    if (questionQuery3.First <studAnsw>().answ3 != null)
                    {
                        // bool ics = (bool)questionQuery3.First<studAnsw>().answ2;


                        //
                        //  Image himg = new Image();
                        // byte[] bytes = questionQuery3.First<studAnsw>().answ3;
                        // Response.BinaryWrite(bytes);
                        //  MemoryStream ms = new MemoryStream(bytes);
                        // himg = Image.FromStream(ms, true);
                        //
                        byte[]       bytes   = questionQuery3.First <studAnsw>().answ3;
                        MemoryStream MStream = new MemoryStream(bytes);
                        string       base64  = Convert.ToBase64String(MStream.ToArray());
                        Image1.ImageUrl   = "data:image/png;base64," + base64;
                        Image1.ImageAlign = ImageAlign.Middle;
                        // Image1.Width = 600;
                        Image1.Width = Unit.Percentage(70);
                        Div4.Controls.Add(Image1);
                    }
                }



                ////

                Div3.Controls.Add(fbutton);
                Div3.Controls.Add(rbl);
                Div2.InnerHtml = "</br>" + no + "." + html2 + "</br>";
                numm           = numm + 1;
                //   rrtf.Add(richTextBox1.Rtf);
                viewDiv.Controls.Add(Div2);

                viewDiv.Controls.Add(Div4);
                viewDiv.Controls.Add(Div5);
                viewDiv.Controls.Add(Div3);
                //查询答案

                /*var q2 = from q in pp.context.studAnsw
                 *       where q.lid == eld.lid && q.stid == pp.st.studentid && q.did == eld.id
                 *       select q;
                 * studAnsw answ1 = null;
                 #00FFFF
                 * if (q2.Count<studAnsw>() > 0) { answ1 = q2.First<studAnsw>(); Lmqansw.Add(answ1); }
                 * ell = questionQuery1.ToList<exerDetail>();
                 */
            }
            ////
        }
Exemple #6
0
        /////////////////////

        //loadq

        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.SQues
                                      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 <SQues>() > 0)
                {
                    lTF = questionQuery3.ToList <SQues>();


                    foreach (SQues 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("没有了啊!");
                }
            }
        }
Exemple #7
0
        //////////////////////////////
        private void toRTF(classinfo tci, exerL tel)
        {
            saveFileDialog1.DefaultExt = ".docx";
            saveFileDialog1.Filter     = "Word file|*.docx";
            String dirsave            = null;
            List <View_student> tlvst = null;
            exerL tel1 = tel;

            var q5 = from o in pp.context.View_student
                     where o.cid == tci.classid
                     select o;

            if (q5.Count <View_student>() > 0)
            {
                tlvst = q5.ToList <View_student>();
            }
            List <exerDetail> led = null;
            var q11 = from o in pp.context.exerDetail
                      where o.lid == tel1.id
                      orderby o.typeq, o.id
            select o;

            if (q11 != null)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    led = q11.ToList <exerDetail>();
                    string localFilePath = saveFileDialog1.FileName.ToString();
                    dirsave = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));

                    foreach (View_student vst in tlvst)
                    {
                        List <int> numofquestion = new List <int>(5);
                        for (int i = 0; i < 5; i++)
                        {
                            numofquestion.Add(0);
                        }
                        int biaoti = 1;
                        richTextBox1.Text      = "";
                        this.richTextBox2.Text = "";
                        //
                        Document doc = new Document();
                        Section  s   = doc.AddSection();
                        led = q11.ToList <exerDetail>();
                        foreach (exerDetail ed1 in led)
                        {
                            if (ed1.typeq == 0)
                            {
                                this.richTextBox2.Rtf = null;
                                var q12 = from o in pp.context.mchoiceQues
                                          where o.id == ed1.qid
                                          select o;
                                mchoiceQues            mcq     = q12.First <mchoiceQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                richTextBox1.Text = "";
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == vst.stid && o.did == ed1.id
                                          select o;
                                studAnsw tsa  = null;
                                String   key1 = "Question not being attemped";;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    tsa = q13.First <studAnsw>();
                                    if (tsa.answ1 == 0)
                                    {
                                        key1 = "A";
                                    }
                                    if (tsa.answ1 == 1)
                                    {
                                        key1 = "B";
                                    }
                                    if (tsa.answ1 == 2)
                                    {
                                        key1 = "C";
                                    }
                                    if (tsa.answ1 == 3)
                                    {
                                        key1 = "D";
                                    }
                                }
                                this.richTextBox2.AppendText("\n(" + key1 + ")_____________________________\n");
                                // this.richTextBox2.AppendText("_____________________________\n");

                                // Paragraph para1 = s.AddParagraph();
                                //para1.AppendRTF(richTextBox2.Rtf);
                                if (numofquestion[0] == 0)
                                {
                                    Paragraph para3 = s.AddParagraph();
                                    para3.AppendText(biaoti + ".选择题");
                                    biaoti++;
                                }
                                Paragraph para1 = s.AddParagraph();
                                numofquestion[0] = numofquestion[0] + 1;
                                para1.AppendRTF(numofquestion[0] + "." + richTextBox2.Rtf);
                            }
                            if (ed1.typeq == 1)
                            {
                                this.richTextBox2.Rtf = null;
                                var q12 = from o in pp.context.TFQues
                                          where o.id == ed1.qid
                                          select o;
                                TFQues mcq = q12.First <TFQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                richTextBox1.Text = "";
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                // this.richTextBox2.AppendText(richTextBox1.Rtf);
                                //get student answervar


                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == vst.stid && o.did == ed1.id
                                          select o;

                                studAnsw tsa  = null;
                                String   key1 = "Question not being attemped";;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    tsa = q13.First <studAnsw>();
                                    if (tsa.answ2 == true)
                                    {
                                        key1 = "True";
                                    }
                                    if (tsa.answ2 == false)
                                    {
                                        key1 = "False";
                                    }
                                }
                                this.richTextBox2.AppendText("\n(" + key1 + ")_____________________________\n");
                                // this.richTextBox2.AppendText("\n_____________________________\n");
                                // Section s = doc.AddSection();
                                // Paragraph para1 = s.AddParagraph();
                                // para1.AppendRTF(richTextBox2.Rtf);
                                if (numofquestion[1] == 0)
                                {
                                    Paragraph para3 = s.AddParagraph();
                                    para3.AppendText(biaoti + ".判断题");
                                    biaoti++;
                                }
                                Paragraph para1 = s.AddParagraph();
                                numofquestion[1] = numofquestion[1] + 1;
                                para1.AppendRTF(numofquestion[1] + "." + richTextBox2.Rtf);
                            }

                            if (ed1.typeq == 2)
                            {
                            }

                            if (ed1.typeq == 3)
                            {
                                this.richTextBox2.Rtf = null;

                                var q12 = from o in pp.context.SQues
                                          where o.id == ed1.qid
                                          select o;
                                SQues mcq = q12.First <SQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                //this.richTextBox2.AppendText(richTextBox1.Rtf );
                                //get student answervar
                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == vst.stid && o.did == ed1.id
                                          select o;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    studAnsw tsa = q13.First <studAnsw>();
                                    //  String key1 = null;
                                    // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                    //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                    Byte[] mybyte = tsa.answ3;
                                    // MessageBox.Show(mybyte.Length.ToString());
                                    System.IO.MemoryStream ms = null;
                                    if (mybyte != null)
                                    {
                                        ms = new System.IO.MemoryStream(mybyte);
                                    }
                                    Image im = Image.FromStream(ms);
                                    int   w  = im.Size.Width;
                                    int   h  = im.Size.Height;
                                    //Section s = doc.AddSection();
                                    //  Paragraph para1 = s.AddParagraph();
                                    //para1.AppendRTF(richTextBox2.Rtf);

                                    if (numofquestion[3] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".简答题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[3] = numofquestion[3] + 1;
                                    para1.AppendRTF(numofquestion[3] + "." + richTextBox2.Rtf);
                                    //  para1.AppendPicture(im);
                                    Paragraph  para2   = s.AddParagraph();
                                    DocPicture picture = para2.AppendPicture(im);
                                    //设置图片大小

                                    if (w < 450)
                                    {
                                        picture.Width  = w;
                                        picture.Height = h;
                                    }
                                    else
                                    {
                                        picture.Width  = 450;
                                        picture.Height = h * 450 / w;
                                        if (h * 450 / w > 450)
                                        {
                                            picture.Height = 450;
                                        }
                                    }
                                }
                                else
                                {
                                    this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                    this.richTextBox2.AppendText("\n_____________________________\n");
                                    // Paragraph para1 = s.AddParagraph();
                                    //para1.AppendRTF(richTextBox2.Rtf);

                                    if (numofquestion[3] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".简答题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[3] = numofquestion[3] + 1;
                                    para1.AppendRTF(numofquestion[3] + "." + richTextBox2.Rtf);
                                }
                            }
                            //////////////////////////////////////end3
                            if (ed1.typeq == 4)
                            {
                                this.richTextBox2.Rtf = null;

                                var q12 = from o in pp.context.AQues
                                          where o.id == ed1.qid
                                          select o;
                                AQues mcq = q12.First <AQues>();
                                System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                this.richTextBox2.LoadFile(mstream, RichTextBoxStreamType.RichText);
                                //this.richTextBox2.AppendText(richTextBox1.Rtf );
                                //get student answervar
                                var q13 = from o in pp.context.studAnsw
                                          where o.stid == vst.stid && o.did == ed1.id
                                          select o;
                                if (q13.Count <studAnsw>() > 0)
                                {
                                    studAnsw tsa = q13.First <studAnsw>();
                                    //  String key1 = null;
                                    // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                    //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                    Byte[] mybyte = tsa.answ3;
                                    // MessageBox.Show(mybyte.Length.ToString());
                                    System.IO.MemoryStream ms = null;
                                    if (mybyte != null)
                                    {
                                        ms = new System.IO.MemoryStream(mybyte);
                                    }
                                    Image im = Image.FromStream(ms);
                                    int   w  = im.Size.Width;
                                    int   h  = im.Size.Height;
                                    //Section s = doc.AddSection();
                                    // Paragraph para1 = s.AddParagraph();
                                    //  para1.AppendRTF(richTextBox2.Rtf);
                                    if (numofquestion[4] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".分析题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[4] = numofquestion[4] + 1;
                                    para1.AppendRTF(numofquestion[4] + "." + richTextBox2.Rtf);

                                    //  para1.AppendPicture(im);
                                    Paragraph  para2   = s.AddParagraph();
                                    DocPicture picture = para2.AppendPicture(im);
                                    //设置图片大小

                                    if (w < 450)
                                    {
                                        picture.Width  = w;
                                        picture.Height = h;
                                    }
                                    else
                                    {
                                        picture.Width  = 450;
                                        picture.Height = h * 450 / w;
                                        if (h * 450 / w > 450)
                                        {
                                            picture.Height = 450;
                                        }
                                    }
                                }
                                else
                                {
                                    this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                    this.richTextBox2.AppendText("\n_____________________________\n");
                                    // Paragraph para1 = s.AddParagraph();
                                    // para1.AppendRTF(richTextBox2.Rtf);
                                    if (numofquestion[4] == 0)
                                    {
                                        Paragraph para3 = s.AddParagraph();
                                        para3.AppendText(biaoti + ".分析题");
                                        biaoti++;
                                    }
                                    Paragraph para1 = s.AddParagraph();
                                    numofquestion[4] = numofquestion[4] + 1;
                                    para1.AppendRTF(numofquestion[4] + "." + richTextBox2.Rtf);
                                }
                            }

                            ////end4
                        }

                        //////////////////savedoc//////////////////////

                        String stsavepath = null;
                        stsavepath = dirsave + @"/" + vst.stid + vst.stname + ".docx";

                        // richTextBox2.SaveFile(saveFileDialog1.FileName);
                        try
                        {
                            doc.SaveToFile(stsavepath, FileFormat.Docx2013);
                        }
                        catch (Exception Err)
                        {
                            MessageBox.Show("WORD文件保存操作失败!" + Err.Message, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }//end eachstudent

                    MessageBox.Show("文档生成结束!");
                }
            }
        }
Exemple #8
0
        ////////////////////////////

        private void toRTF2(classinfo tci, exerL tel)
        {
            saveFileDialog1.DefaultExt = ".rtf";
            saveFileDialog1.Filter     = "RTF file|*.rtf";
            String dirsave            = null;
            List <View_student> tlvst = null;
            exerL tel1 = tel;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string localFilePath = saveFileDialog1.FileName.ToString();
                dirsave = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
            }

            var q5 = from o in pp.context.View_student
                     where o.cid == tci.classid
                     select o;

            if (q5.Count <View_student>() > 0)
            {
                tlvst = q5.ToList <View_student>();
            }
            List <exerDetail> led = null;
            var q11 = from o in pp.context.exerDetail
                      where o.lid == tel1.id
                      orderby o.typeq
                      select o;

            if (q11.Count <exerDetail>() > 0)
            {
                led = q11.ToList <exerDetail>();
            }
            foreach (View_student vst in tlvst)
            {
                richTextBox1.Text      = "";
                this.richTextBox2.Text = "";
                if (q11.Count <exerDetail>() > 0)
                {
                    // led = q11.ToList<exerDetail>();
                    foreach (exerDetail ed1 in led)
                    {
                        //get question
                        if (ed1.typeq == 0)
                        {
                            var q12 = from o in pp.context.mchoiceQues
                                      where o.id == ed1.qid
                                      select o;
                            mchoiceQues            mcq     = q12.First <mchoiceQues>();
                            System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                            richTextBox1.Text = "";
                            this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                            this.richTextBox2.AppendText(richTextBox1.Text);
                            //get student answervar


                            var q13 = from o in pp.context.studAnsw
                                      where o.stid == vst.stid && o.did == ed1.id
                                      select o;

                            studAnsw tsa  = null;
                            String   key1 = "Question not being attemped";;
                            if (q13.Count <studAnsw>() > 0)
                            {
                                tsa = q13.First <studAnsw>();
                                if (tsa.answ1 == 0)
                                {
                                    key1 = "A";
                                }
                                if (tsa.answ1 == 1)
                                {
                                    key1 = "B";
                                }
                                if (tsa.answ1 == 2)
                                {
                                    key1 = "C";
                                }
                                if (tsa.answ1 == 3)
                                {
                                    key1 = "D";
                                }
                            }
                            this.richTextBox2.AppendText("\n(" + key1 + ")");
                            this.richTextBox2.AppendText("\n_____________________________\n");
                        }
                        if (ed1.typeq == 1)
                        {
                            var q12 = from o in pp.context.TFQues
                                      where o.id == ed1.qid
                                      select o;
                            TFQues mcq = q12.First <TFQues>();
                            System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                            richTextBox1.Text = "";
                            this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                            this.richTextBox2.AppendText(richTextBox1.Text);
                            //get student answervar


                            var q13 = from o in pp.context.studAnsw
                                      where o.stid == vst.stid && o.did == ed1.id
                                      select o;

                            studAnsw tsa  = null;
                            String   key1 = "Question not being attemped";;
                            if (q13.Count <studAnsw>() > 0)
                            {
                                tsa = q13.First <studAnsw>();
                                if (tsa.answ2 == true)
                                {
                                    key1 = "True";
                                }
                                if (tsa.answ2 == false)
                                {
                                    key1 = "False";
                                }
                            }
                            this.richTextBox2.AppendText("\n(" + key1 + ")");
                            this.richTextBox2.AppendText("\n_____________________________\n");
                        }

                        if (ed1.typeq == 2)
                        {
                        }

                        if (ed1.typeq == 3)
                        {
                            var q12 = from o in pp.context.SQues
                                      where o.id == ed1.qid
                                      select o;
                            SQues mcq = q12.First <SQues>();
                            System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                            this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                            this.richTextBox2.AppendText(richTextBox1.Text);
                            //get student answervar


                            var q13 = from o in pp.context.studAnsw
                                      where o.stid == vst.stid && o.did == ed1.id
                                      select o;


                            if (q13.Count <studAnsw>() > 0)
                            {
                                studAnsw tsa = q13.First <studAnsw>();
                                //  String key1 = null;
                                // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                Byte[] mybyte             = tsa.answ3;
                                System.IO.MemoryStream ms = null;
                                if (mybyte != null)
                                {
                                    ms = new System.IO.MemoryStream(mybyte);
                                }
                                Image im = Image.FromStream(ms);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                Clipboard.SetDataObject(im, false);
                                richTextBox2.Paste();
                                this.richTextBox2.AppendText("\n_____________________________\n");
                            }
                            else
                            {
                                this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                this.richTextBox2.AppendText("\n_____________________________\n");
                            }
                        }
                        //////////////////////////////////////end3
                        if (ed1.typeq == 4)
                        {
                            var q12 = from o in pp.context.AQues
                                      where o.id == ed1.qid
                                      select o;
                            AQues mcq = q12.First <AQues>();
                            System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                            this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                            this.richTextBox2.AppendText(richTextBox1.Text);
                            //get student answervar


                            var q13 = from o in pp.context.studAnsw
                                      where o.stid == vst.stid && o.did == ed1.id
                                      select o;

                            if (q13.Count <studAnsw>() > 0)
                            {
                                studAnsw tsa = q13.First <studAnsw>();
                                //  String key1 = null;
                                // System.IO.MemoryStream mstream2 = new System.IO.MemoryStream(tsa.answ3 , false);
                                //this.richTextBox1.LoadFile(mstream2, RichTextBoxStreamType.RichText);
                                Byte[] mybyte             = tsa.answ3;
                                System.IO.MemoryStream ms = null;
                                if (mybyte != null)
                                {
                                    ms = new System.IO.MemoryStream(mybyte);
                                }
                                Image im = Image.FromStream(ms);
                                this.richTextBox2.AppendText("\n_____________________________\n");
                                Clipboard.SetDataObject(im, false);
                                richTextBox2.Paste();
                                this.richTextBox2.AppendText("\n_____________________________\n");
                            }
                            else
                            {
                                this.richTextBox2.AppendText("\n(" + "Question not being attemped" + ")");
                                this.richTextBox2.AppendText("\n_____________________________\n");
                            }
                        }

////end4
                    }
                }

                //////////////////savertf//////////////////////
                //  saveFileDialog1.DefaultExt = ".rtf";
                //   saveFileDialog1.Filter = "RTF file|*.rtf";

                //  if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                // {
                String stsavepath = null;
                stsavepath = dirsave + @"/" + vst.stid + vst.stname + ".rtf";

                richTextBox2.SaveFile(stsavepath);

                // }
                //////////////////////
            }
        }
Exemple #9
0
        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");
                }
            }
        }
Exemple #10
0
        ///////////////////////////////////////////////

        private void loadex(int a)
        {
            if (dataGridView1.DataSource != null)
            {
                DataTable dt = (DataTable)dataGridView1.DataSource;
                dt.Rows.Clear();
                dataGridView1.DataSource = dt;
            }
            else

            {
                dataGridView1.Rows.Clear();
            }

            if (a == 0)
            {
                dataGridView1.Columns[3].Visible = true;

                ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[3]).Items.Clear();
                ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[3]).Items.AddRange(new object[] {
                    "A",
                    "B",
                    "C",
                    "D"
                });


                ell = null;

                var questionQuery1 = from o in pp.context.exerDetail
                                     where o.lid == el.id && o.typeq == 0
                                     orderby o.id
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.mchoiceQues
                                         where o.id == eld.qid
                                         select o;
                    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();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                    //查询答案
                    var q2 = from q in pp.context.studAnsw
                             where q.lid == eld.lid && q.stid == pp.st.studentid && q.did == eld.id
                             select q;
                    studAnsw answ1 = null;

                    if (q2.Count <studAnsw>() > 0)
                    {
                        answ1 = q2.First <studAnsw>(); Lmqansw.Add(answ1);
                    }


                    foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                    {
                        dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                    }
                    dgvr.Cells[2].Value = richTextBox1.Rtf;
                    dgvr.Cells[1].Value = mcq.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    string mqkey = null;
                    if (answ1 != null)
                    {
                        if (answ1.answ1 == 0)
                        {
                            mqkey = "A";
                        }
                        if (answ1.answ1 == 1)
                        {
                            mqkey = "B";
                        }
                        if (answ1.answ1 == 2)
                        {
                            mqkey = "C";
                        }
                        if (answ1.answ1 == 3)
                        {
                            mqkey = "D";
                        }
                    }

                    dgvr.Cells[3].Value = mqkey;
                    int hh = (int)(richTextBox1.Rtf.Length / 10);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView1.Rows.Add(dgvr);
                }

                dataGridView1.Columns[4].Visible = false;
                dataGridView1.Columns[5].Visible = false;
            }//end 0

            if (a == 1)

            {
                ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[3]).Items.Clear();
                ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[3]).Items.AddRange(new object[] {
                    "True",
                    "False"
                });
                dataGridView1.Columns[3].Visible = true;
                ell = null;
                var questionQuery1 = from o in pp.context.exerDetail
                                     where o.lid == el.id && o.typeq == 1
                                     orderby o.id
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.TFQues
                                         where o.id == eld.qid
                                         select o;
                    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();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                    //查询答案
                    var q2 = from q in pp.context.studAnsw
                             where q.lid == eld.lid && q.stid == pp.st.studentid && q.did == eld.id
                             select q;
                    studAnsw answ1 = null;

                    if (q2.Count <studAnsw>() > 0)
                    {
                        answ1 = q2.First <studAnsw>(); Lmqansw.Add(answ1);
                    }


                    foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                    {
                        dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                    }
                    dgvr.Cells[2].Value = richTextBox1.Rtf;
                    dgvr.Cells[1].Value = mcq.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    if (answ1 != null)
                    {
                        if (answ1.answ2 != null)
                        {
                            bool mqkey = (bool)answ1.answ2;

                            dgvr.Cells[3].Value = mqkey.ToString();
                        }
                    }

                    int hh = (int)(richTextBox1.Rtf.Length / 8);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView1.Rows.Add(dgvr);
                }

                dataGridView1.Columns[4].Visible = false;
                dataGridView1.Columns[5].Visible = false;
            }//end 1

//填空题预留
////
            if (a == 3)

            {
                dataGridView1.Columns[3].Visible = false;

                dataGridView1.Columns[4].Visible = true;
                dataGridView1.Columns[5].Visible = true;
                if (ff.c_l == 3)
                {
                    dataGridView1.ReadOnly = true; dataGridView1.Columns[5].Visible = false;
                }
                if (ff.c_l == 2)
                {
                    dataGridView1.ReadOnly = false; dataGridView1.Columns[5].Visible = true;
                }


                ell = null;

                var questionQuery1 = from o in pp.context.exerDetail
                                     where o.lid == el.id && o.typeq == 3
                                     orderby o.id
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.SQues
                                         where o.id == eld.qid
                                         orderby o.id
                                         select o;
                    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();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                    //查询答案
                    var q2 = from q in pp.context.studAnsw
                             where q.lid == eld.lid && q.stid == pp.st.studentid && q.did == eld.id
                             select q;
                    studAnsw answ1            = null;
                    System.IO.MemoryStream ms = null;
                    if (q2.Count <studAnsw>() > 0)
                    {
                        answ1 = q2.First <studAnsw>(); Lmqansw.Add(answ1);
                        //读取图片
                        Byte[] mybyte = answ1.answ3;
                        if (mybyte != null)
                        {
                            ms = new System.IO.MemoryStream(mybyte);
                        }

                        //
                    }


                    foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                    {
                        dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                    }
                    dgvr.Cells[2].Value = richTextBox1.Rtf;
                    dgvr.Cells[1].Value = mcq.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    if (ms != null)
                    {
                        dgvr.Cells[4].Value = Image.FromStream(ms);
                    }
                    int hh = (int)(richTextBox1.Rtf.Length / 8);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView1.Rows.Add(dgvr);
                }
            }//end 3


            ////
            if (a == 4)

            {
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[4].Visible = true;
                dataGridView1.Columns[5].Visible = true;
                if (ff.c_l == 3)
                {
                    dataGridView1.ReadOnly = true; dataGridView1.Columns[5].Visible = false;
                }
                if (ff.c_l == 2)
                {
                    dataGridView1.ReadOnly = false; dataGridView1.Columns[5].Visible = true;
                }

                ell = null;
                var questionQuery1 = from o in pp.context.exerDetail
                                     where o.lid == el.id && o.typeq == 4
                                     orderby o.id
                                     select o;
                ell = questionQuery1.ToList <exerDetail>();

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.AQues
                                         where o.id == eld.qid
                                         select o;
                    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();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                    //查询答案
                    var q2 = from q in pp.context.studAnsw
                             where q.lid == eld.lid && q.stid == pp.st.studentid && q.did == eld.id
                             select q;
                    studAnsw answ1            = null;
                    System.IO.MemoryStream ms = null;
                    if (q2.Count <studAnsw>() > 0)
                    {
                        answ1 = q2.First <studAnsw>(); Lmqansw.Add(answ1);
                        //读取图片
                        Byte[] mybyte = answ1.answ3;
                        if (mybyte != null)
                        {
                            ms = new System.IO.MemoryStream(mybyte);
                        }

                        //
                    }


                    foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                    {
                        dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                    }
                    dgvr.Cells[2].Value = richTextBox1.Rtf;
                    dgvr.Cells[1].Value = mcq.id;
                    numm++;
                    dgvr.Cells[0].Value = numm;
                    if (ms != null)
                    {
                        dgvr.Cells[4].Value = Image.FromStream(ms);
                    }
                    int hh = (int)(richTextBox1.Rtf.Length / 8);
                    if (hh > 300)
                    {
                        hh = 300;
                    }
                    dgvr.Height = hh;
                    this.dataGridView1.Rows.Add(dgvr);
                }
            }//end 4
        }
Exemple #11
0
        ///////////////////////////////

        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