userg1.cs
资源名称:xqwy.rar [点击查看]
上传用户:fuyouda
上传日期:2021-03-17
资源大小:8619k
文件大小:21k
源码类别:
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>
- /// userg1 的摘要说明。
- /// </summary>
- public class userg1 : System.Windows.Forms.Form
- {
- private System.Windows.Forms.TabControl tabControl1;
- private System.Windows.Forms.TabPage tabPage1;
- private System.Windows.Forms.TabPage tabPage2;
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.TextBox textBox3;
- private System.Windows.Forms.DataGrid dataGrid1;
- 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 System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.Button button6;
- private System.Windows.Forms.Button button7;
- private System.Windows.Forms.Button button8;
- //private System.Data.OleDb.OleDbDataAdapter oleDbDataAdapter1;
- //private System.Data.DataSet dataSet1;
- private BindingManagerBase MyBind;
- private System.Windows.Forms.Label label1;
- /// <summary>
- /// 必需的设计器变量。
- /// </summary>
- private System.ComponentModel.Container components = null;
- public userg1()
- {
- //
- // 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(userg1));
- this.tabControl1 = new System.Windows.Forms.TabControl();
- this.tabPage1 = new System.Windows.Forms.TabPage();
- this.dataGrid1 = new System.Windows.Forms.DataGrid();
- this.panel1 = new System.Windows.Forms.Panel();
- this.button1 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.button6 = new System.Windows.Forms.Button();
- this.button7 = new System.Windows.Forms.Button();
- this.button8 = new System.Windows.Forms.Button();
- this.tabPage2 = new System.Windows.Forms.TabPage();
- 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.textBox3 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.tabControl1.SuspendLayout();
- this.tabPage1.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
- this.panel1.SuspendLayout();
- this.tabPage2.SuspendLayout();
- this.SuspendLayout();
- //
- // tabControl1
- //
- this.tabControl1.Controls.Add(this.tabPage1);
- this.tabControl1.Controls.Add(this.tabPage2);
- this.tabControl1.Location = new System.Drawing.Point(0, 0);
- this.tabControl1.Name = "tabControl1";
- this.tabControl1.SelectedIndex = 0;
- this.tabControl1.Size = new System.Drawing.Size(520, 376);
- this.tabControl1.TabIndex = 0;
- this.tabControl1.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged);
- //
- // tabPage1
- //
- this.tabPage1.Controls.Add(this.dataGrid1);
- this.tabPage1.Controls.Add(this.panel1);
- this.tabPage1.Location = new System.Drawing.Point(4, 21);
- this.tabPage1.Name = "tabPage1";
- this.tabPage1.Size = new System.Drawing.Size(512, 351);
- this.tabPage1.TabIndex = 0;
- this.tabPage1.Text = "多行显示";
- //
- // dataGrid1
- //
- this.dataGrid1.DataMember = "";
- this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.dataGrid1.Location = new System.Drawing.Point(8, 0);
- this.dataGrid1.Name = "dataGrid1";
- this.dataGrid1.Size = new System.Drawing.Size(464, 208);
- this.dataGrid1.TabIndex = 1;
- //
- // panel1
- //
- this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
- this.panel1.Controls.Add(this.button1);
- this.panel1.Controls.Add(this.button5);
- this.panel1.Controls.Add(this.button6);
- this.panel1.Controls.Add(this.button7);
- this.panel1.Controls.Add(this.button8);
- this.panel1.Location = new System.Drawing.Point(0, 208);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(472, 72);
- this.panel1.TabIndex = 0;
- this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
- //
- // button1
- //
- this.button1.BackColor = System.Drawing.Color.Transparent;
- this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
- this.button1.Location = new System.Drawing.Point(360, 8);
- this.button1.Name = "button1";
- this.button1.TabIndex = 30;
- this.button1.Text = "关闭程序";
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button5
- //
- this.button5.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button5.BackgroundImage")));
- this.button5.Location = new System.Drawing.Point(280, 8);
- this.button5.Name = "button5";
- this.button5.TabIndex = 26;
- this.button5.Text = "末一条记录";
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button6
- //
- this.button6.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button6.BackgroundImage")));
- this.button6.Location = new System.Drawing.Point(192, 8);
- this.button6.Name = "button6";
- this.button6.TabIndex = 25;
- this.button6.Text = "后一条记录";
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // button7
- //
- this.button7.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button7.BackgroundImage")));
- this.button7.Location = new System.Drawing.Point(104, 8);
- this.button7.Name = "button7";
- this.button7.TabIndex = 23;
- this.button7.Text = "前一条记录";
- this.button7.Click += new System.EventHandler(this.button7_Click);
- //
- // button8
- //
- this.button8.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button8.BackgroundImage")));
- this.button8.Location = new System.Drawing.Point(16, 8);
- this.button8.Name = "button8";
- this.button8.TabIndex = 22;
- this.button8.Text = "第一条记录";
- this.button8.Click += new System.EventHandler(this.button8_Click);
- //
- // tabPage2
- //
- this.tabPage2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("tabPage2.BackgroundImage")));
- this.tabPage2.Controls.Add(this.button11);
- this.tabPage2.Controls.Add(this.button12);
- this.tabPage2.Controls.Add(this.button13);
- this.tabPage2.Controls.Add(this.button14);
- this.tabPage2.Controls.Add(this.button15);
- this.tabPage2.Controls.Add(this.button16);
- this.tabPage2.Controls.Add(this.button17);
- this.tabPage2.Controls.Add(this.button18);
- this.tabPage2.Controls.Add(this.button19);
- this.tabPage2.Controls.Add(this.textBox3);
- this.tabPage2.Controls.Add(this.textBox2);
- this.tabPage2.Controls.Add(this.label3);
- this.tabPage2.Controls.Add(this.label2);
- this.tabPage2.Location = new System.Drawing.Point(4, 21);
- this.tabPage2.Name = "tabPage2";
- this.tabPage2.Size = new System.Drawing.Size(512, 351);
- this.tabPage2.TabIndex = 1;
- this.tabPage2.Text = "单框显示";
- this.tabPage2.Click += new System.EventHandler(this.tabPage2_Click);
- //
- // button11
- //
- this.button11.BackColor = System.Drawing.Color.Transparent;
- this.button11.Location = new System.Drawing.Point(344, 208);
- this.button11.Name = "button11";
- this.button11.TabIndex = 21;
- 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(168, 208);
- this.button12.Name = "button12";
- this.button12.TabIndex = 20;
- 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(344, 168);
- this.button13.Name = "button13";
- this.button13.TabIndex = 19;
- 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(256, 168);
- this.button14.Name = "button14";
- this.button14.TabIndex = 18;
- 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(168, 168);
- this.button15.Name = "button15";
- this.button15.TabIndex = 17;
- 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(344, 128);
- this.button16.Name = "button16";
- this.button16.TabIndex = 16;
- 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(256, 128);
- this.button17.Name = "button17";
- this.button17.TabIndex = 14;
- 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(168, 128);
- this.button18.Name = "button18";
- this.button18.TabIndex = 13;
- 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(256, 208);
- this.button19.Name = "button19";
- this.button19.TabIndex = 15;
- this.button19.Text = "删除记录";
- this.button19.Click += new System.EventHandler(this.button19_Click);
- //
- // textBox3
- //
- this.textBox3.Location = new System.Drawing.Point(96, 80);
- this.textBox3.Name = "textBox3";
- this.textBox3.Size = new System.Drawing.Size(120, 21);
- this.textBox3.TabIndex = 6;
- this.textBox3.Text = "";
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(96, 24);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(120, 21);
- this.textBox2.TabIndex = 5;
- this.textBox2.Text = "";
- //
- // label3
- //
- this.label3.BackColor = System.Drawing.Color.Transparent;
- this.label3.Location = new System.Drawing.Point(40, 87);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(56, 16);
- this.label3.TabIndex = 2;
- this.label3.Text = "密 码:";
- //
- // label2
- //
- this.label2.BackColor = System.Drawing.Color.Transparent;
- this.label2.Location = new System.Drawing.Point(40, 31);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(56, 16);
- this.label2.TabIndex = 1;
- this.label2.Text = "用户名:";
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(544, 80);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(152, 32);
- this.label1.TabIndex = 1;
- this.label1.Text = "label1";
- //
- // userg1
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
- this.ClientSize = new System.Drawing.Size(480, 272);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.tabControl1);
- this.Name = "userg1";
- this.Text = "用户管理";
- this.Load += new System.EventHandler(this.userg1_Load);
- this.tabControl1.ResumeLayout(false);
- this.tabPage1.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
- this.panel1.ResumeLayout(false);
- this.tabPage2.ResumeLayout(false);
- this.ResumeLayout(false);
- }
- #endregion
- private void tabPage2_Click(object sender, System.EventArgs e)
- {
- }
- private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- }
- private void userg1_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 user1";
- 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];
- //oleDbDataAdapter1.Fill(dataSet1);
- this.dataGrid1.DataSource=mytable;
- //conn.Close();
- try
- {
- //this.oleDbDataAdapter1.Fill(this.dataSet1,"user1");
- this.textBox2.DataBindings.Add("Text",mytable,"Name");
- this.textBox3.DataBindings.Add("Text",mytable,"Passwd");
- this.MyBind=this.dataGrid1.BindingContext[mytable];
- this.dataGrid1.Select(0);
- }
- catch(Exception Err)
- {
- MessageBox.Show("打开数据库表错误:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
- return;
- }
- }
- private void button8_Click(object sender, System.EventArgs e)
- {
- //第一条记录
- this.dataGrid1.UnSelect(MyBind.Position);
- this.MyBind.Position=0;
- this.dataGrid1.Select(MyBind.Position);
- }
- private void button7_Click(object sender, System.EventArgs e)
- {
- //前一条记录
- if(this.MyBind.Position==0)
- {
- MessageBox.Show("已经是第一条记录","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
- return;
- }
- else
- {
- this.dataGrid1.UnSelect(MyBind.Position);
- this.MyBind.Position--;
- this.dataGrid1.Select(MyBind.Position);
- }
- }
- private void button6_Click(object sender, System.EventArgs e)
- {
- //后一条记录
- if(this.MyBind.Position==this.MyBind.Count-1)
- {
- MessageBox.Show("已经是末一条记录","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
- return;
- }
- else
- {
- this.dataGrid1.UnSelect(MyBind.Position);
- this.MyBind.Position++;
- this.dataGrid1.Select(MyBind.Position);
- this.label1.Text=MyBind.Count.ToString();
- }
- }
- private void button5_Click(object sender, System.EventArgs e)
- {
- //末一条记录
- this.dataGrid1.UnSelect(MyBind.Position);
- this.MyBind.Position=this.MyBind.Count-1;
- this.dataGrid1.Select(this.MyBind.Position);
- }
- private void button4_Click(object sender, System.EventArgs e)
- {
- //新建记录
- }
- 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)
- {
- this.MyBind.Position=this.MyBind.Count-1;
- }
- private void button14_Click(object sender, System.EventArgs e)
- {
- this.textBox2.Text="";
- this.textBox3.Text="";
- }
- 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 user1(Name,Passwd)VALUES('"+this.textBox2.Text.Trim()+"','"+this.textBox3.Text.Trim()+"')";
- //sring strsql="select * from***"
- /*OleDbDataAdapter da1=new OleDbDataAdapter(StrSQL,conn);
- DataSet ds1=new DataSet();
- da1.Fill(ds1);
- DataTable mytable1=new DataTable();
- DataRow newrow=myatble.newrow()
- newrow[0=
- mytable[1,2]
- mytable.add(datarow)
- mytable1=ds1.Tables[0];
- OleDbCommandBuilder cmdbld1=new OleDbCommandBuilder(da1);*/
- OleDbCommand cmd=new OleDbCommand(StrSQL,conn);
- cmd.ExecuteNonQuery();
- //da1.Update(mytable1);
- MessageBox.Show("增加数据集记录操作成功!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- catch(Exception Err)
- {
- MessageBox.Show("增加数据集记录操作失败:"+Err.Message,"信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
- }
- }
- private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
- {
- }
- private void button1_Click(object sender, System.EventArgs e)
- {
- Application.Exit();
- }
- private void button11_Click(object sender, System.EventArgs e)
- {
- Application.Exit();
- }
- 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 user1 where name='"+this.textBox2.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.textBox2.Text.Trim();
- row1[1]=this.textBox3.Text.Trim();
- OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
- da.Update(mytable);
- MessageBox.Show("密码修改成功!");
- conn2.Close();
- }
- catch(Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- private void button3_Click(object sender, System.EventArgs e)
- {
- }
- private void button2_Click(object sender, System.EventArgs e)
- {
- }
- 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 user1 WHERE ";
- StrSQL+=" Name='"+this.textBox2.Text+"'";
- //"delete from user1 where( "Name="'"+this.textBox2.Text.Trim()+"','"+this.textBox3.Text.Trim()+"')";
- //string StrSQL="DELETE FROM user1 WHERE(Name='"+this.textBox2.Text.Trim()+"'and Passwd='"+this.textBox3.Text.Trim()+"')";
- //StrSQL+="Name='"+this.textBox2.Text.Trim()+"'";
- //StrSQL+="Passwd='"+this.textBox3.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);
- }
- }
- }
- }