using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; // Local namespaces using uk.eurologic.lib.core; using uk.eurologic.lib.acme; public partial class CMS_EditMenu : System.Web.UI.Page { protected CAcmeUser m_User; protected void Page_Load(object sender, EventArgs e) { m_User = new CAcmeUser(Request.Cookies); if (!IsPostBack) { popMenuLabels(); } else { updateMenuLabels(); //Response.Write(""); Response.Write(""); Response.End(); } } protected void popMenuLabels() { TextBox[] edtNav2Id_X = new TextBox[12] { edtNav2Id_1, edtNav2Id_2, edtNav2Id_3, edtNav2Id_4, edtNav2Id_5, edtNav2Id_6, edtNav2Id_7, edtNav2Id_8, edtNav2Id_9, edtNav2Id_10, edtNav2Id_11, edtNav2Id_12 }; TextBox[] edtSeq_X = new TextBox[12] { edtSeq_1, edtSeq_2, edtSeq_3, edtSeq_4, edtSeq_5, edtSeq_6, edtSeq_7, edtSeq_8, edtSeq_9, edtSeq_10, edtSeq_11, edtSeq_12 }; TextBox[] edtMenuLabel_X = new TextBox[12] { edtMenuLabel_1, edtMenuLabel_2, edtMenuLabel_3, edtMenuLabel_4, edtMenuLabel_5, edtMenuLabel_6, edtMenuLabel_7, edtMenuLabel_8, edtMenuLabel_9, edtMenuLabel_10, edtMenuLabel_11, edtMenuLabel_12 }; CheckBox[] ckDelete_X = new CheckBox[12] { ckDelete_1, ckDelete_2, ckDelete_3, ckDelete_4, ckDelete_5, ckDelete_6, ckDelete_7, ckDelete_8, ckDelete_9, ckDelete_10, ckDelete_11, ckDelete_12 }; string sNav1Id = Request.QueryString["Nav"] != null ? Request.QueryString["Nav"].ToString() : "Home"; DataTable tbl = CMenu.GetMenuLabels(sNav1Id); // The first record will always be the [Nav1Id].~ value if (tbl.Rows.Count > 0) { int iSeqBase = Int32.Parse(tbl.Rows[0]["Seq"].ToString()); //edtNavBase.Text = tbl.Rows[0]["Nav2Id"].ToString(); edtSeqBase.Text = iSeqBase.ToString(); edtMenuBase.Text = tbl.Rows[0]["MenuLabel"].ToString(); string sMenuName = tbl.Rows[0]["MenuLabel"].ToString(); Label lblDialogTitle = (Label)Page.Master.FindControl("lblDialogTitle"); if (lblDialogTitle != null) lblDialogTitle.Text = "Update menus for " + sMenuName; for (int i = 1; i < tbl.Rows.Count && i <= 12; i++) { edtNav2Id_X[i-1].Text = tbl.Rows[i]["Nav2Id"].ToString(); edtNav2Id_X[i-1].BackColor = System.Drawing.Color.Gainsboro; edtNav2Id_X[i-1].ReadOnly = true; //edtSeq_X[i-1].Text = (Int32.Parse(tbl.Rows[i]["Seq"].ToString()) - iSeqBase).ToString(); edtSeq_X[i - 1].Text = tbl.Rows[i]["Seq"].ToString(); edtMenuLabel_X[i-1].Text = tbl.Rows[i]["MenuLabel"].ToString(); ckDelete_X[i - 1].Visible = true; } } } protected void updateMenuLabels() { // Create arrays of page controls, so that we can use iteration below TextBox[] edtNav2Id_X = new TextBox[12] { edtNav2Id_1, edtNav2Id_2, edtNav2Id_3, edtNav2Id_4, edtNav2Id_5, edtNav2Id_6, edtNav2Id_7, edtNav2Id_8, edtNav2Id_9, edtNav2Id_10, edtNav2Id_11, edtNav2Id_12 }; TextBox[] edtSeq_X = new TextBox[12] { edtSeq_1, edtSeq_2, edtSeq_3, edtSeq_4, edtSeq_5, edtSeq_6, edtSeq_7, edtSeq_8, edtSeq_9, edtSeq_10, edtSeq_11, edtSeq_12 }; TextBox[] edtMenuLabel_X = new TextBox[12] { edtMenuLabel_1, edtMenuLabel_2, edtMenuLabel_3, edtMenuLabel_4, edtMenuLabel_5, edtMenuLabel_6, edtMenuLabel_7, edtMenuLabel_8, edtMenuLabel_9, edtMenuLabel_10, edtMenuLabel_11, edtMenuLabel_12 }; CheckBox[] ckDelete_X = new CheckBox[12] { ckDelete_1, ckDelete_2, ckDelete_3, ckDelete_4, ckDelete_5, ckDelete_6, ckDelete_7, ckDelete_8, ckDelete_9, ckDelete_10, ckDelete_11, ckDelete_12 }; string sNav1Id = Request.QueryString["Nav"]; string sNav2Id = ""; string sMenuLabel = ""; int iSeq = 0; int iSeqBase = 0; Int32.TryParse(edtSeqBase.Text, out iSeqBase); // Update the top-level menu label CMenu.DbUpdateMenuLabel(sNav1Id, "~", iSeqBase, edtMenuBase.Text, m_User.Id); for (int i = 1; i <= 12; i++) { sMenuLabel = edtMenuLabel_X[i-1].Text; sNav2Id = edtNav2Id_X[i-1].Text; if (Int32.TryParse(edtSeq_X[i-1].Text, out iSeq)) { if (iSeq > 0 && sNav2Id != "") { if (edtNav2Id_X[i - 1].ReadOnly) { if (ckDelete_X[i - 1].Checked) CMenu.DbDeleteMenuLabel(sNav1Id, sNav2Id); else CMenu.DbUpdateMenuLabel(sNav1Id, sNav2Id, iSeq, sMenuLabel, m_User.Id); } else CMenu.DbInsertMenuLabel(sNav1Id, sNav2Id, iSeq, sMenuLabel, m_User.Id); } } } } }