自定义表单设计之七-列字段计算配置
  CLYEAq02EKEQ 2023年11月02日 88 0

列字段计算意思是把明细表数值类型字段合计后赋值给主表数值类字段。

自定义表单设计之七-列字段计算配置_自定义表单

自定义表单设计之七-列字段计算配置_自定义表单_02

AddFormColCal.aspx

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>列字段规则</title>
</head>
<body>
    <form id="form1" 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;">
                    明细字段规则
                </td>
            </tr>
            <tr>
                <td style="width: 100%; text-align: left;">
                    <asp:GridView runat="server" ID="AddFormColCalGV" DataKeyNames="id" AutoGenerateColumns="false" EmptyDataText="没有可用明细字段!"
                        SkinID="GridViewSkin" onrowdatabound="AddFormColCalGV_RowDataBound">
                        <Columns>
                            <asp:TemplateField HeaderText="是否合计">
                                <ItemTemplate>
                                    <asp:CheckBox runat="server" ID="SumCheckBox" />
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="明细字段">
                                <ItemTemplate>
                                    <asp:Label runat="server" ID="DetailLabel" Text='<%#Eval("fieldlabel") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="赋值给主字段">
                                <ItemTemplate>
                                    <asp:DropDownList runat="server" ID="ValueToMainFieldDDL" DataTextField="fieldname" DataValueField="id">
                                    </asp:DropDownList>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button runat="server" ID="SaveButton" Text="保存" OnClick="onSaveButtonClick" />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

后端代码

AddFormColCal.aspx.cs

#region EventHandler
        /// <summary>
        /// 保存列字段规则
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void onSaveButtonClick(object sender, EventArgs e)
        {
            string colcalstr = "";
            string maincalstr = "";
            foreach (GridViewRow row in AddFormColCalGV.Rows)
            {
                int fieldid = (int)AddFormColCalGV.DataKeys[row.RowIndex]["id"];
                CheckBox SumCheckBox = row.FindControl("SumCheckBox") as CheckBox;
                DropDownList ddl = row.FindControl("ValueToMainFieldDDL") as DropDownList;

                if (SumCheckBox.Checked)
                {//合计 colcalstr
                    colcalstr += ";detailfield_" + fieldid;
                }
                if (colcalstr.StartsWith(";"))
                {
                    colcalstr = colcalstr.Remove(0, 1);
                }
                
                if (ddl.SelectedIndex > 0)
                {//赋值给主字段 maincalstr
                    maincalstr += ";mainfield_" + ddl.SelectedValue + "=detailfield_" + fieldid;
                }
                if (maincalstr.StartsWith(";"))
                {
                    maincalstr = maincalstr.Remove(0, 1);
                }
            }
            int formid = int.Parse(ViewState["formid"].ToString());
            M.workflow_formdetailinfo formdetailinfoModel = formdetailinfoBLL.GetModel(formid);
            if (formdetailinfoModel != null)
            {
                if (string.IsNullOrEmpty(colcalstr) &&
                    string.IsNullOrEmpty(maincalstr) &&
                    string.IsNullOrEmpty(formdetailinfoModel.rowcalstr))
                {
                    formdetailinfoBLL.Delete(formid);
                }
                else
                {
                    formdetailinfoModel.colcalstr = colcalstr;
                    formdetailinfoModel.maincalstr = maincalstr;
                    formdetailinfoBLL.Update(formdetailinfoModel);
                }
            }
            else
            {
                formdetailinfoModel = new M.workflow_formdetailinfo();
                formdetailinfoModel.colcalstr = colcalstr;
                formdetailinfoModel.maincalstr = maincalstr;
                formdetailinfoBLL.Add(formdetailinfoModel);
            }
            bindColCalRule(formid.ToString());
        }



        protected void AddFormColCalGV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                DropDownList ddl = e.Row.FindControl("ValueToMainFieldDDL") as DropDownList;
                if (ddl != null)
                {
                    List<M.workflow_billfield> mainFieldList = billfieldBLL.GetModelList("viewtype=0 and fieldhtmltype=1 and (type=2 or type=3) and billid=" + ViewState["formid"].ToString());

                    ddl.DataSource = mainFieldList;
                    ddl.DataBind();
                    if (mainFieldList != null && mainFieldList.Count > 0)
                    {
                        ddl.Items.Insert(0, new ListItem("", "-1"));
                    }
                }
                CheckBox SumCheckBox = e.Row.FindControl("SumCheckBox") as CheckBox;
                int fieldid = (int)AddFormColCalGV.DataKeys[e.Row.RowIndex]["id"];
                M.workflow_formdetailinfo formdetailinfoModel = formdetailinfoBLL.GetModel(int.Parse(ViewState["formid"].ToString()));
                if (formdetailinfoModel != null)
                {
                    string colcalstr = formdetailinfoModel.colcalstr;
                    SumCheckBox.Checked = colcalstr.IndexOf("detailfield_" + fieldid) > -1;
                    string maincalstr = formdetailinfoModel.maincalstr;
                    foreach (ListItem item in ddl.Items)
                    {
                        item.Selected = maincalstr.IndexOf("mainfield_" + item.Value + "=detailfield_" + fieldid) > -1;
                    }
                }
            }
        }
        #endregion //End EventHandler

        #region Helper Methods
        private void initialForm()
        {
            string formid = ViewState["formid"].ToString();
            int id = -1;
            if (int.TryParse(formid, out id))
            {
                M.workflow_bill form = formBLL.GetModel(id);
                if (form != null)
                {
                    FormNameLabel.Text = form.namelabel;
                    FormDesLabel.Text = form.formdes;
                }
            }
            bindColCalRule(formid);
        }

        private void bindColCalRule(string formid)
        {
            List<M.workflow_billfield> detailFieldList = billfieldBLL.GetModelList("viewtype=1 and fieldhtmltype=1 and (type=2 or type=3) and billid=" + formid + " order by detailtable, dsporder, id");
            AddFormColCalGV.DataSource = detailFieldList;
            AddFormColCalGV.DataBind();
        }

        #endregion //End Helper Methods

        #region Fields
        private BLL.WorkFlow.workflow_bill formBLL = new B.workflow_bill();
        private B.workflow_formdetailinfo formdetailinfoBLL = new B.workflow_formdetailinfo();
        private B.workflow_billfield billfieldBLL = new B.workflow_billfield();
        #endregion //End Fields
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  9J4CFPeHjrny   2023年12月24日   30   0   0 字段Java字段Java
CLYEAq02EKEQ