日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

CSV出力ボタンラッパー(asp.net)[イベントの作り方に役立つ]

發布時間:2023/12/10 asp.net 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CSV出力ボタンラッパー(asp.net)[イベントの作り方に役立つ] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么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);
??????? }
??? }

轉載于:https://my.oschina.net/cjkall/blog/195902

總結

以上是生活随笔為你收集整理的CSV出力ボタンラッパー(asp.net)[イベントの作り方に役立つ]的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。