Windows Server 2008 서버 관리

 

1. 설치 및 환경 구성
 1) 설치
 2) 웹서버 / FTP / DNS / SMTP / ...
 3) 유동IP주소 => 고정IP주소
 4) TCP/IP 명령어
  a) hostname : 컴퓨터명
  b) ipconfig /all : IP주소정보
  c) ping : 네트워크 진단 도구
   127.0.0.1 / localhost
   로컬에서 본인 컴퓨터 IP주소 대체하는 테스트 주소
   로컬 루프백 주소
  d) inetmgr : 웹서버인 IIS서버를 가동시키는 명령어
   시작 - 관리도구 - IIS(인터넷 정보 서비스) 관리자

2. 사용자 관리
 1) Administrators : 최고관리자
 2) Users : 일반사용자
 3) 사용자 생성/그룹 생성

3. NTFS 파일 시스템 관리
 1) 파일 및 폴더 및 드라이브 관리

4. 공유
 1) 로컬 네트워크 공유

5. 웹서버 구축(웹 공유)
 1) 홈 디렉터리
  a) http://IP주소/ -> 접속하는 로컬의 폴더
 2) 가상 디렉터리(웹 공유)
  a) http://IP주소/웹공유이름/ -> 접속하는 로컬 서버의 폴더
   http://www.dotnetkorea.com/Website/
   가상디렉터리는 하위폴더일 수도 있다.
 3) 기본문서
  a) Default.htm, Default.aspx, Default.asp와 같이 파일명을 타이핑하지 않아도 자동으로 요청하는 페이지
 4) 포트번호(8080)를 사용해서 여러 개의 홈 디렉터리 생성
  a) http://IP주소:8080/ -> 접속

6. FTP서버 구축
 ftp://IP주소/ -> 계정 : ftp01/ftp01 -> C:\Home\ftp01\ 폴더로 접속
 1) 설치 : ipconfig
 2) 사용자 : ftp01
 3) NTFS : 폴더만들고 해당 사용자에게 쓰기 권한 주기
    C\Home\ftp01
 4) 공유 : 로컬 공유는 하지 않아도 됨
 5) 웹공유 : 안해도 됨
 6) 파일공유(FTP) : 별칭(Alias) = 사용자명 동일해야 함. 익명 연결 해제

7. DNS서버 구축
 1) http://www.abc.com/ => C:\Home\abc\Default.htm
 2) 도메인 설정 : abc.com
  a) TCP/IP등록정보의 기본 DNS 서버를 본인 서버IP주소로 설정
  b) 정방향 조회 영역 : 도메인 등록
  c) 역방향 조회 영역 : IP주소 등록
  d) A레코드 설정 : 도메인 = IP주소
  e) www과 같은 새 호스트 등록 : www.abc.com
  f) nslookup 명령어로 테스트(성공하면 내 IP주소. 실패하면 abc.com의 실제 IP주소가 출력됨)
   nslookup abc.com
  g) IIS에 웹 사이트 만들고 도메인 등록 후 테스트
   C:\Home\abc\Default.htm
   웹사이트 만들 때 호스트(도메인) 등록
   http://www.abc.com

 3) 2차 도메인 구축 연습
  a) http://www.dns.com/ => C:\Home\dns.com\www\Default.htm
  b) http://admin.dns.com/ => C:\Home\dns.com\admin\Default.htm

8. 메일서버 구축(옵션) : mail@mail.net
 
9. 원격접속/미디어서버 구축
 1) "Windows Server 2008용 Windows Media 서비스 2008" 검색 및 다운로드
 2) 미디어 서비스
  a) Http:// 사용 : IIS에 웹에 wmv와 미디어 파일
  b) Mms:// 사용 : 미디어 서버에 wmv파일 올려놓고 서비스
   mms://192.168.10.33/media/silverlight.wmv

10. 백업 및 복원
 1) 백업 : 관리도구 - Windows Server 백업
   서버관리자에서 기능 추가 - Windows Server 백업 기능 
  a) 전체백업
  b) 부분백업
  c) 시스템 상태 데이터 백업(윈도우 레지스트리 : 중요 설정 정보)

11. 터미널서비스(원격 데스크톱 연결)
 1) Windows XP 이상에서는 [컴퓨터]-[원격]탭-원격 허용 체크
 2) Administrator에 암호가 설정되었을 때.
 3) [원격 데스크톱 연결] 프로그램을 사용해서 접속 가능
  a) 원격에서 설치만 못할 뿐 모든 설정 가능
 4) 연습 : http://www.remote.com/TSWeb/ -> 원격 접속 가능 페이지 출력
  a) 원격 데스크톱 웹 연결
 5) 원격 접속 권한
  a) Administrators 권한 : 모든 권한으로 원격 로그온 가능
  b) Remote Desktop Users 권한 : 최소한의 기능으로 원격 로그온 가능

 

<목표>
 http://www.aaa.com/ => C:\Home\aaa.com\Default.htm
 ftp://aaa.com/ => aaa/Pa$$w0rd => 위 폴더로 접속 및 업/다운로드 가능

1. 설치
 1) homename, ipconfig /all, ping

2. 사용자
 1) aaa / Pa$$w0rd

3. NTFS
 1) C:\Home\aaa.com\Default.htm
 2) IUSR_컴퓨터명에 읽기권한 이상

4. 공유
 1) \\IP주소\aaa.com$ => LAN환경에서 접속 가능

5. 도메인
 1) 정방향
 2) 역방향
 3) A레코드
 4) 웹페이지 추가
 5)

6. 파일공유

7. 도메인

 
 
Posted by holland14
:



- PagedCollectionView 클래스를 사용하여 컬렉션형태의 데이터에 맞게 페이징 처리를 해주는 컨트롤




왼쪽에 있는 '도구상자'에서 "DataGrid"컨트롤을 "MainPage.xaml"파일의 "Grid"안에 떨어뜨린다.






[MainPage.xaml]

<UserControl xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="RiaDataPager.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <my:DataGrid x:Name="ctlList" AutoGenerateColumns="True"></my:DataGrid>

        <my:DataPager x:Name="ctlPager"

            PageSize="5" Source="{Binding Path=ItemsSource, ElementName=ctlList}" />       

    </Grid>

</UserControl>

 

 






[MainPage.xaml.cs]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Data;

 

namespace RiaDataPager

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

        }

 

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            PagedCollectionView pcv =

                new PagedCollectionView(" ".Split(' '));

            ctlList.ItemsSource = pcv;

        }

    }

}

 

 




















 

Posted by holland14
:



앞에서 실습했던 "DataGrid 컨트롤로 데이터 출력하기"에다 "현재 선택된 행 가져오기"기능을 추가하기 위하여, "RiaDataGrid"파일을 복사해서 쓰지 않고 다시 열어서 실습하였다.






[MainPage.xaml]


<UserControl

xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="RiaDataGrid.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <my:DataGrid x:Name="ctlMemoList" AutoGenerateColumns="True"></my:DataGrid>

            <my:DataGrid x:Name="ctlMemoList2" AutoGenerateColumns="False">

                <my:DataGrid.Columns>

                    <my:DataGridTextColumn Header="번호" Binding="{Binding Num}"></my:DataGridTextColumn>

                    <my:DataGridTemplateColumn Header="이름">

                        <my:DataGridTemplateColumn.CellTemplate>

                            <DataTemplate>

                                <TextBlock Text="{Binding Name}" Foreground="Blue" />

                            </DataTemplate>

                        </my:DataGridTemplateColumn.CellTemplate>

                    </my:DataGridTemplateColumn>

                </my:DataGrid.Columns>

            </my:DataGrid>

            <Button x:Name="btnGet" Content="현재 선택된 가져오기" />

        </StackPanel>

    </Grid>

</UserControl>

 

 








