frmworker.cs
来自「小区物业管理:管理小区的费用、小区工作人员的编排和工资管理、小区的运作、对住户资」· CS 代码 · 共 1,005 行 · 第 1/3 页
CS
1,005 行
Brush objBrush=Brushes.Black ;
Pen objPen=new Pen (objBrush);
objPen.Width =2;
int nLeft=this.pageSetupDialog1 .PageSettings .Margins .Left ;
int nTop=this.pageSetupDialog1 .PageSettings .Margins .Top ;
int nWidth=this.pageSetupDialog1 .PageSettings .PaperSize .Width -(this.pageSetupDialog1 .PageSettings .Margins .Left +this.pageSetupDialog1 .PageSettings .Margins .Right );
int nHeight=this.pageSetupDialog1 .PageSettings .PaperSize .Height -(this.pageSetupDialog1 .PageSettings .Margins .Bottom );
e.Graphics .DrawLine (objPen,nLeft,nTop,nLeft+nWidth,nTop);
e.Graphics .DrawLine (objPen,nLeft,nTop+nHeight,nLeft+nWidth,nTop+nHeight);
e.Graphics .DrawLine (objPen,nLeft,nTop,nLeft,nTop+nHeight);
e.Graphics .DrawLine (objPen,nLeft+nWidth,nTop,nLeft+nWidth,nTop+nHeight);
e.Graphics.DrawString ("员工资料",new Font ("Garamond",40,FontStyle.Bold ),Brushes.Blue ,nLeft+30,nTop+10);
e.Graphics.DrawString ("员工编号",objFont,objBrush ,nLeft+20,nTop+60);
e.Graphics.DrawString ("员工姓名",objFont,objBrush ,nLeft+100,nTop+60);
e.Graphics.DrawString ("员工职位",objFont,objBrush ,nLeft+200,nTop+60);
e.Graphics.DrawString ("工作时段",objFont,objBrush ,nLeft+270,nTop+60);
e.Graphics.DrawString ("身份证号码",objFont,objBrush ,nLeft+360,nTop+60);
e.Graphics.DrawString ("家庭地址",objFont,objBrush ,nLeft+520,nTop+60);
try
{
objSqlConnection=new SqlConnection ("Server=(local);database=atorregulate;user id=sa;password=;");
objSqlConnection.Open ();
objSqlCommand=new SqlCommand ("Select * from worker",objSqlConnection);
objSqlDataReader=objSqlCommand.ExecuteReader ();
int nLine=1;
while(objSqlDataReader.Read ())
{
e.Graphics .DrawString (objSqlDataReader["Wnumber"].ToString (),objFont,objBrush,nLeft+20,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Wname"].ToString (),objFont,objBrush,nLeft+100,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Wcarcor"].ToString (),objFont,objBrush,nLeft+200,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Wtime"].ToString (),objFont,objBrush,nLeft+270,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["WIDcard"].ToString (),objFont,objBrush,nLeft+360,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Waddress"].ToString (),objFont,objBrush,nLeft+520,nTop+60+nLine*30);
nLine++;
}
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message );
}
}
private void btnPrintprv_Click(object sender, System.EventArgs e)
{
this.ppdlgworker .ShowDialog ();
}
private void btnRe_Click(object sender, System.EventArgs e)
{
this.txtname.Clear ();
this.txtID .Clear ();
this.txtIDcard .Clear ();
this.txtaddress.Clear ();
this.txtID .Focus ();
}
private void btn_Click(object sender, System.EventArgs e)
{
this.tabControl1 .Visible =false;
this.dbgworker .Visible =true;
this.btnAdd .Enabled =true;
this.btnPrint .Enabled =true;
this.btnPrintprv .Enabled =true;
}
private void btnEbter_Click(object sender, System.EventArgs e)
{
try
{
string find=this.txtfind1 .Text ;
if(string.Compare (cbofind1.Text ,"精确搜索",true)==0)
{
if(string.Compare (cbofind2.Text ,"员工姓名",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wname='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工编号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wnumber='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"工作时段",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wtime='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工职位",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wcarcor='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工籍贯",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Waddress='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工身份证",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where WIDcard='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
}
else if(string.Compare (cbofind1.Text ,"模糊搜索",true)==0)
{
if(string.Compare (cbofind2.Text ,"员工姓名",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wname like '%"+this.txtfind1 .Text+"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工编号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wnumber like '%"+this.txtfind1 .Text+"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工职位",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wcarcor like '%"+this.txtfind1 .Text+"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"工作时段",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Wtime like '%"+this.txtfind1.Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工籍贯",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where Waddress like '%"+this.txtfind1 .Text+"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"员工身份证",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker where WIDcard like '%"+this.txtfind1 .Text+"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
MessageBox.Show("已搜到 "+objDataSet.Tables["worker"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
}
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message );
}
catch(Exception ex)
{
MessageBox.Show (ex.Message );
}
finally
{
objSqlConnection.Close ();
}
//objSqlConnection.Close ();
this.dbgworker .SetDataBinding (objDataSet,"worker");
}
private void btnaddwo_Click(object sender, System.EventArgs e)
{
try
{
if(this.txtID .Text !=String.Empty &&this.txtname .Text !=String.Empty &&this.cbocarcor .Text !=String.Empty &&this.txtIDcard .Text !=String.Empty &&this.txtaddress .Text !=String.Empty &&this.cbotime .Text !=String.Empty )
{
//如果有数据和字段。验证..
if(ValidateFields())
{
DataRow objDataRow=objDataSet.Tables ["worker"].NewRow ();
objDataRow["员工编号"]=this.txtID .Text ;
objDataRow["员工姓名"]=this.txtname .Text ;
objDataRow["员工职位"]=this.cbocarcor .Text ;
objDataRow["工作时段"]=this.cbotime .Text ;
objDataRow["身份证号码"]=this.txtIDcard .Text ;
objDataRow["家庭地址"]=this.txtaddress .Text ;
objDataSet.Tables ["worker"].Rows .Add (objDataRow);
objDataSet.HasChanges (DataRowState.Added );
objSqlDataAdapter.Update (objDataSet,"worker");
MessageBox.Show ("成功插入员工资料");
this.txtname.Clear ();
this.txtID .Clear ();
this.txtIDcard .Clear ();
this.txtaddress.Clear ();
this.dbgworker .Update ();
this.txtID .Focus ();
}
}
//如果所有字段均为空,则检查
else if(objDataSet.HasChanges ())
{
objSqlDataAdapter.Update (objDataSet,"worker");
MessageBox.Show ("已成功插入记录");
}
//未输入数据按下按钮则显示
else
MessageBox.Show ("提供完整的详细信息");
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message .ToString ());
}
catch(Exception genEx)
{
MessageBox.Show (genEx.Message .ToString ());
}
}
private void btnDEit_Click(object sender, System.EventArgs e)
{
this.tabControl1 .Visible =false;
this.dbgworker .Visible =true;
this.btnAdd .Enabled =true;
this.btnPrint .Enabled =true;
this.btnPrintprv .Enabled =true;
}
private void btnDel1_Click(object sender, System.EventArgs e)
{
string num=this.txtDID .Text ;
string delCmd="Delete from worker where Wnumber='"+num +"'";
objSqlDataAdapter.DeleteCommand =new SqlCommand (delCmd,objSqlConnection);
objParam=objSqlDataAdapter.DeleteCommand .Parameters .Add ("@Wnumber",SqlDbType.Int );
objParam.SourceColumn ="员工编号";
objParam.SourceVersion =DataRowVersion.Original ;
objDialogResult=MessageBox.Show ("确定要删除当前忆录吗?","确定",MessageBoxButtons.YesNo ,MessageBoxIcon.Question );
if(objDialogResult==DialogResult.Yes )
{
try
{
objDataSet.Tables [0].Rows [dbgworker.CurrentRowIndex ].Delete ();
objSqlDataAdapter.Update (objDataSet,"worker");
MessageBox.Show ("已经删除记录");
this.dbgworker .Enabled =true;
objSqlConnection=new SqlConnection ("database=atorregulate;uid=sa;pwd=;SERVER=(local)");
objSqlConnection.Open ();
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
this.dbgworker .SetDataBinding (objDataSet,"worker");
this.dbgworker .Enabled =false;
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message );
}
}
else
return;
}
private void txtIDcard_Leave(object sender, System.EventArgs e)
{
int count=this.txtIDcard .Text .Length ;
if(count<18)
{
MessageBox.Show ("身份证的长度应该为18个字符","身份证");
}
}
private void btnUp_Click(object sender, System.EventArgs e)
{
this.dbgworker .Enabled =true;
objSqlConnection=new SqlConnection ("database=atorregulate;uid=sa;pwd=;SERVER=(local)");
objSqlConnection.Open ();
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Wnumber as 员工编号,Wname as 员工姓名,Wcarcor as 员工职位,Wtime as 工作时段,WIDcard as 身份证号码,Waddress as 家庭地址 from worker",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"worker");
this.dbgworker .SetDataBinding (objDataSet,"worker");
this.dbgworker .Enabled =false;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?