📄 selectcour.cs
字号:
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = "UPDATE 选课信息表 SET 序号 = @序号, 学号 = @学号, 课程编号 = @课程编号 WHERE (序号 = @Original_序号) AND (" +
"学号 = @Original_学号) AND (课程编号 = @Original_课程编号); SELECT 序号, 学号, 课程编号 FROM 选课信息表 W" +
"HERE (序号 = @序号)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@序号", System.Data.SqlDbType.VarChar, 10, "序号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 16, "学号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程编号", System.Data.SqlDbType.VarChar, 10, "课程编号"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_序号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "序号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程编号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程编号", System.Data.DataRowVersion.Original, null));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = "DELETE FROM 选课信息表 WHERE (序号 = @Original_序号) AND (学号 = @Original_学号) AND (课程编号 = @" +
"Original_课程编号)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_序号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "序号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 16, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程编号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程编号", System.Data.DataRowVersion.Original, null));
//
// SelectCour
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(752, 485);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label9);
this.Controls.Add(this.label8);
this.Controls.Add(this.button2);
this.Controls.Add(this.dataGrid2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.toolBar1);
this.Name = "SelectCour";
this.Text = "SelectCour";
this.Load += new System.EventHandler(this.SelectCour_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet71)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void SelectCour_Load(object sender, System.EventArgs e)
{
this.Set(true);
this.dataGrid1.Enabled = false;
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%";
this.sqlDataAdapter2.SelectCommand.Parameters[0].Value = "%";
this.sqlDataAdapter2.SelectCommand.Parameters[1].Value = "%";
this.sqlDataAdapter1.Fill(this.dataSet11);
try
{
this.sqlDataAdapter2.Fill(this.dataSet71);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.cmOrders=(CurrencyManager) BindingContext[dataSet11,"选课信息表"];
}
private void button1_Click(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%";
if(this.textBox1.Text != "")
{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%" + this.textBox1.Text + "%";
}
this.dataSet11.Clear();
this.sqlDataAdapter1.Fill(this.dataSet11);
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
if(e.Button == this.toolBarButton1)
{
try
{
this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
cmOrders.Position = 0;
this.dataGrid1.Select(cmOrders.Position); //选中当前行
this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
return;
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
if(e.Button == this.toolBarButton2)
{
if (cmOrders.Position >= 0)
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position++;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if(e.Button == this.toolBarButton3)
{
if (cmOrders.Position >= 0)
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position--;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
}
return;
}
if(e.Button == this.toolBarButton4)
{
this.dataGrid1.UnSelect(cmOrders.Position);
cmOrders.Position = cmOrders.Count-1;
this.dataGrid1.Select(cmOrders.Position);
this.dataGrid1.CurrentRowIndex = cmOrders.Position;
return;
}
if(e.Button == this.toolBarButton6)
{
this.Set(true);
DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
if(result==DialogResult.OK)
if(cmOrders.Count>0)//立即从数据集中删除
{
cmOrders.RemoveAt(cmOrders.Position);
this.sqlDataAdapter1.Update(dataSet11);
}
else
MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
if(e.Button == this.toolBarButton7)
{
cmOrders.AddNew();//新增一条记录
SetDefaultValue();//设置默认值
SetModifyMode(true);//设置控件只读等属性
this.Set(false);
}
if(e.Button == this.toolBarButton8)
{
bool canSubmit;
canSubmit=this.CheckNotNull();
if(canSubmit==false)//有非空值字段为空,不允许提交
{
return;
}
cmOrders.EndCurrentEdit();
if(dataSet11.GetChanges()!=null)
{
try
{
this.sqlDataAdapter1.Update(dataSet11);
SetModifyMode(false);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
dataSet11.RejectChanges();
}
}
this.SetModifyMode(false);
this.Set(true);
return;
}
if(e.Button == this.toolBarButton9)
{
SetModifyMode(true);
this.Set(false);
}
}
protected virtual void SetDefaultValue()
{
return;
}
//------------供窗体重载,检查非空字段-----------------
protected virtual bool CheckNotNull()
{
return(true);
}
//------------控制各个控件的只读属性-----------
protected virtual void SetModifyMode(bool blnEdit)
{
this.button1.Enabled=!blnEdit;
}
protected void Set(bool bln)
{
this.textBox2.Enabled =!bln;
this.textBox3.Enabled =!bln;
this.textBox4.Enabled =!bln;
}
private void SetDef()
{
string conn = "workstation id=localhost;Integrated Security = SSPT;database = 选课信息表;";
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(conn);
cn.Open();
System.Data.SqlClient.SqlCommand cmd = cn.CreateCommand();
cmd.CommandText = "select max(序号) 最大序号 from 选课信息表";
int max = 1;//计算机新编号
object result = cmd.ExecuteScalar();
if(result != System.DBNull.Value)
{
max = Convert.ToInt32(result) + 1;
}
int leng = max.ToString().Length;
}
private void label6_Click(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
this.sqlDataAdapter2.SelectCommand.Parameters[0].Value = "%";
this.sqlDataAdapter2.SelectCommand.Parameters[1].Value = "%";
if(this.textBox5.Text != "")
{
this.sqlDataAdapter2.SelectCommand.Parameters[0].Value = "%" + this.textBox5.Text + "%";
}
if(this.textBox6.Text != "")
{
this.sqlDataAdapter2.SelectCommand.Parameters[1].Value = "%" + this.textBox6.Text + "%";
}
this.dataSet71.Clear();
this.sqlDataAdapter2.Fill(this.dataSet71);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -