예제 #1
0
        private void Showall()//显示所有信息
        {
            //用自定义方法getcom()在对应数据表中查找是否有当前登陆用户
            SqlDataReader temDR = MyDataClass.getcom("select * from tb_Student where IDS='" + this.Info_ID.Text.Trim() + "'");
            bool          ifcom = temDR.Read();

            //当有记录时
            if (ifcom)
            {
                this.Tag = 1; //将窗口状态设置为浏览状态
                But_Status(); //改变按钮状态
                //根据指定条件查找通讯录信息,并将结果存储在DataSet数据集中
                MyDS_Grid                 = MyDataClass.getDataSet("select name,sex,class,IDT,assignmentID,email from tb_Student where IDS='" + this.Info_ID.Text.Trim() + "'", "tb_Student");
                this.Info_name.Text       = MyDS_Grid.Tables[0].Rows[0][0].ToString(); //显示姓名
                this.Info_sex.Text        = MyDS_Grid.Tables[0].Rows[0][1].ToString(); //显示性别
                this.Info_class.Text      = MyDS_Grid.Tables[0].Rows[0][2].ToString(); //显示班级
                this.Info_teacher.Text    = MyDS_Grid.Tables[0].Rows[0][3].ToString(); //显示教师姓名
                this.Info_assignment.Text = MyDS_Grid.Tables[0].Rows[0][4].ToString(); //显示作业
                this.Info_Email.Text      = MyDS_Grid.Tables[0].Rows[0][5].ToString(); //显示E-mail
            }
            else//不是第一次登陆
            {
                this.butAmend.Enabled  = false;
                this.butCancel.Enabled = false;
            }
        }
예제 #2
0
        private void 教师操作ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //用自定义方法getcom()在对应数据表中查找是否有当前登陆用户
            SqlDataReader temDR = MyDataClass.getcom("select * from tb_Teacher where IDT='" + DataClass.MyMeans.Login_ID.ToString() + "'");
            bool          ifcom = temDR.Read();

            //当有记录时,表示用户名已经修改过用户信息,此时只需要更新
            if (ifcom)
            {
            }
            else
            {
                if (MessageBox.Show("您的个人信息还未完善请填写", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    if (checkchildfrm("F_InfoT") == false)
                    {
                        F_InfoT F_ER = new F_InfoT();
                        F_ER.Text = "完善个人信息";
                        if (F_ER.ShowDialog() == DialogResult.OK)
                        {
                            MessageBox.Show("个人信息补充成功!欢迎进入操作系统教学实验平台!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);//行数为零警告
                        }
                    }
                }
            }
        }
예제 #3
0
        private void butLogin_Click(object sender, EventArgs e)
        {
            if (textName.Text != "" & textPass.Text != "")
            {                                          //数据表中查找是否有当前登录用户
                SQLiteDataReader temDR = MyMeans.getcom("select * from  tb_Login where Name='" + textName.Text.Trim() + "'and Pass='******'");
                bool             ifcom = temDR.Read(); //必须用Reab方法读
                //当有记录时表示用户名和密码正确
                if (ifcom)
                {
                    DataClass.MyMeans.Login_Name = textName.Text.Trim(); //将用户名记录到公共变量中
                    DataClass.MyMeans.Login_ID   = temDR.GetString(0);   //获取当前的操作员编号
                    DataClass.MyMeans.My_con.Close();
                    DataClass.MyMeans.My_con.Dispose();
                    DataClass.MyMeans.Login_n = (int)(this.Tag);//记录当前窗体的Tag属性

                    this.Close();
                }
                else
                {
                    MessageBox.Show("用户名或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textName.Text = "";
                    textPass.Text = "";
                }
            }
            else
            {
                MessageBox.Show("请将登录信息填写完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
예제 #4
0
        private void 查看内容ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string        title       = treeViewFolder.SelectedNode.Text;
            string        sqldefault  = "select * from tbl_note where title='" + title + "'";
            SqlDataReader userdefault = MyMeans.getcom(sqldefault);

            if (userdefault.Read())
            {
                string content = userdefault["content"].ToString();
                this.textBoxTitle.Text   = title;
                this.textBoxContent.Text = content;
            }
        }
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     txtChapterName.Clear();
     txtExpNum.Clear();
     txtRepNum.Clear();
     if (e.ColumnIndex != -1 && e.RowIndex != -1 && !dataGridView1.Rows[e.RowIndex].IsNewRow)
     {
         idc = dataGridView1.CurrentRow.Cells[1].Value.ToString();                                                             //获取操作的章节名
         txtChapterName.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();                                             //显示章节名
         txtChapNum.Text     = idc;                                                                                            //显示章节编号
         SqlDataReader temDR = MyClass.getcom("select count ('" + idc + "') as '份数' from tb_Report where IDC= '" + idc + "'"); //统计该章节的实验报告份数
         if (temDR.Read())
         {
             txtRepNum.Text = temDR.GetValue(temDR.GetOrdinal("份数")).ToString() + "份";                                //显示该章节的实验报告份数
         }
         temDR = MyClass.getcom("select count ('" + idc + "')  as '份数' from tb_Experiment where IDC= '" + idc + "'"); //统计该章节的实验数
         if (temDR.Read())
         {
             txtExpNum.Text = temDR.GetValue(temDR.GetOrdinal("份数")).ToString() + "份";//显示该章节的实验数
         }
     }
 }
예제 #6
0
 //修改所属文件夹
 public void alterinfo()
 {
     if (fm.uc1.uclist.textBoxtitle.Text.Trim() == fm.textBoxTitle.Text.Trim())
     {
         fm.uc1.uclist.textBoxcontent.Text = fm.textBoxContent.Text;
         string        sqldefault  = "select * from tbl_note where title='" + fm.textBoxTitle.Text.Trim() + "'";
         SqlDataReader userdefault = MyMeans.getcom(sqldefault);
         if (userdefault.Read())
         {
             string dbfoldername = userdefault["foldername"].ToString();
             fm.uc1.uclist.textBoxfolder.Text = dbfoldername;
         }
     }
 }
예제 #7
0
        //一点uclist中的删除就在uclist3中增加带有以下信息的控件
        public void addInfo()
        {
            String        SQLstr = "select * from tbl_rabbish order by rtime desc";
            SqlDataReader note   = MyMeans.getcom(SQLstr);

            if (note.Read())
            {
                string dbtitle   = note["rtitle"].ToString();
                string dbcontent = note["rcontent"].ToString();
                string dbtime    = note["rtime"].ToString();
                this.textBoxtitle.Text   = dbtitle;
                this.textBoxcontent.Text = dbcontent;
                this.textBoxtime.Text    = dbtime;
            }
        }
예제 #8
0
        //一点保存所要增加的用户控件显示的信息
        public void addInfo()
        {
            String        SQLstr = "select * from tbl_note where title='" + fm.textBoxTitle.Text.Trim() + "'";
            SqlDataReader note   = MyMeans.getcom(SQLstr);

            if (note.Read())
            {
                string dbtitle   = note["title"].ToString();
                string dbcontent = note["content"].ToString();
                string dbtime    = note["time"].ToString();
                string dbfolder  = note["foldername"].ToString();
                this.textBoxtitle.Text   = dbtitle;
                this.textBoxcontent.Text = dbcontent;
                this.textBoxtime.Text    = dbtime;
                this.textBoxfolder.Text  = dbfolder;
            }
        }
예제 #9
0
        private void butAccept_Click(object sender, EventArgs e)
        {
            SqlDataReader temDR = MyClass.getcom("select * from tb_UserLogin where popenum ='" + DataClass.MyMeans.Login_ID.ToString() + "'"); //查找权限标识跟当前登录人ID相同的记录

            if (temDR.Read())                                                                                                                  //如果有记录
            {
                if (txtPwd.Text.Trim() == temDR.GetString(temDR.GetOrdinal("password")))                                                       //如果输入的密码跟记录相同
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("密码错误!", "提示");
                    txtPwd.Text = "";
                }
            }
        }
예제 #10
0
 private void Login()
 {
     try
     {
         if (txtUserName.Text != "" & txtUserPwd.Text != "")
         {
             //用自定义方法getcom()在Login数据表中查找是否有当前登陆用户
             SqlDataReader temDR = MyClass.getcom("select * from tb_UserLogin where name='" + txtUserName.Text.Trim() + "'and password='******'");
             bool          ifcom = temDR.Read();
             //当有记录时,表示用户名和密码正确
             if (ifcom)
             {
                 string today = DateTime.Now.ToString("yyyy年MM月");                                        //获取当天时间
                 DataClass.MyMeans.Login_Name = txtUserName.Text.Trim();                                  //将用户名记录到公共变量中
                 DataClass.MyMeans.Login_ID   = temDR.GetValue(temDR.GetOrdinal("popenum")).ToString();   //获取权限下的编号
                 DataClass.MyMeans.Login_Time = DateTime.Now.ToString();                                  //获取当前登录时间
                 DataClass.MyMeans.User_Pope  = temDR.GetString(temDR.GetOrdinal("pope"));                //获取当前登录者权限
                 DataClass.MyMeans.User_Pwd   = temDR.GetString(temDR.GetOrdinal("password"));            //获取当前登录者密码
                 DataClass.MyMeans.User_ID    = Convert.ToInt32(temDR.GetValue(temDR.GetOrdinal("IDU"))); //获取当前登录者ID
                 this.Hide();                                                                             //关闭当前窗口
                 F_Parent Main = new F_Parent();                                                          //建立新窗口
                 Main.Show();                                                                             //显示新窗口
             }
             else
             {
                 MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示具有指定内容的消息框
                 txtUserName.Text = "";                                                                //用户名密码错误时将会把用户名和密码栏都清空
                 txtUserPwd.Text  = "";
                 txtUserName.Focus();                                                                  //鼠标焦点指向用户名栏便于用户重新输入
             }
             MyClass.con_close();                                                                      //关闭数据库连接
         }
         else
         {
             MessageBox.Show("请将登录信息添加完整!", "信息输入不完整", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "警告");
     }
 }
예제 #11
0
        private void FormPersonInfo_Load(object sender, EventArgs e)
        {
            InfopanelTop.BackColor = ColorTranslator.FromHtml("#398dee");
            textBoxname.Text       = fm.toolStripMenuuser.Text;

            string        sqldefault  = "select * from tbl_person_info where username='******'";
            SqlDataReader userdefault = MyMeans.getcom(sqldefault);

            if (userdefault.Read())
            {
                string dbrealname    = userdefault["realname"].ToString();
                string dbphone       = userdefault["phone"].ToString();
                string dbdeacription = userdefault["deacription"].ToString();
                string dbprovince    = userdefault["province"].ToString();
                string dbcounty      = userdefault["county"].ToString();
                textrealname.Text    = dbrealname;
                textphone.Text       = dbphone;
                textdeacription.Text = dbdeacription;
                textprovince.Text    = dbprovince;
                textcounty.Text      = dbcounty;
            }
        }
예제 #12
0
        private void FormMyCounter_Load(object sender, EventArgs e)
        {
            panelcountertop.BackColor = ColorTranslator.FromHtml("#398dee");
            labelname.Text            = fm.toolStripMenuuser.Text;
            string        sqldefault = "select * from tbl_person_info where username='******'";
            SqlDataReader personInfo = MyMeans.getcom(sqldefault);

            if (personInfo.Read())
            {
                string dbphone = personInfo["phone"].ToString();
                textphone.Text = dbphone;
            }

            string        registerSql  = "select * from tbl_user where username='******'";
            SqlDataReader registertime = MyMeans.getcom(registerSql);

            if (registertime.Read())
            {
                DateTime time = DateTime.Parse(registertime["logintime"].ToString());
                texttime.Text = "亲爱的" + fm.toolStripMenuuser.Text + ",您在" + time + "注册了灵盘笔记。";
            }
        }
예제 #13
0
 private void buttonLogin_Click(object sender, EventArgs e)
 {
     if (textUsername.Text != null & textPassword.Text != null)
     {
         String        SQLstr = "select * from tbl_user where username='******'and password='******'";
         SqlDataReader user   = MyMeans.getcom(SQLstr);
         bool          ifcom  = user.Read();
         if (ifcom)
         {
             MyMeans.con_close();
             string time = DateTime.Now.ToString();
             this.Hide();
             fm.toolStripMenuuser.Text = textUsername.Text;
             fm.ShowDialog();
         }
         else
         {
             i++;
             if (i >= 3)
             {
                 buttonLogin.Enabled = false;
                 textError.Text      = "密码错误3次,请退出!";
             }
             else
             {
                 textError.Text    = "用户名或密码错误,请重新输入!";
                 textPassword.Text = "";
                 textPassword.Focus();
             }
         }
         MyMeans.con_close();
     }
     else
     {
         textError.Text = "请将登录信息填写完整!";
         textPassword.Focus();
     }
 }
        /*public bool CreateWordFile(string CheckedInfo)
         * {
         *  try
         *  {
         *      Object Nothing = System.Reflection.Missing.Value;
         *      if (!Directory.Exists("D:/创建Word测试"))
         *      {
         *          //如果要创建的目录不存在则创建目录
         *          Directory.CreateDirectory("D:/创建Word测试");//创建文件所在目录
         *      }
         *      string name = "学生实验" + DataClass.MyMeans.Login_ID + DateTime.Now.ToString() + ".doc";
         *      object filename = "D://创建Word测试//" + name;//文件保存路径
         *      //创建Word文档
         *      Word.Application WordApp = new Word.Application();
         *      Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
         *      //嵌入Word内容
         *      WordApp.Selection.ParagraphFormat.LineSpacing = 15f; // 设置文档的行间距
         *      //插入段落
         *      //WordApp.Selection.TypeParagraph();
         *      Word.Paragraph para;
         *      para = WordDoc.Content.Paragraphs.Add(ref Nothing);
         *      //正常格式
         *      para.Range.Font.Bold = 2;
         *      //para.Range.Font.Color = WdColor.wdColorRed;
         *      //para.Range.Font.Italic = 2;
         *      para.Range.Text = groupBox8.Text;//插入标题"基本信息"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = labelChapterName.Text+cb_ChapterName.Text;//插入章节名
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = labelStudentName.Text + txtStudentName.Text +" "+ labelStudentNum.Text+txtStudentNum.Text;//插入学生名和学号
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Font.Bold = 2;
         *      para.Range.Text = groupBox1.Text;//插入"实验题目"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = txtTitle.Text;//插入实验题目
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Font.Bold = 2;
         *      para.Range.Text = groupBox2.Text;//插入"问题描述"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = txtDescription.Text;//插入问题描述
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Font.Bold = 2;
         *      para.Range.Text = groupBox3.Text;//插入"算法设计"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = txtALG.Text;//插入算法设计
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Font.Bold = 2;
         *      para.Range.Text = groupBox4.Text;//插入"运行结果"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = txtRunning.Text;//插入运行结果
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Font.Bold = 2;
         *      para.Range.Text = groupBox5.Text;//插入"问题与收获"
         *      para.Range.InsertParagraphAfter();
         *      para.Range.Text = txtQuestion.Text;//插入问题与收获
         *      para.Range.InsertParagraphAfter();
         *      //落款
         *      WordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();
         *      WordDoc.Paragraphs.Last.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
         *      //文件保存
         *      WordDoc.SaveAs(ref  filename, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing, ref  Nothing);
         *      WordDoc.Close(ref  Nothing, ref  Nothing, ref  Nothing);
         *      WordApp.Quit(ref  Nothing, ref  Nothing, ref  Nothing);
         *      return true;
         *  }
         *  catch (Exception ex)
         *  {
         *      MessageBox.Show(ex.Message,"警告");
         *      return false;
         *  }
         * }*/

        private void F_DoExperiment_Load(object sender, EventArgs e)
        {
            if (this.Tag.Equals(0))//如果为学生新建实验报告模式
            {
                //初始化窗体中的学生信息
                this.txtStudentNum.Text      = DataClass.MyMeans.Login_ID; //显示学号
                this.txtStudentName.Text     = DataClass.Student.name;     //显示学生名
                this.txtStudentNum.ReadOnly  = true;
                this.txtStudentName.ReadOnly = true;
                //this.txtTime.Text = DateTime.Now.ToString();//显示开始实验的系统时间
                this.txtTime.Text      = DateTime.Now.AddDays(0).ToString("yyyy年MM月dd日"); //获取当天时间
                this.txtTime.ReadOnly  = true;
                this.txtTitle.Text     = DataClass.Experiment.ExperimentDone_Title;       //显示正在进行的实验名
                this.txtTitle.ReadOnly = true;
                // TODO: 这行代码将数据加载到表“db_BSDataSet.tb_Chapter”中。您可以根据需要移动或删除它。
                this.tb_ChapterTableAdapter.Fill(this.db_BSDataSet.tb_Chapter);
                this.cb_ChapterName.Enabled = false;
            }
            else
            {
                if (this.Tag.Equals(1))//学生浏览实验报告模式
                {
                    //设置各个按钮不可用
                    this.butAccept.Enabled         = false;
                    this.butClear.Enabled          = false;
                    this.butExperimentView.Enabled = false;
                    this.butPic.Text = "查看图片";
                    //this.butSaveAsWord.Enabled = false;
                    try
                    {
                        SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forStudent + "'");
                        if (temDR.Read())
                        {
                            this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                            this.txtTime.ReadOnly = true;
                            SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + temDR.GetValue(temDR.GetOrdinal("IDC")) + "'");
                            if (temDR2.Read())
                            {
                                this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                                this.cb_ChapterName.Enabled = false;//设置章节名只读
                            }
                            this.txtStudentNum.Text = temDR.GetString(temDR.GetOrdinal("IDS"));
                            SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS ='" + this.txtStudentNum.Text.Trim() + "'");
                            if (temDR3.Read())
                            {
                                this.txtStudentName.Text = temDR3.GetString(temDR3.GetOrdinal("name"));
                            }
                            this.txtStudentNum.ReadOnly  = true;
                            this.txtStudentName.ReadOnly = true;
                            this.txtTitle.Text           = temDR.GetString(temDR.GetOrdinal("title"));
                            this.txtTitle.ReadOnly       = true;
                            this.txtDescription.Text     = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                            this.txtDescription.ReadOnly = true;
                            this.txtALG.Text             = temDR.GetString(temDR.GetOrdinal("ALG"));
                            this.txtALG.ReadOnly         = true;
                            this.txtRunning.Text         = temDR.GetString(temDR.GetOrdinal("running"));
                            this.txtRunning.ReadOnly     = true;
                            this.txtQuestion.Text        = temDR.GetString(temDR.GetOrdinal("question"));
                            this.txtQuestion.ReadOnly    = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else
                {
                    if (this.Tag.Equals(2))//学生修改模式
                    {
                        //初始化窗体中的学生信息
                        this.txtStudentNum.Text      = DataClass.MyMeans.Login_ID; //显示学号
                        this.txtStudentNum.ReadOnly  = true;
                        this.txtStudentName.Text     = DataClass.Student.name;     //显示学生名
                        this.txtStudentName.ReadOnly = true;
                        try
                        {
                            SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forStudent + "'");
                            if (temDR.Read())
                            {
                                this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                                this.txtTime.ReadOnly = true;
                                int           Charnum = Convert.ToInt32(temDR.GetValue(temDR.GetOrdinal("IDC")));
                                SqlDataReader temDR2  = MyClass.getcom("select * from tb_Chapter where IDC='" + Charnum + "'");
                                if (temDR2.Read())
                                {
                                    this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                                    this.cb_ChapterName.Enabled = false;//设置章节名只读
                                }
                                this.txtTitle.Text       = temDR.GetString(temDR.GetOrdinal("title"));
                                this.txtTitle.ReadOnly   = true;//设置标题只读
                                this.txtDescription.Text = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                                this.txtALG.Text         = temDR.GetString(temDR.GetOrdinal("ALG"));
                                this.txtRunning.Text     = temDR.GetString(temDR.GetOrdinal("running"));
                                this.txtQuestion.Text    = temDR.GetString(temDR.GetOrdinal("question"));
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    else
                    {
                        if (this.Tag.Equals(3))//教师浏览实验报告模式
                        {
                            //设置各个按钮不可用
                            this.butPic.Text               = "查看图片";
                            this.butAccept.Enabled         = false;
                            this.butClear.Enabled          = false;
                            this.butExperimentView.Enabled = false;
                            //this.butSaveAsWord.Enabled = false;
                            try
                            {
                                SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forTeacher + "'");
                                if (temDR.Read())
                                {
                                    this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                                    this.txtTime.ReadOnly = true;
                                    SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + temDR.GetValue(temDR.GetOrdinal("IDC")) + "'");
                                    if (temDR2.Read())
                                    {
                                        this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                                        this.cb_ChapterName.Enabled = false;//设置章节名只读
                                    }
                                    this.txtStudentNum.Text = temDR.GetString(temDR.GetOrdinal("IDS"));
                                    SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS ='" + this.txtStudentNum.Text.Trim() + "'");
                                    if (temDR3.Read())
                                    {
                                        this.txtStudentName.Text = temDR3.GetString(temDR3.GetOrdinal("name"));
                                    }
                                    this.txtStudentNum.ReadOnly  = true;
                                    this.txtStudentName.ReadOnly = true;
                                    this.txtTitle.Text           = temDR.GetString(temDR.GetOrdinal("title"));
                                    this.txtTitle.ReadOnly       = true;
                                    this.txtDescription.Text     = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                                    this.txtDescription.ReadOnly = true;
                                    this.txtALG.Text             = temDR.GetString(temDR.GetOrdinal("ALG"));
                                    this.txtALG.ReadOnly         = true;
                                    this.txtRunning.Text         = temDR.GetString(temDR.GetOrdinal("running"));
                                    this.txtRunning.ReadOnly     = true;
                                    this.txtQuestion.Text        = temDR.GetString(temDR.GetOrdinal("question"));
                                    this.txtQuestion.ReadOnly    = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                            }
                        }
                        else
                        {
                            if (this.Tag.Equals(4))//如果是学生重做模式,初始化功能与修改基本相同,只需要修改该模式下提交按钮的功能
                            {
                                //初始化窗体中的学生信息
                                this.txtStudentNum.Text      = DataClass.MyMeans.Login_ID; //显示学号
                                this.txtStudentNum.ReadOnly  = true;
                                this.txtStudentName.Text     = DataClass.Student.name;     //显示学生名
                                this.txtStudentName.ReadOnly = true;
                                try
                                {
                                    SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forStudent + "'");
                                    if (temDR.Read())
                                    {
                                        this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                                        this.txtTime.ReadOnly = true;
                                        int           Charnum = Convert.ToInt32(temDR.GetValue(temDR.GetOrdinal("IDC")));
                                        SqlDataReader temDR2  = MyClass.getcom("select * from tb_Chapter where IDC='" + Charnum + "'");
                                        if (temDR2.Read())
                                        {
                                            this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                                            this.cb_ChapterName.Enabled = false;//设置章节名只读
                                        }
                                        this.txtTitle.Text       = temDR.GetString(temDR.GetOrdinal("title"));
                                        this.txtTitle.ReadOnly   = true;//设置标题只读
                                        this.txtDescription.Text = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                                        this.txtALG.Text         = temDR.GetString(temDR.GetOrdinal("ALG"));
                                        this.txtRunning.Text     = temDR.GetString(temDR.GetOrdinal("running"));
                                        this.txtQuestion.Text    = temDR.GetString(temDR.GetOrdinal("question"));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
 private void Accept()
 {
     try
     {
         if (txtUserName.Text != "" && txtPwd.Text != "" && txtPwd2.Text != "")
         {
             //用自定义方法getcom()在Login数据表中查找是否有当前登陆用户
             SqlDataReader temDR = MyClass.getcom("select * from tb_UserLogin where name='" + txtUserName.Text.Trim() + "' or popenum='" + txtpopenum.Text.Trim() + "'");
             bool          ifcom = temDR.Read();
             //当有记录时,表示用户名或权限号已经被注册
             if (ifcom)
             {
                 MessageBox.Show("该用户名或权限号已经被使用,请重新注册!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示具有指定内容的消息框
                 txtUserName.Clear();                                                                             //用户名已经被注册时将会把用户名和密码栏都清空
                 txtPwd.Clear();
                 txtPwd2.Clear();
                 txtpopenum.Clear();
                 txtUserName.Focus();//鼠标焦点指向用户名栏便于用户重新输入
             }
             else//未重复注册
             {
                 if (txtPwd.Text.Trim() != txtPwd2.Text.Trim())                                                   //如果两个密码栏中密码不同
                 {
                     MessageBox.Show("两次输入密码不一致,请重新注册!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示具有指定内容的消息框
                     txtPwd.Clear();
                     txtPwd2.Clear();
                     txtPwd.Focus();//鼠标焦点指向密码栏1以便于重新输入密码
                 }
                 else//两个密码栏密码想同
                 {
                     if (radioButton1.Checked || radioButton2.Checked)//身份按钮有被选中
                     {
                         string pope = radioButton1.Checked == true ? "T" : "S";
                         //此处代码仍然按照教师号指定设计而非自动生成,如果需要教师号自动生成,则pope="T"的情况中代码需要修改
                         if (pope == "S")
                         {
                             SqlDataReader Reg = MyClass.getcom("insert into tb_UserLogin (name,password,pope,popenum) values('" + txtUserName.Text.Trim() + "','" + txtPwd.Text.ToString() + "','" + pope + "','" + txtpopenum.Text.Trim() + "')");
                             MessageBox.Show("请妥善保管您的登录名和密码并登录系统!", "注册成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             this.Close();//关闭当前窗口
                             F_Login Login = new OSM.F_Login();
                             Login.Show();
                         }
                         else
                         {
                             if (pope == "T")
                             {
                                 SqlDataReader Reg = MyClass.getcom("insert into tb_UserLogin (name,password,pope,popenum) values('" + txtUserName.Text.Trim() + "','" + txtPwd.Text.ToString() + "','" + pope + "','" + txtpopenum.Text.Trim() + "')");
                                 MessageBox.Show("请妥善保管您的登录名和密码并登录系统!", "注册成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                 this.Close();//关闭当前窗口
                                 F_Login Login = new OSM.F_Login();
                                 Login.Show();
                             }
                         }
                     }
                     else
                     {
                         MessageBox.Show("请勾选注册身份!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     }
                 }
             }
         }
         else
         {
             MessageBox.Show("请将注册信息添加完整!", "信息输入不完整", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "警告");
     }
 }
예제 #16
0
        string AllRep = "SELECT [IDR] AS 报告编号,[IDE] AS 实验编号,[IDS] AS 学生学号,[date] AS 完成时间,[title] AS 实验名称,REPLACE(REPLACE([flagCorrect],1,'已批改'),0,'未批改')状态,[mark] AS 实验成绩 from tb_Report where flagSubmit='true'"; //若已经退回的实验报告则不考虑,只显示已经提交的

        public string makesql(string sql, string ARsign)                                                                                                                                                           //组装查询sql语句
        {
            if (cb_ChapterName.Text.Trim() != "")                                                                                                                                                                  //如果实验章节有选择
            {
                string        a;
                SqlDataReader MyDR = MyClass.getcom("select * from tb_Chapter where name ='" + cb_ChapterName.Text.Trim() + "'");
                if (MyDR.Read())
                {
                    int id = Convert.ToInt32(MyDR.GetValue(0));
                    if (id < 10)
                    {
                        a = "0" + id.ToString();
                    }
                    else
                    {
                        a = id.ToString();
                    }
                    //sql += ARsign +"[IDC] LIKE '__" + a + "__'";
                    sql += ARsign + "[IDC] ='" + a + "'";
                }
            }
            if (cb_TeacherName.Text.Trim() != "")//如果实验章节有选择
            {
                string        a;
                SqlDataReader MyDR = MyClass.getcom("select * from tb_Teacher where name ='" + cb_TeacherName.Text.Trim() + "'");
                if (MyDR.Read())
                {
                    int id = Convert.ToInt32(MyDR.GetValue(0));
                    if (id < 10)
                    {
                        a = "0" + id.ToString();
                    }
                    else
                    {
                        a = id.ToString();
                    }
                    sql += ARsign + "IDT = '" + a + "'";
                }
            }
            if (txtDate.Text.ToString() != "")//如果输入了时间
            {
                string a = "%" + txtDate.Text.ToString() + "%";
                sql += ARsign + " [date] LIKE '" + a + "'";
            }
            if (txtTitle.Text.ToString() != "")//如果输入了实验标题
            {
                string a = "%" + txtTitle.Text.ToString() + "%";
                sql += ARsign + " [title] LIKE '" + a + "'";
            }

            if (txtCondition.Text.ToString() != "")      //如果输入了关键字
            {
                if (radioButtonStuClass.Checked == true) //如果输入的是学生班级
                {
                    string a = "%" + txtCondition.Text.Trim() + "%";
                    sql += ARsign + " [class] LIKE '" + a + "'";
                }
                else
                {
                    if (radioButtonStuName.Checked == true)                                                                                   //如果输入的是学生名
                    {
                        SqlDataReader MyDR = MyClass.getcom("select * from tb_Student where name like '%" + txtCondition.Text.Trim() + "%'"); //先搜索该学生是否存在
                        if (MyDR.Read())
                        {
                            string ids = MyDR.GetString(MyDR.GetOrdinal("IDS")).ToString();
                            sql += ARsign + "[IDS] LIKE '" + ids + "'";//如果该学生存在,则将查到的学号套入查找
                        }
                        else
                        {
                            sql += ARsign + "[IDS] LIKE '    '";//如果该学生不存在,则学号为空白
                        }
                    }
                    else
                    {
                        if (radioButtonStuNum.Checked == true)//如果输入的是学生学号
                        {
                            string a = "%" + txtCondition.Text.Trim() + "%";
                            sql += ARsign + " [IDS] LIKE '" + a + "'";
                        }
                        else
                        {
                            MessageBox.Show("请点选关键词条件!", "提示");
                        }
                    }
                }
            }
            if (cb_MarkStatus.Text != "全部" && cb_MarkStatus.Text != "")//如果是批改状态查询
            {
                if (cb_MarkStatus.Text == "已批改")
                {
                    sql += ARsign + "flagCorrect='true' and flagCorrect is not null";
                }
                else
                {
                    if (cb_MarkStatus.Text == "未批改")
                    {
                        sql += ARsign + "flagCorrect='false' and flagCorrect is not null";
                    }
                }
            }
            if (cb_Mark.Text != "全部" && cb_Mark.Text != "")//如果按分数范围查询
            {
                if (cb_Mark.Text == "不及格")
                {
                    sql += ARsign + "mark<60";
                }
                if (cb_Mark.Text == "60 - 70分")
                {
                    sql += ARsign + "mark>60 and mark<70 and mark is not null";
                }
                if (cb_Mark.Text == "70 - 80分")
                {
                    sql += ARsign + "mark>70 and mark<80 and mark is not null";
                }
                if (cb_Mark.Text == "80 - 90分")
                {
                    sql += ARsign + " mark>80 and mark<90 and mark is not null";
                }
                if (cb_Mark.Text == "90 - 满分")
                {
                    sql += ARsign + "mark>90 and mark<100 and mark is not null";
                }
            }
            return(sql);
        }
예제 #17
0
 private void F_GiveMark_Load(object sender, EventArgs e)
 {
     if (this.Tag.Equals(0))//如果是教师第一次批改实验报告模式
     {
         this.butAmend.Enabled  = false;
         this.butCancel.Enabled = false;
         try
         {
             SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forTeacher + "'");
             if (temDR.Read())
             {
                 this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                 this.txtTime.ReadOnly = true;
                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + temDR.GetValue(temDR.GetOrdinal("IDC")) + "'");
                 if (temDR2.Read())
                 {
                     this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                     this.cb_ChapterName.Enabled = false;//设置章节名只读
                 }
                 this.txtStudentNum.Text = temDR.GetString(temDR.GetOrdinal("IDS"));
                 SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS ='" + this.txtStudentNum.Text.Trim() + "'");
                 if (temDR3.Read())
                 {
                     this.txtStudentName.Text = temDR3.GetString(temDR3.GetOrdinal("name"));
                 }
                 this.txtStudentNum.ReadOnly  = true;
                 this.txtStudentName.ReadOnly = true;
                 this.txtTitle.Text           = temDR.GetString(temDR.GetOrdinal("title"));
                 this.txtTitle.ReadOnly       = true;
                 this.txtDescription.Text     = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                 this.txtDescription.ReadOnly = true;
                 this.txtALG.Text             = temDR.GetString(temDR.GetOrdinal("ALG"));
                 this.txtALG.ReadOnly         = true;
                 this.txtRunning.Text         = temDR.GetString(temDR.GetOrdinal("running"));
                 this.txtRunning.ReadOnly     = true;
                 this.txtQuestion.Text        = temDR.GetString(temDR.GetOrdinal("question"));
                 this.txtQuestion.ReadOnly    = true;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else
     {
         if (this.Tag.Equals(1))//如果是教师修改已经批改过的报告模式
         {
             this.butOK.Enabled     = false;
             this.butCancel.Enabled = false;
             try
             {
                 SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forTeacher + "'");
                 if (temDR.Read())
                 {
                     this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                     this.txtTime.ReadOnly = true;
                     SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + temDR.GetValue(temDR.GetOrdinal("IDC")) + "'");
                     if (temDR2.Read())
                     {
                         this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                         this.cb_ChapterName.Enabled = false;//设置章节名只读
                     }
                     this.txtStudentNum.Text = temDR.GetString(temDR.GetOrdinal("IDS"));
                     SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS ='" + this.txtStudentNum.Text.Trim() + "'");
                     if (temDR3.Read())
                     {
                         this.txtStudentName.Text = temDR3.GetString(temDR3.GetOrdinal("name"));
                     }
                     this.txtStudentNum.ReadOnly  = true;
                     this.txtStudentName.ReadOnly = true;
                     this.txtTitle.Text           = temDR.GetString(temDR.GetOrdinal("title"));
                     this.txtTitle.ReadOnly       = true;
                     this.txtDescription.Text     = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                     this.txtDescription.ReadOnly = true;
                     this.txtALG.Text             = temDR.GetString(temDR.GetOrdinal("ALG"));
                     this.txtALG.ReadOnly         = true;
                     this.txtRunning.Text         = temDR.GetString(temDR.GetOrdinal("running"));
                     this.txtRunning.ReadOnly     = true;
                     this.txtQuestion.Text        = temDR.GetString(temDR.GetOrdinal("question"));
                     this.txtQuestion.ReadOnly    = true;
                     this.txtMark.Text            = temDR.GetString(temDR.GetOrdinal("mark"));
                     this.txtMark.ReadOnly        = true;
                     this.txtEvaluation.Text      = temDR.GetString(temDR.GetOrdinal("evaluation"));
                     this.txtEvaluation.ReadOnly  = true;
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
         else
         {
             if (this.Tag.Equals(2))//如果是学生查看已被批分的实验报告模式
             {
                 this.butAmend.Enabled  = false;
                 this.butCancel.Enabled = false;
                 this.butOK.Enabled     = false;
                 try
                 {
                     SqlDataReader temDR = MyClass.getcom("select * from tb_Report where IDR='" + DataClass.Report.Report_ID_forStudent + "'");
                     if (temDR.Read())
                     {
                         this.txtTime.Text     = temDR.GetValue(temDR.GetOrdinal("date")).ToString();
                         this.txtTime.ReadOnly = true;
                         SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + temDR.GetValue(temDR.GetOrdinal("IDC")) + "'");
                         if (temDR2.Read())
                         {
                             this.cb_ChapterName.Text    = temDR2.GetString(temDR2.GetOrdinal("name"));
                             this.cb_ChapterName.Enabled = false;//设置章节名只读
                         }
                         this.txtStudentNum.Text = temDR.GetString(temDR.GetOrdinal("IDS"));
                         SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS ='" + this.txtStudentNum.Text.Trim() + "'");
                         if (temDR3.Read())
                         {
                             this.txtStudentName.Text = temDR3.GetString(temDR3.GetOrdinal("name"));
                         }
                         this.txtStudentNum.ReadOnly  = true;
                         this.txtStudentName.ReadOnly = true;
                         this.txtTitle.Text           = temDR.GetString(temDR.GetOrdinal("title"));
                         this.txtTitle.ReadOnly       = true;
                         this.txtDescription.Text     = temDR.GetValue(temDR.GetOrdinal("description")).ToString();
                         this.txtDescription.ReadOnly = true;
                         this.txtALG.Text             = temDR.GetString(temDR.GetOrdinal("ALG"));
                         this.txtALG.ReadOnly         = true;
                         this.txtRunning.Text         = temDR.GetString(temDR.GetOrdinal("running"));
                         this.txtRunning.ReadOnly     = true;
                         this.txtQuestion.Text        = temDR.GetString(temDR.GetOrdinal("question"));
                         this.txtQuestion.ReadOnly    = true;
                         this.txtMark.Text            = temDR.GetString(temDR.GetOrdinal("mark"));
                         this.txtMark.ReadOnly        = true;
                         this.txtEvaluation.Text      = temDR.GetString(temDR.GetOrdinal("evaluation"));
                         this.txtEvaluation.ReadOnly  = true;
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message);
                 }
             }
         }
     }
 }
예제 #18
0
        private void butCreatWord_Click(object sender, EventArgs e)
        {
            Loading.loading f   = new Loading.loading();                                                                            //实例化进度条
            List <Image>    pic = new List <Image>();                                                                               //存放大图

            if (MessageBox.Show("确定要将所选报告生成Word文档?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) //判断是否在弹出的对话框中单击"确定"按钮
            {
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                fbd.ShowDialog();
                string filesave = fbd.SelectedPath;//获得选择的文件夹路径来存储
                if (filesave != "")
                {
                    DataClass.Report.Report_Path = filesave;                                         //保存最近的实验报告生成路径
                    WordHandle word       = new WordHandle();
                    int        Select_num = 0;                                                       //变量用于存储勾选变量
                    string     SaveFile   = "c:\\a.jpg";
                    string     docname;                                                              //文档名字
                    string     reporthead;                                                           //文档头
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)                               //循环遍历DataGridView控件中的每一行
                    {
                        if (dataGridView1.Rows[i].Cells[0].Value != null)                            //当当前单元格的内容不为空时
                        {
                            if (bool.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) == true) //单元格选中
                            {
                                Select_num++;
                            }
                        }
                    }
                    if (Select_num == 0)                                                                    //如果没有勾选项
                    {
                        MessageBox.Show("请选择操作项!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示消息
                    }
                    else
                    {                                                      //如果选择了项目则开始生成word
                        f.LoadOpen(this);                                  //打开进度条
                        for (int i = 0; i < dataGridView1.Rows.Count; i++) //循环遍历DataGridView控件中的每一行
                        {
                            try
                            {
                                if (dataGridView1.Rows[i].Cells[0].Value != null)                            //当当前单元格的内容不为空时
                                {
                                    if (bool.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) == true) //单元格选中
                                    {
                                        string        idr    = dataGridView1.Rows[i].Cells[1].Value.ToString();
                                        string        ide    = dataGridView1.Rows[i].Cells[2].Value.ToString();
                                        string        ids    = dataGridView1.Rows[i].Cells[3].Value.ToString();
                                        SqlDataReader temDR  = MyClass.getcom("select * from tb_Report where IDR='" + idr.ToString() + "'");
                                        SqlDataReader temDR2 = MyClass.getcom("select * from tb_Experiment where ID='" + ide.ToString() + "'");
                                        SqlDataReader temDR3 = MyClass.getcom("select * from tb_Student where IDS='" + ids.ToString() + "'");
                                        if (temDR.Read() && temDR2.Read() && temDR3.Read())
                                        {
                                            docname = "\\" + ide.ToString() + "_" + ids.ToString() + "_" + temDR3.GetString(temDR3.GetOrdinal("class")) + "_" + temDR3.GetString(temDR3.GetOrdinal("name")) + ".doc";//编辑头信息
                                            word.CreateAWord();
                                            word.InsertText(temDR2.GetString(temDR2.GetOrdinal("title")), 20, Word.WdColor.wdColorDarkRed, 2, Word.WdParagraphAlignment.wdAlignParagraphCenter);
                                            word.NewLine();
                                            reporthead = "实验编号:" + ide.ToString() + "    学号:" + ids.ToString() + "    班级:" + temDR3.GetString(temDR3.GetOrdinal("class")) + "    姓名:" + temDR3.GetString(temDR3.GetOrdinal("name")) + "    时间:" + temDR.GetString(temDR.GetOrdinal("date")) + "    分数:" + temDR.GetString(temDR.GetOrdinal("mark"));
                                            word.InsertText(reporthead, 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphCenter);
                                            word.NewLine();
                                            word.InsertText("一.实验目的", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR2.GetString(temDR2.GetOrdinal("purpose")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText("二.问题描述", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR.GetString(temDR.GetOrdinal("description")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText("三.算法设计", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR.GetString(temDR.GetOrdinal("ALG")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText("四.运行结果", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR.GetString(temDR.GetOrdinal("running")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText("附图:", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            //插图片
                                            pic = MyMC.reImage(ide.ToString(), ids);
                                            foreach (Image p in pic)
                                            {
                                                //p.Save(SaveFile, System.Drawing.Imaging.ImageFormat.Jpeg);//先存至路径
                                                //word.InsertPicture(SaveFile);
                                                //源代码会出现GDI+一般性错误因为用到的数据会处于锁定状态
                                                #region 解决方法

                                                /* 症状
                                                 * Bitmap 对象或一个 图像 对象从一个文件, 构造时该文件仍保留锁定对于对象的生存期。
                                                 * 因此, 无法更改图像并将其保存回它产生相同的文件。
                                                 * 替代方法
                                                 * 创建非索引映像。
                                                 * 创建索引映像。
                                                 * 这两种情况下, 原始 位图 上调用 Bitmap.Dispose() 方法删除该文件上锁或删除要求, 流或内存保持活动。
                                                 *
                                                 * 创建非索引图像
                                                 * 即使原始映像被索引格式中该方法要求新图像位于每像素 (超过 8 位 -) -, 非索引像素格式。
                                                 * 此变通方法使用 Graphics.DrawImage() 方法来将映像复制到新 位图 对象:
                                                 * 1.    构造从流、 从内存, 或从文件原始 位图 。
                                                 * 2.    创建新 位图 的相同大小, 带有是超过 8 位 - - 像素 (BPP) 每像素格式。
                                                 * 3.    使用 Graphics.FromImage() 方法以获取有关二 位图 Graphics 对象。
                                                 * 4.    用于 Graphics.DrawImage() 绘制首 位图 到二 位图 。
                                                 * 5.    用于 Graphics.Dispose() 处置是 图形 。
                                                 * 6.    用于 Bitmap.Dispose() 是首 位图 处置。
                                                 *
                                                 * 创建索引映像
                                                 * 此解决办法在索引格式创建一个 Bitmap 对象:
                                                 * 1.    构造从流、 从内存, 或从文件原始 位图 。
                                                 * 2.    创建新 位图 具有相同的大小和像素格式作为首 位图 。
                                                 * 3.    使用 Bitmap.LockBits() 方法来锁定整个图像对于两 Bitmap 对象以其本机像素格式。
                                                 * 4.    使用 Marshal.Copy 函数或其他内存复制函数来从首 位图 复制到二 位图 图像位。
                                                 * 5.    使用 Bitmap.UnlockBits() 方法可以解锁两 Bitmap 对象。
                                                 * 6.    用于 Bitmap.Dispose() 是首 位图 处置。
                                                 */
                                                #endregion 解决方法
                                                Bitmap bmp = new Bitmap(p);
                                                //新建第二个bitmap类型的bmp2变量,我这里是根据我的程序需要设置的。
                                                Bitmap bmp2 = new Bitmap(p.Width, p.Height,
                                                                         System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
                                                //将第一个bmp拷贝到bmp2中
                                                Graphics draw = Graphics.FromImage(bmp2);
                                                draw.DrawImage(bmp, 0, 0);
                                                bmp2.Save(SaveFile, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                draw.Dispose();
                                                bmp.Dispose();//释放bmp文件资源
                                                word.InsertPicture(SaveFile);
                                            }
                                            word.NewLine();
                                            pic.Clear();
                                            word.InsertText("五.问题与收获", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR.GetString(temDR.GetOrdinal("question")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText("六.教师评价", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.NewLine();
                                            word.InsertText(temDR.GetString(temDR.GetOrdinal("evaluation")), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                            word.SaveWord(filesave + docname, docname);//保存路径
                                            File.Delete(SaveFile);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)             //捕获异常
                            {
                                MessageBox.Show(ex.Message); //弹出异常提示信息
                                break;
                            }
                        }
                        f.LoadClose(this);                                                                  //关闭进度条
                        MessageBox.Show("生成文档结束!", "操作", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示消息
                    }
                }
            }
        }
예제 #19
0
 private void butCreatWord_Click(object sender, EventArgs e)
 {
     Loading.loading f = new Loading.loading();                                                                              //实例化进度条
     if (MessageBox.Show("确定要将所选实验生成Word文档?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) //判断是否在弹出的对话框中单击"确定"按钮
     {
         FolderBrowserDialog fbd = new FolderBrowserDialog();
         fbd.ShowDialog();
         string filesave = fbd.SelectedPath;//获得选择的文件夹路径来存储
         if (filesave != "")
         {
             DataClass.Report.Report_Path = filesave;//保存最近的实验报告生成路径
             WordHandle word       = new WordHandle();
             int        Celect_num = 0;
             string     SaveFile   = "c:\\a.jpg";
             string     docname;                                                              //文档名字
             string     reporthead;                                                           //文档头
             for (int i = 0; i < dataGridView1.Rows.Count; i++)                               //循环遍历DataGridView控件中的每一行
             {
                 if (dataGridView1.Rows[i].Cells[0].Value != null)                            //当当前单元格的内容不为空时
                 {
                     if (bool.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) == true) //单元格选中
                     {
                         Celect_num++;
                     }
                 }
             }
             if (Celect_num == 0)                                                                    //如果没有勾选项
             {
                 MessageBox.Show("请选择操作项!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示消息
             }
             else
             {                                                      //如果选择了项目则开始生成word
                 f.LoadOpen(this);                                  //打开进度条
                 for (int i = 0; i < dataGridView1.Rows.Count; i++) //循环遍历DataGridView控件中的每一行
                 {
                     try
                     {
                         if (dataGridView1.Rows[i].Cells[0].Value != null)                            //当当前单元格的内容不为空时
                         {
                             if (bool.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) == true) //单元格选中
                             {
                                 Celect_num++;
                                 string        ide    = dataGridView1.Rows[i].Cells[1].Value.ToString(); //实验总编号
                                 string        idc    = dataGridView1.Rows[i].Cells[4].Value.ToString(); //章节编号
                                 string        idt    = dataGridView1.Rows[i].Cells[3].Value.ToString(); //教师号
                                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Chapter where IDC='" + idc.ToString() + "'");
                                 SqlDataReader temDR3 = MyClass.getcom("select * from tb_Teacher where IDT='" + idt.ToString() + "'");
                                 if (temDR2.Read() && temDR3.Read())
                                 {
                                     docname = "\\" + ide.ToString() + "_" + dataGridView1.Rows[i].Cells[5].Value.ToString() + "_" + temDR3.GetString(temDR3.GetOrdinal("class")) + "_" + temDR3.GetString(temDR3.GetOrdinal("name")) + ".doc";//编辑头信息
                                     word.CreateAWord();
                                     word.InsertText(dataGridView1.Rows[i].Cells[5].Value.ToString(), 20, Word.WdColor.wdColorDarkRed, 2, Word.WdParagraphAlignment.wdAlignParagraphCenter);
                                     word.NewLine();
                                     reporthead = "实验编号:" + ide.ToString() + "    教师号:" + idt.ToString() + "    班级:" + temDR3.GetString(temDR3.GetOrdinal("class")) + "    教师姓名:" + temDR3.GetString(temDR3.GetOrdinal("name")) + "    时间:" + DateTime.Now.AddDays(0).ToString("yyyy年MM月dd日") + "    所属章节:" + temDR2.GetString(temDR2.GetOrdinal("name"));
                                     word.InsertText(reporthead, 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphCenter);
                                     word.NewLine();
                                     word.InsertText("一.实验题目", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText(dataGridView1.Rows[i].Cells[5].Value.ToString(), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText("二.实验目的", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText(dataGridView1.Rows[i].Cells[6].Value.ToString(), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText("三.实验内容", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText(dataGridView1.Rows[i].Cells[7].Value.ToString(), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText("四.准备知识", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText(dataGridView1.Rows[i].Cells[8].Value.ToString(), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText("五.实验指导", 15, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.InsertText(dataGridView1.Rows[i].Cells[9].Value.ToString(), 10, Word.WdColor.wdColorBlack, 1, Word.WdParagraphAlignment.wdAlignParagraphLeft);
                                     word.NewLine();
                                     word.SaveWord(filesave + docname, docname);//保存路径
                                     File.Delete(SaveFile);
                                 }
                             }
                         }
                     }
                     catch (Exception ex)//捕获异常
                     {
                         //f.LoadClose(this); //关闭进度条
                         MessageBox.Show(ex.Message);//弹出异常提示信息
                         break;
                     }
                 }
                 f.LoadClose(this);                                                                  //关闭进度条
                 MessageBox.Show("生成文档结束!", "操作", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示消息
             }
         }
     }
 }
 private void F_NewExperiment_Load(object sender, EventArgs e)
 {
     // TODO: 这行代码将数据加载到表“db_BSDataSet.tb_Chapter”中。您可以根据需要移动或删除它。
     this.tb_ChapterTableAdapter.Fill(this.db_BSDataSet.tb_Chapter);
     butGetChapterNum.Enabled = false;
     if (this.Tag.Equals(0))//教师新建模式
     {
         this.butDoExperiment.Visible   = false;
         this.txtTeacherNum.Text        = DataClass.MyMeans.Login_ID.ToString();
         this.txtTeacherNum.ReadOnly    = true; //设置教师编号为只读
         this.txtExperimentNum.ReadOnly = true; //设置章节编号为只读
         butGetChapterNum.Enabled       = true;
         try
         {
             //自动生成教师名
             SqlDataReader temDR = MyClass.getcom("select * from tb_Teacher where IDT='" + this.txtTeacherNum.Text.Trim() + "'");
             if (temDR.Read())
             {
                 this.txtTeacherName.Text     = temDR.GetString(temDR.GetOrdinal("name"));
                 this.txtTeacherName.ReadOnly = true;//设置教师名为只读
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "警告");
         }
     }
     else
     if (this.Tag.Equals(1))    //教师浏览模式
     {
         this.butDoExperiment.Visible = false;
         try
         {
             SqlDataReader temDR = MyClass.getcom("select * from tb_Experiment where ID='" + DataClass.Experiment.Experiment_ID_forTeahcer + "'");
             if (temDR.Read())
             {
                 this.txtTeacherNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDT")).ToString();
                 this.txtTeacherNum.ReadOnly = true;
                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Teacher where IDT='" + this.txtTeacherNum.Text.Trim() + "'");
                 if (temDR2.Read())
                 {
                     this.txtTeacherName.Text     = temDR2.GetString(temDR2.GetOrdinal("name"));
                     this.txtTeacherName.ReadOnly = true;    //设置教师名为只读
                 }
                 this.cb_ChapterNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDC")).ToString();
                 this.cb_ChapterNum.Enabled  = false;
                 this.cb_ChapterName.Enabled = false;
                 //this.cb_ChaperNum.DropDownStyle = ComboBoxStyle.DropDownList;
                 //this.cb_ChapterName.DropDownStyle = ComboBoxStyle.DropDownList;
                 this.txtTitle.Text             = temDR.GetString(temDR.GetOrdinal("title"));
                 this.txtTitle.ReadOnly         = true;
                 this.txtExperimentNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDE")).ToString();
                 this.txtExperimentNum.ReadOnly = true;
                 this.txtPurpose.Text           = temDR.GetString(temDR.GetOrdinal("purpose"));
                 this.txtPurpose.ReadOnly       = true;
                 this.txtDetail.Text            = temDR.GetString(temDR.GetOrdinal("detail"));
                 this.txtDetail.ReadOnly        = true;
                 this.txtGuidance.Text          = temDR.GetString(temDR.GetOrdinal("guidance"));
                 this.txtGuidance.ReadOnly      = true;
                 this.txtPreparation.Text       = temDR.GetString(temDR.GetOrdinal("preparation"));
                 this.txtPreparation.ReadOnly   = true;
                 this.butAccept.Enabled         = false;
                 this.butClear.Enabled          = false;
                 this.butOpenFile.Enabled       = false;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "警告");
         }
     }
     else
     if (this.Tag.Equals(2))        //教师修改模式
     {
         this.butDoExperiment.Visible  = false;
         this.butGetChapterNum.Enabled = true;
         try
         {
             SqlDataReader temDR = MyClass.getcom("select * from tb_Experiment where ID='" + DataClass.Experiment.Experiment_ID_forTeahcer + "'");
             if (temDR.Read())
             {
                 this.txtTeacherNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDT")).ToString();
                 this.txtTeacherNum.ReadOnly = true;
                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Teacher where IDT='" + this.txtTeacherNum.Text.Trim() + "'");
                 if (temDR2.Read())
                 {
                     this.txtTeacherName.Text     = temDR2.GetString(temDR2.GetOrdinal("name"));
                     this.txtTeacherName.ReadOnly = true;        //设置教师名为只读
                 }
                 this.cb_ChapterNum.Text    = temDR.GetValue(temDR.GetOrdinal("IDC")).ToString();
                 this.txtTitle.Text         = temDR.GetString(temDR.GetOrdinal("title"));
                 this.txtExperimentNum.Text = temDR.GetValue(temDR.GetOrdinal("IDE")).ToString();
                 this.txtPurpose.Text       = temDR.GetString(temDR.GetOrdinal("purpose"));
                 this.txtDetail.Text        = temDR.GetString(temDR.GetOrdinal("detail"));
                 this.txtGuidance.Text      = temDR.GetString(temDR.GetOrdinal("guidance"));
                 this.txtPreparation.Text   = temDR.GetString(temDR.GetOrdinal("preparation"));
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "警告");
         }
     }
     else
     if (this.Tag.Equals(3))            //学生做实验模式
     {
         try
         {
             SqlDataReader temDR = MyClass.getcom("select * from tb_Experiment where ID='" + DataClass.Experiment.Experiment_ID_forStudent + "'");
             if (temDR.Read())
             {
                 this.txtTeacherNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDT")).ToString();
                 this.txtTeacherNum.ReadOnly = true;
                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Teacher where IDT='" + this.txtTeacherNum.Text.Trim() + "'");
                 if (temDR2.Read())
                 {
                     this.txtTeacherName.Text     = temDR2.GetString(temDR2.GetOrdinal("name"));
                     this.txtTeacherName.ReadOnly = true;            //设置教师名为只读
                 }
                 this.cb_ChapterNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDC")).ToString();
                 this.cb_ChapterNum.Enabled  = false;
                 this.cb_ChapterName.Enabled = false;
                 //this.cb_ChaperNum.DropDownStyle = ComboBoxStyle.DropDownList;
                 //this.cb_ChapterName.DropDownStyle = ComboBoxStyle.DropDownList;
                 this.txtTitle.Text             = temDR.GetString(temDR.GetOrdinal("title"));
                 this.txtTitle.ReadOnly         = true;
                 this.txtExperimentNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDE")).ToString();
                 this.txtExperimentNum.ReadOnly = true;
                 this.txtPurpose.Text           = temDR.GetString(temDR.GetOrdinal("purpose"));
                 this.txtPurpose.ReadOnly       = true;
                 this.txtDetail.Text            = temDR.GetString(temDR.GetOrdinal("detail"));
                 this.txtDetail.ReadOnly        = true;
                 this.txtGuidance.Text          = temDR.GetString(temDR.GetOrdinal("guidance"));
                 this.txtGuidance.ReadOnly      = true;
                 this.txtPreparation.Text       = temDR.GetString(temDR.GetOrdinal("preparation"));
                 this.txtPreparation.ReadOnly   = true;
                 this.butAccept.Enabled         = false;
                 this.butClear.Enabled          = false;
                 this.butOpenFile.Enabled       = false;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "警告");
         }
     }
     else
     if (this.Tag.Equals(4))                //学生浏览模式
     {
         this.butDoExperiment.Enabled = false;
         try
         {
             SqlDataReader temDR = MyClass.getcom("select * from tb_Experiment where ID='" + DataClass.Experiment.Experiment_ID_forStudent + "'");
             if (temDR.Read())
             {
                 this.txtTeacherNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDT")).ToString();
                 this.txtTeacherNum.ReadOnly = true;
                 SqlDataReader temDR2 = MyClass.getcom("select * from tb_Teacher where IDT='" + this.txtTeacherNum.Text.Trim() + "'");
                 if (temDR2.Read())
                 {
                     this.txtTeacherName.Text     = temDR2.GetString(temDR2.GetOrdinal("name"));
                     this.txtTeacherName.ReadOnly = true;                //设置教师名为只读
                 }
                 this.cb_ChapterNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDC")).ToString();
                 this.cb_ChapterNum.Enabled  = false;
                 this.cb_ChapterName.Enabled = false;
                 //this.cb_ChaperNum.DropDownStyle = ComboBoxStyle.DropDownList;
                 //this.cb_ChapterName.DropDownStyle = ComboBoxStyle.DropDownList;
                 this.txtTitle.Text             = temDR.GetString(temDR.GetOrdinal("title"));
                 this.txtTitle.ReadOnly         = true;
                 this.txtExperimentNum.Text     = temDR.GetValue(temDR.GetOrdinal("IDE")).ToString();
                 this.txtExperimentNum.ReadOnly = true;
                 this.txtPurpose.Text           = temDR.GetString(temDR.GetOrdinal("purpose"));
                 this.txtPurpose.ReadOnly       = true;
                 this.txtDetail.Text            = temDR.GetString(temDR.GetOrdinal("detail"));
                 this.txtDetail.ReadOnly        = true;
                 this.txtGuidance.Text          = temDR.GetString(temDR.GetOrdinal("guidance"));
                 this.txtGuidance.ReadOnly      = true;
                 this.txtPreparation.Text       = temDR.GetString(temDR.GetOrdinal("preparation"));
                 this.txtPreparation.ReadOnly   = true;
                 this.butAccept.Enabled         = false;
                 this.butClear.Enabled          = false;
                 this.butOpenFile.Enabled       = false;
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "警告");
         }
     }
 }