Skip to content

Commit 9fb7d54

Browse files
committed
Updated 2022-5-14
Updated 2022-5-14
1 parent aeade4d commit 9fb7d54

File tree

143 files changed

+29159
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+29159
-11
lines changed

CsharpLibs/README.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

CsharpLibs/packages.config

Lines changed: 0 additions & 9 deletions
This file was deleted.

Notested/ASPXMVCMap.rar

30.4 MB
Binary file not shown.

Notested/CNBlogs.UWP-master.zip

4.64 MB
Binary file not shown.

Notested/CSharpJson.rar

27.9 KB
Binary file not shown.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
using System;
2+
using System.Web.UI.WebControls;
3+
using System.IO;
4+
using System.Web.UI;
5+
6+
namespace DotNet.Utilities
7+
{
8+
public class BasePage :System.Web.UI.Page
9+
{
10+
public BasePage()
11+
{
12+
//
13+
//TODO: 在此处添加构造函数逻辑
14+
//
15+
}
16+
17+
public static string Title = "标题";
18+
public static string keywords = "关键字";
19+
public static string description = "网站描述";
20+
21+
protected override void OnInit(EventArgs e)
22+
{
23+
if (Session["admin"] == null || Session["admin"].ToString().Trim() == "")
24+
{
25+
Response.Redirect("login.aspx");
26+
}
27+
base.OnInit(e);
28+
}
29+
30+
protected void ExportData(string strContent, string FileName)
31+
{
32+
33+
FileName = FileName + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
34+
35+
Response.Clear();
36+
Response.Charset = "gb2312";
37+
Response.ContentType = "application/ms-excel";
38+
Response.ContentEncoding = System.Text.Encoding.UTF8;
39+
//this.Page.EnableViewState = false;
40+
// 添加头信息,为"文件下载/另存为"对话框指定默认文件名
41+
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".xls");
42+
// 把文件流发送到客户端
43+
Response.Write("<html><head><meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">");
44+
Response.Write(strContent);
45+
Response.Write("</body></html>");
46+
// 停止页面的执行
47+
//Response.End();
48+
}
49+
50+
/// <summary>
51+
/// 导出Excel
52+
/// </summary>
53+
/// <param name="obj"></param>
54+
public void ExportData(GridView obj)
55+
{
56+
try
57+
{
58+
string style = "";
59+
if (obj.Rows.Count > 0)
60+
{
61+
style = @"<style> .text { mso-number-format:\@; } </script> ";
62+
}
63+
else
64+
{
65+
style = "no data.";
66+
}
67+
68+
Response.ClearContent();
69+
DateTime dt = DateTime.Now;
70+
string filename = dt.Year.ToString() + dt.Month.ToString() + dt.Day.ToString() + dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString();
71+
Response.AddHeader("content-disposition", "attachment; filename=ExportData" + filename + ".xls");
72+
Response.ContentType = "application/ms-excel";
73+
Response.Charset = "GB2312";
74+
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
75+
StringWriter sw = new StringWriter();
76+
HtmlTextWriter htw = new HtmlTextWriter(sw);
77+
obj.RenderControl(htw);
78+
Response.Write(style);
79+
Response.Write(sw.ToString());
80+
Response.End();
81+
}
82+
catch
83+
{
84+
}
85+
}
86+
}
87+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Web.UI.WebControls;
2+
using System.Web.UI;
3+
using System.Data;
4+
using System.Data.SqlClient;
5+
6+
namespace DotNet.Utilities
7+
{
8+
/// <summary>
9+
/// 数据展示控件 绑定数据类
10+
/// </summary>
11+
public class BindDataControl
12+
{
13+
#region 绑定服务器数据控件 简单绑定DataList
14+
/// <summary>
15+
/// 简单绑定DataList
16+
/// </summary>
17+
/// <param name="ctrl">控件ID</param>
18+
/// <param name="mydv">数据视图</param>
19+
public static void BindDataList(Control ctrl, DataView mydv)
20+
{
21+
((DataList)ctrl).DataSourceID = null;
22+
((DataList)ctrl).DataSource = mydv;
23+
((DataList)ctrl).DataBind();
24+
}
25+
#endregion
26+
27+
#region 绑定服务器数据控件 SqlDataReader简单绑定DataList
28+
/// <summary>
29+
/// SqlDataReader简单绑定DataList
30+
/// </summary>
31+
/// <param name="ctrl">控件ID</param>
32+
/// <param name="mydv">数据视图</param>
33+
public static void BindDataReaderList(Control ctrl, SqlDataReader mydv)
34+
{
35+
((DataList)ctrl).DataSourceID = null;
36+
((DataList)ctrl).DataSource = mydv;
37+
((DataList)ctrl).DataBind();
38+
}
39+
#endregion
40+
41+
#region 绑定服务器数据控件 简单绑定 GridView
42+
/// <summary>
43+
/// 简单绑定GridView
44+
/// </summary>
45+
/// <param name="ctrl">控件ID</param>
46+
/// <param name="mydv">数据视图</param>
47+
public static void BindGridView(Control ctrl, DataView mydv)
48+
{
49+
((GridView)ctrl).DataSourceID = null;
50+
((GridView)ctrl).DataSource = mydv;
51+
((GridView)ctrl).DataBind();
52+
}
53+
#endregion
54+
55+
/// <summary>
56+
/// 绑定服务器控件 简单绑定Repeater
57+
/// </summary>
58+
/// <param name="ctrl">控件ID</param>
59+
/// <param name="mydv">数据视图</param>
60+
public static void BindRepeater(Control ctrl, DataView mydv)
61+
{
62+
((Repeater)ctrl).DataSourceID = null;
63+
((Repeater)ctrl).DataSource = mydv;
64+
((Repeater)ctrl).DataBind();
65+
}
66+
}
67+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using System.Data;
2+
using System.IO;
3+
4+
namespace DotNet.Utilities
5+
{
6+
/// <summary>
7+
/// CSV文件转换类
8+
/// </summary>
9+
public static class CsvHelper
10+
{
11+
/// <summary>
12+
/// 导出报表为Csv
13+
/// </summary>
14+
/// <param name="dt">DataTable</param>
15+
/// <param name="strFilePath">物理路径</param>
16+
/// <param name="tableheader">表头</param>
17+
/// <param name="columname">字段标题,逗号分隔</param>
18+
public static bool dt2csv(DataTable dt, string strFilePath, string tableheader, string columname)
19+
{
20+
try
21+
{
22+
string strBufferLine = "";
23+
StreamWriter strmWriterObj = new StreamWriter(strFilePath, false, System.Text.Encoding.UTF8);
24+
strmWriterObj.WriteLine(tableheader);
25+
strmWriterObj.WriteLine(columname);
26+
for (int i = 0; i < dt.Rows.Count; i++)
27+
{
28+
strBufferLine = "";
29+
for (int j = 0; j < dt.Columns.Count; j++)
30+
{
31+
if (j > 0)
32+
strBufferLine += ",";
33+
strBufferLine += dt.Rows[i][j].ToString();
34+
}
35+
strmWriterObj.WriteLine(strBufferLine);
36+
}
37+
strmWriterObj.Close();
38+
return true;
39+
}
40+
catch
41+
{
42+
return false;
43+
}
44+
}
45+
46+
/// <summary>
47+
/// 将Csv读入DataTable
48+
/// </summary>
49+
/// <param name="filePath">csv文件路径</param>
50+
/// <param name="n">表示第n行是字段title,第n+1行是记录开始</param>
51+
public static DataTable csv2dt(string filePath, int n, DataTable dt)
52+
{
53+
StreamReader reader = new StreamReader(filePath, System.Text.Encoding.UTF8, false);
54+
int i = 0, m = 0;
55+
reader.Peek();
56+
while (reader.Peek() > 0)
57+
{
58+
m = m + 1;
59+
string str = reader.ReadLine();
60+
if (m >= n + 1)
61+
{
62+
string[] split = str.Split(',');
63+
64+
System.Data.DataRow dr = dt.NewRow();
65+
for (i = 0; i < split.Length; i++)
66+
{
67+
dr[i] = split[i];
68+
}
69+
dt.Rows.Add(dr);
70+
}
71+
}
72+
return dt;
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)