Ejemplo n.º 1
0
        protected void ctlUserProfile_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int rowIndex = 0;

            InvisibleAllPopUpcontrol();

            if (e.CommandName.Equals("Approver"))
            {
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                UId      = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString());
                Approver.Initialize(UId);
                Approver.ShowDetail();

                // แก้ไขการกด link ในกริด ที่จะเป็น Editor มาในหน้าเดียวกัน ไม่ต้องทำการ CountAndBind จะทำให้ไม่เกิด Event ในการกด Link ครั้งต่อไป
                //ctlUserProfileGrid.DataCountAndBind();
            }
            if (e.CommandName.Equals("Initiator"))
            {
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                UId      = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString());
                Initiator.Initialize(UId);
                Initiator.ShowDetail();
                //Approver.CloseApproverGrid();
            }
            if (e.CommandName.Equals("Group"))
            {
                rowIndex = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex;
                UId      = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString());
                UserGroup.Initialize(UId);
                UserGroup.ShowDetail();
                ctlUpdatePanelInformation.Update();
            }
            if (e.CommandName.Equals("UserProfileMethodEdit"))
            {
                rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                UId      = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString());

                ctlAddEditPopup.Initialize(FlagEnum.EditFlag, UId);
                //ctlAddEditPopup.ShowPopUp();
                ShowPopUp();
            }

            if (e.CommandName.Equals("UserProfileMethodDelete"))
            {
                try
                {
                    rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
                    UId      = UIHelper.ParseLong(ctlUserProfileGrid.DataKeys[rowIndex].Value.ToString());
                    SuUser userprofile = QueryProvider.SuUserQuery.FindByIdentity(UId);
                    SuUserService.DeleteUser(userprofile);
                }
                catch (Exception ex)
                {
                    if (((System.Data.SqlClient.SqlException)(ex.GetBaseException())).Number == 547)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertInUseData",
                                                                "alert('This data is now in use.');", true);
                        ctlUserProfileGrid.DataCountAndBind();
                    }
                }

                ctlUserProfileGrid.DataCountAndBind();
            }
            ctlUserProfileGrid.SelectedIndex = rowIndex;
            ctlUserGridUpdatePanel.Update();
            ctlUpdatePanelInformation.Update();
        }