📄 frmusermanagement.cs
字号:
private void btnSearch_Click(object sender, System.EventArgs e)
{
//calling the method ClearDetails
this.ClearDetails();
//if the Employee Name is not null -
// store the value of the textfield to searchValue[0]
if(this.txtEName.Text!="")
{
searchValue[0] = this.txtEName.Text;
}
else
{
//if the textfield is null, make searchValue[0] to null
searchValue[0] = "";
}
//if the ComboBox fields is not null -
// store the value of the ComboBox to searchValue[1]
if(this.cboUId.Text!="")
{
searchValue[1] = this.cboUId.Text;
}
else
{
//if the combobox is null, make searchValue[1] to null
searchValue[1] = "";
}
//if the CheckBox field is checked -
// store the value true to searchValue[2]
if(this.chkEStat.Checked)
{
searchValue[2] = true.ToString();
}
else
{
//if the checkbox is unchecked store false to searchValue[2]
searchValue[2] = false.ToString();
}
UserManagement UAdminMgmt = new UserManagement();
dtab = new DataTable("Employees");
//Calling the FetchEmployeeDetails method of the Usermanagement class -
//and passing the searchValue to it
dtab = UAdminMgmt.FetchEmployeeDetails(searchValue);
//Setting the Data Grid's datasource to dtab
this.dbgDispEmp.DataSource = dtab;
//Checking if the Data Grid has atleast one row
if(this.dbgDispEmp.CurrentRowIndex > -1)
{
this.dbgDispEmp.Enabled = true;
this.btnPrint.Enabled =true;
this.btnPrintPreview.Enabled =true;
//Calling the method HidePWDColumninDG to hide the password field in Data Grid
this.HidePWDColumninDG();
}
else
{
MessageBox.Show("未找到任何记录");
}
}
private void btnExit_Click(object sender, System.EventArgs e)
{
frmMainMenu.varUsrMgmt = 0;
this.Close();
// frmMainMenu.mainMenuctr = 0;
}
//Method to hide the Password field in the Data Grid
private void HidePWDColumninDG()
{
//DataGridTextBoxColumn dcol = new DataGridTextBoxColumn();
//If already Existing , then remove
if(this.dbgDispEmp.TableStyles.Count >0)
{
this.dbgDispEmp.TableStyles.RemoveAt(0);
}
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dtab.TableName;
this.dbgDispEmp.DataSource = dtab;
//Adding the TableSTyle to the DataGrid
this.dbgDispEmp.TableStyles.Add(ts);
this.dbgDispEmp.TableStyles[0].GridColumnStyles[1].Width = 0;
}
//Data Grid Double Click
private void dbgDispEmp_DoubleClick(object sender, System.EventArgs e)
{
this.grpUsrDet.Enabled = true;
this.txtUsrId.Enabled = false;
this.txtPwd.Enabled = false;
this.btnUpdate.Enabled = true;
this.btnPwd.Enabled = true;
this.btnNew.Enabled = false;
this.btnSearch.Enabled = false;
this.btnPrint.Enabled = true;
this.pwdStat = true;
int prval = 0;
int ctr = 0;
//Data Grid's first Column value is storing the text field txtUsrId
this.txtUsrId.Text = this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,0].ToString();
//Data Grid's second Column value is storing the text field txtPwd
this.txtPwd.Text = this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,1].ToString();
//Data Grid's third Column value is storing the variable prval
prval = Convert.ToInt32(this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,2]);
this.ClearPriorities();
//Binary Conversion for Priority Field
while(prval !=0)
{
if((prval % 2) == 1)
{
this.chlPrior.SetItemChecked(ctr,true);
}
prval = prval/2;
ctr++;
}
//Data Grid's fourth Column value is storing the text field txtEmpName
this.txtEmpName.Text = this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,3].ToString();
//Data Grid's fifth Column value is storing the Check Box chkEmpStat
this.chkEmpStat.Checked = Convert.ToBoolean(this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,4].ToString());
//Data Grid's sixth Column value is storing the text field txtEmailId
this.txtEmailId.Text = this.dbgDispEmp[this.dbgDispEmp.CurrentRowIndex,5].ToString();
}
//Clicking on the PassWord Button
private void btnPwd_Click(object sender, System.EventArgs e)
{
//Creating an object of frmChangePassword class and passing the values
// UserId and Password to the constructor function
frmChangePassword fcpd = new frmChangePassword(this.txtUsrId.Text,this.txtPwd.Text);
fcpd.ShowDialog();
this.txtPwd.Text = fcpd.password;
//After changing the password refreshing the datagrid
//btnSearch_Click(sender,e);
this.btnPwd.Enabled = true;
this.btnPrint.Enabled = false;
this.btnNew.Enabled = false;
this.btnSearch.Enabled = true;
this.txtUsrId.Enabled = false;
this.txtPwd.Enabled = false;
}
private void chlPrior_Leave(object sender, System.EventArgs e)
{
if (this.pwdStat == false)
this.txtPwd.Enabled = true;
else
this.txtPwd.Enabled = false;
}
private void chkEmpStat_CheckedChanged(object sender, System.EventArgs e)
{
//Storing the current status of the CheckBox to the variable EmpStatus
this.EmpStatus = this.chkEmpStat.Checked;
}
private void txtEmailId_Validated(object sender, System.EventArgs e)
{
// If all conditions have been met, clear the ErrorProvider of errors.
errEmp.SetError(txtEmailId, "");
}
private void txtEmailId_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
frmNewUser f = new frmNewUser();
if(! f.ValidEmailAddress(this.txtEmailId.Text, out errorMsg))
{
// Cancel the event and select the text to be corrected by the user.
e.Cancel = true;
txtEmailId.Select(0, txtEmailId.Text.Length);
// Set the ErrorProvider error with the text to display.
this.errEmp.SetError(txtEmailId, errorMsg);
}
}
private void frmUserManagement_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
frmMainMenu.varUsrMgmt = 0;
}
private void txtEName_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.txtEName,"选择一个员工姓名用来搜索...(可选)");
}
private void cboUId_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.cboUId ,"选择一个用户标识用来搜索...(可选)");
}
private void chkEStat_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.chkEStat, "选择一个状态用来搜索...(可选)");
}
private void txtUsrId_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.txtEName,"输入用户标识");
}
private void txtEmpName_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.txtEName,"输入员工姓名");
}
private void chlPrior_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.chlPrior,"输入员工优先级");
}
private void txtPwd_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.txtPwd,"输入密码");
}
private void txtEmailId_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.txtEmailId,"输入电子邮件地址");
}
private void btnNew_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.btnNew,"添加记录");
}
private void btnUpdate_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.btnUpdate,"更新记录");
}
private void btnPrint_MouseHover(object sender, System.EventArgs e)
{
this.tipUsrMgmt.SetToolTip(this.btnPrint,"打印搜索结果");
}
private void pDocUser_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Graphics g = e.Graphics;
DrawTopLabel(g);
bool more = dataGridPrinter.DrawDataGrid(g);
if (more == true)
{
e.HasMorePages = true;
dataGridPrinter.PageNumber++;
}
}
void DrawTopLabel(Graphics g)
{
int TopMargin = pDocUser.DefaultPageSettings.Margins.Top;
lblHeading.Text ="用户信息";
g.FillRectangle(new SolidBrush(lblHeading.BackColor), lblHeading.Location.X, lblHeading.Location.Y + TopMargin, lblHeading.Size.Width+100, lblHeading.Size.Height);
g.DrawString(lblHeading.Text, lblHeading.Font, new SolidBrush(lblHeading.ForeColor), lblHeading.Location.X + 50, lblHeading.Location.Y + TopMargin, new StringFormat());
}
private void btnPrint_Click(object sender, System.EventArgs e)
{
try
{
DataTable dt=(DataTable)this.dbgDispEmp.DataSource;
dataGridPrinter = new DataGridPrinter(this.dbgDispEmp, pDocUser,dt);
dataGridPrinter.PageNumber = 1;
dataGridPrinter.RowCount = 0;
if (pdlgUser.ShowDialog() == DialogResult.OK)
{
pDocUser.Print();
}
}
catch(Exception excep)
{
MessageBox.Show("打印机设置不正确或者未安装。" +excep.Message.ToString());
}
}
private void btnPrintPreview_Click(object sender, System.EventArgs e)
{
DataTable dt=(DataTable)this.dbgDispEmp.DataSource;
dataGridPrinter = new DataGridPrinter(this.dbgDispEmp, pDocUser,dt);
dataGridPrinter.PageNumber = 1;
dataGridPrinter.RowCount = 0;
this.ppdlgUser.ShowDialog();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -