본문 바로가기
C#

C# 랜덤함수 적응하기 - 문화상품권 번호 추출하기

by 아스키의 공부방 2012. 12. 23.
728x90
반응형

 

 

 

이는 실제 문화상품권 코드가 아닌 문화상품권 핀코드의

형태만 따라한것입니다.

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 윈폼
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Random rnd = new Random();
        int temp;

        private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Text = Convert.ToString(rnd.Next(0001, 9999));
            textBox2.Text = Convert.ToString(rnd.Next(0001, 9999));
            textBox3.Text = Convert.ToString(rnd.Next(0001, 9999));
            textBox4.Text = Convert.ToString(rnd.Next(0001, 999999));

            if (Convert.ToInt32(textBox1.Text) <= 9)
            {
                temp = Convert.ToInt32(textBox1.Text);
                textBox1.Text = "000" + temp;
            }
            else if (Convert.ToInt32(textBox1.Text) >= 10 && Convert.ToInt32(textBox1.Text) <= 99)
            {
                temp = Convert.ToInt32(textBox1.Text);
                textBox1.Text = "00" + temp;
            }
            else if (Convert.ToInt32(textBox1.Text) >= 100 && Convert.ToInt32(textBox1.Text) <= 999)
            {
                temp = Convert.ToInt32(textBox1.Text);
                textBox1.Text = "0" + temp;
            }

            if (Convert.ToInt32(textBox2.Text) <= 9)
            {
                temp = Convert.ToInt32(textBox2.Text);
                textBox2.Text = "000" + temp;
            }
            else if (Convert.ToInt32(textBox2.Text) >= 10 && Convert.ToInt32(textBox2.Text) <= 99)
            {
                temp = Convert.ToInt32(textBox2.Text);
                textBox2.Text = "00" + temp;
            }
            else if (Convert.ToInt32(textBox2.Text) >= 100 && Convert.ToInt32(textBox2.Text) <= 999)
            {
                temp = Convert.ToInt32(textBox2.Text);
                textBox2.Text = "0" + temp;
            }

            if (Convert.ToInt32(textBox3.Text) <= 9)
            {
                temp = Convert.ToInt32(textBox3.Text);
                textBox3.Text = "000" + temp;
            }
            else if (Convert.ToInt32(textBox3.Text) >= 10 && Convert.ToInt32(textBox3.Text) <= 99)
            {
                temp = Convert.ToInt32(textBox3.Text);
                textBox3.Text = "00" + temp;
            }
            else if (Convert.ToInt32(textBox3.Text) >= 100 && Convert.ToInt32(textBox3.Text) <= 999)
            {
                temp = Convert.ToInt32(textBox3.Text);
                textBox3.Text = "0" + temp;
            }

            if (Convert.ToInt32(textBox4.Text) <= 9)
            {
                temp = Convert.ToInt32(textBox4.Text);
                textBox4.Text = "00000" + temp;
            }
            else if (Convert.ToInt32(textBox4.Text) >= 10 && Convert.ToInt32(textBox4.Text) <= 99)
            {
                temp = Convert.ToInt32(textBox4.Text);
                textBox4.Text = "0000" + temp;
            }
            else if (Convert.ToInt32(textBox4.Text) >= 100 && Convert.ToInt32(textBox4.Text) <= 999)
            {
                temp = Convert.ToInt32(textBox4.Text);
                textBox4.Text = "000" + temp;
            }
            else if (Convert.ToInt32(textBox4.Text) >= 1000 && Convert.ToInt32(textBox4.Text) <= 9999)
            {
                temp = Convert.ToInt32(textBox4.Text);
                textBox4.Text = "00" + temp;
            }
            else if (Convert.ToInt32(textBox4.Text) >= 10000 && Convert.ToInt32(textBox4.Text) <= 99999)
            {
                temp = Convert.ToInt32(textBox4.Text);
                textBox4.Text = "0" + temp;
            }
        }
    }
}

윈폼.exe

 

윈폼.zip

728x90
반응형

'C#' 카테고리의 다른 글

C# 각종 프로그램 실행시키기  (0) 2012.12.24
C# 시스템 종료하기  (0) 2012.12.24
C# 로또 번호 추첨기  (0) 2012.12.22
C# 오른쪽마우스 클릭시 메뉴 띄우기  (0) 2012.12.13
C# 메세지박스 띄우기  (0) 2012.12.13