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.Windows.Forms; namespace NXWMS.Forms.Base.ChildFrm { public partial class FrmSupplierEdit : KryptonForm { private int _id; public EnumOperation operation { get; set; } public int Id { get => _id; set => _id = value; } public FrmSupplierEdit() { InitializeComponent(); } public void InitControl() { //TODO 0805 以下所有配置都需要从数据库或者其它地方读取,这里暂时写死,后期加上配置表,联动查询 var fieldList = new List().GetFieldValueCodeList(); cmbSupplierType.DataSource = fieldList; cmbSupplierType.DisplayMember = "Name"; cmbSupplierType.ValueMember = "Code"; cmbSupplierType.SelectedIndex = -1; fieldList = new List(); fieldList.Add(new FieldValue { Code = "江苏省", Name = "江苏省" }); cmbProvince.DataSource = fieldList; cmbProvince.DisplayMember = "Name"; cmbProvince.ValueMember = "Code"; cmbProvince.SelectedIndex = -1; fieldList = new List(); fieldList.Add(new FieldValue { Code = "无锡市", Name = "无锡市" }); cmbCity.DataSource = fieldList; cmbCity.DisplayMember = "Name"; cmbCity.ValueMember = "Code"; cmbCity.SelectedIndex = -1; fieldList = new List(); fieldList.Add(new FieldValue { Code = "锡山区", Name = "锡山区" }); cmbArea.DataSource = fieldList; cmbArea.DisplayMember = "Name"; cmbArea.ValueMember = "Code"; cmbArea.SelectedIndex = -1; } private void FrmSupplierEdit_Shown(object sender, EventArgs e) { } private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtSupplierCode.Text)) { KryptonMessageBox.Show($"请输入客户编码!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (operation) { case EnumOperation.Add: var addResult = BaseServices.supplierService.Add(new SupplierCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, IsUsed = chkUse.Checked, SupplierType = cmbSupplierType.SelectedValue == null ? "" : cmbSupplierType.SelectedValue.ToString(), Describe = richDescibe.Text, Address = txtAddress.Text, Area = cmbArea.Text, City = cmbCity.Text, Contract = txtContract.Text, ContractPhone = txtContractPhone.Text, SupplierCode = txtSupplierCode.Text, SupplierName = txtSupplierName.Text, PostalCode = txtPostalCode.Text, Province = cmbProvince.Text, Route = txtRoute.Text, Street = cmbStreet.Text, }); 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.supplierService.Edit(new SupplierCondition { OperationUserId = AppConfig.UserLoginResult.UserInfo.UserId, IsUsed = chkUse.Checked, SupplierType = cmbSupplierType.SelectedValue == null ? "" : cmbSupplierType.SelectedValue.ToString(), Describe = richDescibe.Text, Address = txtAddress.Text, Area = cmbArea.Text, City = cmbCity.Text, Contract = txtContract.Text, ContractPhone = txtContractPhone.Text, SupplierCode = txtSupplierCode.Text, SupplierName = txtSupplierName.Text, PostalCode = txtPostalCode.Text, Province = cmbProvince.Text, Route = txtRoute.Text, Street = cmbStreet.Text, 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; } } private void btnExit_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.Cancel; } } }