代码拉取完成,页面将自动刷新
using Entites;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using vivo_tools_Libraries;
namespace vivo_tools_3
{
public partial class AddUserForm : UIForm
{
public AddUserForm()
{
InitializeComponent();
this.Text = "注册用户";
this.lb_uname.Text = "用户名不能为空";
this.lb_upwd.Text = "密码不能为空";
this.lb_upwd_2.Text = "重复密码不能为空";
this.lb_uimage.Text = "请选择头像";
//this.label1.Visible = false;
}
private void ub_save_Click(object sender, EventArgs e)
{
if (tb_uname.Text == null || tb_uname.Text == "")
{
ShowInfoDialog("提示", "用户名不能为空!", this.Style);
}
else if (tb_upwd.Text == null || tb_upwd.Text == "")
{
ShowInfoDialog("提示", "密码不能为空!", this.Style);
}
else if (tb_upwd.Text.Length < 6 || tb_upwd.Text.Length > 16)
{
ShowInfoDialog("提示", "密码长度6-16位数!", this.Style);
}
else if (tb_upwd_2.Text == null || tb_upwd_2.Text == "")
{
ShowInfoDialog("提示", "重复密码不能为空!", this.Style);
}
else if (tb_upwd_2.Text != tb_upwd.Text)
{
ShowInfoDialog("提示", "重复密码不一致!", this.Style);
}
else
{
int num = DataBase.AddUsers(tb_uname.Text.Trim(), this.tb_upwd_2.Text.Trim(), this.uimage);
if (num > 0)
{
ShowInfoDialog("提示", "保存成功!", this.Style);
this.Close();
}
else
{
ShowInfoDialog("提示", "保存失败!", this.Style);
}
}
}
private void lb_uname_TextChanged(object sender, EventArgs e)
{
if (this.lb_uname.Text == "用户名可以使用")
{
this.lb_uname.ForeColor = Color.DarkGreen;
}
else
{
this.lb_uname.ForeColor = Color.IndianRed;
}
}
private void lb_upwd_TextChanged(object sender, EventArgs e)
{
if (this.lb_upwd.Text == "密码符合规定")
{
this.lb_upwd.ForeColor = Color.DarkGreen;
}
else
{
this.lb_upwd.ForeColor = Color.IndianRed;
}
}
private void lb_upwd_2_TextChanged(object sender, EventArgs e)
{
if (this.lb_upwd_2.Text == "密码一致")
{
this.lb_upwd_2.ForeColor = Color.DarkGreen;
}
else
{
this.lb_upwd_2.ForeColor = Color.IndianRed;
}
}
private void tb_uname_TextChanged(object sender, EventArgs e)
{
if (tb_uname.Text.Trim() != null && tb_uname.Text.Trim() != "")
{
v_Users users = DataBase.GetUserByUname(tb_uname.Text);
if (users != null)
{
if (users.Uname == null || users.Uname == "" || users.Uname != tb_uname.Text)
{
this.lb_uname.Text = "用户名可以使用";
}
else
{
this.lb_uname.Text = "用户名已被占用,请换一个试试";
}
}
else
{
this.lb_uname.Text = "用户名可以使用";
}
}
else
{
this.lb_uname.Text = "用户名不能为空";
}
}
private void tb_upwd_TextChanged(object sender, EventArgs e)
{
if (tb_upwd.Text.Trim() != null && tb_upwd.Text.Trim() != "")
{
if (tb_upwd.Text.Length < 6 || tb_upwd.Text.Length > 16)
{
this.lb_upwd.Text = "密码长度必须6-16位数";
}
else
{
this.lb_upwd.Text = "密码符合规定";
}
}
else
{
this.lb_upwd.Text = "密码不能为空";
}
}
private void tb_upwd_2_TextChanged(object sender, EventArgs e)
{
if (tb_upwd_2.Text != tb_upwd.Text)
{
this.lb_upwd_2.Text = "重复密码不一致";
}
else
{
this.lb_upwd_2.Text = "密码一致";
}
}
private void lb_uimage_TextChanged(object sender, EventArgs e)
{
if (this.lb_uimage.Text == "已选择头像")
{
this.lb_uimage.ForeColor = Color.DarkGreen;
}
else
{
this.lb_uimage.ForeColor = Color.IndianRed;
}
}
private string uimage = "";
private void pictureBox1_Click(object sender, EventArgs e)
{
OpenFileDialog opg = new OpenFileDialog();
opg.Title = "请选择需要上传的头像:";
opg.Filter = "图像文件(jpg, gif, bmp, png...)|*.jpg; *.jpeg; *.gif; *.bmp; *.tif; *.tiff; *.png| JPeg 图像文件(*.jpg;*.jpeg)"
+ "|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)"
+ "| *.png |所有文件(*.*)|*.*";
if (opg.ShowDialog() == DialogResult.OK)
{
string filename = opg.FileName;//获取要上传的图片
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);//将图片读入流中
byte[] imagebytes = new byte[fs.Length];//二进制数组,用以临时存储图像的二进制编码
BinaryReader br = new BinaryReader(fs);//二进制读取器
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));//将图片读入到二进制数组中
String str = imagebytes.ToBase64String();// UTF8代码页的编码 byte[]数组转换
Console.WriteLine(str);
uimage = str;
MemoryStream ms = new MemoryStream(imagebytes, 0, imagebytes.Length);
ms.Write(imagebytes, 0, imagebytes.Length);
pictureBox1.BackgroundImage = Image.FromStream(ms);
}
else
{
uimage = "";
pictureBox1.BackgroundImage = null;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics,
this.pictureBox1.ClientRectangle,
Color.FromArgb(200, 200, 200, 200), //左
1,
ButtonBorderStyle.Solid,
Color.FromArgb(200, 200, 200, 200),//上
1,
ButtonBorderStyle.Solid,
Color.FromArgb(200, 200, 200, 200),//右
1,
ButtonBorderStyle.Solid,
Color.FromArgb(200, 200, 200, 200),//下
1,
ButtonBorderStyle.Solid);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。