zoukankan      html  css  js  c++  java
  • asp.net动态生成表格和控件

    asp.net动态生成表格和控件

     

                                        <asp:Table ID="TableFlowDetail" runat="server" Font-Size="12px" CellPadding="0" CellSpacing="0" Width="50%">
                                        </asp:Table>

    #region 组成明细审核流程
            dt 
    = commFD .SelectCommFlowDetailsDynamic("CommFlowID=" + FlowID + " and DeleteFlag=0""AuditingOrder ASC");
            
    if (dt.Rows.Count > 0)
            {
                
    for (int i = 1; i <= dt.Rows.Count; i++//注意下标从1开始的
                {
                    
    //TableRow row = new TableRow();

                    TableRow rowHead 
    = new TableRow();
                    TableRow rowRecord 
    = new TableRow();
                    TableCell cellHead 
    = new TableCell();
                    TableCell cellRecord 
    = new TableCell();
                    cellHead.HorizontalAlign 
    = HorizontalAlign.Center;
                    rowHead.Height 
    = 22;

                    
    this.TableFlowDetail.BorderColor = System.Drawing.Color.DarkGray;
                    
    this.TableFlowDetail.BorderWidth = 1;

                    cellHead.BorderWidth 
    = 1;
                    cellRecord.BorderWidth 
    = 1;

                    Table tableRecord 
    = new Table();
                    TableRow rowDetailHead 
    = new TableRow();
                    TableRow rowDetailRecord 
    = new TableRow();
                    tableRecord.CellPadding 
    = 0;
                    tableRecord.CellSpacing 
    = 0;
                    tableRecord.BorderWidth 
    = 1;
                    tableRecord.Width 
    = 560;
                    tableRecord.BorderColor 
    = System.Drawing.Color.DarkGray;
                    rowDetailHead.HorizontalAlign 
    = HorizontalAlign.Center;
                    rowDetailRecord.HorizontalAlign 
    = HorizontalAlign.Center;

                    Label labelHead 
    = new Label();
                    labelHead.ID 
    = "labelHead" + i.ToString();

                    
    //后面要用到审核按钮是否生效
                    string commFlowDetailID = dt.Rows[i - 1]["commflowdetailid"].ToString();
                    
    string AuditingName = oas.GetPersonName(commAD.GetAuditinguserID(materialApplyID,commFlowDetailID));
                    
    string HistoryAuditingName = oas.GetPersonName(commAD.GetHistoryAuditinguserID(materialApplyID, commFlowDetailID));
                    
    string currentName = oas.SelectArchivesName(Session["Hwapu_OAS_UserID"].ToString());
                    
    bool enable = false;
                    
    if (AuditingName.IndexOf(currentName)>=0 && IsSubmit == 1 && currentStatus ==1 && IsFreeze == 0)
                        enable 
    = true;
                    
    else
                        enable 
    = false;
                    
    /* 控制是否开启审核后修改的开关*/
                    
    //判断是否是最后一条记录或后面的审核人没有开始审核
                    if (enable) //如果已经是不可用了就不必判断了
                    {
                        dtRecord.Clear();
                        
    if (dt.Rows.Count > i)//不大于说明还没到
                        {
                            dtRecord 
    = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'  and  auditingflag=1 and historyflag=0""CommAuditingDetailID desc");
                            
    if (dtRecord.Rows.Count > 0//有记录,说明已经开始审核了
                            {
                                enable 
    = false;
                            }
                        }
                        
    else
                        {
                            
    //如果已经达到流程的最后一个阶段了,
                            
    //则判断最后一个阶段是否开始审核,如果已经开始了则就不能修改了,最后一个流程有记录了说明已经开始了
                            dtRecord = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'  and  auditingflag=1 and historyflag=0""CommAuditingDetailID desc");
                            
    if (dtRecord.Rows.Count > 0)
                                enable 
    = false;
                        }
                        
    //这里为了防止如果审核的流程里有两个步骤是同一个人审核时会出现两部都可以审核,这里控制只能第一个可以审核
                        
    //后面的必须等前面的审核了才能审核
                        if (enable && i > 1//i>1是为了避免第一个,因为他前面没有记录
                        {
                            dtRecord.Clear();
                            dtRecord 
    = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i - 2]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'  and  auditingflag=1 and historyflag=0""CommAuditingDetailID desc");
                            
    if (dtRecord.Rows.Count <= 0)//没有记录说明前面的还没开始
                                enable = false;
                        }
                        
    if (enable)
                        {
                            dtRecord.Clear();
                            dtRecord 
    = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'  and  auditingflag=1 and historyflag=0""CommAuditingDetailID desc");
                            
    if (dtRecord.Rows.Count > 0)//没有记录说明前面的还没开始
                                enable = false;
                        }
                    }

                    
                    labelHead.Text 
    += dt.Rows[i - 1]["AuditingDept"].ToString() + "";
                    labelHead.Text 
    += oas.GetPersonName(commAD.GetAuditinguserID(materialApplyID, commFlowDetailID));//dt.Rows[i - 1]["AuditingName"].ToString() + ",";
                    if (HistoryAuditingName.Length > 0)
                        labelHead.Text 
    += "(原审核人:"+HistoryAuditingName+")";
                    labelHead.Text 
    += dt.Rows[i - 1]["NeedTime"].ToString() + "工作日";
                    labelHead.Text 
    += "<font color='RoyalBlue'>(" + dt.Rows[i - 1]["Remark"].ToString() + ")</font>";
                    cellHead.Controls.Add(labelHead);
                    rowHead.Cells.Add(cellHead);
                    
    this.TableFlowDetail.Rows.Add(rowHead);

                    
    #region 开始明细记录表的建立

                    System.Collections.ArrayList listDetailHead 
    = new ArrayList();
                    System.Collections.ArrayList listDetailRecord 
    = new ArrayList();
                    listDetailHead 
    = oas.SplitString(dt.Rows[i - 1]["DetailHead"].ToString(), "|");

                    
    //labelAuditingOrder.Text = dt.Rows[i - 1]["AuditingOrder"].ToString();

                    
    //labelDetailHead.Text = dt.Rows[i - 1]["DetailHead"].ToString();
                    
    //查询明细流程的审核记录
                    dtRecord.Clear();

                    
    if (this.LabelIsSubmit.Text.Trim().Equals("提交"))//提交状态不看上一次失败的审核记录
                        dtRecord = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'  and auditingflag=0 and  Historyflag=0""CommAuditingDetailID desc");
                    
    else //未提交时可以看上一次失败的审核记录
                        dtRecord = commAD.SelectCommAuditingDetailsDynamic("CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + " and BillID='" + materialApplyID + "'""CommAuditingDetailID desc");
                    
                    
    if (dtRecord.Rows.Count > 0)
                        listDetailRecord 
    = oas.SplitStringBill(dtRecord.Rows[0]["DetailRecord"].ToString(), '|');
                    
    for (int j = 0; j < listDetailHead.Count; j++)
                    {
                        TableCell cellDetailHead 
    = new TableCell();
                        TableCell cellDetialRecord 
    = new TableCell();

                        Label labelDetailHead 
    = new Label();
                        Label labelDetailRecord 
    = new Label();
                        cellDetailHead.BorderWidth 
    = 1;
                        cellDetialRecord.BorderWidth 
    = 1;
                        labelDetailHead.ID 
    = "labelDetailHead" + j.ToString();
                        labelDetailHead.Text 
    = listDetailHead[j].ToString();
                        labelDetailRecord.ID 
    = "labelDetailRecord" + j.ToString();
                        
    if (listDetailRecord.Count > 0)
                            
    if(dtRecord .Rows[0]["auditingflag"].ToString().Equals("1"))
                                   labelDetailRecord.Text 
    = listDetailRecord[j].ToString();
                        
    else
                            labelDetailRecord.Text 
    = "  ";

                        cellDetailHead.Controls.Add(labelDetailHead);
                        cellDetialRecord.Controls.Add(labelDetailRecord);
                        rowDetailHead.Cells.Add(cellDetailHead);
                        rowDetailRecord.Cells.Add(cellDetialRecord);
                    }

                    TableCell cellAuditingStateHead 
    = new TableCell();
                    TableCell cellAuditingStateRecord 
    = new TableCell();
                    cellAuditingStateHead.BorderWidth 
    = 1;
                    cellAuditingStateRecord.BorderWidth 
    = 1;
                    Label labelAuditingStateHead 
    = new Label();
                    Label labelAuditingStateRecord 
    = new Label();
                    labelAuditingStateHead.ID 
    = "labelAuditingStateHead";
                    labelAuditingStateHead.Text 
    = "审核状态";
                    labelAuditingStateRecord.ID 
    = "labelAuditingStateRecord";

                    
    if (dtRecord.Rows.Count > 0)
                    {
                        
    if (dtRecord.Rows[0]["AuditingStatus"].ToString().Equals("0"))
                            labelAuditingStateRecord.Text 
    = "未审核";
                        
    else if (dtRecord.Rows[0]["AuditingStatus"].ToString().Equals("1"))
                            labelAuditingStateRecord.Text 
    = "<font color='#00AA00'>审核通过</font>";
                        
    else if (dtRecord.Rows[0]["AuditingStatus"].ToString().Equals("2"))
                            labelAuditingStateRecord.Text 
    = "<font color='#00AA00'>合格</font>";
                        
    else if (dtRecord.Rows[0]["AuditingStatus"].ToString().Equals("-1"))
                            labelAuditingStateRecord.Text 
    = "<font color='#AA0000'>审核失败</font>";
                        
    else if (dtRecord.Rows[0]["AuditingStatus"].ToString().Equals("-2"))
                            labelAuditingStateRecord.Text 
    = "<font color='#AA0000'>废弃</font>";
                    }
                    
    else
                        labelAuditingStateRecord.Text 
    = "  ";

                    cellAuditingStateHead.Controls.Add(labelAuditingStateHead);
                    cellAuditingStateRecord.Controls.Add(labelAuditingStateRecord);
                    rowDetailHead.Cells.Add(cellAuditingStateHead);
                    rowDetailRecord.Cells.Add(cellAuditingStateRecord);



                    TableCell cellAuditingAddDateHead 
    = new TableCell();
                    TableCell cellAuditingAddDateRecord 
    = new TableCell();
                    cellAuditingAddDateHead.BorderWidth 
    = 1;
                    cellAuditingAddDateRecord.BorderWidth 
    = 1;
                    Label labelAuditingAddDateHead 
    = new Label();
                    Label labelAuditingAddDateRecord 
    = new Label();
                    labelAuditingAddDateHead.ID 
    = "labelAuditingStateHead";
                    labelAuditingAddDateHead.Text 
    = "审核日期";
                    labelAuditingAddDateRecord.ID 
    = "labelAuditingStateRecord";

                    
    if (dtRecord.Rows.Count > 0)
                        labelAuditingAddDateRecord.Text 
    =OASBasicBLL.GetFormateDate( dtRecord.Rows[0]["AddDate"].ToString());
                    
    else
                        labelAuditingAddDateRecord.Text 
    = "  ";

                    cellAuditingAddDateHead.Controls.Add(labelAuditingAddDateHead);
                    cellAuditingAddDateRecord.Controls.Add(labelAuditingAddDateRecord);
                    rowDetailHead.Cells.Add(cellAuditingAddDateHead);
                    rowDetailRecord.Cells.Add(cellAuditingAddDateRecord);

                    TableCell cellAuditingIdeaHead 
    = new TableCell();
                    TableCell cellAuditingIdeaRecord 
    = new TableCell();
                    cellAuditingIdeaHead.BorderWidth 
    = 1;
                    cellAuditingIdeaRecord.BorderWidth 
    = 1;
                    Label labelAuditingIdeaHead 
    = new Label();
                    Label labelAuditingIdeaRecord 
    = new Label();
                    labelAuditingIdeaHead.ID 
    = "labelAuditingIdeaHead";
                    labelAuditingIdeaHead.Text 
    = "审核意见";
                    labelAuditingIdeaRecord.ID 
    = "labelAuditingIdeaRecord";

                    
    if (dtRecord.Rows.Count > 0)
                        labelAuditingIdeaRecord.Text 
    = dtRecord.Rows[0]["AuditingIdea"].ToString();
                    
    else
                        labelAuditingIdeaRecord.Text 
    = "  ";

                    cellAuditingIdeaHead.Controls.Add(labelAuditingIdeaHead);
                    cellAuditingIdeaRecord.Controls.Add(labelAuditingIdeaRecord);
                    rowDetailHead.Cells.Add(cellAuditingIdeaHead);
                    rowDetailRecord.Cells.Add(cellAuditingIdeaRecord);

                    TableCell cellDetailOperateHead 
    = new TableCell();
                    TableCell cellDetailOperateRecord 
    = new TableCell();

                    cellDetailOperateHead.BorderWidth 
    = 1;
                    cellDetailOperateRecord.BorderWidth 
    = 1;

                    Label labelDetailOperate 
    = new Label();
                    labelDetailOperate.ID 
    = "labelDetailOperate";
                    labelDetailOperate.Text 
    = "操作";

                    
    //LinkButton linkButtonEdit = new LinkButton();   
                    
    //linkButtonEdit.ID = "linkButtonEdit";              
                    
    //linkButtonEdit.Text = "修改";             
                    
    //linkButtonEdit.CommandArgument = dt.Rows[i - 1]["FlowDetailID"].ToString();  
                    
    //linkButtonEdit.Command += new CommandEventHandler(this.LinkButtonEditClick);  //LinkButtonEditClick(dt.Rows[i - 1]["FlowDetailID"].ToString());

                    HyperLink linkEdit 
    = new HyperLink();
                    linkEdit.ID 
    = "linkEdit";


                    
    if (dtRecord.Rows.Count > 0)
                    {
                        linkEdit.Text 
    = "审核";
                        
    if (enable)
                        {
                            
    if (Request.QueryString["action"!= null)
                                linkEdit.NavigateUrl 
    = "MaterialApplyFlowAuditing.aspx?MaterialApplyID=" + Request.QueryString["MaterialApplyID"].ToString() + "&CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + "&CommAuditingDetailID=" + dtRecord.Rows[0]["CommAuditingDetailID"].ToString() + "&Operate=edit&action=" + Request.QueryString["action"].ToString() + "&url=MaterialApply";
                            
    this.HiddenCurrentAuditingDetailID.Value = dtRecord.Rows[0]["CommAuditingDetailID"].ToString();
                            
    this.ButtonDispach.Enabled = true;

                        }
                        
    else
                        {
                            linkEdit.ForeColor 
    = System.Drawing.Color.DarkGray;
                          
                        }
                    }
                    
    else
                    {
                        linkEdit.Text 
    = "审核";
                        
    if (enable)
                        {
                            
    if (Request.QueryString["action"!= null)
                                linkEdit.NavigateUrl 
    = "MaterialApplyFlowAuditing.aspx?MaterialApplyID=" + Request.QueryString["MaterialApplyID"].ToString() + "&CommFlowDetailID=" + dt.Rows[i - 1]["CommFlowDetailID"].ToString() + "&CommAuditingDetailID=" + dtRecord.Rows[0]["CommAuditingDetailID"].ToString() + "&Operate=auditing&action=" + Request.QueryString["action"].ToString() + "&url=MaterialApply";
                         
                        }
                        
    else
                            linkEdit.ForeColor 
    = System.Drawing.Color.DarkGray;
                    }

                    cellDetailOperateHead.Controls.Add(labelDetailOperate);
                    cellDetailOperateRecord.Controls.Add(linkEdit);

                    rowDetailHead.Cells.Add(cellDetailOperateHead);
                    rowDetailRecord.Cells.Add(cellDetailOperateRecord);
                    rowDetailHead.Height 
    = 22;
                    rowDetailRecord.Height 
    = 22;
                    rowDetailHead.Style.Add(HtmlTextWriterStyle.FontSize,
    "12px");
                    rowDetailRecord.Style.Add(HtmlTextWriterStyle.FontSize, 
    "12px");
                    tableRecord.Rows.Add(rowDetailHead);
                    tableRecord.Rows.Add(rowDetailRecord);
                    
    #endregion 明细记录表的建立完成

                    
    //添加明细记录表
                    cellRecord.Controls.Add(tableRecord);
                    rowRecord.Cells.Add(cellRecord);
                    rowRecord.Height 
    = 22;
                    
    this.TableFlowDetail.Rows.Add(rowRecord);
                    
    //this.TableFlowDetail.Style.Add("width","60%");

                }
            }
            
    #endregion
  • 相关阅读:
    有趣的网抑云
    [扩展阅读] timeit 模块详解(准确测量小段代码的执行时间)
    第044讲:魔法方法:简单定制
    第043讲:魔法方法:算术运算2
    第042讲:魔法方法:算术运算1
    第041讲:魔法方法:构造和析构
    吴恩达深度学习 第一课第四周课后编程作业 assignment4_2
    吴恩达深度学习 第一课第四周课后编程作业 assignment4_1
    第040讲:类和对象:一些相关的BIF
    [扩展阅读] property 的详细使用方法
  • 原文地址:https://www.cnblogs.com/ringwang/p/1370979.html
Copyright © 2011-2022 走看看