📄 fstuinfo.cs
字号:
// textBox12
//
this.textBox12.Location = new System.Drawing.Point(280, 544);
this.textBox12.Name = "textBox12";
this.textBox12.Size = new System.Drawing.Size(120, 21);
this.textBox12.TabIndex = 19;
this.textBox12.Text = "";
//
// label12
//
this.label12.Location = new System.Drawing.Point(232, 544);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(48, 24);
this.label12.TabIndex = 20;
this.label12.Text = "共有:";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(760, 605);
this.Controls.Add(this.label12);
this.Controls.Add(this.textBox12);
this.Controls.Add(this.textBox11);
this.Controls.Add(this.textBox10);
this.Controls.Add(this.textBox9);
this.Controls.Add(this.label11);
this.Controls.Add(this.label10);
this.Controls.Add(this.label9);
this.Controls.Add(this.textBox8);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.toolBar1);
this.Name = "Form2";
this.Text = "学生信息维护";
this.Load += new System.EventHandler(this.Form2_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void Form2_Load(object sender, System.EventArgs e)
{
this.dataGrid1.Enabled = false;
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%";
this.sqlDataAdapter1.SelectCommand.Parameters[1].Value = "%";
this.sqlDataAdapter1.SelectCommand.Parameters[2].Value = "%";
try
{
this.sqlDataAdapter1.Fill(this.dataSet11);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
this.cmOrders=(CurrencyManager) BindingContext[dataSet11,"学生基本信息"];
this.Set(true);
this.textBox12.Enabled = false;
this.textbox_change();
}
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);
this.textbox_change();
}
if(e.Button == this.toolBarButton7)
{
SetModifyMode(true);
this.Set(false);
}
if(e.Button == this.toolBarButton8)
{
bool canSubmit;
canSubmit=this.CheckNotNull();
if(canSubmit==false)//有非空值字段为空,不允许提交
{
return;
}
cmOrders.EndCurrentEdit();
this.Set(true);
if(dataSet11.GetChanges()!=null)
{
string qq ;
qq = this.textBox8.Text;
if(qq == "男" || qq == "女")
{
try
{
this.sqlDataAdapter1.Update(dataSet11);
SetModifyMode(false);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
dataSet11.RejectChanges();
}
}
else
{
MessageBox.Show("只能输入男或女","提示",MessageBoxButtons.YesNo);
this.textBox8.Clear();
this.textBox8.Enabled = true;
}
}
this.SetModifyMode(false);
this.textbox_change();
return;
}
if(e.Button == this.toolBarButton9)
{
this.textBox5.Focus();
cmOrders.AddNew();//新增一条记录
SetDefaultValue();//设置默认值
SetModifyMode(true);//设置控件只读等属性
this.Set(false);
if(e.Button == this.toolBarButton10)
{
this.Close();
}
}
if(e.Button == this.toolBarButton10)
{
this.Close();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%";
this.sqlDataAdapter1.SelectCommand.Parameters[1].Value="%";
this.sqlDataAdapter1.SelectCommand.Parameters[2].Value="%";
if(this.textBox1.Text != "")
{
this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%"+this.textBox1.Text+"%";
}
if(this.textBox2.Text != "")
{
this.sqlDataAdapter1.SelectCommand.Parameters[1].Value="%"+this.textBox2.Text+"%";
}
if(this.textBox3.Text != "")
{
this.sqlDataAdapter1.SelectCommand.Parameters[2].Value="%"+this.textBox3.Text+"%";
}
this.dataSet11.Clear();//刷新数据
this.sqlDataAdapter1.Fill(this.dataSet11);
}
//--------------供窗体重载,设置默认值------------
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.textBox4.Enabled =!bln;
this.textBox5.Enabled =!bln;
this.textBox6.Enabled =!bln;
this.textBox7.Enabled =!bln;
this.textBox8.Enabled =!bln;
this.textBox9.Enabled =!bln;
this.textBox10.Enabled =!bln;
this.textBox11.Enabled =!bln;
}
private void textbox_change()
{
int count=this.BindingContext[this.dataSet11,"学生基本信息"].Count;
this.textBox12.Text= count+"条记录";
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -