frmuserdatrm.cs
来自「小区物业管理:管理小区的费用、小区工作人员的编排和工资管理、小区的运作、对住户资」· CS 代码 · 共 1,011 行 · 第 1/3 页
CS
1,011 行
{
if(this.printworker .ShowDialog ()==DialogResult.OK )
{
this.pdocworker .Print ();
}
}
private void pdocworker_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Font objFont=new Font ("Tahoma",11,FontStyle.Regular );
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+240,nTop+60);
e.Graphics.DrawString ("家庭地址",objFont,objBrush ,nLeft+320,nTop+60);
e.Graphics.DrawString ("工作单位",objFont,objBrush ,nLeft+420,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 userdatrm",objSqlConnection);
objSqlDataReader=objSqlCommand.ExecuteReader ();
int nLine=1;
while(objSqlDataReader.Read ())
{
e.Graphics .DrawString (objSqlDataReader["Snumber"].ToString (),objFont,objBrush,nLeft+20,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Susername"].ToString (),objFont,objBrush,nLeft+100,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Usex"].ToString (),objFont,objBrush,nLeft+200,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["UIDcard"].ToString (),objFont,objBrush,nLeft+240,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Uaddress"].ToString (),objFont,objBrush,nLeft+240,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Uwordunit"].ToString (),objFont,objBrush,nLeft+420,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Utelnumber"].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.txttel .Clear ();
this.txtworkaddress .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 Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Susername='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户房号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Snumber='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户籍贯",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Saddress='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户身份证",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where cardID='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户联系电话",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Stelnumber='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户工作单位",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Swordunit='"+this.txtfind1 .Text +"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].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 Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Susername like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户房号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Snumber like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户籍贯",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Saddress like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户身份证",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where cardID like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户联系电话",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Stelnumber like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住户工作单位",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm where Swordunit like '%"+this.txtfind1 .Text +"&'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
MessageBox.Show("已搜到 "+objDataSet.Tables["userdatrm"].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,"userdatrm");
}
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.txtworkaddress .Text !=String.Empty &&this.txttel .Text !=String.Empty )
{
//如果有数据和字段。验证..
if(ValidateFields())
{
DataRow objDataRow=objDataSet.Tables ["userdatrm"].NewRow ();
objDataRow["住户房号"]=this.txtID .Text ;
objDataRow["住户姓名"]=this.txtname .Text ;
objDataRow["住户性别"]=this.cbocarcor .Text ;
objDataRow["身份证"]=this.txtIDcard .Text ;
objDataRow["家庭地址"]=this.txtaddress .Text ;
objDataRow["工作单位"]=this.txtworkaddress .Text ;
objDataRow["联系电话"]=this.txttel .Text ;
objDataSet.Tables ["userdatrm"].Rows .Add (objDataRow);
objDataSet.HasChanges (DataRowState.Added );
objSqlDataAdapter.Update (objDataSet,"userdatrm");
MessageBox.Show ("成功插入员工资料");
this.txtname.Clear ();
this.txtID .Clear ();
this.txtIDcard .Clear ();
this.txtaddress.Clear ();
this.txttel .Clear ();
this.txtworkaddress .Clear ();
this.txtID .Focus ();
this.dbgworker .Update ();
this.txtID .Focus ();
}
}
//如果所有字段均为空,则检查
else if(objDataSet.HasChanges ())
{
objSqlDataAdapter.Update (objDataSet,"userdatrm");
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 userdatrm where Snumber='"+num +"'";
objSqlDataAdapter.DeleteCommand =new SqlCommand (delCmd,objSqlConnection);
objParam=objSqlDataAdapter.DeleteCommand .Parameters .Add ("@Snumber",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,"userdatrm");
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 Snumber as 住户房号,Susername as 住户姓名,Ssex as 住户性别,SIDcard as 身份证,Saddress as 家庭地址,Swordunit as 工作单位,Stelnumber as 联系电话 from userdatrm",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"userdatrm");
this.dbgworker .SetDataBinding (objDataSet,"userdatrm");
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个字符","身份证");
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?