1 Star 2 Fork 0

轮回/vivo-tools-3

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
UserForm.cs 9.92 KB
一键复制 编辑 原始数据 按行查看 历史
轮回 提交于 2022-04-27 10:26 . 更新3.0.0beta5
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 UserForm : UIForm
{
private string uname;
private UIToolTip tt = null;
public UserForm(string uname)
{
InitializeComponent();
this.Text = uname + "的信息";
this.uname = uname;
this.label4.Visible = false;
this.label5.Visible = false;
this.tb_upwd_2.Visible = false;
this.tb_newupwd.Visible = false;
this.ub_save.Visible = false;
this.label6.Visible = false;
tt = new UIToolTip();
tt.SetToolTip(pictureBox1, "点击更换头像");
}
public UserForm(v_Users users)
{
InitializeComponent();
this.users = users;
this.Text = users.Uname + "的信息";
this.label4.Visible = false;
this.label5.Visible = false;
this.tb_upwd_2.Visible = false;
this.tb_newupwd.Visible = false;
this.ub_save.Visible = false;
this.label6.Visible = false;
tt = new UIToolTip();
tt.SetToolTip(pictureBox1, "点击更换头像");
}
private v_Users users;
private void Users_Form_Load(object sender, EventArgs e)
{
if (users == null)
{
users = DataBase.GetUserByUname(uname);
}
if (users != null)
{
this.tb_id.Text = users.Uid.ToString();
this.tb_uname.Text = users.Uname;
this.tb_upwd.Text = users.Upwd;
if (users.Uimage != null && users.Uimage != "")
{
if (users.Uimage.Length < 3)
{
Image m = (Image)Properties.UsersImage.ResourceManager.GetObject(users.Uimage);
//Properties.Resource1.ResourceManager.GetObject("");
this.pictureBox1.BackgroundImage = m;
}
else
{
byte[] imagebytes = users.Uimage.ToBase64Bytes();
MemoryStream ms = new MemoryStream(imagebytes, 0, imagebytes.Length);
ms.Write(imagebytes, 0, imagebytes.Length);
Image img = Image.FromStream(ms);
pictureBox1.BackgroundImage = img;
}
}
else
{
this.pictureBox1.BackgroundImage = null;
}
}
}
string Dothings;
private void ub_edit_pwd_Click(object sender, EventArgs e)
{
Dothings = "editpwd";
this.tb_upwd_2.Clear();
this.tb_newupwd.Clear();
this.label4.Visible = true;
this.label5.Visible = true;
this.tb_upwd_2.Visible = true;
this.tb_newupwd.Visible = true;
this.ub_save.Visible = true;
this.tb_upwd_2.Focus();
this.tb_upwd_2.SelectAll();
this.ub_save.Text = "保存";
}
private void ub_exit_Click(object sender, EventArgs e)
{
Dothings = "exit";
this.tb_upwd_2.Clear();
this.tb_newupwd.Clear();
this.label4.Visible = true;
this.tb_upwd_2.Visible = true;
this.tb_upwd_2.Focus();
this.tb_upwd_2.SelectAll();
this.label5.Visible = false;
this.tb_newupwd.Visible = false;
this.ub_save.Visible = true;
this.ub_save.Text = "确定";
}
private void ub_save_Click(object sender, EventArgs e)
{
//setOK = 1;
if (Dothings == "editpwd")
{
if (tb_upwd_2.Text != tb_upwd.Text)
{
ShowInfoDialog("提示", "重复密码不一致!", this.Style);
}
else if (tb_newupwd.Text == null || tb_newupwd.Text == "")
{
ShowInfoDialog("提示", "新密码不能为空!", this.Style);
}
else if (tb_upwd.Text == tb_newupwd.Text)
{
ShowInfoDialog("提示", "新旧密码不能一致", this.Style);
}
else
{
v_Users users = new v_Users(Int32.Parse(tb_id.Text), tb_uname.Text, tb_newupwd.Text);
int num = DataBase.EditUpwd(users);
if (num > 0)
{
ShowInfoDialog("提示", "修改成功!", this.Style);
this.Close();
}
else
{
ShowInfoDialog("提示", "修改失败!", this.Style);
}
}
}
else if (Dothings == "exit")
{
if (tb_upwd_2.Text != tb_upwd.Text)
{
ShowInfoDialog("提示", "重复密码不一致!", this.Style);
}
else
{
setOK = 1;
this.Close();
}
}
}
public int setOK = 0;
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);
users.Uimage = str;
int num = DataBase.EditUimage(users);
if (num > 0)
{
ShowInfoDialog("提示", "修改成功", this.Style);
MemoryStream ms = new MemoryStream(imagebytes, 0, imagebytes.Length);
ms.Write(imagebytes, 0, imagebytes.Length);
Image img = Image.FromStream(ms);
pictureBox1.BackgroundImage = img;
}
else
{
ShowErrorDialog("提示", "修改失败", this.Style);
}
}
}
private void UserForm_UIStyleChanged(object sender, EventArgs e)
{
if (TitleColor.R * 0.299 + TitleColor.G * 0.578 + TitleColor.B * 0.114 >= 192)
{
this.TitleForeColor = Color.FromArgb(96, 98, 102);
this.ControlBoxForeColor = Color.FromArgb(96, 98, 102);
this.ub_save.ForeColor = Color.FromArgb(96, 98, 102);
this.ub_exit.ForeColor = Color.FromArgb(96, 98, 102);
this.ub_edit_pwd.ForeColor = Color.FromArgb(96, 98, 102);
}
else
{
this.TitleForeColor = Color.White;
this.ControlBoxForeColor = Color.White;
this.ub_save.ForeColor = Color.White;
this.ub_exit.ForeColor = Color.White;
this.ub_edit_pwd.ForeColor = Color.White;
}
}
private void pictureBox1_MouseHover(object sender, EventArgs e)
{
this.label6.Visible = true;
pictureBox1.BackColor = Color.FromArgb(200, 200, 200);
}
private void pictureBox1_MouseLeave(object sender, EventArgs e)
{
this.label6.Visible = false;
pictureBox1.BackColor = Color.Transparent;
}
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);
}
private void pictureBox1_BackColorChanged(object sender, EventArgs e)
{
label6.BackColor = pictureBox1.BackColor;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/PeopleCarWorld/vivo-tools-3.git
[email protected]:PeopleCarWorld/vivo-tools-3.git
PeopleCarWorld
vivo-tools-3
vivo-tools-3
master

搜索帮助