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.
399 lines
10 KiB
399 lines
10 KiB
<%@ CodeTemplate Language="C#" ClassName="PageCs" 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="Theme" Type="System.String" Default="Default" Optional="True" Category="Context" Description="" %>
|
|
<%@ Property Name="title" Type="System.String" Default="" Optional="True" Category="Context" Description="" %>
|
|
|
|
<%
|
|
DbEntity db = Template.GetDataBase(databaseProjectName);
|
|
foreach(Table tb in db.Tables)
|
|
{
|
|
OpenResponse(databaseProjectName+"\\WebSite\\"+tb.ModuleName+"\\"+tb.PropertyName+".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.PropertyName%> : PageEx
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
//TopMenuId = (int)TopMenuEnums.<%=tb.ModuleName%>;
|
|
if(!IsPostBack)
|
|
{
|
|
Privlege = "111111";//RoleDalEx.SelectActNo(RoleId, Request.Url.AbsolutePath);
|
|
if (GetPrivlege(PrivlegeEnums.New) == false)
|
|
btnNew.Visible = false;
|
|
if(GetPrivlege(PrivlegeEnums.View))
|
|
{
|
|
LoadGv(true);
|
|
|
|
}
|
|
}
|
|
}
|
|
#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.PropertyName+" = \"+ 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.PropertyName+" 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 = DateUnit.FormatDate(DateUnit.ToDate(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();
|
|
}
|
|
%>
|
|
|