private async void button6_Click(object sender, EventArgs e) { string userID = textBox1.Text; string password = textBox2.Text; string passwordMD5 = MD5Encrypt(password); if (userID.Length == 0 || userID == "单行输入") { DialogResult result; using (Form_Tips tip = new Form_Tips("提示", "用户ID为空,是否注册新账号")) { tip.ShowDialog(); result = tip.DialogResult; } if (result == DialogResult.Yes) { using (Form_Register reg = new Form_Register()) { this.Hide(); reg.ShowDialog(); this.Show(); } } } else { if (password.Length == 0 || password == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入密码!")) { tip.ShowDialog(); } } else { try { string url = baseUrl + "/login?Uid=" + userID + "&password="******""); if (result.IsSuccessStatusCode) { using (Form_TripNote tn = new Form_TripNote(int.Parse(userID))) { tn.changePanel = tn.AddControlsToPanel; this.Hide(); tn.ShowDialog(); textBox1.Text = ""; textBox2.Text = ""; } this.Show(); } else { using (Form_Tips tip = new Form_Tips("警告", "用户名或密码输入错误")) { tip.ShowDialog(); } } } catch (Exception e1) { using (Form_Tips tip = new Form_Tips("警告", e1.Message)) { tip.ShowDialog(); } } } } }
private async void button6_Click(object sender, EventArgs e) { if (Txtbox_name.Text.Length == 0 || Txtbox_name.Text == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入用户名!")) { tip.ShowDialog(); } } else if (TxtBox_psw.Text.Length == 0 || TxtBox_psw.Text == "单行输入") { using (Form_Tips tip = new Form_Tips("提示", "请输入密码!")) { tip.ShowDialog(); } } else { User user = new User(); XmlSerializer xmlSerializer = new XmlSerializer(typeof(User)); Client client = new Client(); string data = ""; try { string url = baseUrl + "/register"; user.Uname = Txtbox_name.Text; user.Password = MD5Encrypt(TxtBox_psw.Text); user.Sex = Cbbox_gender.Text; user.Introduction = richTextBox_introducation.Text; using (StringWriter sw = new StringWriter()) { xmlSerializer.Serialize(sw, user); data = sw.ToString(); } HttpResponseMessage result = await client.Post(url, data); if (result.IsSuccessStatusCode) { User newuser = new User(); newuser = (User)xmlSerializer.Deserialize(await result.Content.ReadAsStreamAsync()); user.Uid = int.Parse(newuser.Uid.ToString("00000")); using (Form_Tips tip = new Form_Tips("提示", "注册成功!您的ID是" + newuser.Uid.ToString("00000"))) { tip.ShowDialog(); } using (Form_TripNote tn = new Form_TripNote()) { this.Hide(); tn.ShowDialog(); this.Dispose(); } } } catch (Exception e1) { using (Form_Tips tip = new Form_Tips("警告", e1.Message)) { tip.ShowDialog(); } } } }