[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Collections.ObjectModel;

 

namespace RiaDataGrid

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            btnGet.Click += new RoutedEventHandler(btnGet_Click);

            ctlMemoList2.SelectionChanged += new SelectionChangedEventHandler(ctlMemoList2_SelectionChanged);

        }

        // 행을 선택하자마자 선택된 행을 보여주기

        void ctlMemoList2_SelectionChanged(object sender, SelectionChangedEventArgs e)

        {

            btnGet_Click(null, null);

        }

        // 현재 선택된 행을 가져오려면???

        void btnGet_Click(object sender, RoutedEventArgs e)

        {

            if (ctlMemoList2.SelectedIndex != -1) // 선택되었다면...

            {

                // SelectedItem으로 현재 선택된 행을 가져와서 Memo 타입으로 변경 대입

                Memo m = ctlMemoList2.SelectedItem as Memo;

                MessageBox.Show(String.Format("번호 : {0}, 이름 : {1}", m.Num, m.Name));

            }

        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            FuncList();

            FuncObservable();

        }

 

        private void FuncObservable()

        {

            ObservableCollection<Memo> lst = new ObservableCollection<Memo>();

 

            lst.Add(new Memo() { Num = 1, Name = "홍길동" });

            lst.Add(new Memo() { Num = 2, Name = "백두산" });

            lst.Add(new Memo() { Num = 3, Name = "한라산" });

 

            this.ctlMemoList2.ItemsSource = lst;

        }

 

        private void FuncList()

        {

            List<Memo> lst = new List<Memo>();

 

            lst.Add(new Memo() { Num = 1, Name = "홍길동" });

            lst.Add(new Memo() { Num = 2, Name = "백두산" });

            lst.Add(new Memo() { Num = 3, Name = "한라산" });

 

            this.ctlMemoList.ItemsSource = lst;

        }

    }

 

    public class Memo

    {

        public int Num { get; set; }

        public string Name { get; set; }

    }

}

 

 
















Posted by holland14
:




- WinForm/ASP.NET에서 제공되는 Grid컨트롤보다는 기능의 아쉬움이 있다.

- DataGrid 사용
    - 왼쪽 도구 상자에서 DataGrid 끌어서 XAML에 등록
        - System.Windows.Controls.Data 어셈블리 등록 필요






[MainPage.xaml]


<UserControl

xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="RiaDataGrid.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <StackPanel>

            <my:DataGrid x:Name="ctlMemoList" AutoGenerateColumns="True"></my:DataGrid>

            <my:DataGrid x:Name="ctlMemoList2" AutoGenerateColumns="False">

                <my:DataGrid.Columns>

                    <my:DataGridTextColumn Header="번호" Binding="{Binding Num}"></my:DataGridTextColumn>

                    <my:DataGridTemplateColumn Header="이름">

                        <my:DataGridTemplateColumn.CellTemplate>

                            <DataTemplate>

                                <TextBlock Text="{Binding Name}" Foreground="Blue" />

                            </DataTemplate>

                        </my:DataGridTemplateColumn.CellTemplate>

                    </my:DataGridTemplateColumn>

                </my:DataGrid.Columns>

            </my:DataGrid>

        </StackPanel>

    </Grid>

</UserControl>

 

 








[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Collections.ObjectModel;

 

namespace RiaDataGrid

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

        }

 

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            FuncList();

            FuncObservable();

        }

 

        private void FuncObservable()

        {

            ObservableCollection<Memo> lst = new ObservableCollection<Memo>();

 

            lst.Add(new Memo() { Num = 1, Name = "홍길동" });

            lst.Add(new Memo() { Num = 2, Name = "백두산" });

            lst.Add(new Memo() { Num = 3, Name = "한라산" });

 

            this.ctlMemoList2.ItemsSource = lst;

        }

 

        private void FuncList()

        {

            List<Memo> lst = new List<Memo>();

 

            lst.Add(new Memo() { Num = 1, Name = "홍길동" });

            lst.Add(new Memo() { Num = 2, Name = "백두산" });

            lst.Add(new Memo() { Num = 3, Name = "한라산" });

 

            this.ctlMemoList.ItemsSource = lst;

        }

    }

 

    public class Memo

    {

        public int Num { get; set; }

        public string Name { get; set; }

    }

}

 

 
















Posted by holland14
:



컨트롤과 컨트롤간에 직접 바인딩 제공





앞에서했던 "RiaDataTemplate"파일을 복사하여 "RiaControlBinding"로 폴더명을 바꾸고 프로젝트를 열어서 실습한다.







[MainPage.xaml]


<UserControl x:Class="RiaCollectionBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.RowDefinitions>

            <RowDefinition Height="400"></RowDefinition>

            <RowDefinition Height="*"></RowDefinition>       

        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">

            <ListBox x:Name="lstProducts" Width="400" Height="400" Margin="10">

                <ListBox.ItemTemplate>

                    <DataTemplate>

                        <StackPanel Orientation="Horizontal">

                            <TextBlock Text="{Binding Path=ProductID}" Foreground="Red" Margin="3" />

                            <Image Source="{Binding ProductImage}" Margin="2" Height="80" Width="80" />

                            <TextBlock Text="{Binding ModelName}" Margin="3" />

                        </StackPanel>

                    </DataTemplate>

                </ListBox.ItemTemplate>

            </ListBox>

            <ListBox x:Name="lstProducts2" Width="200" Height="120"></ListBox>

        </StackPanel>

        <!-- 컨트롤과 컨트롤간의 바인딩 -->

        <StackPanel Grid.Row="1">

            <TextBlock Text="{Binding SelectedItem.ProductID, ElementName=lstProducts2}" />

            <TextBlock Text="{Binding SelectedItem.ModelName, ElementName=lstProducts2}" />

            <Image Source="{Binding SelectedItem.ProductImage, ElementName=lstProducts2}"

                Width="100" Height="100" />

            <TextBlock Text="{Binding SelectedItem.SellPrice, ElementName=lstProducts2}" />

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            InitializeData();

        }

 

        private void InitializeData()

        {

            // 3개의 상품을 등록

            List<ProductEntity> lst = new List<ProductEntity>();

            // 수작업으로 등록

            ProductEntity pe1 = new ProductEntity() {

                ProductID = 1, ModelName = "좋은컴퓨터", SellPrice = 100, ProductImage = "COM-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 2, ModelName = "좋은책", SellPrice = 80, ProductImage = "BOOK-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 3, ModelName = "좋은강의", SellPrice = 100, ProductImage = "SOFTWARE-01.jpg" };

            lst.Add(pe1);           

            // 리스트 컨트롤에 바인딩

            this.lstProducts.ItemsSource = lst; // 컬렉션 형태의 데이터는 ItemsSource 속성으로 바인딩

            //this.lstProducts.DisplayMemberPath = "ModelName";

            this.lstProducts.SelectedIndex = 0;

 

            this.lstProducts2.ItemsSource = lst;

        }

    }

}

 

 









[ProductEntity.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public class ProductEntity

    {

        public int ProductID { get; set; }

        public string ModelName { get; set; }

        public int SellPrice { get; set; }

        public string ProductImage { get; set; }

        // 리스트박스 바인딩 기본 필드를 설정

        public override string ToString() {

            return ModelName;

        }

    }

}

 

 
















Posted by holland14
:



앞에서했던 "RiaCollectionBinding"파일을 복사하여 "RiaDataTemplate"로 폴더명을 바꾸고 프로젝트를 열어서 실습한다.







아래그림과 같이 '솔루션 탐색기'에서 'ClientBin'폴더에 '이미지파일'인 "BOOK-01.jpg", "COM-01.jpg", "SOFTWARE-01.jpg"파일을 붙여넣는다.










[MainPage.xaml]


 

<UserControl x:Class="RiaCollectionBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.RowDefinitions>

            <RowDefinition Height="400"></RowDefinition>

            <RowDefinition Height="*"></RowDefinition>       

        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">

            <ListBox x:Name="lstProducts" Width="400" Height="400" Margin="10">

                <ListBox.ItemTemplate>

                    <DataTemplate>

                        <StackPanel Orientation="Horizontal">

                            <TextBlock Text="{Binding Path=ProductID}" Foreground="Red" Margin="3" />

                            <Image Source="{Binding ProductImage}" Margin="2" Height="80" Width="80" />

                            <TextBlock Text="{Binding ModelName}" Margin="3" />

                        </StackPanel>

                    </DataTemplate>

                </ListBox.ItemTemplate>

            </ListBox>

            <ListBox x:Name="lstProducts2" Width="200" Height="120"></ListBox>

        </StackPanel>

    </Grid>

</UserControl>

 

 









[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            InitializeData();

        }

 

        private void InitializeData()

        {

            // 3개의 상품을 등록

            List<ProductEntity> lst = new List<ProductEntity>();

            // 수작업으로 등록

            ProductEntity pe1 = new ProductEntity() {

                ProductID = 1, ModelName = "좋은컴퓨터", SellPrice = 100, ProductImage = "COM-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 2, ModelName = "좋은책", SellPrice = 80, ProductImage = "BOOK-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 3, ModelName = "좋은강의", SellPrice = 100, ProductImage = "SOFTWARE-01.jpg" };

            lst.Add(pe1);           

            // 리스트 컨트롤에 바인딩

            this.lstProducts.ItemsSource = lst; // 컬렉션 형태의 데이터는 ItemsSource 속성으로 바인딩

            //this.lstProducts.DisplayMemberPath = "ModelName";

            this.lstProducts.SelectedIndex = 0;

 

            this.lstProducts2.ItemsSource = lst;

        }

    }

}

 

 







[ProductEntity.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public class ProductEntity

    {

        public int ProductID { get; set; }

        public string ModelName { get; set; }

        public int SellPrice { get; set; }

        public string ProductImage { get; set; }

        // 리스트박스 바인딩 기본 필드를 설정

        public override string ToString() {

            return ModelName;

        }

    }

}

 

 

















Posted by holland14
:



아래그림과 같이 '솔루션 탐색기'에서 '새 항목 추가"로 "클래스"파일인 "ProductEntity.cs"를 추가하고 아래와 같이 코딩한다.









[ProductEntity.cs]

using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public class ProductEntity

    {

        public int ProductID { get; set; }

        public string ModelName { get; set; }

        public int SellPrice { get; set; }

        public string ProductImage { get; set; }

        // 리스트박스 바인딩 기본 필드를 설정

        public override string ToString() {

            return ModelName;

        }

    }

}

 

 







[MainPage.xaml]


<UserControl x:Class="RiaCollectionBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400">

 

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.RowDefinitions>

            <RowDefinition Height="100"></RowDefinition>

            <RowDefinition Height="*"></RowDefinition>       

        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">

            <ListBox x:Name="lstProducts" Width="200" Height="120"></ListBox>

            <ListBox x:Name="lstProducts2" Width="200" Height="120"></ListBox>

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaCollectionBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

            InitializeData();

        }

 

        private void InitializeData()

        {

            // 3개의 상품을 등록

            List<ProductEntity> lst = new List<ProductEntity>();

            // 수작업으로 등록

            ProductEntity pe1 = new ProductEntity() {

                ProductID = 1, ModelName = "좋은컴퓨터", SellPrice = 100, ProductImage = "COM-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 2, ModelName = "좋은책", SellPrice = 80, ProductImage = "BOOK-01.jpg" };

            lst.Add(pe1);

            pe1 = new ProductEntity() {

                ProductID = 3, ModelName = "좋은강의", SellPrice = 100, ProductImage = "SOFTWARE-01.jpg" };

            lst.Add(pe1);           

            // 리스트 컨트롤에 바인딩

            this.lstProducts.ItemsSource = lst; // 컬렉션 형태의 데이터는 ItemsSource 속성으로 바인딩

            this.lstProducts.DisplayMemberPath = "ModelName";

            this.lstProducts.SelectedIndex = 0;

 

            this.lstProducts2.ItemsSource = lst;

        }

    }

}

 

 
















Posted by holland14
:




- DataContext에 전달할 클래스 생성
    - 반드시 INotifyPropertyChanged 인터페이스 구현

- 바인딩 식에서 ValidatesOnException 속성을 true로 설정하면, 바인딩 에러 발생시 지정된 에러메시지가 출력됨








앞에서했던 "RiaINotifyPropertyChanged"파일을 복사하여 "RiaValidation"로 폴더명을 바꾸고 프로젝트를 열어서 실습한다.







[MainPage.xaml]

<UserControl x:Class="RiaSimpleBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400"

    xmlns:me="clr-namespace:RiaSimpleBinding"

    >

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <me:PostDateConverter x:Key="pdConverter" />

        </Grid.Resources>

        <StackPanel>

            <TextBlock Text="직접 바인딩" />

            <TextBox x:Name="lblNum" Text="{Binding Path=Num, Mode=TwoWay}" />

            <TextBlock Text="XAML 바인딩" />

            <TextBox Text="{Binding Path=Name, Mode=TwoWay, ValidatesOnExceptions=True}" Width="200" />

            <TextBox Text="{Binding Path=PostDate, Converter={StaticResource pdConverter}, Mode=TwoWay}" />

            <Button x:Name="btnSave" Content="저장" />

            <Button x:Name="btnChanged" Content="코드 비하인드의 값을 변경" />

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            btnSave.Click += new RoutedEventHandler(btnSave_Click);

            btnChanged.Click += new RoutedEventHandler(btnChanged_Click);

        }

        // Memo 데이터 한개 바인딩

        private MemoEntity me = new MemoEntity() { Num = 1, Name = "홍길동", PostDate = DateTime.Now };

        void btnChanged_Click(object sender, RoutedEventArgs e)

        {

            me.Num = 2; me.Name = "한라산"; me.PostDate = DateTime.Now.AddDays(1);

        }

 

        void btnSave_Click(object sender, RoutedEventArgs e)

        {

            // UI -> C#으로 데이터 가져오기

            me = this.LayoutRoot.DataContext as MemoEntity;

            if (me != null)

            {

                MessageBox.Show(String.Format("{0}, {1}, {2}", me.Num, me.Name, me.PostDate));

            }

        }

 

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            //[1] 컨트롤에 직접 바인딩

            this.lblNum.Text = me.Num.ToString();

            //[2] XAML 바인딩식을 사용해서 바인딩

            this.LayoutRoot.DataContext = me;

        }

    }

}

 

 






[MemoEntity.cs]

using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public class MemoEntity : System.ComponentModel.INotifyPropertyChanged

    {

        public int Num { get; set; }

        private string _Name;

        public string Name

        {

            get

            {

                return _Name;

            }

            set

            {

                // 넘겨온 Name 대해서 유효성 검사

                if (value.Length < 2)

                {

                    throw new Exception("이름은 2 이상으로 입력하시오.");

                }

 

                _Name = value;

                if (PropertyChanged != null)

                {

                    // 속성값이 변경되었다면, 동적으로 Name 속성을 반영해라...

                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Name"));

                }

            }

        }

        public DateTime PostDate { get; set; }          

 

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;       

    }

}

 

 






[PostDateConverter.cs]

using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Data;

 

namespace RiaSimpleBinding

{

    public class PostDateConverter : IValueConverter

    {

        // 12/10/2009 => 2009 12 10 변환

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            // 넘겨져 값을 날짜형으로 변환

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt.ToString("yyyyMMdd");

            }

            else

            {

                return "";

            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt;

            }

            return dt;

        }

    }

}

 

 







[실행결과]

--> '솔루션 탐색기'에서 "RiaSimpleBindingTestPage.html"파일을 마우스 우클릭한 후 "브라우저에서 보기"로 실행하여 결과를 확인한다.("F5"로 실행시 예외처리 에러가 난다.)

















Posted by holland14
:


- OneTime
    - 딱 한번만 바인딩

- OneWay
    - 코드에서 UI로만 바인딩

- TwoWay
    - 코드에서 UI로, UI에서 코드로 바인딩

- INotifyPropertyChanged 인터페이스 구현
    - TwoWay로 데이터 원본이 바뀌자마자 UI도 변경되게하려면 엔터티 클래스에 INotifyPropertyChanged 인터페이스를 상속받아 구현해야 함






앞에서했던 "RiaConvertBack"파일을 복사해서 "RiaINotifyPropertyChanged"로 폴더명을 변경하여 실습한다.







[MainPage.xaml]


<UserControl x:Class="RiaSimpleBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400"

    xmlns:me="clr-namespace:RiaSimpleBinding"

    >

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <me:PostDateConverter x:Key="pdConverter" />

        </Grid.Resources>

        <StackPanel>

            <TextBlock Text="직접 바인딩" />

            <TextBox x:Name="lblNum" Text="{Binding Path=Num, Mode=TwoWay}" />

            <TextBlock Text="XAML 바인딩" />

            <TextBox Text="{Binding Path=Name, Mode=TwoWay}" />

            <TextBox Text="{Binding Path=PostDate, Converter={StaticResource pdConverter}, Mode=TwoWay}" />

            <Button x:Name="btnSave" Content="저장" />

            <Button x:Name="btnChanged" Content="코드 비하인드의 값을 변경" />

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            btnSave.Click += new RoutedEventHandler(btnSave_Click);

            btnChanged.Click += new RoutedEventHandler(btnChanged_Click);

        }

        // Memo 데이터 한개 바인딩

        private MemoEntity me = new MemoEntity() { Num = 1, Name = "홍길동", PostDate = DateTime.Now };

        void btnChanged_Click(object sender, RoutedEventArgs e)

        {

            me.Num = 2; me.Name = "한라산"; me.PostDate = DateTime.Now.AddDays(1);

        }

 

        void btnSave_Click(object sender, RoutedEventArgs e)

        {

            // UI -> C#으로 데이터 가져오기

            me = this.LayoutRoot.DataContext as MemoEntity;

            if (me != null)

            {

                MessageBox.Show(String.Format("{0}, {1}, {2}", me.Num, me.Name, me.PostDate));

            }

        }

 

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            //[1] 컨트롤에 직접 바인딩

            this.lblNum.Text = me.Num.ToString();

            //[2] XAML 바인딩식을 사용해서 바인딩

            this.LayoutRoot.DataContext = me;

        }

    }

}

 

 






