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 AddGoodsCore(ref int retCode, GoodsCore goodsCore)//添加商品代码 { try { SqlCommand sqlCmd = new SqlCommand("GoodsDb.dbo.p_AddGoodsCore", sqlCnt) { //添加参数 CommandType = CommandType.StoredProcedure }; sqlCmd.Parameters.Add("@GoodsId", SqlDbType.Int).Value = goodsCore.GoodsId; sqlCmd.Parameters.Add("@GoodsName", SqlDbType.NVarChar).Value = goodsCore.GoodsName; sqlCmd.Parameters.Add("@GoodsAppGroupCode", SqlDbType.VarChar).Value = goodsCore.GoodsAppGroupCode; sqlCmd.Parameters.Add("@GoodsType", SqlDbType.SmallInt).Value = goodsCore.GoodsType; sqlCmd.Parameters.Add("@DeliveryType", SqlDbType.SmallInt).Value = goodsCore.DeliveryType; sqlCmd.Parameters.Add("@SaleStatus", SqlDbType.SmallInt).Value = goodsCore.SaleStatus; sqlCmd.Parameters.Add("@EffectiveFrom", SqlDbType.DateTimeOffset).Value = goodsCore.EffectiveFrom; sqlCmd.Parameters.Add("@EffectiveTo", SqlDbType.DateTimeOffset).Value = goodsCore.EffectiveTo; sqlCmd.Parameters.Add("@SaleableQuantity", SqlDbType.Int).Value = goodsCore.SaleableQuantity; sqlCmd.Parameters.Add("@RefundUnitCode", SqlDbType.SmallInt).Value = goodsCore.RefundUnitCode; sqlCmd.Parameters.Add("@IsRefundable", SqlDbType.Bit).Value = goodsCore.IsRefundable; sqlCmd.Parameters.Add("@IsAvailableRecurringPayment", SqlDbType.Bit).Value = goodsCore.IsAvailableRecurringPayment; sqlCmd.Parameters.Add("@ChangerAdminAccount", SqlDbType.VarChar).Value = goodsCore.ChangerAdminAccount; sqlCmd.Parameters.Add("@GoodsDescription", SqlDbType.NVarChar).Value = goodsCore.GoodsDescription; sqlCmd.Parameters.Add("@GoodsData", SqlDbType.VarChar).Value = goodsCore.GoodsData; sqlCmd.Parameters.Add("@ParentGoodsId", SqlDbType.Int).Value = DBNull.Value; sqlCmd.Parameters.Add("@GoodsPurchaseType", SqlDbType.SmallInt).Value = goodsCore.GoodsPurchaseType; sqlCmd.Parameters.Add("@GoodsPurchaseCheckMask", SqlDbType.Int).Value = goodsCore.GoodsPurchaseCheckMask; //添加返回值 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 buttonOk_Click(object sender, EventArgs e) { bool isOK = true; double weight = 0; double price = 0; if (string.IsNullOrEmpty(textBoxName.Text) || string.IsNullOrEmpty(textBoxPrice.Text) || string.IsNullOrEmpty(textBoxWeight.Text)) { isOK = false; ErrorsViewWrapper.ShowError(ErrorTexts.ENTER_ALL_FIELDS); } if (isOK) { try { weight = Convert.ToDouble(textBoxWeight.Text); } catch { isOK = false; ErrorsViewWrapper.ShowError(ErrorTexts.INCORRECT_WEIGHT); } } if (isOK) { try { price = Convert.ToDouble(textBoxPrice.Text); } catch { isOK = false; ErrorsViewWrapper.ShowError(ErrorTexts.INCORRECT_PRICE); } } if (isOK) { if (isEdit) { GoodsCore.EditGood(goodID, textBoxName.Text, GoodsCategoriesCore.GoodsCategories.GetID(comboBoxCategory.SelectedItem.ToString()), weight, price, comboBoxVisble.SelectedItem.ToString() == GeneralConstants.YES ? 1 : 0); GoodsCore.GetGoods(); AdminForm.instance.UpdateDataGridViewGoods(); for (int i = 0; i < dataGridViewConsumbles.Rows.Count; i++) { DataGridViewCellCollection collection = dataGridViewConsumbles.Rows[i].Cells; if (collection[0].Value.ToString() == "") { GoodConsumlesCore.AddGoodConsumle(goodID, ConsumblesCore.Consumbles.GetID(collection[1].Value.ToString()), Convert.ToDouble(collection[2].Value)); } } this.Close(); } else { Good good = GoodsCore.AddGood(textBoxName.Text, GoodsCategoriesCore.GoodsCategories.GetID(comboBoxCategory.SelectedValue.ToString()), Convert.ToDouble(textBoxWeight.Text), Convert.ToDouble(textBoxPrice.Text), comboBoxVisble.SelectedItem.ToString() == GeneralConstants.YES ? 1 : 0); for (int i = 0; i < dataGridViewConsumbles.Rows.Count; i++) { DataGridViewCellCollection collection = dataGridViewConsumbles.Rows[i].Cells; GoodConsumlesCore.AddGoodConsumle(good.id, ConsumblesCore.Consumbles.GetID(collection[1].Value.ToString()), Convert.ToDouble(collection[2].Value)); } GoodsCore.GetGoods(); AdminForm.instance.AddGoodToGrid(good); this.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, "提示"); } }