📄 form_stkcx.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
namespace bizdb
{
/// <summary>
/// Form_stkcx 的摘要说明。
/// </summary>
public class Form_stkcx : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel pnl_stkcx;
private System.Windows.Forms.Label lbl_cjsj1;
private System.Windows.Forms.Label lbl_cjsj2;
private System.Windows.Forms.DateTimePicker dtp_cjsj1;
private System.Windows.Forms.DateTimePicker dtp_cjsj2;
private System.Windows.Forms.Button btn_cx;
private System.Windows.Forms.Button btn_sc;
private System.Windows.Forms.DataGrid dgd_stkcx;
private System.Data.SqlClient.SqlConnection sqlcnt_cx = new SqlConnection();
private System.Data.SqlClient.SqlCommand sqlcmd_cx;
private System.Data.SqlClient.SqlDataAdapter sqldpt_cx = new SqlDataAdapter();
private System.Data.DataSet dst_cx = new DataSet();
private System.Data.SqlClient.SqlCommand sqlcmd_d;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
private dbAccess db = new dbAccess();
public Form_stkcx()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.pnl_stkcx = new System.Windows.Forms.Panel();
this.btn_sc = new System.Windows.Forms.Button();
this.btn_cx = new System.Windows.Forms.Button();
this.dtp_cjsj2 = new System.Windows.Forms.DateTimePicker();
this.dtp_cjsj1 = new System.Windows.Forms.DateTimePicker();
this.lbl_cjsj2 = new System.Windows.Forms.Label();
this.lbl_cjsj1 = new System.Windows.Forms.Label();
this.dgd_stkcx = new System.Windows.Forms.DataGrid();
this.pnl_stkcx.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgd_stkcx)).BeginInit();
this.SuspendLayout();
//
// pnl_stkcx
//
this.pnl_stkcx.Controls.Add(this.btn_sc);
this.pnl_stkcx.Controls.Add(this.btn_cx);
this.pnl_stkcx.Controls.Add(this.dtp_cjsj2);
this.pnl_stkcx.Controls.Add(this.dtp_cjsj1);
this.pnl_stkcx.Controls.Add(this.lbl_cjsj2);
this.pnl_stkcx.Controls.Add(this.lbl_cjsj1);
this.pnl_stkcx.Dock = System.Windows.Forms.DockStyle.Top;
this.pnl_stkcx.Location = new System.Drawing.Point(0, 0);
this.pnl_stkcx.Name = "pnl_stkcx";
this.pnl_stkcx.Size = new System.Drawing.Size(792, 120);
this.pnl_stkcx.TabIndex = 0;
//
// btn_sc
//
this.btn_sc.Location = new System.Drawing.Point(664, 72);
this.btn_sc.Name = "btn_sc";
this.btn_sc.TabIndex = 5;
this.btn_sc.Text = "删除";
this.btn_sc.Click += new System.EventHandler(this.btn_sc_Click);
//
// btn_cx
//
this.btn_cx.Location = new System.Drawing.Point(496, 72);
this.btn_cx.Name = "btn_cx";
this.btn_cx.TabIndex = 4;
this.btn_cx.Text = "查询";
this.btn_cx.Click += new System.EventHandler(this.btn_cx_Click);
//
// dtp_cjsj2
//
this.dtp_cjsj2.Location = new System.Drawing.Point(152, 72);
this.dtp_cjsj2.Name = "dtp_cjsj2";
this.dtp_cjsj2.TabIndex = 3;
this.dtp_cjsj2.Value = new System.DateTime(2004, 1, 1, 0, 0, 0, 0);
//
// dtp_cjsj1
//
this.dtp_cjsj1.Location = new System.Drawing.Point(152, 24);
this.dtp_cjsj1.Name = "dtp_cjsj1";
this.dtp_cjsj1.TabIndex = 2;
this.dtp_cjsj1.Value = new System.DateTime(2004, 1, 1, 0, 0, 0, 0);
//
// lbl_cjsj2
//
this.lbl_cjsj2.Location = new System.Drawing.Point(24, 72);
this.lbl_cjsj2.Name = "lbl_cjsj2";
this.lbl_cjsj2.TabIndex = 1;
this.lbl_cjsj2.Text = "至";
//
// lbl_cjsj1
//
this.lbl_cjsj1.Location = new System.Drawing.Point(24, 24);
this.lbl_cjsj1.Name = "lbl_cjsj1";
this.lbl_cjsj1.Size = new System.Drawing.Size(104, 23);
this.lbl_cjsj1.TabIndex = 0;
this.lbl_cjsj1.Text = "试题创建时间从";
//
// dgd_stkcx
//
this.dgd_stkcx.DataMember = "";
this.dgd_stkcx.Dock = System.Windows.Forms.DockStyle.Bottom;
this.dgd_stkcx.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dgd_stkcx.Location = new System.Drawing.Point(0, 125);
this.dgd_stkcx.Name = "dgd_stkcx";
this.dgd_stkcx.ReadOnly = true;
this.dgd_stkcx.Size = new System.Drawing.Size(792, 448);
this.dgd_stkcx.TabIndex = 1;
this.dgd_stkcx.MouseUp += new System.Windows.Forms.MouseEventHandler(this.dgd_stkcx_MouseUp);
this.dgd_stkcx.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dgd_stkcx_Navigate);
//
// Form_stkcx
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(792, 573);
this.Controls.Add(this.dgd_stkcx);
this.Controls.Add(this.pnl_stkcx);
this.Name = "Form_stkcx";
this.Text = "试题库查询";
this.Load += new System.EventHandler(this.Form_stkcx_Load);
this.pnl_stkcx.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgd_stkcx)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void dgd_stkcx_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
private void Form_stkcx_Load(object sender, System.EventArgs e)
{
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.ControlBox = false;
this.sqlcnt_cx.ConnectionString = db.connStr;
System.Windows.Forms.DataGridTableStyle dgt_st = new DataGridTableStyle();
dgt_st.MappingName = "Question";
System.Windows.Forms.DataGridColumnStyle dgc_st1 = new DataGridTextBoxColumn();
dgc_st1.MappingName = "que_content";
dgc_st1.HeaderText = "试题内容";
dgc_st1.Width = (dgd_stkcx.Width)*2/3;
System.Windows.Forms.DataGridColumnStyle dgc_st2 = new DataGridTextBoxColumn();
dgc_st2.MappingName = "que_type";
dgc_st2.HeaderText = "试题样式";
System.Windows.Forms.DataGridColumnStyle dgc_st3 = new DataGridTextBoxColumn();
dgc_st3.MappingName = "que_score";
dgc_st3.HeaderText = "试题分值";
System.Windows.Forms.DataGridColumnStyle dgc_st4 = new DataGridTextBoxColumn();
dgc_st4.MappingName = "que_difficulty";
dgc_st4.HeaderText = "试题难度";
dgt_st.GridColumnStyles.Add(dgc_st1);
dgt_st.GridColumnStyles.Add(dgc_st2);
dgt_st.GridColumnStyles.Add(dgc_st3);
dgt_st.GridColumnStyles.Add(dgc_st4);
this.dgd_stkcx.TableStyles.Add(dgt_st);
}
private void btn_cx_Click(object sender, System.EventArgs e)
{
try
{
this.sqlcmd_cx = this.sqlcnt_cx.CreateCommand();
this.sqlcmd_cx.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmd_cx.CommandText = "select_date";
sqlcmd_cx.Parameters.Add("@que_sdate1",System.Data.SqlDbType.DateTime);
sqlcmd_cx.Parameters.Add("@que_sdate2",System.Data.SqlDbType.DateTime);
sqlcmd_cx.Parameters["@que_sdate1"].Value = System.DateTime.Parse(this.dtp_cjsj1.Value.ToString());
sqlcmd_cx.Parameters["@que_sdate2"].Value = System.DateTime.Parse(this.dtp_cjsj2.Value.ToString());
this.sqldpt_cx.SelectCommand = sqlcmd_cx;
if(this.dst_cx.Tables.IndexOf("Question") != -1)
{
this.dst_cx.Tables["Question"].Clear();
}
sqlcnt_cx.Open();
sqldpt_cx.Fill(dst_cx,"Question");
sqlcnt_cx.Close();
this.dgd_stkcx.DataSource = dst_cx;
this.dgd_stkcx.DataMember = "Question";
}
catch(System.Exception mass)
{
MessageBox.Show(mass.Message);
this.sqlcnt_cx.Close();
}
}
private void btn_sc_Click(object sender, System.EventArgs e)
{
try
{
DialogResult result=MessageBox.Show("确定要删除记录吗?","阜和教育课程体系试题库系统提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(result == DialogResult.Yes)
{
this.sqlcmd_d = this.sqlcnt_cx.CreateCommand();
this.sqlcmd_d.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmd_d.CommandText = "delete_date";
sqlcmd_d.Parameters.Add("@que_no",System.Data.SqlDbType.Int);
sqlcmd_d.Parameters["@que_no"].Value = int.Parse(dst_cx.Tables["Question"].Rows[this.dgd_stkcx.CurrentRowIndex]["que_no"].ToString());//System.DateTime.Parse(dst_cx.Tables["Question"].Rows[this.dgd_stkcx.CurrentRowIndex]["que_createtime"].ToString());
sqlcnt_cx.Open();
sqlcmd_d.ExecuteNonQuery();
sqlcnt_cx.Close();
this.sqlcmd_cx = this.sqlcnt_cx.CreateCommand();
this.sqlcmd_cx.CommandType = System.Data.CommandType.StoredProcedure;
sqlcmd_cx.CommandText = "select_date";
sqlcmd_cx.Parameters.Add("@que_sdate1",System.Data.SqlDbType.DateTime);
sqlcmd_cx.Parameters.Add("@que_sdate2",System.Data.SqlDbType.DateTime);
sqlcmd_cx.Parameters["@que_sdate1"].Value = System.DateTime.Parse(this.dtp_cjsj1.Value.ToString());
sqlcmd_cx.Parameters["@que_sdate2"].Value = System.DateTime.Parse(this.dtp_cjsj2.Value.ToString());
this.sqldpt_cx.SelectCommand = sqlcmd_cx;
if(this.dst_cx.Tables.IndexOf("Question") != -1)
{
this.dst_cx.Tables["Question"].Clear();
}
sqlcnt_cx.Open();
sqldpt_cx.Fill(dst_cx,"Question");
sqlcnt_cx.Close();
}
}
catch//(System.Exception mass)
{
MessageBox.Show("答案可能已经被引用,请确认后删除","阜和教育课程体系试题库系统提示",MessageBoxButtons.OK);
sqlcnt_cx.Close();
}
//答案可能已经被引用,请确认后删除
}
private void dgd_stkcx_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(e.Button == System.Windows.Forms.MouseButtons.Left)
{
if(this.dgd_stkcx.CurrentRowIndex != -1)
{
dgd_stkcx.Select(this.dgd_stkcx.CurrentRowIndex);
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -