智慧社區(qū)商超管理系統(tǒng)的設(shè)計與開發(fā)---------商品信息錄入界面功能設(shè)計
一、gif動態(tài)效果圖

二、主要功能及后臺數(shù)據(jù)庫表結(jié)構(gòu)
1、主要功能
登陸進入系統(tǒng)之后,打開商品錄入板塊。此時會彈出錄入界面,輸入想要錄入的商品信息點擊錄入,若步驟成功,將會彈出商品信息錄入成功的窗口點擊確定,即可錄入進數(shù)據(jù)庫。
2、后臺數(shù)據(jù)庫表結(jié)構(gòu)


三、ADO.NET插入數(shù)據(jù)庫的流程
1、圖解


2、代碼
```
String id = this.tb_Id.Text.Trim();
String name = this.tb_Name.Text.Trim();
float price = float.Parse(this.tb_Price.Text.Trim());
String spec = this.tb_Spec.Text.Trim();
String remark = this.tb_Remark.Text.Trim();
// 連接字符串,注意與實際環(huán)境保持一致
String connStr = ConfigurationManager.ConnectionStrings["SuperMarketSales"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connStr);
try
{
? // 連接數(shù)據(jù)庫
? sqlConn.Open();
}
catch (Exception exp)
{
? MessageBox.Show("訪問數(shù)據(jù)庫錯誤:" + exp.Message);
}
finally
{
? sqlConn.Close();
}
// 構(gòu)造命令
String sqlStr = "insert
into GOODS2(ID, NAME, PRICE, SPEC, REMARK) values(@id, @name, @price, @spec,
@remark)";
SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
// SQL字符串參數(shù)賦值
cmd.Parameters.Add(new SqlParameter("@id", id));
cmd.Parameters.Add(new SqlParameter("@name", name));
cmd.Parameters.Add(new SqlParameter("@price", price));
cmd.Parameters.Add(new SqlParameter("@spec", spec));
cmd.Parameters.Add(new SqlParameter("@remark", remark));
// 將命令發(fā)送給數(shù)據(jù)庫
int res = cmd.ExecuteNonQuery();
// 根據(jù)返回值判斷是否插入成功
if (res != 0)
{
? MessageBox.Show("商品信息錄入成功");
}
else
{
? MessageBox.Show("商品信息錄入失敗");
}
```
四、畫面功能是如何迭代的,描述迭代過程(無外鍵à有外鍵)
1、外鍵
界面無外鍵的時候是沒有供應(yīng)商的選項,用的是GOODSINFO表在這個數(shù)據(jù)庫表中是沒有外鍵的,通過添加供應(yīng)商這一列的外鍵實現(xiàn)從數(shù)據(jù)庫GOODS表中直接用數(shù)據(jù)庫中SUPPLIER表中的數(shù)據(jù)。
五、ComboBox數(shù)據(jù)綁定流程
1、具體流程:
a、指定ComboBox的數(shù)據(jù)源為DataSet的MySupplier表
b、將DataSet和DataAdapter綁定
c、加入鏈接數(shù)據(jù)庫代碼try··catch·· finally
2、圖示:


六、項目過程中的重要代碼
插入窗體
```
RecordForm pwdForm = new RecordForm();
? ? ? ? ? ? pwdForm.MdiParent = this;
? ? ? ? ? ? pwdForm.StartPosition = FormStartPosition.CenterScreen;
? ? ? ? ? ? pwdForm.Show();
```
錄入商品信息
```
private void bt_Ok_Click(object sender, EventArgs e)
? ? ? ? {
? ? ? ? ? ? String id = this.tb_Id.Text.Trim();
? ? ? ? ? ? String name = this.tb_Name.Text.Trim();
? ? ? ? ? ? float price = float.Parse(this.tb_Price.Text.Trim());
? ? ? ? ? ? String spec = this.tb_Spec.Text.Trim();
? ? ? ? ? ? String remark = this.tb_Remark.Text.Trim();
? ? ? ? ? ? // 連接字符串,注意與實際環(huán)境保持一致
? ? ? ? ? ? String connStr = ConfigurationManager.ConnectionStrings["SuperMarketSales"].ConnectionString;
? ? ? ? ? ? SqlConnection sqlConn = new SqlConnection(connStr);
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? // 連接數(shù)據(jù)庫
? ? ? ? ? ? ? ? sqlConn.Open();
? ? ? ? ? ? ? ? // 構(gòu)造命令
? ? ? ? ? ? ? ? String sqlStr = "insert into GOODS2(ID, NAME, PRICE, SPEC, REMARK) values(@id, @name, @price, @spec, @remark)";
? ? ? ? ? ? ? ? SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
? ? ? ? ? ? ? ? // SQL字符串參數(shù)賦值
? ? ? ? ? ? ? ? cmd.Parameters.Add(new SqlParameter("@id", id));
? ? ? ? ? ? ? ? cmd.Parameters.Add(new SqlParameter("@name", name));
? ? ? ? ? ? ? ? cmd.Parameters.Add(new SqlParameter("@price", price));
? ? ? ? ? ? ? ? cmd.Parameters.Add(new SqlParameter("@spec", spec));
? ? ? ? ? ? ? ? cmd.Parameters.Add(new SqlParameter("@remark", remark));
? ? ? ? ? ? ? ? // 將命令發(fā)送給數(shù)據(jù)庫
? ? ? ? ? ? ? ? int res = cmd.ExecuteNonQuery();
? ? ? ? ? ? ? ? // 根據(jù)返回值判斷是否插入成功
? ? ? ? ? ? ? ? if (res != 0)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? MessageBox.Show("商品信息錄入成功");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? MessageBox.Show("商品信息錄入失敗");
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception exp)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("訪問數(shù)據(jù)庫錯誤:" + exp.ToString());
? ? ? ? ? ? }
? ? ? ? ? ? finally
? ? ? ? ? ? {
? ? ? ? ? ? ? ? sqlConn.Close();
? ? ? ? ? ? }
```