Exemple #1
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedIndex >= 0)
     {
         exerL yex = l1[listBox1.SelectedIndex];
         if (textBox1.Text != "")
         {
             yex.name = textBox1.Text;
             pp.context.UpdateObject(yex);
             pp.context.SaveChanges();
             updatalist();
             textBox1.Text = "";
         }
         else
         {
             MessageBox.Show("请文本框中输入新名称");
         }
     }
     else
     {
         MessageBox.Show("请选择私有练习");
     }
 }
        ///////////////start

        private void display(int a, bool bb)
        {
            int numobjective  = -1;
            int con           = -1;
            int diff          = -1;
            var questionQuery = from o in context.exerL
                                where o.id == pp.exerl1
                                select o;

            exerL ell = questionQuery.First <exerL>();

            var questionQuery2 = from o in context.Course
                                 where o.id == ell.courseid
                                 select o;
            Course cc = questionQuery2.First <Course>();

            // pp.elword = l1[listBox1.SelectedIndex];
            // pp.vdlword = lcs[comboBox1.SelectedIndex];
            if (cc != null)
            {
                numobjective = (int)cc.numobjective;
                con          = (int)cc.numcontent;
                diff         = (int)cc.diff;
                if (bb)
                {
                    comboBox2.Items.Clear();
                    for (int i = 0; i < numobjective; i++)
                    {
                        comboBox2.Items.Add(i + 1);
                    }
                    comboBox3.Items.Clear();
                    for (int i = 0; i < con; i++)
                    {
                        comboBox3.Items.Add(i + 1);
                    }
                    comboBox4.Items.Clear();
                    for (int i = 0; i < diff; i++)
                    {
                        comboBox4.Items.Add(i + 1);
                    }
                }
                int  c1 = -1;
                int  c2 = -1;
                int  c3 = -1;
                bool b1 = false;
                bool b2 = false;
                bool b3 = false;
                if (comboBox2.Text != "")
                {
                    c1 = int.Parse(comboBox2.Text);
                }
                else
                {
                    b1 = true;
                }

                if (comboBox3.Text != "")
                {
                    c2 = int.Parse(comboBox3.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 == 0)
                {
                    // comboBox1.Text = comboBox1.Items[a].ToString();
                    comboBox5.Text = "1";

                    var questionQuery3 = (from o in context.mchoiceQues
                                          where (b1 || o.objective == c1) &&
                                          (b2 || o.con == c2) &&
                                          (b3 || o.diff == c3) &&
                                          (o.courseid == pp.cc1)
                                          select o).Skip(pageNum * pagesize).Take(pagesize);
                    List <mchoiceQues> lmq = questionQuery3.ToList <mchoiceQues>();


                    foreach (mchoiceQues mcq in lmq)
                    {
                        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);
                    }
                }


                /////end mq
                if (a == 1)
                {
                    // comboBox1.Text = comboBox1.Items[a].ToString();
                    comboBox5.Text = "1";
                    var questionQuery3 = (from o in context.TFQues
                                          where (b1 || o.objective == c1) &&
                                          (b2 || o.con == c2) &&
                                          (b3 || o.diff == c3) &&
                                          (o.courseid == pp.cc1)
                                          select o).Skip(pageNum * pagesize).Take(pagesize);
                    List <TFQues> lmq = questionQuery3.ToList <TFQues>();
                    this.dataGridView1.RowTemplate.Height = 100;
                    foreach (TFQues mcq in lmq)
                    {
                        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;
                        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 / 10);
                        if (hh > 300)
                        {
                            hh = 300;
                        }
                        dgvr.Height = hh;
                        this.dataGridView1.Rows.Add(dgvr);
                    }
                }
                ////endTF

                //startSques
                if (a == 3)
                {
                    // comboBox1.Text = comboBox1.Items[a].ToString();
                    comboBox5.Text = "5";
                    var questionQuery3 = (from o in context.SQues
                                          where (b1 || o.objective == c1) &&
                                          (b2 || o.con == c2) &&
                                          (b3 || o.diff == c3) &&
                                          (o.courseid == pp.cc1)
                                          select o).Skip(pageNum * pagesize).Take(pagesize);
                    List <SQues> lmq = questionQuery3.ToList <SQues>();
                    this.dataGridView1.RowTemplate.Height = 100;
                    foreach (SQues mcq in lmq)
                    {
                        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;
                        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 / 10);
                        if (hh > 300)
                        {
                            hh = 300;
                        }
                        dgvr.Height = hh;
                        this.dataGridView1.Rows.Add(dgvr);
                    }
                }
                //endSques


                //startAques
                if (a == 4)
                {
                    // comboBox1.Text = comboBox1.Items[a].ToString();
                    comboBox5.Text = "10";
                    var questionQuery3 = (from o in context.AQues
                                          where (b1 || o.objective == c1) &&
                                          (b2 || o.con == c2) &&
                                          (b3 || o.diff == c3) &&
                                          (o.courseid == pp.cc1)
                                          select o).Skip(pageNum * pagesize).Take(pagesize);
                    List <AQues> lmq = questionQuery3.ToList <AQues>();
                    this.dataGridView1.RowTemplate.Height = 100;
                    foreach (AQues mcq in lmq)
                    {
                        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;
                        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 / 10);
                        if (hh > 300)
                        {
                            hh = 300;
                        }
                        dgvr.Height = hh;
                        this.dataGridView1.Rows.Add(dgvr);
                    }
                }
                //endAques
            }
        }
Exemple #3
0
 public Dcheck(param p, exerL eel)
 {
     pp = p;
     el = eel;
     InitializeComponent();
 }
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
        //////////////////////////////
        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 #6
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 #7
0
 public void autogen(bool flag, int nums, int totalscore)
 {
     if (flag)
     {
         List <int> lobjetive = new List <int>();
         List <int> objectives = new List <int>();
         int        p = -1; int sump = 0;
         for (int i = 0; i < dataGridView2.Rows.Count; i++)
         {
             if (dataGridView2.Rows[i].Cells[1].Value != null)
             {
                 p = int.Parse(dataGridView2.Rows[i].Cells[1].Value.ToString());
             }
             else
             {
                 p = 0;
             }
             objectives.Add(p);
             sump = sump + p;
             lobjetive.Add(i + 1);
         }
         List <int> cons = new List <int>();
         int        q = -1; int sumq = 0;
         for (int i = 0; i < dataGridView3.Rows.Count; i++)
         {
             if (dataGridView3.Rows[i].Cells[1].Value != null)
             {
                 q = int.Parse(dataGridView3.Rows[i].Cells[1].Value.ToString());
             }
             else
             {
                 q = 0;
             }
             cons.Add(q);
             sumq = sumq + q;
         }
         if (sump != 100 || sumq != 100)
         {
             MessageBox.Show("Sum must be 100"); return;
         }
         List <exerL> ell = new List <ServiceReference1.exerL>();
         for (int i = 0; i < nums; i++)
         {
             exerL el = addexerL(textBox1.Text + i);
             if (el != null)
             {
                 ell.Add(el);
             }
             else
             {
                 return;
             }
         }
         updatalist();
         textBox1.Text = "";
         List <int> numt = new List <int>();
         numt.Add(int.Parse(textBox2.Text));
         numt.Add(int.Parse(textBox3.Text));
         numt.Add(int.Parse(textBox4.Text));
         numt.Add(int.Parse(textBox5.Text));
         numt.Add(int.Parse(textBox6.Text));
         List <int> snum = new List <int>();
         snum.Add(int.Parse(comboBox2.Text));
         snum.Add(int.Parse(comboBox3.Text));
         snum.Add(int.Parse(comboBox4.Text));
         snum.Add(int.Parse(comboBox5.Text));
         snum.Add(int.Parse(comboBox6.Text));
         addexerdetail(lcs[comboBox7.SelectedIndex], ell, objectives, cons, numt, snum, totalscore);
     }
     else
     {
     }
 }