页面做的比较简单。
下图左边程序主界面,右边是各个页面的代码。
主程序入口代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace sale
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Login());
// Application.Run(new MainForm());//测试用
}
}
}
下面是主页面代码。
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace sale
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)//修改
{
Change form = new Change();
form.Show();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)//添加
{
Add form = new Add();//新建一个对象,打开添加窗口
form.Show();
}
private void button4_Click(object sender, EventArgs e)//删除 不会写直接删除,只好和其他一样,多做一个窗口
{
Delete form = new Delete();//打开删除的页面
form.Show();
}
private void button5_Click(object sender, EventArgs e)//查询
{
if (this.textBox1.Text.Trim() == "")
{
MessageBox.Show("请输入要查询的商品名称", "提示");
}
else{
string str = @"Data Source=zky\sqlexpress;Initial Catalog=sale;Integrated Security=True";
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand cmd = new SqlCommand();//绑定SqlConnection对象
cmd.CommandText = "Select* from good where name_good='" + this.textBox1.Text.Trim() + "'";//
cmd.Connection = conn;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();//数据集
sda.Fill(ds);
this.dataGridView1.DataSource = ds;
this.dataGridView1.DataMember = ds.Tables[0].ToString();//依次赋值
this.dataGridView1.AutoGenerateColumns =true;
dataGridView1.ReadOnly = true;//不允许直接在列表上编辑
dataGridView1.Columns[2].Visible = false;//第2列不出现在表中
dataGridView1.Columns[4].Visible = false;//第4列不出现在表中
dataGridView1.Columns[5].Visible = false;//第5列不出现在表中
conn.Close();
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)//主显示框
{
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}