你好,游客 登录 注册 搜索
背景:
阅读新闻

代码生成工具之界面快速生成

[日期:2013-10-25] 来源:Linux社区  作者:wuhuacong [字体:大 中 小]

这些效果是很基本的界面布局了,如果需要更好看的,可以根据需要调整下每行的数量,以及显示方式。这样的效果,虽然不算最好看,但是已经帮我们把界面元素弄起来了,我们后面的工作就很好开展,不用再重复添加每个字段对应的控件布局信息了。具体的代码是标准的HTML控件代码如下所示。

 
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="Pages_ItemDetail_EditItemDetail"  Codebehind="EditItemDetail.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h3 id="h_title" align="center" runat="server">编辑备件信息表 </h3>
    <table class="formitem" cellspacing="1" cellpadding="0" align="Center" border="0"
        style="border-width: 0px; width: 98%;">
        <caption>基本信息</caption>  
        <tr style="width: 100%;">
            <th align="left" style="width: 20%;">
                 备件编号 :
            </th>
            <td style="width: 80%;" colspan="3">
                &nbsp;<asp:TextBox ID="txtItemNo" runat="server" Width="250px" MaxLength="100"></asp:TextBox>
            </td>
        </tr>
        <tr style="width: 100%;">
            <th align="left" style="width: 20%;">
                 备件名称 :
            </th>
            <td style="width: 80%;" colspan="3">
                &nbsp;<asp:TextBox ID="txtItemName" runat="server" Width="250px" MaxLength="100"></asp:TextBox>
            </td>
        </tr>
        <tr style="width: 100%;">
            <th align="left" style="width: 20%;">
                 供货商 :
            </th>
            <td style="width: 80%;" colspan="3">
                &nbsp;<asp:TextBox ID="txtManufacture" runat="server" Width="250px" MaxLength="100"></asp:TextBox>
            </td>
        </tr>
...............
 

当然后台代码的保存及赋值显示,肯定是少不了的了,这些也是根据我的框架代码生成的,应该来说是很有用的。

 
public partial class Pages_ItemDetail_EditItemDetail : BasePage
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        this.IsFunctionControl = true;
        this.FunctionID = "ItemDetail/Edit";
    }
    
    private void BindData()
    {
        try
        {
            string id = Request.QueryString["ID"];
            if(!string.IsNullOrEmpty(id))
            {
                ItemDetailInfo info = BLLFactory<ItemDetail>.Instance.FindByID(id);
                if(info != null)
                {
                     this.txtItemNo.Text = info.ItemNo;
                     this.txtItemName.Text = info.ItemName;
                     this.txtManufacture.Text = info.Manufacture;
                     this.txtMapNo.Text = info.MapNo;
                     this.txtSpecification.Text = info.Specification;
                     this.txtMaterial.Text = info.Material;
                     this.txtItemBigType.Text = info.ItemBigType;
                     this.txtItemType.Text = info.ItemType;
                     this.txtUnit.Text = info.Unit;
                     this.txtPrice.Text = info.Price.ToString();
                     this.txtSource.Text = info.Source;
                     this.txtStoragePos.Text = info.StoragePos;
                     this.txtUsagePos.Text = info.UsagePos;
                     this.txtNote.Text = info.Note;
                     this.txtWareHouse.Text = info.WareHouse;
                     this.txtDept.Text = info.Dept;
                 }
            }
        }
        catch(Exception ex)
        {
            Helper.ShowError(this, ex, false);
            return;
        }
      }

    protected void Page_Load(object sender, EventArgs e)
    { 
        if(!this.IsPostBack)
        {
            BindData();
        }
    }

    /// <summary>
    /// 获取数据
    /// </summary> 
    private ItemDetailInfo SetData(ItemDetailInfo info)
    { 
         info.ItemNo = this.txtItemNo.Text;   
         info.ItemName = this.txtItemName.Text;   
         info.Manufacture = this.txtManufacture.Text;   
         info.MapNo = this.txtMapNo.Text;   
         info.Specification = this.txtSpecification.Text;   
         info.Material = this.txtMaterial.Text;   
         info.ItemBigType = this.txtItemBigType.Text;   
         info.ItemType = this.txtItemType.Text;   
         info.Unit = this.txtUnit.Text;   
         info.Price = Helper.SafeConvertDecimal(this.txtPrice.Text);
         info.Source = this.txtSource.Text;   
         info.StoragePos = this.txtStoragePos.Text;   
         info.UsagePos = this.txtUsagePos.Text;   
         info.Note = this.txtNote.Text;   
         info.WareHouse = this.txtWareHouse.Text;   
         info.Dept = this.txtDept.Text;   
         return info;
    }
     
    protected void imgSubmit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            string id = Request.QueryString["ID"];
            if(string.IsNullOrEmpty(id))
            {
                ItemDetailInfo info = new ItemDetailInfo();
                SetData(info);
                
                BLLFactory<ItemDetail>.Instance.Insert(info);
            }
            else
            {
                ItemDetailInfo info = BLLFactory<ItemDetail>.Instance.FindByID(id);
                if(info != null)
                {
                    SetData(info);
                    BLLFactory<ItemDetail>.Instance.Update(info, id);
                }
            }
        }
        catch(Exception ex)
        {
            Helper.ShowError(this, ex, false);
            return;
        }
        
        Response.Redirect("ListItemDetail.aspx");
    }

    protected void imgBack_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("ListItemDetail.aspx");
    }
}
 

有了这些智能的界面生成,界面开发其实是一件不再枯燥的事情,节省更多的时间,做更有意义的事情。

linux
相关资讯       代码生成工具  代码 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款