Пример #1
0
        ////////////////////////////savemqkey

        private void savemqk(int key, int did2)
        {
            DataGridViewRow dv  = this.dataGridView1.CurrentRow;
            int             qid = int.Parse(dv.Cells[1].Value.ToString());
            // MessageBox.Show(dv.Cells[1].Value.ToString());
            studAnsw sansw = new studAnsw();

            sansw.answ1 = key;
            sansw.stid  = pp.st.studentid;
            sansw.lid   = el.id;
            sansw.did   = did2;
            studAnsw sansw2 = null;
            var      q2     = from q in pp.context.studAnsw
                              where q.lid == el.id && q.stid == pp.st.studentid && q.did == did2
                              select q;

            if (q2.Count <studAnsw>() > 0)
            {
                sansw2 = q2.First <studAnsw>();
            }

            if (sansw2 == null)
            {
                sansw.mark = -100;
                pp.context.AddTostudAnsw(sansw);
            }
            else
            {
                sansw2.answ1 = key;
                pp.context.UpdateObject(sansw2);
            }
            pp.context.SaveChanges();
        }
Пример #2
0
        private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            //  MessageBox.Show("ok");
            if (e.ColumnIndex == 4 && listBox1.SelectedIndex == 3)
            {
                studAnsw stA  = null;
                int      qid  = -1;
                int      qid2 = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
                qid = getidinansw(3, qid2);
                string stid = lstv[dataGridView2.CurrentRow.Index].stid;
                //  var q2 = ltvdl.Where(o => o.Expr1 == qid && o.typeq == 3);
                var q3 = from o in pp.context.studAnsw
                         where o.did == qid && o.stid == stid && o.lid == el.id
                         select o;
                if (q3.Count <studAnsw>() > 0)
                {
                    stA      = q3.First <studAnsw>();
                    stA.mark = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString());

                    pp.context.UpdateObject(stA);
                    pp.context.SaveChanges();
                }
                //  MessageBox.Show("ok");
            }


            if (e.ColumnIndex == 4 && listBox1.SelectedIndex == 4)
            {
                studAnsw stA = null;
                //int qid = -1;
                //string stid = lstv[dataGridView2.CurrentRow.Index].stid;
                // int qid2 = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
                //qid = getidinansw(4, qid2);
                int qid  = -1;
                int qid2 = (int)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
                qid = getidinansw(4, qid2);
                string stid = lstv[dataGridView2.CurrentRow.Index].stid;
                var    q3   = from o in pp.context.studAnsw
                              where o.did == qid && o.stid == stid && o.lid == el.id
                              select o;
                if (q3.Count <studAnsw>() > 0)
                {
                    stA      = q3.First <studAnsw>();
                    stA.mark = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString());

                    pp.context.UpdateObject(stA);
                    pp.context.SaveChanges();
                }
                //  MessageBox.Show("ok");
            }
            ///////////////////////////////////////////////updata form show



            ///////////////////////////////////////////////////////////////////
        }
Пример #3
0
        //////////////////////////////////////


        private void saveimg(Byte[]   key3, int did3)
        {
            DataGridViewRow dv  = this.dataGridView1.CurrentRow;
            int             qid = int.Parse(dv.Cells[1].Value.ToString());
            // MessageBox.Show(dv.Cells[1].Value.ToString());
            studAnsw sansw = new studAnsw();

            sansw.answ3 = key3;
            sansw.stid  = pp.st.studentid;
            sansw.lid   = el.id;
            sansw.did   = did3;
            studAnsw sansw2 = null;

            try
            {
                var q3 = from q in pp.context.studAnsw
                         where q.lid == el.id && q.stid == pp.st.studentid && q.did == did3
                         select q;
                if (q3.Count <studAnsw>() > 0)
                {
                    sansw2 = q3.First <studAnsw>();
                }

                if (sansw2 == null)
                {
                    sansw.mark = -100;
                    pp.context.AddTostudAnsw(sansw);
                }
                else
                {
                    sansw2.answ3 = null;
                    sansw2.answ3 = key3;
                    pp.context.UpdateObject(sansw2);
                }
                pp.context.SaveChanges();
            }
            catch (Exception e)

            {
                MessageBox.Show(e.Message);
            }
        }
