Microsoft MVP성태의 닷넷 이야기
Phone: 3. 윈도우 폰을 위한 Holiyday Calendar 앱 개발 [링크 복사], [링크+제목 복사],
조회: 24793
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
[testApp.zip]    
(연관된 글이 1개 있습니다.)

윈도우 폰을 위한 Holiyday Calendar 앱 개발

제가 근무하는 회사에서는 휴가 관리 프로그램을 모바일로 배포하고 있습니다.

Holiday Manager 
 - 아이폰: http://itunes.apple.com/us/app/holiday-manager/id502327711?l=ko&ls=1&mt=8
 - 안드로이드폰: https://market.android.com/details?id=com.jennifersoft.holidays.app

대단한 프로그램은 아니고, 단지 날짜 선택해 두고 1년에 몇 개의 날짜가 선택되었는지만 세어주면 끝입니다.

사실 회사 직원들만 쓸 용도로 배포하는 것이라서 원래는 직원들의 개개인에 맞는 서비스가 제공되어야 하는데, 아시다시피 '모바일 앱'들이 별도의 '앱스토어' 등을 통해서 배포되다 보니 '범용적'으로 사용할 수 있도록 개발되어져야 합니다.

그래서, 회사 직원들의 근속연수에 따른 (+)휴가 일수를 보여준다던가, 그로 인한 남은 휴가 일수를 계산하는 서비스는 불가능하고 단지 '한 개인이 1년에 며칠의 휴가를 냈는가'를 자체적으로 계산할 수 있는 정도의 기능만 제공해 주고 있습니다.

이번 글은 그 응용 프로그램을 만들면서 사용한 팁을 소개하는 것입니다. ^^





1. 달력 컨트롤

자... '휴가 관리'가 목적이니, 우선 달력 컨트롤이 있어야 합니다. 아쉽게도 기본 설치되는 "Silverlight for Windows Phone"에는 달력 컨트롤이 제공되지 않으므로 별도의 컨트롤을 다음의 사이트에서 다운로드해 설치해야 합니다.

Windows Phone Controls  
; http://wpcontrols.codeplex.com/releases/view/71749

달력 컨트롤을 사용하는 방법은 간단합니다.

<phone:PhoneApplicationPage x:Class="HolidayManager.MainPage"
...[생략]...
    xmlns:WPControls="clr-namespace:WPControls;assembly=WPControls"
    shell:SystemTray.IsVisible="True">

    <phone:PhoneApplicationPage.Resources>
        <local:ColorConverter x:Key="ColorConverter"/>
    </phone:PhoneApplicationPage.Resources>

    <Grid x:Name="ContentPanel" Grid.Row="1">
        <WPControls:Calendar HorizontalAlignment="Stretch" 
                                ColorConverter="{StaticResource ColorConverter}"
                                Name="calendar1" VerticalAlignment="Top" />
    </Grid>

특이한 점이라면, 위에서 ColorConverter를 사용하고 있는데요. 목적은 해당 날짜의 문자 색이나 배경색을 바꾸기 위해서입니다. 대충 아래와 같이 하면, 토요일은 문자 색상을 Purple로 지정하고, 일요일은 빨간색, 그리고 '휴가로 지정된 날짜'는 회색으로 배경을 채웁니다. (실제 코드에서는 약간 변경되었습니다.)

public class ColorConverter : IDateToBrushConverter
{
    public Brush Convert(DateTime dateTime, bool isSelected, Brush defaultValue, BrushType brushType)
    {
        if (brushType == BrushType.Background)
        {
            if (IsToday(dateTime) == true)
            {
                return new SolidColorBrush(Colors.LightGray);
            }
            else
            {
                return defaultValue;
            }
        }
        else
        {
            if (dateTime.DayOfWeek == DayOfWeek.Saturday)
            {
                return new SolidColorBrush(Colors.Purple);
            }
            else if (dateTime.DayOfWeek == DayOfWeek.Sunday)
            {
                return new SolidColorBrush(Colors.Red);
            }
            else
            {
                return defaultValue;
            }
        }

    }

    private bool IsToday(DateTime dateTime)
    {
        DateTime now = DateTime.Now;
        return (dateTime.Year == now.Year &&
            dateTime.Month == now.Month &&
            dateTime.Day == now.Day);
    }
}

how_to_dev_holiday_manager_1.png


2. SQL Compact Edition 사용

그다음은 사용자가 지정한 날짜를 '휴가'로 저장해야 합니다. 그렇다면 '저장소'가 필요한데요. 간단한 프로그램이라서 그냥 단순하게 파일로 저장해도 되지만... ^^ 우리의 목표는 '공부'하는 효과도 병행하는 것이기 때문에 '망고 폰'부터 적용되는 "SQL CE"를 사용해 보겠습니다.

예전에 간단하게 SQL Compact Edition을 다뤄본 적이 있었는데요.

Pet Shop 4.0 - SQL Server Compact Edition Version - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/815

망고 폰에서는 데스크톱 App과는 달리 SQL Compact Edition을 사용한다고 해서 별도의 dll을 참조하거나 배포할 일은 없습니다. (망고 폰에 내장되어 있습니다. 아마도 폰의 GAC 같은 곳에 등록되어 있겠지요.) 따라서, 해줄 일은 "System.Data.Linq" 어셈블리를 참조하고 "Enterprise Framework"의 "Code First"와 유사한 방식으로 DataContext를 정의해서 사용하면 됩니다.

말이 좀 장황한데, 다음의 글들을 읽어보시면 쉽게 사용할 수 있습니다. ^^

SQL CE 버전으로 날개 단 윈도우폰 7 망고
; http://www.imaso.co.kr/?doc=bbs/gnuboard.php&wr_id=37900&bo_table=article

Mango Sample: Database Part 1:2 
; http://blog.jerrynixon.com/2011/11/mango-sample-database-part-12.html

아래는 위의 글을 읽고 제가 적용한 DataContext 소스입니다.

using System;
...[생략]...
using System.Linq;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.ComponentModel;

namespace HolidayManager.Db
{
    public class HolidayContext : DataContext
    {
        public static string ConnectionString = "Data Source=isostore:/HolidayManager.sdf";

        public HolidayContext(string connectionString) : base(connectionString) 
        {
        }

        public Table<MyHoliday> MyHolidays;

        public void InsertMyHoliday(DateTime selectedDate, HolidayType type)
        {
            MyHoliday mh = new MyHoliday();
            mh.Date = selectedDate;
            mh.Type = type;

            RemoveMyHoliday(false, selectedDate);

            this.MyHolidays.InsertOnSubmit(mh);
            this.SubmitChanges();
        }

        internal void RemoveMyHoliday(bool commitChanges, DateTime dateToRemove)
        {
            var dates = (from entity in this.MyHolidays 
             where entity.Date == dateToRemove
             select entity ).ToList();

            this.MyHolidays.DeleteAllOnSubmit(dates);

            if (commitChanges == true)
            {
                this.SubmitChanges();
            }
        }

        internal void ToggleHoliday(DateTime dateTime)
        {
            var dates = (from entity in this.MyHolidays
                         where entity.Date == dateTime
                         select entity).ToList();

            if (dates.Count() >= 1)
            {
                this.MyHolidays.DeleteAllOnSubmit(dates);
            }
            else
            {
                InsertMyHoliday(dateTime, HolidayType.Full);
            }

            this.SubmitChanges();
        }
    }

    public enum HolidayType
    {
        None,
        Full,
        Half,
    }

    [Table]
    public class MyHoliday
    {
        public MyHoliday()
        {
        }

        public MyHoliday(DateTime date, HolidayType type)
        {
            this.Date = date;
            this.Type = type;
        }

        DateTime date;
        [Column(IsPrimaryKey = true, DbType = "DATETIME NOT NULL", CanBeNull = false)]
        public DateTime Date
        {
            get { return date; }
            set { date = value; }
        }

        HolidayType type;
        [Column(DbType = "int NOT NULL", CanBeNull = false)]
        public HolidayType Type
        {
            get { return type; }
            set { type = value; }
        }
    }
}

이렇게 해서 테이블 규격을 정했으니, 이제 데이터베이스를 생성해야 하는데요. 응용 프로그램이 동작하기 위해 무조건 생성되어 있어야 하니 최초에 한 번은 다음과 같이 꼭 실행해 주어야 합니다.

private void CreateDatabase()
{
    using (HolidayContext db = new HolidayContext(HolidayContext.ConnectionString))
    {
        if (db.DatabaseExists() == false)
        {
            db.CreateDatabase();
        }
    }
}

SQL CE 쓰는 방법이 그다지 어렵지 않지요? ^^


3. 격리 저장소의 파일 확인하는 도구

보통, Database 생성하고 나서 사용하다 보면 가볍게 데이터를 확인하고 싶을 때가 있습니다. 물론, 앱에서 그런 역할을 하는 코드를 넣어주어도 되지만 관리 콘솔이 있었으면 좋겠다는 생각이 드는데요.

다행히 약간의 절차를 거치면 확인하는 것이 가능한데, 이를 위해 우선 다음의 도구를 다운로드해야 합니다.

Windows Phone Power Tools  
; http://wptools.codeplex.com/releases/view/73232

"Power Tools"의 "file browser" 탭 영역을 이용하면 해당 앱의 폴더 구조를 볼 수 있습니다.

how_to_dev_holiday_manager_2.png

"GET" 버튼을 누르면 선택된 파일을 PC로 다운로드 할 수 있고, Visual Studio의 "Server Explorer"를 이용하면 다음과 같이 구조를 탐색하는 것이 가능합니다. (그러게요... 이렇게 꼭 확인해 봐야 마음이 놓인다니까요. ^^)

how_to_dev_holiday_manager_3.png




그 외에는, 딱히 떠오르는 '팁' 성격의 항목이 없습니다. 정말 간단한 프로그램이지요. ^^ 아래는 실행 화면! (성태는 올해 2일의 휴가를 냈답니다. ^^)

how_to_dev_holiday_manager_4.png

마지막으로 남은 작업은 '배포'인데,,, 이건 '마켓플레이스'에 정상적으로 등록되고 나면 마저 쓰도록 하겠습니다.

("Holiday Calendar"에 대한 소스 코드는 이 글에 첨부되어 있으니 참고하세요. ^^)




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/23/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [61]  62  63  64  65  66  67  68  69  70  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
12416정성태11/19/202017423오류 유형: 681. Visual C++ - error LNK2001: unresolved external symbol _CrtDbgReport
12415정성태11/18/202017542.NET Framework: 971. UnmanagedCallersOnly 특성과 DNNE 사용파일 다운로드1
12414정성태11/18/202019748VC++: 138. x64 빌드에서 extern "C"가 아닌 경우 ___cdecl name mangling 적용 [4]파일 다운로드1
12413정성태11/17/202018675.NET Framework: 970. .NET 5 / .NET Core - UnmanagedCallersOnly 특성을 사용한 함수 내보내기파일 다운로드1
12412정성태11/16/202020772.NET Framework: 969. .NET Framework 및 .NET 5 - UnmanagedCallersOnly 특성 사용파일 다운로드1
12411정성태11/12/202017540오류 유형: 680. C# 9.0 - Error CS8889 The target runtime doesn't support extensible or runtime-environment default calling conventions.
12410정성태11/12/202017755디버깅 기술: 174. windbg - System.TypeLoadException 예외 분석 사례
12409정성태11/12/202019584.NET Framework: 968. C# 9.0의 Function pointer를 이용한 함수 주소 구하는 방법파일 다운로드1
12408정성태11/9/202034835도서: 시작하세요! C# 9.0 프로그래밍 [8]
12407정성태11/9/202019959.NET Framework: 967. "clr!JIT_DbgIsJustMyCode" 호출이 뭘까요?
12406정성태11/8/202020899.NET Framework: 966. C# 9.0 - (15) 최상위 문(Top-level statements) [5]파일 다운로드1
12405정성태11/8/202018894.NET Framework: 965. C# 9.0 - (14) 부분 메서드에 대한 새로운 기능(New features for partial methods)파일 다운로드1
12404정성태11/7/202019502.NET Framework: 964. C# 9.0 - (13) 모듈 이니셜라이저(Module initializers)파일 다운로드1
12403정성태11/7/202018303.NET Framework: 963. C# 9.0 - (12) foreach 루프에 대한 GetEnumerator 확장 메서드 지원(Extension GetEnumerator)파일 다운로드1
12402정성태11/7/202019868.NET Framework: 962. C# 9.0 - (11) 공변 반환 형식(Covariant return types) [1]파일 다운로드1
12401정성태11/5/202019161VS.NET IDE: 153. 닷넷 응용 프로그램에서의 "My Code" 범위와 "Enable Just My Code"의 역할 [1]
12400정성태11/5/202015330오류 유형: 679. Visual Studio - "Source Not Found" 창에 "Decompile source code" 링크가 없는 경우
12399정성태11/5/202018781.NET Framework: 961. C# 9.0 - (10) 대상으로 형식화된 조건식(Target-typed conditional expressions)파일 다운로드1
12398정성태11/4/202018442오류 유형: 678. Windows Server 2008 R2 환경에서 Powershell을 psexec로 원격 실행할 때 hang이 발생하는 문제
12397정성태11/4/202018489.NET Framework: 960. C# - 조건 연산자(?:)를 사용하는 경우 달라지는 메서드 선택 사례파일 다운로드1
12396정성태11/3/202015430VS.NET IDE: 152. Visual Studio - "Tools" / "External Tools..."에 등록된 외부 명령어에 대한 단축키 설정 방법
12395정성태11/3/202018271오류 유형: 677. SSMS로 DB 접근 시 The server principal "..." is not able to access the database "..." under the current security context.
12394정성태11/3/202015900오류 유형: 676. cacls - The Recycle Bin on ... is corrupted. Do you want to empty the Recycle Bin for this drive?
12393정성태11/3/202015437오류 유형: 675. Visual Studio - 닷넷 응용 프로그램 디버깅 시 Disassembly 창에서 BP 설정할 때 "Error while processing breakpoint." 오류
12392정성태11/2/202019972.NET Framework: 959. C# 9.0 - (9) 레코드(Records) [4]파일 다운로드1
12390정성태11/1/202019743디버깅 기술: 173. windbg - System.Configuration.ConfigurationErrorsException 예외 분석 방법
... [61]  62  63  64  65  66  67  68  69  70  71  72  73  74  75  ...