using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Collections.Generic; using System.Text; using System.IO; /// /// Summary description for ReportParameter /// public class ReportParameter { private SortedList _paramList = new SortedList(); public ReportParameter() { } public void Add(string name, string value) { if (!_paramList.ContainsKey(name)) _paramList.Add(name, value); else _paramList[name] = value; } public void Clear() { _paramList.Clear(); } public string Save(string fileName, bool random) { string realFileName = GetRealFileName(fileName, random); if (File.Exists(realFileName)) File.Delete(realFileName); using (StreamWriter sw = File.CreateText(realFileName)) { for (int i = 0; i < _paramList.Count; i++) { sw.WriteLine(String.Format("{0}={1}", _paramList.Keys[i], _paramList.Values[i])); } sw.Close(); } return realFileName; } /// /// 為檔案名稱加上隨機字尾 /// private string GetRealFileName(string fileName, bool random) { if (!random) return fileName; string ext = Path.GetExtension(fileName); string s = Path.ChangeExtension(fileName, null); do { Random r = new Random(); int suffix = r.Next(int.MaxValue); fileName = String.Format("{0}_{1:x8}{2}", s, suffix, ext); } while (File.Exists(fileName)); return fileName; } }