⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proctparinfo.cs

📁 程序设计语言上机考试系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
            if (dataGridView2.ColumnCount == 3)
            {
                //允许在gV中编辑
                edit = true;
                richpanduan.Text = Convert.ToString(dataGridView2[0, dataGridView2.CurrentCell.RowIndex].Value).Trim();
                radiop = Convert.ToString(dataGridView2[1, dataGridView2.CurrentCell.RowIndex].Value).Trim();
                if (radiop == "对")
                    radioBtnRight.Checked = true;
                else
                    radioBtnWrong.Checked = true;
                txtPnandu.Text = Convert.ToString(dataGridView2[2, dataGridView2.CurrentCell.RowIndex].Value).Trim();
            }
            else
            {
                //不允许在gV中编辑
                edit = true;
                richpanduan.Text = Convert.ToString(dataGridView2[2, dataGridView2.CurrentCell.RowIndex].Value).Trim();
                radiop = Convert.ToString(dataGridView2[3, dataGridView2.CurrentCell.RowIndex].Value).Trim();
                if (radiop == "对")
                    radioBtnRight.Checked = true;
                else
                    radioBtnWrong.Checked = true;
                txtPnandu.Text = Convert.ToString(dataGridView2[4, dataGridView2.CurrentCell.RowIndex].Value).Trim();
                txtpnum.Text = Convert.ToString(dataGridView2[0, dataGridView2.CurrentCell.RowIndex].Value).Trim();
            }
        }
        #endregion


        #region 添加判断题
        private void btnPAdd_Click(object sender, EventArgs e)
        {
            if (richpanduan.Text.Trim() == "" || txtPnandu.Text.Trim() == "")
                MessageBox.Show("请填写完整的试题", "提示");
            else
            {
                if (radioBtnRight.Checked)
                    radiop = "对";
                else
                    radiop = "错";
                string question = richpanduan.Text.Trim();
                //转义“'”
                question = question.Replace("'", "''");
                //自动生成编号
                opAndvalidate.autoNum("select id from panduan", "panduan", "id", "B", "1000001", txtpnum);
                //添加判断题
                boperate.getcom("insert into panduan(id,types,title,answer,quotiety) values('" + txtpnum.Text.ToString().Trim() + "','" + "B" + "','" + question + "','" + radiop + "','" + txtPnandu.Text.Trim() + "')");
                tabPanduan_Click(sender, e);
                MessageBox.Show("试题信息添加成功", "提示");
                clear();
            }
        }
        #endregion

        #region 双击表格显示判断题
        private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            btnPDisplay_Click(sender, e);
        }
        #endregion

        #region 更新判断题
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPUpdata_Click(object sender, EventArgs e)
        {
            if (edit)
            {
                try
                {
                    if (MessageBox.Show("确定要修改吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        if (radioBtnRight.Checked)
                            radiop = "对";
                        else
                            radiop = "错";
                        string question = richpanduan.Text.Trim();
                        question = question.Replace("'", "''");
                        boperate.getcom("update panduan set title='" + question + "',answer='" + radiop + "',quotiety='" + txtPnandu.Text.Trim() + "' where id='" + txtpnum.Text.Trim() + "'");
                        tabPanduan_Click(sender, e);
                        MessageBox.Show("数据更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        richpanduan.Clear();
                        edit = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
        }
        #endregion

        #region 删除判断题
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定要删除吗?", "删除确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    boperate.getcom("delete from panduan where id='" + Convert.ToString(dataGridView2[0, dataGridView2.CurrentCell.RowIndex].Value).Trim() + "'");
                    tabPanduan_Click(sender, e);
                    MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }
        #endregion
        
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.tabChoose == this.tabControl1.SelectedTab)
            {
                //选择题
                tabChoose_Click(sender, e);
            }
            if (this.tabPanduan == this.tabControl1.SelectedTab)
            {
                //判断题
                tabPanduan_Click(sender, e);
            }
            if (this.tabProgram == this.tabControl1.SelectedTab)
            {
                //程序设计题
                tabProgram_Click(sender, e);
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.White;
            dataGridView1.CurrentRow.DefaultCellStyle.BackColor = Color.LightSlateGray; 
            //将鼠标点击行设为选中状态
            dataGridView1.CurrentRow.Selected = true;
        }

        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
                dataGridView2.Rows[i].DefaultCellStyle.BackColor = Color.White;
            dataGridView2.CurrentRow.DefaultCellStyle.BackColor = Color.LightSlateGray;
            //将鼠标点击行设为选中状态
            dataGridView2.CurrentRow.Selected = true;
        }
        
        #region 关闭窗口
        private void tsbtnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 导出试题
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (tscboxCondition.Text.Trim() == "")
                MessageBox.Show("请选择要导出的试题类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            else
            {
                try
                {
                    string savepath = "";
                    if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                    {
                        //保存文件的路径
                        savepath = folderBrowserDialog1.SelectedPath;
                        Object Nothing = Missing.Value;
                        string name = tscboxCondition.Text.Trim() + ".doc";
                        //保存的文件名
                        object filename = savepath + "/" + name;

                        Word.Application wApp = new Word.Application();
                        wApp.Visible = false;  //试题导完前,关闭显示
                        Document WordDoc = wApp.Documents.Add(ref   Nothing, ref   Nothing, ref   Nothing, ref   Nothing);
                        wApp.Selection.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;//设置右对齐
                        if (tscboxCondition.Text.Trim() == "选择题")
                        {
                            //如选择导出的是选择题,加载选择题界面
                            tabChoose_Click(sender, e);
                            WordDoc.Paragraphs.First.Range.Text = tscboxCondition.Text.Trim() + " [共有:" + (dataGridView1.Rows.Count ).ToString() + "道题]";
                            for (int i = 0; i < dataGridView1.RowCount ; i++)
                            {
                                wApp.Selection.TypeText((i + 1).ToString() + "、");
                                wApp.Selection.TypeText(dataGridView1.Rows[i].Cells[2].Value.ToString().Trim());
                                wApp.Selection.TypeText("\n");
                                wApp.Selection.TypeText("\t" + "A、" + dataGridView1.Rows[i].Cells[3].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "B、" + dataGridView1.Rows[i].Cells[4].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "C、" + dataGridView1.Rows[i].Cells[5].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "D、" + dataGridView1.Rows[i].Cells[6].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "答案:" + dataGridView1.Rows[i].Cells[7].Value.ToString().Trim() + "\t");
                                wApp.Selection.TypeText("\t" + "难度系数:" + dataGridView1.Rows[i].Cells[8].Value.ToString().Trim() + "\n");
                            }
                        }
                        else if (tscboxCondition.Text.Trim() == "判断题")
                        {
                            //如选择导出的是判断题,加载判断题界面
                            tabPanduan_Click(sender, e);
                            WordDoc.Paragraphs.First.Range.Text = tscboxCondition.Text.Trim() + " [共有:" + (dataGridView2.Rows.Count ).ToString() + "道题]";
                            for (int i = 0; i < dataGridView2.RowCount ; i++)
                            {
                                wApp.Selection.TypeText((i + 1).ToString() + "、");
                                wApp.Selection.TypeText(dataGridView2.Rows[i].Cells[2].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "答案:" + dataGridView2.Rows[i].Cells[3].Value.ToString().Trim() + "\t");
                                wApp.Selection.TypeText("\t" + "难度系数:" + dataGridView2.Rows[i].Cells[4].Value.ToString().Trim() + "\n");
                            }
                        }
                        else if (tscboxCondition.Text.Trim() == "程序设计题")
                        {
                            //如选择导出的是程序题,加载程序题界面
                            tabProgram_Click(sender, e);
                            WordDoc.Paragraphs.First.Range.Text = tscboxCondition.Text.Trim() + " [共有:" + (dataGridView3.Rows.Count ).ToString() + "道题]";
                            for (int i = 0; i < dataGridView3.RowCount ; i++)
                            {
                                wApp.Selection.TypeText((i + 1).ToString() + "、");
                                wApp.Selection.TypeText(dataGridView3.Rows[i].Cells[2].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "参考答案:" + dataGridView3.Rows[i].Cells[3].Value.ToString().Trim() + "\n");
                                wApp.Selection.TypeText("\t" + "难度系数:" + dataGridView3.Rows[i].Cells[4].Value.ToString().Trim() + "\n");
                            }
                        }
                        wApp.Visible = true;  //显示导出的word
                        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);

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        #endregion

        #region 点击程序设计题标签
        private void tabProgram_Click(object sender, EventArgs e)
        {
            choose = false;
            program = true;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -