using ComponentFactory.Krypton.Toolkit;
using NXWMS.Client.Model.AppModels.Condition;
using NXWMS.Client.Model.AppModels.Result;
using NXWMS.Client.Model.AppModels.Result.SysSettings;
using NXWMS.Client.Model.CoreModels;
using NXWMS.Client.String.Enums;
using NXWMS.Commons;
using NXWMS.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace NXWMS.Forms.SysSettings.ChildFrm
{
public partial class FrmUserEdit : KryptonForm
{
///
/// 界面最后执行操作
///
private EnumOperation _LastOperation;
private RolePermissionResult _selectRolePermission;
private int _selectId;
///
/// 客户端字段排序列表
///
private List _clientFieldOrderList;
private int _selectMainMenuIndex;
private int _selectMenuIndex;
private int _selectFunctionIndex;
///
/// 角色列表
///
private List _roleList;
public FrmUserEdit()
{
InitializeComponent();
}
public void InitControl()
{
CheckForIllegalCrossThreadCalls = false;
var fieldValueList = (from x in _roleList
select new FieldValue
{
Code = x.ROLE_CODE,
Name = x.ROLE_NAME
}).ToList();
cmbRole.DataSource = fieldValueList.Where((x, i) => fieldValueList.FindIndex(z => z.Code == x.Code) == i).ToList();
cmbRole.DisplayMember = "Name";
cmbRole.ValueMember = "Code";
cmbRole.SelectedIndex = -1;
cmbGender.DataSource = new List().GetFieldValueIdList();
cmbGender.DisplayMember = "Name";
cmbGender.ValueMember = "Id";
cmbGender.SelectedIndex = -1;
txtUserCode.SetControlBase(50);
txtUserName.SetControlBase(100);
txtNickName.SetControlBase(50);
txtIphoneNumber.SetControlBase(20);
txtJobTitle.SetControlBase(50);
txtEmail.SetControlBase(100);
txtAddress.SetControlBase(200);
}
public EnumOperation Operation { get => _LastOperation; set => _LastOperation = value; }
public int SelectId { get => _selectId; set => _selectId = value; }
public List RoleList { get => _roleList; set => _roleList = value; }
private void btnSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(txtUserCode.Text))
{
KryptonMessageBox.Show($"请输入用户编码。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(txtUserName.Text))
{
KryptonMessageBox.Show($"请输入用户名称。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (string.IsNullOrWhiteSpace(cmbGender.Text))
{
KryptonMessageBox.Show($"请选择性别。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
switch (Operation)
{
case EnumOperation.Add:
var addResult = SysSettingsServices.userService.Add(new UserCondition
{
JobTitle = txtJobTitle.Text,
NickName = txtNickName.Text,
Address = txtAddress.Text,
PhoneNumber = txtIphoneNumber.Text,
UserName = txtUserName.Text,
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
Email = txtEmail.Text,
Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
IsUsed = chkUse.Checked,
RoleCode = cmbRole.SelectedValue.GetObjectToString(),
UserCode = txtUserCode.Text,
});
if (addResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
groupOperation.Visible = false;
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
case EnumOperation.Edit:
var editResult = SysSettingsServices.userService.Edit(new UserCondition
{
JobTitle = txtJobTitle.Text.Trim(),
NickName = txtNickName.Text,
Address = txtAddress.Text,
PhoneNumber = txtIphoneNumber.Text,
UserName = txtUserName.Text,
OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId,
Email = txtEmail.Text,
Gender = cmbGender.SelectedValue.GetObjectToInt().Value,
IsUsed = chkUse.Checked,
RoleCode = cmbRole.SelectedValue.GetObjectToString(),
UserId = SelectId,
});
if (editResult.Status == OperateStatus.Success)
{
KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
groupOperation.Visible = false;
}
else
{
KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
break;
}
DialogResult = DialogResult.OK;
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}