using HighWayIot.Repository.domain;
using HighWayIot.Repository.service;
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 HighWayIot.Winform.UserControlPages.SysConfigPages
{
public partial class UserAddForm : Form
{
///
/// 角色数据库业务实例
///
SysUserInfoService SysUserInfoService = SysUserInfoService.Instance;
public UserAddForm(string[] roleList)
{
InitializeComponent();
UserRoleComboBox.DataSource = roleList;
}
///
/// 确认添加按钮
///
///
///
private void ConfrimAddButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(UserNameTextBox.Text.Trim()))
{
MessageBox.Show("用户名编号不能为空!");
return;
}
SysUserEntity userEntity = new SysUserEntity()
{
UserName = UserNameTextBox.Text.Trim(),
Password = PasswordTextBox.Text.Trim(),
UserRole = UserRoleComboBox.SelectedText
};
var list = SysUserInfoService.GetUserInfoByUserName(UserNameTextBox.Text);
if (list.Count() != 0)
{
MessageBox.Show("不能有相同用户名!", "结果", MessageBoxButtons.OK);
return;
}
if (SysUserInfoService.InsertUserInfo(userEntity))
{
MessageBox.Show("数据添加成功!", "结果", MessageBoxButtons.OK);
}
else
{
MessageBox.Show("数据添加失败!请看日志查询失败原因", "结果", MessageBoxButtons.OK);
}
this.Close();
this.Dispose();
}
}
}