frmstorey.cs
来自「小区物业管理:管理小区的费用、小区工作人员的编排和工资管理、小区的运作、对住户资」· CS 代码 · 共 932 行 · 第 1/3 页
CS
932 行
this.dbgworker .Enabled =false;
}
private void btnPrint_Click(object sender, System.EventArgs e)
{
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+340,nTop+60);
e.Graphics.DrawString ("住房电话",objFont,objBrush ,nLeft+420,nTop+60);
try
{
objSqlConnection=new SqlConnection ("database=atorregulate;uid=sa;pwd=;SERVER=(local)");
objSqlConnection.Open ();
objSqlCommand=new SqlCommand ("Select * from storey",objSqlConnection);
objSqlDataReader=objSqlCommand.ExecuteReader ();
int nLine=1;
while(objSqlDataReader.Read ())
{
e.Graphics .DrawString (objSqlDataReader["Nstorey"].ToString (),objFont,objBrush,nLeft+20,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Nitem"].ToString (),objFont,objBrush,nLeft+100,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Nusername"].ToString (),objFont,objBrush,nLeft+200,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Nhabitus"].ToString (),objFont,objBrush,nLeft+340,nTop+60+nLine*30);
e.Graphics .DrawString (objSqlDataReader["Ntelnumber"].ToString (),objFont,objBrush,nLeft+420,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.txttel .Clear ();
this.txtnum .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 Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nstorey='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房栋号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nitem='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房业主",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nusername='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房状态",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nhabitus='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房电话",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Ntelnumber='"+find+"'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].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 Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nstorey like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房栋号",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nitem like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房业主",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nusername like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房状态",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Nhabitus like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
}
else if(string.Compare (cbofind2.Text ,"住房电话",true)==0)
{
objSqlDataAdapter=new SqlDataAdapter ();
objSqlDataAdapter.SelectCommand =new SqlCommand ("select Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey where Ntelnumber like '%"+this.txtfind1 .Text +"%'",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
MessageBox.Show("已搜到 "+objDataSet.Tables["storey"].Rows.Count+" 条记录","注意");
this.dbgworker .Enabled =false;
this.txtfind1 .Clear ();
}
}
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message );
}
catch(Exception ex)
{
MessageBox.Show (ex.Message );
}
this.dbgworker .SetDataBinding (objDataSet,"storey");
}
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.txtnum .Text !=String.Empty &&this.txttel .Text !=String.Empty )
{
//如果有数据和字段。验证..
if(ValidateFields())
{
DataRow objDataRow=objDataSet.Tables ["storey"].NewRow ();
objDataRow["住房房号"]=this.txtID .Text ;
objDataRow["住房栋号"]=this.txtnum .Text ;
objDataRow["住房业主"]=this.cbocarcor .Text ;
objDataRow["住房状态"]=this.txtname .Text ;
objDataRow["住房电话"]=this.txttel .Text ;
objDataSet.Tables ["storey"].Rows .Add (objDataRow);
objDataSet.HasChanges (DataRowState.Added );
objSqlDataAdapter.Update (objDataSet,"storey");
MessageBox.Show ("成功插入员工资料");
this.txtname.Clear ();
this.txtID .Clear ();
this.txttel .Clear ();
this.txtnum .Clear ();
this.txtID .Focus ();
this.dbgworker .Update ();
this.txtID .Focus ();
}
}
//如果所有字段均为空,则检查
else if(objDataSet.HasChanges ())
{
objSqlDataAdapter.Update (objDataSet,"storey");
MessageBox.Show ("已成功插入记录");
}
//未输入数据按下按钮则显示
else
MessageBox.Show ("提供完整的详细信息");
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message .ToString ());
}
catch(Exception genEx)
{
MessageBox.Show (genEx.Message .ToString ());
}
}
private void btnDru_Click(object sender, System.EventArgs e)
{
this.txtDID .Clear ();
this.txtDID .Focus ();
}
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 storey where Nstorey='"+num +"'";
objSqlDataAdapter.DeleteCommand =new SqlCommand (delCmd,objSqlConnection);
objParam=objSqlDataAdapter.DeleteCommand .Parameters .Add ("@Nstorey",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,"storey");
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 Nstorey as 住房房号,Nitem as 住房栋号,Nusername as 住房业主,Nhabitus as 住房状态,Ntelnumber as 住房电话 from storey",objSqlConnection);
objDataSet=new DataSet ();
objSqlDataAdapter.Fill (objDataSet,"storey");
this.dbgworker .SetDataBinding (objDataSet,"storey");
this.dbgworker .Enabled =false;
}
catch(SqlException ex)
{
MessageBox.Show (ex.Message );
}
}
else
return;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?