protected void btnDelOK_Click(object sender, System.EventArgs e)
    {
        plMain.Visible = true;
        plDelete.Visible = false;

        PccMsg myMsg = new PccMsg(CheckQueryString("Method"));
        string strGroupID = myMsg.Query("Key");
        myMsg.LoadXml();
        myMsg.CreateFirstNode("group_id", strGroupID);
        myMsg.CreateFirstNode("ap_id", CheckQueryString("ApID"));

        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"]);
        string strReturn = mybs.DoReturnStr("DeleteGroupByGroupID", myMsg.GetXmlStr, "");

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            GenMasterTable();
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + myMsg.Query("errmsg") + "');</script>");
        }
    }
    protected void btnOK_Click(object sender, System.EventArgs e)
    {
        if (txtGroupName.Text == "")
        {
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");
            lblMsg.Text = myLabel.GetErrMsg("lbl0010", "ADTPurDoc/GroupManage");
            return;
        }

        //先判斷是Insert or Update
        bool bUpdate = false;
        string group_id = "";
        PccMsg myMsg = new PccMsg();

        if (Request.Params["Method"] != null)
        {
            bUpdate = true;
            myMsg.LoadXml(Request.Params["Method"].ToString());
            group_id = myMsg.Query("Key");
        }

        myMsg.ClearContext();
        myMsg.CreateFirstNode("group_id", group_id);
        myMsg.CreateFirstNode("ap_id", CheckQueryString("ApID"));
        myMsg.CreateFirstNode("group_nm", txtGroupName.Text);
        myMsg.CreateFirstNode("group_type", ddlGroupType.SelectedItem.Value);

        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"]);
        string strReturn = "";

        if (bUpdate)
        {
            myMsg.CreateFirstNode("upd_id", Session["UserID"].ToString());
            strReturn = mybs.DoReturnStr("UpdateGroupByGroupID", myMsg.GetXmlStr, "");
        }
        else
        {
            myMsg.CreateFirstNode("add_id", Session["UserID"].ToString());
            strReturn = mybs.DoReturnStr("InsertGroupByApID", myMsg.GetXmlStr, "");
        }

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            Response.Redirect(GROUPMANAGE + "?ApID=" + CheckQueryString("ApID"));
        }
        else
        {
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myMsg.Query("errmsg");
        }
    }
    protected void BtnAddNewOK_ServerClick(object sender, System.EventArgs e)
    {
        PccMsg myMsg = new PccMsg();
        bs_FactGroupManage mybs = new bs_FactGroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        string strReturn = string.Empty;
        string strMsg = string.Empty;
        if (ViewState["ActionType"] != null && ViewState["ActionType"].ToString() == "New")
        {
            strReturn = mybs.DoReturnStr("Insert_DS_FGRP", GenDBXML(), string.Empty);
            strMsg = "新增成功";
        }
        else
        {
            strReturn = mybs.DoReturnStr("Update_DS_FGRP", GenDBXML(), string.Empty);
            strMsg = "修改成功";
        }
        myMsg.LoadXml(strReturn);
        string strUrl = FACTGROUPMAANGE + "?ApID=" + m_ApID + "&SelectedNode=" + TreeView1.SelectedValue;
        //string strUrl = FACTGROUPMAANGE + "?ApID=" + m_ApID + "&SelectedNode=" + TreeView1.SelectedNodeIndex;

        if (myMsg.Query("returnValue") == "0")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + strMsg + "');window.parent.location.href='" + strUrl + "';</script>");
        }
        else
        {
            LblErrMsg.Font.Size = FontUnit.Large;
            LblErrMsg.Text = myMsg.Query("errmsg");
        }
    }
    protected void btnDelOK_Click(object sender, System.EventArgs e)
    {
        PccMsg myMsg = new PccMsg(Request.Params["Method"].ToString());
        string strKey = myMsg.Query("Key");
        string strXML = "<PccMsg><user_id>" + Session["UserID"].ToString() + "</user_id><ask_id>" + strKey + "</ask_id></PccMsg>";

        PccBsSystemForC.bs_UserManager mybs = new PccBsSystemForC.bs_UserManager(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);

        DataTable dt;

        string strReturn = mybs.DoReturnStr("DeleteAskUser", strXML, "");
        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            //要送信給被駁回的申請者 20040418
            dt = mybs.DoReturnDataSet("GetAskByAskID", "", strKey).Tables["Ask"];

            if (!SendMailToApply(dt.Rows[0]["ap_id"].ToString(), dt.Rows[0]["ap_name"].ToString(), dt.Rows[0]["user_desc"].ToString(), dt.Rows[0]["email"].ToString()))
            {
                return;
            }
            Response.Redirect(CHECKUSERMANAGE + "?ApID=" + Request.Params["ApID"].ToString());
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + myMsg.Query("errmsg") + "');</script>");
        }
    }
    protected void btnOK_Click(object sender, System.EventArgs e)
    {
        if (CheckForm("JoinGroupID") == "")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('You not yet select group!');</script>");
            GenMasterTable();
            return;
        }

        string strReturn = "";
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("user_id", ViewState["UserID"].ToString());
        myMsg.CreateFirstNode("ap_id", CheckQueryString("ApID"));
        myMsg.CreateFirstNode("group_str", CheckForm("JoinGroupID"));
        myMsg.CreateFirstNode("group_org", ViewState["group_org"].ToString());

        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"]);

        strReturn = mybs.DoReturnStr("JoinGroupByUserID", myMsg.GetXmlStr, "");

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") != "0")
        {
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myMsg.Query("errmsg");
            GenMasterTable();
        }
        else
        {
            Response.Redirect(USERMANAGE + "?ApID=" + CheckQueryString("ApID") + "&QueryCondition=" + CheckQueryString("QueryCondition"));
        }
    }
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        if (ViewState["CurrentValue"] == null && tab_fact.Rows.Count == 0) return;

        Temporary();
        string strFact = "";
        bs_FactGroupManage mybs = new bs_FactGroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        strFact = Session["FactFgrpTemporary"].ToString();
        if (strFact.Length == 0)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('您還未選擇任何廠別唷!');</script>");
            GenMasterTable();
            return;
        }

        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("Ap_Id", m_Ap_Id);
        myMsg.CreateFirstNode("Fgrp_Id", m_Fgrp_Id);
        myMsg.CreateFirstNode("Fact_Str", strFact);
        myMsg.CreateFirstNode("Upd_Id", Session["UserID"].ToString());
        string strReturn = mybs.DoReturnStr("PickMultiFactToFgrp", myMsg.GetXmlStr, string.Empty);
        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") != "0")
        {
            lblMsg.Font.Size = 12;
            lblMsg.Text = myMsg.Query("errmsg");
            return;
        }
        else
        {
            Session["FactFgrpTemporary"] = string.Empty;
            Response.Redirect(FACTGROUPDETAIL + "?ApID=" + m_Ap_Id + "&SrcUp_Id=" + Request.QueryString["SrcUp_Id"] + "&Up_Id=" + Request.QueryString["Up_Id"] + "&QueryCondition=" + Request.QueryString["QueryCondition"]);
        }
    }
    protected void btnDelOK1_Click(object sender, System.EventArgs e)
    {
        string strReturn = "";
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("User_Id", Request.Params["User_ID"]);
        myMsg.CreateFirstNode("Ap_Id", CheckQueryString("ApID"));
        myMsg.CreateFirstNode("Fgrp_Id", m_Fgrp_Id);
        myMsg.CreateFirstNode("Upd_Id", Session["UserID"].ToString());

        bs_FactGroupManage mybs = new bs_FactGroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);

        strReturn = mybs.DoReturnStr("deleteUserGrpByFgrpIDAndUserID", myMsg.GetXmlStr, "");

        myMsg.LoadXml(strReturn);
        if (myMsg.Query("returnValue") == "0")
        {
            lblMsg.Text = "";
            // ting
            Response.Redirect(MYURL + "?ApID=" + m_ap_id + "&QueryCondition=" + GetQueryCondition());
        }
        else
        {
            lblMsg.Font.Size = 12;
            lblMsg.Text = myMsg.Query("errmsg");
        }
    }
    protected void btnDelOK_Click(object sender, System.EventArgs e)
    {
        plMain.Visible = true;
        plDelete.Visible = false;

        PccMsg mySrcMsg = new PccMsg(Request.QueryString["Method"]);

        PccMsg myMsg = new PccMsg();
        bs_ApManager mybs = new bs_ApManager(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        string strReturn = "";
        switch (mySrcMsg.Query("Method"))
        {
            case "MasterDelFunc":
                myMsg.CreateFirstNode("ap_id", mySrcMsg.Query("Key"));
                strReturn = mybs.DoReturnStr("DeleteProAp", myMsg.GetXmlStr, "");
                break;
            case "DetailDelFunc":
                myMsg.CreateFirstNode("menu_id", mySrcMsg.Query("Key"));
                strReturn = mybs.DoReturnStr("DeleteProMenu", myMsg.GetXmlStr, "");
                break;
        }

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            GenMasterTable();
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + myMsg.Query("errmsg") + "');</script>");
        }
    }
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        if (ViewState["CurrentValue"] == null && tab_fact.Rows.Count == 0) return;

        Temporary();
        string strFactNo = "";
        bs_UserFactManage mybs = new bs_UserFactManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        strFactNo = Session["Facttemporary"].ToString();
        if (strFactNo.Length == 0)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('您還未選擇任何廠別唷!');</script>");
            GenMasterTable();
            return;
        }

        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("ap_id", m_ap_id);
        myMsg.CreateFirstNode("no_str", strFactNo);
        myMsg.CreateFirstNode("upd_id", Session["UserID"].ToString());
        string strReturn = mybs.DoReturnStr("PickMultiFact", myMsg.GetXmlStr, "");
        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") != "0")
        {
            lblMsg.Font.Size = 12;
            lblMsg.Text = myMsg.Query("errmsg");
        }
        else
        {
            Response.Redirect(USERFACTMANAGE + "?ApID=" + m_ap_id);
        }
    }
Beispiel #10
0
        //web.huuminh 2014/04/19
        //insert data_qc_web erp
        public string db_insupd_data_qc_web(string strXML)
        {
            PccMsg myMsg = new PccMsg();
            myMsg.LoadXml(strXML);

            string fact_no = myMsg.Query("fact_no");
            string rec_date = myMsg.Query("rec_date");
            string vou_no = myMsg.Query("vou_no");
            string sec_no = myMsg.Query("sec_no");
            string bad_no = myMsg.Query("bad_no");
            string time_no = myMsg.Query("time_no");
            string kind_mk = myMsg.Query("kind_mk");
            string upd_user = myMsg.Query("upd_user");
            string upd_time = myMsg.Query("upd_time");
            string qty = myMsg.Query("qty");
            string qty_chk = myMsg.Query("qty_chk");
            string dept_no = myMsg.Query("dept_no");
            string Type = myMsg.Query("Type");

            int num = int.Parse(qty);
            string strReturn;

            string txt = "";
            string txt2 = "";
            if (Type == "0")
            {
                txt = "insert into data_qc_web(fact_no,rec_date,fact_odr_no,sec_no,bad_no,time_no,kind_mk,upd_user,upd_time,qty,qty_chk,dept_no)";
                txt +=
                    "  VALUES('" + fact_no + "','" + rec_date + "','" + vou_no + "','" + sec_no + "','" + bad_no + "','" + time_no + "','" + kind_mk + "','" + upd_user + "','" + upd_time + "','" + qty + "','" + qty_chk + "','" + dept_no + "')";
            }
            else
            {
                txt = "update data_qc_web set qty=NVL(qty,0)+"+qty+" , qty_chk='" + qty_chk + "'";
                txt += " where fact_odr_no='" + vou_no + "'"
                            + " and fact_no = '" + fact_no + "' "
                            + " AND rec_date = '" + rec_date + "' "
                            + " AND sec_no = '" + sec_no + "' "
                            + " AND bad_no = '" + bad_no + "' "
                            + " AND kind_mk = '" + kind_mk + "' "
                            + " AND time_no = '" + time_no + "' "
                            + " AND upd_user = '******' "
                            + " AND dept_no = '" + dept_no + "' "
                            + " AND dept_no = '" + dept_no + "' ";
            }

            try
            {
                int iCount;
                ExcuteSQL(txt, out iCount);
               // ExcuteSQL(txt2, out iCount);
                strReturn = "OK";
            }
            catch (Exception e)
            {
                strReturn = e.ToString();
            }
            return strReturn;
        }
    protected void btnAddComeOn_Click(object sender, System.EventArgs e)
    {
        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();
        string strUserID = "", strReturn = "";

        for (int i = 0; i < DataGrid1.Items.Count; i++)
        {
            if (((CheckBox)DataGrid1.Items[i].Cells[6].Controls[1]).Checked)
            {
                strUserID += DataGrid1.Items[i].Cells[1].Text + ",";
            }
        }

        if (strUserID != "")
        {
            strUserID = strUserID.Substring(0, strUserID.Length - 1);

            myMsg.LoadXml();
            myMsg.CreateFirstNode("group_id", CheckQueryString("GroupID"));
            myMsg.CreateFirstNode("user_str", strUserID);
            strReturn = mybs.DoReturnStr("InsertUGrp", myMsg.GetXmlStr, "");

            myMsg.LoadXml(strReturn);

            if (myMsg.Query("returnValue") == "0")
            {
                Response.Redirect(GROUPMANAGE + "?ApID=" + CheckQueryString("ApID") + "&QueryCondition=" + CheckQueryString("QueryCondition"));
            }
            else
            {
                lblMsg.Font.Size = FontUnit.Large;
                lblMsg.Text = myMsg.Query("errmsg");
            }
        }
        else
        {
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myLabel.GetErrMsg("lbl0014", "SysManager/UserManager");
        }
    }
    protected void btnDelOK_Click(object sender, System.EventArgs e)
    {
        plMain.Visible = true;
        plDelete.Visible = false;

        PccMsg myMsg = new PccMsg(CheckRequestQueryString("Method"));
        PccMsg myReturnMsg = new PccMsg();
        string strUserID = myMsg.Query("Key");
        myMsg.LoadXml();
        myMsg.CreateFirstNode("user_id", strUserID);
        myMsg.CreateFirstNode("ap_id", CheckRequestQueryString("ApID"));

        //增加一個刪除e_userfact的關連 20040924
        myMsg.CreateFirstNode("upd_id", Session["UserID"].ToString());
        myMsg.CreateFirstNode("fact_id", "0");
        myMsg.CreateFirstNode("uf_id", "0");
        bs_UserFactManage mybs1 = new bs_UserFactManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        string strReturn = mybs1.DoReturnStr("DeleteUserFactByUser", myMsg.GetXmlStr, "");
        myReturnMsg.LoadXml(strReturn);

        if (myReturnMsg.Query("returnValue") != "0")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + myMsg.Query("errmsg") + "');</script>");
            return;
        }

        bs_UserManager mybs = new bs_UserManager(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        strReturn = mybs.DoReturnStr("DeleteUserByApID", myMsg.GetXmlStr, "");

        myReturnMsg.LoadXml(strReturn);

        if (myReturnMsg.Query("returnValue") == "0")
        {
            GenMasterTable();
        }
        else
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + myMsg.Query("errmsg") + "');</script>");
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] == null) return;

        //設定Title 20041104
        for (int i = 0; i < Header1.Controls.Count; i++)
        {
            if (Header1.Controls[i].ID == TITLE)
            {
                Label mylblTitle = (Label)(Header1.Controls[i]);
                mylblTitle.Text = "使用者的廠別權限";
            }
        }
        m_ap_id = Request.Params["ApID"];
        PccMsg myMsg = new PccMsg();
        if (!IsPostBack)
        {
            //設定之前User鍵入的查詢資料。 ...ting...
            if (Request.Params["QueryCondition"] != null && Request.Params["QueryCondition"].ToString() != "")
            {
                myMsg.LoadXml(Request.Params["QueryCondition"]);
                txtusernm.Text = myMsg.Query("QueryCondition/txtusernm");
                txtfactno.Text = myMsg.Query("QueryCondition/txtfactno");
            }

            Session["Usertemporary"] = "";
            Session["Facttemporary"] = "";

            if (CheckQueryString("Method") != "")
            {
                myMsg.LoadXml(Request.QueryString["Method"]);
                string method = myMsg.Query("Method");
                if (method == "MasterDelFunc")
                {
                    panelDelUser.Visible = true;
                    PanelGrid.Visible = false;
                    m_uf_id = myMsg.Query("Key");
                    txtuser.Value = m_uf_id;
                    m_fact_nm = myMsg.Query("KeyOther");
                    lblDelMsg1.Text = "您是否要將<font color=green><b>" + m_fact_nm + "</b></font>此廠別從此使用者移除?";
                }

            }
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");
            SetLabel(ref myLabel);
            GenMasterTable(ref myLabel);
        }
    }
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        if (ViewState["CurrentValue"] == null && tab_user.Rows.Count == 0) return;

        Temporary();
        string strUser = "";
        bs_UserFactManage mybs = new bs_UserFactManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        strUser = Session["Usertemporary"].ToString();
        if (strUser.Length == 0)
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('您還未選擇任何使用者唷!');</script>");
            GenMasterTable();
            return;
        }

        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("ap_id", m_ap_id);
        myMsg.CreateFirstNode("fact_id", m_fact_id);
        myMsg.CreateFirstNode("user_str", strUser);
        if (ConfigurationManager.AppSettings[m_ap_id + "-FactByGroup"] != null)
            //myMsg.CreateFirstNode("FactByGroup",ConfigurationManager.AppSettings[m_ap_id + "-FactByGroup"].ToString());
            // ting
            myMsg.CreateFirstNode("FactByGroup", ConfigurationManager.AppSettings[m_ap_id + "-FactByGroup"].ToString() + "&QueryCondition=" + Request.QueryString["QueryCondition"]);
        else
            myMsg.CreateFirstNode("FactByGroup", "N");

        myMsg.CreateFirstNode("upd_id", Session["UserID"].ToString());
        string strReturn = mybs.DoReturnStr("PickMultiUserFact", myMsg.GetXmlStr, "");
        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") != "0")
        {
            lblMsg.Font.Size = 12;
            lblMsg.Text = myMsg.Query("errmsg");
            return;
        }
        else
        {
            //Response.Redirect(PICKUSER + "?ApID=" + m_ap_id);
            // ting
            Response.Redirect(PICKUSER + "?ApID=" + m_ap_id + "&QueryCondition=" + Request.QueryString["QueryCondition"]);
        }
    }
    public string SaveApplyCheckDataQC(string ac_id, string fact_no, string dept_no, string sec_no, string type_check, string vou_no, string total, string floor, string build_no, string myType)
    {
        bs_ApplyData myBs = new bs_ApplyData(ConfigurationSettings.AppSettings["AppConnectionType"], ConfigurationSettings.AppSettings["AppConnectionServer"], ConfigurationSettings.AppSettings["AppConnectionDB"], ConfigurationSettings.AppSettings["AppConnectionUser"], ConfigurationSettings.AppSettings["AppConnectionPwd"], "", ConfigurationSettings.AppSettings["EventLogPath"]);
        PccMsg myMsg = new PccMsg();
        myMsg.CreateFirstNode("ac_id", ac_id);
        myMsg.CreateFirstNode("fact_no", fact_no);
        myMsg.CreateFirstNode("dept_no", dept_no);
        myMsg.CreateFirstNode("sec_no", sec_no);
        myMsg.CreateFirstNode("type_check", type_check);
        myMsg.CreateFirstNode("vou_no", vou_no);
        myMsg.CreateFirstNode("total", total);
        myMsg.CreateFirstNode("floor", floor);
        myMsg.CreateFirstNode("build_no", build_no);
        myMsg.CreateFirstNode("Type", myType);

        string strXML = myMsg.GetXmlStr;
        string strReturn = myBs.DoReturnStr("INSUPDAPPLYCHECKQ", strXML, "");
        myMsg.LoadXml(strReturn);
        return strReturn;

        //return myMsg.Query("Err");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"] == null) return;

        m_ap_id = Request.Params["ApID"];
        PccMsg myMsg = new PccMsg();
        if (CheckQueryString("Method") != "")
        {
            myMsg.LoadXml(Request.QueryString["Method"]);
            string method = myMsg.Query("Method");
            if (method == "DetailDelFunc")
            {
                panelDelUser.Visible = true;
                PanelGrid.Visible = false;
                m_Fgrp_Id = myMsg.Query("Key");
                txtuser.Value = m_Fgrp_Id;
                m_Fgrp_Nm = myMsg.Query("KeyOther");
                lblDelMsg1.Text = "您是否要將<font color=green><b>" + m_Fgrp_Nm + "</b></font>此廠群組從此使用者(<font color=green><b>" + CheckQueryString("User_Desc") + "</b>)中移除?";
            }

        }
        if (!IsPostBack)
        {
            //設定之前User鍵入的查詢資料。 ...ting...
            if (Request.Params["QueryCondition"] != null && Request.Params["QueryCondition"].ToString() != "")
            {
                myMsg.LoadXml(Request.Params["QueryCondition"]);
                txtusernm.Text = myMsg.Query("QueryCondition/txtusernm");
                txtfactno.Text = myMsg.Query("QueryCondition/txtfactno");
            }

            PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");
            SetLabel(ref myLabel);
            GenMasterTable(ref myLabel);
        }
    }
    protected void btnOK_Click(object sender, System.EventArgs e)
    {
        PccMsg myMsg = new PccMsg();

        bs_ApManager mybs = new bs_ApManager(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        string strReturn = "";

        if (Request.Params["Type"] != null && Request.Params["Type"].ToString() == "New")
            strReturn = mybs.DoReturnStr("InsertProMenu", GenDBXML(), "");
        else
            strReturn = mybs.DoReturnStr("UpdateProMenu", GenDBXML(), "");

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            Response.Redirect(APMANAGE + "?ApID=" + Request.QueryString["ApID"] + "&QueryCondition=" + Request.QueryString["QueryCondition"]);
        }
        else
        {
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myMsg.Query("errmsg");
        }
    }
 private string GetMenuID()
 {
     PccMsg myMsg = new PccMsg();
     try
     {
         if (Request.Params["Method"] != null)
             myMsg.LoadXml(Request.Params["Method"].ToString());
         return myMsg.Query("Key");
     }
     catch
     {
         return "0";
     }
 }
    private void SaveDataQC(string qtyOKitem,string TypeQC)
    {
        if (hOdrNo.Value != "")
        {
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath("~") + "/XmlDoc", Session["CodePage"].ToString(), "Label");
            int item = int.Parse(qtyOKitem);
            string ac_id = "0";
            string fact_no = lblFactNo1.Text.ToString().Trim();
            string dept_no = ddlDepNo.SelectedValue.Trim();
            string sec_no = ddlSec_no.SelectedValue.Trim();
            string type_check = Request.QueryString["TypeCheck"].ToString();
            string vou_no = hOdrNo.Value;

            //kiểm tra time_no dứơi ERP
            string time_sec = DateTime.Now.ToString("hhmm");
            string time_no = "";
            DataTable dtTime_no = mybs.get_time_no(fact_no, dept_no, time_sec);
            if (dtTime_no.Rows.Count > 0)
                time_no = dtTime_no.Rows[0]["time_no"].ToString().Trim();
            else
            {
                Response.Write("<script>alert('" + sTimeNo + "');</script>");
                return;
            }

            // lây total dưới SQL
            //DataTable dtTotal = mybs.get_sum_act_qty(fact_no, dept_no, sec_no, vou_no);
            string total = lblSumRutKiem1.Text;// dtTotal.Rows[0]["SumTotal"].ToString().Trim();

            //lấy floor
            DataTable dtFloor = mybs.get_floor_erp(fact_no, dept_no, sec_no);
            string floor = "";
            if (dtFloor.Rows.Count > 0)
                floor = dtFloor.Rows[0]["floor"].ToString().Trim();

            //lấy build_no
            DataTable dtBuild = mybs.get_build_no_erp(fact_no, dept_no, sec_no, floor);
            string build_no = "";
            if (dtBuild.Rows.Count > 0)
                build_no = dtBuild.Rows[0]["build_no"].ToString().Trim();

            string myType = "0";
            string ok = SaveApplyCheckDataQC(ac_id, fact_no, dept_no, sec_no, type_check, vou_no, total, floor, build_no, myType);

            PccMsg myMsg = new PccMsg();
            myMsg.LoadXml(ok);
            string ac_id_e = myMsg.Query("ac_id");
            string Err = myMsg.Query("Err");
            string Mes = myLabel.GetErrMsg("lbl0026", "QC/Tilte");
            if (Err == "Success!")
            {
                string bad_no = hBadNo.Value;
                string bad_desc = hBad_cn.Value;
                string bad_descVN = hBad_vn.Value;
                string userQC_id = Session["UserID"].ToString().Trim();

                string qty = "0";
                string qty_OKitem = "0";
                if (TypeQC == "0")
                    qty_OKitem = qtyOKitem;
                else
                    qty = qtyOKitem;

                // câp nhật xuống table ApplyCheckD
                string ok2 = "";
                if (TypeQC == "0")
                    ok2 = SaveCheckDetail("", ac_id_e, "", "", "", userQC_id, qty, qty_OKitem, "0");
                else
                    ok2 = SaveCheckDetail("", ac_id_e, bad_no, bad_desc, bad_descVN, userQC_id, qty, "", "0");

                if (ok2 == "Success!")
                {
                    if (TypeQC == "0")
                    {
                        bad_no = "     ";
                        bad_desc = "";
                        bad_descVN = "";
                    }

                    //kiểm tra dử liệu dưới ERP? 0 : insert 1: update
                    string rec_date = DateTime.Now.ToString("yyyyMMdd");
                    string upd_user = Session["UserEMail"].ToString().Trim();
                    string upd_time = DateTime.Now.ToString("yyyyMMddhhmmss");
                    // trường hơp TypeQC == "0" SL đạt -- kiểm tra (fact_no,rec_date,fact_odr_no,sec_no)
                    string kind_mk = "2";
                    string TypeErp = "0";

                    DataTable dtTest = mybs.testCountVouNOErp(vou_no, fact_no, rec_date, bad_no, sec_no, kind_mk);
                    if (dtTest.Rows.Count > 0)
                        TypeErp = "1";

                    //get sum qty dua vao bad_no
                    DataTable dtSumQtyByBadBo = mybs.sum_qty_02ByBad_no(vou_no, fact_no, rec_date, sec_no, bad_no, kind_mk);
                    int sum_qty_bad_no = int.Parse(dtSumQtyByBadBo.Rows[0]["SumQtyChk"].ToString());
                    sum_qty_bad_no = sum_qty_bad_no + item;
                    string qtyErp = Convert.ToString(sum_qty_bad_no);

                    //get sum qty => qty_chk
                    DataTable dtQtyCheck = mybs.sum_qty_02(vou_no, fact_no, rec_date, sec_no, kind_mk);
                    int sum_qty = int.Parse(dtQtyCheck.Rows[0]["SumQtyChk"].ToString());

                    string qty_chk = Convert.ToString(sum_qty + item); //dtQtyCheck.Rows[0]["SumQtyChk"].ToString().Trim();
                    /*
                     string qtyErp = qtyOKitem;
                     string qty_chk = qtyOKitem;
                     */
                    //câp nhật xuống ERP
                    string ok3 = mybs.SaveDataErpQC02(fact_no, rec_date, vou_no, sec_no, bad_no, time_no, type_check, upd_user, upd_time, qtyErp, qty_chk, dept_no, TypeErp);
                    //if (ok3 == "OK")
                        //Response.Write("<script>alert('" + Mes + "');</script>");
                    if (ok3 != "OK")
                    {
                        Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                        return;
                    }
                }
                else
                {
                    Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                    return;
                }
                ltrBadReason.Text = GetBadReson();
                GetSumQtyToal();

            }
            else
            {
                Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                return;
            }
        }
    }
    protected void btnAddComeOn_Click(object sender, System.EventArgs e)
    {
        bs_UserManager mybs = new bs_UserManager(ConfigurationSettings.AppSettings["ConnectionType"] , ConfigurationSettings.AppSettings["ConnectionServer"], ConfigurationSettings.AppSettings["ConnectionDB"], ConfigurationSettings.AppSettings["ConnectionUser"], ConfigurationSettings.AppSettings["ConnectionPwd"],Session["UserIDAndName"].ToString(),ConfigurationSettings.AppSettings["EventLogPath"]);
            PccMsg myMsg = new PccMsg();
            string strUserID,strReturn,errormsg = "",strXML = "";
            bool bSelect = false;

            for (int i = 0; i < DataGrid1.Items.Count ; i++)
            {
                if (((CheckBox)DataGrid1.Items[i].Cells[6].Controls[1]).Checked)
                {
                    strUserID = DataGrid1.Items[i].Cells[1].Text;
                    myMsg.LoadXml();
                    myMsg.CreateFirstNode("ap_id",Request.QueryString["ApID"]);
                    myMsg.CreateFirstNode("user_id",strUserID);
                    myMsg.CreateFirstNode("mana_mk","N");
                    myMsg.CreateFirstNode("upd_id",Session["UserID"].ToString());

                    //strXML = GetUserXML(strUserID);

                    strReturn = mybs.DoReturnStr("JoinUserToAp",myMsg.GetXmlStr,"");

                    myMsg.LoadXml(strReturn);

                    if (myMsg.Query("returnValue") != "0")
                    {
                        lblMsg.Font.Size = FontUnit.Large;
                        lblMsg.Text = myMsg.Query("errmsg");
                        break;
                    }

                    bSelect = true;
                }
            }

            if (bSelect)
            {
                if (myMsg.Query("returnValue") == "0")
                {
                    Response.Redirect(USERMANAGE + "?ApID=" + Request.QueryString["ApID"] + "&QueryCondition=" + Request.QueryString["QueryCondition"]);
                }
                else
                {
                    lblMsg.Font.Size = FontUnit.Large;
                    if (errormsg == "")
                        lblMsg.Text = myMsg.Query("errmsg");
                    else
                        lblMsg.Text = errormsg;

                }
            }
            else
            {
                PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"),Session["CodePage"].ToString() ,"Label");
                lblMsg.Font.Size = FontUnit.Large;
                if (errormsg == "")
                    lblMsg.Text = myLabel.GetErrMsg("lbl0014","SysManager/UserManager");
                else
                    lblMsg.Text = errormsg;

            }
    }
    private void GenUpdateData()
    {
        bs_ApManager mybs = new bs_ApManager(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("menu_id", GetMenuID());
        string strReturn = mybs.DoReturnStr("GetMenuByMenuID", myMsg.GetXmlStr, "");

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("Return") == "OK")
        {
            txtMenuNo.Text = myMsg.Query("menu_no");
            txtMenuName.Text = myMsg.Query("menu_nm");
            txtMenuLink.Text = myMsg.Query("menu_link");
            ddlApName.Items.FindByValue(myMsg.Query("ap_id")).Selected = true;
            if (myMsg.Query("check_mk") == "Y") chkCheckMK.Checked = true; else chkCheckMK.Checked = false;
            txtManageMK.Text = myMsg.Query("manage_mk");
        }
        else
        {
            btnOK.Visible = false;
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myMsg.Query("Return");
        }
    }
    private void SaveApplyRating(string qtyOKitem, string TypeQC)
    {
        if (hOdrNo.Value != "")
        {
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath("~") + "/XmlDoc", Session["CodePage"].ToString(), "Label");
            int item = int.Parse(qtyOKitem);
            string AcRat_id = "0";
            string fact_no = lblFactNo1.Text.ToString().Trim();
            string dept_no = ddlDepNo.SelectedValue.Trim();
            string sec_no = ddlSec_no.SelectedValue.Trim();
            string type_check = Request.QueryString["TypeCheck"].ToString();
            string vou_no = hOdrNo.Value;

            //kiểm tra time_no dứơi ERP
            string time_sec = DateTime.Now.ToString("hhmm");
            string time_no = "";
            DataTable dtTime_no = mybs.get_time_no(fact_no, dept_no, time_sec);
            if (dtTime_no.Rows.Count > 0)
                time_no = dtTime_no.Rows[0]["time_no"].ToString().Trim();
            else
            {
                Response.Write("<script>alert('" + sTimeNo + "');</script>");
                return;
            }

            // lây total dưới SQL
            string total = qtyOKitem;// lblSumRutKiem1.Text;// dtTotal.Rows[0]["SumTotal"].ToString().Trim();

            //lấy floor
            DataTable dtFloor = mybs.get_floor_erp(fact_no, dept_no, sec_no);
            string floor = "";
            if (dtFloor.Rows.Count > 0)
                floor = dtFloor.Rows[0]["floor"].ToString().Trim();

            //lấy build_no
            DataTable dtBuild = mybs.get_build_no_erp(fact_no, dept_no, sec_no, floor);
            string build_no = "";
            if (dtBuild.Rows.Count > 0)
                build_no = dtBuild.Rows[0]["build_no"].ToString().Trim();

            string userQC_id = ddlQC.SelectedValue.Trim();
            string upd_id = Session["UserID"].ToString().Trim();
            string myType = "0";
            string ok = SaveApplyRating(AcRat_id, fact_no, dept_no, sec_no, vou_no, total, floor, build_no, userQC_id, upd_id, myType);

            PccMsg myMsg = new PccMsg();
            myMsg.LoadXml(ok);
            string AcRat_id_e = myMsg.Query("AcRat_id");
            string Err = myMsg.Query("Err");
            string Mes = myLabel.GetErrMsg("lbl0026", "QC/Tilte");
            if (Err == "Success!")
            {
                string bad_no = hBadNo.Value;
                string bad_desc = hBad_cn.Value;
                string bad_descVN = hBad_vn.Value;

                string qty = "0";
                string qty_OKitem = "0";
                if (TypeQC == "0")
                    qty_OKitem = qtyOKitem;
                else
                    qty = qtyOKitem;

                // câp nhật xuống table RatingD
                string ok2 = "";
                if (TypeQC == "0")
                    ok2 = SaveApplyRatingDetail("", AcRat_id_e, "", "", "",  qty, qty_OKitem,upd_id, "0");
                else
                    ok2 = SaveApplyRatingDetail("", AcRat_id_e, bad_no, bad_desc, bad_descVN,qty, "",upd_id, "0");

                //if (ok2 == "Success!")
                    //Response.Write("<script>alert('"+Mes+"');</script>");
                if (ok2 != "Success!")
                {
                    Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                    return;
                }

                ltrBadReason.Text = GetBadReson();
                GetSumQtyToal();
            }
            else
            {
                Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                return;
            }
        }
    }
    private string GetUserXML(string user_id)
    {
        PccBsSystemForC.bs_UserManager mybs = new PccBsSystemForC.bs_UserManager(ConfigurationSettings.AppSettings["ConnectionType"] , ConfigurationSettings.AppSettings["ConnectionServer"], ConfigurationSettings.AppSettings["ConnectionDB"], ConfigurationSettings.AppSettings["ConnectionUser"], ConfigurationSettings.AppSettings["ConnectionPwd"],Session["UserIDAndName"].ToString(),ConfigurationSettings.AppSettings["EventLogPath"]);
            PccCommonForC.PccMsg myMsg = new PccCommonForC.PccMsg();
            myMsg.CreateFirstNode("user_id",user_id);

            PccMsg myReturnMsg = new PccMsg();
            myReturnMsg.LoadXml(mybs.DoReturnStr("GetUserData",myMsg.GetXmlStr,""));

            //10/6還要繼續做XML的方法 20041006
            string fact_id = myReturnMsg.Query("fact_id");
            myReturnMsg.CreateFirstNode("fact_no", GetFactNoByFactID(fact_id));

            return myReturnMsg.GetXmlStr;
    }
    protected void BtnDelFactOK_Click(object sender, System.EventArgs e)
    {
        PccMsg myMsg = new PccMsg();
        bs_FactGroupManage mybs = new bs_FactGroupManage(ConfigurationManager.AppSettings["ConnectionType"], ConfigurationManager.AppSettings["ConnectionServer"], ConfigurationManager.AppSettings["ConnectionDB"], ConfigurationManager.AppSettings["ConnectionUser"], ConfigurationManager.AppSettings["ConnectionPwd"], Session["UserIDAndName"].ToString(), ConfigurationManager.AppSettings["EventLogPath"]);
        string strReturn = string.Empty;
        string strMsg = string.Empty;
        strReturn = mybs.DoReturnStr("delete_DS_FACTGRP", GenDBXML(), string.Empty);
        strMsg = "刪除成功";

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("returnValue") == "0")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(),"New", "<script language=javascript>alert('" + strMsg + "');</script>");
            Response.Redirect(MYURL + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + m_Up_Id + "&QueryCondition=" + GetQueryCondition());
        }
        else
        {
            LblErrMsg.Font.Size = FontUnit.Large;
            LblErrMsg.Text = myMsg.Query("errmsg");
        }
    }
    private void GenUpdateData()
    {
        bs_ApManager mybs = new bs_ApManager(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("ap_id", GetApID());
        string strReturn = mybs.DoReturnStr("GetApByApID", myMsg.GetXmlStr, "");

        myMsg.LoadXml(strReturn);

        if (myMsg.Query("Return") == "OK")
        {
            txtApNo.Text = myMsg.Query("ap_id");
            txtApName.Text = myMsg.Query("ap_name");
            txtApLink.Text = myMsg.Query("ap_link");
            txtVpath.Text = myMsg.Query("ap_vpath");
        }
        else
        {
            btnOK.Visible = false;
            lblMsg.Font.Size = FontUnit.Large;
            lblMsg.Text = myMsg.Query("Return");
        }
    }
    private void GenMasterTableData(ref PccErrMsg myLabel)
    {
        #region 取得Login的使用者是否有刪除的權限

        GetMenuAuth myAuth = new GetMenuAuth();
        myAuth.AspxFile = "FactGroupManage104.aspx";
        bool del_auth = myAuth.IsDeleteAuth();

        #endregion

        #region 取得廠群組的主資料ByUpID

        bs_FactGroupManage mybs = new bs_FactGroupManage(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("Up_Id", m_SrcUp_Id);
        myMsg.CreateFirstNode("Ap_Id", m_ApID);
        myMsg.CreateFirstNode("Fgrp_Nm", TxtQueryFgrpNm.Text);
        string strXML = myMsg.GetXmlStr;

        DataSet myDS_FGRPDs = mybs.DoReturnDataSet("Get_DS_FGRPByUpID", strXML, "");
        DataTable myDS_FGRPData = myDS_FGRPDs.Tables["DS_FGRPByUpID"];

        #endregion

        if (myDS_FGRPData != null && myDS_FGRPData.Rows.Count > 0)
        {
            #region 定義基本變數

            int MasterCount = 0;
            string MasterStyle = string.Empty;
            PccMsg myTempMsg;
            PccMsg myMsg1;
            PccRow myRow;
            //取出資料總筆數
            PageControl1.TotalSize = myDS_FGRPDs.Tables["TCounts"].Rows[0]["Counts"].ToString();
            PageControl1.BuildPager();

            #endregion

            #region 明細資料類別之共同參數

            myMsg.LoadXml();
            myMsg.CreateFirstNode("TableClass", "ActDocTB");
            myMsg.CreateFirstNode("RowHeaderClass", "TDShowHeader");
            myMsg.CreateFirstNode("RowClass1", "ffd000");
            myMsg.CreateFirstNode("RowClass2", "fff000");
            string strClassXML = myMsg.GetXmlStr;

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

            #endregion

            #region 內建廠別明細資料的欄位參數

            string[] FFields = { "編號", "廠別", "廠別名稱", "事業群", "公司編號", "刪除" };
            int[] FFieldsPercent = { 5, 15, 35, 20, 15, 10 };
            string[] FFieldsItem = { "--NO--", "fact_no", "fact_nm", "fgrp_nm", "comp_no", "factgrp_id" };
            string[] FFieldType = new string[6];
            FFieldType[0] = "--NO--";
            FFieldType[1] = "<PccMsg><Type>Text</Type></PccMsg>";
            FFieldType[2] = "<PccMsg><Type>Text</Type></PccMsg>";
            FFieldType[3] = "<PccMsg><Type>Text</Type></PccMsg>";
            FFieldType[4] = "<PccMsg><Type>Text</Type></PccMsg>";

            #endregion

            #region 內建使用者明細資料的欄位參數

            string[] UFields = { "編號", "電子郵件帳號", "姓名", "廠別", "事業群", "分機", "刪除" };
            int[] UFieldsPercent = { 5, 30, 15, 15, 15, 10, 10 };
            string[] UFieldsItem = { "--NO--", "email", "user_desc", "fact_no", "fgrp_nm", "ext", "usergrp_id" };
            string[] UFieldType = new string[7];
            UFieldType[0] = "--NO--";
            UFieldType[1] = "<PccMsg><Type>Text</Type></PccMsg>";
            UFieldType[2] = "<PccMsg><Type>Text</Type></PccMsg>";
            UFieldType[3] = "<PccMsg><Type>Text</Type></PccMsg>";
            UFieldType[4] = "<PccMsg><Type>Text</Type></PccMsg>";
            UFieldType[5] = "<PccMsg><Type>Text</Type></PccMsg>";

            #endregion

            //再利用此Table再取得其每一列的資料,再Gen出主要的Table Row.
            foreach (DataRow myMasterRow in myDS_FGRPData.Rows)
            {
                #region 主要廠群組的資料列設定

                if (MasterCount % 2 == 0) MasterStyle = "eee000"; else MasterStyle = "fff000";
                myRow = new PccRow("", HorizontalAlign.Center, 0, 0);
                myRow.SetRowCss(MasterStyle);
                //編號
                myRow.AddTextCell(PageControl1.ListCount, 5);
                //廠群組名稱
                if (myAuth.IsAddAuth())
                {
                    myTempMsg = new PccMsg();
                    myTempMsg.CreateFirstNode("Href", PICKFACT + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString() + "&Method=" + GetMethod("PickFactToFgrpFunc", "Fgrp_Id", "Fgrp_Nm", myMasterRow) + "&QueryCondition=" + GetQueryCondition());
                    myTempMsg.CreateFirstNode("Text", myMasterRow["Fgrp_Nm"].ToString().Trim());
                    myRow.AddLinkHrefCell(myTempMsg.GetXmlStr, 56);
                }
                else
                {
                    myRow.AddTextCell(myMasterRow["Fgrp_Nm"].ToString(), 56);
                }

                //廠別檢視
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", "檢視所屬廠別");
                myTempMsg.CreateFirstNode("LinkID", "HLinkView" + myMasterRow["Fgrp_Id"].ToString());
                myTempMsg.CreateFirstNode("Image", Session["PageLayer"] + "images/detal.gif");
                myTempMsg.CreateFirstNode("ClickFun", "doSection(view_F" + MasterCount.ToString() + ")");
                myRow.AddLinkCell(myTempMsg.GetXmlStr, 12);
                //使用者檢視
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", "檢視所屬使用者");
                myTempMsg.CreateFirstNode("LinkID", "HLinkView" + myMasterRow["Fgrp_Id"].ToString());
                myTempMsg.CreateFirstNode("Image", Session["PageLayer"] + "images/detal.gif");
                myTempMsg.CreateFirstNode("ClickFun", "doSection(view_U" + MasterCount.ToString() + ")");
                myRow.AddLinkCell(myTempMsg.GetXmlStr, 12);
                //管理
                myTempMsg = new PccMsg();
                //判斷是否和上層ID是一樣的
                if (myMasterRow["Fgrp_Id"].ToString() != Request.Params["SrcUp_Id"])
                {
                    //先加入修改的Item
                    if (myAuth.IsUpdateAuth())
                    {
                        myTempMsg.CreateNode("LinkButton");
                        myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/edit.gif");
                        myTempMsg.AddToNode("ToolTip", myLabel.GetErrMsg("lbl0014", "SysManager/ApManager"));
                        myTempMsg.AddToNode("href", MYURL + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString());
                        myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                        myTempMsg.AddToNode("Method", GetMethod("MasterUpdateFunc", "Fgrp_Id", "Fgrp_Nm", myMasterRow));
                        myTempMsg.UpdateNode();
                    }
                    if (del_auth)
                    {
                        //再加入刪除的Item
                        myTempMsg.CreateNode("LinkButton");
                        myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                        myTempMsg.AddToNode("ToolTip", myLabel.GetErrMsg("lbl0015", "SysManager/ApManager"));
                        myTempMsg.AddToNode("href", MYURL + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString());
                        myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                        myTempMsg.AddToNode("Method", GetMethod("MasterDelFunc", "Fgrp_Id", "Fgrp_Nm", myMasterRow));
                        myTempMsg.UpdateNode();
                    }
                    //再加入加入使用者的Item
                    if (myAuth.IsAddAuth())
                    {
                        myTempMsg.CreateNode("LinkButton");
                        myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/add.gif");
                        myTempMsg.AddToNode("ToolTip", "加入使用者");
                        myTempMsg.AddToNode("href", PICKUSER + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString());
                        myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                        myTempMsg.AddToNode("Method", GetMethod("AddUserFunc", "Fgrp_Id", "Fgrp_Nm", myMasterRow));
                        myTempMsg.UpdateNode();
                    }
                }

                myRow.AddMultiLinkCell(myTempMsg.GetXmlStr, 15);
                TblDs_Fgrp.Rows.Add(myRow.Row);

                #endregion

                #region 內建廠別明細資料的欄位參數,此處會取得資料,並設定給主表格

                //設定廠別明細欄位中多個Link Image的參數
                myMsg1 = new PccMsg();

                if (del_auth && myMasterRow["Fgrp_Id"].ToString() != Request.Params["SrcUp_Id"])
                {
                    myMsg1.CreateFirstNode("Type", "MultiLink");

                    myMsg1.CreateNode("LinkButton");
                    myMsg1.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                    myMsg1.AddToNode("ToolTip", "刪除此廠別與此廠群組之關係");
                    myMsg1.AddToNode("href", MYURL + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString() + "&Fgrp_Nm=" + myMasterRow["Fgrp_Nm"].ToString());
                    myMsg1.AddToNode("QueryCondition", GetQueryCondition());
                    myNode = myMsg1.CreateParentNode("Method");
                    myMsg1.AddToNode("MethodName", "FactDelFunc", ref myNode);
                    myMsg1.AddToNode("Key", "factgrp_id", ref myNode);
                    myMsg1.AddToNode("KeyOther", "fact_no", ref myNode);
                    myMsg1.UpdateNode(myNode);
                    myMsg1.UpdateNode();

                }
                else
                {
                    myMsg1.CreateFirstNode("Type", "Space");
                }

                FFieldType[5] = myMsg1.GetXmlStr;

                //設定要取得廠別資料的XML
                myMsg1.LoadXml();
                myMsg1.CreateFirstNode("Fgrp_Id", myMasterRow["Fgrp_Id"].ToString());
                tblFactGroup = mybs.DoReturnDataSet("get_DS_FACTGRPByFgrpID", myMsg1.GetXmlStr, string.Empty).Tables["DS_FACTGRP"];

                PccDetailTable myFDTable = new PccDetailTable("FDT" + myMasterRow["Fgrp_Id"].ToString());
                myFDTable.ClassXML = strClassXML;
                myFDTable.Fields = FFields;
                myFDTable.FieldsPercent = FFieldsPercent;
                myFDTable.FieldsItem = FFieldsItem;
                myFDTable.FieldsType = FFieldType;
                myFDTable.NewDataTable = tblFactGroup;

                myFDTable.Create();

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

                TblDs_Fgrp.Rows.Add(myRow.Row);

                #endregion

                #region 內建使用者明細資料的欄位參數,此處會取得資料,並設定給主表格

                //設定廠別明細欄位中多個Link Image的參數
                myMsg1 = new PccMsg();

                if (del_auth && myMasterRow["Fgrp_Id"].ToString() != Request.Params["SrcUp_Id"])
                {
                    myMsg1.CreateFirstNode("Type", "MultiLink");

                    myMsg1.CreateNode("LinkButton");
                    myMsg1.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                    myMsg1.AddToNode("ToolTip", "刪除此使用者與此廠群組之關係");
                    myMsg1.AddToNode("href", MYURL + "?ApID=" + m_ApID + "&SrcUp_Id=" + m_SrcUp_Id + "&Up_Id=" + myMasterRow["Up_Id"].ToString() + "&Fgrp_Nm=" + myMasterRow["Fgrp_Nm"].ToString());
                    myMsg1.AddToNode("QueryCondition", GetQueryCondition());
                    myNode = myMsg1.CreateParentNode("Method");
                    myMsg1.AddToNode("MethodName", "UserDelFunc", ref myNode);
                    myMsg1.AddToNode("Key", "usergrp_id", ref myNode);
                    myMsg1.AddToNode("KeyOther", "user_desc", ref myNode);
                    myMsg1.UpdateNode(myNode);
                    myMsg1.UpdateNode();

                }
                else
                {
                    myMsg1.CreateFirstNode("Type", "Space");
                }

                UFieldType[6] = myMsg1.GetXmlStr;

                //設定要取得廠別資料的XML
                myMsg1.LoadXml();
                myMsg1.CreateFirstNode("Fgrp_Id", myMasterRow["Fgrp_Id"].ToString());
                tblUserGroup = mybs.DoReturnDataSet("get_DS_USERGRPByFgrpID", myMsg1.GetXmlStr, string.Empty).Tables["DS_USERGRP"];

                PccDetailTable myUDTable = new PccDetailTable("UDT" + myMasterRow["Fgrp_Id"].ToString());
                myUDTable.ClassXML = strClassXML;
                myUDTable.Fields = UFields;
                myUDTable.FieldsPercent = UFieldsPercent;
                myUDTable.FieldsItem = UFieldsItem;
                myUDTable.FieldsType = UFieldType;
                myUDTable.NewDataTable = tblUserGroup;

                myUDTable.Create();

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

                TblDs_Fgrp.Rows.Add(myRow.Row);

                #endregion

                MasterCount += 1;
            } // end of foreach datarow
        }// end of if table count is 0
        else
        {
            PageControl1.TotalSize = "0";
            PageControl1.BuildPager();
        }
    }
    private void SaveData(string qty)
    {
        if (hOdrNo.Value != "" )
        {
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath("~") + "/XmlDoc", Session["CodePage"].ToString(), "Label");

            string ac_id = "0";
            string fact_no = lblFactNo1.Text.ToString().Trim();
            string dept_no = ddlDepNo.SelectedValue.Trim();
            string sec_no = ddlSec_no.SelectedValue.Trim();
            string type_check = Request.QueryString["TypeCheck"].ToString();
            string vou_no = hOdrNo.Value;

            //kiểm tra time_no dứơi ERP
            string time_sec = DateTime.Now.ToString("hhmm");
            string time_no="";
            DataTable dtTime_no = mybs.get_time_no(fact_no, dept_no, time_sec);
            if (dtTime_no.Rows.Count > 0)
                time_no = dtTime_no.Rows[0]["time_no"].ToString().Trim();
            else
            {
                Response.Write("<script>alert('" + sTimeNo + "');</script>");
                return;
            }

            // lây total dưới ERP
            DataTable dtTotal = mybs.get_sum_act_qty(fact_no, dept_no, sec_no, vou_no);
            string total_act_qty = dtTotal.Rows[0]["SumTotal"].ToString().Trim();

            //lấy floor
            DataTable dtFloor = mybs.get_floor_erp(fact_no, dept_no, sec_no);
            string floor = "";
            if (dtFloor.Rows.Count > 0)
                floor = dtFloor.Rows[0]["floor"].ToString().Trim();

            //lấy build_no
            DataTable dtBuild = mybs.get_build_no_erp(fact_no, dept_no, sec_no, floor);
            string build_no = "";
            if (dtBuild.Rows.Count > 0)
                build_no = dtBuild.Rows[0]["build_no"].ToString().Trim();

            string myType = "0";
            string ok = SaveApplyCheckData(ac_id, fact_no, dept_no, sec_no, type_check, vou_no, total_act_qty, floor, build_no, myType);

            PccMsg myMsg = new PccMsg();
            myMsg.LoadXml(ok);
            string ac_id_e = myMsg.Query("ac_id");
            string Err = myMsg.Query("Err");
            string Mes = myLabel.GetErrMsg("lbl0026", "QC/Tilte"); //"cập nhật thành công !";// myLabelEr.GetErrMsg("msg0004");
            if (Err == "Success!")
            {
                string bad_no = hBadNo.Value;
                string bad_desc = hBad_cn.Value;
                string bad_descVN = hBad_vn.Value;
                string userQC_id = Session["UserID"].ToString().Trim();

                string qtyOKitem = "0";
                // câp nhật xuống table ApplyCheckD
                string ok2 = SaveCheckDetail("", ac_id_e, bad_no, bad_desc, bad_descVN, userQC_id, qty, qtyOKitem, "0");
                if (ok2 == "Success!")
                {

                    string rec_date = DateTime.Now.ToString("yyyyMMdd");
                    string kind_mk = "1";
                    string TypeErp = "0";
                    //câp nhật xuống ERP
                    string upd_user = Session["UserEMail"].ToString().Trim();
                    string upd_time=DateTime.Now.ToString("yyyyMMddhhmmss");

                    /*
                    //SL không đạt
                    DataTable dtQty = SumQtyToal(type_check, vou_no, fact_no, dept_no, sec_no, bad_no, rec_date, "4");
                    string qtyErp=dtQty.Rows[0]["SumQty"].ToString().Trim();
                   */

                    //get sum qty
                    string cur_time=DateTime.Now.ToString("hhmm");
                    DataTable dtQtyERP = mybs.sum_qty_erp(vou_no, fact_no, sec_no, kind_mk, time_no, rec_date, upd_user, dept_no);

                    //kiểm tra dử liệu dưới ERP? 0 : insert 1: update
                    DataTable dtTest = mybs.testCountBadNoErp(vou_no, fact_no, rec_date, sec_no, bad_no, kind_mk, upd_user, dept_no, time_no);
                    if (dtTest.Rows[0]["kt"].ToString()!="0")
                        TypeErp = "1";

                    string qtyErpN = "0";// dtQtyERP.Rows[0]["SumQty"].ToString().Trim();
                    int kq=0;
                    if(dtQtyERP.Rows.Count>0)
                        qtyErpN = dtQtyERP.Rows[0]["SumQty_chk"].ToString().Trim();
                    kq = int.Parse(total_act_qty) - int.Parse(qtyErpN);
                    string qty_chk =  kq.ToString();

                    string qtyErp = qty;

                    string ok3=mybs.SaveDataErp(fact_no, rec_date, vou_no, sec_no, bad_no, time_no, type_check, upd_user, upd_time, qtyErp, qty_chk,dept_no, TypeErp);
                    //if(ok3=="OK")
                        //Response.Write("<script>alert('"+Mes+"');</script>");
                    if (ok3 != "OK")
                    {
                        Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                        return;
                    }

                }
                else
                {
                    Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                    return;
                }
                ltrBadReason.Text = GetBadReson();
                GetSumQtyToal();

            }
            else
            {
                Response.Write("<script>alert('Error, Please contact administrator !');</script>");
                return;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        // 將使用者程式碼置於此以初始化網頁
        if (Session["UserID"] == null) return;

        GetMenuAuth myAuth = new GetMenuAuth();
        myAuth.AspxFile = "FactGroupManage104.aspx";

        //設定所要做的動作
        string strAction = string.Empty;

        if (myAuth.IsAddAuth())
            LbtnAddNewFgrp.Visible = true;

        m_ApID = Request.Params["ApID"];

        if (CheckQueryString("SrcUp_Id") != "")
        {
            m_SrcUp_Id = Request.Params["SrcUp_Id"];
        }

        if (CheckQueryString("Up_Id") != "")
        {
            m_Up_Id = Request.Params["Up_Id"];
        }

        PccMsg myMsg = new PccMsg();
        PccMsg myQueryMsg = new PccMsg();

        PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");

        if (CheckQueryString("Method") != "")
        {
            myMsg.LoadXml(Request.QueryString["Method"]);
            strAction = myMsg.Query("Method");
            switch (strAction)
            {
                case ("MasterUpdateFunc"):
                    m_FgrpId = myMsg.Query("Key");
                    break;
                case ("MasterDelFunc"):
                    m_FgrpId = myMsg.Query("Key");
                    break;
                case ("UpdFgrpFact"):
                    m_FgrpFactId = myMsg.Query("Key");
                    break;
                case "FactDelFunc":
                    m_FactGrpId = myMsg.Query("Key");
                    break;
                case "UserDelFunc":
                    m_UserGrpId = myMsg.Query("Key");
                    break;
            }

        }

        if (!IsPostBack)
        {
            string SrcUp_Id = string.Empty;
            if (Request.Params["SrcUp_Id"] != null)
            {
                SrcUp_Id = Request.Params["SrcUp_Id"].ToString();
                GenTree(ref TreeView1);
                //利用GetNodeIndex去設定m_CurrentNodeIndex的值,不需要再去設定一次Selected Lemor 20080312
                string aaa = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                //TreeView1.FindNode(GetNodeIndex(TreeView1.Nodes, SrcUp_Id)).Selected = true;
                //TreeView1.SelectedValue = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                //TreeView1.SelectedNodeIndex = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                if (m_CurrentNodeIndex != null)
                {
                    string[] a;
                    a = m_CurrentNodeIndex.Split('/');
                    TreeView1.ExpandDepth = a.Length - 1;
                    //TreeView1.ExpandLevel = a.Length - 1;
                    TreeView1.FindNode(m_CurrentNodeIndex).Selected = true;
                    TreeView1.FindNode(m_CurrentNodeIndex).Expand();

                    //TreeView1.SelectedValue = m_CurrentNodeIndex;
                    //TreeView1.SelectedNodeIndex = m_CurrentNodeIndex;
                }
            }

            //設定之前User鍵入的查詢資料。 2005/5/23
            if (CheckQueryString("QueryCondition") != "")
            {
                myQueryMsg.LoadXml(CheckQueryString("QueryCondition"));
                TxtQueryFgrpNm.Text = myQueryMsg.Query("QueryCondition/TxtQueryFgrpNm");
            }

            SetLabel(ref myLabel);
            switch (strAction)
            {
                case ("MasterUpdateFunc"):
                    ViewState["ActionType"] = "MasterUpdateFunc";
                    PalFgrp.Visible = false;
                    PalAddFgrp.Visible = true;
                    TxtFgrpNm.Text = myMsg.Query("KeyOther");
                    break;
                case ("MasterDelFunc"):
                    ViewState["ActionType"] = "MasterDeleteFunc";
                    PalFgrp.Visible = false;
                    PalAddFgrp.Visible = false;
                    PalDelFgrp.Visible = true;
                    LblDelMsg.Text = "注意:此動作會刪除此廠群組(<b>" + myMsg.Query("KeyOther") + "</b>)以下的所有廠群組及其相關之廠別和使用者!";
                    break;
                case ("UpdFgrpFact"):
                    m_FgrpFactId = myMsg.Query("Key");
                    break;
                case "FactDelFunc":
                    ViewState["ActionType"] = "FactDelFunc";
                    PalFgrp.Visible = false;
                    PalAddFgrp.Visible = false;
                    PalDelFgrp.Visible = false;
                    PalDelFact.Visible = true;
                    LblDelFactMsg.Text = "注意:此動作會刪除此廠群組(<b>" + CheckQueryString("Fgrp_Nm") + "</b>)以下的廠別(<b>" + myMsg.Query("KeyOther") + "</b>)!";
                    break;
                case "UserDelFunc":
                    ViewState["ActionType"] = "UserDelFunc";
                    PalFgrp.Visible = false;
                    PalAddFgrp.Visible = false;
                    PalDelFgrp.Visible = false;
                    PalDelFact.Visible = false;
                    PalDelUser.Visible = true;
                    LblDelUserMsg.Text = "注意:此動作會刪除此廠群組(<b>" + CheckQueryString("Fgrp_Nm") + "</b>)以下的使用者(<b>" + myMsg.Query("KeyOther") + "</b>)之權限!";
                    break;
                default:
                    GenMasterTable();
                    break;
            }

        }
        else
        {
            string SrcUp_Id = string.Empty;
            if (Request.Params["SrcUp_Id"] != null)
            {
                SrcUp_Id = Request.Params["SrcUp_Id"].ToString();
                GenTree(ref TreeView1);
                //利用GetNodeIndex去設定m_CurrentNodeIndex的值,不需要再去設定一次Selected Lemor 20080312
                string aaa = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                //TreeView1.FindNode(GetNodeIndex(TreeView1.Nodes, SrcUp_Id)).Selected = true;
                //TreeView1.SelectedValue = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                //TreeView1.SelectedNodeIndex = GetNodeIndex(TreeView1.Nodes, SrcUp_Id);
                if (m_CurrentNodeIndex != null)
                {
                    string[] a;
                    a = m_CurrentNodeIndex.Split('/');
                    TreeView1.ExpandDepth = a.Length - 1;
                    //TreeView1.ExpandLevel = a.Length - 1;
                    TreeView1.FindNode(m_CurrentNodeIndex).Selected = true;
                    TreeView1.FindNode(m_CurrentNodeIndex).Expand();
                    //TreeView1.SelectedValue = m_CurrentNodeIndex;
                    //TreeView1.SelectedNodeIndex = m_CurrentNodeIndex;
                }
            }
        }
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (Session["UserID"] == null) return;

        // 將使用者程式碼置於此以初始化網頁

        //設定抬頭 20040607
        //			for(int i = 0 ; i < Header1.Controls.Count ; i++)
        //			{
        //				if (Header1.Controls[i].ID == "PccTitle")
        //				{
        //					Label mylblTitle = (Label)(Header1.Controls[i]);
        //					mylblTitle.Text = "應用程式管理";
        //				}
        //			}

        if (!IsPostBack)
        {
            //Calendar1.Text = "20000101";
            PccErrMsg myLabel = new PccErrMsg(Server.MapPath(Session["PageLayer"] + "XmlDoc"), Session["CodePage"].ToString(), "Label");
            PccMsg myMsg = new PccMsg();
            SetLabel(ref myLabel);

            //設定之前User鍵入的查詢資料。 2004/3/8
            if (Request.Params["QueryCondition"] != null && Request.Params["QueryCondition"].ToString() != "")
            {
                myMsg.LoadXml(Request.Params["QueryCondition"].ToString());
                txtApName.Text = myMsg.Query("QueryCondition/txtApName");
            }

            GenMasterTable(ref myLabel);

            if (Request.Params["Method"] != null && Request.Params["Method"].ToString() != "")
            {
                myMsg.LoadXml(Request.Params["Method"].ToString());
                switch (myMsg.Query("Method"))
                {
                    case "MasterDelFunc":
                        MasterDelFunc(myMsg.Query("Key"), myMsg.Query("KeyOther"), ref myLabel);
                        break;
                    case "DetailDelFunc":
                        DetailDelFunc(myMsg.Query("Key"), myMsg.Query("KeyOther"), ref myLabel);
                        break;
                }
            }

        }
    }
    private void GenMasterTableData(ref PccErrMsg myLabel)
    {
        //取得Login的使用者是否有刪除的權限
        GetMenuAuth myAuth = new GetMenuAuth();
        bool del_auth = myAuth.IsDeleteAuth();

        PccBsSystemForC.bs_ApManager mybs = new PccBsSystemForC.bs_ApManager(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("Vpath", ConfigurationManager.AppSettings["vpath"].ToString());
        myMsg.CreateFirstNode("ApName", txtApName.Text);
        string strXML = myMsg.GetXmlStr;
        DataSet myApDs = mybs.DoReturnDataSet("GetApByVpath", strXML, "");

        DataTable myApData = myApDs.Tables["Ap"];

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

            PccRow myRow;

            //取出資料總筆數
            PageControl1.TotalSize = myApDs.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;

            XmlElement myNode;

            //明細資料的欄位參數
            string strOrgFields5 = "link-新增選單-" + MENUADDNEW + "?ApID=" + Request.Params["ApID"].ToString() + "&Type=New&QueryCondition=" + GetQueryCondition();
            string[] Fields = { "編號", "選單編碼", "選單名稱", "選單連結", "管理區", strOrgFields5 };
            int[] FieldsPercent = { 5, 8, 17, 50, 10, 10 };
            string[] FieldsItem = { "--NO--", "menu_no", "menu_nm", "menu_link", "manage_mk", "menu_id" };
            string[] FieldsType = new string[6];
            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>Text</Type></PccMsg>";

            //設定明細欄位中多個Link Image的參數
            myMsg.LoadXml();
            myMsg.CreateFirstNode("Type", "MultiLink");

            //設定第一個更新選單的Image參數
            myMsg.CreateNode("LinkButton");
            myMsg.AddToNode("Image", Session["PageLayer"] + "images/edit.gif");
            myMsg.AddToNode("ToolTip", "更新選單");
            myMsg.AddToNode("href", MENUADDNEW + "?ApID=" + Request.Params["ApID"].ToString());
            myMsg.AddToNode("QueryCondition", GetQueryCondition());
            myNode = myMsg.CreateParentNode("Method");
            myMsg.AddToNode("MethodName", "DetailUpdFunc", ref myNode);
            myMsg.AddToNode("Key", "menu_id", ref myNode);
            myMsg.AddToNode("KeyOther", "menu_nm", ref myNode);
            myMsg.UpdateNode(myNode);
            myMsg.UpdateNode();

            if (del_auth)
            {
                //設定第二個刪除選單的Image參數
                myMsg.CreateNode("LinkButton");
                myMsg.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                myMsg.AddToNode("ToolTip", "刪除選單");
                myMsg.AddToNode("href", APMANAGE + "?ApID=" + Request.Params["ApID"].ToString());
                myMsg.AddToNode("QueryCondition", GetQueryCondition());
                myNode = myMsg.CreateParentNode("Method");
                myMsg.AddToNode("MethodName", "DetailDelFunc", ref myNode);
                myMsg.AddToNode("Key", "menu_id", ref myNode);
                myMsg.AddToNode("KeyOther", "menu_nm", ref myNode);
                myMsg.UpdateNode(myNode);
                myMsg.UpdateNode();
            }

            FieldsType[5] = myMsg.GetXmlStr;

            //要取得明細資料的Table變數
            DataTable tblMenuByApID;

            //再利用此Table再取得其每一列的資料,再Gen出主要的Table Row.
            foreach (DataRow myMasterRow in myApData.Rows)
            {
                if (MasterCount % 2 == 0) MasterStyle = "eee000"; else MasterStyle = "fff000";
                myRow = new PccRow();
                myRow.SetRowCss(MasterStyle);
                //編號
                myRow.AddTextCell(PageControl1.ListCount, 5);
                //應用程式編碼
                myRow.AddTextCell(myMasterRow["ap_id"].ToString(), 10);
                //應用程式名稱
                myRow.AddTextCell(myMasterRow["ap_name"].ToString(), 15);
                //應用程式連結
                myRow.AddTextCell(myMasterRow["ap_link"].ToString(), 40);
                //應用程式目錄
                myRow.AddTextCell(myMasterRow["ap_vpath"].ToString(), 15);
                //檢視
                myTempMsg = new PccMsg();
                myTempMsg.CreateFirstNode("ToolTip", myLabel.GetErrMsg("lbl0018", "SysManager/ApManager"));
                myTempMsg.CreateFirstNode("LinkID", "HLinkView" + myMasterRow["ap_id"].ToString());
                myTempMsg.CreateFirstNode("Image", Session["PageLayer"] + "images/detal.gif");
                myTempMsg.CreateFirstNode("ClickFun", "doSection(view_" + MasterCount.ToString() + ")");
                myRow.AddLinkCell(myTempMsg.GetXmlStr, 5);
                //管理
                myTempMsg.LoadXml();
                //先加入修改的Item
                myTempMsg.CreateNode("LinkButton");
                myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/edit.gif");
                myTempMsg.AddToNode("ToolTip", myLabel.GetErrMsg("lbl0014", "SysManager/ApManager"));
                myTempMsg.AddToNode("href", APADDNEW + "?ApID=" + Request.Params["ApID"].ToString());
                myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                myTempMsg.AddToNode("Method", GetMethod("MasterUpdateFunc", "ap_id", "ap_name", myMasterRow));
                myTempMsg.UpdateNode();
                if (del_auth)
                {
                    //再加入刪除的Item
                    myTempMsg.CreateNode("LinkButton");
                    myTempMsg.AddToNode("Image", Session["PageLayer"] + "images/del.gif");
                    myTempMsg.AddToNode("ToolTip", myLabel.GetErrMsg("lbl0015", "SysManager/ApManager"));
                    myTempMsg.AddToNode("href", APMANAGE + "?ApID=" + Request.Params["ApID"].ToString());
                    myTempMsg.AddToNode("QueryCondition", GetQueryCondition());
                    myTempMsg.AddToNode("Method", GetMethod("MasterDelFunc", "ap_id", "ap_name", myMasterRow));
                    myTempMsg.UpdateNode();
                }
                myRow.AddMultiLinkCell(myTempMsg.GetXmlStr, 5);

                tblAp.Rows.Add(myRow.Row);

                tblMenuByApID = mybs.DoReturnDataSet("GetMenuByApID", "<PccMsg><ap_id>" + myMasterRow["ap_id"].ToString() + "</ap_id></PccMsg>", "").Tables["Menu"];

                //設定選單明細資料類別之參數
                PccDetailTable myDTable = new PccDetailTable("DT" + myMasterRow["ap_id"].ToString());
                myDTable.ClassXML = strClassXML;
                Fields[5] = strOrgFields5 + "&Key=" + myMasterRow["ap_id"].ToString();
                myDTable.Fields = Fields;
                myDTable.FieldsPercent = FieldsPercent;
                myDTable.FieldsItem = FieldsItem;
                myDTable.FieldsType = FieldsType;
                myDTable.NewDataTable = tblMenuByApID;

                myDTable.Create();

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

                tblAp.Rows.Add(myRow.Row);

                MasterCount += 1;

            } // end of foreach datarow
        } // end of if table count is 0
        else
        {
            PageControl1.TotalSize = "0";
            PageControl1.BuildPager();
        }
    }