==> 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 Frm입력());
        }
    }
}



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



==> Weight.cs


using System;

public class Weight
{
    public int 반 { get; set; }
    public int 번호 { get; set; }
    public int 몸무게 { get; set; }
    public Weight(int 반, int 번호, int 몸무게)
    {
        this.반 = 반; this.번호 = 번호; this.몸무게 = 몸무게;
    }
}



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



==> Frm입력.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 Frm입력 : Form
    {
        public Frm입력()
        {
            InitializeComponent();
            lst = new List<Weight>();
        }

        private List<Weight> lst;
        private void btn입력_Click(object sender, EventArgs e)
        {
            lst.Add(new Weight(Convert.ToInt32(txt반.Text)
                , Convert.ToInt32(txt번호.Text)
                , Convert.ToInt32(txt몸무게.Text)));
            // 텍스트박스 클리어
            txt반.Text = "";
            txt번호.Text = String.Empty;
            txt몸무게.Clear();
        }

        private void btn출력_Click(object sender, EventArgs e)
        {
            Frm출력 f = new Frm출력(lst);
            f.Show();       // 출력 창 띄우고,
            this.Hide();    // 현재 폼 숨기고
        }
    }
}



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



==> Frm출력.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 Frm출력 : Form
    {
        public Frm출력()
        {
            InitializeComponent();
        }

        private List<Weight> lst;
        public Frm출력(List<Weight> lst)
        {
            InitializeComponent(); // 폼 초기화
            this.lst = lst;
        }

        private void Frm출력_Load(object sender, EventArgs e)
        {
            this.ctlPrint.DataSource = lst; // 출력(알아서)
        }
    }
}



< 실행결과 >


==> 입력 폼






==> 출력 폼



Posted by holland14
:


==> Program.cs


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

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



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


==> MainForm.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 MyWinForms
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void 끝내기ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 현재 프로그램 종료
            Application.Exit();
        }

        private void miAbout_Click(object sender, EventArgs e)
        {
            // 모달 폼 : 현재 창을 닫아야지만, 메인으로 이동 가능
            FrmAbout fa = new FrmAbout();
            fa.ShowDialog();
        }

        private void miButton_Click(object sender, EventArgs e)
        {
            // 모달리스 폼 : 독립적인 하나의 폼
            MyWinForms.Controls.FrmButton fb = new MyWinForms.Controls.FrmButton();
            fb.MdiParent = this; // MDI 컨테이너를 현재 폼(메인)으로 설정
            fb.Show();
        }

        private void mnuHelp_Load(object sender, EventArgs e)
        {

        }

        #region 컨텍스트메뉴
        private void cmsAbout_Click(object sender, EventArgs e)
        {
            //FrmAbout fa = new FrmAbout();
            //fa.ShowDailog();
            miAbout_Click(null, null); // 재 사용
        }

        private void cmsExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion
    }
}


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


==> FrmAbout.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 MyWinForms
{
    public partial class FrmAbout : Form
    {
        public FrmAbout()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            // 현재 폼 닫기
            this.Close();
        }

        private void lblTitle_Click(object sender, EventArgs e)
        {

        }
    }
}


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


==> FrmButton.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 MyWinForms.Controls
{
    public partial class FrmButton : Form
    {
        public FrmButton()
        {
            InitializeComponent();
        }
    }
}



< 실행결과 >




==> 모달 폼


==> 모달리스 폼


 ==> 컨텍스트메뉴

Posted by holland14
:


==> Program.cs


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

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


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


==> 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 HelloWorld
{
    public partial class HelloWorld : Form
    {
        public HelloWorld()
        {
            InitializeComponent();
        }

        private void btnClick_Click(object sender, EventArgs e)
        {
            MessageBox.Show("안녕하세요. 윈폼");
        }
    }
}


< 실행결과 >



Posted by holland14
:

using System;
using System.Linq;
using System.Collections.Generic;

public class Product
{
    public string Name { get; set; }
    public int Quantity { get; set; }
}

public class ProName
{
    public string ModelName { get; set; }
}

public class 프로젝션
{
    public static void Main()
    {
        int[] data = {3, 4, 5, 2, 1};
        var query = from d in data where d % 2 == 0 select d; // 결과유추
        IEnumerable<int> q = from d in data where d % 2 == 0 select d; // 기본
        int[] even = (from d in data where d % 2 == 0 select d).ToArray(); // 배열형로 뽑아냄
        List<int> lst = (from d in data where d % 2 == 0 select d).ToList(); // 리스트로 뽑아냄

        Product[] products = {
                                 new Product{Name="닷넷", Quantity=1000},
                                 new Product{Name="자바", Quantity=10}
                             };
        //var pro = from p in products select p; //[1]
        IEnumerable<ProName> pro = from p in products
                                   select new ProName { ModelName = p.Name }; //[2] 다른 클래스의 프로퍼티로 변환시켜 출력
       
        foreach (var item in pro)
     {
      Console.WriteLine("{0}", item.ModelName); // 다른 개체형으로 변환
     }
    }
}


 

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

