📄 frm商品管理.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 餐饮管理系统
{
public partial class frm商品管理 : Form
{
public frm商品管理()
{
InitializeComponent();
}
private void frm商品管理_Load(object sender, EventArgs e)
{
button库存_Click(null, null);
}
private void button库存_Click(object sender, EventArgs e)
{
//ViewProductInfo是一个视图,,,,,,,,,,新知识!!!!!!!!!!
string strSql = "select * from ViewProductInfo";
DataTable dt = DBserver.setComGetTable(strSql);
dataGridView1.DataSource = dt;
tabControl1.SelectedTab = tabPage库存;
//foreach (DataGridViewRow dgvr in dataGridView1.Rows)
//{
// string strproducID = dgvr.Cells["Column商品编号"].ToString();
// string strProducTypeSQL = string.Format("select 商品类名 from dt_PriductTypeName where ID=(select 商品类别代号 from dt_Productinfo where 商品编号='{0}')", strproducID);
// string strCurrValue = DBserver.setCommGetScalar(strProducTypeSQL).ToString();
// dgvr.Cells["Column商品类别"].Value = strCurrValue;
//}
}
private void button添加库存_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage添加库存;
//首先将窗体中添加品种的控件的可用性变为FAlse
groupBoxAddType.Enabled = false;
groupBoxAdd库存.Enabled = true;
string strSql = "select 商品类名 from dt_PriductTypeName ";
DataTable dt = DBserver.setComGetTable(strSql);
comboBoxAdd库存ProType.DataSource = dt;
comboBoxAdd库存ProType.DisplayMember = "商品类名";
}
private void buttonAdd库存Ok_Click(object sender, EventArgs e)
{
//接收界面上的值
string strProductID = textBoxAdd库存ProID.Text.Trim();
string strProductName = textBoxAdd库存ProName.Text.Trim();
string strProductType = comboBoxAdd库存ProType.Text.Trim();
float fProductPrice = 0.0f;
try
{
fProductPrice = float.Parse(textBoxAdd库存ProPrice.Text.Trim());
}
catch
{
}
try
{
string strSQL = string.Format("select ID from dt_PriductTypeName where 商品类名= '{0}'", strProductType);
int nID = int.Parse(DBserver.setCommGetScalar(strSQL).ToString());
string StrSql = string.Format("insert into dt_Productinfo(商品编号,商品名称,商品类别代号,价格)values('{0}','{1}',{2},{3})",
strProductID, strProductName, nID, fProductPrice);
if (DBserver.setCommNornQuey(StrSql) > 0)
{
MessageBox.Show("添加成功!");
button库存_Click(null, null);
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
private void button添加品种_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage添加库存;
groupBoxAdd库存.Enabled = false;
groupBoxAddType.Enabled = true;
}
private void buttonAdd品种Ok_Click(object sender, EventArgs e)
{
//另一种方法向数据库中添加数据
string strProductNewType=textBoxAddTypeName.Text.Trim();
SqlConnection conn=new SqlConnection("server=.;trusted_connection=yes;database=餐饮管理系统;");
conn.Open();
//定义一个参数
SqlParameter strCurrType = new SqlParameter("@strProductNewType", SqlDbType.Char, 50);
//Sql语句
string strSql = "insert into dt_PriductTypeName(商品类名)values(@strProductNewType)";
//命令语句的创建
SqlCommand comm = new SqlCommand(strSql, conn);
//给命令语句加参数
comm.Parameters.Add(strCurrType);
//给所加参数赋值
strCurrType.Value = strProductNewType;
comm.ExecuteNonQuery();
button库存_Click(null, null);
}
private void buttonAdd品种Cancle_Click(object sender, EventArgs e)
{
groupBoxAddType.Enabled = false;
button库存_Click(null, null);
}
private void buttonAdd库存Cancle_Click(object sender, EventArgs e)
{
groupBoxAdd库存.Enabled = false;
button库存_Click(null, null);
}
private void buttonDele_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("删除之前必须选中一行数据!");
return;
}
string strCurrID = dataGridView1.CurrentRow.Cells["Column商品编号"].Value.ToString();
string strSql = string.Format("delete from dt_Productinfo where 商品编号='{0}'", strCurrID);
if (DBserver.setCommNornQuey(strSql) > 0)
{
MessageBox.Show("删除成功!");
button库存_Click(null, null);
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -