Files
sryang 577060bc78 chore: 首次簽入 Thinkyu ASP.NET 專案
- 加入 Visual Studio / ASP.NET .gitignore
- 排除建置輸出、IDE 設定、NuGet packages、大型 MSI 安裝檔
2026-09-10 09:42:37 +08:00

76 lines
1.7 KiB
C#

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>
/// Summary description for ReportParameter
/// </summary>
public class ReportParameter
{
private SortedList<string, string> _paramList = new SortedList<string, string>();
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;
}
/// <summary>
/// 為檔案名稱加上隨機字尾
/// </summary>
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;
}
}