Пример #4
0
        ///////////////////////////////////////////

        private void markmqandTF()
        {
            // View_student vst = lstv[dataGridView2.CurrentRow.Index];
            var q0 = ltvdl.Where(o => o.typeq == 0);
            List <View_detai_exerL> ltvdl0 = q0.ToList <View_detai_exerL>();

            foreach (View_detai_exerL vde in ltvdl0)
            {
                var q01 = from o in pp.context.mchoiceQues
                          where o.id == vde.qid
                          orderby o.id
                          select new stkey {
                    qid = o.id, qkey = (int)o.answ, lid = (int)vde.Expr1
                };
                if (q01.Count() > 0)

                {
                    qansw.Add(q01.First());
                }
            }
            ////////////////////////////////////////endmq

            var t1 = ltvdl.Where(o => o.typeq == 1);
            List <View_detai_exerL> ltvdl1 = t1.ToList <View_detai_exerL>();

            foreach (View_detai_exerL vde in ltvdl1)
            {
                var t11 = from o in pp.context.TFQues
                          where o.id == vde.qid
                          orderby o.id
                          select  new stkey2 {
                    qid = o.id, qkey = (bool)o.answ, lid = (int)vde.Expr1
                };
                if (t11.Count() > 0)

                {
                    TFansw.Add(t11.First());
                }
            }



            //////////////////////////////////////////////////



            foreach (View_student vs in lstv)

            {
                //if (vs.stid== "20171113202") {

                foreach (View_detai_exerL vel in ltvdl)
                {
                    if (vel.typeq == 0)
                    {
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vs.stid
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw stA  = q1.First <studAnsw>();
                            stkey    bstk = qansw.Find(o => o.lid == stA.did && (o.qkey == stA.answ1 + 1));
                            if (bstk != null)
                            {
                                stA.mark = (int)vel.score;
                                pp.context.UpdateObject(stA);
                                // pp.context.SaveChanges();
                            }
                            else
                            {
                                stA.mark = 0;
                                pp.context.UpdateObject(stA);
                                // pp.context.SaveChanges();
                            }
                        }
                    }
                    ////////////////////////////////end 00
                    if (vel.typeq == 1)
                    {
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vs.stid
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw stA  = q1.First <studAnsw>();
                            stkey2   bstk = TFansw.Find(o => o.lid == stA.did && (o.qkey == (bool)stA.answ2));
                            if (bstk != null)
                            {
                                stA.mark = (int)vel.score;
                                pp.context.UpdateObject(stA);
                                // pp.context.SaveChanges();
                            }
                            else
                            {
                                stA.mark = 0;
                                pp.context.UpdateObject(stA);
                                // pp.context.SaveChanges();
                            }
                        }
                    }



                    ///////////////////////////////////////////////////////////

                    pp.context.SaveChanges();

                    // }
                }//for each vel
            }
        }
Пример #5
0
        private void showdatagrid()
        {
            dataGridView1.Rows.Clear();
            View_student vst   = lstv[dataGridView2.CurrentRow.Index];
            int          qtype = listBox1.SelectedIndex;

            if (qtype == 0)
            {
                //ltvdl
                dataGridView1.Columns[1].Visible = true;
                dataGridView1.Columns[2].Visible = true;
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[4].Visible = false;
                var q0 = ltvdl.Where(o => o.typeq == 0);
                List <View_detai_exerL> ltvdl0 = q0.ToList <View_detai_exerL>();
                foreach (View_detai_exerL vel in ltvdl0)
                {
                    if (vel.typeq == 0)
                    {
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vst.stid && o.lid == el.id
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw        stA  = q1.First <studAnsw>();
                            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[0].Value = vel.qid;
                            String an = "";
                            if (stA.answ1 == 0)
                            {
                                an = "A";
                            }
                            if (stA.answ1 == 1)
                            {
                                an = "B";
                            }
                            if (stA.answ1 == 2)
                            {
                                an = "C";
                            }
                            if (stA.answ1 == 3)
                            {
                                an = "D";
                            }
                            dgvr.Cells[1].Value = an;
                            dgvr.Cells[2].Value = stA.mark;
                            this.dataGridView1.Rows.Add(dgvr);

                            /////////////////////////////
                        }
                        else
                        {
                            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[0].Value = vel.qid;
                            dgvr.Cells[1].Value = null;
                            dgvr.Cells[2].Value = 0;
                            this.dataGridView1.Rows.Add(dgvr);
                        }
                    }
                }
            }//end0

            ////////////////////////////////////////////////
            if (qtype == 1)
            {
                //ltvdl
                dataGridView1.Columns[1].Visible = true;
                dataGridView1.Columns[2].Visible = true;
                dataGridView1.Columns[3].Visible = false;
                dataGridView1.Columns[4].Visible = false;
                var q0 = ltvdl.Where(o => o.typeq == 1);
                List <View_detai_exerL> ltvdl0 = q0.ToList <View_detai_exerL>();
                foreach (View_detai_exerL vel in ltvdl0)
                {
                    if (vel.typeq == 1)
                    {
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vst.stid && o.lid == el.id
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw        stA  = q1.First <studAnsw>();
                            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[0].Value = vel.qid;
                            dgvr.Cells[1].Value = stA.answ2;
                            dgvr.Cells[2].Value = stA.mark;
                            this.dataGridView1.Rows.Add(dgvr);

                            /////////////////////////////
                        }
                        else
                        {
                            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[0].Value = vel.qid;
                            dgvr.Cells[1].Value = null;
                            dgvr.Cells[2].Value = 0;
                            this.dataGridView1.Rows.Add(dgvr);
                        }
                    }
                }
            }
            ////////////////////////////////////////////////

            ///////////////////////////////////////end2



            if (qtype == 3)
            {
                //ltvdl

                var q0 = ltvdl.Where(o => o.typeq == 3);
                List <View_detai_exerL> ltvdl0 = q0.ToList <View_detai_exerL>();
                foreach (View_detai_exerL vel in ltvdl0)
                {
                    if (vel.typeq == 3)
                    {
                        //((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[4]).Items.Clear();
                        //  for (int i = 0; i <= vel.score; i++)
                        // {
                        //  a.Add(i);

                        //((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[4]).Items.Add(i.ToString());
                        // }
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vst.stid && o.lid == el.id
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw        stA  = q1.First <studAnsw>();
                            DataGridViewRow dgvr = new DataGridViewRow();
                            // dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                            foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                            {
                                dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                            }
                            DataGridViewComboBoxCell dc = (DataGridViewComboBoxCell)dgvr.Cells[4];
                            dc.Items.Clear();
                            for (int i = 0; i <= vel.score; i++)
                            {
                                dc.Items.Add(i.ToString());
                            }
                            dgvr.Cells[0].Value = vel.qid;
                            //  dgvr.Cells[1].Value = stA.answ2;
                            //  dgvr.Cells[2].Value = stA.mark;
                            System.IO.MemoryStream ms = null;
                            Byte[] mybyte             = stA.answ3;
                            if (mybyte != null)
                            {
                                ms = new System.IO.MemoryStream(mybyte);
                            }
                            if (ms != null)
                            {
                                dgvr.Cells[3].Value = Image.FromStream(ms);
                            }


                            if (stA.mark >= 0)
                            {
                                dgvr.Cells[4].Value = stA.mark.ToString();
                            }
                            // else
                            //  dgvr.Cells[4].Value = "0";
                            int hh = (int)ms.Length / 250;
                            //MessageBox.Show(hh.ToString());
                            if (hh > 350)
                            {
                                hh = 350;
                            }
                            dgvr.Height = hh;
                            this.dataGridView1.Rows.Add(dgvr);

                            /////////////////////////////
                        }
                        else
                        {
                            DataGridViewRow dgvr = new DataGridViewRow();


                            //dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
                            foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                            {
                                dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                            }
                            DataGridViewComboBoxCell dc = (DataGridViewComboBoxCell)dgvr.Cells[4];
                            dc.Items.Clear();
                            for (int i = 0; i <= vel.score; i++)
                            {
                                dc.Items.Add(i.ToString());
                            }
                            dgvr.Cells[0].Value = vel.qid;
                            //  dgvr.Cells[3].Value = null;
                            // ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[4]).Items.Clear();
                            // List<int>  a = new List<int>();

                            dgvr.Cells[4].Value = "0";
                            this.dataGridView1.Rows.Add(dgvr);
                        }
                    }
                }
                dataGridView1.Columns[1].Visible = false;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = true;
                dataGridView1.Columns[4].Visible = true;
            }



            /////////////////////////////            end3


            if (qtype == 4)
            {
                //ltvdl


                var q0 = ltvdl.Where(o => o.typeq == 4);
                List <View_detai_exerL> ltvdl0 = q0.ToList <View_detai_exerL>();
                foreach (View_detai_exerL vel in ltvdl0)
                {
                    if (vel.typeq == 4)
                    {
                        var q1 = from o in pp.context.studAnsw
                                 where o.did == vel.Expr1 && o.stid == vst.stid && o.lid == el.id
                                 select o;
                        if (q1.Count() > 0)
                        {
                            studAnsw        stA  = q1.First <studAnsw>();
                            DataGridViewRow dgvr = new DataGridViewRow();
                            // dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

                            foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                            {
                                dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                            }
                            DataGridViewComboBoxCell dc = (DataGridViewComboBoxCell)dgvr.Cells[4];
                            dc.Items.Clear();
                            for (int i = 0; i <= vel.score; i++)
                            {
                                dc.Items.Add(i.ToString());
                            }
                            dgvr.Cells[0].Value = vel.qid;
                            //  dgvr.Cells[1].Value = stA.answ2;
                            //  dgvr.Cells[2].Value = stA.mark;
                            System.IO.MemoryStream ms = null;
                            Byte[] mybyte             = stA.answ3;
                            if (mybyte != null)
                            {
                                ms = new System.IO.MemoryStream(mybyte);
                            }
                            if (ms != null)
                            {
                                dgvr.Cells[3].Value = Image.FromStream(ms);
                            }
                            //   ((System.Windows.Forms.DataGridViewComboBoxColumn)dataGridView1.Columns[4]).Items.Clear();


                            if (stA.mark >= 0)
                            {
                                dgvr.Cells[4].Value = stA.mark.ToString();
                            }
                            // else
                            //   dgvr.Cells[4].Value = "0";
                            int hh = (int)ms.Length / 250;
                            //MessageBox.Show(hh.ToString());
                            if (hh > 350)
                            {
                                hh = 350;
                            }
                            dgvr.Height = hh;
                            this.dataGridView1.Rows.Add(dgvr);

                            /////////////////////////////
                        }
                        else
                        {
                            DataGridViewRow dgvr = new DataGridViewRow();
                            //dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
                            foreach (DataGridViewColumn c in this.dataGridView1.Columns)
                            {
                                dgvr.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);
                            }
                            DataGridViewComboBoxCell dc = (DataGridViewComboBoxCell)dgvr.Cells[4];
                            dc.Items.Clear();
                            for (int i = 0; i <= vel.score; i++)
                            {
                                dc.Items.Add(i.ToString());
                            }
                            dgvr.Cells[0].Value = vel.qid;
                            //  dgvr.Cells[3].Value = null;
                            //
                            // List<int>  a = new List<int>();

                            dgvr.Cells[4].Value = "0";
                            this.dataGridView1.Rows.Add(dgvr);
                        }
                    }
                }

                dataGridView1.Columns[1].Visible = false;
                dataGridView1.Columns[2].Visible = false;
                dataGridView1.Columns[3].Visible = true;
                dataGridView1.Columns[4].Visible = true;
            }



            /////////////////////////////            end4
        }       //end shows
Пример #6
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!");
            }
        }
Пример #7
0
        //


        protected void but_Click(object sender, EventArgs e)
        {
            Button        rbl    = (Button)sender;
            int           indexp = int.Parse(rbl.CommandArgument);
            HtmlInputFile tfb    = lfb[indexp];

            HttpPostedFile file = tfb.PostedFile;

            try
            {
                Stream objFile;
                objFile = file.InputStream;
                BinaryReader objReader = new BinaryReader(objFile);
                //读取文件内容
                byte[] byteFile = objReader.ReadBytes((int)objFile.Length);
                if (objFile.Length > 350 * 1024)
                {
                    Response.Write("<script>window.alert('图片文件大于300k了')</script>");
                }

                else
                {
                    if (file.FileName == "" || file.ContentLength == 0)
                    {
                        Response.Write("<script>window.alert('请选择文件')</script>");
                    }
                    else
                    {
                        exerDetail tel            = ell[indexp];
                        var        questionQuery3 = from o in pp.context.studAnsw
                                                    where o.did == tel.id && o.lid == tel.lid && o.stid == st.studentid
                                                    select o;
                        if (questionQuery3.Count <studAnsw>() > 0)
                        {
                            studAnsw tst = questionQuery3.First <studAnsw>();
                            if (tst.answ3 != null)
                            {
                                tst.answ3 = byteFile;
                                pp.context.UpdateObject(tst);

                                pp.context.SaveChanges();


                                Response.AddHeader("Refresh", "0");
                            }
                        }
                        else
                        {
                            studAnsw tst = new studAnsw();
                            tst.did   = tel.id;
                            tst.lid   = tel.lid;
                            tst.stid  = st.studentid;
                            tst.answ3 = byteFile;

                            pp.context.AddTostudAnsw(tst);

                            pp.context.SaveChanges();

                            Response.AddHeader("Refresh", "0");
                        }
                    }
                }



                //文件扩展名
                //string strExtent = file.FileName.Substring(file.FileName.LastIndexOf("."));
            }
            catch (Exception ex)
            {
                // Response.Write(@"<script>window.alert('"+ ex .Message+ @"')</script>");
                System.Threading.Thread.Sleep(3000);
                Response.AddHeader("Refresh", "0");
            }


            //   Response.Write(@"<script>window.alert("+rbl+@")</script>");
        }
Пример #8
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("文档生成结束!");
                }
            }
        }
Пример #9
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);

                // }
                //////////////////////
            }
        }
Пример #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // String str= Request.QueryString["r0"];
            // Label1.Text = str;
            List <String> keystrl = new List <string>();
            //Global gb = new Global();
            Global  gb = Session["gb"] as Global;;
            paramst pp = gb.pp;

            exeriseid = Session["Lexserise"] as String;
            st        = Session["user"] as StudInfo;

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

            ell = questionQuery1.ToList <exerDetail>();
            for (int i = 0; i < ell.Count(); i++)
            {
                String index = "r" + i;
                String str   = Request.QueryString[index];
                keystrl.Add(str);
            }


            int num = 0;

            foreach (exerDetail eld in ell)
            {
                ///更新答案
                var questionQuery3 = from o in pp.context.studAnsw
                                     where o.did == eld.id && o.lid == eld.lid && o.stid == st.studentid
                                     select o;
                if (questionQuery3.Count <studAnsw>() > 0)
                {
                    // if (questionQuery3.First<studAnsw>().answ1 != null)
                    // {
                    int      cs      = -1;
                    studAnsw stanser = questionQuery3.First <studAnsw>();
                    if (keystrl[num] == "A")
                    {
                        cs = 0;
                    }
                    if (keystrl[num] == "B")
                    {
                        cs = 1;
                    }
                    if (keystrl[num] == "C")
                    {
                        cs = 2;
                    }
                    if (keystrl[num] == "D")
                    {
                        cs = 3;
                    }
                    if (cs != -1)
                    {
                        stanser.answ1 = cs;
                    }
                    pp.context.UpdateObject(stanser);

                    //  }
                }
                else
                {
                    if (keystrl[num] != null)
                    {
                        int cs = -1;
                        if (keystrl[num] == "A")
                        {
                            cs = 0;
                        }
                        if (keystrl[num] == "B")
                        {
                            cs = 1;
                        }
                        if (keystrl[num] == "C")
                        {
                            cs = 2;
                        }
                        if (keystrl[num] == "D")
                        {
                            cs = 3;
                        }
                        studAnsw tst = new studAnsw();
                        if (cs != -1)
                        {
                            tst.answ1 = cs;
                        }
                        tst.did  = eld.id;
                        tst.lid  = eld.lid;
                        tst.stid = st.studentid;
                        pp.context.AddTostudAnsw(tst);
                        pp.context.SaveChanges();
                    }
                }
                num++;
            }//endeach
            pp.context.SaveChanges();
        }
Пример #11
0
        ///////////////////////////////////////////////

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

            {
                dataGridView1.Rows.Clear();
            }

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

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


                ell = null;

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

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.mchoiceQues
                                         where o.id == eld.qid
                                         select o;
                    mchoiceQues            mcq     = questionQuery2.First <mchoiceQues>();
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                    this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                    //   rrtf.Add(richTextBox1.Rtf);
                    DataGridViewRow dgvr = new DataGridViewRow();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

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

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


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

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

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

            if (a == 1)

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

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.TFQues
                                         where o.id == eld.qid
                                         select o;
                    TFQues mcq = questionQuery2.First <TFQues>();
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                    this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                    //   rrtf.Add(richTextBox1.Rtf);
                    DataGridViewRow dgvr = new DataGridViewRow();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

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

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


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

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

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

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

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

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

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


                ell = null;

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

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.SQues
                                         where o.id == eld.qid
                                         orderby o.id
                                         select o;
                    SQues mcq = questionQuery2.First <SQues>();
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                    this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                    //   rrtf.Add(richTextBox1.Rtf);
                    DataGridViewRow dgvr = new DataGridViewRow();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

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

                        //
                    }


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


            ////
            if (a == 4)

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

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

                int numm = 0;

                foreach (exerDetail eld in ell)
                {
                    var questionQuery2 = from o in pp.context.AQues
                                         where o.id == eld.qid
                                         select o;
                    AQues mcq = questionQuery2.First <AQues>();
                    System.IO.MemoryStream mstream = new System.IO.MemoryStream(mcq.question, false);
                    this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                    //   rrtf.Add(richTextBox1.Rtf);
                    DataGridViewRow dgvr = new DataGridViewRow();
                    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;

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

                        //
                    }


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