modizh.cs
资源名称:xqwy.rar [点击查看]
上传用户:fuyouda
上传日期:2021-03-17
资源大小:8619k
文件大小:20k
源码类别:
Windows编程
开发平台:
C/C++
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.OleDb;
- namespace WindowsApplication1
- {
- /// <summary>
- /// modizh 的摘要说明。
- /// </summary>
- public class modizh : System.Windows.Forms.Form
- {
- private System.Windows.Forms.Button button11;
- private System.Windows.Forms.Button button12;
- private System.Windows.Forms.Button button13;
- private System.Windows.Forms.Button button14;
- private System.Windows.Forms.Button button15;
- private System.Windows.Forms.Button button16;
- private System.Windows.Forms.Button button17;
- private System.Windows.Forms.Button button18;
- private System.Windows.Forms.Button button19;
- private BindingManagerBase MyBind;
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.TextBox textBox6;
- private System.Windows.Forms.TextBox textBox5;
- private System.Windows.Forms.TextBox textBox4;
- private System.Windows.Forms.TextBox textBox3;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.Label label6;
- private System.Windows.Forms.Label label5;
- private System.Windows.Forms.Label label4;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.TextBox textBox7;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public modizh()
- {
- //
- // Windows 窗体设计器支持所必需的
- //
- InitializeComponent();
- //
- // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
- //
- }
- /// <summary>
- /// 清理所有正在使用的资源。
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #region Windows 窗体设计器生成的代码
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(modizh));
- this.button11 = new System.Windows.Forms.Button();
- this.button12 = new System.Windows.Forms.Button();
- this.button13 = new System.Windows.Forms.Button();
- this.button14 = new System.Windows.Forms.Button();
- this.button15 = new System.Windows.Forms.Button();
- this.button16 = new System.Windows.Forms.Button();
- this.button17 = new System.Windows.Forms.Button();
- this.button18 = new System.Windows.Forms.Button();
- this.button19 = new System.Windows.Forms.Button();
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.textBox6 = new System.Windows.Forms.TextBox();
- this.textBox5 = new System.Windows.Forms.TextBox();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.textBox3 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.label6 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.textBox7 = new System.Windows.Forms.TextBox();
- this.groupBox1.SuspendLayout();
- this.SuspendLayout();
- //
- // button11
- //
- this.button11.BackColor = System.Drawing.Color.Transparent;
- this.button11.Location = new System.Drawing.Point(416, 224);
- this.button11.Name = "button11";
- this.button11.Size = new System.Drawing.Size(75, 30);
- this.button11.TabIndex = 30;
- this.button11.Text = "关闭程序";
- this.button11.Click += new System.EventHandler(this.button11_Click);
- //
- // button12
- //
- this.button12.BackColor = System.Drawing.Color.Transparent;
- this.button12.Location = new System.Drawing.Point(232, 264);
- this.button12.Name = "button12";
- this.button12.Size = new System.Drawing.Size(75, 30);
- this.button12.TabIndex = 29;
- this.button12.Text = "修改记录";
- this.button12.Click += new System.EventHandler(this.button12_Click);
- //
- // button13
- //
- this.button13.BackColor = System.Drawing.Color.Transparent;
- this.button13.Location = new System.Drawing.Point(128, 264);
- this.button13.Name = "button13";
- this.button13.Size = new System.Drawing.Size(75, 30);
- this.button13.TabIndex = 28;
- this.button13.Text = "增加记录";
- this.button13.Click += new System.EventHandler(this.button13_Click);
- //
- // button14
- //
- this.button14.BackColor = System.Drawing.Color.Transparent;
- this.button14.Location = new System.Drawing.Point(32, 264);
- this.button14.Name = "button14";
- this.button14.Size = new System.Drawing.Size(75, 30);
- this.button14.TabIndex = 27;
- this.button14.Text = "新建记录";
- this.button14.Click += new System.EventHandler(this.button14_Click);
- //
- // button15
- //
- this.button15.BackColor = System.Drawing.Color.Transparent;
- this.button15.Location = new System.Drawing.Point(328, 224);
- this.button15.Name = "button15";
- this.button15.Size = new System.Drawing.Size(75, 30);
- this.button15.TabIndex = 26;
- this.button15.Text = "末一条记录";
- this.button15.Click += new System.EventHandler(this.button15_Click);
- //
- // button16
- //
- this.button16.BackColor = System.Drawing.Color.Transparent;
- this.button16.Location = new System.Drawing.Point(224, 224);
- this.button16.Name = "button16";
- this.button16.Size = new System.Drawing.Size(75, 30);
- this.button16.TabIndex = 25;
- this.button16.Text = "后一条记录";
- this.button16.Click += new System.EventHandler(this.button16_Click);
- //
- // button17
- //
- this.button17.BackColor = System.Drawing.Color.Transparent;
- this.button17.Location = new System.Drawing.Point(128, 224);
- this.button17.Name = "button17";
- this.button17.Size = new System.Drawing.Size(75, 30);
- this.button17.TabIndex = 23;
- this.button17.Text = "前一条记录";
- this.button17.Click += new System.EventHandler(this.button17_Click);
- //
- // button18
- //
- this.button18.BackColor = System.Drawing.Color.Transparent;
- this.button18.Location = new System.Drawing.Point(32, 224);
- this.button18.Name = "button18";
- this.button18.Size = new System.Drawing.Size(75, 30);
- this.button18.TabIndex = 22;
- this.button18.Text = "第一条记录";
- this.button18.Click += new System.EventHandler(this.button18_Click);
- //
- // button19
- //
- this.button19.BackColor = System.Drawing.Color.Transparent;
- this.button19.Location = new System.Drawing.Point(328, 264);
- this.button19.Name = "button19";
- this.button19.Size = new System.Drawing.Size(75, 30);
- this.button19.TabIndex = 24;
- this.button19.Text = "删除记录";
- this.button19.Click += new System.EventHandler(this.button19_Click);
- //
- // groupBox1
- //
- this.groupBox1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("groupBox1.BackgroundImage")));
- this.groupBox1.Controls.Add(this.textBox6);
- this.groupBox1.Controls.Add(this.textBox5);
- this.groupBox1.Controls.Add(this.textBox4);
- this.groupBox1.Controls.Add(this.textBox3);
- this.groupBox1.Controls.Add(this.textBox2);
- this.groupBox1.Controls.Add(this.textBox1);
- this.groupBox1.Controls.Add(this.label6);
- this.groupBox1.Controls.Add(this.label5);
- this.groupBox1.Controls.Add(this.label4);
- this.groupBox1.Controls.Add(this.label3);
- this.groupBox1.Controls.Add(this.label2);
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Controls.Add(this.textBox7);
- this.groupBox1.Location = new System.Drawing.Point(24, 32);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(456, 176);
- this.groupBox1.TabIndex = 31;
- this.groupBox1.TabStop = false;
- this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(320, 136);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(128, 21);
- this.textBox6.TabIndex = 23;
- this.textBox6.Text = "";
- this.textBox6.TextChanged += new System.EventHandler(this.textBox6_TextChanged);
- //
- // textBox5
- //
- this.textBox5.Location = new System.Drawing.Point(320, 80);
- this.textBox5.Name = "textBox5";
- this.textBox5.Size = new System.Drawing.Size(128, 21);
- this.textBox5.TabIndex = 22;
- this.textBox5.Text = "";
- this.textBox5.TextChanged += new System.EventHandler(this.textBox5_TextChanged);
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(320, 32);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(128, 21);
- this.textBox4.TabIndex = 21;
- this.textBox4.Text = "";
- this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(88, 136);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(128, 21);
- this.textBox3.TabIndex = 20;
- this.textBox3.Text = "";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(88, 80);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(128, 21);
- this.textBox2.TabIndex = 19;
- this.textBox2.Text = "";
- this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(88, 32);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(128, 21);
- this.textBox1.TabIndex = 18;
- this.textBox1.Text = "";
- this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
- //
- // label6
- //
- this.label6.BackColor = System.Drawing.Color.Transparent;
- this.label6.Location = new System.Drawing.Point(256, 144);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(56, 16);
- this.label6.TabIndex = 17;
- this.label6.Text = "备 注:";
- //
- // label5
- //
- this.label5.BackColor = System.Drawing.Color.Transparent;
- this.label5.Location = new System.Drawing.Point(264, 85);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(56, 16);
- this.label5.TabIndex = 16;
- this.label5.Text = "电 话:";
- this.label5.Click += new System.EventHandler(this.label5_Click);
- //
- // label4
- //
- this.label4.BackColor = System.Drawing.Color.Transparent;
- this.label4.Location = new System.Drawing.Point(256, 37);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(72, 16);
- this.label4.TabIndex = 15;
- this.label4.Text = "常住人口:";
- this.label4.Click += new System.EventHandler(this.label4_Click);
- //
- // label3
- //
- this.label3.BackColor = System.Drawing.Color.Transparent;
- this.label3.Location = new System.Drawing.Point(32, 141);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(56, 16);
- this.label3.TabIndex = 14;
- 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)
- {
- }
- }
- }