• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Asp.net常用的操作函数

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

 

        /// <summary>
        /// 取得本周第一天的日期,即星期日
        /// </summary>
        /// <returns></returns>
        public static string GetWeekFirstDate()
        {
            
return DateTime.Now.AddDays(Convert.ToDouble((0 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
        }
        
/// <summary>
        /// 取得本周最后一天的日期
        /// </summary>
        /// <returns></returns>
        public static string GetWeekLastDate()
        {
            
return DateTime.Now.AddDays(Convert.ToDouble((6 - Convert.ToInt16(DateTime.Now.DayOfWeek)))).ToShortDateString();
        }
        
/// <summary>
        /// 转换成Long型,错误返回-1
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static long ConvertToLong(object value)
        {
            
long id = -1;
            
long.TryParse(value.ToString(), out id);
            
return id;
        }
        
/// <summary>
        /// 转换成Double型,错误返回-1
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double ConvertToDouble(object value)
        {
            
double id = -1;
            
double.TryParse(value.ToString(), out id);
            
return id;
        }
        
/// <summary>
        /// 转换成Int型,-1转换错误
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static int ConvertToInt(object value)
        {
            
int id = -1;
            
int.TryParse(value.ToString(), out id);
            
return id;
        }
        
/// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="dt"></param>
        /// <param name="strText"></param>
        /// <param name="strValue"></param>
        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();
        }
        
/// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="dt"></param>
        /// <param name="strText"></param>
        /// <param name="strValue"></param>
        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();
        }
        
/// <summary>
        /// 绑定数据到ListControl
        /// </summary>
        /// <param name="lc"></param>
        /// <param name="FirstText"></param>
        /// <param name="FirstValue"></param>
        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());
            }
        }
        
/// <summary>
        ///根据指定值选定控件中中的项
        /// </summary>
        /// <param name="rbl">控件名</param>
        /// <param name="flg">指定值</param>
        /// <returns></returns>
        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;
        }
        
/// <summary>
        ///根据指定值选定控件中中的项
        /// </summary>
        /// <param name="rbl">控件名</param>
        /// <param name="flg">指定值</param>
        /// <returns></returns>
        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;
                        }
                    }
                }
            }
        }
        
/// <summary>
        ///根据指定值选定控件中中的项
        /// </summary>
        /// <param name="rbl">控件名</param>
        /// <param name="flg">指定值</param>
        /// <returns></returns>
        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(01);
            
return strValue.Split(';');
        }
        
/// <summary>
        ///根据指定值选定控件中中的项
        /// </summary>
        /// <param name="rbl">控件名</param>
        /// <param name="flg">指定值</param>
        /// <returns></returns>
        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;
        }
        
///<summary>
        ///根据指定值选定控件中中的项
        /// </summary>
        /// <param name="rbl">控件名</param>
        /// <param name="flg">指定值</param>
        /// <returns></returns>
        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;
        }
        
/// <summary>
        /// 将字符串转换为日期
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        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;
            }
        }
    
        
/// <summary>
        /// 将表中指定的一个字段构造成数组
        /// </summary>
        /// <param name="_SetUpedTable">Table</param>
        //

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
性能工具MiniProfiler在Asp.Net WebForm跟踪EntityFramework发布时间:2022-07-10
下一篇:
ASP.NET中实现简单访问统计计数器发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap