레이블이 C#학원인 게시물을 표시합니다. 모든 게시물 표시
레이블이 C#학원인 게시물을 표시합니다. 모든 게시물 표시

2022년 2월 19일 토요일

C# 동영상, 윈폼, HelloWorld 콘솔프로그램에서 윈폼, 윈도우 띄우기

 C# 동영상, 윈폼, HelloWorld  콘솔프로그램에서 윈폼, 윈도우 띄우기

http://ojc.asia/bbs/board.php?bo_table=LecCsharp&wr_id=422 


C# 동영상, 윈폼, HelloWorld 콘솔프로그램에서 윈폼, 윈도우 띄우기

C# 동영상, 윈폼, HelloWorld 콘솔프로그램에서 윈폼, 윈도우 띄우기윈폼, HelloWorld콘솔프로그램에서 윈폼 띄우기VS 2022C# 윈폼(Application 클래스)C#.NET 프레임워크에서는 간단히 윈도우를 만들 수 있도

ojc.asia






윈폼, HelloWorld

콘솔프로그램에서 윈폼 띄우기


VS 2022






C# 윈폼(Application 클래스)


C#.NET 프레임워크에서는 간단히 윈도우를 만들 수 있도록 Winform 클래스 라이브러리를 제공하며 다음과 같은 방법으로 윈도우를 생성한다. 


  • System.Windows.Forms.Form 클래스에서 파생된 윈도우폼 클래스 선언
  • 위에서 만든 클래스의 인스턴스를 System.Windows.Forms.Application.Run( Form을 상속받은 클래스의 객체 ) 메소드에 매개변수로 넘겨 호출하면서 윈폼 응용 프로그램을 시작한다.


Application 클래스의 기능은 윈도우 응용프로그램을 시작하고 종료시키고, 윈도우 메시지를 처리하는 일을 한다.


응용프로그램의 시작은 Application.Run(), 응용프로그램의 종료는 Application.Exit()인데 Exit() 메소드가 호출되었다고 바로 종료되는 것은 아니다. 이 메소드가 하는 일은 응용프로그램의 모든 윈도우를 닫은 후 Run() 메소드가 Return되도록 하는 것이므로 Run() 메소드 뒷부분에 프로그램이 종료되면서 할 일이 있다면 해당 코드를 기술하면 된다.


[별도 이벤트처리 메소드를 만들고 델리게이트의 인자로]


콘솔 프로젝트에서 System.Windows.Forms를 참조 추가해야 한다.


using System;

using System.Windows.Forms;


class Program : Form

    {

        static void Main(string[] args)

        {

            Program form = new Program();

            form.Click += new EventHandler(form.Form_Click);

            Console.WriteLine("윈도우 시작...");

            Application.Run(form);

            Console.WriteLine("윈도우 종료...");

        }


        void Form_Click(object sender, EventArgs e)

        {

            Console.WriteLine("폼클릭 이벤트...");

            Application.Exit();

        }

    }



[람다식을 이용한 무명함수로 이벤트 처리]


using System;

using System.Windows.Forms;


namespace ConsoleApplication9

{

    class Program : Form    {

        static void Main(string[] args)        {

            Program form = new Program();

            form.Click += new EventHandler(

                   (sender, eventArgs) =>

                   {

                      Console.WriteLine("폼클릭 이벤트...");

                      Application.Exit();

                   });

            Console.WriteLine("윈도우 시작...");

            Application.Run(form);

            Console.WriteLine("윈도우 종료...");            

        }

    }

}






#윈폼, #윈폼HelloWorld, #콘솔프로그램, #Application, #Winform, #Application.Run, #닷넷교육, #닷넷동영상, #시샵동영상, 윈폼, 윈폼HelloWorld, 콘솔프로그램, Application, Winform, Application.Run, 닷넷교육, 닷넷동영상, 시샵동영상, C#교육, C#학원

C# 동영상, 링크/링큐 Linq To DataSet, 데이터셋 기본쿼리, 내부조인/외부조인, C#학원, C#교육, C#동영상교육, C#학원교육

 C# 동영상, 링크/링큐 Linq To DataSet, 데이터셋 기본쿼리, 내부조인/외부조인,  C#학원, C#교육, C#동영상교육, C#학원교육


http://ojc.asia/bbs/board.php?bo_table=LecCsharp&wr_id=421 




LINQ

Linq To DataSet

 기본쿼리, 내부조인/외부조인






https://www.youtube.com/watch?v=7MkvvOXRQME&list=PLxU-iZCqT52DJyR6gqJy0MCL8RiTVXdos&index=26 

C# LINQ(LINQ TO DATASET)


https://www.youtube.com/watch?v=GqDWbAOjO4A&list=PLxU-iZCqT52DJyR6gqJy0MCL8RiTVXdos&index=22 

 

