C# 랜덤함수 적응하기 - 문화상품권 번호 추출하기
이는 실제 문화상품권 코드가 아닌 문화상품권 핀코드의
형태만 따라한것입니다.
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;
}
}
}
}