[PostDateConverter.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Data;

 

namespace RiaSimpleBinding

{

    public class PostDateConverter : IValueConverter

    {

        // 12/10/2009 => 2009 12 10 변환

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            // 넘겨져 값을 날짜형으로 변환

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt.ToString("yyyyMMdd");

            }

            else

            {

                return "";

            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt;

            }

            return dt;

        }

    }

}

 

 








[MemoEntity.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public class MemoEntity : System.ComponentModel.INotifyPropertyChanged

    {

        public int Num { get; set; }

        private string _Name;

        public string Name

        {

            get

            {

                return _Name;

            }

            set

            {

                _Name = value;

                if (PropertyChanged != null)

                {

                    // 속성값이 변경되었다면, 동적으로 Name 속성을 반영해라...

                    PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Name"));

                }

            }

        }

        public DateTime PostDate { get; set; }          

 

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;       

    }

}

 

 


















Posted by holland14
:



이전에 했던 "RiaIValueConverter" 파일을 복사해서, 복사한 파일의 폴더명을 "RiaConvertBack"로 바꾸고 프로젝트를 열어서 실습한다.





[MainPage.xaml]


<UserControl x:Class="RiaSimpleBinding.MainPage"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

    mc:Ignorable="d"

    d:DesignHeight="300" d:DesignWidth="400"

    xmlns:me="clr-namespace:RiaSimpleBinding"

    >

    <Grid x:Name="LayoutRoot" Background="White">

        <Grid.Resources>

            <me:PostDateConverter x:Key="pdConverter" />

        </Grid.Resources>

        <StackPanel>

            <TextBlock Text="직접 바인딩" />

            <TextBox x:Name="lblNum" Text="{Binding Path=Num, Mode=TwoWay}" />

            <TextBlock Text="XAML 바인딩" />

            <TextBox Text="{Binding Path=Name, Mode=TwoWay}" />

            <TextBox Text="{Binding Path=PostDate, Converter={StaticResource pdConverter}, Mode=TwoWay}" />

            <Button x:Name="btnSave" Content="저장" />

        </StackPanel>

    </Grid>

</UserControl>

 

 







[MainPage.xaml.cs]


using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public partial class MainPage : UserControl

    {

        public MainPage()

        {

            InitializeComponent();

 

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            btnSave.Click += new RoutedEventHandler(btnSave_Click);

        }

 

        void btnSave_Click(object sender, RoutedEventArgs e)

        {

            // UI -> C#으로 데이터 가져오기

            MemoEntity me = this.LayoutRoot.DataContext as MemoEntity;

            if (me != null)

            {

                MessageBox.Show(String.Format("{0}, {1}, {2}", me.Num, me.Name, me.PostDate));

            }

        }

 

        void MainPage_Loaded(object sender, RoutedEventArgs e)

        {

            // Memo 데이터 한개 바인딩

            MemoEntity me = new MemoEntity() { Num = 1, Name = "홍길동", PostDate = DateTime.Now };

            //[1] 컨트롤에 직접 바인딩

            this.lblNum.Text = me.Num.ToString();

            //[2] XAML 바인딩식을 사용해서 바인딩

            this.LayoutRoot.DataContext = me;

        }

    }

}

 

 






[PostDateConverter.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using System.Windows.Data;

 

namespace RiaSimpleBinding

{

    public class PostDateConverter : IValueConverter

    {

        // 12/10/2009 => 2009 12 10 변환

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            // 넘겨져 값을 날짜형으로 변환

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt.ToString("yyyyMMdd");

            }

            else

            {

                return "";

            }

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {

            DateTime dt = DateTime.Now;

            if (DateTime.TryParse(value.ToString(), out dt))

            {

                return dt;

            }

            return dt;

        }

    }

}

 

 







[MemoEntity.cs]


using System;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Ink;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

 

namespace RiaSimpleBinding

{

    public class MemoEntity

    {

        public int Num { get; set; }

        public string Name { get; set; }

        public DateTime PostDate { get; set; }

    }

}

 

 

















Posted by holland14
: