?? frm商品管理.cs
字號(hào):
?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 餐飲管理系統(tǒng)
{
public partial class frm商品管理 : Form
{
public frm商品管理()
{
InitializeComponent();
}
private void frm商品管理_Load(object sender, EventArgs e)
{
button庫(kù)存_Click(null, null);
}
private void button庫(kù)存_Click(object sender, EventArgs e)
{
//ViewProductInfo是一個(gè)視圖,,,,,,,,,,新知識(shí)!!!!!!!!!!
string strSql = "select * from ViewProductInfo";
DataTable dt = DBserver.setComGetTable(strSql);
dataGridView1.DataSource = dt;
tabControl1.SelectedTab = tabPage庫(kù)存;
//foreach (DataGridViewRow dgvr in dataGridView1.Rows)
//{
// string strproducID = dgvr.Cells["Column商品編號(hào)"].ToString();
// string strProducTypeSQL = string.Format("select 商品類(lèi)名 from dt_PriductTypeName where ID=(select 商品類(lèi)別代號(hào) from dt_Productinfo where 商品編號(hào)='{0}')", strproducID);
// string strCurrValue = DBserver.setCommGetScalar(strProducTypeSQL).ToString();
// dgvr.Cells["Column商品類(lèi)別"].Value = strCurrValue;
//}
}
private void button添加庫(kù)存_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage添加庫(kù)存;
//首先將窗體中添加品種的控件的可用性變?yōu)镕Alse
groupBoxAddType.Enabled = false;
groupBoxAdd庫(kù)存.Enabled = true;
string strSql = "select 商品類(lèi)名 from dt_PriductTypeName ";
DataTable dt = DBserver.setComGetTable(strSql);
comboBoxAdd庫(kù)存ProType.DataSource = dt;
comboBoxAdd庫(kù)存ProType.DisplayMember = "商品類(lèi)名";
}
private void buttonAdd庫(kù)存Ok_Click(object sender, EventArgs e)
{
//接收界面上的值
string strProductID = textBoxAdd庫(kù)存ProID.Text.Trim();
string strProductName = textBoxAdd庫(kù)存ProName.Text.Trim();
string strProductType = comboBoxAdd庫(kù)存ProType.Text.Trim();
float fProductPrice = 0.0f;
try
{
fProductPrice = float.Parse(textBoxAdd庫(kù)存ProPrice.Text.Trim());
}
catch
{
}
try
{
string strSQL = string.Format("select ID from dt_PriductTypeName where 商品類(lèi)名= '{0}'", strProductType);
int nID = int.Parse(DBserver.setCommGetScalar(strSQL).ToString());
string StrSql = string.Format("insert into dt_Productinfo(商品編號(hào),商品名稱(chēng),商品類(lèi)別代號(hào),價(jià)格)values('{0}','{1}',{2},{3})",
strProductID, strProductName, nID, fProductPrice);
if (DBserver.setCommNornQuey(StrSql) > 0)
{
MessageBox.Show("添加成功!");
button庫(kù)存_Click(null, null);
}
}
catch (Exception ee)
{
MessageBox.Show(ee.Message);
}
}
private void button添加品種_Click(object sender, EventArgs e)
{
tabControl1.SelectedTab = tabPage添加庫(kù)存;
groupBoxAdd庫(kù)存.Enabled = false;
groupBoxAddType.Enabled = true;
}
private void buttonAdd品種Ok_Click(object sender, EventArgs e)
{
//另一種方法向數(shù)據(jù)庫(kù)中添加數(shù)據(jù)
string strProductNewType=textBoxAddTypeName.Text.Trim();
SqlConnection conn=new SqlConnection("server=.;trusted_connection=yes;database=餐飲管理系統(tǒng);");
conn.Open();
//定義一個(gè)參數(shù)
SqlParameter strCurrType = new SqlParameter("@strProductNewType", SqlDbType.Char, 50);
//Sql語(yǔ)句
string strSql = "insert into dt_PriductTypeName(商品類(lèi)名)values(@strProductNewType)";
//命令語(yǔ)句的創(chuàng)建
SqlCommand comm = new SqlCommand(strSql, conn);
//給命令語(yǔ)句加參數(shù)
comm.Parameters.Add(strCurrType);
//給所加參數(shù)賦值
strCurrType.Value = strProductNewType;
comm.ExecuteNonQuery();
button庫(kù)存_Click(null, null);
}
private void buttonAdd品種Cancle_Click(object sender, EventArgs e)
{
groupBoxAddType.Enabled = false;
button庫(kù)存_Click(null, null);
}
private void buttonAdd庫(kù)存Cancle_Click(object sender, EventArgs e)
{
groupBoxAdd庫(kù)存.Enabled = false;
button庫(kù)存_Click(null, null);
}
private void buttonDele_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 0)
{
MessageBox.Show("刪除之前必須選中一行數(shù)據(jù)!");
return;
}
string strCurrID = dataGridView1.CurrentRow.Cells["Column商品編號(hào)"].Value.ToString();
string strSql = string.Format("delete from dt_Productinfo where 商品編號(hào)='{0}'", strCurrID);
if (DBserver.setCommNornQuey(strSql) > 0)
{
MessageBox.Show("刪除成功!");
button庫(kù)存_Click(null, null);
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -