==> Program.cs



using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace 급여처리프로그램
{
    static class Program
    {
        /// <summary>
        /// 해당 응용 프로그램의 주 진입점입니다.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}



==============================================================================================



==> Money.cs



using System;

namespace 급여처리프로그램
{
    // 엔터티 클래스
    public class Money
    {
        public int 사번 { get; set; }
        public int 급 { get; set; }
        public int 호 { get; set; }
        public int 수당 { get; set; }
        public int 지급액 { get; set; }
        public int 세금 { get; set; }
        public int 차인지급액 { get; set; }
    }
}



==============================================================================================



==> Form1.cs



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();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        List<Money> money = new List<Money>(); // DB
        private bool IsOnlyNum(int 사번) {
            bool result = false;
            for (int i = 0; i < money.Count; i++) {
                if (money[i].사번 == 사번) {
                    result = true;
                }
            }
            return result;
        }
        private void btn입력_Click(object sender, EventArgs e) {
            Money m = new Money();
            if (!Char.IsDigit(txt사번.Text, 0))
            {
                MessageBox.Show("사번은 정수라니까???"); return;
            }
            // 중복 제거
            if (!IsOnlyNum(Convert.ToInt32(txt사번.Text))) {
                m.사번 = Convert.ToInt32(txt사번.Text); 
            }
            else {
                MessageBox.Show("이미 있는 사원입니다.");
                txt사번.Focus(); txt사번.Select();
                return;
            }

            m.급 = Convert.ToInt32(cbo급.Items[
                cbo급.SelectedIndex].ToString().Substring(0, 1));
            m.호 = Convert.ToInt32(com호.Items[
                com호.SelectedIndex].ToString().Substring(0, 1));
            m.수당 = Convert.ToInt32(txt수당.Text);

            money.Add(m); // 하나씩 추가

            ClearText();
            this.txt사번.Focus();
        }

        private void ClearText()
        {
            txt사번.Text = txt수당.Text = "";
            cbo급.SelectedIndex = 0;
            com호.SelectedIndex = 0;
        }

        private void cmd출력_Click(object sender, EventArgs e)
        {
            // Process
            ProcessData();

            // Sort
            IEnumerable<Money> q = (from m in money
                                   orderby m.사번
                                   select m).ToList();

            // 입력 데이터 출력
            this.dgvPrint.DataSource = q;
        }

        private void ProcessData()
        {
            for (int i = 0; i < money.Count; i++)
            {
                // 지급액 : 급 호봉 계산표
                money[i].지급액 =
                    Calc지급액(money[i].급, money[i].호) + money[i].수당;
                // 세금
                money[i].세금 = Calc세금(money[i].지급액);
                // 차인지급액
                money[i].차인지급액 = money[i].지급액 - money[i].세금;
            }
        }

        private int Calc세금(int 지급액)
        {
            int tax = 0;

            if (지급액 < 70000)
            {
                tax = (지급액 * 0) - 0;
            }
            else if (지급액 < 80000)
            {
                tax = Convert.ToInt32(지급액 * 0.005) - 300;
            }
            else if (지급액 < 90000)
            {
                tax = Convert.ToInt32(지급액 * 0.007) - 500;
            }
            else
            {
                tax = Convert.ToInt32(지급액 * 0.012) - 1000;
            }

            return tax;
        }
        private int Calc지급액(int 급, int 호)
        {
            int result = 0;
            if (급 == 1)
            {
                switch (호)
                {
                    case 1: result = 95000; break;
                    case 2: result = 92000; break;
                    case 3: result = 89000; break;
                    case 4: result = 86000; break;
                    case 5: result = 83000; break;
                    default:
                        break;
                }
            }
            else
            {
                switch (호)
                {
                    case 1: result = 80000; break;
                    case 2: result = 75000; break;
                    case 3: result = 70000; break;
                    case 4: result = 65000; break;
                    case 5: result = 60000; break;
                    default:
                        break;
                }
            }
            return result;
        }
    }
}





< 실행결과 >




--> '사원번호', '급', '호', '수당'은 입력으로 받고 '지급액', '세금', '차인지급액' 부분은 출력하면 나온다.




--> '사원번호', '급', '호', '수당'을 아래와 같이 입력한 후 출력버튼을 누른 후 화면




--> 출력 버튼을 누른 후 화면 ('지급액', '세금', '차인지급액' 부분이 출력되었다. 입력한 '사원번호', '급', '호', '수당' 도 함께 나온다.)



Posted by holland14
: