📄 frmusersearch.cs
字号:
this.pdocUser.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.pdocUser_PrintPage);
//
// pdlgUser
//
this.pdlgUser.Document = this.pdocUser;
//
// frmUserSearch
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(783, 520);
this.ControlBox = false;
this.Controls.Add(this.btnSave);
this.Controls.Add(this.btnHelp);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.dbgUserDetails);
this.Controls.Add(this.cboStatus);
this.Controls.Add(this.cboUserType);
this.Controls.Add(this.txtUserName);
this.Controls.Add(this.lblHeading);
this.Controls.Add(this.btnPrint);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.lblUserType);
this.Controls.Add(this.lblUserName);
this.Controls.Add(this.lblStatus);
this.Controls.Add(this.grpSearch);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Location = new System.Drawing.Point(146, 115);
this.Name = "frmUserSearch";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "frmUserSearch";
this.TopMost = true;
this.Load += new System.EventHandler(this.frmUserSearch_Load);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmUserSearch_Paint);
((System.ComponentModel.ISupportInitialize)(this.dbgUserDetails)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void dbgUserDetails_DoubleClick(object sender, System.EventArgs e)
{
try
{
//如果是第一次进入则DataGrid的Visible 设为false
if(this.index ==0)
{
return;
}
index++;
this.Hide();
dtUser =(DataTable)dbgUserDetails.DataSource;
DataRow drUser = dtUser.Rows[dbgUserDetails.CurrentRowIndex];
this.userid = drUser[1].ToString();
//set flag as 3 for opening the frmUser form in the modify mode
// frmUser user=new frmUser(3,this,this.userid);
frmUser user=new frmUser(3,this,this.dbgUserDetails .CurrentCell .RowNumber ,this.dtBefore );
if ((index==1) && (frmUser.dtUpdate!=null))
{
frmUser.dtUpdate.Clear();
}
user.Show();
}
catch(Exception excep)
{
MessageBox.Show(excep.Message.ToString ());
MessageBox.Show(excep.StackTrace.ToString ());
}
}
private void btnClose_Click(object sender, System.EventArgs e)
{
updateflag=false;
this.Close();
}
private void frmUserSearch_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(updateflag)
{
this.btnSave .Enabled =true;
}
}
private void btnSave_Click(object sender, System.EventArgs e)
{
try
{
DataAccess objDA = DataAccess.GetInstance ();
//to know whether updation was performed or no updation
//was performed in the other form, we check the
//rowUpdated array contents. This array contains a set
//of true and false values where true will indicate
//that row has been modified
bool updated=false;
for (int index = 0;index < rowUpdated.Length;index++)
{
if (rowUpdated[index])
updated=true;
}
if (updated)
{
//create an instance of user class and
//invoke its UpdateRecords method,
//pass to it the data table containing the
//set of modified records
User objUser = new User();
objUser.UpdateRecords(frmUser.dtUpdate);
//after updation, refresh the datagrid by retrieving records again
doSearch();
MessageBox.Show ("已成功更新用户详细信息");
}
else
{
MessageBox.Show ("未检测到对用户详细信息所作的修改");
}
this.btnClose.Enabled =true;
this.btnSave .Enabled =false;
}
catch(Exception excep)
{
MessageBox.Show ("出现异常"+excep.StackTrace.ToString ());
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
doSearch();
//查询一次加1,启动DataGrid的双击事件
this.index ++;
//store the fetched records into another table
dtBefore = (DataTable)this.dbgUserDetails.DataSource;
}
private void cboStatus_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (this.cboStatus.Text.Equals ("Active"))
this.status=true;
else
this.status=false;
}
private void frmUserSearch_Load(object sender, System.EventArgs e)
{
this.btnSave .Enabled =false;
this.cboStatus.Text ="Active";
this.status = true;
if (updateflag) //check if update was performed in the frmUser form and data was modified there
{
//if yes,
//then enable Save button in this form
this.btnSave.Enabled =true;
//绑定已经frmUser窗体中修改过的表dtUpdate
this.dbgUserDetails.DataSource=frmUser.dtUpdate;//dtBefore;
}
this.Focus ();
}
private void doSearch()
{
try
{
if(this.txtUserName.Text != "") //if username is not null
{
searchValue[0] = this.txtUserName.Text;
}
else
{
searchValue[0] = "";
}
if(this.cboUserType.Text != "") //if usertype is not null
{
searchValue[1] = this.cboUserType.Text;
}
else if(this.cboUserType.Text == "") //if usertype is null
{
searchValue[1] = "";
}
if(this.cboStatus.Text != "") //if status is not null
{
searchValue[2] = this.status.ToString();
}
else
{
searchValue[2] = "" ;
}
//create an instance of user class and invoke the
//method to fetch the records based on given criteria
DataAccess objDA=DataAccess.GetInstance ();
User objUser = new User();
searchValue[3]="";
DataTable dtUser = objUser.FetchRecords(searchValue);
//populate the datagrid with the fetched data
this.dbgUserDetails.DataSource = dtUser;
//based on the number of rows in the datagrid, create
// an array of boolean values
if (rowUpdated==null)
rowUpdated = new bool[dtUser.Rows.Count];
}
catch(Exception myException)
{
Console.WriteLine(myException.Message);
}
}
private void btnPrint_Click(object sender, System.EventArgs e)
{
try
{
if (pdlgUser.ShowDialog() == DialogResult.OK)
{
pdocUser.Print();
}
}
catch(Exception excep)
{
MessageBox.Show("打印时出错。" +excep.Message.ToString());
}
}
private void pdocUser_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
try
{
DataTable dt=(DataTable)this.dbgUserDetails.DataSource;
Datagridprinter objDGP = new Datagridprinter(this.dbgUserDetails, pdocUser,dt);
objDGP.PageNumber = 1;
objDGP.RowCount = 0;
Graphics g = e.Graphics;
bool more = objDGP.DrawDataGrid(g);
if (more == true)
{
e.HasMorePages = true;
objDGP.PageNumber++;
}
}
catch(Exception excep)
{
MessageBox.Show("打印时出错。" +excep.Message.ToString());
}
}
private void btnHelp_Click(object sender, System.EventArgs e)
{
Help.ShowHelp(this,Environment.CurrentDirectory +@"\\OES_Help\OES_Help.chm");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -