示例#1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int quantity = Convert.ToInt32(TextBox1.Text);

            for (int i = 0; i < quantity; i++)
            {
                string lastSerialNumber = CashCard.retrieveLastCashCard();
                string lastCardSeries   = lastSerialNumber.Substring(0, 4);
                int    lastSeriesNumber = Convert.ToInt32(lastSerialNumber.Substring(4));

                string newCardSeries       = null;
                int    newCardSeriesNumber = 0;
                string newSerialNumber     = null;

                if (lastCardSeries == "ABCD")
                {
                    if (lastSeriesNumber != 99999999)
                    {
                        newCardSeries = "ABCD";
                        Random rand      = new Random((int)DateTime.Now.Ticks);
                        int    randomNum = rand.Next(1, 99);
                        newCardSeriesNumber = lastSeriesNumber + randomNum;
                        newSerialNumber     = newCardSeries.Substring(0, 2) + newCardSeriesNumber + newCardSeries.Substring(2);
                    }
                    else
                    {
                        newCardSeries = "CDEF";
                        Random rand      = new Random((int)DateTime.Now.Ticks);
                        int    randomNum = rand.Next(12345678, 99999999);
                        newCardSeriesNumber = randomNum;
                        newSerialNumber     = newCardSeries.Substring(0, 2) + newCardSeriesNumber + newCardSeries.Substring(2);
                    }
                }
                else if (lastCardSeries == "CDEF")
                {
                    newCardSeries = "CDEF";
                    Random rand      = new Random((int)DateTime.Now.Ticks);
                    int    randomNum = rand.Next(1, 99);
                    newCardSeriesNumber = lastSeriesNumber + randomNum;
                    newSerialNumber     = newCardSeries.Substring(0, 2) + newCardSeriesNumber + newCardSeries.Substring(2);
                }

                CashCard cc = new CashCard();
                string   newSecurityCode = cc.generateSecurityCode();
                int      cashValue       = Convert.ToInt32(DropDownList1.SelectedValue);

                cc.createCashCard(newSerialNumber, cc.generateSecurityCodeHash(newSecurityCode), cashValue);

                var row       = new TableRow();
                var countCell = new TableCell();
                countCell.Text = HttpUtility.HtmlEncode(Convert.ToString(i + 1));
                var serialNumCell = new TableCell();
                serialNumCell.Text = HttpUtility.HtmlEncode(newSerialNumber);
                var securityCodeCell = new TableCell();
                securityCodeCell.Text = HttpUtility.HtmlEncode(newSecurityCode);
                row.Controls.Add(countCell);
                row.Controls.Add(serialNumCell);
                row.Controls.Add(securityCodeCell);
                Table1.Controls.Add(row);

                Session["TableContent"] = Table1;
                da.adminCardLog(quantity, cashValue, userid);
            }
        }