using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using static Org.BouncyCastle.Math.EC.ECCurve; namespace GeBoShi.UI.User { public partial class NewRoleFrm : Form { RoleService _Service = new RoleService(); Role _Role = new Role(); User _FatherUser; public NewRoleFrm(User fatherUser, Role m = null) { InitializeComponent(); this.uiTitel1.ShowContrlBox(false, false, true); this.uiTitel1.FatherForm = this; _FatherUser = fatherUser; if (m != null) { _Role = m; this.txtCode.Enabled = false; } } private void InitDataView() { this.txtCode.Text = _Role.Code; this.txtName.Text = _Role.Name; this.log.Text = ""; } private void NewRoleFrm_Load(object sender, EventArgs e) { InitDataView(); } private void btnSave_Click(object sender, EventArgs e) { try { string szCode = this.txtCode.Text.Trim(); string szName = this.txtName.Text.Trim(); if (szCode == "" || szName == "") { this.log.Text = "请填写编号和名称!"; return; } _Role.Code = szCode; _Role.Name = szName; _Role.ModifyUserCode = _FatherUser.Code; bool result; if (_Role.Id == 0) { _Role.CreateUserCode = _FatherUser.Code; result = _Service.Insert(_Role); } else result = _Service.Update(_Role); if (!result) throw new Exception("保存失败!"); MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } } }