📄 formkhxx.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace _10901BS
{
public partial class formKhxx : Form
{
int eeee = 0;
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
SqlDataAdapter da;
SqlDataReader eee;
DataSet ee = new DataSet();
public formKhxx()
{
InitializeComponent();
}
private void 客户表_Load(object sender, EventArgs e)
{
if (cn.State == ConnectionState.Closed)
{
cn.ConnectionString = "Data Source=.;Initial Catalog=110901DB;Integrated Security=True";
cn.Open();
}
da = new SqlDataAdapter("select hyID as '会员卡号',hyName as '会员姓名',hylx as '会员类型',hySfzh as '会员身份证号',hyDh as '会员电话',hyDz as '会员地址',beiZhu as '备注'from KhBiao", cn);
ee.Clear();
da.Fill(ee);
this.dataGridView1.DataSource = ee.Tables[0];
this.dataGridView1.Columns[0].Width = 80;
this.dataGridView1.Columns[1].Width = 80;
this.dataGridView1.Columns[2].Width = 80;
this.dataGridView1.Columns[3].Width = 120;
this.dataGridView1.Columns[5].Width = 200;
this.dataGridView1.Columns[6].Width = 200;
this.txthyID.Text = "";
this.txthyName.Text ="";
this.txthyLx.Text ="";
this.txthySfzh.Text ="";
this.txthyDh.Text ="";
this.txthyDz.Text = "";
this.txtbeiZhu.Text = "";
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
this.txthyID.Text = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
this.txthyName.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
this.txthyLx.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
this.txthySfzh.Text = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
this.txthyDh.Text = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
this.txthyDz.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
this.txtbeiZhu.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();
}
//添加功能
private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.txthyID.Text.Length != 4 && this.txthyID.Text != "")
{
MessageBox.Show("编号输入有误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
txthyID.Text = "";
txthyID.Focus();
return;
}
if (this.txthyName.Text == "")
{
MessageBox.Show("您尚未输入姓名,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
txthyName.Focus();
return;
}
if (this.txthyID.Text == "")
{
cm.Connection = cn;
cm.CommandText = "select hyID from khBiao ORDER by hyID DESC ";
this.txthyID.Text = Convert.ToString(Convert.ToInt32(cm.ExecuteScalar().ToString()) + 1).PadLeft(4, '0');
}
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "select * from khBiao where hyID = '" + this.txthyID.Text + "' ";
eee = cm.ExecuteReader();
if (eee.Read())
{
MessageBox.Show("您输入的编号已存在,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
txthyID.Text = "";
txthyID.Focus();
eee.Close();
}
else
{
eee.Close();
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "insert into khBiao values('" + this.txthyID.Text + "','" + this.txthyName.Text + "','" + this.txthyLx.Text + "','" + this.txthySfzh.Text + "','" + this.txthyDh.Text + "','" + this.txthyDz.Text + "','" + this.txtbeiZhu.Text + "')";
cm.ExecuteNonQuery();
MessageBox.Show("添加成功!");
ee.Clear();
客户表_Load(sender, e);
}
}
//修改功能
private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.txthyID.Text.Length != 4)
{
MessageBox.Show("编号输入有误,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
txthyID.Text = "";
txthyID.Focus();
return;
}
if (this.txthyName.Text == "")
{
MessageBox.Show("您尚未输入姓名,请重新输入!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
txthyName.Focus();
return;
}
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "update khBiao set hyName='" + this.txthyName.Text + "',hyLx='" + this.txthyLx.Text + "',hySfzh='" + this.txthySfzh.Text + "',hyDh='" + this.txthyDh.Text + "',hyDz='" + this.txthyDz.Text + "',beiZhu='" + this.txtbeiZhu.Text + "'where hyID='" + this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
cm.ExecuteNonQuery();
MessageBox.Show("修改成功!");
客户表_Load(sender, e);
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (eeee == 0)
{
DialogResult c = MessageBox.Show("真的要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (c == DialogResult.Yes)
{
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandText = "delete khBiao where hyID='" + this.dataGridView1.CurrentRow.Cells[0].Value.ToString() + "'";
cm.ExecuteNonQuery();
MessageBox.Show("删除成功!");
客户表_Load(sender, e);
}
}
else
{
MessageBox.Show("您的操作未完成,请点击 取消 后进行此操作!");
}
}
//刷新功能
private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
{
客户表_Load(sender, e);
}
private void 查询_Click(object sender, EventArgs e)
{
if (txthyID.Text == "" && txthyName.Text == "" && txthyLx.Text == "" && txthySfzh.Text == "" && txthyDh.Text == "" && txthyDz.Text == "")
{
MessageBox.Show("请输入查询信息!");
return;
}
//hyID查询
else if (txthyID.Text != "" && txthyName.Text == "" && txthyLx.Text == "" && txthySfzh.Text == "" && txthyDh.Text == "" && txthyDz.Text == "" && txtbeiZhu.Text == "")
{
cm.Connection = cn;
cm.CommandText = "select * from khBiao where hyID='" + this.txthyID.Text + "'";
eee = cm.ExecuteReader();
if (eee.Read())
{
ee.Clear();
eee.Close();
cm.CommandText = "select hyID as '会员卡号',hyName as '会员姓名',hylx as '会员类型',hySfzh as '会员身份证号',hyDh as '会员电话',hyDz as '会员地址',beiZhu as '备注' from khBiao where hyID='" + this.txthyID.Text + "'";
da.SelectCommand = cm;
da.Fill(ee);
this.dataGridView1.DataSource = ee.Tables[0];
MessageBox.Show("查询成功!");
}
else
{
eee.Close();
MessageBox.Show("系统提示:您的查询的信息不存在!");
}
}
//khName查询
else if (txthyID.Text == "" && txthyName.Text != "" && txthyLx.Text == "" && txthySfzh.Text == "" && txthyDh.Text == "" && txthyDz.Text == "")
{
cm.Connection = cn;
cm.CommandText = "select * from khBiao where hyName='" + this.txthyName.Text + "'";
eee = cm.ExecuteReader();
if (eee.Read())
{
ee.Clear();
eee.Close();
cm.CommandText = "select hyID as '会员卡号',hyName as '会员姓名',hylx as '会员类型',hySfzh as '会员身份证号',hyDh as '会员电话',hyDz as '会员地址',beiZhu as '备注' from khBiao where hyName='" + this.txthyName.Text + "'";
da.SelectCommand = cm;
da.Fill(ee);
this.dataGridView1.DataSource = ee.Tables[0];
MessageBox.Show("查询成功!");
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -