动态组合SQL语句方式实现批量更新
2013-03-11 04:21
393 查看
View Code
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; //引入如下命名空间 using System.Text.RegularExpressions; using System.Text; /// <summary> ///StrHelper 的摘要说明 /// </summary> public class StrHelper { public StrHelper(){} /// <summary> /// 截取字符串函数 /// </summary> /// <param name="str">所要截取的字符串</param> /// <param name="num">截取字符串的长度</param> /// <returns></returns> static public string GetSubString(string str, int num) { #region return (str.Length > num) ? str.Substring(0, num) + "..." : str; #endregion } /// <summary> /// 截取字符串优化版 /// </summary> /// <param name="stringToSub">所要截取的字符串</param> /// <param name="length">截取字符串的长度</param> /// <returns></returns> public static string GetFirstString(string stringToSub, int length) { #region Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled); char[] stringChar = stringToSub.ToCharArray(); StringBuilder sb = new StringBuilder(); int nLength = 0; bool isCut = false; for (int i = 0; i < stringChar.Length; i++) { if (regex.IsMatch((stringChar[i]).ToString()))//regex.IsMatch指示正则表达式在输入字符串中是否找到匹配项 { sb.Append(stringChar[i]);//将信息追加到当前 StringBuilder 的结尾 nLength += 2; } else { sb.Append(stringChar[i]); nLength = nLength + 1; } if (nLength > length)//替换字符串 { isCut = true; break; } } if (isCut) return sb.ToString() + "..."; else return sb.ToString(); #endregion } /// 弹出JavaScript小窗口 /// </summary> /// <param name="js">窗口信息</param> public static void Alert(string message) { #region string js = @"<Script language='JavaScript'> alert('" + message + "');</Script>"; HttpContext.Current.Response.Write(js); #endregion } public static void GridViewHeader(GridView gdv)//显示表头并显示没有数据的提示信息 { //表头的设置 GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); foreach (DataControlField field in gdv.Columns) { TableCell cell = new TableCell(); cell.Text = field.HeaderText; cell.Width = field.HeaderStyle.Width; cell.Height = field.HeaderStyle.Height; cell.ForeColor = field.HeaderStyle.ForeColor; cell.Font.Size = field.HeaderStyle.Font.Size; cell.Font.Bold = field.HeaderStyle.Font.Bold; cell.Font.Name = field.HeaderStyle.Font.Name; cell.Font.Strikeout = field.HeaderStyle.Font.Strikeout; cell.Font.Underline = field.HeaderStyle.Font.Underline; cell.BackColor = field.HeaderStyle.BackColor; cell.VerticalAlign = field.HeaderStyle.VerticalAlign; cell.HorizontalAlign = field.HeaderStyle.HorizontalAlign; cell.CssClass = field.HeaderStyle.CssClass; cell.BorderColor = field.HeaderStyle.BorderColor; cell.BorderStyle = field.HeaderStyle.BorderStyle; cell.BorderWidth = field.HeaderStyle.BorderWidth; row.Cells.Add(cell); } TableItemStyle headStyle = gdv.HeaderStyle; TableItemStyle emptyStyle = gdv.EmptyDataRowStyle; emptyStyle.Width = headStyle.Width; emptyStyle.Height = headStyle.Height; emptyStyle.ForeColor = headStyle.ForeColor; emptyStyle.Font.Size = headStyle.Font.Size; emptyStyle.Font.Bold = headStyle.Font.Bold; emptyStyle.Font.Name = headStyle.Font.Name; emptyStyle.Font.Strikeout = headStyle.Font.Strikeout; emptyStyle.Font.Underline = headStyle.Font.Underline; emptyStyle.BackColor = headStyle.BackColor; emptyStyle.VerticalAlign = headStyle.VerticalAlign; emptyStyle.HorizontalAlign = headStyle.HorizontalAlign; emptyStyle.CssClass = headStyle.CssClass; emptyStyle.BorderColor = headStyle.BorderColor; emptyStyle.BorderStyle = headStyle.BorderStyle; emptyStyle.BorderWidth = headStyle.BorderWidth; //空白行的设置 GridViewRow row1 = new GridViewRow(0, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); TableCell cell1 = new TableCell(); cell1.Text = "没有相关数据可以显示!"; cell1.BackColor = System.Drawing.Color.White; row1.Cells.Add(cell1); cell1.ColumnSpan = 6;//合并列 if (gdv.Controls.Count == 0) { gdv.Page.Response.Write("<script language='javascript'>alert('必须在初始化表格类之前执行DataBind方法并设置EmptyDataText属性不为空!');</script>"); } else { gdv.Controls[0].Controls.Clear(); gdv.Controls[0].Controls.AddAt(0, row); gdv.Controls[0].Controls.AddAt(1, row1); } } }
相关文章推荐
- 动态组合SQL语句方式实现批量更新的实例
- 动态组合SQL语句方式实现批量更新的实例
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
- 动态SQL实现批量删除指定数据库的全部进程
- sql语句的批量更新
- .Net 分页实现系列之二基于sql语句分页的方式
- 用SqlCommandBuilder 实现批量更新
- 一个批量更新的sql语句引发的关于创业者心态的思考
- PHP mysqli 增强 批量执行sql 语句的实现代码
- 用SqlCommandBuilder 实现批量更新
- SqlCommandBuilder 实现批量更新
- Sql语句批量更新数据(多表关联)
- 对sql查询语句组合查询的通用实现算法(c++版,java版)
- 熟悉IBatisNet的兄弟,探讨下 如何实现 动态添加SQL语句,查询出随时所需的信息
- .net 用SqlCommandBuilder 实现数据库批量更新
- 用SqlCommandBuilder 实现批量更新