geboshi_V1/LeatherProject/LeatherApp/UIExtend/UIDefectImage.cs

99 lines
3.3 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 UIDefectImage : UserControl
{
/// <summary>
/// code,name
/// </summary>
public Action<string, string> CodeChangeEvent;
public UIDefectImage(string modelName)
{
InitializeComponent();
init(modelName);
}
private void init(string modelName)
{
if (Config.OpenHalconDefect)
{
JObject obj = new JObject();
obj.Add("id", 0);
obj.Add("code", "ng");
obj.Add("name", "NG");
obj.Add("color", "Red");
JArray arr = new JArray();
arr.Add(obj);
var list = arr.Select(x => new { code = x.Value<string>("code"), name = x.Value<string>("name") }).ToList();
uiComboBox1.ValueMember = "code";
uiComboBox1.DisplayMember = "name";
uiComboBox1.DataSource = list;
}
else
{
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; }
}
[Description("瑕疵位置"), Category("自定义")]
public string DefecLocation
{
set { this.lblLocation.Text = value; }
}
[Description("瑕疵图"), Category("自定义")]
public Image Image
{
set { this.ucImageView1.loadImage(value);}
}
private void uiComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string code = uiComboBox1.SelectedValue.ToString();
string name = uiComboBox1.Text.ToString();
if (this.Tag != null)//修改不起作用
{
var item = (DefectInfo)this.Tag;
item.Code = code;
item.Name = name;
}
API.OutputDebugString("AAAAAAAAA-"+code + " " + name);
CodeChangeEvent?.Invoke(code,name);
}
private void ucImageView1_Load(object sender, EventArgs e)
{
uiCheckBox1.Left = this.uiComboBox1.Left + this.uiComboBox1.Width + 5;
this.lblLocation.Left = this.uiCheckBox1.Left + uiCheckBox1.Width + 5;
}
}
}