当前位置 : 主页 > 网络编程 > net编程 >

自定义表单设计之四-表单字段实现

来源:互联网 收集:自由互联 发布时间:2023-10-08
表单编辑字段 自定义表单添加、修改、删除列,列字段类型保存到字段表中,并且修改自定义主表添加修改列。 html xmlns="http://www.w3.org/1999/xhtml"head runat="server" title表单字段列表/title/

自定义表单设计之四-表单字段实现_html

表单编辑字段

自定义表单添加、修改、删除列,列字段类型保存到字段表中,并且修改自定义主表添加修改列。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>表单字段列表</title>
</head>
<body>
    <form id="formFieldList" runat="server">
    <div>
        <table class="table_bgcolor">
            <tr>
                <td style="width: 100%; text-align: left;" class="table_titlebgcolor">
                    表单管理:编辑字段
                </td>
            </tr>
            <tr>
                <td style="width: 100%; text-align: left;">
                    表单名称:<asp:Label runat="server" ID="FormNameLabel"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 100%; text-align: left;">
                    表单描述:<asp:Label runat="server" ID="FormDesLabel"></asp:Label>
                </td>
            </tr>
            <tr>
                <td style="width: 100%; text-align: left;">
                    <a class="button" target="_blank" href="AddFormField.aspx?formid=<%=getFormID() %>&fieldid=0">
                        添加字段</a>  
                    <%--<a id="AddFormFieldBatch" class="button" target="_blank" href="AddFormFieldBatch.aspx?formid=<%=getFormID() %>">
                        批量添加字段 </a>--%>
                    <asp:GridView runat="server" ID="FormFieldGridView" SkinID="GridViewSkin" DataKeyNames="id" AutoGenerateColumns="false">
                        <EmptyDataTemplate>
                            <table style="background-color: White; border-color: #4F7FC9; border-width: 1px;
                                border-style: solid; border-collapse: collapse;">
                                <tr class="table_titlebgcolor" style="font-weight: bold;">
                                    <th scope="col" style="width: 15%">
                                        字段名称
                                    </th>
                                    <th scope="col" style="width: 25%">
                                        字段显示名
                                    </th>
                                    <th scope="col" style="width: 15%">
                                        字段位置
                                    </th>
                                    <th scope="col" style="width: 15%">
                                        表现形式
                                    </th>
                                    <th scope="col" style="width: 15%">
                                        字段类型
                                    </th>
                                    <th scope="col" style="width: 15%">
                                        显示顺序
                                    </th>
                                </tr>
                                <tr>
                                    <td colspan="6">
                                        您可以点击“批量添加字段”按钮添加字段!
                                    </td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <Columns>
                            <asp:TemplateField HeaderText="序号">
                                <ItemTemplate>
                                    <%# Container.DataItemIndex + 1 %>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="fieldname" HeaderText="字段名称" />
                            <asp:BoundField DataField="fieldlabel" HeaderText="字段显示名" />
                            <asp:TemplateField HeaderText="字段位置">
                                <ItemTemplate>
                                    <%# ShowViewType(Eval("viewType")) %>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="表现形式">
                                <ItemTemplate>
                                    <%# ShowHtmlType(Eval("fieldhtmltype")) %>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="字段类型">
                                <ItemTemplate>
                                    <%# ShowColumnType(Eval("fieldhtmltype"), Eval("type"), Eval("id"))%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="dsporder" HeaderText="显示顺序" />

                            <asp:HyperLinkField HeaderText=" 编 辑 " ControlStyle-CssClass="button" DataNavigateUrlFields="billid,id" Target="_blank" DataNavigateUrlFormatString="~/Workflow/EditFormField.aspx?formid={0}&fieldid={1}" Text=" 编辑 " />
                            <asp:TemplateField HeaderText=" 删 除 ">
                                <ItemTemplate>
                                <asp:Button runat="server" ID="DeleteFieldButton" Text=" 删除 " OnClick="onDeleteFieldButtonClick" />
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

FormFieldList.aspx.cs

/// <summary>
        /// 删除字段
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void onDeleteFieldButtonClick(object sender, EventArgs e)
        {
            //1)关于此表单是否有工作流实例
            //2)工作流节点字段视图要修改 可见 必填 编辑
            Button deleteButton = sender as Button;
            GridViewRow row = deleteButton.NamingContainer as GridViewRow;

            int fieldID = (int)FormFieldGridView.DataKeys[row.RowIndex]["id"];
            M.workflow_billfield billfield = billfieldBLL.GetModel(fieldID);
            if (billfield != null)
            {
                int viewType = billfield.viewtype.Value;
                if (viewType == 0)
                {//清理主表
                    formBLL.DeleteFieldOfMainTable(billfield);
                }
                else
                {//清理明细表
                    formBLL.DeleteFieldOfDetailTable(billfield);
                }
                string htmlType = billfield.fieldhtmltype;
                if (htmlType == "5")
                {//清理下拉框
                    List<M.workflow_SelectItem> selectItemList = selectItemBLL.GetModelList("fieldid=" + fieldID);
                    foreach (M.workflow_SelectItem item in selectItemList)
                    {
                        selectItemBLL.Delete(item.id);
                    }
                }
                if (htmlType == "7")
                {//清理特殊字段
                    List<M.workflow_specialfield> specialfieldList = specialfieldBLL.GetModelList("fieldid=" + fieldID);
                    foreach (M.workflow_specialfield specialfield in specialfieldList)
                    {
                        specialfieldBLL.Delete(specialfield.id);
                    }
                }
                billfieldBLL.Delete(fieldID);
                initialForm();//刷新列表
            }
        }

        protected string getFormID()
        {
            return ViewState["formid"].ToString();
        }

        protected string ShowViewType(object o)
        {
            if (o.ToString() == "0")
            {
                return "主表";
            }
            if (o.ToString() == "1")
            {
                return "明细表";
            }
            return "";
        }

        protected string ShowHtmlType(object o)
        {
            if(htmlTypeDic.ContainsKey(o.ToString()))
            {
                return htmlTypeDic[o.ToString()];
            }
            return "";
        }

        /// <summary>
        /// 显示列的详细类型
        /// </summary>
        /// <param name="htmlType"></param>
        /// <param name="type"></param>
        /// <param name="fieldID"></param>
        /// <returns></returns>
        protected string ShowColumnType(object htmlType, object type, object fieldID)
        {
            string result = "";
            string fieldType = type.ToString();
            switch (htmlType.ToString())
            {
                case "1"://单行文本框
                    if (fieldType == "1")
                    {//文本
                        result = "文本";
                    }
                    else if (fieldType == "2")
                    {//整数
                        result = "整数";
                    }
                    else if (fieldType == "3")
                    {//浮点数
                        result = "浮点数";
                    }
                    else if (fieldType == "4")
                    {//金额转换
                        result = "金额转换";
                    }
                    else if (fieldType == "5")
                    {//金额千分位
                        result = "金额千分位";
                    }
                    break;
                case "2"://多行文本框
                    result = "多行文本框";
                    break;
                case "3"://浏览按钮

                    int db_type = int.Parse(fieldType);
                    result = getBrowserUrlType(db_type);
                    break;
                case "4"://Check框
                    result = "Check框";
                    break;
                case "5"://选择框
                    result = getContentItem(fieldID);
                    break;
                case "6"://附件上传
                    if (fieldType == "1")
                    {
                        result = "上传文件";
                    }
                    if (fieldType == "2")
                    {
                        result = "上传图片";
                    }
                    break;
                case "7"://特殊字段
                    if (fieldType == "1")
                    {
                        result = "自定义链接";
                    }
                    if (fieldType == "2")
                    {
                        result = "描述性文字";
                    }
                    break;
            }
            return result;
        }

        private string getContentItem(object fieldID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<table>");
            List<M.workflow_SelectItem> selectItemList = selectItemBLL.GetModelList("fieldid=" + fieldID.ToString() + " order by listorder");
            if (selectItemList != null && selectItemList.Count > 0)
            {
                foreach (M.workflow_SelectItem item in selectItemList)
                {
                    sb.Append("<tr><td>");
                    sb.Append(item.selectname);
                    sb.Append("</td></tr>");
                }
            }
            sb.Append("</table>");
            return sb.ToString();
        }

        private void initialForm()
        {
            string formid = ViewState["formid"].ToString();
            int id = -1;
            if (int.TryParse(formid, out id))
            {
                M.workflow_bill formModel = formBLL.GetModel(id);
                if (formModel != null)
                {
                    FormNameLabel.Text = formModel.namelabel;
                    FormDesLabel.Text = formModel.formdes;
                }
                List<M.workflow_billfield> formFieldModelList = billfieldBLL.GetModelList("billid=" + formid + " order by viewtype,dsporder");
                FormFieldGridView.DataSource = formFieldModelList;
                FormFieldGridView.DataBind();
            }
        }

        private string getBrowserUrlType(int db_type)
        {
            YaXing.Model.WorkFlow.workflow_browserurl browserurl = browserurlBLL.GetModel(db_type);
            if (browserurl != null)
            {
                return browserurl.fielddbtype;
            }
            return "";
        }
        #region Fields
        BLL.WorkFlow.workflow_browserurl browserurlBLL = new BLL.WorkFlow.workflow_browserurl();
        private BLL.WorkFlow.SequenceIndex seqBLL = new B.SequenceIndex();
        private BLL.WorkFlow.workflow_bill formBLL = new B.workflow_bill();
        private B.workflow_billfield billfieldBLL = new B.workflow_billfield();
        private B.workflow_billdetailtable formDetailTableBLL = new B.workflow_billdetailtable();
        private B.workflow_formdetailinfo formDetailInfoBLL = new B.workflow_formdetailinfo();
        BLL.WorkFlow.workflow_SelectItem selectItemBLL = new BLL.WorkFlow.workflow_SelectItem();
        BLL.WorkFlow.workflow_specialfield specialfieldBLL = new BLL.WorkFlow.workflow_specialfield();
        private Dictionary<string, string> htmlTypeDic = new Dictionary<string,string>(){{"1", "单行文本框"}, {"2", "多行文本框"}, {"3", "浏览按钮"}, {"4", "Check框"}, {"5", "选择框"}, {"6", "附件上传"}, {"7", "特殊字段"}};
        #endregion //End Fields
网友评论