protected void Btn_Save_Click(object sender, EventArgs e) { try { //取得登入user資料 databind(); #region 取得畫面元件的值 //新密碼 = 登入者帳號 DateTime processtime = DateTime.Now; //密碼解密 SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); string UserPwd = Cry.Decrypt(dt_Result.Rows[0]["PASSWORD"].ToString()); #endregion if (TextBoxOldPassword.Text != UserPwd) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('舊密碼不正確');", true); } else if (TextBoxNewPassword.Text != TextBoxConfirmNewPassword.Text) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('新密碼與確認新密碼不一致');", true); } else if (TextBoxNewPassword.Text.Length < 8) { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('新密碼不可小於8碼');", true); } else { //密碼加密 string CryPassword = Cry.Encrypt(TextBoxNewPassword.Text); #region 加入更新條件 ParameterList.Clear(); //舊值 ParameterList.Add(dt_Result.Rows[0]["ID"]); ParameterList.Add(dt_Result.Rows[0]["CODE"]); ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(dt_Result.Rows[0]["CREATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["CREATEUID"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEUID"]); ParameterList.Add(dt_Result.Rows[0]["ENABLE"]); ParameterList.Add(dt_Result.Rows[0]["PASSWORD"]); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); //需要更新值 ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(CryPassword); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); #endregion SYSModel.MaintainUser BCO = new SYSModel.MaintainUser(ConnectionDB); int UpdateRecord = BCO.UpdateUser(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新0筆資料!"); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('更改完成');", true); } } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
/// <summary> /// 複製鈕 帶入新增資料 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void FormView1_DataBound(object sender, EventArgs e) { //密碼解密 if (FormView1.CurrentMode == FormViewMode.Edit)// || FormView1.CurrentMode == FormViewMode.ReadOnly) { SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); ((TextBox)FormView1.FindControl("TextBoxPassword")).Text = Cry.Decrypt(((TextBox)FormView1.FindControl("TextBoxPassword")).Text); } }
protected void btnExport_Click(object sender, EventArgs e) { try { ErrorMsgLabel.Text = ""; DataTable Dt; #region 檢查是否已匯入檔案 if (Session["SYS203_" + PageTimeStamp.Value] != null) { Dt = (DataTable)Session["SYS203_" + PageTimeStamp.Value]; } else { throw new Exception("請先匯入檔案"); } #endregion string strPassword = string.Empty; string strCryPassword = string.Empty; SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); SYSModel.MaintainUser BCO2 = new SYSModel.MaintainUser(ConnectionDB); for (int i = 0; i < Dt.Rows.Count; i++) { strPassword = Dt.Rows[i][0].ToString(); strCryPassword = Cry.Encrypt(strPassword); ParameterList.Clear(); ParameterList.Add(strPassword); dt_Result = BCO2.QuerySwitch(SYSModel.MaintainUser.QueryType.CODE, ParameterList ); ParameterList.Clear(); //舊值 ParameterList.Add(dt_Result.Rows[0]["ID"]); ParameterList.Add(dt_Result.Rows[0]["CODE"]); ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(dt_Result.Rows[0]["CREATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["CREATEUID"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEUID"]); ParameterList.Add(dt_Result.Rows[0]["ENABLE"]); ParameterList.Add(dt_Result.Rows[0]["PASSWORD"]); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); //需要更新值 DateTime processtime = DateTime.Now; ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(strCryPassword); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); int UpdateRecord = 0; UpdateRecord = BCO2.UpdateUser(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新失敗!"); } //UpdateExcelRecords(strPassword, strCryPassword.Trim()); } this.ErrorMsgLabel.Text = "匯入完成!"; //DownLoadFile(); } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
protected void Btn_Save_Click(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; int UpdateRecord = 0; try { //取得登入user資料 databind(); if (dt_Result.Rows.Count == 0) { throw new Exception("讀取不到使用者,更新失敗!"); } #region 取得畫面元件的值 //新密碼 = 登入者帳號 DateTime processtime = DateTime.Now; string v_Password = TextBoxCode.Text; //密碼加密 SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); string CryPassword = Cry.Encrypt(v_Password); #endregion #region 加入更新條件 ParameterList.Clear(); //舊值 ParameterList.Add(dt_Result.Rows[0]["ID"]); ParameterList.Add(dt_Result.Rows[0]["CODE"]); ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(dt_Result.Rows[0]["CREATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["CREATEUID"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEDATE"]); ParameterList.Add(dt_Result.Rows[0]["UPDATEUID"]); ParameterList.Add(dt_Result.Rows[0]["ENABLE"]); ParameterList.Add(dt_Result.Rows[0]["PASSWORD"]); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); //需要更新值 ParameterList.Add(dt_Result.Rows[0]["NAME"]); ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(CryPassword); ParameterList.Add(dt_Result.Rows[0]["MEMO"]); #endregion SYSModel.MaintainUser BCO = new SYSModel.MaintainUser(ConnectionDB); UpdateRecord = BCO.UpdateUser(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新0筆資料!"); } else { ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "ClientScript", "alert('更改完成');", true); } } 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 = ((TextBox)FormView1.FindControl("TextBoxName")).Text.Trim(); DateTime processtime = DateTime.Now; string v_Memo = ((TextBox)FormView1.FindControl("TextBoxMemo")).Text.Trim(); string v_Password = ((TextBox)FormView1.FindControl("TextBoxPassword")).Text.Trim(); if (v_Password.Length <8) throw new Exception("密碼長度不足8碼!"); //密碼加密 SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); string CryPassword = Cry.Encrypt(v_Password); #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]["PASSWORD"]); ParameterList.Add(Dt.Rows[0]["MEMO"]); //需要更新值 ParameterList.Add(v_Name); ParameterList.Add(processtime); ParameterList.Add(Session["UID"].ToString()); ParameterList.Add(CryPassword); ParameterList.Add(v_Memo); #endregion SYSModel.MaintainUser BCO = new SYSModel.MaintainUser(ConnectionDB); UpdateRecord = BCO.UpdateUser(ParameterList, null); if (UpdateRecord == 0) { throw new Exception("更新0筆資料!"); } else { LogHelper LOG = new LogHelper(ConnectionDB); ParameterList.Clear(); ParameterList.Add("SYS04人員");//0 ParameterList.Add(Session["UID"].ToString());//1 ParameterList.Add("U");//2 ParameterList.Add(Dt.Rows[0]["CODE"].ToString());//3 ParameterList.Add(Request.ServerVariables["Server_Name"]);//4 LOG.AddSafeLog(ParameterList); //ScriptManager.RegisterStartupScript(this.up_Msg, typeof(UpdatePanel), "SYS042", string.Format("<script>alert('更改完成');location.replace('SYS042.aspx?mode=readonly&ID={0}');</script>", Dt.Rows[0]["ID"].ToString()),false); Response.Write(string.Format("<script>alert('更改完成');location.replace('SYS042.aspx?mode=readonly&ID={0}');</script>", Dt.Rows[0]["ID"].ToString())); } } 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) { try { int AddRecord = 0; ErrorMsgLabel.Text = ""; #region 取得畫面元件的值 string v_Code = ((WUI.SLP.SLPUnique)FormView1.FindControl("TextBoxCode")).Text.Trim(); string v_Name = ((TextBox)FormView1.FindControl("TextBoxName")).Text.Trim(); DateTime processtime = DateTime.Now; //string v_Organizationcode = ((WUI.SLP.Organization)FormView1.FindControl("TextBoxOrganizationCode")).Text.Trim(); string v_Password = ((TextBox)FormView1.FindControl("TextBoxPassword")).Text.Trim(); string v_Memo = ((TextBox)FormView1.FindControl("TextBoxMemo")).Text.Trim(); if (v_Password.Length < 8) throw new Exception("密碼長度不足8碼!"); //密碼加密 SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); string CryPassword = Cry.Encrypt(v_Password); ParameterList.Clear(); SYSModel.MaintainProgram Uniq = new SYSModel.MaintainProgram(ConnectionDB); ParameterList.Add(v_Code); ParameterList.Add("SYS_USER"); ParameterList.Add("CODE"); 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(v_Code); 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_Organizationcode); ParameterList.Add(CryPassword); ParameterList.Add(v_Memo); #endregion SYSModel.MaintainUser BCO = new SYSModel.MaintainUser(ConnectionDB); AddRecord = BCO.CreateUser(ParameterList, null); if (AddRecord == 0) { throw new Exception("新增0筆資料!"); } else { LogHelper LOG = new LogHelper(ConnectionDB); ParameterList.Clear(); ParameterList.Add("SYS04人員");//0 ParameterList.Add(Session["UID"].ToString());//1 ParameterList.Add("I");//2 ParameterList.Add(v_Code);//3 ParameterList.Add(Request.ServerVariables["Server_Name"]);//4 LOG.AddSafeLog(ParameterList); Response.Write("<script>alert('新增完成');location.replace('SYS042.aspx?mode=readonly&ID=" + AddRecord + "');</script>"); } } catch (Exception ex) { ErrorMsgLabel.Text = ex.Message; } }
}//end EditUserButton_Click /// <summary> /// 複製鈕 帶入新增資料 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void FormView1_DataBound(object sender, EventArgs e) { ErrorMsgLabel.Text = ""; //密碼解密 if (FormView1.CurrentMode == FormViewMode.Edit) //|| FormView1.CurrentMode == FormViewMode.ReadOnly) { try { SYSModel.CryptographyHelper Cry = new SYSModel.CryptographyHelper(); ((TextBox)FormView1.FindControl("TextBoxPassword")).Text = Cry.Decrypt(((TextBox)FormView1.FindControl("TextBoxPassword")).Text); } catch (Exception ex) { // 如果不是用加密insert資料 檢視時不解密 } } }