zoukankan      html  css  js  c++  java
  • 一個簡單的排班方法

    目的:排出 2010年1~12月的A.P.N排班記錄 

    void Main()

    {
    IList<Schedule> schedules = new List<Schedule>();
    int year = 2010;
    int[] months = {1,2,3,4,5,6,7,8,9,10,11,12};
    foreach(int i in months){
    int maxDays = DateTime.DaysInMonth(year, i);
    for(int j=1; j<=maxDays; j++){
    foreach(string n in Enum.GetNames(typeof(ScheduleMode))){
    schedules.Add(new Schedule(){
    Year = year,
    Month = i,
    Date = j,
    Mode = (ScheduleMode)Enum.Parse(typeof(ScheduleMode), n),
    Description = string.Format("Work on {3}, {0}/{1}/{2}", year,i,j, new DateTime(year,i,j).DayOfWeek)
    });
    }
    }
    }
    schedules.Dump();
    }

    // Define other methods and classes here
    public enum ScheduleMode {
    A,P,N
    }
    public class Schedule{
    public int Year {get;set;}
    public int Month {get;set;}
    public int Date {get;set;}
    public ScheduleMode Mode {get;set;}
    public string Description {get;set;}
    }

    //////////////////////////////////////////////////////////////////////////////////////

     這裏隱含了另一個功能,可以通過Enum.GetNames(typeof(ScheduleMode))獲得枚舉類型的各項名稱(用於綁定到UI界面),還可以通過(ScheduleMode)Enum.Parse(typeof(ScheduleMode), n)將某個字符串轉換成枚舉類型(用於從數據庫查詢到的值轉換成枚舉類型),這樣我們就可以很方便地將數據庫中的查詢到的值轉換成“預先”定義好的枚舉類型(可以有“名稱”和“值”)。

  • 相关阅读:
    Dotfuscator 保护您的应用程序
    IOS 类方法
    播放音乐与视频
    windows phone 手机信息的查看
    更改枢轴视图的Item字的大小
    IOS 总结
    Windows Phone 中HttpWebRequest用法
    关于Listbox的 SelectionChanged 事件 (同一个Item只触发一次问题)
    windows phone 标准色值
    IOS GPS 定位
  • 原文地址:https://www.cnblogs.com/Koy/p/1784063.html
Copyright © 2011-2022 走看看