📄 form_kc.cs
字号:
txt_ckjc.Enabled = true;
txt_jxdgsm.Enabled =true;
}
private void setfalse()
{
cbb_kcsl.Enabled = false;
cbb_kcjd.Enabled =false;
txt_kcdm.Enabled = false;
txt_kcmc.Enabled = false;
txt_ckjc.Enabled = false;
txt_jxdgsm.Enabled =false;
}
private void reject_jxdy()
{
if (i != 0)
{
this.dst_kc.RejectChanges();
i = 0;
}
}
private void load_kc()
{
i = 0;
dst_kc.Clear();
txt_kcdm.DataBindings.Clear();
txt_kcmc.DataBindings.Clear();
txt_ckjc.DataBindings.Clear();
txt_jxdgsm.DataBindings.Clear();
sqlcnt.ConnectionString = dbAccess.conn ;
try
{
sqlcnt.Open();
}
catch
{
MessageBox.Show("服务器连接错误","阜和教育课程体系试题库系统提示");
return;
}
cbb_kcsl.Items.Clear ();
cbb_kcjd.Items.Clear ();
cbb_kcsl.Items.Add("基础课");
cbb_kcsl.Items.Add("公共课");
cbb_kcsl.Items.Add("专业课");
cbb_kcsl.Items.Add("其他");
cbb_kcjd.Items.Add ("第一阶段");
cbb_kcjd.Items.Add ("第二阶段");
cbb_kcjd.Items.Add ("第三阶段");
sqlcmd.CommandText = "select cou_no,cou_name,cou_kind = (case cou_kind when 1 then '基础课' when 2 then '公共课' when 3 then '专业课' when 4 then '其他' end),cou_level = (case cou_level when 1 then '第一阶段' when 2 then '第二阶段' when 3 then '第三阶段' end),cou_outline,cou_material,cou_memo from course";
sqlcmd.Connection = sqlcnt ;
sqldpt_kc.SelectCommand = sqlcmd;
sqldpt_kc.Fill(dst_kc,"table");
txt_kcdm.DataBindings.Add(new Binding("text",dst_kc,"table.cou_no"));
txt_kcmc.DataBindings.Add(new Binding("text",dst_kc,"table.cou_name"));
txt_ckjc.DataBindings.Add(new Binding("text",dst_kc,"table.cou_material"));
txt_jxdgsm.DataBindings.Add(new Binding("text",dst_kc,"table.cou_outline"));
DataGridTableStyle style=new DataGridTableStyle();
style.MappingName = "table";
DataGridTextBoxColumn cou_no = new DataGridTextBoxColumn();
cou_no.HeaderText = "课程代码";
cou_no.MappingName = "cou_no";
cou_no.Width = 70;
DataGridTextBoxColumn cou_name = new DataGridTextBoxColumn();
cou_name.HeaderText = "课程名称";
cou_name.MappingName = "cou_name";
cou_name.Width = 130;
DataGridTextBoxColumn cou_kind = new DataGridTextBoxColumn();
cou_kind.HeaderText = "课程属类";
cou_kind.MappingName = "cou_kind";
cou_kind.Width = 70;
DataGridTextBoxColumn cou_level = new DataGridTextBoxColumn();
cou_level.HeaderText = "课程阶段";
cou_level.MappingName = "cou_level";
cou_level.Width =90;
DataGridTextBoxColumn cou_outline = new DataGridTextBoxColumn();
cou_outline.HeaderText = "课程教学大纲说明";
cou_outline.MappingName = "cou_outline";
cou_outline.Width = 200;
DataGridTextBoxColumn cou_material = new DataGridTextBoxColumn ();
cou_material.HeaderText ="参考教材";
cou_material.MappingName = "cou_material";
cou_material.Width = 200;
style.GridColumnStyles.AddRange(new DataGridColumnStyle[]{cou_no,cou_name,cou_kind,cou_level,cou_outline,cou_material,});
dgd_kc.TableStyles.Clear();
dgd_kc.TableStyles.Add (style);
dgd_kc.SetDataBinding(dst_kc,"table");
if (this.dst_kc.Tables[0].Rows.Count != 0)
{
dgd_kc.CurrentRowIndex = 0;
dgd_kc.Select(dgd_kc.CurrentRowIndex);
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
}
sqlcnt.Close ();
this.setfalse();
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
}
private void dgd_kc_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
Point pt = new Point(e.X,e.Y);
DataGrid.HitTestInfo hit = dgd_kc.HitTest(pt);
if(hit.Type == DataGrid.HitTestType.Cell)
{
dgd_kc.Select(hit.Row);
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
}
}
private void btn_sjl_Click(object sender, System.EventArgs e)
{
this.reject_jxdy();
dgd_kc.UnSelect(dgd_kc.CurrentRowIndex);
dgd_kc.CurrentRowIndex = 0;
dgd_kc.Select(dgd_kc.CurrentRowIndex);
this.setfalse();
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
}
private void btn_qyjl_Click(object sender, System.EventArgs e)
{
this.reject_jxdy ();
if (dgd_kc.CurrentRowIndex != 0)
{
dgd_kc.UnSelect(dgd_kc.CurrentRowIndex );
dgd_kc.CurrentRowIndex -= 1;
dgd_kc.Select (dgd_kc.CurrentRowIndex );
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
}
this.setfalse();
}
private void btn_hyjl_Click(object sender, System.EventArgs e)
{
this.reject_jxdy ();
if (dgd_kc.CurrentRowIndex != dst_kc.Tables[0].Rows.Count - 1)
{
dgd_kc.UnSelect(dgd_kc.CurrentRowIndex );
dgd_kc.CurrentRowIndex += 1;
dgd_kc.Select (dgd_kc.CurrentRowIndex );
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
}
this.setfalse();
}
private void btn_mjl_Click(object sender, System.EventArgs e)
{
this.reject_jxdy ();
dgd_kc.UnSelect(dgd_kc.CurrentRowIndex);
dgd_kc.CurrentRowIndex=dst_kc.Tables[0].Rows.Count - 1;
dgd_kc.Select(dgd_kc.CurrentRowIndex);
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
this.cbb_kcjd.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][3].ToString ();
this.cbb_kcsl.SelectedItem = this.dst_kc.Tables [0].Rows[dgd_kc.CurrentRowIndex ][2].ToString ();
this.setfalse();
}
private void btn_bj_Click(object sender, System.EventArgs e)
{
i = 1;
this.setenable();
btn_tj.Enabled = false;
btn_sc.Enabled = false;
btn_qrtj.Enabled = true;
btn_qx.Enabled = true;
}
private void btn_qrtj_Click(object sender, System.EventArgs e)
{
SqlCommand sqlsp = new SqlCommand();
if (i == 1)
{
if (this.cbb_kcjd.SelectedIndex == -1 || this.cbb_kcsl.SelectedIndex == -1)
{
MessageBox.Show("课程属类课程阶段不可为空","阜和教育课程体系试题库系统提示");
return;
}
sqlsp.CommandText = "UpdateCourse";
sqlsp.Connection = sqlcnt;
sqlsp.CommandType = CommandType.StoredProcedure;
SqlParameter myPara1 = sqlsp.Parameters.Add("@cou_no",SqlDbType.Int);
myPara1.Value = int.Parse(this.txt_kcdm.Text);
myPara1.Direction = ParameterDirection.Input ;
SqlParameter myPara2 = sqlsp.Parameters.Add("@cou_name",SqlDbType.VarChar,30);
myPara2.Value = this.txt_kcmc.Text ;
myPara2.Direction = ParameterDirection.Input;
SqlParameter myPara3 = sqlsp.Parameters.Add("@cou_kind",SqlDbType.Char,1);
myPara3.Value = this.cbb_kcsl.SelectedIndex + 1;
myPara3.Direction = ParameterDirection.Input ;
SqlParameter myPara4 = sqlsp.Parameters.Add("@cou_level",SqlDbType.Char,1);
myPara4.Value = this.cbb_kcjd.SelectedIndex + 1;
myPara4.Direction = ParameterDirection.Input ;
SqlParameter myPara5 = sqlsp.Parameters.Add("@cou_outline",SqlDbType.Text);
myPara5.Value = this.txt_jxdgsm.Text ;
myPara5.Direction = ParameterDirection.Input ;
SqlParameter myPara6 = sqlsp.Parameters.Add("@cou_material",SqlDbType.VarChar,200);
myPara6.Value = this.txt_ckjc.Text;
myPara6.Direction = ParameterDirection.Input ;
}
if (i == 2)
{
if (this.cbb_kcjd.SelectedIndex == -1 || this.cbb_kcsl.SelectedIndex == -1)
{
MessageBox.Show("课程属类课程阶段不可为空","阜和教育课程体系试题库系统提示");
return;
}
sqlsp.CommandText ="InsertCourse";
sqlsp.Connection = sqlcnt;
sqlsp.CommandType = CommandType.StoredProcedure ;
SqlParameter myPara1 = sqlsp.Parameters.Add("@cou_name",SqlDbType.VarChar,30);
string oo = this.txt_kcmc.Text ;
myPara1.Value = oo;
myPara1.Direction = ParameterDirection.Input ;
SqlParameter myPara2 = sqlsp.Parameters.Add("@cou_kind",SqlDbType.Char,1);
myPara2.Value = this.cbb_kcsl.SelectedIndex +1;
myPara2.Direction = ParameterDirection.Input ;
SqlParameter myPara3 = sqlsp.Parameters.Add("@cou_level",SqlDbType.Char,1);
myPara3.Value = this.cbb_kcjd.SelectedIndex + 1;
myPara3.Direction = ParameterDirection.Input ;
SqlParameter myPara4 = sqlsp.Parameters.Add("@cou_outline",SqlDbType.Text );
myPara4.Value = this.txt_jxdgsm.Text ;
myPara4.Direction = ParameterDirection.Input ;
SqlParameter myPara5 = sqlsp.Parameters.Add("@cou_material",SqlDbType.VarChar ,200);
myPara5.Value = this.txt_ckjc.Text ;
myPara5.Direction = ParameterDirection.Input ;
}
if (i == 3)
{
sqlsp.CommandText = "DeleteCourse";
sqlsp.Connection = sqlcnt;
sqlsp.CommandType = CommandType.StoredProcedure ;
SqlParameter myPara1 = sqlsp.Parameters.Add ("@cou_no",SqlDbType.Int);
myPara1.Value = cou_no;
myPara1.Direction = ParameterDirection.Input ;
}
try
{
sqlcnt.Open ();
}
catch
{
MessageBox.Show("服务器连接出错","阜和教育课程体系试题库系统提示");
this.setfalse();
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
i = 0;
return;
}
try
{
sqlsp.ExecuteReader();
}
catch
{
MessageBox.Show("此课在授课中...不可删除","阜和教育课程体系试题库系统提示");
this.setfalse();
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
i = 0;
return;
}
finally
{
sqlcnt.Close ();
}
this.dst_kc.AcceptChanges ();
MessageBox.Show("数据库成功更新","阜和教育课程体系试题库系统提示");
this.load_kc ();
}
private void btn_tj_Click(object sender, System.EventArgs e)
{
i = 2;
DataRow drw = this.dst_kc.Tables [0].NewRow ();
dst_kc.Tables [0].Rows.Add(drw);
this.dgd_kc.UnSelect (dgd_kc.CurrentRowIndex );
this.dgd_kc.CurrentRowIndex = this.dst_kc.Tables[0].Rows.Count - 1;
this.dgd_kc.Select(dgd_kc.CurrentRowIndex );
this.cbb_kcjd.SelectedIndex = -1;
this.cbb_kcsl.SelectedIndex = -1;
this.btn_tj.Enabled = false;
this.btn_sc.Enabled = false;
this.btn_qrtj.Enabled = true;
this.btn_qx.Enabled = true;
this.setenable ();
}
private void btn_sc_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show("确认要删除吗?","阜和教育课程体系试题库系统提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(result==DialogResult.Yes)
{
try
{
i = 3;
cou_no = int.Parse(this.dst_kc.Tables[0].Rows[dgd_kc.CurrentRowIndex][0].ToString());
dst_kc.Tables[0].Rows[dgd_kc.CurrentRowIndex].Delete ();
SqlCommand sqlsp = new SqlCommand();
if (i == 3)
{
sqlsp.CommandText = "DeleteCourse";
sqlsp.Connection = sqlcnt;
sqlsp.CommandType = CommandType.StoredProcedure ;
SqlParameter myPara1 = sqlsp.Parameters.Add ("@cou_no",SqlDbType.Int);
myPara1.Value = cou_no;
myPara1.Direction = ParameterDirection.Input ;
}
try
{
sqlcnt.Open ();
}
catch
{
MessageBox.Show("服务器连接出错","阜和教育课程体系试题库系统提示");
return;
}
try
{
sqlsp.ExecuteReader();
}
catch
{
MessageBox.Show("此课在授课中...不可删除","阜和教育课程体系试题库系统提示");
return;
}
finally
{
sqlcnt.Close ();
}
this.dst_kc.AcceptChanges ();
// MessageBox.Show("数据库成功更新","阜和教育课程体系试题库系统提示");
this.load_kc ();
}
catch
{
MessageBox.Show("输入数据不正确!","阜和教育课程体系试题库系统提示");//
}
}
//
}
private void btn_qx_Click(object sender, System.EventArgs e)
{
this.reject_jxdy ();
i =0;
btn_bj.Enabled = true;
btn_tj.Enabled = true;
btn_sc.Enabled = true;
this.btn_qrtj.Enabled = false;
btn_qx.Enabled = false;
this.setfalse ();
}
private void dgd_kc_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (i != 0)
{
dgd_kc.CurrentRowIndex = dst_kc.Tables[0].Rows.Count - 1;
dgd_kc.Select(dgd_kc.CurrentRowIndex);
this.btn_qx_Click (sender,e);
}
}
private void dgd_kc_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -