89 lines
3.6 KiB
C#
89 lines
3.6 KiB
C#
using Common.Models.UnqTables;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Server.Winforms
|
|
{
|
|
public partial class SetDefaultuserForm : DefaultForm
|
|
{
|
|
public SetDefaultuserForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
public Staff AdminEntity;
|
|
public Role RoleEntity;
|
|
private void SetDefaultUser_Load(object sender, EventArgs e)
|
|
{
|
|
RoleEntity = Client.SingleClient.Db.Queryable<Role>().Where(f => f.Name == "超级管理员").First();
|
|
|
|
|
|
AdminEntity = Client.SingleClient.Db.Queryable<Staff>().Where(f =>f.IsCreator == true).First();
|
|
if (AdminEntity != null)
|
|
{
|
|
this.textBox1.Text = AdminEntity.Username;
|
|
}
|
|
}
|
|
|
|
//List<string> roles = new List<string>() { "Anlyze", "Data", "Tools", "Artificial", "Qunfa", "Social", "Account", "Lianmeng", "Robot", "Staff", "Member", "Grouping", "WechatUser", "Fans", "Blacklist", "Reminder", "Func", "Pub", "Base", "Rebate", "Feed", "Keywords", "Order", "TbOrder", "JdOrder", "DyOrder", "MtOrder", "SnOrder", "WphOrder", "PddOrder", "Financial", "CashList", "PayRecord", "IntegralRecord", "Help", "RunLog", "QA", "Guide", "About"};
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
if (string.IsNullOrEmpty(this.textBox1.Text) || string.IsNullOrEmpty(this.textBox2.Text) || string.IsNullOrEmpty(this.textBox3.Text))
|
|
{
|
|
MessageBox.Show("操作失败,用户名或密码为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
else if (this.textBox2.Text != this.textBox3.Text)
|
|
{
|
|
MessageBox.Show("操作失败,两次密码输入的不一致", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
else
|
|
{
|
|
|
|
|
|
|
|
//修改了用户名,就检查下用户名是否存在
|
|
if (AdminEntity != null && AdminEntity.Username != this.textBox1.Text)
|
|
{
|
|
var v = Client.SingleClient.Db.Queryable<Staff>().Where(f => f.Username == this.textBox1.Text).First();
|
|
if (v != null)
|
|
{
|
|
MessageBox.Show("操作失败,该用户名已存在请修改后重试", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
return;
|
|
}
|
|
}
|
|
//MD5加密
|
|
var password = Common.Utils.Util.GetMd5(this.textBox2.Text);
|
|
if (AdminEntity == null)
|
|
{
|
|
AdminEntity = new Staff();
|
|
AdminEntity.IsCreator = true;
|
|
AdminEntity.Username = this.textBox1.Text;
|
|
AdminEntity.Password = password;
|
|
AdminEntity.RoleId = RoleEntity.Id;
|
|
AdminEntity.IsCreator = true;
|
|
Client.SingleClient.Db.Insertable(AdminEntity).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
AdminEntity.IsCreator = true;
|
|
AdminEntity.Username = this.textBox1.Text;
|
|
AdminEntity.Password = password;
|
|
Client.SingleClient.Db.Updateable(AdminEntity).ExecuteCommand();
|
|
}
|
|
|
|
|
|
this.DialogResult = DialogResult.Yes;
|
|
this.Close();
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|