using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 课程设计
{
public partial class Form1 : Form
{
OleDbConnection conn = new OleDbConnection(" Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Supermarket.mdb");
DataSet ds = new DataSet();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“supermarketDataSet.MemberInfo”中。您可以根据需要移动或移除它。
this.memberInfoTableAdapter.Fill(this.supermarketDataSet.MemberInfo);
textBox6.Text = DateTime.Today.ToShortDateString();
conn.Open();
OleDbCommand cmd = new OleDbCommand("SELECT * FROM MEMBERTYPE", conn);
OleDbDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox2.Items.Add(dr["会员等级"]);
}
dr.Close();
conn.Close();
MemberInfo();
}
private void button1_Click(object sender, EventArgs e)
{
string MemberId = newMemberId(textBox5.Text);
string sql = String.Format("INSERT INTO MEMBERInfo (会员姓名,会员性别,家庭住址,联系电话,邮箱,会员编号,入会时间,会员等级,折扣率) VALUES('"+textBox1.Text+"', '"+comboBox1.Text+"', '"+textBox2.Text+"', '"+textBox3.Text+"', '"+textBox4.Text+"', '"+textBox5.Text+"', '"+textBox6.Text+"', '"+comboBox2.Text+"', '"+textBox10.Text+"')");
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("添加会员成功,会员编号:" + MemberId);
}
private string newMemberId(string 会员编号)
{
string sql = "SELECT COUNT(*) FROM MEMBERINFO WHERE 会员编号='" + 会员编号 + "'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
int number = Convert.ToInt32(cmd.ExecuteScalar()) + 1;
conn.Close();
return 会员编号 + "_" + number.ToString();
}
public void MemberInfo()
{
string showcmd = "select * from MemberInfo";
DataSet mydataset = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(showcmd, conn);
da.Fill(mydataset, "MemberInfo");
dataGridView1.DataSource = mydataset.Tables["MemberInfo"];
}
private void button2_Click(object sender, EventArgs e)
{
int i;
foreach (DataGridViewRow dgvr in dataGridView1.Rows)
{
if (Convert.ToBoolean(dgvr.Cells["Check"].Value) == true)
{
i = dgvr.Index;
i = e.RowIndex;
ds.Tables["MenberInfo"].Rows[i].Delete();
}
}
}
}
}