在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <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(0, 1); 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> // |
请发表评论