zoukankan      html  css  js  c++  java
  • Temp

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;


    using IBatisNet.Common;
    using IBatisNet.DataMapper;
    using IBatisNet.Common.Utilities;
    using DAO;
    using Model;

    public partial class DynamicControl_two : System.Web.UI.Page
    {
        private MainProcess[] main;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ViewState["MP"] == null)
            {
                main = new MainProcess[1];
                main[0] = new MainProcess();
               // main[0].addProcess(new MainProcess.Process());
                ViewState["MP"] = main;
                //Response.Write("<script language=javascript>alert('null')</script>");
                addMainProcess();
            }
            else
            {
                  //Response.Write("<script language=javascript>alert('Load')</script>");
                this.Container.Controls.Clear();
                addMainProcess();
            }
        }
        private void addMainProcess()
        {
            main = (MainProcess[])ViewState["MP"];
            for (int num = 1; num < main.Length+ 1; num++)
            {
                Table table = new Table();
                table.ID = "_table" + num;
                TableRow trHead = new TableRow();
                TableCell tcHead = new TableCell();

                //add table head
                Label lblHead = new Label();
                lblHead.ID = "_lblHead" + num;
                lblHead.Text = "MainProcess: " + num;

                Button btnDeleteMainProcess = new Button();
                btnDeleteMainProcess.ID = "_btnDeleteMainProcess" + num;
                btnDeleteMainProcess.Text = "DeleteMainProcess";
                btnDeleteMainProcess.Click += new EventHandler(btnDeleteMainProcess_Click);
                btnDeleteMainProcess.CommandName = "_deleteMainProcess" + num;

                Button btnAddProcess = new Button();
                btnAddProcess.ID = "_btnAddProcess" + num;
                btnAddProcess.Text = "AddProcess";
                btnAddProcess.Click += new EventHandler(btnAddProcess_Click);
                btnAddProcess.CommandName = "_addProcess" + num;

                tcHead.Controls.Add(lblHead);
                tcHead.Controls.Add(btnDeleteMainProcess);
                tcHead.Controls.Add(btnAddProcess);
                trHead.Controls.Add(tcHead);
                table.Controls.Add(trHead);
               
           
                for (int i = 1; i < main[num-1].ProList.Length+1; i++)
                {              
                    table.Controls.Add(addProcess(num,i));
                }
                this.Container.Controls.Add(table);
            }
        }

        private TableRow addProcess(int mainIndex,int proIndex)
        {
            string location = mainIndex.ToString() + proIndex.ToString();
            //add table row
            TableRow tri = new TableRow();
            TableCell tci = new TableCell();

            Label lblProcessName = new Label();
            lblProcessName.ID = "_lblProName" + location;
            lblProcessName.Text = "Process" + proIndex + ":";

            TextBox txtProcessName = new TextBox();
            txtProcessName.ID = "_txtProcessName" + location;

            Label lblPrincipal = new Label();
            lblPrincipal.ID = "_lblPrincipal" + location;
            lblPrincipal.Text = "Principal:";

            DropDownList ddlPrincipal = new DropDownList();
            ddlPrincipal.ID = "_ddlPrincipal" + location;
            //bindDDL(ddlPrincipal);

            Button btnDeleteProcess = new Button();
            btnDeleteProcess.ID = "_btnDeleteProcess" + location;
            btnDeleteProcess.Text = "DeleteProcess" + proIndex;
            btnDeleteProcess.Click += new EventHandler(btnDeleteProcess_Click);
            btnDeleteProcess.CommandName = "_deleteProcess" + location;


            tci.Controls.Add(lblProcessName);
            tci.Controls.Add(txtProcessName);
            tci.Controls.Add(lblPrincipal);
            tci.Controls.Add(ddlPrincipal);
            tci.Controls.Add(btnDeleteProcess);

            tri.Controls.Add(tci);
            return tri;
        }

        protected void btnAddMainProcess_Click(object sender, EventArgs e)
        {
           // Response.Write("<script language=javascript>alert('addMain')</script>");
            main = (MainProcess[])ViewState["MP"];
            MainProcess[] temp = new MainProcess[main.Length + 1];
            for (int i = 0; i < main.Length; i++)
            {
                temp[i] = main[i];
            }
            temp[main.Length] = new MainProcess();
            ViewState["MP"] = temp;
        }  

        void btnDeleteMainProcess_Click(object sender, EventArgs e)
        {
           // Response.Write("<script language=javascript>alert('DeleteMain')</script>");
            main = (MainProcess[])ViewState["MP"];
            string flag = ((Button)sender).CommandName;
            int index =int.Parse(flag.Substring(flag.Length-1,1))-1;

            MainProcess[] temp = new MainProcess[main.Length - 1];
            for (int i = 0; i < main.Length; i++)
            {
                if (i < index) temp[i] = main[i];
                else if (i > index) temp[i - 1] = main[i];
            }
            ViewState["MP"] = temp;
        }

        void btnAddProcess_Click(object sender, EventArgs e)
        {
            string flag = ((Button)sender).CommandName;
            int index = int.Parse(flag.Substring(flag.Length - 1, 1)) - 1;
            main = (MainProcess[])ViewState["MP"];
            main[index].addProcess(new MainProcess.Process());
            ViewState["MP"] = main;
        }
        void btnDeleteProcess_Click(object sender, EventArgs e)
        {
            string flag = ((Button)sender).CommandName;
            string location = flag.Substring(flag.Length - 2, 2);
            int mpIndex = int.Parse(flag.Substring(flag.Length - 2, 1)) - 1;
            int proIndex = int.Parse(flag.Substring(flag.Length - 1, 1)) - 1;
            main = (MainProcess[])ViewState["MP"];
            main[mpIndex].removeProcess(proIndex);
            ViewState["MP"] = main;
        }
        private void readData()
        {
            main = (MainProcess[])ViewState["MP"];
            for (int i = 0; i < main.Length; i++)
            {
                Table tabel = (Table)Container.FindControl("_table" + (i+1));
                for (int row = 1; row < tabel.Rows.Count; row++)
                {
                   // main[i].ProList[row].ProName = ((TextBox)tabel.Rows[row].Cells[0].FindControl("_txtProcessName" + (i+1).ToString() + (row+1))).Text;
                    main[i].ProList[row-1].ProName = ((TextBox)tabel.Rows[row].Cells[0].Controls[1]).Text;
                    Response.Write(main[i].ProList[row-1].ProName + "<br>");
                }
            }
            ViewState["MP"] = main;
        }
        private void bindData()
        {

        }
        private void bindDDL(DropDownList ddl)
        {
            ddl.DataSource = Mapper.Instance().QueryForList("SelectArticalDetail", null);
            ddl.DataTextField = "Author_Name";
            ddl.DataValueField = "Detail_ID";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("", "-1"));
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            readData();
        }
    }

  • 相关阅读:
    【题解】[湖南集训]谈笑风生
    【题解】[POI2011]ROT-Tree Rotations
    【题解】[ZJOI2019]语言
    【题解】[HEOI2012]采花
    【题解】[JSOI2009]计数问题
    【题解】[USACO17JAN]Promotion Counting P
    heketi简单安装配置使用
    kubernetes api
    skywalking简单安装配置使用
    《技术的正宗与野路子》
  • 原文地址:https://www.cnblogs.com/Flynn/p/869522.html
Copyright © 2011-2022 走看看