private void SetObjectControl(string PageStatus) { #region 檢視 if (PageStatus == "VIEW") { #region 判斷簽核日與刪除按鈕 if ((this.slp_down_CRM_CONFIRM_DATE.Text != String.Empty) || (this.slp_down_UNIT_CONFIRM_DATE.Text != String.Empty)) { this.but_Delete.Enabled = false; //this.but_Edit.Enabled = false; this.txt_down_CODE.Enabled = false; this.slp_down_PROC_UNIT.Enabled = false; this.slp_down_REQUEST_NO.Enabled = false; this.slp_down_GRADE.Enabled = false; this.slp_down_PROC_MAN.Enabled = false; this.txt_down_PROC_STATEMENT.Enabled = false; this.txt_down_REQUEST_STATEMENT.Enabled = false; } #endregion UID_UNIT = string.Empty; #region 判斷所屬單位 if (this.slp_down_PROC_UNIT.Text != String.Empty) { //取得使用者角色權限 ArrayList ParameterList = new ArrayList();//20091117 ParameterList.Clear(); ParameterList.Add(Session["UID"].ToString()); PIC.VDS2G.COMMON.SYS.MaintainUserRoleRel co_userrole = new PIC.VDS2G.COMMON.SYS.MaintainUserRoleRel(ConntionDB); //DataTable dtUR = co_userrole.QuerySwitch(PIC.VDS2G.COMMON.SYS.SYSCommon.QueryType.Custom, ParameterList); DataTable dtUR = co_userrole.QueryUserRoleRelByUserCode(ParameterList); if (dtUR.Rows.Count > 0) { DataRow[] dRows = dtUR.Select(String.Format(@"ROLECODE in ('{0}','{1}')", this.slp_down_PROC_UNIT.Text, CRM_UNIT)); if (dRows.Length < 1) { this.but_Edit.Enabled = false; this.but_Delete.Enabled = false; } else { UID_UNIT = dRows[0]["ROLECODE"].ToString().Trim(); } } else //查無關連檔 { if (Session["UID"].ToString() != "admin") { this.but_Edit.Enabled = false; this.but_Delete.Enabled = false; } } } #endregion } else if (PageStatus == "EDIT") { #region 根據所屬單位判斷是否可編輯 if (UID_UNIT == CRM_UNIT) { txt_down_CODE.Enabled = true; txt_down_CODE.CssClass = ""; slp_down_PROC_UNIT.Enabled = true; slp_down_PROC_MAN.Enabled = true; slp_down_PROC_MAN.CssClass = ""; //slp_down_REQUEST_NO.Enabled = true; DropDownList drop_REQUEST_NO = (DropDownList)((ASP.sys_slp_slp_codefile_ascx)slp_down_REQUEST_NO).FindControl("D1"); drop_REQUEST_NO.Enabled = true; drop_REQUEST_NO.CssClass = ""; RadioButtonList rbt_GRADE = (RadioButtonList)((ASP.sys_slp_slp_enumbase_ascx)slp_down_GRADE).FindControl("R1"); rbt_GRADE.Enabled = true; //slp_down_GRADE.Enabled = true; txt_down_REQUEST_STATEMENT.Enabled = true; txt_down_REQUEST_STATEMENT.CssClass = ""; chb_down_CRM_CONFIRM_DATE.Enabled = true; chb_down_UNIT_CONFIRM_DATE.Enabled = false; } else { txt_down_CODE.Enabled = false; txt_down_CODE.CssClass = "readtxtbox"; slp_down_PROC_UNIT.Enabled = false; slp_down_PROC_UNIT.TextBox_Code.CssClass = "readtxtbox"; slp_down_PROC_MAN.Enabled = false; slp_down_PROC_MAN.CssClass = "readtxtbox"; //slp_down_REQUEST_NO.Enabled = false; DropDownList drop_REQUEST_NO = (DropDownList)((ASP.sys_slp_slp_codefile_ascx)slp_down_REQUEST_NO).FindControl("D1"); drop_REQUEST_NO.Enabled = false; drop_REQUEST_NO.CssClass = "readtxtbox"; RadioButtonList rbt_GRADE = (RadioButtonList)((ASP.sys_slp_slp_enumbase_ascx)slp_down_GRADE).FindControl("R1"); rbt_GRADE.Enabled = false; //slp_down_GRADE.Enabled = false; txt_down_REQUEST_STATEMENT.Enabled = false; txt_down_REQUEST_STATEMENT.CssClass = "readtxtbox"; chb_down_CRM_CONFIRM_DATE.Enabled = false; chb_down_UNIT_CONFIRM_DATE.Enabled = true; } #endregion } else if (PageStatus == "INSERT") { #region txt_down_CODE.Enabled = true; txt_down_CODE.CssClass = ""; slp_down_PROC_UNIT.Enabled = true; slp_down_PROC_MAN.Enabled = true; slp_down_PROC_MAN.CssClass = ""; //slp_down_REQUEST_NO.Enabled = true; DropDownList drop_REQUEST_NO = (DropDownList)((ASP.sys_slp_slp_codefile_ascx)slp_down_REQUEST_NO).FindControl("D1"); drop_REQUEST_NO.Enabled = true; drop_REQUEST_NO.CssClass = ""; RadioButtonList rbt_GRADE = (RadioButtonList)((ASP.sys_slp_slp_enumbase_ascx)slp_down_GRADE).FindControl("R1"); rbt_GRADE.Enabled = true; slp_down_GRADE.Enabled = true; //slp_down_GRADE.Enabled = true; txt_down_REQUEST_STATEMENT.Enabled = true; txt_down_REQUEST_STATEMENT.CssClass = ""; chb_down_CRM_CONFIRM_DATE.Enabled = true; chb_down_UNIT_CONFIRM_DATE.Enabled = false; #endregion } #endregion }
/// <summary> /// 查詢資料庫取得資料 /// </summary> private void databind() { //抓取本頁初次登記的時間 string SessionIDName = "SYS051_" + PageTimeStamp.Value; SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConntionDB); ParameterList.Clear(); ParameterList.Add(""); //ParameterList.Add(TextBoxCode.Text.Trim()); ParameterList.Add(""); //ParameterList.Add(TextBoxName.Text.Trim()); ParameterList.Add(TextBoxCreateDate.StartDate.Trim()); ParameterList.Add(TextBoxCreateDate.EndDate.Trim()); ParameterList.Add(TextBoxCreateUID.Text.Trim()); ParameterList.Add(TextBoxUpdateDate.StartDate.Trim()); ParameterList.Add(TextBoxUpdateDate.EndDate.Trim()); ParameterList.Add(TextBoxUpdateUID.Text.Trim()); ParameterList.Add(TextBoxUserCode.Text.Trim()); ParameterList.Add(TextBoxRoleCode.Text.Trim()); ParameterList.Add(TextBoxRowCountLimit.Text.Trim()); DataTable Dt = BCO.QueryRow(ParameterList, CheckBoxLikeSearch.Checked); Session[SessionIDName] = Dt; GridView1.DataSource = Dt; //設定分頁大小 if (TextBoxPagesize.Text == "0") { GridView1.PageSize = 1; } else { GridView1.PageSize = (TextBoxPagesize.Text == "") ? 10 : (int.Parse(TextBoxPagesize.Text) < 0) ? 10 : int.Parse(TextBoxPagesize.Text); } GridView1.PageIndex = 0; GridView1.DataBind(); #region 將Key值存到Session中 ArrayList arl_Key = new ArrayList(); foreach (DataRow drRow in Dt.Rows) { arl_Key.Add("id=" + drRow["ID"].ToString()); } Session["SYS05_SortKey" + this.PageTimeStamp.Value] = arl_Key; #endregion if (Dt.Rows.Count == 0) { this.ErrorMsgLabel.Text = "查無資料"; } }
/// <summary> /// 於檢視模式,按下刪除鈕 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DeleteButton_Click(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; int DeleteRecord = 0; #region 取得畫面元件的值 DateTime processtime = DateTime.Now; #endregion #region 取得刪除前舊值 #region 使用XML轉回DataSet DataSet Ds = new DataSet(); DataTable Dt = dt_Result; #endregion if (Dt.Rows.Count == 0) { throw new Exception("抓取不到舊值,更新失敗!"); } #endregion #region 加入更新條件 ParameterList.Clear(); //舊值 ParameterList.Add(Dt.Rows[0]["ID"]); ParameterList.Add(Dt.Rows[0]["CODE"]); ParameterList.Add(Dt.Rows[0]["NAME"]); ParameterList.Add(Dt.Rows[0]["CREATEDATE"]); ParameterList.Add(Dt.Rows[0]["CREATEUID"]); ParameterList.Add(Dt.Rows[0]["UPDATEDATE"]); ParameterList.Add(Dt.Rows[0]["UPDATEUID"]); ParameterList.Add(Dt.Rows[0]["ENABLE"]); ParameterList.Add(Dt.Rows[0]["USERCODE"]); ParameterList.Add(Dt.Rows[0]["ROLECODE"]); //需要更新值 ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); #endregion SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConnectionDB); DeleteRecord = BCO.DeleteUserRoleRel(ParameterList, null); if (DeleteRecord == 0) { throw new Exception("刪除失敗!"); } else { Response.Write("<script>alert('刪除完成');location.replace('SYS051.aspx?Code=SYS05');</script>"); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
}//end EditCancelButton_Click /// <summary> /// 編輯模式,按下更新確認鈕 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void EditCommitButton_Click(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; int UpdateRecord = 0; #region 取得畫面元件的值 string v_Name = ""; DateTime processtime = DateTime.Now; string v_UserCode = ((WUI.SLP.User)this.FormView1.FindControl("TextBoxUserCode")).Text; string v_RoleCode = ((WUI.SLP.Role)this.FormView1.FindControl("TextBoxRoleCode")).Text; ParameterList.Clear(); SYSModel.MaintainProgram Uniq = new SYSModel.MaintainProgram(ConnectionDB); ParameterList.Add(v_UserCode); ParameterList.Add("SYS_USERROLEREL"); ParameterList.Add("USERCODE"); ParameterList.Add(""); #endregion #region 取得更新前舊值 #region 使用XML轉回DataSet DataSet Ds = new DataSet(); DataTable Dt = dt_Result; #endregion if (Dt.Rows.Count == 0) { throw new Exception("抓取不到舊值,更新失敗!"); } #endregion #region 加入更新條件 ParameterList.Clear(); //舊值 ParameterList.Add(Dt.Rows[0]["ID"]); ParameterList.Add(Dt.Rows[0]["CODE"]); ParameterList.Add(Dt.Rows[0]["NAME"]); ParameterList.Add(Dt.Rows[0]["CREATEDATE"]); ParameterList.Add(Dt.Rows[0]["CREATEUID"]); ParameterList.Add(Dt.Rows[0]["UPDATEDATE"]); ParameterList.Add(Dt.Rows[0]["UPDATEUID"]); ParameterList.Add(Dt.Rows[0]["ENABLE"]); ParameterList.Add(Dt.Rows[0]["USERCODE"]); ParameterList.Add(Dt.Rows[0]["ROLECODE"]); //需要更新值 ParameterList.Add(v_Name); ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(v_UserCode); ParameterList.Add(v_RoleCode); #endregion SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConnectionDB); UpdateRecord = BCO.UpdateUserRoleRel(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新0筆資料!"); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "SYS052", "<script>alert('更改完成');</script>"); ChangeFormMode(FormViewMode.ReadOnly); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
}//end InsertCancelButton_Click /// <summary> /// 由新增模式,確認新增 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void InsertButton_Click(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; int AddRecord = 0; try { #region 取得畫面元件的值 DateTime processtime = DateTime.Now; string v_UserCode = ((WUI.SLP.User)this.FormView1.FindControl("TextBoxUserCode")).Text; string v_RoleCode = ((WUI.SLP.Role)this.FormView1.FindControl("TextBoxRoleCode")).Text; //TextBox rolename = ((TextBox)this.FormView1.FindControl("TextBoxRoleCode").FindControl("TextBoxName")); string v_RoleName = ""; SYSModel.MaintainUser BCO1 = new SYSModel.MaintainUser(ConnectionDB); ParameterList.Clear(); ParameterList.Add(v_UserCode); DataTable Chkuser = BCO1.QueryUserByCode(ParameterList); if (Chkuser.Rows.Count != 1) { ErrorMsgLabel.Text = "請輸入正確人員代號"; return; } SYSModel.MaintainRole BCO2 = new SYSModel.MaintainRole(ConnectionDB); ParameterList.Clear(); ParameterList.Add(v_RoleCode); DataTable Chkrole = BCO2.QueryRoleByCode(ParameterList); if (Chkrole.Rows.Count != 1) { ErrorMsgLabel.Text = "請輸入正確角色代號"; return; } else { v_RoleName = Chkrole.Rows[0]["NAME"].ToString(); } ParameterList.Clear(); SYSModel.MaintainProgram Uniq = new SYSModel.MaintainProgram(ConnectionDB); ParameterList.Add(v_UserCode); ParameterList.Add("SYS_USERROLEREL"); ParameterList.Add("USERCODE"); ParameterList.Add(""); DataTable Dup = Uniq.QuerySwitch(SYSModel.MaintainProgram.QueryType.Duplicate, ParameterList ); if (Dup.Rows.Count > 0) { if (Dup.Rows[0]["ENABLE"].ToString() == "1") { throw new Exception("人員已存在角色關連!"); } } #endregion #region 加入輸入條件 ParameterList.Clear(); ParameterList.Add("");//ParameterList.Add(v_Code); ParameterList.Add(v_RoleName);//ParameterList.Add(v_Name); ParameterList.Add(processtime); //vCreateDate ParameterList.Add(Session["UID"].ToString()); //vCreateUID ParameterList.Add(processtime); //vUpdateDate ParameterList.Add(Session["UID"].ToString()); //vUpdateUID ParameterList.Add(v_UserCode); ParameterList.Add(v_RoleCode); #endregion SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConnectionDB); AddRecord = BCO.CreateUserRoleRel(ParameterList, null); if (AddRecord == 0) { throw new Exception("新增0筆資料!"); } else { Response.Write("<script>alert('新增完成');location.replace('SYS052.aspx?mode=readonly&ID=" + AddRecord + "');</script>"); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
private void Loaddata(string NewCode) { SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConnectionDB); ParameterList.Clear(); ParameterList.Add(NewCode); DataTable Dt = BCO.QueryUserRoleRelByID(ParameterList); if (Dt != null) { if (Dt.Rows.Count == 0) { ArrayList AL = (ArrayList)Session["SYS05_SortKey" + Request.QueryString["SYS052_PageTimeStamp"]]; string strRemove = "id=" + NewCode; AL.Remove(strRemove); Session["SYS05_SortKey" + Request.QueryString["SYS052_PageTimeStamp"]] = AL; throw new Exception("此筆資料已被其他使用者刪除,請點選上一筆/下一筆鈕或回查詢頁重新查詢!"); } } }
/// <summary> /// 繫結資料 /// </summary> /// <param name=VirtualDataID></param> private void databind(FormViewMode fvm) { try { SYSModel.MaintainUserRoleRel BCO = new SYSModel.MaintainUserRoleRel(ConnectionDB); ParameterList.Clear(); if (Request["ID"] != null) ParameterList.Add(Request["ID"].ToString()); else ParameterList.Add("0"); dt_Result = BCO.QuerySwitch(SYSModel.MaintainUserRoleRel.QueryType.ID, ParameterList ); if (dt_Result.Rows.Count > 0) { this.hiddenID.Value = dt_Result.Rows[0]["ID"].ToString(); FormView1.DataSource = dt_Result; FormView1.DataBind(); if (dt_Result.Rows[0]["ENABLE"].ToString() == "0") { ((Button)FormView1.FindControl("EditButton")).Visible = false; ((Button)FormView1.FindControl("DeleteButton")).Visible = false; } } AuthorityControls(this); //ToolBarStatus switch (fvm) { case FormViewMode.Edit: ToolBarStatus("edit"); break; case FormViewMode.Insert: ToolBarStatus("insert"); break; case FormViewMode.ReadOnly: ToolBarStatus("readonly"); break; } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }//databind