コード例 #1
0
        public IdentifyUserForm()
        {
            InitializeComponent();

            Product product1 = new Product("Computer", 6199, 20);
            Product product2 = new Product("Phone", 4688, 30);

            productList.Add(product1);
            productList.Add(product2);
        }
コード例 #2
0
ファイル: AddProductForm.cs プロジェクト: puliuyinyi/learngit
        private void addCompletedButton_Click(object sender, EventArgs e)
        {
            Product product;

            String productName;
            float productPrice;
            int productStock;

            if (newProductNameTextBox.Text == "" || newProductPriceTextBox.Text == "" || newProductStockTextBox.Text == "")
                MessageBox.Show("You should input complete product information!");
            else
            {
                productName = newProductNameTextBox.Text;
                if (isPositiveNumber(newProductPriceTextBox.Text) == true)  //对用户输入的产品价格数据的合法性进行验证
                {
                    productPrice = Convert.ToSingle(newProductPriceTextBox.Text);

                    if (isPositiveInteger(newProductStockTextBox.Text) == true) //对用户输入的产品库存数据的合法性进行验证
                    {
                        productStock = Convert.ToInt32(newProductStockTextBox.Text);
                        product = new Product(productName, productPrice, productStock);
                        productList.Add(product);
                    }
                    else
                        MessageBox.Show("The stock is invalid !\r\t The stock must be positive interger!\r\t Please input again!");
                }
                else
                    MessageBox.Show("The productPrice is invalid!\r\tThe price can't be negative number or letters!The price should only have one point!!\r\tPlease input again!");

            }
            this.Close();
        }