?? user.cs
字號:
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserPassword", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserPassword", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserSort", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserSort", System.Data.DataRowVersion.Original, null));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO [User] (UserID, UserPassword, UserSort) VALUES (@UserID, @UserPasswor" +
"d, @UserSort); SELECT UserID, UserPassword, UserSort FROM [User] WHERE (UserID =" +
" @UserID)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.NVarChar, 10, "UserID"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserPassword", System.Data.SqlDbType.NVarChar, 10, "UserPassword"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserSort", System.Data.SqlDbType.NVarChar, 10, "UserSort"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT UserID, UserPassword, UserSort FROM [User]";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE [User] SET UserID = @UserID, UserPassword = @UserPassword, UserSort = @UserSort WHERE (UserID = @Original_UserID) AND (UserPassword = @Original_UserPassword OR @Original_UserPassword IS NULL AND UserPassword IS NULL) AND (UserSort = @Original_UserSort OR @Original_UserSort IS NULL AND UserSort IS NULL); SELECT UserID, UserPassword, UserSort FROM [User] WHERE (UserID = @UserID)";
this.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.NVarChar, 10, "UserID"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserPassword", System.Data.SqlDbType.NVarChar, 10, "UserPassword"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@UserSort", System.Data.SqlDbType.NVarChar, 10, "UserSort"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserID", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserPassword", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserPassword", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_UserSort", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "UserSort", System.Data.DataRowVersion.Original, null));
//
// User
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.LightGray;
this.ClientSize = new System.Drawing.Size(448, 237);
this.Controls.Add(this.lblDatasetPosition);
this.Controls.Add(this.btnPrevious);
this.Controls.Add(this.btnNext);
this.Controls.Add(this.btnLast);
this.Controls.Add(this.btnFirst);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.groupBox3);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "User";
this.Text = "用戶信息管理";
this.Load += new System.EventHandler(this.User_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.objDataSetUser)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
public void ErrorHandle(System.Exception E)
{
MessageBox.Show(E.ToString());
}
private void ButtonPositonChange()
{
this.btnPrevious.Enabled=true;
this.btnNext.Enabled=true;
this.btnFirst.Enabled=true;
this.btnLast.Enabled=true;
if(this.BindingContext[this.objDataSetUser,"User"].Position==0)
{
this.btnFirst.Enabled=false;
this.btnPrevious.Enabled=false;
}
if(this.BindingContext[this.objDataSetUser,"User"].Position==this.BindingContext[this.objDataSetUser,"User"].Count-1)
{
this.btnNext.Enabled=false;
this.btnLast.Enabled=false;
}
}
private void DatasetPostionChange()
{
this.lblDatasetPosition.Text=(this.BindingContext[this.objDataSetUser,"User"].Position+1)+"的"+
(this.BindingContext[this.objDataSetUser,"User"].Count);
}
private void TextEnableControl(bool valid)
{
if(valid)
{
this.textId.Enabled=true;
this.textSort.Enabled=true;
this.textPassword.Enabled=true;
//this.chkValid.Enabled=true;
}
else
{
this.textId.Enabled=false;
this.textSort.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()
{
DataSetUser objDataSetTemp=new DataSetUser();
try
{
this.FillDataSet(objDataSetTemp);
}
catch (System.Exception E)
{
// 在此處添加錯誤處理代碼。
this.ErrorHandle(E);
}
try
{
this.objDataSetUser.Clear();
this.objDataSetUser.Merge(objDataSetTemp);
}
catch(System.Exception E)
{
// 在此處添加錯誤處理代碼。
this.ErrorHandle(E);
}
}
private void FillDataSet(DataSetUser 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 User_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.objDataSetUser,"User"].Position+=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnPrevious_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetUser,"User"].Position-=1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnFirst_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetUser,"User"].Position=0;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnLast_Click(object sender, System.EventArgs e)
{
this.BindingContext[this.objDataSetUser,"User"].Position=this.BindingContext[this.objDataSetUser,"User"].Count-1;
this.ButtonPositonChange();
this.DatasetPostionChange();
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
try
{
this.BindingContext[this.objDataSetUser,"User"].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.objDataSetUser,"User"].Count>0)&
(MessageBox.Show("真的要刪除此記錄嗎","確定刪除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
{
try
{
int currentPosition=this.BindingContext[this.objDataSetUser,"User"].Position;
this.objDataSetUser.User.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);
}
private void btnQuery_Click(object sender, System.EventArgs e)
{
}
public void UpdateDataSet()
{
this.BindingContext[this.objDataSetUser,"User"].EndCurrentEdit();
DataSetUser objDataSetTemp=new DataSetUser();
objDataSetTemp=(DataSetUser)(this.objDataSetUser.GetChanges());
try
{
this.UpdateDataSource(objDataSetTemp);
this.objDataSetUser.Merge(objDataSetTemp);
this.objDataSetUser.AcceptChanges();
}
catch(System.Exception E)
{
this.ErrorHandle(E);
}
}
public void UpdateDataSource(DataSetUser 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.objDataSetUser,"User"].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();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -