private void InitcboMenuParent() { cMenu oMenu = new cMenu(); string strMessage = string.Empty, strCriteria = string.Empty, strMenuParent = string.Empty; strMenuParent = cboMenuParent.SelectedValue; int i; DataSet ds = new DataSet(); DataTable dt = new DataTable(); strCriteria = " and [Status]='Y' Order by MenuOrder"; if (oMenu.SP_MENU_SEL(strCriteria, ref ds, ref strMessage)) { dt = ds.Tables[0]; cboMenuParent.Items.Clear(); cboMenuParent.Items.Add(new ListItem("---- เลือกทั้งหมด ----", "")); for (i = 0; i <= dt.Rows.Count - 1; i++) { cboMenuParent.Items.Add(new ListItem(dt.Rows[i]["MenuName"].ToString(), dt.Rows[i]["MenuID"].ToString())); } if (cboMenuParent.Items.FindByValue(strMenuParent) != null) { cboMenuParent.SelectedIndex = -1; cboMenuParent.Items.FindByValue(strMenuParent).Selected = true; } } }
private void setData() { cMenu oMenu = new cMenu(); DataSet ds = new DataSet(); string strMessage = string.Empty, strCriteria = string.Empty; try { strCriteria = " and MenuID = '" + ViewState["MenuID"].ToString() + "' "; if (!oMenu.SP_MENU_SEL(strCriteria, ref ds, ref strMessage)) { lblError.Text = strMessage; } else { if (ds.Tables[0].Rows.Count > 0) { #region get Data hddMenuID.Value = ds.Tables[0].Rows[0]["MenuID"].ToString(); txtMenuName.Text = ds.Tables[0].Rows[0]["MenuName"].ToString(); hddMenuName.Value = ds.Tables[0].Rows[0]["MenuName"].ToString(); txtMenuNavigationUrl.Text = ds.Tables[0].Rows[0]["MenuNavigationUrl"].ToString(); txtMenuImageUrl.Text = ds.Tables[0].Rows[0]["MenuImageUrl"].ToString(); if (cboMenuTarget.Items.FindByValue(ds.Tables[0].Rows[0]["MenuTarget"].ToString()) != null) { cboMenuTarget.SelectedIndex = -1; cboMenuTarget.Items.FindByValue(ds.Tables[0].Rows[0]["MenuTarget"].ToString()).Selected = true; } InitcboMenuParent(); if (cboMenuParent.Items.FindByValue(ds.Tables[0].Rows[0]["MenuParent"].ToString()) != null) { cboMenuParent.SelectedIndex = -1; cboMenuParent.Items.FindByValue(ds.Tables[0].Rows[0]["MenuParent"].ToString()).Selected = true; } txtMenuOrder.Value = ds.Tables[0].Rows[0]["MenuOrder"].ToString(); chkCanView.Checked = ds.Tables[0].Rows[0]["CanView"].ToString() == "Y" ? true : false; chkCanInsert.Checked = ds.Tables[0].Rows[0]["CanInsert"].ToString() == "Y" ? true : false; chkCanEdit.Checked = ds.Tables[0].Rows[0]["CanEdit"].ToString() == "Y" ? true : false; chkCanDelete.Checked = ds.Tables[0].Rows[0]["CanDelete"].ToString() == "Y" ? true : false; chkCanApprove.Checked = ds.Tables[0].Rows[0]["CanApprove"].ToString() == "Y" ? true : false; chkCanExtra.Checked = ds.Tables[0].Rows[0]["CanExtra"].ToString() == "Y" ? true : false; chkStatus.Checked = ds.Tables[0].Rows[0]["Status"].ToString() == "Y" ? true : false; txtRemark.Text = ds.Tables[0].Rows[0]["Remark"].ToString(); txtUpdatedBy.Text = ds.Tables[0].Rows[0]["UpdatedBy"].ToString();; txtUpdatedDate.Text = ds.Tables[0].Rows[0]["UpdatedDate"].ToString() != "" ? cCommon.CheckDate(ds.Tables[0].Rows[0]["UpdatedDate"].ToString()) : ""; #endregion } } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } }
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; } } }
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); }