예제 #1
0
        private void BtnQuantityEnter_Click(object sender, EventArgs e)
        {
            if (txtQuantity.Text == "")
            {
                MessageBox.Show("Quantity can not be empty."); return;
            }
            if (txtRetailValue.Text == "")
            {
                MessageBox.Show("Retail Value can not be empty"); return;
            }

            int quantity;

            if (!int.TryParse(txtQuantity.Text, out quantity))
            {
                MessageBox.Show("Quantity not a number."); return;
            }
            int retailValue;

            if (!int.TryParse(txtRetailValue.Text, out retailValue))
            {
                MessageBox.Show("Retail Value not a number."); return;
            }


            if (quantity < 0)
            {
                MessageBox.Show("Quantity can not be negative");
                return;
            }
            if (retailValue < 0)
            {
                MessageBox.Show("RetailValue can not be negative"); return;
            }


            if (quantity == 0)
            {
                MessageBox.Show("Quantity can not be Zero"); return;
            }
            if (retailValue == 0)
            {
                MessageBox.Show("RetailValue can not be Zero"); return;
            }



            PointCardDataBaseControl.retailValue = retailValue;

            if (retailValue >= 200)
            {
                PointCardDataBaseControl.goldCoins            = 800;
                PointCardDataBaseControl.remainLuckyDrawTimes = 2;
            }
            else if (retailValue >= 100)
            {
                PointCardDataBaseControl.goldCoins            = 350;
                PointCardDataBaseControl.remainLuckyDrawTimes = 1;
            }
            else
            {
                PointCardDataBaseControl.goldCoins            = 150;
                PointCardDataBaseControl.remainLuckyDrawTimes = 0;
            }

            PointCardDataBaseControl.status         = "Inactive";
            PointCardDataBaseControl.generationDate = DateTime.Now.ToString("dd/MM/yyyy");

            for (int i = 0; i < quantity; i++)
            {
                PointCardDataBaseControl.pointCardID = "V" + (SystemDataBaseControl.Get_PointCardNum() + 1 + i).ToString().PadLeft(7, '0');
                PointCardDataBaseControl.activePwd   = CreatePassword(8);
                PointCardDataBaseControl.Insert();
            }

            MessageBox.Show("Point Cards create success.");

            txtQuantity.Text    = "";
            txtRetailValue.Text = "";

            MessageBox.Show("The Range of Point Card ID is " + "V" + (SystemDataBaseControl.Get_PointCardNum() + 1).ToString().PadLeft(7, '0') +
                            " to " + "V" + (SystemDataBaseControl.Get_PointCardNum() + quantity).ToString().PadLeft(7, '0'));

            SystemDataBaseControl.Updata_PointCardNum(SystemDataBaseControl.Get_PointCardNum() + quantity);
        }