DT 的数据字典
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

465 lines
13 KiB

<%@ CodeTemplate Language="C#" ClassName="MPageCs" TargetLanguage="C#" Debug="False" Description="" %>
<%@ Property Name="databaseProjectName" Type="System.String" Default="SpSampleDb" Optional="True" Category="Context" Description="" %>
<%@ Property Name="moduleName" Type="System.String" Default="Manager" Optional="True" Category="Context" Description="" %>
<%@ Property Name="folderName" Type="System.String" Default="System" Optional="True" Category="Context" Description="" %>
<%@ Property Name="popedom" Type="System.String" Default="" Optional="True" Category="Context" Description="" %>
<%
DbEntity db = Template.GetDataBase(databaseProjectName);
foreach(Table tb in db.Tables)
{
OpenResponse(databaseProjectName+"\\MWebSite\\"+tb.ModuleName+"\\"+tb.Name.ToLower()+".aspx.cs");
Field pkField = null;
foreach(Field fd in tb.Fields)
{
if( fd.IsPK )
pkField = fd;
}
%>
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using Dal;
using Model;
using WebBase;
/*******************************************************/
/*Project:
Module :
Description :
Date : <%=DateTime.Now.ToString()%>
Create : lxc
Update :
TODO : */
/*******************************************************/
public partial class <%=moduleName%>_<%=folderName%>_<%=tb.Name%> : PageEx
{
public string script = "<script type='text/javascript' src='../Js/language_en.js'></script>";
protected void Page_Load(object sender, EventArgs e)
{
//TopMenuId = (int)TopMenuEnums.<%=tb.ModuleName%>;
if (LanguageType == "zh_cn")
{
script = "<script type='text/javascript' src='../Js/language_zh_cn.js'></script>";
}
if(!IsPostBack)
{
PageNo = "pc000<%=tb.MemberName%>";
GetLanguageLst(true);
LoadGv(true);
<%
foreach(Field fd in tb.Fields)
{
if( fd.IsFK == true)
{
Table tbTo = tb.ParentTable(fd.PropertyName);
if( tbTo!=null&& tbTo.Fields.Count > 1)
{
string textFieldName = tbTo.Fields[1].PropertyName;
string valueFieldName = tb.ParentField(fd.PropertyName).PropertyName;
Response.WriteLine("\t\t\t\t#region Load"+tbTo.PropertyName);
Response.WriteLine("\t\t\t\tDataSet ds"+fd.PropertyName+" = "+tbTo.PropertyName+"Dal.Select();");
if( fd.LoadCodeProperty("Find") != "0")
{
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,true)+".DataTextField= \""+textFieldName+"\";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,true)+".DataValueField= \""+valueFieldName+"\";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,true)+".DataSource = ds"+fd.PropertyName+";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,true)+".DataBind();");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,true)+".Items.Insert(0,new ListItem(\"ALL\",\"\"));");
}
if( fd.LoadCodeProperty("Edit") != "0")
{
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".DataTextField= \""+textFieldName+"\";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".DataValueField= \""+valueFieldName+"\";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".DataSource = ds"+fd.PropertyName+";");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".DataBind();");
Response.WriteLine("\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".Items.Insert(0,new ListItem(\"-Select-\",\"\"));");
}
Response.WriteLine("\t\t\t\t#endregion");
}
}
}
%>
initLanguage();
}
}
#region initLanguage
protected void initLanguage()
{
btnNew.Text = getLabtext("btnnew");
btnFind.Text = getLabtext("btnfind");
btnOK.Text = getLabtext("btnok");
btnCancel.Text = getLabtext("btncancel");
if (gv<%=tb.PropertyName%>.Rows.Count > 0)
{
gv<%=tb.PropertyName%>.HeaderRow.Cells[1].Text = getLabtext("No");
<%
int x = 0;
foreach(Field fd in tb.Fields)
{
x=x+1;
Response.WriteLine("\t\tgv"+tb.PropertyName+".HeaderRow.Cells["+x+"].Text = getLabtext(\""+fd.MemberName+"\");");
}
%>
}
}
#endregion
#region Bind
protected void LoadGv(bool bGetCount)
{
int totalCount = 0;
#region Build where
string where = "";
<%
foreach(Field fd in tb.Fields)
{
if(fd.LoadCodeProperty("Find") == "0")
continue;
if( fd.Identity.Enable == false)
{
string textOrSelectvalue = "Text";
if(FieldHelper.GetControlName(fd,true).StartsWith("ddl") == true)
textOrSelectvalue = "SelectedValue";
switch(fd.DataType.GroupName.ToUpper())
{
case "NUMBER":
Response.WriteLine("\t\tif("+FieldHelper.GetControlName(fd,true)+"."+textOrSelectvalue+".Trim() != \"\")");
Response.WriteLine("\t\t\twhere += \" a."+ fd.MemberName+" = \"+ FormatCom.String("+FieldHelper.GetControlName(fd,true)+"."+textOrSelectvalue+") + \" and \";");
break;
case "STRING":
case "BLOB":
Response.WriteLine("\t\tif("+FieldHelper.GetControlName(fd,true)+"."+textOrSelectvalue+".Trim() != \"\")");
Response.WriteLine("\t\t\twhere += \" a."+ fd.MemberName+" like '%\"+ FormatCom.String("+FieldHelper.GetControlName(fd,true)+"."+textOrSelectvalue+") + \"%' and \";");
break;
}
}
}
%> // where += CurWhere;
if( where.EndsWith(" and "))
where = where.Substring(0,where.Length-5);
#endregion
DataSet ds = <%=tb.PropertyName%>Dal.SelectFromView(where, dp.CurrentPageIndex, dp.PageSize, out totalCount);
if (bGetCount)
dp.RecordCount = totalCount;
gv<%=tb.PropertyName%>.DataSource = ds;
gv<%=tb.PropertyName%>.DataBind();
}
#endregion
#region Edit
/// <summary>
/// Edit
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gv<%=tb.PropertyName%>_RowEditing(object sender, System.Web.UI.WebControls.GridViewEditEventArgs e)
{
if (GetPrivlege(PrivlegeEnums.Edit))
{
Action = ActionEdit;
PK = Convert.ToString(gv<%=tb.PropertyName%>.DataKeys[e.NewEditIndex].Value);
<%=tb.PropertyName%>Model <%=tb.MemberName%> = <%=tb.PropertyName%>Dal.Select(Convert.<%=pkField.DataType.Convert%>(PK));
if (<%=tb.MemberName%> != null)
{
<%
foreach(Field fd in tb.Fields)
{
if( fd.LoadCodeProperty("Edit") != "0")
{
if( fd.IsPK == false && fd.Identity.Enable == false)
{
string strValue="";
if( fd.DataType.GroupName.ToUpper() != "STRING")
strValue =" Convert.ToString("+ tb.MemberName+"."+fd.MemberName+")";
else
strValue = tb.MemberName+"."+fd.MemberName;
string strEdt = "";
if( fd.IsFK == false && fd.NoteIsEnum==false)
{
if( fd.DataType.GroupName.ToUpper() == "DATETIME")
strEdt ="\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".Text = Convert.ToString("+tb.MemberName+"."+fd.MemberName+");";
else
strEdt ="\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".Text = "+strValue+";";
}
else
{
strEdt="\t\t\t\tif( "+FieldHelper.GetControlName(fd,false)+".Items.FindByValue("+strValue+") != null)\r\n"
+"\t\t\t\t\t"+FieldHelper.GetControlName(fd,false)+".SelectedValue="+strValue+";";
}
Response.WriteLine(strEdt);
}
}
}
%>
e.NewEditIndex = -1;
SetEditModel();
}
}
}
#endregion
#region Delete
/// <summary>
/// Delete
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gv<%=tb.PropertyName%>_RowDeleting(object sender, System.Web.UI.WebControls.GridViewDeleteEventArgs e)
{
if (GetPrivlege(PrivlegeEnums.Delete))
{
PK = Convert.ToString(gv<%=tb.PropertyName%>.DataKeys[e.RowIndex].Value);
int i = <%=tb.PropertyName%>Dal.Delete(Convert.<%=pkField.DataType.Convert%>(PK));
if (i == 1)
{
dp.RecordCount--;
LoadGv(false);
}
}
}
#endregion
protected void gv<%=tb.PropertyName%>_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
<%
int idb=1;
foreach(Field fd in tb.Fields)
{
if(fd.LoadCodeProperty("List") == "0")
continue;
if( fd.DataType.FullName=="Date")
{
%>
#region <%=fd.PropertyName%>
HiddenField hf<%=fd.PropertyName%> = e.Row.FindControl("hf<%=fd.PropertyName%>") as HiddenField;
Label lab<%=fd.PropertyName%> = e.Row.FindControl("lab<%=fd.PropertyName%>") as Label;
lab<%=fd.PropertyName%>.Text = SqlHelper.String(SqlHelper.Date(hf<%=fd.PropertyName%>.Value));
#endregion
<%
}
if( fd.NoteIsEnum== true)
{
%>
#region <%=fd.PropertyName%>
int i<%=fd.PropertyName%> = <%=Convert.ToString(idb)%>;
switch(e.Row.Cells[<%=Convert.ToString(idb)%>].Text)
{
<%
foreach(string key in fd.NoteEnums.AllKeys)
{
%> case "<%=fd.NoteEnums[key]%>":
e.Row.Cells[<%=Convert.ToString(idb)%>].Text="<%=key%>";
break;
<%
}
%>
}
#endregion
<%
}
idb++;
}
%>
}
}
#region Validator
private bool FrmValidator(string action)
{
return true;
}
#endregion
#region Save
/// <summary>
/// Save
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnOK_Click(object sender, EventArgs e)
{
#region Validate
if (FrmValidator(Action) == false)
{
return;
}
<%
foreach(Field fd in tb.Fields)
{
if( fd.LoadCodeProperty("Edit") == "0")
continue;
string textOrSelectvalue = "Text";
if(FieldHelper.GetControlName(fd,true).StartsWith("ddl") == true)
textOrSelectvalue = "SelectedValue";
if( fd.IsPK == false && fd.Identity.Enable == false && fd.IsNullable == false)
{
%>
if( <%=FieldHelper.GetControlName(fd,false)%>.<%=textOrSelectvalue%>.Trim() == "")
{
MessageBox("<%=fd.CnName%> can not null");
return;
}
<%
}
}
%>
#endregion
<%=tb.PropertyName%>Model <%=tb.MemberName%> = new <%=tb.PropertyName%>Model();
if (Action == ActionEdit)
{
<%=tb.MemberName%> = <%=tb.PropertyName%>Dal.Select( FormatCom.ToInt(PK));
}
<%
foreach(Field fd in tb.Fields)
{
if( fd.IsPK == false && fd.Identity.Enable == false)
{
if(fd.DataType.GroupName.ToUpper() != "DATETIME")
Response.WriteLine("\t\tif("+FieldHelper.GetControlName(fd,false)+".Text.Trim() != \"\")");
string strSav = tb.MemberName+"."+fd.MemberName+"=";
if( fd.DataType.GroupName.ToUpper() == "DATETIME")
{
strSav += "DateUnit.ToDate("+FieldHelper.GetControlName(fd,false);
}
else if( fd.DataType.GroupName.ToUpper() == "TOINT32")
{
strSav += "FormatCom.ToInt("+FieldHelper.GetControlName(fd,false);
}
else
{
if( fd.DataType.GroupName.ToUpper() != "STRING")
{
strSav += "FormatCom."+fd.DataType.Convert+"(";
}
strSav +=FieldHelper.GetControlName(fd,false);
}
if( FieldHelper.GetControlName(fd,false).StartsWith("ddl"))
strSav += ".SelectedValue)";
else
strSav += ".Text";
if( fd.DataType.GroupName.ToUpper() != "STRING") // && fd.DataType.GroupName.ToUpper() != "DATETIME")
strSav +=")";
Response.WriteLine("\t\t\t"+strSav+";");
}
}
%>
#region Add
if ( Action == ActionNew)
{
<%
foreach(Field fd in tb.Fields)
{
if( fd.IsPK == true && fd.Identity.Enable == false)
{
%>
if( <%=FieldHelper.GetControlName(fd,false)%>.Text.Trim() != "")
<%=tb.MemberName%>.<%=fd.PropertyName%> = Convert.<%=fd.DataType.Convert%>(FormatCom.String(<%=FieldHelper.GetControlName(fd,false)%>.Text));
<%
}
}
%>
int i = <%=tb.PropertyName%>Dal.Insert(<%=tb.MemberName%>);
if (i == 1)
{
SetFindModel();
LoadGv(false);
dp.RecordCount++;
}
else
MessageBox("Error!");
}
#endregion
#region Edit
else if (Action == ActionEdit)
{
<%=tb.MemberName%>.<%=pkField.MemberName%>=Convert.<%=pkField.DataType.Convert%>(PK);
int i = <%=tb.PropertyName%>Dal.Update(<%=tb.MemberName%>);
if (i == 1)
{
SetFindModel();
LoadGv(false);
}
else
MessageBox("Error!");
}
#endregion
}
#endregion
protected void btnCancel_Click(object sender, EventArgs e)
{
SetFindModel();
}
#region Find
protected void btnFind_Click(object sender, EventArgs e)
{
LoadGv(true);
}
#endregion
protected void dp_PageChanged(object src, PageChangedEventArgs e)
{
LoadGv(false);
}
protected void btnNew_Click(object sender, EventArgs e)
{
Action = "New";
SetEditModel();
}
protected override void SetEditModel()
{
base.SetEditModel();
findPanel.Visible = false;
editPanel.Visible = true;
}
protected override void SetFindModel()
{
base.SetFindModel();
findPanel.Visible = true;
editPanel.Visible = false;
}
}
<%
CloseResponse();
}
%>