resource1(codesmith)

ipqxiang 2007-04-15 11:06:28
<% Start(); %>

<script runat="template">

</script>
<script runat="template">
<!-- #include file="../CommFunctions/CommUtil.cs" -->
public void Start()
{
try
{
this.RenderToFile(this.WebServiceOutputPath + @"\" +this.SourceTable.Name + "Base.cs",true);
}
catch
{}

}
</script>

<script runat="template">
private string _WebServiceOutputPath = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[CodeTemplateProperty(CodeTemplatePropertyOption.Optional)]
[Category("Web - Advanced")]
[Description("The full path for the the WebService files. this path match with the webservice url.")]
[DefaultValue("")]
public string WebServiceOutputPath
{
get
{
if (_WebServiceOutputPath.Length == 0)
{
return @"c:\NetTiers\" + (ChooseSourceDatabase != null ? ChooseSourceDatabase.Name + @"\WebServices" : @"Output\WebServices");
}
return _WebServiceOutputPath;
}
set
{
if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1);
_WebServiceOutputPath = value;
}
}
</script>
end table bll
...全文
142 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ipqxiang 2007-04-15
  • 打赏
  • 举报
回复
GO
--=================================================== Update Store Procedure sp_Insert<%=this.SourceTable.Name %> Start ========================================
-----------------------------------------------------------------------------------------------------------------------
-- FunName: sp_Update<%=this.SourceTable.Name %>
-- author: <%=System.Environment.UserName.ToString() %>
-- date: <%=DateTime.Now.ToShortDateString() %>
-- Function: ...
-- Return: ...
-------------------------------------------------------------------------------------------------------------------------
-- if exist the procedure,drop the procedure.
IF EXISTS(SELECT [NAME] FROM sysobjects WHERE [NAME]='sp_Update<%=this.SourceTable.Name %>' AND [TYPE]='P')
DROP PROCEDURE sp_Update<%=this.SourceTable.Name %>
GO
CREATE PROCEDURE <%=OwerOrLnkName%>.sp_Update<%=this.SourceTable.Name %>
(
<%
_rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if(_rows == this.SourceTable.Columns.Count)
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + ")");
}
else
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + "),");
}
}
%>
)
AS
BEGIN
-- update into data.
UPDATE <%=this.SourceTable.Name %> SET
<%
string _FilterSql = string.Empty;
_rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if(_rows == this.SourceTable.Columns.Count)
{
if(!(bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
if(_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())
{
_FilterSql += _col.Name + "=@" + _col.Name.ToLower() + " AND ";
}
else
{
Response.WriteLine(" " + _col.Name + "=@"+_col.Name.ToLower());
}
}
else
{
_FilterSql += _col.Name + "=@" + _col.Name.ToLower() + " AND ";
}
}
else
{
if(!(bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
if(_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())
{
_FilterSql += _col.Name + "=@" + _col.Name.ToLower() + " AND ";
}
else
{
Response.WriteLine(" " + _col.Name + "=@" +_col.Name.ToLower()+ ",");
}
}
else
{
_FilterSql += _col.Name + "=@" + _col.Name.ToLower() + " AND ";
}
}
}
if(0 < _FilterSql.Length)
{
Response.WriteLine(" WHERE " + _FilterSql.Substring(0,_FilterSql.Length - 4));
}
%>
END
--=================================================== Update Store Procedure sp_Insert<%=this.SourceTable.Name %> End ========================================
GO
--=================================================== Delete Store Procedure sp_Insert<%=this.SourceTable.Name %> Start ========================================
-----------------------------------------------------------------------------------------------------------------------
-- FunName: sp_Delete<%=this.SourceTable.Name %>
-- author: <%=System.Environment.UserName.ToString() %>
-- date: <%=DateTime.Now.ToShortDateString() %>
-- Function: ...
-- Return: ...
-------------------------------------------------------------------------------------------------------------------------
-- if exist the procedure,drop the procedure.
IF EXISTS(SELECT [NAME] FROM sysobjects WHERE [NAME]='sp_Delete<%=this.SourceTable.Name %>' AND [TYPE]='P')
DROP PROCEDURE sp_Delete<%=this.SourceTable.Name %>
GO
CREATE PROCEDURE <%=OwerOrLnkName%>.sp_Delete<%=this.SourceTable.Name %>
(
<%
_rows = 0;
string _refrenceSql = string.Empty;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if((null != _col.ExtendedProperties["CS_IsIdentity"]
&& (bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
|| (_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())

)
{
_refrenceSql += " @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + "),";
}
}
if(0 < _refrenceSql.Length)
{
_refrenceSql = _refrenceSql.Substring(0,_refrenceSql.Length - 1);
Response.WriteLine(_refrenceSql);
}
%>
)
AS
BEGIN
-- Delete data.
DELETE <%=this.SourceTable.Name %>
<%
_FilterSql = string.Empty;
_rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if((null != _col.ExtendedProperties["CS_IsIdentity"]
&& (bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
|| (_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())

)
{
_FilterSql += _col.Name + "=@" + _col.Name.ToLower() + " AND ";
}
}
if(0 < _FilterSql.Length)
{
Response.WriteLine(" WHERE " + _FilterSql.Substring(0,_FilterSql.Length - 4));
}
%>
END
--=================================================== Delete Store Procedure sp_Insert<%=this.SourceTable.Name %> End ========================================
GO
ipqxiang 2007-04-15
  • 打赏
  • 举报
回复
<%--
Name:OpData.
Author: F2826665
Description: create store procedures eg:insert,update,delete.
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="SQL" Src="" Inherits="" Debug="False" Description="Template description here." %>
<%@ Property Name="SampleStringProperty" Type="System.String" Default="SomeValue" Optional="True" Category="Strings" Description="This is a sample string property." %>
<%@ Property Name="SampleBooleanProperty" Type="System.Boolean" Default="True" Optional="False" Category="Booleans" Description="This is a sample boolean property." %>
<%@ Assembly Name="System.Data" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Design" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="ChooseSourceDatabase" Type="SchemaExplorer.DatabaseSchema" Optional="False" Category="Getting Started - Required" Description="Database that the tables views, and stored procedures should be based on. IMPORTANT!!! If SourceTables and SourceViews are left blank, the Entire Database will then be generated." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Connection" Description="Table that the data access class should be based on." %>
<%@ Property Name="NameSpace" Type="System.String" Category="Style" Description="Root Namespace." %>
<%@ Property Name="DALNameSpace" Type="System.String" Category="Data" Description="DAL Namespace." %>
<%@ Property Name="DatabaseConnectionStringsName" Type="System.String" Category="Data" Description="Database Name." %>
<%@ Property Name="OwerOrLnkName" Type="System.String" Category="Data" Description="Database Name." %>

<% Start(); %>

<script runat="template">
public
</script>
<script runat="template">
<!-- #include file="../CommFunctions/CommUtil.cs" -->
public void Start()
{
try
{
this.RenderToFile(this.WebServiceOutputPath + @"\sp_" +this.SourceTable.Name + ".SQL",true);
}
catch
{}

}
</script>

<script runat="template">
private string _WebServiceOutputPath = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[CodeTemplateProperty(CodeTemplatePropertyOption.Optional)]
[Category("Web - Advanced")]
[Description("The full path for the the WebService files. this path match with the webservice url.")]
[DefaultValue("")]
public string WebServiceOutputPath
{
get
{
if (_WebServiceOutputPath.Length == 0)
{
return @"c:\NetTiers\" + (ChooseSourceDatabase != null ? ChooseSourceDatabase.Name + @"\WebServices" : @"Output\WebServices");
}
return _WebServiceOutputPath;
}
set
{
if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1);
_WebServiceOutputPath = value;
}
}
</script>

--=================================================== Insert Store Procedure sp_Insert<%=this.SourceTable.Name %> Start ========================================
-----------------------------------------------------------------------------------------------------------------------
-- FunName: sp_Insert<%=this.SourceTable.Name %>
-- author: <%=System.Environment.UserName.ToString() %>
-- date: <%=DateTime.Now.ToShortDateString() %>
-- Function: ...
-- Return: ...
-------------------------------------------------------------------------------------------------------------------------
-- if exist the procedure,drop the procedure.
IF EXISTS(SELECT [NAME] FROM sysobjects WHERE [NAME]='sp_Insert<%=this.SourceTable.Name %>' AND [TYPE]='P')
DROP PROCEDURE sp_Insert<%=this.SourceTable.Name %>
GO
CREATE PROCEDURE <%=OwerOrLnkName%>.sp_Insert<%=this.SourceTable.Name %>
(
<%
int _rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows++;
if((null != _col.ExtendedProperties["CS_IsIdentity"]
&& (bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
|| (_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())

)
{
if(_rows == this.SourceTable.Columns.Count)
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + ") OUTPUT");
}
else
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + ") OUTPUT,");
}
}
else
{
if(_rows == this.SourceTable.Columns.Count)
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + ")");
}
else
{
Response.WriteLine(" @"+_col.Name.ToLower()+ " " + _col.NativeType + "(" + _col.Size + "),");
}
}
}
%>
)
AS
BEGIN
-- Set var value.
<%
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
if((bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
Response.WriteLine(" SET @" + _col.Name.ToLower() + "=IDENT_CURRENT('" + this.SourceTable.Name + "')+1");
}
else if(_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())
{
Response.WriteLine(" SET @" + _col.Name.ToLower() + "=NEWID()");
}
}
%>
-- inser into data.
INSERT INTO <%=this.SourceTable.Name %>
(
<%
_rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if(!(bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
if(_rows == this.SourceTable.Columns.Count)
{
Response.WriteLine(" " + _col.Name );
}
else
{
Response.WriteLine(" " + _col.Name + ",");
}
}
}
%>
)
VALUES
(
<%
_rows = 0;
foreach(ColumnSchema _col in this.SourceTable.Columns)
{
_rows ++;
if(_rows == this.SourceTable.Columns.Count)
{
if(!(bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
if(_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())
{
Response.WriteLine(" @" + _col.Name.ToLower());
}
else
{
Response.WriteLine(" @"+_col.Name.ToLower());
}
}
}
else
{
if(!(bool)_col.ExtendedProperties["CS_IsIdentity"].Value)
{
if(_col.NativeType.ToUpper() == Convert.ToString(System.Data.SqlDbType.UniqueIdentifier).ToUpper())
{
Response.WriteLine(" @" + _col.Name.ToLower() + ",");
}
else
{
Response.WriteLine(" @"+_col.Name.ToLower() + ",");
}
}
}
}
%>
)
END
--=================================================== Insert Store Procedure sp_Insert<%=this.SourceTable.Name %> End ========================================
ipqxiang 2007-04-15
  • 打赏
  • 举报
回复
<%--
Name:Table base.
Author: F2826665
Description: create a table class of base.
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Src="" Inherits="" Debug="False" Description="Template description here." %>
<%@ Property Name="SampleStringProperty" Type="System.String" Default="SomeValue" Optional="True" Category="Strings" Description="This is a sample string property." %>
<%@ Property Name="SampleBooleanProperty" Type="System.Boolean" Default="True" Optional="False" Category="Booleans" Description="This is a sample boolean property." %>
<%@ Assembly Name="System.Data" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Design" %>

<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="ChooseSourceDatabase" Type="SchemaExplorer.DatabaseSchema" Optional="False" Category="Getting Started - Required" Description="Database that the tables views, and stored procedures should be based on. IMPORTANT!!! If SourceTables and SourceViews are left blank, the Entire Database will then be generated." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Connection" Description="Table that the data access class should be based on." %>
<%@ Property Name="NameSpace" Type="System.String" Category="Style" Description="Root Namespace." %>
<%@ Property Name="DALNameSpace" Type="System.String" Category="Data" Description="DAL Namespace." %>
<%@ Property Name="DatabaseConnectionStringsName" Type="System.String" Category="Data" Description="Database Name." %>
<%@ Property Name="OwerOrLnkName" Type="System.String" Category="Data" Description="Database Name." %>

//-----------------------------------------------------------------------------------------------------------------------
// FunName: <%=this.SourceTable.Name %>Base.cs
// author: <%=System.Environment.UserName.ToString() %>
// date: <%=DateTime.Now.ToShortDateString() %>
// Function: ...
//-----------------------------------------------------------------------------------------------------------------------

#region Using directives

using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Data.Common;
using System.Collections.Generic;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using <%=DALNameSpace%>;

#endregion

namespace <%=NameSpace%>
{
public class <%=this.SourceTable.Name %>Base
{
#region member variable.
protected Database m_Database = null;
protected ICollection<string> m_NeedUpdateFields = new List<string>();
<% foreach(ColumnSchema _col in this.SourceTable.Columns) %>
<% { %>
private <%= GetCSharpVariableType(_col) %> m_<%=Convert.ToString(_col.Name).ToLower()%>;
<% } %>
#endregion

#region Base functions.
/// <summary>
/// construction functions.
/// </summary>
public <%=this.SourceTable.Name %>Base()
{
this.m_Database = DatabaseFactory.CreateDatabase("<%=this.DatabaseConnectionStringsName%>");
this.ClearCollection();
}
/// <summary>
/// construction functions.
/// </summary>
public <%=this.SourceTable.Name %>Base(Database db)
{
this.m_Database = db;
this.ClearCollection();
}
/// <summary>
/// construction functions.
/// </summary>
public <%=this.SourceTable.Name %>Base(string ConnectionStringName)
{
this.m_Database = DatabaseFactory.CreateDatabase(ConnectionStringName);
this.ClearCollection();
}
public void ClearCollection()
{
this.m_NeedUpdateFields.Clear();
}
/// <summary>
/// initlize a class or set a value to the object.
/// </summary>
public bool Load(<%=GetPrimaryKeys(this.SourceTable)%>)
{
bool rtnValue = false;
string sql = "SELECT * FROM <%=OwerOrLnkName + "." + this.SourceTable.Name %> WHERE <%=GetPrimaryKeysValueAndText(this.SourceTable)%>";
using(IDataReader dataReader = this.m_Database.ExecuteReader(CommandType.Text, sql))
{
try
{
if(dataReader.Read())
{
<% foreach(ColumnSchema _col in this.SourceTable.Columns) {%>
<% string dataReaderStr = "dataReader[\"" + _col.Name + "\"]"; %>
this.<%=_col.Name %> = <%=GetFieldValue(_col,dataReaderStr)%>;
<% } %>
rtnValue = true;
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
if(null != dataReader && !dataReader.IsClosed)
{
dataReader.Close();
}
}
}
return rtnValue;
}
/// <summary>
/// initlize a class or set a value to the object.
/// </summary>
public bool LoadFilter(string _Filter)
{
bool rtnValue = false;
string sql = "SELECT * FROM <%=OwerOrLnkName + "." + this.SourceTable.Name %> WHERE " + _Filter + "";
using(IDataReader dataReader = this.m_Database.ExecuteReader(CommandType.Text, sql))
{
try
{
if(dataReader.Read())
{
<% foreach(ColumnSchema _col in this.SourceTable.Columns) {%>
<% string dataReaderStr = "dataReader[\"" + _col.Name + "\"]"; %>
this.<%=_col.Name %> = <%=GetFieldValue(_col,dataReaderStr)%>;
<% } %>
rtnValue = true;
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
if(null != dataReader && !dataReader.IsClosed)
{
dataReader.Close();
}
}
}
return rtnValue;
}
#endregion

#region propertities
public Database DatabaseManager
{
get
{
return (this.m_Database == null ? new <%=this.SourceTable.Name %>Base().m_Database : this.m_Database);
}
set
{
this.m_Database = value;
}
}
<% foreach(ColumnSchema _col in this.SourceTable.Columns) %>
<% { %>
public <%= (GetCSharpVariableType(_col) + " " + _col.Name) %>
{
get
{
return m_<%=Convert.ToString(_col.Name).ToLower()%>;
}
set
{
m_<%=Convert.ToString(_col.Name).ToLower()%> = value;
this.m_NeedUpdateFields.Add("<%=_col.Name%>");
}
}
<% } %>
#endregion
}
}

<% Start(); %>

<script runat="template">
public
</script>
<script runat="template">
<!-- #include file="../CommFunctions/CommUtil.cs" -->
public void Start()
{
try
{
this.RenderToFile(this.WebServiceOutputPath + @"\" +this.SourceTable.Name + "Base.cs",true);
}
catch
{}

}
</script>

<script runat="template">
private string _WebServiceOutputPath = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[CodeTemplateProperty(CodeTemplatePropertyOption.Optional)]
[Category("Web - Advanced")]
[Description("The full path for the the WebService files. this path match with the webservice url.")]
[DefaultValue("")]
public string WebServiceOutputPath
{
get
{
if (_WebServiceOutputPath.Length == 0)
{
return @"c:\NetTiers\" + (ChooseSourceDatabase != null ? ChooseSourceDatabase.Name + @"\WebServices" : @"Output\WebServices");
}
return _WebServiceOutputPath;
}
set
{
if (value.EndsWith("\\")) value = value.Substring(0, value.Length - 1);
_WebServiceOutputPath = value;
}
}
</script>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