데이터셋(DataSet)은 클라이언트의 메모리에 존재하는 DataTable을 가지며 일반적으로 DataBase의 테이블 데이터를 DataAdapter를 통해 가지고 와서 서버와의 연결을 끊은 상태에서 데이터를 조작하기 의한 메모리 캐시같은 구조이며 개발자가 직접 DataSet 안에 DataTable을 만들고 마치 DB 테이블 데이터 처럼 데이터를 넣고 조작을 해도 된다.

 

DataSet은 메모리 상의  데이터베이스(DB)를 표현하고 DataTable은 하나의 테이블(Table)을 표현한다.


 

IEnumerable<T> 제네릭 인터페이스를 구현한 데이터 소스는 LINQ을 통해 쿼리할 수 있으므로 


DataSet의 DataTable에 대해 AsEnumerable을 호출하여  IEnumerable<T> 인터페이스를 구현한 개체가 반환되도록 하면 LINQ 쿼리식에서 이용할 수 있다.

 

LINQ to DataSet 쿼리 역시 쿼리 식 구문과 메소드 기반 쿼리 구문이라는 두 가지 구문 형식으로 만들 수 있다.

 

- 쿼리 식 구문

쿼리 식은 선언적 쿼리 구문으로 이 구문을 사용하면 C#에서 SQL에서와 비슷한 형식으로 쿼리를 작성할 수 있다.

 

- 메서드 기반 쿼리 구문

메소드 기반 쿼리 구문은 메소드 형태에 람다식을 매개 변수로 전달하는 방법이다.

 

using System.Data;

using System.Collections;

class LinqToDataSet

{

    static void Main()

    {

        //CUSTOMER DataTable생성

        DataTable customer_dt = new DataTable("customer");


        //컬럼4개 정의

        DataColumn col1 = new DataColumn();

        DataColumn col2 = new DataColumn();

        DataColumn col3 = new DataColumn();

        DataColumn col4 = new DataColumn();


        col1.DataType = System.Type.GetType("System.Int16");

        col1.ReadOnly = true; col1.AllowDBNull = false; col1.Unique = true;


        col1.ColumnName = "ID"; col1.AutoIncrement = true; col1.AutoIncrementSeed = 1;



        col2.DataType = System.Type.GetType("System.String");

        col2.ColumnName = "Name";


        col3.DataType = System.Type.GetType("System.String");

        col3.ColumnName = "Addr"; col3.DefaultValue = "서울";


        col4.DataType = System.Type.GetType("System.String");

        col4.ColumnName = "Tel";


        customer_dt.Columns.Add(col1); customer_dt.Columns.Add(col2);

        customer_dt.Columns.Add(col3); customer_dt.Columns.Add(col4);


        DataRow row1 = customer_dt.NewRow();


        row1[1] = "가길동"; row1[2] = "수원"; row1[3] = "111-2222";

        customer_dt.Rows.Add(row1);


        DataRow row2 = customer_dt.NewRow();

        row2[1] = "나길동"; row2[2] = "울산"; row2[3] = "111-2222";

        customer_dt.Rows.Add(row2);


        DataRow row3 = customer_dt.NewRow();

        row3[1] = "다길동"; row3[2] = "부산"; row3[3] = "333-2222";

        customer_dt.Rows.Add(row3);


        Console.Write("\n");


        foreach (DataColumn header in customer_dt.Columns)

        {

            Console.Write("{0, -6}\t", header.ColumnName);

        }


        Console.WriteLine("\n---------------------------------");

        foreach (DataRow rows in customer_dt.Rows)

        {

            foreach (DataColumn cols in customer_dt.Columns)

            {

                Console.Write("{0, -4}\t", rows[cols.ColumnName]);

            }

            Console.Write("\n");

        }


        DataSet set = new DataSet("customer_sales");

        set.Tables.Add(customer_dt);


        //DataSet의 내용을 XML로 출력

        Console.WriteLine(set.GetXml());


        // 쿼리식 기반 Linq To DataSet, 전체 고객 출력

        IEnumerable query = from customer in customer_dt.AsEnumerable()

                            select customer;


        Console.WriteLine("-----------------------------------------");

        Console.WriteLine("Customers : ");

        foreach (DataRow r in query)

        {

            Console.WriteLine(r.Field<string>("Name") + "::" + r.Field<string>("Addr") + "::" + r.Field<string>("Tel"));

        }


        // 쿼리식 기반 Linq To DataSet, 고객의 이름 출력

        IEnumerable query0 = from customer in customer_dt.AsEnumerable()

                             select customer.Field<string>("Name");


        Console.WriteLine("-----------------------------------------");

        Console.WriteLine("Customer Names : ");

        foreach (string customerName in query0)

        {

            Console.WriteLine(customerName);

        }


        // 메소드 기반 쿼리구문 Linq To DataSet, 모든 고객의 이름, 주소, 전화번호 추출

        var query2 = customer_dt.AsEnumerable().

                        Select(customer => new

                        {

                            Name = customer.Field<string>("Name"),

                            Addr = customer.Field<string>("Addr"),

                            Tel = customer.Field<string>("Tel")

                        });


        Console.WriteLine("-----------------------------------------");

        Console.WriteLine("Customers : ");

        foreach (var customerInfo in query2)

        {

            Console.WriteLine("Name: {0}, Addr: {1}, Tel : {2}",

                customerInfo.Name, customerInfo.Addr, customerInfo.Tel);

        }


        Console.WriteLine("-----------------------------------------");


        //SALES 데이터 생성

        DataTable sales_dt = new DataTable("sales");


        DataColumn scol1 = new DataColumn();

        DataColumn scol2 = new DataColumn();


        scol1.DataType = System.Type.GetType("System.String");

        scol1.ColumnName = "Name";


        scol2.DataType = System.Type.GetType("System.String");

        scol2.ColumnName = "Goods";


        sales_dt.Columns.Add(scol1); sales_dt.Columns.Add(scol2);


        DataRow srow1 = sales_dt.NewRow();

        srow1[0] = "가길동"; srow1[1] = "수박";

        sales_dt.Rows.Add(srow1);


        DataRow srow2 = sales_dt.NewRow();

        srow2[0] = "나길동"; srow2[1] = "참외";

        sales_dt.Rows.Add(srow2);


        set.Tables.Add(sales_dt);

        //---------------------------------------------


        // 내부조인

        var query3 =

                    from customer in customer_dt.AsEnumerable()

                    join sales in sales_dt.AsEnumerable()

                    on customer.Field<string>("Name") equals sales.Field<string>("Name")

                    select new

                    {

                        Name = customer.Field<string>("Name"),

                        Addr = customer.Field<string>("Addr"),

                        Goods = sales.Field<string>("Goods")

                    };


        foreach (var customerSale in query3)

        {

            Console.WriteLine("Name: {0}, Addr: {1}, Goods : {2} ",

                customerSale.Name, customerSale.Addr, customerSale.Goods);

        }

        Console.WriteLine("----------------------------------------- 내부조인");


        // 외부조인

        var query4 =

                    from customer in customer_dt.AsEnumerable()

                    join sales in sales_dt.AsEnumerable()

                    on customer.Field<string>("Name") equals sales.Field<string>("Name") into tmp

                    from sales in tmp.DefaultIfEmpty()

                    select new

                    {

                        Name = customer.Field<string>("Name"),

                        Addr = customer.Field<string>("Addr"),

                        Goods = (sales == null) ? "상품없음" : sales.Field<string>("Goods")

                    };


        foreach (var customerSale in query4)

        {

            Console.WriteLine("Name: {0}, Addr: {1}, Goods : {2} ",

                customerSale.Name, customerSale.Addr, customerSale.Goods);

        }

        Console.WriteLine("----------------------------------------- 외부조인");

    }

}




[결과]

ID      Name    Addr    Tel

---------------------------------

1       가길동  수원    111-2222

2       나길동  울산    111-2222

3       다길동  부산    333-2222

<customer_sales>

  <customer>

    <ID>1</ID>

    <Name>가길동</Name>

    <Addr>수원</Addr>

    <Tel>111-2222</Tel>

  </customer>

  <customer>

    <ID>2</ID>

    <Name>나길동</Name>

    <Addr>울산</Addr>

    <Tel>111-2222</Tel>

  </customer>

  <customer>

    <ID>3</ID>

    <Name>다길동</Name>

    <Addr>부산</Addr>

    <Tel>333-2222</Tel>

  </customer>

</customer_sales>

-----------------------------------------

Customers :

가길동::수원::111-2222

나길동::울산::111-2222

다길동::부산::333-2222

-----------------------------------------

Customer Names :

가길동

나길동

다길동

-----------------------------------------

Customers :

Name: 가길동, Addr: 수원, Tel : 111-2222

Name: 나길동, Addr: 울산, Tel : 111-2222

Name: 다길동, Addr: 부산, Tel : 333-2222

-----------------------------------------

Name: 가길동, Addr: 수원, Goods : 수박

Name: 나길동, Addr: 울산, Goods : 참외

----------------------------------------- 내부조인

Name: 가길동, Addr: 수원, Goods : 수박

Name: 나길동, Addr: 울산, Goods : 참외

Name: 다길동, Addr: 부산, Goods : 상품없음

----------------------------------------- 외부조인




#링크, #링큐, #LinqToDataSet, #데이터셋, #링크조인, #링큐조인, #닷넷교육, #닷넷동영상, #시샵교육, #시샵동영상, 링크, 링큐, LinqToDataSet, 데이터셋, 링크조인, 링큐조인, 닷넷교육, 닷넷동영상, 시샵교육, 시샵동영상, C#교육, C#학원, C#동영상

(C#교육동영상)C# ADO.NET 실습 ODP.NET/ODAC 설치 오라클 함수 호출 실습, C#학원, WPF학원, 닷넷학원, 자바학원

  (C#교육동영상)C# ADO.NET 실습  ODP.NET/ODAC 설치  오라클 함수 호출 실습, C#학원, WPF학원, 닷넷학원, 자바학원 https://www.youtube.com/watch?v=qIPU85yAlzc&list=PLxU-i...