using System; namespace DPExample { class GameRole { // 生命力 private int vit; public int Vitality { get { return vit; } set { vit = value; } } // 攻擊力 private int atk; public int Attack { get { return atk; } set { atk = value; } } // 防禦力 private int def; public int Defense { get { return def; } set { def = value; } } // 狀態顯示 public void StateDisplay() { Console.WriteLine ("角色當前狀態:"); Console.WriteLine ("體力:{0}", this.vit); Console.WriteLine ("攻擊力:{0}", this.atk); Console.WriteLine ("防禦力:{0}", this.def); Console.WriteLine (""); } // 獲得初始狀態 public void GetInitState() { this.vit = 100; this.atk = 100; this.def = 100; } // 戰鬥 public void Fight() { if (this.vit > 0) this.vit -= 20; if (this.atk > 0) this.atk -= 20; if (this.def > 0) this.def -= 20; } // 保存角色狀態 public RoleStateMemento SaveState() { return (new RoleStateMemento(vit, atk, def)); } // 恢復角色狀態 public void RecoveryState(RoleStateMemento memento) { this.vit = memento.Vitality; this.atk = memento.Attack; this.def = memento.Defense; } } // 角色狀態儲存箱 class RoleStateMemento { private int vit; public int Vitality { get { return vit; } set { vit = value; } } private int atk; public int Attack { get { return atk; } set { atk = value; } } private int def; public int Defense { get { return def; } set { def = value; } } public RoleStateMemento (int vit, int atk, int def) { this.vit = vit; this.atk = atk; this.def = def; } } // 角色狀態管理者 class RoleStateCaretaker { private RoleStateMemento memento; public RoleStateMemento Memento { get { return memento; } set { memento = value; } } } }
前由 我有全區的電話資料,問題在於我要依不同里別來製作出電話簿。結果如下圖: 單純採用合併列印無法達成我的需求。解決方法係用「功能變數」儲存上一個里別,與現在里別進行比較:若不同,則換頁。不過,這樣功能變數還蠻長的。最後,我還是採用 C# 來解決。 解決方案 用 C# 控制 WORD 中合併列印的「資料來源 Data Source」,給予不同里別的「sqlstatement」。迴圈處理不同的里別即可。但可預見其處理過程會很慢,不過還好,我可以不用在意它,有跑出結果即可。 程式碼 IList<string> areas = new List<string>() { "後壁", "侯伯", "嘉苳", "土溝", "嘉田", "嘉民", "菁豊", "崁頂", "後廍", "墨林", "菁寮", "新嘉", "頂長", "平安", "仕安", "竹新", "新東", "長安", "頂安", "福安", "烏樹" }; string root = @"D:\"; // 根目錄 string data = root + @"\data.docm"; // 資料檔(即資料來源) string template = root + @"\template.docx"; // 已設定好格式與合併欄位的 Word 檔 string output = @"d:\Final"; // 輸出之資料夾 object oMissing = System.Reflection.Missing.Va...
留言
張貼留言