public bool AddGoods(GoodsCore goodsCore, GoodsSaleLimitCore goodsSaleLimitCore, GoodsCategoryCore goodsCategoryCore, GoodsDisplayCore goodsDisplayCore, GoodsSalePricePolicyCore goodsSalePricePolicyCore, GoodsBasicPriceCore goodsBasicPriceCore, GoodsItemCore goodsItemCore, GoodsItemBasicPriceCore goodsItemBasicPriceCore, GoodsChangeCore goodsChangeCore) { int retCode = 0; try { AddGoodsCore(ref retCode, goodsCore); AddGoodsSaleLimitCore(ref retCode, goodsSaleLimitCore); AddGoodsCategoryCore(ref retCode, goodsCategoryCore); AddGoodsDisplayCore(ref retCode, goodsDisplayCore); AddGoodsSalePricePolicyCore(ref retCode, goodsSalePricePolicyCore); AddGoodsBasicPriceCore(ref retCode, goodsBasicPriceCore); AddGoodsItemCore(ref retCode, goodsItemCore); AddGoodsItemBasicPriceCore(ref retCode, goodsItemBasicPriceCore); AddGoodsChangeCore(ref retCode, goodsChangeCore); return(true); } catch (Exception ex) { throw new Exception(ex.Message); } }
public void AddGoodsCategoryCore(ref int retCode, GoodsCategoryCore goodsCategoryCore)//添加商品类别代码 { try { SqlCommand sqlCmd = new SqlCommand("GoodsDb.dbo.p_AddGoodsCategoryCore", sqlCnt) { //添加参数 CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.Add("@GoodsId", SqlDbType.Int).Value = goodsCategoryCore.GoodsId; sqlCmd.Parameters.Add("@CategoryId", SqlDbType.SmallInt).Value = goodsCategoryCore.CategoryId; sqlCmd.Parameters.Add("@DisplayOrder", SqlDbType.Int).Value = goodsCategoryCore.DisplayOrder; //添加返回值 SqlParameter parReturn = new SqlParameter("@return", SqlDbType.Int) { Direction = ParameterDirection.ReturnValue }; sqlCmd.Parameters.Add(parReturn); //执行 sqlCnt.Open(); sqlCmd.ExecuteNonQuery(); retCode = (int)parReturn.Value; if (retCode != 0) { throw new Exception(sqlCmd.CommandText + " 执行出错"); } } catch (Exception ex) { throw new Exception(ex.Message); } finally { // 断开 sqlCnt.Close(); } }
private void button_AddGoods_Click(object sender, EventArgs e) { try { if (listView_Items.Items.Count == 0) { throw new ArgumentException("至少添加一个项目"); } if (!bns.IsGoodsByGoodsId(textBox_GoodsId.Text)) { throw new ArgumentException("数据库已存在相同的商品ID"); } int retCode = 0; int.TryParse(textBox_GoodsId.Text, out int GoodsId); int.TryParse(textBox_SaleStatus.Text, out int SaleStatus); int.TryParse(textBox_GoodsPrice.Text, out int Price); short.TryParse(((ComBoBoxItem)comboBox_CategoryId.SelectedItem).Value, out short CategoryId); string GoodsName = textBox_GoodsName.Text; string GoodsDescription = textBox_GoodsDescription.Text; string GoodsAdminAccount = textBox_GoodsAdminAccount.Text; //添加商品 GoodsCore goodsCore = new GoodsCore(GoodsId, GoodsName, null, null, GoodsAdminAccount, GoodsDescription); GoodsSaleLimitCore goodsSaleLimitCore = new GoodsSaleLimitCore(GoodsId); GoodsCategoryCore goodsCategoryCore = new GoodsCategoryCore(GoodsId, CategoryId); GoodsDisplayCore goodsDisplayCore = new GoodsDisplayCore(GoodsId, GoodsName, GoodsDescription); GoodsSalePricePolicyCore goodsSalePricePolicyCore = new GoodsSalePricePolicyCore(GoodsId, Price); GoodsBasicPriceCore goodsBasicPriceCore = new GoodsBasicPriceCore(GoodsId, Price); GoodsChangeCore goodsChangeCore = new GoodsChangeCore(GoodsId, 2, textBox_GoodsAdminAccount.Text); bns.AddGoodsCore(ref retCode, goodsCore); bns.AddGoodsSaleLimitCore(ref retCode, goodsSaleLimitCore); bns.AddGoodsCategoryCore(ref retCode, goodsCategoryCore); bns.AddGoodsDisplayCore(ref retCode, goodsDisplayCore); bns.AddGoodsSalePricePolicyCore(ref retCode, goodsSalePricePolicyCore); bns.AddGoodsBasicPriceCore(ref retCode, goodsBasicPriceCore); bns.AddGoodsChangeCore(ref retCode, goodsChangeCore); //添加项目 foreach (ListViewItem item in listView_Items.Items) { int.TryParse(item.SubItems[0].Text, out int ItemId); int.TryParse(item.SubItems[2].Text, out int GameItemId); int.TryParse(item.SubItems[3].Text, out int ItemQuantity); string ItemName = item.SubItems[4].Text; string ItemDescription = item.SubItems[5].Text; string ItemAdminAccount = item.SubItems[2].Text; ItemCore itemCore = new ItemCore(ItemId, GameItemId, ItemName, ItemAdminAccount, ItemDescription); GameItemCore gameItemCore = new GameItemCore(ItemId, GameItemId); ItemDisplayCore itemDisplayCore = new ItemDisplayCore(ItemId, GameItemId, ItemName, ItemDescription); GoodsItemCore goodsItemCore = new GoodsItemCore(GoodsId, ItemId, GameItemId, ItemQuantity); GoodsItemBasicPriceCore goodsItemBasicPriceCore = new GoodsItemBasicPriceCore(GoodsId, ItemId, Price); bns.AddItemCore(ref retCode, itemCore); bns.AddGameItemCore(ref retCode, gameItemCore); bns.AddItemDisplayCore(ref retCode, itemDisplayCore); bns.AddGoodsItemCore(ref retCode, goodsItemCore); bns.AddGoodsItemBasicPriceCore(ref retCode, goodsItemBasicPriceCore); } MessageBox.Show("商品添加成功", "提示"); } catch (Exception ex) { MessageBox.Show(ex.Message, "提示"); } }