📄 form2.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace PeiJian
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
int a = 0,b=0;
data data = new data();
private OleDbDataReader reader;
private void have3()
{
string sqlstr = "select * from [user]";
reader = data.GetData(sqlstr);
while (reader.Read())
{
if (reader["userid"].ToString() == textBox1.Text)
{
b = 1;
}
}
reader.Close();
}
private void tj()
{
int rows;
string str = "insert into [user](userid,[password]) values ('" + textBox1.Text + "','" + textBox2.Text + "')";
if (textBox1.Text.Trim() != "" && textBox2.Text.Trim() != "")
{
try
{
rows = data.Operdata(str);
if (rows != 1)
{
MessageBox.Show("没有插入成功");
}
MessageBox.Show("恭喜您,插入成功!");
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
}
else
MessageBox.Show("用户名和密码不能为空!");
}
private void gl()
{
string sqlstr = "select * from [user]";
reader = data.GetData(sqlstr);
listBox1.Items.Clear();
while (reader.Read())
{
listBox1.Items.Add(reader["userid"].ToString());
}
if (listBox1.Items.Count > 0)
{
listBox1.SetSelected(0, true);//选中第个1项
}
reader.Close();
}
private void gl1()
{
string sqlstr = "select * from [user] where userid='"+listBox1.SelectedItem+"'";
reader = data.GetData(sqlstr);
while (reader.Read())
{
textBox1.Text = reader["userid"].ToString();
textBox2.Text = reader["password"].ToString();
}
reader.Close();
}
private void have()
{
string sqlstr = "select * from [user]";
reader = data.GetData(sqlstr);
while (reader.Read())
{
if (reader["userid"].ToString() == textBox1.Text)
{
if (reader["password"].ToString() == textBox2.Text)
{
a = 1;
}
}
}
reader.Close();
}
private void xg()
{
int rows;
string str = "update [user] set userid='" + textBox1.Text + "',[password]='" + textBox2.Text + "' where userid='"+listBox1.SelectedItem+"'";
if (textBox1.Text.Trim() != "" && textBox2.Text.Trim() != "")
{
try
{
rows = data.Operdata(str);
if (rows != 1)
{
MessageBox.Show("没有修改成功");
}
else
{
MessageBox.Show("恭喜您,修改成功!");
}
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
}
else
MessageBox.Show("用户名和密码不能为空!");
}
private void sc()
{
int rows;
string str = "delete from [user] where userid='"+listBox1.SelectedItem+"'";
try
{
rows = data.Operdata(str);
if (rows != 1)
{
MessageBox.Show("没有删除成功");
}
MessageBox.Show("恭喜您,删除成功!");
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
}
private void cx()
{
string sqlstr = "select * from products";
reader = data.GetData(sqlstr);
listBox1.Items.Clear();
while (reader.Read())
{
listBox2.Items.Add(reader["mingcheng"].ToString());
}
if (listBox2.Items.Count > 0)
{
listBox2.SetSelected(0, true);//选中第个1项
}
reader.Close();
}
private void cx1()
{
string sqlstr = "select * from products where mingcheng like '%" + textBox3.Text + "%' or leixinid like '%" + textBox3.Text + "%' or gaikuang like '%" + textBox3.Text + "%'";
reader = data.GetData(sqlstr);
listBox1.Items.Clear();
while (reader.Read())
{
listBox2.Items.Add(reader["mingcheng"].ToString());
}
if (listBox2.Items.Count > 0)
{
listBox2.SetSelected(0, true);//选中第个1项
}
reader.Close();
}
private void cx2()
{
string sqlstr = "select * from products";
reader = data.GetData(sqlstr);
listBox1.Items.Clear();
while (reader.Read())
{
listBox3.Items.Add(reader["mingcheng"].ToString());
}
if (listBox3.Items.Count > 0)
{
listBox3.SetSelected(0, true);//选中第个1项
}
reader.Close();
}
private void cx3()
{
string sqlstr = "select * from products where mingcheng like '%" + textBox4.Text + "%' or leixinid like '%" + textBox4.Text + "%' or gaikuang like '%" + textBox4.Text + "%'";
reader = data.GetData(sqlstr);
listBox1.Items.Clear();
while (reader.Read())
{
listBox3.Items.Add(reader["mingcheng"].ToString());
}
if (listBox3.Items.Count > 0)
{
listBox3.SetSelected(0, true);//选中第个1项
}
reader.Close();
}
private void ck()
{
string sqlstr = "select * from canku where mingcheng='" + listBox3.SelectedItem + "'";
reader = data.GetData(sqlstr);
while (reader.Read())
{
textBox6.Text = reader["shuliang"].ToString();
textBox7.Text = reader["jiage"].ToString();
textBox8.Text = reader["riqi"].ToString();
}
reader.Close();
}
private void tjck()
{
int rows = 0;
string sqlstr = "insert into canku(mingcheng,shuliang,jiage,riqi) values('" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + DateTime.Today.ToString()+"')";
try
{
rows = data.Operdata(sqlstr);
if (rows != 1)
{
MessageBox.Show("没有添加成功");
}
else
{
MessageBox.Show("恭喜您,添加成功!");
}
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
}
private void have1()
{
string sqlstr = "select * from canku where mingcheng='" + textBox5.Text + "'";
reader = data.GetData(sqlstr);
if (reader.Read() == false)
{
reader.Close();
tjck();
ck();
}
else
{
MessageBox.Show("已存在该产品信息!");
}
reader.Close();
}
private void have2()
{
string sqlstr = "select * from canku where mingcheng='" + textBox5.Text + "'";
reader = data.GetData(sqlstr);
if (reader.Read() == false)
{
button14.Enabled = true;
button15.Enabled = false;
button16.Enabled = false;
textBox6.ReadOnly = false;
textBox7.ReadOnly = false;
}
else
{
button14.Enabled = false;
button15.Enabled = true;
button16.Enabled = true;
textBox6.ReadOnly = true;
textBox7.ReadOnly = true;
}
reader.Close();
}
private void xiugai()
{
int rows = 0;
string sqlstr = "update canku set shuliang='" + textBox6.Text + "',jiage='" + textBox7.Text + "',riqi='" + DateTime.Today.ToString() + "' where mingcheng='" + textBox5.Text + "'";
try
{
rows = data.Operdata(sqlstr);
if (rows != 1)
{
MessageBox.Show("没有修改成功");
}
else
{
MessageBox.Show("恭喜您,修改成功!");
}
}
catch (Exception e2)
{
MessageBox.Show(e2.Message);
}
}
private void shanchu()
{
int rows;
string str = "delete from canku where mingcheng='" + textBox5.Text + "'";
try
{
rows = data.Operdata(str);
if (rows != 1)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -