geboshi_V1/LeatherProject/LeatherApp/UIExtend/UIDefectEdit.cs

67 lines
2.1 KiB
C#

using Models;
using Newtonsoft.Json.Linq;
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 LeatherApp.UIExtend
{
public partial class UIDefectEdit : UserControl
{
/// <summary>
/// code,name
/// </summary>
public Action<string, string> CodeChangeEvent;
private string _modelName;
public UIDefectEdit(string modelName)
{
InitializeComponent();
_modelName = modelName;
init(modelName);
}
private void init(string modelName)
{
JArray defectItemList;
Config.LoadModelDefectItemList(modelName, out defectItemList);
var list = defectItemList.Select(x => new { code = x.Value<string>("code"), name = x.Value<string>("name") }).ToList();
uiComboBox1.ValueMember = "code";
uiComboBox1.DisplayMember = "name";
uiComboBox1.DataSource = list;
}
[Description("忽略"), Category("自定义")]
public bool Checked
{
get { return this.uiCheckBox1.Checked; }
set { this.uiCheckBox1.Checked = value; }
}
[Description("瑕疵"), Category("自定义")]
public string Code
{
get { return this.uiComboBox1.SelectedValue.ToString(); }
set { this.uiComboBox1.SelectedValue = value; }
}
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string code = uiComboBox1.SelectedValue.ToString();
string name = uiComboBox1.SelectedText.ToString();
if (this.Tag != null)
{
var item = (DefectInfo)this.Tag;
item.Code = code;
item.Name = name;
}
CodeChangeEvent?.Invoke(code,name);
}
}
}