PageShow <%-- Name:PageShow Author: XuYabao Description: CREATE PageShow --%> <%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Src="" Inherits="" Debug="False" Description="Template description here." %> <%@ Assembly Name="System.Data" %> <%@ Import Namespace="System.Data" %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the stored procedures should be based on." %> <%@ Property Name="BLL" Type="String" Default="XUBLL" Category="Context" Description="BLL." %> <%@ Property Name="Model" Type="String" Default="XUModel" Category="Context" Description="Model." %> <%@ Property Name="Author" Type="String" Default="徐亚豹" Category="Context" Description="Author." %> <%@ Property Name="Description" Type="String" T Default="" Category="Context" Description="Description." Optional="true" %> <mce:script runat="template"><!-- public string GetDataType(ColumnSchema column) { string param = ""; switch (column.DataType) { case DbType.Int32: param += "int"; break; case DbType.Int64: param += "int"; break; case DbType.Double: param += "double"; break; case DbType.DateTime: param += "DateTime"; break; case DbType.Decimal: { param += "decimal"; break; } default: { param += "string"; break; } } return param; } // --></mce:script> ///显示 : XUCommon.BasePage { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ShowData(); } } #region 获取<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// <summary> /// 描述: 获取<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> /// </summary> /// <param name="PageIndex">页面索引</param> private void ShowData(int PageIndex) { <%= BLL %>.<%= SourceTable.Name.Substring(2) %> obj; DataTable dt; try { obj = new <%= BLL %>.<%= SourceTable.Name.Substring(2) %>(); dt = obj.<%= SourceTable.Name.Substring(2) %>Get(0); XUCommon.ControlBind.BindGrid(grdData, dt, PageIndex); } catch(Exception e) { PopUpErrMessageBox(e.Message.ToString()); } finally { obj = null; dt = null; } } /// <summary> /// 获取首页 /// </summary> private void ShowData() { ShowData(0); } #endregion #region 删除<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// <summary> /// 描述: 删除<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> /// </summary> /// <returns></returns> private int DeleteData(int intID) { int intRet = 0; <%= BLL %>.<%= SourceTable.Name.Substring(2) %> obj; try { obj = new <%= BLL %>.<%= SourceTable.Name.Substring(2) %>(); intRet = obj.<%= SourceTable.Name.Substring(2) %>Del(intID); PopUpMessageBox("删除成功!"); ShowData(grdData.CurrentPageIndex); } catch (Exception e) { PopUpErrMessageBox(e.Message.ToString()); } finally { obj = null; } return intRet; } #endregion #region 事件 protected void grdData_ItemCommand(object sender, C1.Web.C1WebGrid.C1CommandEventArgs e) { if (e.CommandName.ToLower() == "del") { int intID = Convert.ToInt32(e.Item.Cells[0].Text); DeleteData(intID); } } protected void grdData_PageIndexChanging(object sender, C1.Web.C1WebGrid.C1PageChangingEventArgs e) { ShowData(e.NewPageIndex); } protected void btnQuery_Click(object sender, EventArgs e) { ShowData(); } #endregion #region DataGridCommandEventArgs protected void grdData_ItemCommand(object source, DataGridCommandEventArgs e) { if (e.CommandName.ToLower() == "delete") { int intID = Convert.ToInt32(e.Item.Cells[0].Text); DeleteData(intID); } } #endregion } ///编辑 : XUCommon.BasePage { protected void Page_Load(object sender, EventArgs e) { if(!IsPostBack) { InitPage(); } } #region 页面初始化 /// <summary> /// 页面初始化 /// </summary> private void InitPage() { try { int intID = GetQueryID(); if (intID > 0) { lblPosition.Visible = false; lblPosition2.Visible = true; ShowData(); } else { lblPosition.Visible = true; lblPosition2.Visible = false; } } catch (Exception e) { btnSave.Enabled = false; PopUpErrMessageBox(e.Message.ToString()); } } #endregion #region 获取<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// <summary> /// 描述: 获取<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> /// </summary> private void ShowData() { <%= BLL %>.<%= SourceTable.Name.Substring(2) %> obj; <%= Model %>.<%= SourceTable.Name.Substring(2) %> mod; try { int intID = GetQueryID(); obj = new <%= BLL %>.<%= SourceTable.Name.Substring(2) %>(); mod = obj.<%= SourceTable.Name.Substring(2) %>ModelGet(intID); if (mod != null) { <% for (int i = 1; i < SourceTable.Columns.Count; i++) { %> txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text = mod.<%= SourceTable.Columns[i].Name.Substring(2) %>.ToString(); <% } %> } else { PopUpMessageBox("没有获取到相关数据!"); } } catch (Exception e) { PopUpErrMessageBox(e.Message.ToString()); } finally { obj = null; mod = null; } } #endregion #region 新增<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// <summary> /// 描述: 新增<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> /// </summary> /// <returns></returns> private int AddData() { int intRet = 0; <%= BLL %>.<%= SourceTable.Name.Substring(2) %> obj; <%= Model %>.<%= SourceTable.Name.Substring(2) %> mod; try { obj = new <%= BLL %>.<%= SourceTable.Name.Substring(2) %>(); mod = new <%= Model %>.<%= SourceTable.Name.Substring(2) %>(); <% for (int i = 1; i < SourceTable.Columns.Count; i++) { %> <% if(SourceTable.Columns[i].DataType == DbType.String){ %> mod.<%= SourceTable.Columns[i].Name.Substring(2) %> = txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text; <% } else { %> mod.<%= SourceTable.Columns[i].Name.Substring(2) %> = Convert.To<%= SourceTable.Columns[i].DataType %>(txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text); <% }} %> intRet = obj.<%= SourceTable.Name.Substring(2) %>Add(mod); PopUpMessageBox("保存成功!"); InitControl(); } catch (Exception e) { PopUpErrMessageBox(e.Message.ToString()); } finally { obj = null; mod = null; } return intRet; } #endregion #region 修改<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// <summary> /// 描述: 修改<% if (SourceTable.Description.Trim().Length == 0) { %><%= SourceTable.Name.Substring(2) %><% }else{%><%= SourceTable.Description %><% } %> /// 创建: <%= Author %> <%= DateTime.Now.ToString("yyyy-MM-dd") %> /// </summary> /// <returns></returns> private int EditData() { int intRet = 0; <%= BLL %>.<%= SourceTable.Name.Substring(2) %> obj; <%= Model %>.<%= SourceTable.Name.Substring(2) %> mod; try { int intID = GetQueryID(); obj = new <%= BLL %>.<%= SourceTable.Name.Substring(2) %>(); mod = new <%= Model %>.<%= SourceTable.Name.Substring(2) %>(); mod.<%= SourceTable.Columns[0].Name.Substring(2) %> = intID; <% for (int i = 1; i < SourceTable.Columns.Count; i++) { %> <% if(SourceTable.Columns[i].DataType == DbType.String){ %> mod.<%= SourceTable.Columns[i].Name.Substring(2) %> = txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text; <% } else { %> mod.<%= SourceTable.Columns[i].Name.Substring(2) %> = Convert.To<%= SourceTable.Columns[i].DataType %>(txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text); <% }} %> intRet = obj.<%= SourceTable.Name.Substring(2) %>Edit(mod); PopUpMessageBox("保存成功!"); } catch (Exception e) { PopUpErrMessageBox(e.Message.ToString()); } finally { obj = null; mod = null; } return intRet; } #endregion #region 控件值初始化 /// <summary> /// 控件值初始化 /// </summary> private void InitControl() { <% for (int i = 1; i < SourceTable.Columns.Count; i++) { %> txt<%= SourceTable.Columns[i].Name.Substring(2) %>.Text = ""; <% } %> } #endregion protected void btnSave_Click(object sender, EventArgs e) { int intID = GetQueryID(); if (intID > 0) { EditData(); } else { AddData(); } } }