示例#1
0
        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string      strMessage = string.Empty;
            string      strCheck   = string.Empty;
            string      strScript  = string.Empty;
            HiddenField hddMenuID  = (HiddenField)GridView1.Rows[e.RowIndex].FindControl("hddMenuID");
            cMenu       oMenu      = new cMenu();

            try
            {
                if (!oMenu.SP_MENU_DEL(hddMenuID.Value.ToString(), ref strMessage))
                {
                    if (strMessage.Contains("REFERENCE constraint"))
                    {
                        MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                    }
                    else
                    {
                        lblError.Text = strMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("REFERENCE constraint"))
                {
                    MsgBox("ไม่สามารถลบข้อมูลได้เนื่องจากมีการนำไปใช้ในระบบแล้ว");
                }
                else
                {
                    lblError.Text = ex.Message.ToString();
                }
            }
            finally
            {
                oMenu.Dispose();
            }
            BindGridView(0);
        }
示例#2
0
        private void BindGridView(int nPageNo)
        {
            cMenu   oMenu        = new cMenu();
            DataSet ds           = new DataSet();
            string  strMessage   = string.Empty;
            string  strCriteria  = string.Empty;
            string  strMenuName  = string.Empty;
            string  stMenuParent = string.Empty;
            string  strUrl       = string.Empty;

            strMenuName  = txtMenuName.Text.Replace("'", "''").Trim();
            strUrl       = txtUrl.Text.Replace("'", "''").Trim();
            stMenuParent = cboMenuParent.SelectedValue;

            if (!strMenuName.Equals(""))
            {
                strCriteria = strCriteria + "  And  (MenuName like '%" + strMenuName + "%') ";
            }

            if (!strUrl.Equals(""))
            {
                strCriteria = strCriteria + "  And  (MenuNavigationUrl like '%" + strUrl + "%') ";
            }

            if (!stMenuParent.Equals(""))
            {
                strCriteria = strCriteria + "  And  (MenuParent = '" + stMenuParent + "') ";
            }


            if (RadioActive.Checked)
            {
                strCriteria = strCriteria + "  And  ([Status] ='Y') ";
            }
            else if (RadioCancel.Checked)
            {
                strCriteria = strCriteria + "  And  ([Status] ='N') ";
            }

            try
            {
                if (!oMenu.SP_MENU_SEL(strCriteria, ref ds, ref strMessage))
                {
                    lblError.Text = strMessage;
                }
                else
                {
                    try
                    {
                        GridView1.PageIndex           = nPageNo;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                    catch
                    {
                        GridView1.PageIndex           = 0;
                        txthTotalRecord.Value         = ds.Tables[0].Rows.Count.ToString();
                        ds.Tables[0].DefaultView.Sort = ViewState["sort"] + " " + ViewState["direction"];
                        GridView1.DataSource          = ds.Tables[0];
                        GridView1.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oMenu.Dispose();
                ds.Dispose();
                if (GridView1.Rows.Count > 0)
                {
                    GridView1.TopPagerRow.Visible = true;
                }
            }
        }
示例#3
0
        private bool saveData()
        {
            bool   blnResult  = false;
            bool   blnDup     = false;
            string strMessage = string.Empty;
            //Tab 1
            string
                pMenuID            = string.Empty,
                pMenuName          = string.Empty,
                pMenuNavigationUrl = string.Empty,
                pMenuImageUrl      = string.Empty,
                pMenuTarget        = string.Empty,
                pMenuParent        = string.Empty,
                pMenuOrder         = string.Empty,
                pCanView           = string.Empty,
                pCanInsert         = string.Empty,
                pCanEdit           = string.Empty,
                pCanDelete         = string.Empty,
                pCanApprove        = string.Empty,
                pCanExtra          = string.Empty,
                pStatus            = string.Empty,
                strRemark          = string.Empty,
                strCreatedBy       = string.Empty,
                strUpdatedBy       = string.Empty;
            string  strScript      = string.Empty;
            cMenu   oMenu          = new cMenu();
            DataSet ds             = new DataSet();

            try
            {
                #region set Data
                pMenuID            = hddMenuID.Value.ToString();
                pMenuName          = txtMenuName.Text;
                pMenuNavigationUrl = txtMenuNavigationUrl.Text;
                pMenuImageUrl      = txtMenuImageUrl.Text;
                pMenuTarget        = cboMenuTarget.SelectedValue;
                pMenuParent        = cboMenuParent.SelectedValue;
                pMenuOrder         = txtMenuOrder.Value.ToString();
                pCanView           = chkCanView.Checked ? "Y" : "N";
                pCanInsert         = chkCanInsert.Checked ? "Y" : "N";
                pCanEdit           = chkCanEdit.Checked ? "Y" : "N";
                pCanDelete         = chkCanDelete.Checked ? "Y" : "N";
                pCanApprove        = chkCanApprove.Checked ? "Y" : "N";
                pCanExtra          = chkCanExtra.Checked ? "Y" : "N";
                pStatus            = chkStatus.Checked ? "Y" : "N";
                strRemark          = txtRemark.Text;
                strCreatedBy       = Session["username"].ToString();
                strUpdatedBy       = Session["username"].ToString();
                #endregion
                if (ViewState["mode"].ToString().ToLower().Equals("edit"))
                {
                    #region edit

                    #region check dup
                    string strCheckDup = string.Empty;
                    strCheckDup = " and MenuName = '" + pMenuName + "'  and [MenuName] <> '" + hddMenuName.Value.ToString() + "' ";
                    if (!oMenu.SP_MENU_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถแก้ไขข้อมูลได้ เนื่องจาก" +
                                "\\nข้อมูล ชื่อเมนู : " + pMenuName.Trim() +
                                "\\nซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion
                    if (!blnDup)
                    {
                        if (oMenu.SP_MENU_UPD(pMenuID, pMenuName, pMenuNavigationUrl, pMenuImageUrl, pMenuTarget, pMenuParent, pMenuOrder, pCanView,
                                              pCanInsert, pCanEdit, pCanDelete, pCanApprove, pCanExtra, pStatus, strRemark, strUpdatedBy, ref strMessage))
                        {
                            blnResult = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "chkdup", strScript, true);
                    }
                    #endregion
                }
                else
                {
                    #region check dup
                    string strCheckDup = string.Empty;
                    strCheckDup = " and [MenuName] = '" + pMenuName + "' ";
                    if (!oMenu.SP_MENU_SEL(strCheckDup, ref ds, ref strMessage))
                    {
                        lblError.Text = strMessage;
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            strScript =
                                "alert(\"ไม่สามารถเพิ่มข้อมูลได้ เนื่องจาก" +
                                "\\nข้อมูล เมนู : " + pMenuName.Trim() +
                                "\\nซ้ำ\");\n";
                            blnDup = true;
                        }
                    }
                    #endregion

                    #region insert
                    if (!blnDup)
                    {
                        if (oMenu.SP_MENU_INS(pMenuName, pMenuNavigationUrl, pMenuImageUrl, pMenuTarget, pMenuParent, pMenuOrder, pCanView,
                                              pCanInsert, pCanEdit, pCanDelete, pCanApprove, pCanExtra, pStatus, strRemark, strUpdatedBy, ref strMessage))
                        {
                            string strCode = " and [MenuName] = '" + pMenuName + "' ";
                            if (!oMenu.SP_MENU_SEL(strCheckDup, ref ds, ref strMessage))
                            {
                                lblError.Text = strMessage;
                            }
                            else
                            {
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    ViewState["MenuID"] = ds.Tables[0].Rows[0]["MenuID"].ToString();
                                }
                            }
                            blnResult = true;
                        }
                        else
                        {
                            lblError.Text = strMessage.ToString();
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "close", strScript, true);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message.ToString();
            }
            finally
            {
                oMenu.Dispose();
            }
            return(blnResult);
        }