📄 reader.cs
字号:
this.textName.Enabled=true;
this.textBorrowBooks.Enabled=true;
this.textEmail.Enabled=true;
this.textTelNo.Enabled=true;
this.textPassword.Enabled=true;
//this.chkValid.Enabled=true;
}
else
{
this.textId.Enabled=false;
this.textName.Enabled=false;
this.textBorrowBooks.Enabled=false;
this.textEmail.Enabled=false;
this.textTelNo.Enabled=false;
this.textPassword.Enabled=false;
//this.chkValid.Enabled=false;
}
}
private void ButtonEnableControl(bool valid)
{
if(valid)
{
this.btnCancel.Enabled=true;
this.btnApply.Enabled=true;
}
else
{
this.btnCancel.Enabled=false;
this.btnApply.Enabled=false;
}
}
private void LoadDataSet()
{
DataSetReader objDataSetTemp=new DataSetReader();
try
{
this.FillDataSet(objDataSetTemp);
}
catch (System.Exception E)
{
// 在此处添加错误处理代码。
this.ErrorHandle(E);
}
try
{
this.objDataSetReader.Clear();
this.objDataSetReader.Merge(objDataSetTemp);
}
catch(System.Exception E)
{
// 在此处添加错误处理代码。
this.ErrorHandle(E);
}
}
private void FillDataSet(DataSetReader dataset)
{
dataset.EnforceConstraints=false;
try
{
this.sqlConnection1.Open();
this.sqlDataAdapter1.Fill(dataset);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
dataset.EnforceConstraints=true;
this.sqlConnection1.Close();
}
}
private void Reader_Load(object sender, System.EventArgs e)
{
this.LoadDataSet();
this.DatasetPostionChange();
this.ButtonPositonChange();
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnNext_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetReader,"Reader"].Position+=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetReader,"Reader"].Position-=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetReader,"Reader"].Position=0;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetReader,"Reader"].Position=this.BindingContext[this.objDataSetReader,"Reader"].Count-1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.objDataSetReader,"Reader"].AddNew();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.DatasetPostionChange();
this.ButtonPositonChange();
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
if((this.BindingContext[this.objDataSetReader,"Reader"].Count>0)&
(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
try
{
int currentPosition=this.BindingContext[this.objDataSetReader,"Reader"].Position;
this.objDataSetReader.Reader.Rows[currentPosition].Delete();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.ButtonPositonChange();
this.DatasetPostionChange();
}
else
return;
}
private void btnModify_Click(object sender, System.EventArgs e)
{
this.TextEnableControl(true);
this.ButtonEnableControl(true);
}
public void UpdateDataSet()
{
this.BindingContext[this.objDataSetReader,"Reader"].EndCurrentEdit();
DataSetReader objDataSetTemp=new DataSetReader();
objDataSetTemp=(DataSetReader)(this.objDataSetReader.GetChanges());
try
{
this.UpdateDataSource(objDataSetTemp);
this.objDataSetReader.Merge(objDataSetTemp);
this.objDataSetReader.AcceptChanges();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
}
public void UpdateDataSource(DataSetReader Changerows)
{
try
{
this.sqlConnection1.Open();
this.sqlDataAdapter1.Update(Changerows);
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
finally
{
this.sqlConnection1.Close();
}
}
private void btnApply_Click(object sender, System.EventArgs e)
{
try
{
this.UpdateDataSet();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.ButtonPositonChange();
this.DatasetPostionChange();
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.objDataSetReader,"Reader"].CancelCurrentEdit();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
this.DatasetPostionChange();
this.TextEnableControl(false);
this.TextEnableControl(false);
this.ButtonEnableControl(false);
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -