usermanager.cs
来自「独立完成考勤管理软件加打卡系统(C#) 是打卡加管理系统软件 」· CS 代码 · 共 981 行 · 第 1/3 页
CS
981 行
if(userTable.Rows[k][0].ToString().Trim().Equals(this.textUserID.Text.ToString().Trim()))
{
MessageBox.Show(this,"此号码已经存在不能再添加啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
ClearText();
this.textUserID.Focus();
UserIDAddOne();
return true;
}
}
}
catch(Exception exse)
{
MessageBox.Show(this,exse.ToString().Trim(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
return false;
}
#endregion
#region 初始化文本框为只读状态的函数
private void ReadText(bool f)
{
this.userTypeComBox.Enabled=f;
this.userName.Enabled=f;
this.textpassword.Enabled=f;
this.textUserID.Enabled=f;
}
#endregion
#region 填充用户类型下拉表框的函数
private void fillUserType(DataTable userSet)
{
for(int i=1;i<userSet.Rows.Count;i++)
{
this.userTypeComBox.Items.Add(userSet.Rows[i][3].ToString().Trim());
}
}
#endregion
#region 绑定函数
private void BudingsFunction(DataTable userSet)
{
this.cmOrders=(System.Windows.Forms.CurrencyManager)BindingContext[userSet];
this.textUserID.DataBindings.Add("Text",userSet,"用户号");
this.textpassword.DataBindings.Add("Text",userSet,"密码");
this.userTypeComBox.DataBindings.Add("Text",userSet,"用户类型");
this.userName.DataBindings.Add("Text",userSet,"用户名称");
this.textBox1.Text=MD4.DecryptString(this.textpassword.Text);
}
#endregion
#region 清空文本框内容的函数
private void ClearText()
{
this.textUserID.Text="";
this.textpassword.Text="";
this.userTypeComBox.Text="";
this.userName.Text="";
}
#endregion
#region 用户号自动加1的函数
private void UserIDAddOne()
{
try
{
string strSql="select max(用户号)用户号 from System_UserTable";
int maxID=1;
object result=conn.ExcuteStrSqlObject(strSql);
if(result!=System.DBNull.Value)
{
maxID=Convert.ToInt32(result)+1;
}
this.textUserID.Text=maxID.ToString().Trim();
}
catch(Exception ele)
{
MessageBox.Show(this,ele.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 工具栏上事件....
#region 上一条记录按钮
private void btnLast_Click(object sender, System.EventArgs e)
{
try
{
if(this.cmOrders.Position.Equals(0))
{
MessageBox.Show(this,"你已经到了第一条记录啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.btnFirst.Enabled=false;
this.btnLast.Enabled=false;
this.btnEnd.Enabled=true;
this.btnNext.Enabled=true;
}
else if(this.cmOrders.Position>0)
{
this.dataGrid.UnSelect(this.cmOrders.Position);
this.cmOrders.Position--;
this.dataGrid.Select(this.cmOrders.Position);
this.dataGrid.CurrentRowIndex=this.cmOrders.Position;
}
}
catch(Exception elses)
{
throw new Exception(elses.ToString());
}
}
#endregion
#region 下一条记录
private void btnNext_Click(object sender, System.EventArgs e)
{
try
{
if(this.cmOrders.Position.Equals(this.cmOrders.Count-1))
{
MessageBox.Show(this,"你已经到了最后一条记录啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.btnFirst.Enabled=true;
this.btnLast.Enabled=true;
this.btnEnd.Enabled=false;
this.btnNext.Enabled=false;
}
else if(this.cmOrders.Position<this.cmOrders.Count-1)
{
this.dataGrid.UnSelect(this.cmOrders.Position);
this.cmOrders.Position++;
this.dataGrid.Select(this.cmOrders.Position);
this.dataGrid.CurrentRowIndex=this.cmOrders.Position;
}
}
catch(Exception elses)
{
throw new Exception(elses.ToString());
}
}
#endregion
#region 首记录按钮
private void btnFirst_Click(object sender, System.EventArgs e)
{
try
{
this.dataGrid.UnSelect(this.cmOrders.Position);
this.cmOrders.Position=0;
this.dataGrid.Select(this.cmOrders.Position);
this.dataGrid.CurrentRowIndex=this.cmOrders.Position;
MessageBox.Show(this,"你已经到了第一条记录啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.btnFirst.Enabled=false;
this.btnLast.Enabled=false;
this.btnEnd.Enabled=true;
this.btnNext.Enabled=true;
}
catch(Exception elses)
{
throw new Exception(elses.ToString());
}
}
#endregion
#region 尾记录按钮
private void btnEnd_Click(object sender, System.EventArgs e)
{
try
{
this.dataGrid.UnSelect(this.cmOrders.Position);
this.cmOrders.Position=this.cmOrders.Count-1;
this.dataGrid.Select(this.cmOrders.Position);
this.dataGrid.CurrentRowIndex=this.cmOrders.Position;
MessageBox.Show(this,"你已经到了最后一条记录啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.btnFirst.Enabled=true;
this.btnLast.Enabled=true;
this.btnEnd.Enabled=false;
this.btnNext.Enabled=false;
}
catch(Exception elses)
{
throw new Exception(elses.ToString());
}
}
#endregion
#region 添加按钮
private void btnAdd_Click(object sender, System.EventArgs e)
{
try
{
ReadText(true);
UserIDAddOne();
this.cmOrders.AddNew();
blAdd=true;
}
catch(Exception eye)
{
MessageBox.Show(this,eye.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 修改按钮
private void btnModify_Click(object sender, System.EventArgs e)
{
try
{
ReadText(true);
blModify=true;
}
catch(Exception eye)
{
MessageBox.Show(this,eye.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 删除按钮
private void btnDelete_Click(object sender, System.EventArgs e)
{
try
{
string userID=getuserFirstIDText(),usersecondID=this.dataGrid[0,1].ToString();
ReadText(true);
DialogResult result=MessageBox.Show(this,"是否删除此数据啦!!!","提示信息",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if(result.Equals(DialogResult.Yes))
{
this.cmOrders.RemoveAt(this.cmOrders.Position);
this.sqlUserDataAdaper.Update(this.userTableSet);
}
else
{
MessageBox.Show(this,"表中已经没有数据啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch(Exception eye)
{
MessageBox.Show(this,eye.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 保存按钮
private void btnSave_Click(object sender, System.EventArgs e)
{
try
{
if(UserManager.blAdd.Equals(true))
{
ReadText(false);
if(this.CheckIsNotNull())
{
return;
}
this.cmOrders.EndCurrentEdit();
this.textpassword.Text=MD4.EncryptString(this.textBox1.Text);
this.sqlUserDataAdaper.Update(this.userTableSet);
MessageBox.Show(this,"添加成功啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else if(UserManager.blModify.Equals(true))
{
ReadText(false);
if(this.CheckIsNotNull())
{
return;
}
this.cmOrders.EndCurrentEdit();
this.textpassword.Text=MD4.EncryptString(this.textBox1.Text);
this.sqlUserDataAdaper.Update(this.userTableSet);
MessageBox.Show(this,"修改成功啦!!!","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
catch(Exception eye)
{
MessageBox.Show(this,eye.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
#endregion
#region 退出按钮
private void btnExit_Click(object sender, System.EventArgs e)
{
DialogResult result=MessageBox.Show(this,"是否关闭窗体!!!","提示信息",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
if(result.Equals(DialogResult.Yes))
{
Close();
}
else
{
return;
}
}
#endregion
#endregion
#region DataFunction
private DataTable ExcuteSql(string strSql,string tableName)
{
DataSet dsSet=new DataSet();
DataTable dsTable=new DataTable();
try
{
dsSet=conn.ExcuteDataSetResult(strSql,tableName);
dsTable=dsSet.Tables[0];
}
catch(Exception eles)
{
MessageBox.Show(this,eles.ToString(),"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
return dsTable;
}
#endregion
#region getuserFirstIDText()
private String getuserFirstIDText()
{
string userIDText=this.dataGrid[0,0].ToString();
return userIDText;
}
#endregion
#region datagrid()
private String datagrid()
{
string selectUserID="";
selectUserID=this.textUserID.Text.ToString();
MessageBox.Show(this,selectUserID,"提示信息",MessageBoxButtons.OK,MessageBoxIcon.Information);
return selectUserID;
}
#endregion
#region 光标变化...
private void userTypeComBox_MouseLeave(object sender, System.EventArgs e)
{
ComboBox com=(ComboBox)sender;
com.DropDownStyle=System.Windows.Forms.ComboBoxStyle.Simple;
}
private void userTypeComBox_MouseEnter(object sender, System.EventArgs e)
{
ComboBox com=(ComboBox)sender;
com.DropDownStyle=System.Windows.Forms.ComboBoxStyle.DropDown;
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?