private void GenMasterTableData(ref PccErrMsg myLabel)
    {
        bs_GroupManage mybs = new bs_GroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("StartRecord", PageControl1.StartRecord.ToString());
        myMsg.CreateFirstNode("PageSize", PageControl1.PageSize.ToString());
        myMsg.CreateFirstNode("ap_id", Request.QueryString["ApID"]);
        myMsg.CreateFirstNode("group_nm", txtGroupName.Text);

        //加入判斷是否要有事業群之判斷20041116
        string strGroupFilter = "N", strFactFilter = "N";
        string strTemp = "";
        myMsg.CreateFirstNode("user_id", Session["UserID"].ToString());
        GetMenuAuth myAuth = new GetMenuAuth();

        //判斷是否要利用事業群來分設權限
        if (ConfigurationManager.AppSettings[m_apid + "-FactByGroup"] != null && ConfigurationManager.AppSettings[m_apid + "-FactByGroup"].ToString() == "Y")
        {
            //判斷此使用者是否可以分配不同的事業群權限
            if (!myAuth.IsReportAuth())
            {
                //表示他必須區分事業群
                myMsg.CreateFirstNode("GroupFilter", "Y");
                strGroupFilter = "Y";
            }
            else
            {
                myMsg.CreateFirstNode("GroupFilter", "N");
            }
        }
        else
        {
            myMsg.CreateFirstNode("GroupFilter", "N");
        }

        if (ConfigurationManager.AppSettings[m_apid + "-FactFilter"] != null && ConfigurationManager.AppSettings[m_apid + "-FactFilter"].ToString() == "Y")
        {
            //表示他必須區分廠管理 20041118 注意要區別廠管理的先決條件是要區分事業群
            myMsg.CreateFirstNode("FactFilter", "Y");
            strFactFilter = "Y";
        }

        string strXML = myMsg.GetXmlStr;
        DataSet myGroupDs = mybs.DoReturnDataSet("GetGroupbyApID", strXML, "");

        DataTable myGroupData = myGroupDs.Tables["Group"];

        if (myGroupData.Rows.Count > 0)
        {
            int MasterCount = 0;
            string MasterStyle = "";
            PccMsg myTempMsg;

            PccRow myRow;
            //取出資料總筆數
            PageControl1.TotalSize = myGroupDs.Tables["TCounts"].Rows[0]["Counts"].ToString();
            PageControl1.BuildPager();

            //明細資料類別之共同參數
            myMsg.LoadXml();
            myMsg.CreateFirstNode("TableClass", "ActDocTB");
            myMsg.CreateFirstNode("RowHeaderClass", "TDShowHeader");
            myMsg.CreateFirstNode("RowClass1", "ffd000");
            myMsg.CreateFirstNode("RowClass2", "fff000");
            string strClassXML = myMsg.GetXmlStr;

            //使用者明細資料類別之參數
            string strOrgFields5 = "";
            if (myAuth.IsDeleteAuth())
            {
                strOrgFields5 = "btn-刪除-Return_Click(this)";
            }
            string[] Fields = { "編號", "電子郵件帳號", "使用者名稱", "廠別", strOrgFields5 };
            int[] FieldsPercent = { 5, 30, 20, 35, 10 };
            string[] FieldsItem = { "--NO--", "email", "user_desc", "fact_nm", "user_id" };
            //string[] TransFunc = {"","TransUserNm","TransUserDesc","TransFactNm",""};
            string[] FieldsType = new string[5];
            FieldsType[0] = "--NO--";
            FieldsType[1] = "<PccMsg><Type>Text</Type></PccMsg>";
            FieldsType[2] = "<PccMsg><Type>Text</Type></PccMsg>";
            FieldsType[3] = "<PccMsg><Type>Text</Type></PccMsg>";
            FieldsType[4] = "<PccMsg><Type>CheckBox</Type><Value>user_id</Value></PccMsg>";

            //選單明細資料類別之參數
            string strOrgFields8 = "";
            if (myAuth.IsUpdateAuth())
            {
                strOrgFields8 = "btn-更新送出-Return_ClickM(this)"; ;
            }

            //判斷是否為超級管理者,若是則不控管自己Menu的CheckBox權限 20041119
            string strcheckbox = "";
            if (Session["UserEMail"].ToString() != ConfigurationManager.AppSettings["superAdminEmail"].ToString())
                strcheckbox = "CheckBoxByValueJudgeUserRight";
            else
                strcheckbox = "CheckBoxByValue";

            string[] MFields = { "編號", "選單名稱", "顯示權限", "新增權限", "更新權限", "刪除權限", "報表權限", "發信權限", strOrgFields8 };
            int[] MFieldsPercent = { 5, 25, 10, 10, 10, 10, 10, 10, 10 };
            string[] MFieldsItem = { "--NO--", "menu_nm", "show_mk", "add_mk", "upd_mk", "del_mk", "rpt_mk", "send_mk", "groupd_id" };
            string[] MFieldsType = new string[9];
            MFieldsType[0] = "--NO--";
            MFieldsType[1] = "<PccMsg><Type>Text</Type></PccMsg>";
            MFieldsType[2] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[3] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[4] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[5] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[6] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[7] = "<PccMsg><Type>" + strcheckbox + "</Type><Value>menu_id</Value></PccMsg>";
            MFieldsType[8] = "<PccMsg><Type>Space</Type></PccMsg>";

            //要取得明細資料的Table變數
            DataTable tblUserGroup, tblMenuGroup;

            //再利用此Table再取得其每一列的資料,再Gen出主要的Table Row.
            foreach (DataRow myMasterRow in myGroupData.Rows)
            {
                if (MasterCount % 2 == 0) MasterStyle = "cssGridRowAlternating"; else MasterStyle = "cssGridRow";
                myRow = new PccRow("", HorizontalAlign.Center, 0, 0);
                myRow.SetRowCss(MasterStyle);

                //編號
                myRow.AddTextCell(PageControl1.ListCount, 10);
                //群組名稱(點選群組名稱可把使用者加入此群組)
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", myMasterRow["group_nm"].ToString());
                myTempMsg.CreateFirstNode("LinkID", "ULink" + myMasterRow["group_id"].ToString());
                myTempMsg.CreateFirstNode("Href", USERADDCOMEON + "?ApID=" + CheckQueryString("ApID") + "&GroupID=" + myMasterRow["group_id"].ToString() + "&GroupNm=" + myMasterRow["group_nm"].ToString() + "&QueryCondition=" + GetQueryCondition());
                myTempMsg.CreateFirstNode("Text", myMasterRow["group_nm"].ToString());
                myRow.AddLinkHrefCell(myTempMsg.GetXmlStr, 60);
                //檢視使用者
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", myLabel.GetErrMsg("lbl0020", "ADTPurDoc/GroupManage"));
                myTempMsg.CreateFirstNode("LinkID", "HLinkViewU" + myMasterRow["group_id"].ToString());
                myTempMsg.CreateFirstNode("Image", Session["PageLayer"] + "images/detal.gif");
                myTempMsg.CreateFirstNode("ClickFun", "doSection(view_U" + MasterCount.ToString() + ")");
                myRow.AddLinkCell(myTempMsg.GetXmlStr, 10);
                //檢視選單
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", myLabel.GetErrMsg("lbl0021", "ADTPurDoc/GroupManage"));
                myTempMsg.CreateFirstNode("LinkID", "HLinkViewM" + myMasterRow["group_id"].ToString());
                myTempMsg.CreateFirstNode("Image", Session["PageLayer"] + "images/detal.gif");
                myTempMsg.CreateFirstNode("ClickFun", "doSection(view_M" + MasterCount.ToString() + ")");
                myRow.AddLinkCell(myTempMsg.GetXmlStr, 10);
                //群組管理
                myTempMsg.LoadXml();
                //加入群組管理修改及刪除的Item
                if (myAuth.IsUpdateAuth())
                {
                    myTempMsg.CreateNode("LinkButton");
                    myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/edit.gif");
                    myTempMsg.AddToNode("ToolTip", "修改群組");
                    myTempMsg.AddToNode("href", GROUPADDNEW + "?ApID=" + Request.Params["ApID"].ToString());
                    myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                    myTempMsg.AddToNode("Method", GetMethod("MasterUpdateFunc", "group_id", "group_nm", myMasterRow));
                    myTempMsg.UpdateNode();
                }
                if (myAuth.IsDeleteAuth())
                {
                    myTempMsg.CreateNode("LinkButton");
                    myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                    myTempMsg.AddToNode("ToolTip", "刪除群組");
                    myTempMsg.AddToNode("href", GROUPMANAGE + "?ApID=" + Request.Params["ApID"].ToString());
                    myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                    myTempMsg.AddToNode("Method", GetMethod("MasterDelFunc", "group_id", "group_nm", myMasterRow));
                    myTempMsg.UpdateNode();
                }
                myRow.AddMultiLinkCell(myTempMsg.GetXmlStr, 10);

                tblGroup.Rows.Add(myRow.Row);

                //設定使用者明細資料類別之參數
                strTemp = "<PccMsg>";
                strTemp += "<group_id>" + myMasterRow["group_id"].ToString() + "</group_id>";
                strTemp += "<ap_id>" + m_apid + "</ap_id>";
                strTemp += "<user_id>" + Session["UserID"].ToString() + "</user_id>";
                strTemp += "<GroupFilter>" + strGroupFilter + "</GroupFilter>";
                strTemp += "<FactFilter>" + strFactFilter + "</FactFilter>";
                strTemp += "</PccMsg>";
                tblUserGroup = mybs.DoReturnDataSet("GetUserByGroupID", strTemp, "").Tables["UserGroup"];

                PccDetailTable myDTable = new PccDetailTable("UDT" + myMasterRow["group_id"].ToString());
                myDTable.ClassXML = strClassXML;
                myDTable.Fields = Fields;
                myDTable.FieldsPercent = FieldsPercent;
                myDTable.FieldsItem = FieldsItem;
                myDTable.FieldsType = FieldsType;
                myDTable.NewDataTable = tblUserGroup;

                //myDTable.TransFunc = TransFunc;
                //myDTable.objThis = this;

                myDTable.Create();

                myRow.Reset();
                myRow.SetRowCss("off");
                myRow.SetRowID("view_U" + MasterCount);
                myRow.SetDefaultCellData("DGridTD", HorizontalAlign.Center, 0, 10);
                myRow.AddControl(myDTable.NewTable, 100);

                tblGroup.Rows.Add(myRow.Row);

                //設定選單明細資料類別之參數
                tblMenuGroup = mybs.DoReturnDataSet("GetMenuByGroupID", "<PccMsg><group_id>" + myMasterRow["group_id"].ToString() + "</group_id></PccMsg>", "").Tables["MenuGroup"];

                PccDetailTable myMDTable = new PccDetailTable("MDT" + myMasterRow["group_id"].ToString());
                myMDTable.ClassXML = strClassXML;
                myMDTable.Fields = MFields;
                myMDTable.FieldsPercent = MFieldsPercent;
                myMDTable.FieldsItem = MFieldsItem;
                myMDTable.FieldsType = MFieldsType;
                myMDTable.NewDataTable = tblMenuGroup;

                myMDTable.Create();

                if (m_menuIDArray == null)
                {
                    m_menuIDArray = myMDTable.GetDataArray("menu_id");
                    ViewState["MenuID"] = m_menuIDArray;
                }

                myRow.Reset();
                myRow.SetRowCss("off");
                myRow.SetRowID("view_M" + MasterCount);
                myRow.SetDefaultCellData("DGridTD", HorizontalAlign.Center, 0, 10);
                myRow.AddControl(myMDTable.NewTable, 100);

                tblGroup.Rows.Add(myRow.Row);

                MasterCount += 1;

            } // end of foreach datarow
        } // end of if table count is 0
        else
        {
            PageControl1.TotalSize = "0";
            PageControl1.BuildPager();
        }
    }
    private DropDownList GetGroup(string ask_id)
    {
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("ap_id", m_apid);
        myMsg.CreateFirstNode("group_nm", "");

        GetMenuAuth myAuth = new GetMenuAuth();

        //判斷是否要利用事業群來分設權限 20041118
        myMsg.CreateFirstNode("user_id", Session["UserID"].ToString());

        if (ConfigurationManager.AppSettings[m_apid + "-FactByGroup"] != null && ConfigurationManager.AppSettings[m_apid + "-FactByGroup"].ToString() == "Y")
        {
            //判斷此使用者是否可以分配不同的事業群權限
            if (!myAuth.IsReportAuth())
            {
                //表示他必須區分事業群
                myMsg.CreateFirstNode("GroupFilter", "Y");
            }
            else
            {
                myMsg.CreateFirstNode("GroupFilter", "N");
            }
        }
        else
        {
            myMsg.CreateFirstNode("GroupFilter", "N");
        }

        bs_GroupManage mybsGroup = new bs_GroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        DataTable dt = mybsGroup.DoReturnDataSet("GetAllGroupByApID", myMsg.GetXmlStr, "").Tables["Group"];

        DataRow myRow = dt.NewRow();
        myRow["group_id"] = 0;
        myRow["group_nm"] = "--請選擇--";
        myRow["group_type"] = "0";
        dt.Rows.InsertAt(myRow, 0);

        DropDownList myddlGroup = new DropDownList();

        myddlGroup.ID = "ddlGroup";
        myddlGroup.Attributes.Add("onChange", "GroupChange(this)");
        //myddlGroup.Enabled = false;

        myddlGroup.DataSource = dt.DefaultView;
        myddlGroup.DataTextField = "group_nm";
        myddlGroup.DataValueField = "group_id";
        myddlGroup.DataBind();

        return myddlGroup;
    }
    private void SetData(ref PccCommonForC.PccMsg myMsg)
    {
        PccMsg myMsg1 = new PccMsg();
        myMsg1.CreateFirstNode("group_id", myMsg.Query("Key"));

        bs_GroupManage mybs = new bs_GroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        DataSet dsReturn = mybs.DoReturnDataSet("GetGroupByGroupID", myMsg1.GetXmlStr, "");

        if (dsReturn != null)
        {
            DataTable dt = dsReturn.Tables["Group"];
            txtGroupName.Text = dt.Rows[0]["group_nm"].ToString();

            ddlGroupType.SelectedIndex = -1;
            ddlGroupType.Items.FindByValue(dt.Rows[0]["group_type"].ToString()).Selected = true;
        }
        else
        {
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = "載入資料錯誤";
        }
    }
    private void BindDataGrid(string strOrder, string strUserDesc, string strFactID, ref bs_GroupManage mybs)
    {
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("ap_id", CheckQueryString("ApID"));
        myMsg.CreateFirstNode("group_id", CheckQueryString("GroupID"));
        myMsg.CreateFirstNode("fact_id", strFactID);
        myMsg.CreateFirstNode("user_desc", strUserDesc);
        myMsg.CreateFirstNode("order", strOrder);

        //加入判斷是否要有事業群之判斷20041116
        myMsg.CreateFirstNode("user_id", Session["UserID"].ToString());
        GetMenuAuth myAuth = new GetMenuAuth();
        myAuth.AspxFile = "GroupManage104.aspx";

        //判斷是否要利用事業群來分設權限
        if (ConfigurationManager.AppSettings[m_apid + "-FactByGroup"] != null && ConfigurationManager.AppSettings[m_apid + "-FactByGroup"].ToString() == "Y")
        {
            //判斷此使用者是否可以分配不同的事業群權限
            if (!myAuth.IsReportAuth())
            {
                //表示他必須區分事業群
                myMsg.CreateFirstNode("GroupFilter", "Y");
            }
            else
            {
                myMsg.CreateFirstNode("GroupFilter", "N");
            }
        }
        else
        {
            myMsg.CreateFirstNode("GroupFilter", "N");
        }

        if (ConfigurationManager.AppSettings[m_apid + "-FactFilter"] != null && ConfigurationManager.AppSettings[m_apid + "-FactFilter"].ToString() == "Y")
        {
            //表示他必須區分廠管理 20041118 注意要區別廠管理的先決條件是要區分事業群
            myMsg.CreateFirstNode("FactFilter", "Y");
        }

        DataSet ds = mybs.DoReturnDataSet("GetAnotherUserByGroup", myMsg.GetXmlStr, "");
        ViewState["order"] = strOrder;

        if (ds != null)
        {
            DataGrid1.DataSource = ds.Tables["AnotherUserByGroup"].DefaultView;
            DataGrid1.DataBind();
        }
        else
        {
            btnAddComeOn.Visible = false;
        }
    }