コード例 #1
0
        /// <summary>
        /// 生成Web用户控件
        /// </summary>
        public static string GetUserControlCode(Model.Table table, Model.CodeStyle style)
        {
            int width = table.Fields.Count > 1 ? 100 / (table.Fields.Count - 1) : 100;

            StringBuilder code = new StringBuilder(CommonCode.GetHtmlCopyrightCode());

            AppendFormatLine(code, 0, "<%@ Control Language=\"C#\" AutoEventWireup=\"true\" Codebehind=\"{0}{1}Grid.ascx.cs\"",
                             style.AfterNamespace, table.Name);
            AppendFormatLine(code, 1, "Inherits=\"Controls_{0}{1}Grid\" %>", style.AfterNamespace, table.Name);
            AppendFormatLine(code, 0, "<table id=\"{0}Grid\" class=\"data\" style=\"width: 100%;\">", table.Name);
            AppendFormatLine(code, 1, "<tr class=\"title\">");
            int i = 0;

            foreach (Model.Field field in table.Fields)
            {
                if (field != table.ConditionRows[0])
                {
                    AppendFormatLine(code, 2, "<td style=\"width: {0}%;\">", width);

                    if (i == 0)
                    {
                        AppendFormatLine(code, 3, "<input id=\"chkChooseAll{0}\" type=\"checkbox\" onclick=\"chooseAll('{0}Grid','chkChooseAll{0}')\" />",
                                         table.Name);
                    }
                    AppendFormatLine(code, 3, "{0}", field.FieldDescn);
                    AppendFormatLine(code, 2, "</td>");
                    i++;
                }
            }
            AppendFormatLine(code, 1, "</tr>");
            AppendFormatLine(code, 1, "<asp:Repeater ID=\"grd{0}\" runat=\"server\" OnItemCommand=\"grd{0}_ItemCommand\">", table.Name);
            AppendFormatLine(code, 2, "<ItemTemplate>");
            AppendFormatLine(code, 3, "<tr>");

            i = 0;
            foreach (Model.Field field in table.Fields)
            {
                if (field != table.ConditionRows[0])
                {
                    AppendFormatLine(code, 4, "<td>");

                    if (i == 0)
                    {
                        AppendFormatLine(code, 5, "<asp:CheckBox ID=\"chkChoose\" runat=\"server\" /><asp:HiddenField ID=\"hf{0}\"", table.Name);
                        AppendFormatLine(code, 6, "runat=\"server\" Value='<%# Eval(\"{0}\") %>' />", table.ConditionRows[0].FieldName);
                    }
                    AppendFormatLine(code, 5, "<span title=\"<%# Eval(\"{0}\") %>\">", field.FieldName);
                    AppendFormatLine(code, 6, "<%# Eval(\"{0}\") %></span>", field.FieldName);
                    AppendFormatLine(code, 4, "</td>");
                    i++;
                }
            }
            AppendFormatLine(code, 3, "</tr>");
            AppendFormatLine(code, 2, "</ItemTemplate>");
            AppendFormatLine(code, 1, "</asp:Repeater>");
            AppendFormatLine(code, 0, "</table>");

            return(code.ToString());
        }
コード例 #2
0
        /// <summary>
        /// 生成Web用户控件
        /// </summary>
        /// <param name="l"></param>
        /// <returns></returns>
        public static string GetUserControlCode(Model.Table table, Model.CodeStyle style)
        {
            List <Model.Field> l = table.Fields;
            bool HasIdentifierRow;

            Model.Field IdentifierRow = CodeHelper.GetKeyField(table, out HasIdentifierRow);

            StringBuilder code = new StringBuilder(CommonCode.GetHtmlCopyrightCode());

            code.AppendLine("<%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeFile=\"" + style.DotAfterNamespace.Replace(".", "") + table.Name + "ListControl.ascx.cs\"");
            code.AppendLine("    Inherits=\"Controls_" + style.DotAfterNamespace.Replace(".", "") + table.Name + "ListControl\" %>");
            code.AppendLine("<asp:Repeater ID=\"rpt" + table.Name + "\" runat=\"server\" OnItemCommand=\"rpt" + table.Name + "_ItemCommand\">");
            code.AppendLine("    <HeaderTemplate>");
            code.AppendLine("        <table id=\"" + table.Name + "List\" style=\"width: 100%;\">");
            code.AppendLine("            <tr>");
            int i = 0;

            foreach (Model.Field r in l)
            {
                if (r != IdentifierRow)
                {
                    if (i < l.Count - 1)
                    {
                        code.AppendLine("                <td style=\"text-align: left;\">");
                    }
                    else
                    {
                        code.AppendLine("                <td style=\"text-align: right;\">");
                    }

                    if (i == 0)
                    {
                        code.AppendLine("                    <input id=\"chkChooseAll" + table.Name + "\" type=\"checkbox\" onclick=\"ChooseAll('" + table.Name + "List','chkChooseAll" + table.Name + "')\" />");
                    }
                    code.AppendLine("                    " + r.FieldDescn + "");
                    code.AppendLine("                </td>");
                    i++;
                }
            }
            code.AppendLine("            </tr>");
            code.AppendLine("    </HeaderTemplate>");
            code.AppendLine("    <ItemTemplate>");
            code.AppendLine("        <tr onmouseover=\"Fuscous(this)\" onmouseout=\"Undertone(this)\">");
            i = 0;
            foreach (Model.Field r in l)
            {
                if (r != IdentifierRow)
                {
                    if (i < l.Count - 1)
                    {
                        code.AppendLine("            <td style=\"text-align: left;\">");
                    }
                    else
                    {
                        code.AppendLine("            <td style=\"text-align: right;\">");
                    }

                    if (i == 0)
                    {
                        code.AppendLine("                <asp:CheckBox ID=\"chkChoose\" runat=\"server\" /><asp:HiddenField ID=\"hf" + table.Name + "\"");
                        code.AppendLine("                    runat=\"server\" Value='<%# Eval(\"" + IdentifierRow.FieldName + "\") %>' />");
                    }
                    code.AppendLine("                <%# Eval(\"" + r.FieldName + "\") %>");
                    code.AppendLine("            </td>");
                    i++;
                }
            }
            code.AppendLine("        </tr>");
            code.AppendLine("    </ItemTemplate>");
            code.AppendLine("    <FooterTemplate>");
            code.AppendLine("        </table>");
            code.AppendLine("    </FooterTemplate>");
            code.AppendLine("</asp:Repeater>");

            return(code.ToString());
        }