첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;
using System.Collections;
using System.ServiceModel;

/// <summary>
/// 서점 인터페이스
/// </summary>
[ServiceContract(Namespace = "http://noname.com/bookstore", Name = "IMyBookStore")]
interface IBookStore
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Method

    #region 주문하기 - Order(userID, isbn, amount)

    /// <summary>
    /// 주문하기
    /// </summary>
    /// <param name="userID">사용자 ID</param>
    /// <param name="isbn">ISBN</param>
    /// <param name="amount">수량</param>
    /// <returns>주문 ID</returns>
    [OperationContract(Name="PlaceOrder")]
    int Order(string userID, string isbn, int amount);

    #endregion

    #region 취소하기 - Cancel(orderID)

    /// <summary>
    /// 취소하기
    /// </summary>
    /// <param name="orderID">주문 ID</param>
    /// <returns>처리 결과</returns>
    [OperationContract(Name="CancelOrder")]
    bool Cancel(int orderID);

    #endregion

    #region 검색하기 - Search(title)

    /// <summary>
    /// 검색하기
    /// </summary>
    /// <param name="title">제목</param>
    /// <returns>제목 배열</returns>
    [OperationContract(Name="SearchByTitle")]
    string[] Search(string searchTitle);

    #endregion

    #region 검색하기 - Search(title, author)

    /// <summary>
    /// 검색하기
    /// </summary>
    /// <param name="title">제목</param>
    /// <param name="author">저자</param>
    /// <returns>제목 배열</returns>
    [OperationContract(Name="SearchByTitleAndAuthor")]
    string[] Search(string title, string author);

    #endregion
}

/// <summary>
/// 서점 서비스
/// </summary>
[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class BookStoreService : IBookStore
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Static
    //////////////////////////////////////////////////////////////////////////////// Private

    #region Field

    /// <summary>
    /// 주문 ID
    /// </summary>
    private static int _orderID = 0;

    /// <summary>
    /// 제목 배열
    /// </summary>
    private static string[] _titleArray = new string[] { "도서 1", "도서 2", "도서 3" };

    /// <summary>
    /// 저자 배열
    /// </summary>
    private static string[] _authorArray = new string[] { "저자 1", "저자 2", "저자 3" };

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 주문하기 - Order(userID, isbn, amount)

    /// <summary>
    /// 주문하기
    /// </summary>
    /// <param name="userID">사용자 ID</param>
    /// <param name="isbn">ISBN</param>
    /// <param name="amount">수량</param>
    /// <returns>주문 ID</returns>
    public int Order(string userID, string isbn, int amount)
    {
        int price = GetUnitPrice(isbn) * amount;

        _orderID += 1;

        Console.WriteLine
        (
            "도서 주문 : 주문 ID={0}\n            사용자 ID={1}, ISBN={2}, 수량={3}, 가격={4}",
            _orderID,
            userID,
            isbn,
            amount,
            price
        );

        return _orderID;
    }

    #endregion

    #region 취소하기 - Cancel(orderID)

    /// <summary>
    /// 취소하기
    /// </summary>
    /// <param name="orderID">주문 ID</param>
    /// <returns>처리 결과</returns>
    public bool Cancel(int orderID)
    {
        Console.WriteLine("취소 주문 : 주문 ID={0}", orderID);

        return true;
    }

    #endregion

    #region 검색하기 - Search(title)

    /// <summary>
    /// 검색하기
    /// </summary>
    /// <param name="title">제목</param>
    /// <returns>제목 배열</returns>
    public string[] Search(string title)
    {
        ArrayList arrayList = new ArrayList();

        for(int i = 0; i < _titleArray.Length; i++)
        {
            if(_titleArray[i].StartsWith(title) == true)
            {
                arrayList.Add(_titleArray[i]);
            }
        }

        return (string[])arrayList.ToArray(typeof(string));
    }

    #endregion

    #region 검색하기 - Search(title, author)

    /// <summary>
    /// 검색하기
    /// </summary>
    /// <param name="title">제목</param>
    /// <param name="author">저자</param>
    /// <returns>제목 배열</returns>
    public string[] Search(string title, string author)
    {
        ArrayList arrayList = new ArrayList();

        for(int i = 0; i < _titleArray.Length; i++)
        {
            if(_titleArray[i].StartsWith(title) == true && _authorArray[i].StartsWith(author))
            {
                arrayList.Add(_titleArray[i]);
            }
        }

        return (string[])arrayList.ToArray(typeof(string));
    }

    #endregion

    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region 단가 구하기 - GetUnitPrice(isbn)

    /// <summary>
    /// 단가 구하기
    /// </summary>
    /// <param name="isbn">ISBN</param>
    /// <returns>단가</returns>
    private int GetUnitPrice(string isbn)
    {
        return 35000;
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요