ATm

来源:互联网 发布:古风头像源码怎么用 编辑:程序博客网 时间:2024/04/28 22:19


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ATM
{
    public partial class Card : Form
    {
        DataSet ds = new DataSet();
        SqlDataAdapter dataAdapter = null;
        public Card()
        {
            InitializeComponent();
        } string connStr = "Data Source=.;Initial Catalog=ATM;Persist Security Info=True;User ID=sa;Password=1234";

          
         private void Card_Load(object sender, EventArgs e)
        {
            string sql = @"SELECT  customerName as 客户姓名, PID as 身份证号, telephone as 电话, address as 地址 FROM userInfo";
            SqlConnection connection = new SqlConnection(connStr);
            dataAdapter = new SqlDataAdapter(sql, connection);
            dataAdapter.Fill(ds);
            this.dataGridView1.DataSource = ds.Tables[0];
        }
      

        private void button1_Click(object sender, EventArgs e)
        {

            string sql = @"SELECT  customerName as 客户姓名, PID as 身份证号, telephone as 电话, address as 地址 FROM userInfo where 1=1";
            if (textBox3.Text != "")
            {
                sql = sql + "and telephone like'%" + textBox3.Text + "%'";
            }
            if (textBox2.Text != "")
            {
                sql = sql + "and PID like'%" + textBox2.Text + "%'";
            }
            if (textBox1.Text != "")
            {
                sql = sql + "and customerName like'%" + textBox1.Text + "%'";

            }
            dataAdapter.SelectCommand.CommandText = sql;
            ds.Tables[0].Clear();
            dataAdapter.Fill(ds);
        }

      
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

      

    }
}

0 0