Exemplo n.º 1
0
 public shiweipi(param pp1, classinfo cl1, View_class_exp vce1)
 {
     InitializeComponent();
     pp  = pp1;
     cl  = cl1;
     vce = vce1;
 }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (selindex >= 0)
            {
                classinfo tcl = lsc2[selindex];
                var       re  = from o in pp.context.classExer
                                where o.cid == tcl.classid
                                select o;
                if (re.Count <classExer>() > 0)
                {
                    MessageBox.Show("已经有练习关联不能删除!先去除关联或联系管理员");
                }
                else
                {
                    pp.context.DeleteObject(tcl);
                    pp.context.SaveChanges();
                }
            }
            listBox1.ValueMember = null;
            listBox1.DataSource  = null;

            var questionQuery2 = from p in context.classinfo
                                 where p.teacher == pp.teacher.teacherid
                                 select p;

            lsc2 = questionQuery2.ToList();
            // classinfo_Load(sender, e);
            listBox1.DataSource  = lsc2;
            listBox1.ValueMember = "classinfo1";
        }
Exemplo n.º 3
0
 public shiyan(paramst p, classinfo clin1, StudInfo stin1)
 {
     InitializeComponent();
     pp   = p;
     clin = clin1;
     stin = stin1;
 }
Exemplo n.º 4
0
 public nosubmit(param pp1, classinfo cl1, exerL el1)
 {
     InitializeComponent();
     pp = pp1;
     cl = cl1;
     el = el1;
 }
Exemplo n.º 5
0
        ////////////export all report
        private void exportreport(classinfo cl1, View_class_exp vst1)
        {
            String dirsave = null;
            List <View_class_student> lstwei = new List <View_class_student>();

            // List<View_class_student> lstall = null;

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



            List <studreport> lstrep = null;
            var questionQuery2       = from o in pp.context.studreport
                                       where o.classid == cl1.classid && o.expid == vst1.expid
                                       select o;

            if (questionQuery2.Count() > 0)
            {
                lstrep = questionQuery2.ToList <studreport>();

                foreach (studreport qew in lstrep)
                {
                    string attaDirectory = dirsave + @"\" + qew.stid + EXtools.getstuname(pp, qew.stid);
                    String repname       = qew.fname;
                    if (repname[repname.Length - 1] == 'x' || repname[repname.Length - 1] == 'X')
                    {
                        attaDirectory = attaDirectory + @".docx";
                    }
                    else
                    {
                        attaDirectory = attaDirectory + @".doc";
                    }

                    Byte[]       Files = qew.rep;
                    BinaryWriter bw    = new BinaryWriter(File.Open(attaDirectory, FileMode.OpenOrCreate));
                    bw.Write(Files);
                    bw.Close();
                    ///导出附件
                    ///
                    if (qew.aname != null && qew.atta != null)
                    {
                        string attaDirectory2 = dirsave + @"\" + qew.stid + EXtools.getstuname(pp, qew.stid);
                        attaDirectory2 = attaDirectory2 + @".rar";
                        Byte[]       Files2 = qew.atta;
                        BinaryWriter bw2    = new BinaryWriter(File.Open(attaDirectory2, FileMode.OpenOrCreate));
                        bw2.Write(Files2);
                        bw2.Close();
                    }
                }
            }
            else
            {
                MessageBox.Show("没有报告可以导出");
            }
        }
Exemplo n.º 6
0
        /// //////////
        private List <exerL> getexerl2(classinfo tcin)
        {
            List <exerL> tel = null;
            var          q1  = from o in pp.context.exerL
                               where o.courseid == tcin.courseid
                               select o;

            tel = q1.ToList();
            return(tel);
        }
Exemplo n.º 7
0
 public mark(TaskList tl1)
 {
     InitializeComponent();
     tl     = tl1;
     clinfo = tl.lclinfo[tl.sel1];
     pp     = tl.pp;
     lstv   = getstudent2(clinfo);
     el     = tl1.ler[tl.sel2];
     ltvdl  = getmqbylnio(el);
 }
Exemplo n.º 8
0
        ///////

        private List <classExer> getclexerl(classinfo tcin)
        {
            List <classExer> tel = null;
            var q1 = from o in pp.context.classExer
                     where o.cid == tcin.classid
                     select o;

            tel = q1.ToList();

            return(tel);
        }
Exemplo n.º 9
0
        ////////////////////////////
        private List <classExer> tlce(classinfo tcl)
        {
            List <classExer> tlce2 = null;
            var q2 = from o in pp.context.classExer
                     where o.cid == tcl.classid
                     select o;

            if (q2.Count <classExer>() > 0)
            {
                tlce2 = q2.ToList <classExer>();
            }


            return(tlce2);
        }
Exemplo n.º 10
0
        ////////////////////////

        private List <class_student> getclassstudent(classinfo tcinfo)
        {
            List <class_student> lcsl2 = new List <class_student>();

            var q1 = from o in pp.context.class_student
                     where o.classid == tcinfo.classid
                     select o;

            if (q1.Count <class_student>() > 0)
            {
                lcsl2 = q1.ToList <class_student>();
            }

            return(lcsl2);
        }
Exemplo n.º 11
0
        private List <View_student> getstudent2(classinfo tcinfo)
        {
            List <View_student> lst2 = new List <View_student>();

            var q1 = from o in pp.context.View_student

                     where o.cid == tcinfo.classid
                     select o;

            if (q1.Count <View_student>() > 0)
            {
                lst2 = q1.ToList <View_student>();
            }

            return(lst2);
        }
Exemplo n.º 12
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex >= 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 });

                ltemp = q1.OrderBy(s => s.stime).ToList <Object>();
                dataGridView1.DataSource = ltemp;
            }
        }
Exemplo n.º 13
0
        ////////////////////////////////////////

        private List <StudInfo> getstudent(classinfo tcinfo)
        {
            List <StudInfo>      lst2    = new List <StudInfo>();
            List <class_student> temp_cs = getclassstudent(tcinfo);

            foreach (class_student cs in temp_cs)
            {
                StudInfo st = null;
                var      q1 = from o in pp.context.StudInfo
                              where o.studentid == cs.studentid
                              select o;
                if (q1.Count <StudInfo>() > 0)
                {
                    st = q1.First <StudInfo>();
                }

                lst2.Add(st);
            }
            return(lst2);
        }
Exemplo n.º 14
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (selindex >= 0)
            {
                String yname = lsc2[selindex].classinfo1.ToString();
                foreach (classinfo cinfo in lsc2)
                {
                    if (cinfo.classinfo1.Trim() == textBox1.Text.Trim() && yname.Trim() != textBox1.Text.Trim())
                    {
                        MessageBox.Show("已有同样的班级名称请改名!"); return;
                    }
                }
                classinfo ci = lsc2[selindex];
                ci.classinfo1 = textBox1.Text;

                ci.teacher = pp.teacher.teacherid;
                ci.finish  = comboBox2.SelectedIndex;
                foreach (V_tea_course cc in lsc)
                {
                    if (comboBox1.Text == cc.CourseName)
                    {
                        ci.courseid = cc.couseid;
                    }
                }
                //  ci.addtime = System.DateTime.Now;
                context.UpdateObject(ci);
                context.SaveChanges();

                listBox1.ValueMember = null;
                listBox1.DataSource  = null;

                var questionQuery2 = from p in context.classinfo
                                     where p.teacher == pp.teacher.teacherid
                                     select p;

                lsc2 = questionQuery2.ToList();
                // classinfo_Load(sender, e);
                listBox1.DataSource  = lsc2;
                listBox1.ValueMember = "classinfo1";
            }
        }
Exemplo n.º 15
0
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            lvce = null;
            dataGridView1.DataSource = null;
            dataGridView1.Rows.Clear();

            if (listBox1.SelectedIndex >= 0)
            {
                classinfo clin = lcl[listBox1.SelectedIndex];

                var questionQuery = from o in pp.context.View_class_exp
                                    where (o.classid == clin.classid)
                                    orderby o.con
                                    select o;
                if (questionQuery.Count() > 0)
                {
                    lvce = questionQuery.ToList <View_class_exp>();
                }
                dataGridView1.AutoGenerateColumns = false;
                dataGridView1.DataSource          = lvce;
            }
        }
Exemplo n.º 16
0
 private void tlel(classinfo tcl)
 {
     lce = tlce(tcl);
     ler.Clear();
     ler_how.Clear();
     if (lce != null)
     {
         foreach (classExer ce in lce)
         {
             var q1 = from o in pp.context.exerL
                      where o.id == ce.eid
                      // select new { o.id ,o.name,ce.endtime };
                      select o;
             if (q1.Count <exerL>() > 0)
             {
                 exerL tel = q1.First <exerL>();
                 ler.Add(tel);
             }
         }
     }
     ////////////////////////////////////////
     if (lce != null)
     {
         foreach (classExer ce in lce)
         {
             var q2 = from o in pp.context.exerL
                      where o.id == ce.eid
                      select new { o.id, o.name, ce.endtime };
             List <Object> tll = q2.ToList <Object>();
             //  if (q2.Count<Object>()> 0)
             if (tll.Count == 1)
             {
                 object tel = tll[0];
                 ler_how.Add(tel);
             }
         }
     }
 }
Exemplo n.º 17
0
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Response.Write("<script>window.alert('your message')</script>");
            Session.Add("cindex", DropDownList1.SelectedIndex);
            if (DropDownList1.SelectedIndex >= 0)
            {
                sel1 = DropDownList1.SelectedIndex;
                // Response.Write(@"<script>window.alert('"+sel1+@"')</script>");
                classinfo cin = lclinfo[sel1];
                lce = getclexerl(cin);
                erl = getexerl2(cin);
                GridView1.DataSource = null;
                GridView1.DataBind();
                //  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 extime(p.eid, c.name, p.starttime, p.endtime));

                ltemp = q1.OrderBy(s => s.stime).ToList <extime>();
                GridView1.DataSource = ltemp;
                GridView1.DataBind();
                Session.Add("ltemp", ltemp);
                //

                var questionQuery = from o in pp.context.View_class_exp
                                    where (o.classid == cin.classid)
                                    orderby o.con
                                    select o;
                if (questionQuery.Count() > 0)
                {
                    lvce = questionQuery.ToList <View_class_exp>();
                }
                GridView2.DataSource = lvce;
                GridView2.DataBind();
                Session.Add("lvce", lvce);

                //
            }
        }
Exemplo n.º 18
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);

                // }
                //////////////////////
            }
        }
Exemplo n.º 19
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("文档生成结束!");
                }
            }
        }
Exemplo n.º 20
0
        //////////////////////////
        private void exportsum(classinfo cl1, View_class_exp vst1, V_tea_course vcourse, int poscol)
        {
            String dirsave = null;
            List <View_class_student> lstwei = new List <View_class_student>();

            // List<View_class_student> lstall = null;
            saveFileDialog2.DefaultExt = ".xlsx";
            saveFileDialog2.Filter     = "EXCEL file|*.xlsx";
            if (saveFileDialog2.ShowDialog() == DialogResult.OK)
            {
                string localFilePath = saveFileDialog2.FileName.ToString();
                // dirsave = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));
                dirsave = localFilePath;
            }

            //////////////////////excel

            Spire.Xls.Workbook wb = new Spire.Xls.Workbook();
            //清除默认的工作表
            wb.Worksheets.Clear();
            //添加一个工作表并指定表名
            Worksheet sheet = wb.Worksheets.Add("score");

            sheet.Range[2, 2].Text = "序号";
            sheet.Range[3, 2].Text = "分值";
            sheet.Range[4, 2].Text = "指标";
            sheet.Range[5, 1].Text = "学号";
            sheet.Range[5, 2].Text = "姓名";

            int    intobjective = vcourse.numobjective;
            String expobjective = vst1.objective;

            String[] strexpobj = expobjective.Split('|');

            for (int i = 1; i <= intobjective + 1; i++)
            {
                if (i < intobjective + 1)
                {
                    sheet.Range[4, poscol + i - 1].Text = i.ToString();
                }
                else
                {
                    sheet.Range[4, poscol + i - 1].Text = "已交";
                }
            }
            int irow           = 6;
            int icol           = poscol;
            var questionQuery1 = from o in pp.context.View_class_student
                                 where o.classid == cl1.classid
                                 orderby o.classno
                                 select o;
            List <View_class_student> lstall = null;

            if (questionQuery1.Count <View_class_student>() > 0)
            {
                lstall = questionQuery1.ToList <View_class_student>();
            }
            ///
            ///
            if (lstall != null)
            {
                foreach (View_class_student itvst in lstall)
                {
                    sheet.Range[irow, 1].Text = itvst.studentid;
                    sheet.Range[irow, 2].Text = itvst.name;


                    var questionQuery2 = from o in pp.context.studreport
                                         where o.classid == cl1.classid && o.expid == vst1.expid && o.stid == itvst.studentid
                                         select o;

                    studreport isturep = null;
                    if (questionQuery2.Count <studreport>() > 0)
                    {
                        isturep = questionQuery2.First <studreport>();
                        String   strmarks = isturep.score;
                        String[] strmark  = strmarks.Split('|');
                        for (int i = 1; i <= intobjective + 1; i++)
                        {
                            if (i < intobjective + 1)
                            {
                                sheet.Range[irow, poscol + i - 1].Value2 = 0;
                                for (int j = 1; j < strexpobj.Length; j++)
                                {
                                    if (i == int.Parse(strexpobj[j]))
                                    {
                                        sheet.Range[irow, poscol + i - 1].Value2 = int.Parse(strmark[j]);
                                    }
                                }
                            }
                            // else
                            // sheet.Range[irow, poscol + i - 1].Text = "NO";
                        }
                    }
                    else
                    {
                        for (int i = 1; i <= intobjective + 1; i++)
                        {
                            if (i < intobjective + 1)
                            {
                                sheet.Range[irow, poscol + i - 1].Value2 = 0;
                            }
                            else
                            {
                                sheet.Range[irow, poscol + i - 1].Text = "NO";
                            }
                        }
                    }



                    irow = irow + 1;
                } //foreach (View_class_stu
            }     /// end if( lstall !=null)
               ///



            sheet.AllocatedRange.AutoFitColumns();
            wb.SaveToFile(dirsave, ExcelVersion.Version2013);
            MessageBox.Show("excel生成好了");
        }