设计师自我修养左佐pdf:Asp.net常用的操作函数-程序开发-红黑联盟
来源:百度文库 编辑:九乡新闻网 时间:2024/09/21 09:05:14
Asp.net常用的操作函数
文章录入:7747.Net 责任编辑:7747.Net 18
【字体:小 大】
///
/// 取得本周第一天的日期,即星期日
///
///
public static string GetWeekFirstDate()
{
return DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString(); } ///
/// 取得本周最后一天的日期
///
///
public static string GetWeekLastDate()
{
return DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
} ///
/// 转换成Long型,错误返回-1
///
///
///
public static long ConvertToLong(object value)
{
long id = -1;
long.TryParse(value.ToString(), out id);
return id;
}
///
/// 转换成Double型,错误返回-1
///
///
///
public static double ConvertToDouble(object value)
{
double id = -1;
double.TryParse(value.ToString(), out id);
return id;
} ///
/// 转换成Int型,-1转换错误
///
///
///
public static int ConvertToInt(object value)
{
int id = -1;
int.TryParse(value.ToString(), out id);
return id;
}
///
/// 绑定数据到ListControl
///
///
///
///
///
public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue)
{
lc.Items.Clear(); foreach (DataRow myRow in dt.Rows)
{
lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
}
lc.DataBind();
} ///
/// 绑定数据到ListControl
///
///
///
///
///
public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue, string FirstText, string FirstValue)
{
lc.Items.Clear();
lc.Items.Add(new ListItem(FirstText, FirstValue));
foreach (DataRow myRow in dt.Rows)
{
lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
}
lc.DataBind();
} ///
/// 绑定数据到ListControl
///
///
///
///
public static void BindDrop(ListControl lc, string FirstText, string FirstValue)
{
lc.Items.Clear();
lc.Items.Add(new ListItem(FirstText, FirstValue));
lc.DataBind();
}
public static void BindDataDrop(ListControl list, int iBegin, int iEnd)
{
list.Items.Clear();
int count = iEnd - iBegin;
for (int i = iBegin; i <= iEnd; i++)
{
list.Items.Add(i.ToString());
}
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectFlg(ListControl rbl, string flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Value.Trim() == flg.Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static void SelectFlg(ListControl rbl, DataTable dt, string ColumnName)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
foreach (DataRow row in dt.Rows)
{
string flg = row[ColumnName].ToString();
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{ if (rbl.Items[i].Value.Trim() == flg.Trim())
{
isSelect = true;
rbl.Items[i].Selected = true; }
}
}
}
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static string[] GetDropSelect(ListControl rbl)
{
//rbl.Items
string strValue = "";
int FlgCount = rbl.Items.Count;
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Selected)
{
strValue += ";" + rbl.Items[i].Value;
//rbl.SelectedIndex = i;
}
}
strValue = strValue.Remove(0, 1);
return strValue.Split(';');
} ///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectFlg(ListControl rbl, object flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Value.Trim() == flg.ToString().Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectText(ListControl rbl, string flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Text.Trim() == flg.Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
/// 将字符串转换为日期
///
///
///
public static DateTime ParseDateTime(string p)
{
try
{
if (p != string.Empty)
{
return Convert.ToDateTime(p);
}
else
{
return DateTime.MinValue;
}
}
catch (Exception err)
{
return DateTime.Now;
}
}
///
/// 将表中指定的一个字段构造成数组
///
/// Table
/// 指定的字段
///
public static string[] AddTableColumnToArrayMethod(DataTable _SetUpedTable, string column)
{
string[] setUpArray = new string[_SetUpedTable.Rows.Count];
for (int i = 0; i < setUpArray.Length; i++)
{
setUpArray[i] = _SetUpedTable.Rows[i][column].ToString();
}
return setUpArray;
}
///
/// 是否为日期型字符串
///
/// 日期字符串(2008-05-08)
///
public static bool IsDate(string StrSource)
{
return Regex.IsMatch(StrSource, @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
} ///
/// 是否为时间型字符串
///
/// 时间字符串(15:00:00)
///
public static bool IsTime(string StrSource)
{
return Regex.IsMatch(StrSource, @"^((20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$");
} ///
/// 是否为日期+时间型字符串
///
///
///
public static bool IsDateTime(string StrSource)
{
return Regex.IsMatch(StrSource, @"^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$ ");
}
///
/// 在指定的目录写入文件
///
/// 文件夹的路径
/// 写入的文本内容
/// 写入的文本文件名称
public static void WriteFile(string driectory, string content, string fileName)
{
CreateDirectory(driectory);
FileStream fs = new FileStream(driectory + fileName, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(content + "\n");
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close();
} ///
/// 递归创建文件夹
///
/// 文件夹的路径
private static void CreateDirectory(string directoryName)
{
string sParentDirectory = Path.GetDirectoryName(directoryName);
if (!Directory.Exists(sParentDirectory))
CreateDirectory(sParentDirectory);
if (!Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
} 摘自红色黑客联盟(www.7747.net) 原文:http://www.7747.net/kf/201103/86637.html
文章录入:7747.Net 责任编辑:7747.Net 18
【字体:小 大】
///
/// 取得本周第一天的日期,即星期日
///
///
public static string GetWeekFirstDate()
{
return DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString(); } ///
/// 取得本周最后一天的日期
///
///
public static string GetWeekLastDate()
{
return DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
} ///
/// 转换成Long型,错误返回-1
///
///
///
public static long ConvertToLong(object value)
{
long id = -1;
long.TryParse(value.ToString(), out id);
return id;
}
///
/// 转换成Double型,错误返回-1
///
///
///
public static double ConvertToDouble(object value)
{
double id = -1;
double.TryParse(value.ToString(), out id);
return id;
} ///
/// 转换成Int型,-1转换错误
///
///
///
public static int ConvertToInt(object value)
{
int id = -1;
int.TryParse(value.ToString(), out id);
return id;
}
///
/// 绑定数据到ListControl
///
///
///
///
///
public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue)
{
lc.Items.Clear(); foreach (DataRow myRow in dt.Rows)
{
lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
}
lc.DataBind();
} ///
/// 绑定数据到ListControl
///
///
///
///
///
public static void BindDrop(ListControl lc, DataTable dt, string strText, string strValue, string FirstText, string FirstValue)
{
lc.Items.Clear();
lc.Items.Add(new ListItem(FirstText, FirstValue));
foreach (DataRow myRow in dt.Rows)
{
lc.Items.Add(new ListItem(myRow[strText].ToString(), myRow[strValue].ToString()));
}
lc.DataBind();
} ///
/// 绑定数据到ListControl
///
///
///
///
public static void BindDrop(ListControl lc, string FirstText, string FirstValue)
{
lc.Items.Clear();
lc.Items.Add(new ListItem(FirstText, FirstValue));
lc.DataBind();
}
public static void BindDataDrop(ListControl list, int iBegin, int iEnd)
{
list.Items.Clear();
int count = iEnd - iBegin;
for (int i = iBegin; i <= iEnd; i++)
{
list.Items.Add(i.ToString());
}
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectFlg(ListControl rbl, string flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Value.Trim() == flg.Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static void SelectFlg(ListControl rbl, DataTable dt, string ColumnName)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
foreach (DataRow row in dt.Rows)
{
string flg = row[ColumnName].ToString();
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{ if (rbl.Items[i].Value.Trim() == flg.Trim())
{
isSelect = true;
rbl.Items[i].Selected = true; }
}
}
}
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static string[] GetDropSelect(ListControl rbl)
{
//rbl.Items
string strValue = "";
int FlgCount = rbl.Items.Count;
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Selected)
{
strValue += ";" + rbl.Items[i].Value;
//rbl.SelectedIndex = i;
}
}
strValue = strValue.Remove(0, 1);
return strValue.Split(';');
} ///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectFlg(ListControl rbl, object flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Value.Trim() == flg.ToString().Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
///根据指定值选定控件中中的项
///
/// 控件名
/// 指定值
///
public static bool SelectText(ListControl rbl, string flg)
{
bool isSelect = false;
int FlgCount = rbl.Items.Count;
if (flg == null)
{
flg = "";
}
if (flg != null)
{
for (int i = 0; i <= FlgCount - 1; i++)
{
if (rbl.Items[i].Text.Trim() == flg.Trim())
{
isSelect = true;
rbl.SelectedIndex = i;
break;
}
}
}
return isSelect;
}
///
/// 将字符串转换为日期
///
///
///
public static DateTime ParseDateTime(string p)
{
try
{
if (p != string.Empty)
{
return Convert.ToDateTime(p);
}
else
{
return DateTime.MinValue;
}
}
catch (Exception err)
{
return DateTime.Now;
}
}
///
/// 将表中指定的一个字段构造成数组
///
/// Table
/// 指定的字段
///
public static string[] AddTableColumnToArrayMethod(DataTable _SetUpedTable, string column)
{
string[] setUpArray = new string[_SetUpedTable.Rows.Count];
for (int i = 0; i < setUpArray.Length; i++)
{
setUpArray[i] = _SetUpedTable.Rows[i][column].ToString();
}
return setUpArray;
}
///
/// 是否为日期型字符串
///
/// 日期字符串(2008-05-08)
///
public static bool IsDate(string StrSource)
{
return Regex.IsMatch(StrSource, @"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-9]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
} ///
/// 是否为时间型字符串
///
/// 时间字符串(15:00:00)
///
public static bool IsTime(string StrSource)
{
return Regex.IsMatch(StrSource, @"^((20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$");
} ///
/// 是否为日期+时间型字符串
///
///
///
public static bool IsDateTime(string StrSource)
{
return Regex.IsMatch(StrSource, @"^(((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d)$ ");
}
///
/// 在指定的目录写入文件
///
/// 文件夹的路径
/// 写入的文本内容
/// 写入的文本文件名称
public static void WriteFile(string driectory, string content, string fileName)
{
CreateDirectory(driectory);
FileStream fs = new FileStream(driectory + fileName, FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(content + "\n");
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close();
} ///
/// 递归创建文件夹
///
/// 文件夹的路径
private static void CreateDirectory(string directoryName)
{
string sParentDirectory = Path.GetDirectoryName(directoryName);
if (!Directory.Exists(sParentDirectory))
CreateDirectory(sParentDirectory);
if (!Directory.Exists(directoryName))
Directory.CreateDirectory(directoryName);
} 摘自红色黑客联盟(www.7747.net) 原文:http://www.7747.net/kf/201103/86637.html
Asp.net常用的操作函数-程序开发-红黑联盟
10个常用方法有效优化ASP.NET的性能-程序开发-红黑联盟
Asp.Nne 编程常用的二十六个函数详解-程序开发-红黑联盟
介绍asp.net正则表达式的组集合-程序开发-红黑联盟
掌握Asp.Net编程语言的九大步骤-程序开发-红黑联盟
Asp.net网站性能优化二则-程序开发-红黑联盟
提高网站速度:ASP.NET缓存详解-程序开发-红黑联盟
C#反射的理解-程序开发-红黑联盟
使用C#多线程设计的电脑摇奖程序-程序开发-红黑联盟
用设计模式固化你的C#程序(2)-程序开发-红黑联盟
用设计模式固化你的C#程序(3)-程序开发-红黑联盟
多线程下载(FtpWebRequest)-程序开发-红黑联盟
C# Socket多线程编程实例-程序开发-红黑联盟
c#泛型和反射的设计应用-程序开发-红黑联盟
asp.net网站开发程序规范 - 解决方案
到底是什么反射,泛型,委托,泛型-程序开发-红黑联盟
C# 清理IE缓存文件实例代码-程序开发-红黑联盟
C# 清理Cookies文件实例代码-程序开发-红黑联盟
掌握Asp.Net编程语言的九大步骤-程序开发
asp.net 开发快捷键
ASP.NET一些常用的技巧
常用的ASP连接数据库的函数
ADO.NET操作存储过程 - 小云子、asp.net开发学习笔记 - CSDN博客
ASP.NET页面生命周期与应用程序生命周期 - 程序开发技术博客 - CSDN博客