C# 단어 및 수업 내용 복습(정리) ==> 테스트 관련  (0) 2009.08.26
105. 파일처리  (0) 2009.08.24
(테스트) 체중 관리 프로그램  (0) 2009.08.20
89. LINQ - 그룹알고리즘  (0) 2009.08.19
88. LINQ - 병합  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Collections.Generic;
using System.Linq;

public class KG
{
    public int Ban { get; set; }
    public int Num { get; set; }
    public int Kg { get; set; }
    public int banAvg { get; set; }
    public int SumBanKg { get; set; }
    public int BanAvg { get; set; }
    public int TotalKg { get; set; }
    public int TotalAvg { get; set; }

    public KG()
    {
        // Empty
    }
    public KG(int ban, int num, int kg)
    {
        this.Ban = ban;
        this.Num = num;
        this.Kg = kg;
    }
}

public class 체중관리프로그램
{
    public static void Main(string[] args)
    {
        int banTemp = 0;
        int numTemp = 0;
        int kgTemp = 0;

        List<KG> lst = new List<KG>();
        KG pi;

        Console.WriteLine("자료를 입력하세요.");
        do
        {
            pi = new KG();
            Console.Write("반 : _\b");
            banTemp = Convert.ToInt32(Console.ReadLine());              // 반정보 입력
            if (banTemp > 9)                                            // 반정보 9까지 인지 확인
            {
                Console.WriteLine("반은 1~9 사이의 값이여야 합니다.");      // Error
                return;
            }
            else
            {
                pi.Ban = banTemp;
            }

            Console.Write("번호 : __\b\b");
            numTemp = Convert.ToInt32(Console.ReadLine());              // 번호 입력
            if (numTemp > 10 || numTemp < 1)                            // 1~10 인지 확인
            {
                Console.WriteLine("번호는 1~10 사이의 값이여야 합니다.");    // Error
                return;
            }
            else
            {
                pi.Num = numTemp;
            }

            Console.Write("몸무게 : __\b\b");
            kgTemp = Convert.ToInt32(Console.ReadLine());               // 몸무게 입력
            if (kgTemp < 40 || kgTemp > 200)                            // 40 ~ 200 인지 확인
            {
                Console.WriteLine("몸무게는 40~200 사이의 값이여야 합니다."); // Error
                return;
            }
            else
            {
                pi.Kg = kgTemp;
            }
            lst.Add(pi);

        } while (lst.Count < 5);       // 최대 학생수 10명 확인

        IEnumerable<IGrouping<int, KG>> q = from p in lst group p by p.Ban;     // 반별로 그룹핑
        int countBan = q.Count();                                               // 반수 확인
        foreach (IGrouping<int, KG> g in q)                                     // 반별 출력
        {
            Console.WriteLine("\r\n" + g.Key + "반\t번호\t몸무게");
            foreach (KG k in g)
            {
                Console.WriteLine("{0}\t {1}\t {2}", k.Ban, k.Num, k.Kg);       // 개인 출력
            }
            IEnumerable<int> query = from p in lst where p.Ban == g.Key select p.Kg;    // 몸무게만 선택
            pi.SumBanKg = query.Sum();                                                  // 몸무게 합산
            pi.BanAvg = (int)((double)query.Sum() / (double)query.Count() + 0.5);       // 반평균 계산 (반올림)

            pi.TotalKg += pi.BanAvg;                                                    // 전체 합산

            Console.WriteLine(g.Key + "반 평균 :" + pi.BanAvg);                        // 반평균 출력
        }
        pi.TotalAvg = (int)(((double)pi.TotalKg / (double)countBan) + 0.5);             // 전체 평균 (반올림)
        Console.WriteLine("전체평균 : " + pi.TotalAvg);
    }
}


'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

105. 파일처리  (0) 2009.08.24
90. 프로젝션  (0) 2009.08.20
89. LINQ - 그룹알고리즘  (0) 2009.08.19
88. LINQ - 병합  (0) 2009.08.19
87. LINQ - 합계 카운트 평균  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;

namespace LINQ
{
    public class ProductInfo
    {
        public string Name { get; set; }
        public int Quantity { get; set; }
    }

    public class 그룹알고리즘
    {
        public static void Main()
        {
            //[1] Input
            List<ProductInfo> lst = new List<ProductInfo>()
            {
                new ProductInfo{Name="RADIO", Quantity=3},
                new ProductInfo{Name="TV", Quantity=1},
                new ProductInfo{Name="RADIO", Quantity=2},
                new ProductInfo{Name="DVD", Quantity=5}
            };

            //[2] Process
            IEnumerable<IGrouping<string, ProductInfo>> q =
                from p in lst group p by p.Name;

            //[3] Output
            foreach (IGrouping<string, ProductInfo> item in q)
            {
                Console.WriteLine("{0}", item.Key);
                foreach (ProductInfo pi in item)
                {
                    Console.WriteLine("상품:{0}, 판매량:{1}", pi.Name, pi.Quantity);
                }
            }
        }
    }
}

 

/*
Google에서 "LINQ 101" 로 검색하면
MSDN에 "101 LINQ Samples" 로 LINQ관련 문법 및 정보가 카테고리별로
정리되어 있으니 참고할 것!
*/

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

90. 프로젝션  (0) 2009.08.20
(테스트) 체중 관리 프로그램  (0) 2009.08.20
88. LINQ - 병합  (0) 2009.08.19
87. LINQ - 합계 카운트 평균  (0) 2009.08.19
86. 지연된 실행  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Linq;

public class 병합
{
    public static void Main()
    {
        int[] data1 = { 3, 5, 4 };
        int[] data2 = { 2, 1 };

        int[] result = (from o in data1 select o).Union(from t in data2 select t).OrderBy(x => x).ToArray();

        for (int i = 0; i < result.Length; i++)
        {
            Console.WriteLine("{0}", result[i]);
        }
    }
}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

(테스트) 체중 관리 프로그램  (0) 2009.08.20
89. LINQ - 그룹알고리즘  (0) 2009.08.19
87. LINQ - 합계 카운트 평균  (0) 2009.08.19
86. 지연된 실행  (0) 2009.08.19
85. 쿼리식반환값처리  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Linq;

public class 합계카운트평균
{
    public static void Main()
    {
        // Input
        int[] data = { 3, 5, 4, 2, 1 };

        // Process
        var q = from d in data
                where d % 2 == 0
                select d;

        int sum = q.Sum(); // 합계
        int cnt = q.Count(); // 카운트
        int avg = Convert.ToInt32(q.Average()); // 평균
        int max = (from d in data select d).Max(); // 최대값
        int min = (from d in data select d).OrderByDescending(p => p).Last(); // 최소값

        // Output
        Console.WriteLine("합계 : {0}\n카운트 : {1}\n평균 : {2}", sum, cnt, avg);
        Console.WriteLine("최대값 : {0}", max);
        Console.WriteLine("최소값 : {0}", min);
    }

}

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

89. LINQ - 그룹알고리즘  (0) 2009.08.19
88. LINQ - 병합  (0) 2009.08.19
86. 지연된 실행  (0) 2009.08.19
85. 쿼리식반환값처리  (0) 2009.08.19
84. 표준쿼리연산자  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Linq;

public class 지연된실행
{
    public static void Main()
    {
        int[] data = { 3, 5, 4, 2, 1 };

        var q =
            from d in data orderby d select d;  // q는 쿼리문을 담고 있는 그릇
        foreach (var item in q)
        {
            Console.WriteLine("{0}", item); // 1, 2, 3, 4, 5
        }

        // 중간에 데이터 변경
        data[0] = 1000; // 3 -> 1000으로 값이 바뀌었음

        foreach (var item in q) // 변경된 내용으로 다시 쿼리 실행. 지연된 실행
        {
            Console.WriteLine("{0}", item); // 1, 2, 4, 5, 1000
        }
      
    }

}

/*
q는 결과값을 가지고 있는게 아니라 쿼리식(from d in data orderby d select d;)을 가지고 있다.
*/

'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

88. LINQ - 병합  (0) 2009.08.19
87. LINQ - 합계 카운트 평균  (0) 2009.08.19
85. 쿼리식반환값처리  (0) 2009.08.19
84. 표준쿼리연산자  (0) 2009.08.19
83. 쿼리식  (0) 2009.08.19
Posted by holland14
:

using System;
using System.Collections.Generic;
using System.Linq;

public class 쿼리식반환값처리
{
    public static void Main()
    {
        int[] data = { 3, 5, 4, 2, 1 };

        //[!] Process
        IEnumerable<int> q = from d in data select d; // 기본
        var query = from d in data select d; // var
        int[] sorted = (from d in data orderby d select d).ToArray(); // 결과값을 배열형으로 변환
        for (int i = 0; i < sorted.Length; i++)
       {
           Console.WriteLine("{0}", sorted[i]);
       }

        List<int> lst = (from d in data orderby d descending select d).ToList();
        for (int i = 0; i < lst.Count; i++)
        {
            Console.WriteLine("{0}", lst[i]); // 컬렉션
        }
    }
}

/*
IEnumerable대신 var키워드를 쓸 수 있다.
*/


'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글

87. LINQ - 합계 카운트 평균  (0) 2009.08.19
86. 지연된 실행  (0) 2009.08.19
84. 표준쿼리연산자  (0) 2009.08.19
83. 쿼리식  (0) 2009.08.19
82. IEnumerable인터페이스  (0) 2009.08.19
Posted by holland14
: