using System; using System.Collections.Generic; using System.Windows.Forms; using System.Web.Script.Serialization; namespace 成套报价软件 { /// 修改密码对话框:调会员服务改密(校验旧密码)。 public partial class 修改密码 : Form { public 修改密码() { InitializeComponent(); this.BackColor = System.Drawing.Color.White; } private void btn确认_Click(object sender, EventArgs e) { try { if (txt新密码.Text != txt确认新密码.Text) { MessageBox.Show(this, "两次输入的新密码不一致。", "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!会员服务Host.EnsureRunning()) { MessageBox.Show(this, "会员服务连接失败,请检查服务器地址与网络。", "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string json = new JavaScriptSerializer().Serialize(new Dictionary { { "手机号", txt手机号码.Text.Trim() }, { "旧密码", txt旧密码.Text }, { "新密码", txt新密码.Text } }); var resp = new JavaScriptSerializer() .Deserialize>(会员服务Host.Post("/api/changepwd", json)); bool ok = resp.ContainsKey("ok") && Convert.ToBoolean(resp["ok"]); if (ok) { // ★改密成功=立即退出登录(用户 2026-09-26 要求):清空内存登录态, // 由主窗口紧接着弹登录窗让客户用新密码重新登录 MainForm.当前登录手机号 = ""; MainForm.当前登录密码 = ""; MainForm.当前会员类型 = ""; MainForm.当前有效期 = ""; MessageBox.Show(this, "密码修改成功,请用新密码重新登录。", "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } else { MessageBox.Show(this, "修改失败: " + (resp.ContainsKey("msg") ? Convert.ToString(resp["msg"]) : "未知错误"), "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(this, "修改密码异常: " + ex.Message, "修改密码", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }