private void SetDropDownList(bool Enable) { if (this.GridView1.Rows.Count <= 0) return; UserID = int.Parse(ViewState["UserID"].ToString()); string UserName = ViewState["UserName"].ToString(); int ParentUserID = int.Parse(ViewState["ParentUserID"].ToString()); string ParentUserName = ViewState["ParentUserName"].ToString(); Js.BLL.Account.UserDal dal = new Js.BLL.Account.UserDal(); dtRole = dal.GetUserRolePermission(UserID, UserName).Tables[0]; //父級用戶權限 DataTable dt; if (ViewState["ParentUserName"].ToString().ToLower() == "administrator" || ViewState["ParentUserName"].ToString() == "") dt = dal.GetPermission(Session["language_session"].ToString()).Tables[0]; else dt = dal.GetUserPermission(ParentUserID, ParentUserName).Tables[0]; DropDownList ddl; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadBrowse")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadDo")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadAdd")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadEdit")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadDelete")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadPrint")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadStop")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadCheck")); ddl.Enabled = Enable; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadUnCheck")); ddl.Enabled = Enable; for (int i = 0; i < this.GridView1.Rows.Count; i++) { //int SysID = int.Parse(this.GridView1.Rows[i].Cells[13].Text); //int PermissionID = int.Parse(this.GridView1.Rows[i].Cells[14].Text); //DataRow[] dr = dtRole.Select(string.Format("SysID={0} and PermissionID={1}", SysID, PermissionID)); //DataRow[] drp = dt.Select(string.Format("SysID={0} and PermissionID={1}", SysID, PermissionID)); //角色權限 //string RolePermission = "0000000000"; //string ParentPermission = "0000000000"; //if (dr.Length > 0) // RolePermission = dr[0]["Permission"].ToString(); //if (drp.Length > 0) // ParentPermission = drp[0]["Permission"].ToString(); //Browse ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlBrowse")); //if (int.Parse(RolePermission.Substring(0, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //int PIndex = int.Parse(ParentPermission.Substring(0, 1)); //for(int j=PIndex+1;j<4;j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Do ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlDo")); //if (int.Parse(RolePermission.Substring(1, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(1, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Add ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlAdd")); //if (int.Parse(RolePermission.Substring(2, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(2, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Edit ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlEdit")); //if (int.Parse(RolePermission.Substring(3, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(3, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Delete ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlDelete")); //if (int.Parse(RolePermission.Substring(4, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(4, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Print ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlPrint")); //if (int.Parse(RolePermission.Substring(5, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(5, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Stop ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlStop")); //if (int.Parse(RolePermission.Substring(6, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(6, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //Check ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlCheck")); //if (int.Parse(RolePermission.Substring(7, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(7, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); //UnCheck ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlUnCheck")); //if (int.Parse(RolePermission.Substring(8, 1)) > 0) // ddl.Enabled = false; //else ddl.Enabled = Enable; //PIndex = int.Parse(ParentPermission.Substring(8, 1)); //for (int j = PIndex + 1; j < 4; j++) // ddl.Items[j].Attributes.Add("disabled", "disabled"); } }
protected void btnSave_Click(object sender, EventArgs e) { UserID = int.Parse(ViewState["UserID"].ToString()); string UserName = ViewState["UserName"].ToString(); Js.BLL.Account.UserDal dal = new Js.BLL.Account.UserDal(); dtRole = dal.GetUserRolePermission(UserID, UserName).Tables[0]; ArrayList SysID = new ArrayList(); ArrayList PermissionID = new ArrayList(); ArrayList Permission = new ArrayList(); DropDownList ddl; for (int i = 0; i < this.GridView1.Rows.Count; i++) { DataRow[] dr = dtRole.Select(string.Format("SysID={0} and PermissionID={1}", this.GridView1.Rows[i].Cells[13].Text, this.GridView1.Rows[i].Cells[14].Text)); //角色權限 string RolePermission = "0000000000"; if (dr.Length > 0) RolePermission = dr[0]["Permission"].ToString(); string Permissions = ""; SysID.Add(this.GridView1.Rows[i].Cells[13].Text); PermissionID.Add(this.GridView1.Rows[i].Cells[14].Text); //Permission += "," + this.GridView1.Rows[i].Cells[13].Text; //Permission += "|" + this.GridView1.Rows[i].Cells[14].Text + "|"; //Browse ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlBrowse")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions = "0"; //Do ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlDo")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlAdd")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //Edit ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlEdit")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //Delete ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlDelete")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //Print ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlPrint")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //Stop ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlStop")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //Check ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlCheck")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; //UnCheck ddl = (DropDownList)(this.GridView1.Rows[i].FindControl("ddlUnCheck")); if (ddl != null) { Permissions += ddl.SelectedIndex.ToString(); ddl.Enabled = false; } else Permissions += "0"; Permission.Add(Permissions); } dal.AddUserPermission(int.Parse(ViewState["UserID"].ToString()), SysID, PermissionID, Permission); ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadBrowse")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadDo")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadAdd")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadEdit")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadDelete")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadPrint")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadStop")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadCheck")); ddl.Enabled = false; ddl = (DropDownList)(this.GridView1.HeaderRow.FindControl("ddlHeadUnCheck")); ddl.Enabled = false; IsEdit = false; this.btnAdd.Enabled = !IsEdit; this.btnPermission.Enabled = !IsEdit; this.btnDelete.Enabled = !IsEdit; this.btnCopyPermission.Enabled = IsEdit; this.btnCancel.Enabled = IsEdit; this.btnSave.Enabled = IsEdit; ScriptManager.RegisterStartupScript(this.updatePanel, this.GetType(), "Display", "document.getElementById('tdTree').style.display = '';treeview_resize();", true); }