private void ProductForm_Load(object sender, EventArgs e) { String productInformation = ""; for (int counter = 0; counter < productList.Count; counter++) { ProductClass product = productList[counter]; productInformation += String.Format("{0,-13} {1,13:C} {2}", product.getProductName(), product.getProductPrice(), product.getProductStock()); productInformation += "\r\n"; } ProductInformationTextBox.Text = productInformation; }
public ProductForm(List <ProductClass> productList) { InitializeComponent(); this.productList = productList; String productInformation = ""; for (int counter = 0; counter < productList.Count; counter++) { ProductClass product = productList[counter]; productInformation += String.Format("{0,-13} {1,13:C} {2}", product.getProductName(), product.getProductPrice(), product.getProductStock()); productInformation += "\r\n"; } ProductInformationTextBox.Text = productInformation; }
private void CheckOutButton_Click(object sender, EventArgs e) { if (productComboBox1.SelectedIndex != -1) { if (QuantityTextBox1.Text == "") { MessageBox.Show("You have chosen a product bot not filling the quantity,please input the quantity"); } else { int quantity; String quantityString = QuantityTextBox1.Text; if (isPositiveInteger(quantityString) == true) //对用户输入的购买商品数量的数据的合法性检验 { quantity = Convert.ToInt32(quantityString); if (quantity > productList[productComboBox1.SelectedIndex].getProductStock()) //判断用户输入购买数量是否已经超过购买商品的库存量 { MessageBox.Show("the quantity(in the QuantityTextBox1) has over the products's stock! please input again!"); } else { /*更新库存*/ productList[productComboBox1.SelectedIndex].setProductStock(productList[productComboBox1.SelectedIndex].getProductStock() - quantity); float unitPrice = productList[productComboBox1.SelectedIndex].getProductPrice(); totalMoney += unitPrice * quantity; //计算当前用户购买商品的总价 } } else { MessageBox.Show("the data is invalid!\r\tthe quantity(in the textBox1) must be positive integer!\r\tplease input again!"); } } } if (productComboBox2.SelectedIndex != -1) { if (QuantityTextBox2.Text == "") { MessageBox.Show("You have chosen a product bot not filling the quantity,please input the quantity"); } else { int quantity; String quantityString = QuantityTextBox2.Text; if (isPositiveInteger(quantityString) == true)//对用户输入的购买商品数量的数据的合法性检验 { quantity = Convert.ToInt32(quantityString); if (quantity > productList[productComboBox2.SelectedIndex].getProductStock())//判断用户输入购买数量是否已经超过购买商品的库存量 { MessageBox.Show("the quantity(in the QuantityTextBox2) has over the products's stock! please input again!"); } else { /*更新库存*/ productList[productComboBox2.SelectedIndex].setProductStock(productList[productComboBox2.SelectedIndex].getProductStock() - quantity); float unitPrice = productList[productComboBox2.SelectedIndex].getProductPrice(); totalMoney += unitPrice * quantity;//计算当前用户购买商品的总价 } } else { MessageBox.Show("the data is invalid!\r\tthe quantity(in the textBox2) must be positive integer!\r\tplease input again!"); } } } if (productComboBox3.SelectedIndex != -1) { if (QuantityTextBox3.Text == "") { MessageBox.Show("You have chosen a product bot not filling the quantity,please input the quantity"); } else { int quantity; String quantityString = QuantityTextBox3.Text; if (isPositiveInteger(quantityString) == true)//对用户输入的购买商品数量的数据的合法性检验 { quantity = Convert.ToInt32(quantityString); if (quantity > productList[productComboBox3.SelectedIndex].getProductStock())//判断用户输入购买数量是否已经超过购买商品的库存量 { MessageBox.Show("the quantity(in the QuantityTextBox3) has over the products's stock! please input again!"); } else { /*更新库存*/ productList[productComboBox3.SelectedIndex].setProductStock(productList[productComboBox3.SelectedIndex].getProductStock() - quantity); float unitPrice = productList[productComboBox3.SelectedIndex].getProductPrice(); totalMoney += unitPrice * quantity;//计算当前用户购买商品的总价 } } else { MessageBox.Show("the data is invalid!\r\tthe quantity(in the textBox3) must be positive integer!\r\tplease input again!"); } } } if (productComboBox4.SelectedIndex != -1) { if (QuantityTextBox4.Text == "") { MessageBox.Show("You have chosen a product bot not filling the quantity,please input the quantity"); } else { int quantity; String quantityString = QuantityTextBox4.Text; if (isPositiveInteger(quantityString) == true)//对用户输入的购买商品数量的数据的合法性检验 { quantity = Convert.ToInt32(quantityString); if (quantity > productList[productComboBox4.SelectedIndex].getProductStock())//判断用户输入购买数量是否已经超过购买商品的库存量 { MessageBox.Show("the quantity(in the QuantityTextBox4) has over the products's stock! please input again!"); } else { /*更新库存*/ productList[productComboBox4.SelectedIndex].setProductStock(productList[productComboBox4.SelectedIndex].getProductStock() - quantity); float unitPrice = productList[productComboBox4.SelectedIndex].getProductPrice(); totalMoney += unitPrice * quantity;//计算当前用户购买商品的总价 } } else { MessageBox.Show("the data is invalid!\r\tthe quantity(in the textBox4) must be positive integer!\r\tplease input again!"); } } } if (productComboBox5.SelectedIndex != -1) { if (QuantityTextBox5.Text == "") { MessageBox.Show("You have chosen a product bot not filling the quantity,please input the quantity"); } else { int quantity; String quantityString = QuantityTextBox5.Text; if (isPositiveInteger(quantityString) == true) //对用户输入的购买商品数量的数据的合法性检验 { quantity = Convert.ToInt32(quantityString); if (quantity > productList[productComboBox5.SelectedIndex].getProductStock()) //判断用户输入购买数量是否已经超过购买商品的库存量 { MessageBox.Show("the quantity(in the QuantityTextBox5) has over the products's stock! please input again!"); } else { /*更新库存*/ productList[productComboBox5.SelectedIndex].setProductStock(productList[productComboBox5.SelectedIndex].getProductStock() - quantity); float unitPrice = productList[productComboBox5.SelectedIndex].getProductPrice(); totalMoney += unitPrice * quantity; //计算当前用户购买商品的总价 } } else { MessageBox.Show("the data is invalid!\r\tthe quantity(in the textBox5) must be positive integer!\r\tplease input again!"); } } } CheckOutTextBox.Text = String.Format("the total money is :\r\n {0,35:C}", totalMoney); //显示当前用户购买商品的总价 /*初始化更新相关商品库存后的商品信息,用户可以在newProductInformationComboBox中选择查看商品信息*/ newProductInformationComboBox.Items.Clear(); for (int counter = 0; counter < productList.Count; counter++) { String productInformation = ""; ProductClass product = productList[counter]; productInformation += String.Format("name:{0,-10}price:{1,6:C} stock:{2} ", product.getProductName(), product.getProductPrice(), product.getProductStock()); newProductInformationComboBox.Items.Add(productInformation); } }