📄 modizh.cs
字号:
this.label3.Text = "户 型:";
this.label3.Click += new System.EventHandler(this.label3_Click);
//
// label2
//
this.label2.BackColor = System.Drawing.Color.Transparent;
this.label2.Location = new System.Drawing.Point(32, 86);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(56, 16);
this.label2.TabIndex = 13;
this.label2.Text = "户 主:";
this.label2.Click += new System.EventHandler(this.label2_Click);
//
// label1
//
this.label1.BackColor = System.Drawing.Color.Transparent;
this.label1.Location = new System.Drawing.Point(32, 38);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 18);
this.label1.TabIndex = 12;
this.label1.Text = "门牌号:";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(88, 136);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(128, 21);
this.textBox7.TabIndex = 20;
this.textBox7.Text = "textBox3";
this.textBox7.TextChanged += new System.EventHandler(this.textBox7_TextChanged);
//
// modizh
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(528, 312);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.button11);
this.Controls.Add(this.button12);
this.Controls.Add(this.button13);
this.Controls.Add(this.button14);
this.Controls.Add(this.button15);
this.Controls.Add(this.button16);
this.Controls.Add(this.button17);
this.Controls.Add(this.button18);
this.Controls.Add(this.button19);
this.Name = "modizh";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "modizh";
this.Load += new System.EventHandler(this.modizh_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void modizh_Load(object sender, System.EventArgs e)
{
string connstr,selectcmd;
connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
selectcmd="select * from zhb";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
OleDbDataAdapter da=new OleDbDataAdapter(selectcmd,conn);
//OleDbDataAdapter oleDbDataAdapter1=new OleDbDataAdapter(selectcmd,conn);
DataSet ds=new DataSet();
//DataSet dataSet1=new DataSet();
da.Fill(ds);
DataTable mytable=new DataTable();
mytable=ds.Tables[0];
MyBind=this.groupBox1.BindingContext[mytable];
//oleDbDataAdapter1.Fill(dataSet1);
//this.dataGrid1.DataSource=mytable;
//conn.Close();
try
{
//this.oleDbDataAdapter1.Fill(this.dataSet1,"user1");
this.textBox1.DataBindings.Add("Text",mytable,"Mph");
this.textBox2.DataBindings.Add("Text",mytable,"Hz");
this.textBox3.DataBindings.Add("Text",mytable,"Hx");
this.textBox4.DataBindings.Add("Text",mytable,"Czr");
this.textBox5.DataBindings.Add("Text",mytable,"Dh");
this.textBox6.DataBindings.Add("Text",mytable,"Bz");
}
catch(Exception Err)
{
MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
private void button18_Click(object sender, System.EventArgs e)
{
this.MyBind.Position=0;
}
private void button17_Click(object sender, System.EventArgs e)
{
this.MyBind.Position--;
}
private void button16_Click(object sender, System.EventArgs e)
{
this.MyBind.Position++;
}
private void button15_Click(object sender, System.EventArgs e)
{
try
{
this.MyBind.Position=this.MyBind.Count-1;
}
catch(Exception Err)
{
MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
}
private void button13_Click(object sender, System.EventArgs e)
{
//增加记录
if(this.textBox2.Text.Length<1|this.textBox3.Text.Length<1)
{
MessageBox.Show("客户所有信息必须填写!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
return;
}
try
{
string connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
string StrSQL="INSERT INTO zhb (Mph,Hz,Hx,Czr,Dh,Bz)VALUES('"+this.textBox1.Text.Trim()+"','"+this.textBox2.Text.Trim()+"','"+this.textBox3.Text.Trim()+"','"+this.textBox4.Text.Trim()+"','"+this.textBox5.Text.Trim()+"','"+this.textBox6.Text.Trim()+"')";
OleDbCommand cmd=new OleDbCommand(StrSQL,conn);
cmd.ExecuteNonQuery();
MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("增加数据集记录操作失败:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button19_Click(object sender, System.EventArgs e)
{
try
{
string connstr="Provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+"\\xqwy.mdb";
OleDbConnection conn=new OleDbConnection(connstr);
conn.Open();
string StrSQL="DELETE FROM zhb WHERE ";
StrSQL+=" Mph='"+this.textBox1.Text+"'";
OleDbCommand cmd=new OleDbCommand(StrSQL,conn);
cmd.ExecuteNonQuery();
MessageBox.Show("删除数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
catch(Exception Err)
{
MessageBox.Show("删除数据集记录操作失败:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void button14_Click(object sender, System.EventArgs e)
{
this.textBox1.Text="";
this.textBox2.Text="";
this.textBox3.Text="";
this.textBox4.Text="";
this.textBox5.Text="";
this.textBox6.Text="";
}
private void button12_Click(object sender, System.EventArgs e)
{
//修改记录
try
{
OleDbConnection conn2=new OleDbConnection(@"provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+ "\\xqwy.mdb");
conn2.Open();
string strsql="select * from zhb where Mph='"+this.textBox1.Text.Trim()+"' ";
OleDbDataAdapter da=new OleDbDataAdapter(strsql,conn2);
DataSet ds=new DataSet();
da.Fill(ds);
DataTable mytable=new DataTable();
mytable=ds.Tables[0];
DataRow row1;
row1=mytable.Rows[0];
row1[0]=this.textBox1.Text.Trim();
row1[1]=this.textBox2.Text.Trim();
row1[2]=this.textBox3.Text.Trim();
row1[3]=this.textBox4.Text.Trim();
row1[4]=this.textBox5.Text.Trim();
row1[5]=this.textBox6.Text.Trim();
OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
da.Update(mytable);
MessageBox.Show("记录修改成功!");
conn2.Close();
}
catch(Exception err)
{
MessageBox.Show(err.Message);
}
}
private void button11_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void label8_Click(object sender, System.EventArgs e)
{
}
private void label7_Click(object sender, System.EventArgs e)
{
}
private void textBox7_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox4_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void label5_Click(object sender, System.EventArgs e)
{
}
private void label4_Click(object sender, System.EventArgs e)
{
}
private void label2_Click(object sender, System.EventArgs e)
{
}
private void label1_Click(object sender, System.EventArgs e)
{
}
private void groupBox1_Enter(object sender, System.EventArgs e)
{
}
private void textBox6_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox5_TextChanged(object sender, System.EventArgs e)
{
}
private void label3_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -