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

📄 proctparinfo.cs

📁 程序设计语言上机考试系统
💻 CS
📖 第 1 页 / 共 4 页
字号:
            }
        }
        #endregion

        #region 删除程序设计题
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("确定要删除吗?", "删除确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    boperate.getcom("delete from program where id='" + Convert.ToString(dataGridView3[0, dataGridView3.CurrentCell.RowIndex].Value).Trim() + "'");
                    tabProgram_Click(sender, e);
                    MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
            }
        }
        #endregion

        private void dataGridView3_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView3.ColumnCount == 3)
            {
                edit = true;
                richprogram.Text = Convert.ToString(dataGridView3[0, dataGridView3.CurrentCell.RowIndex].Value).Trim();
                richanswer.Text = Convert.ToString(dataGridView3[1, dataGridView3.CurrentCell.RowIndex].Value).Trim();
                comboBnandu.Text = Convert.ToString(dataGridView3[2, dataGridView3.CurrentCell.RowIndex].Value).Trim();
            }
            else
            {
                edit = true;
                richprogram.Text = Convert.ToString(dataGridView3[2, dataGridView3.CurrentCell.RowIndex].Value).Trim();
                richanswer.Text = Convert.ToString(dataGridView3[3, dataGridView3.CurrentCell.RowIndex].Value).Trim();
                comboBnandu.Text = Convert.ToString(dataGridView3[4, dataGridView3.CurrentCell.RowIndex].Value).Trim();
                txtpronum.Text = Convert.ToString(dataGridView3[0, dataGridView3.CurrentCell.RowIndex].Value).Trim();
            }
        }
        #region 修改程序设计题
        private void btnUpdata_Click(object sender, EventArgs e)
        {
            if (edit)
            {
                try
                {
                    if (MessageBox.Show("确定要修改吗?", "确定", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        string question = richprogram.Text.Trim().Replace("'", "''");
                        string answer = richanswer.Text.Trim().Replace("'", "''");
                        boperate.getcom("update program set title='" + question + "',answer='" + answer + "',quotiety='" + comboBnandu.Text.Trim() + "' where id='" + txtpronum.Text.Trim() + "'");
                        tabProgram_Click(sender, e);
                        MessageBox.Show("数据更新成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        richprogram.Clear();
                        richanswer.Clear();
                        edit = false;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
        }
        #endregion


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

        private void tSMItemDelete_Click(object sender, EventArgs e)
        {
            int[][] selectindex = new int[3][];

            if (MessageBox.Show("确实要删除选择信息吗?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
            {
                //如果选择的是选择题标签
                if (choose)
                {
                    //将选中的行的index存在数组selectindex中
                    selectindex[0] = new int[dataGridView1.SelectedRows.Count];
                    for (int i = 0, j = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        if (dataGridView1.Rows[i].Selected)
                        {
                            selectindex[0][j] = Convert.ToInt32(dataGridView1.Rows[i].Index.ToString());
                            j++;
                        }
                    }
                    //从selectindex数组中index值最大的行开始,依次删除选中的行
                    for (int i = dataGridView1.SelectedRows.Count - 1; i >= 0; i--)
                    {
                        boperate.getcom("delete from choose where id='" + Convert.ToString(dataGridView1.Rows[selectindex[0][i]].Cells[0].Value).Trim() + "'");
                    }
                    ProctParInfo_Load(sender, e);

                }
                //-------------------------------------------------------------------------------
                //如果选择的是判断题标签
                if (panduan)
                {
                    //将选中的行的index存在数组selectindex中
                    selectindex[1] = new int[dataGridView2.SelectedRows.Count];
                    for (int i = 0, j = 0; i < dataGridView2.Rows.Count; i++)
                    {
                        if (dataGridView2.Rows[i].Selected)
                        {
                            selectindex[1][j] = Convert.ToInt32(dataGridView2.Rows[i].Index.ToString());
                            j++;
                        }
                    }
                    //从selectindex数组中index值最大的行开始,依次删除选中的行
                    for (int i = dataGridView2.SelectedRows.Count - 1; i >= 0; i--)
                    {
                        boperate.getcom("delete from panduan where id='" + Convert.ToString(dataGridView2.Rows[selectindex[1][i]].Cells[0].Value).Trim() + "'");
                    }
                    tabPanduan_Click(sender, e);

                }
                //-------------------------------------------------------------------------------
                //如果现在的是程序设计题标签
                if (program)
                {
                    //将选中的行的index存在数组selectindex中
                    selectindex[2] = new int[dataGridView3.SelectedRows.Count];
                    for (int i = 0, j = 0; i < dataGridView3.Rows.Count; i++)
                    {
                        if (dataGridView3.Rows[i].Selected)
                        {
                            selectindex[2][j] = Convert.ToInt32(dataGridView3.Rows[i].Index.ToString());
                            j++;
                        }
                    }
                    //从selectindex数组中index值最大的行开始,依次删除选中的行
                    for (int i = dataGridView3.SelectedRows.Count - 1; i >= 0; i--)
                    {
                        boperate.getcom("delete from program where id='" + Convert.ToString(dataGridView3.Rows[selectindex[2][i]].Cells[0].Value).Trim() + "'");
                    }
                    tabProgram_Click(sender, e);

                }
            }
            MessageBox.Show("删除数据成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        #region  关键字搜索
        private void tsbtnLook_Click(object sender, EventArgs e)
        {
            bool isright = true; //判断输入的关键字是否合法
            string search = ""; //需要查找的字段
            if(choose)
            {
                search = "";
                if (tstxtKeyWord.Text.Trim() != "")
                {
                    if (tSCBox.Text.Trim() == "" || tSCBox.Text.Trim() == "试题内容")
                    {
                        search = "title";
                    }
                    else if (tSCBox.Text.Trim() == "试题难度")
                    {
                        search = "quotiety";
                        if (!opAndvalidate.validateNum(tstxtKeyWord.Text.Trim()))
                        {
                            errorProvider1.SetError(tstxtKeyWord.Control, "请输入正整数");
                            isright = false;
                        }
                    }
                    if (isright)
                    {
                        DataSet ds = boperate.getds("select id as 编号,types as 试题类型,title as 试题," + "selecta as 选项A,selectb as 选项B,selectc as 选项C,selectd as 选项D," + "answer as 试题答案,quotiety as 难度系数 from choose where " + search + " like '%" + tstxtKeyWord.Text.Trim() + "%' order by id", "choose");
                        if (ds.Tables[0].Rows.Count > 0)
                            dataGridView1.DataSource = ds.Tables[0];
                        else
                            MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                }
            }
            if(panduan)
            {
                search = "";
                if (tstxtKeyWord.Text.Trim() != "")
                {
                    if (tSCBox.Text.Trim() == "" || tSCBox.Text.Trim() == "试题内容")
                    {
                        search = "title";
                    }
                    else if (tSCBox.Text.Trim() == "试题难度")
                    {
                        search = "quotiety";
                        if (!opAndvalidate.validateNum(tstxtKeyWord.Text.Trim()))
                        {
                            errorProvider1.SetError(tstxtKeyWord.Control, "请输入正整数");
                            isright = false;
                        }
                    }
                    if (isright)
                    {
                        DataSet ds = boperate.getds("select id as 编号,types as 试题类型,title as 试题,answer as 试题答案,quotiety as 难度系数 from panduan where " + search + " like '%" + tstxtKeyWord.Text.Trim() + "%' order by id", "pandu");
                        if (ds.Tables[0].Rows.Count > 0)
                            dataGridView2.DataSource = ds.Tables[0];
                        else
                            MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                }
            }
            if(program)
            {
                search = "";
                if (tstxtKeyWord.Text.Trim() != "")
                {
                    if (tSCBox.Text.Trim() == "" || tSCBox.Text.Trim() == "试题内容")
                    {
                        search = "title";
                    }
                   else if (tSCBox.Text.Trim() == "试题难度")
                    {
                        search = "quotiety";
                        if (!opAndvalidate.validateNum(tstxtKeyWord.Text.Trim()))
                        {
                            errorProvider1.SetError(tstxtKeyWord.Control, "请输入正整数");
                            isright = false;
                        }
                    }
                    if (isright)
                    {
                        DataSet ds = boperate.getds("select id as 编号,types as 试题类型,title as 试题,answer as 参考答案,quotiety as 难度系数 from program where " + search + " like '%" + tstxtKeyWord.Text.Trim() + "%' order by id", "program");
                        if (ds.Tables[0].Rows.Count > 0)
                            dataGridView3.DataSource = ds.Tables[0];
                        else
                            MessageBox.Show("没有要查找的相关记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                    }
                }
            }
        }
        #endregion

    }
}

⌨️ 快捷键说明

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