代码拉取完成,页面将自动刷新
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Entites;
using Sunny.UI;
using vivo_tools_Libraries;
namespace vivo_tools_3
{
public partial class EditUser : UIForm
{
UIToolTip tt = null;
public EditUser(v_Users users)
{
InitializeComponent();
//this.uiAvatar1.BackColor = Color.Transparent;
this.Text = "修改用户 - " + users.Uname;
this.users = users;
this.tb_id.Text = users.Uid.ToString();
this.tb_uname.Text = users.Uname.ToString();
if (users.IsAdmin == 1)
{
this.urb_y.Checked = true;
this.urb_n.Checked = false;
}
else if (users.IsAdmin == 0)
{
this.urb_y.Checked = false;
this.urb_n.Checked = true;
}
this.tb_upwd.Text = users.Upwd.ToString();
if (users.Uimage != null && users.Uimage != "")
{
if (users.Uimage.Length < 3)
{
pictureBox1.BackgroundImage = (Image)Properties.UsersImage.ResourceManager.GetObject(users.Uimage);
}
else
{
byte[] imagebytes = users.Uimage.ToBase64Bytes();
//Encoding.Default.GetBytes(users.Uimage);
MemoryStream ms = new MemoryStream(imagebytes, 0, imagebytes.Length);
ms.Write(imagebytes, 0, imagebytes.Length);
pictureBox1.BackgroundImage = Image.FromStream(ms);
}
}
else
{
pictureBox1.BackgroundImage = null;
}
tt = new UIToolTip();
tt.SetToolTip(pictureBox1, "点击更换头像");
this.label6.Visible = false;
}
private v_Users users;
private void ub_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
public int setOK = 0;
private void ub_save_Click(object sender, EventArgs e)
{
if (urb_y.Checked == true)
{
this.users.IsAdmin = 1;
}
else
{
this.users.IsAdmin = 0;
}
v_Users users = new v_Users(Int32.Parse(tb_id.Text), tb_uname.Text, tb_upwd.Text, this.users.Uimage, this.users.IsAdmin);
int num = DataBase.EditUsers(users);
if (num > 0)
{
ShowInfoDialog("提示", "修改成功!", this.Style);
setOK = 1;
this.Close();
}
else
{
ShowInfoDialog("提示", "修改失败!", this.Style);
}
}
private void EditUser_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_Cancel.ForeColor = Color.FromArgb(96, 98, 102);
}
else
{
this.TitleForeColor = Color.White;
this.ControlBoxForeColor = Color.White;
this.ub_save.ForeColor = Color.White;
this.ub_Cancel.ForeColor = Color.White;
}
this.rectColor = this.TitleColor;
}
private void uiCheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (uiCheckBox1.Checked == true)
{
this.tb_upwd.PasswordChar = default(char);
}
else
{
this.tb_upwd.PasswordChar = '●';
}
}
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;
MemoryStream ms = new MemoryStream(imagebytes, 0, imagebytes.Length);
ms.Write(imagebytes, 0, imagebytes.Length);
pictureBox1.BackgroundImage = Image.FromStream(ms);
}
}
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_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;
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。