protected void Btn_AddUser_Click(object sender, EventArgs e) { if (TB_UserID.Text.Equals("")) ShowMessage("請輸入用戶ID!", MessagePanel, TB_UserID); else if (TB_UserPw.Text.Equals("")) ShowMessage("請輸入用戶密碼!", MessagePanel, TB_UserPw); else if (TB_UserName.Text.Equals("")) ShowMessage("請輸入用戶名稱!", MessagePanel, TB_UserName); else { String UserID = TB_UserID.Text.Trim(); String UserName = TB_UserName.Text.Trim(); String UserPW = Cryptography.MD5(TB_UserPw.Text); String UserDept = DDL_Dept.SelectedValue; String sql = "select * from rps_userinfo where user_id = '" + UserID + "'"; Database db = new Database("rpsdb", sql, Database.WebConfig); SqlDataReader reader = db.GetReader(); if (reader.HasRows) ShowMessage("用戶ID己存在!", MessagePanel, TB_UserID); else { reader.Close(); sql = "insert into rps_userinfo values (" + "'" + UserID + "', '" + UserPW + "', '" + UserName + "', '" + UserDept + "', '1900-01-01 00:00:00.000', 'T')"; db.ExecuteSql(sql); sql = "insert into rps_usermenu values ('" + UserID + "','R00')"; db.ExecuteSql(sql); sql = "insert into rps_usermenu values ('" + UserID + "','R0002')"; db.ExecuteSql(sql); String ClientScript = "alert('用戶新增成功!'); location.replace('R0101_UserMaintenance.aspx'); "; ScriptManager.RegisterClientScriptBlock(UpdatePanel1, GetType(), "Alert", ClientScript, true); } } }
protected void Button1_Click(object sender, EventArgs e) { if (TB_OldPassword.Text.Equals("")) ShowMessage("請輸入舊密碼!", MessagePanel, TB_OldPassword); else if (TB_NewPassword.Text.Equals("")) ShowMessage("請輸入新密碼!", MessagePanel, TB_NewPassword); else if (TB_ConfirmPassword.Text.Equals("")) ShowMessage("請輸入確認密碼!", MessagePanel, TB_ConfirmPassword); else if (!TB_ConfirmPassword.Text.Equals(TB_NewPassword.Text)) { ShowMessage("新密碼與確認密碼不吻合!", MessagePanel, TB_NewPassword); TB_NewPassword.Text = ""; TB_ConfirmPassword.Text = ""; } else if (!this.user.ValidatePassword(TB_OldPassword.Text)) { ShowMessage("舊密碼不正確!", MessagePanel, TB_OldPassword); } else { MessagePanel.Text = " "; try { String HashPW = Cryptography.MD5(TB_NewPassword.Text); String sql = "update rps_userinfo set user_pw = '" + HashPW + "' where user_id = '" + user.ID + "'"; Database db = new Database("rpsdb", sql, Database.WebConfig); db.ExecuteSql(sql); MessagePanel.Text = " "; TB_OldPassword.Text = ""; TB_NewPassword.Text = ""; TB_ConfirmPassword.Text = ""; String script = "alert('密碼成功更新!'); location.replace('/Main.aspx');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", script, true); } catch (Exception) { String script = "alert('密碼更新失敗!'); location.replace('/Main.aspx');"; ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ClientScript", script, true); } } }