using ComponentFactory.Krypton.Toolkit; using NXWMS.Client.Model.AppModels.Condition.Base; 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.Web.UI.WebControls; using System.Windows.Forms; namespace NXWMS.Forms.Base.ChildFrm { public partial class FrmUitEdit : KryptonForm { public FrmUitEdit() { InitializeComponent(); } private int _id; public EnumOperation operation { get; set; } public int Id { get => _id; set => _id = value; } private void btnExit_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } public void InitControl() { var fieldList = new List().GetFieldValueCodeList(); cmbUnitType.DataSource = fieldList; cmbUnitType.DisplayMember = "Name"; cmbUnitType.ValueMember = "Code"; cmbUnitType.SelectedIndex = -1; } private void FrmUitEdit_Shown(object sender, EventArgs e) { } private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtUnitCode.Text)) { KryptonMessageBox.Show($"请输入单位编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrWhiteSpace(cmbUnitType.Text)) { KryptonMessageBox.Show($"请选择单位类型!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (operation) { case EnumOperation.Add: var addResult = BaseServices.unitService.Add(new UnitCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, IsUsed = chkUse.Checked, Describe = richDescibe.Text, UnitCode = txtUnitCode.Text, UnitName = txtUnitName.Text, UnitType = cmbUnitType.SelectedValue == null ? "" : cmbUnitType.SelectedValue.ToString(), }); ; if (addResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); InitControl(); groupOperation.Visible = false; this.DialogResult = DialogResult.OK; } else { KryptonMessageBox.Show($"操作失败!\r\n{addResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case EnumOperation.Edit: var editResult = BaseServices.unitService.Edit(new UnitCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, IsUsed = chkUse.Checked, Describe = richDescibe.Text, UnitCode = txtUnitCode.Text, UnitName = txtUnitName.Text, UnitType = cmbUnitType.SelectedValue == null ? "" : cmbUnitType.SelectedValue.ToString(), Id = Id, }); if (editResult.Status == OperateStatus.Success) { KryptonMessageBox.Show($"操作成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); InitControl(); groupOperation.Visible = false; this.DialogResult = DialogResult.OK; } else { KryptonMessageBox.Show($"操作失败!\r\n{editResult.Message}", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; } } } }