為什么80%的碼農都做不了架構師?>>> ??
??? /// <summary>
??? /// CSV出力ボタンラッパー。
??? /// </summary>
??? public class CsvOutputButtonWrapper
??? {
??????? /// <summary>
??????? /// CSV出力ボタン
??????? /// </summary>
??????? private Button btnOutputCsv;
??????? /// <summary>
??????? /// CSVファイル名
??????? /// </summary>
??????? private string csvFileName;
??????? /// <summary>
??????? /// ヘッダー行
??????? /// </summary>
??????? private GridViewRow headerRow;
??????? /// <summary>
??????? /// HttpResponse
??????? /// </summary>
??????? HttpResponse response;
??????? /// <summary>
??????? /// 検索條件をCSV形式へ変換するイベントハンドル
??????? /// </summary>
??????? /// <returns></returns>
??????? public delegate string ConvertConditionEventHandler();
??????? /// <summary>
??????? /// 一覧データをCSV形式へ変換するイベントハンドル
??????? /// </summary>
??????? /// <returns></returns>
??????? public delegate string ConvertListEventHandler();
??????? /// <summary>
??????? /// 検索條件をCSV形式へ変換するイベント
??????? /// </summary>
??????? public event ConvertConditionEventHandler ConvertCondition;
??????? /// <summary>
??????? /// 一覧データをCSV形式へ変換するイベント
??????? /// </summary>
??????? public event ConvertListEventHandler ConvertList;
??????? /// <summary>
??????? /// CSVボタンのクリックイベント
??????? /// </summary>
??????? /// <param name="sender"></param>
??????? /// <param name="e"></param>
??????? private void btnOutputCsv_Click(object sender, EventArgs e)
??????? {
??????????? // CSVファイルを生成し、出力する
??????????? FileUtil.OutputCSV(response, this.csvFileName, CreateCSVFile());
??????? }
??????? /// <summary>
??????? /// CSV出力ファイルの內容を作る
??????? /// </summary>
??????? /// <returns></returns>
??????? private byte[] CreateCSVFile()
??????? {
??????????? StringBuilder sb = new StringBuilder();
??????????? Encoding encoding = Encoding.GetEncoding("Shift-JIS");
??????????? if (this.ConvertCondition != null)
??????????? {
??????????????? // 検索條件
??????????????? sb.Append(this.ConvertCondition());
??????????????? // 空行
??????????????? sb.AppendLine(string.Empty);
??????????? }
??????????? if (this.ConvertList != null)
??????????? {
??????????????? // グリッドのヘッダー行
??????????????? if (this.headerRow != null)
??????????????????? sb.AppendLine(PageUtil.ConvertGridViewHeaderToCSV(this.headerRow));
??????????????? // グリッドのデータ行
??????????????? sb.Append(this.ConvertList());
??????????? }
??????????? return encoding.GetBytes(sb.ToString());
??????? }
??????? /// <summary>
??????? /// コンストラクタ
??????? /// </summary>
??????? /// <param name="btnOutputCsv">CSV出力ボタン</param>
??????? /// <param name="csvFileName">CSVファイル名</param>
??????? /// <param name="headerRow">ヘッダー行</param>
??????? /// <param name="response">HttpResponse</param>
??????? public CsvOutputButtonWrapper(Button btnOutputCsv, string csvFileName, GridViewRow headerRow, HttpResponse response)
??????? {
??????????? this.btnOutputCsv = btnOutputCsv;
??????????? this.csvFileName = csvFileName;
??????????? this.headerRow = headerRow;
??????????? this.response = response;
??????????? this.btnOutputCsv.Click += new EventHandler(btnOutputCsv_Click);
??????? }
??? }