日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据对象类代码的生成小工具

發(fā)布時間:2025/3/19 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据对象类代码的生成小工具 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

閑著沒事做了一個數(shù)據(jù)對象類代碼生成的小工具,本來原來做過一個,是在1.1 下面的,后來找不到了,現(xiàn)在做程序沒辦法,自己寫一個吧,小興趣的朋友隨便看看吧,下面是代碼 :

<%@?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?/>");
????????
//加入空的構造函數(shù)
????????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();
????}

}

總結

以上是生活随笔為你收集整理的数据对象类代码的生成小工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。