数据对象类代码的生成小工具
生活随笔
收集整理的這篇文章主要介紹了
数据对象类代码的生成小工具
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
閑著沒事做了一個數據對象類代碼生成的小工具,本來原來做過一個,是在1.1 下面的,后來找不到了,現在做程序沒辦法,自己寫一個吧,小興趣的朋友隨便看看吧,下面是代碼 :
<%@?Page?Language="C#"?AutoEventWireup="true"?CodeFile="DataObject.aspx.cs"?Inherits="CodeGenerator_DataObject"?%><!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html?xmlns="http://www.w3.org/1999/xhtml"?>
<head?runat="server">
????<title>Untitled?Page</title>
???<link?href="style.css"?rel="stylesheet"?type="text/css"?/>?
???<style?type="text/css">
<!--
.gridview?{}{
????color:?#333333;
????background-color:?#CCDDEE;
????width:?100%;
????text-align:?left;
}
.even?{}{
????color:?#333333;
????background-color:?#FFFFFF;
}
.gridview?a?{}{
????font-weight:?bold;
????color:?#3399FF;
}
.gridview?th?a?{}{
????color:????#FFFFFF;
????font-weight:?bold;
}
.gridview?th?{}{
????background-color:?#666666;
????padding:?3px;
}
h2?{}{
????color:?#3399FF;
}
.gridview?td?{}{
????padding:?3px;
}
body?{}{
????font-family:?Verdana,?Arial,?Helvetica,?sans-serif;
????font-size:?14px;
????line-height:?110%;
????text-align:?center;
}
strong?{}{
????color:?#336699;
}
li?{}{
????color:?#333333;
}
em?{}{
????color:?#FF9966;
}
#main?{}{
????width:?760px;
????text-align:?left;
????text-indent:?20px;
????border:?1px?dashed?#009933;
????padding:?10px;
????margin-top:?5px;
????margin-right:?0px;
????margin-bottom:?0px;
????margin-left:?0px;
????background-repeat:?repeat-x;
}
-->
???</style>
</head>
<body>
????<form?id="form1"?runat="server">
????<div?id?=?"main"?style="filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr='#CEDFF6',?endColorStr='#4B92D9',?gradientType='0')">
???<h4>Data?object?code?generator?by?Darkangle?29?Mar,2006</h4>?
???<div?id?=?"MYNameSpace">
???<table?class="gridview">
????????<tr>
????????????<td>Name?Space?:?</td>
????????????<td>?<asp:TextBox?ID="NameSpace"?runat="server"></asp:TextBox>??<asp:RequiredFieldValidator?ID="RequiredFieldValidator1"?runat="server"?ControlToValidate="NameSpace"
???????????ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator></td>
????????</tr>
????????<tr>
????????????<td>Class??Name?:</td>
????????????<td><asp:TextBox?ID="ClassName"?runat="server"></asp:TextBox>
???????<asp:RequiredFieldValidator?ID="RequiredFieldValidator2"?runat="server"?ControlToValidate="ClassName"
???????????ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator></td>
????????</tr>
???</table>
??????</div>
???<hr?/>
????????<table?class="gridview">
????????????<tr>
????????????????<th><span?style="color:?White;">Property?Name</span></th>
????????????????<th><span?style="color:?White;">Read?|?Write?|?Property?Type</span></th>
????????????</tr>
????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox1"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList1"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType1"?Text="string"?runat="server"></asp:TextBox>
??????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox2"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList2"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType2"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox3"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList3"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType3"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox4"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList4"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType4"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox5"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList5"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType5"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox6"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList6"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType6"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox7"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList7"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType7"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox8"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList8"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType8"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox9"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList9"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType9"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????????????????????<tr>
????????????????<td><asp:TextBox?ID="TextBox10"?runat="server"></asp:TextBox></td>
????????????????<td><asp:CheckBoxList?ID="CheckBoxList10"?runat="server"?RepeatLayout="Flow"?RepeatDirection="Horizontal">
????????????????????????<asp:ListItem>Read</asp:ListItem>
????????????????????????<asp:ListItem>Write</asp:ListItem>
????????????????????</asp:CheckBoxList>
????????????????????<asp:TextBox?ID="PropertyType10"?Text="string"?runat="server"></asp:TextBox>
????????????????????</td>
????????????</tr>
????????</table>?
????????<hr?/>
????????<asp:Button?ID="Button1"?runat="server"?Text="Get?Code?Now?!"?OnClick="Button1_Click"?/>
????????<div?id?=?"MYcode">
????????????<asp:Literal?ID="code"?runat="server"></asp:Literal>
????????</div>
??????</div>
????</form>
</body>
</html>
下面是后臺代碼 : using?System;
using?System.Data;
using?System.Configuration;
using?System.Collections;
using?System.Web;
using?System.Web.Security;
using?System.Web.UI;
using?System.Web.UI.WebControls;
using?System.Web.UI.WebControls.WebParts;
using?System.Web.UI.HtmlControls;
public?partial?class?CodeGenerator_DataObject?:?System.Web.UI.Page
{
????protected?void?Page_Load(object?sender,?EventArgs?e)
????{
????}
????protected?void?Button1_Click(object?sender,?EventArgs?e)
????{
????????System.Text.StringBuilder?sb?=?new?System.Text.StringBuilder();
????????System.Text.StringBuilder?sb1?=?new?System.Text.StringBuilder();
????????System.Text.StringBuilder?sb2?=?new?System.Text.StringBuilder();
????????System.Text.StringBuilder?sb3?=?new?System.Text.StringBuilder();
????????System.Text.StringBuilder?sb4?=?new?System.Text.StringBuilder();
????????sb.Append("namespace?"?+?NameSpace.Text?+?"?{<br?/>");
????????sb.Append("public?class?"?+?ClassName.Text?+?"?{<br?/>");
????????//加入空的構造函數
????????sb3.Append("public?"?+?ClassName.Text?+?"()?{}<br?/>");
????????sb3.Append("public?"?+?ClassName.Text?+?"(");
????????for(int?i?=?1;i?<?11;i++)
????????{
????????????TextBox?tb?=?(TextBox)Page.FindControl("TextBox"?+?i);
????????????TextBox?propertytype?=?(TextBox)Page.FindControl("PropertyType"?+?i);
????????????CheckBoxList?cbl?=?(CheckBoxList)Page.FindControl("CheckBoxList"?+?i);
????????????//屬性名不為空
????????????if(!(tb.Text?==?String.Empty))
????????????{
????????????????sb1.Append("private?"??+?propertytype.Text?+??"?_"?+?tb.Text?+?";<br?/>");
????????????????sb2.Append("public?"?+?propertytype.Text?+?"?"?+?tb.Text?+?"?{<br?/>");
????????????????if(cbl.Items[0].Selected)
????????????????????sb2.Append("get?{?return?_"?+?tb.Text?+?";?}<br?/>");
????????????????if(cbl.Items[1].Selected)
????????????????????sb2.Append("set?{?_"?+?tb.Text?+?"?=?value;?}<br?/>");
????????????????sb2.Append("}<br?/>");
?????????????????sb3.Append(propertytype.Text?+?"?"?+?tb.Text?+?",");
?????????????????//注意,這里最后會多出來一個逗號,要去掉它
?????????????????sb4.Append("this._"?+?tb.Text?+?"?=?"?+?tb.Text?+?";<br?/>");
????????????}
????????}
????????//去掉最后一個逗號
????????sb3.Replace(",","",(sb3.Length?-?1),?1);
????????sb.Append(sb1.ToString());
????????sb.Append(sb3.ToString());
????????sb.Append(")?{<br?/>");
????????sb.Append(sb4.ToString());
????????sb.Append("}<br?/>");
????????sb.Append(sb2.ToString());
????????sb.Append("}<br?/>}<br?/>");
????????code.Text?=?sb.ToString();
????}
}
總結
以上是生活随笔為你收集整理的数据对象类代码的生成小工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在asp中怎么调用带输出参数的存储过程
- 下一篇: (转)浅析当今视频文件的格式