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

            ProductClass newProduct1 = new ProductClass("Computer", 6199, 20);
            ProductClass newProduct2 = new ProductClass("Phone", 4688, 30);

            productList.Add(newProduct1);
            productList.Add(newProduct2);
        }
コード例 #2
0
        public IdentifyUserForm()
        {
            InitializeComponent();

            ProductClass newProduct1 = new ProductClass("Computer", 6199, 20);
            ProductClass newProduct2 = new ProductClass("Phone", 4688, 30);

            productList.Add(newProduct1);
            productList.Add(newProduct2);
        }
コード例 #3
0
        public ModifyProductForm(List <ProductClass> productList)
        {
            InitializeComponent();
            this.productList = productList;

            for (int counter = 0; counter < productList.Count; counter++)
            {
                String       productInformation = "";
                ProductClass product            = productList[counter];
                productInformation += product.getProductName();
                ProductItemsComboBox.Items.Add(productInformation); //初始化用户可修改的商品信息,以供用户选择
            }
        }
コード例 #4
0
ファイル: ProductForm.cs プロジェクト: puliuyinyi/learngit
        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;
        }
コード例 #5
0
ファイル: ProductForm.cs プロジェクト: puliuyinyi/learngit
        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;
        }
コード例 #6
0
ファイル: AddProductForm.cs プロジェクト: puliuyinyi/learngit
        private void addCompletedButton_Click(object sender, EventArgs e)
        {
            ProductClass 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 ProductClass(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();
        }
コード例 #7
0
ファイル: ShoppingForm.cs プロジェクト: puliuyinyi/learngit
        public ShoppingForm(List <ProductClass> productList)
        {
            InitializeComponent();

            this.productList = productList;

            /*为1个查询商品框和5个购买商品可选框添加已有商品,以备用户选择购买*/
            for (int counter = 0; counter < productList.Count; counter++)
            {
                String       productInformation = "";
                ProductClass product            = productList[counter];
                productInformation += String.Format("name:{0,-10}", product.getProductName());

                productListTextBox.Text += productInformation;

                QueryProductsInformationComboBox.Items.Add(productInformation);

                productComboBox1.Items.Add(productInformation);
                productComboBox2.Items.Add(productInformation);
                productComboBox3.Items.Add(productInformation);
                productComboBox4.Items.Add(productInformation);
                productComboBox5.Items.Add(productInformation);
            }
        }
コード例 #8
0
ファイル: AddProductForm.cs プロジェクト: puliuyinyi/learngit
        private void addCompletedButton_Click(object sender, EventArgs e)
        {
            ProductClass 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 ProductClass(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();
        }
コード例 #9
0
ファイル: ShoppingForm.cs プロジェクト: puliuyinyi/learngit
        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);
            }
        }