153 lines
4.1 KiB
C#
153 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.EventSystems;
|
|
using WI;
|
|
using System;
|
|
using static MQTT;
|
|
using CHN;
|
|
using System.Globalization;
|
|
|
|
public class UI_MachineKPI : UIBase, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
|
{
|
|
public SimpleField data;
|
|
|
|
public RectTransform Default_KPI;
|
|
private RectTransform Expand_KPI;
|
|
|
|
private TextMeshProUGUI DefaultMachineName;
|
|
private TextMeshProUGUI ExpandMachineName;
|
|
private Image Default_Status;
|
|
private Image Expand_Status;
|
|
|
|
private TextMeshProUGUI eorate;
|
|
private TextMeshProUGUI daynight;
|
|
private TextMeshProUGUI workcd;
|
|
private TextMeshProUGUI porate;
|
|
private TextMeshProUGUI goodqtyrate;
|
|
private TextMeshProUGUI workdt;
|
|
private TextMeshProUGUI wordno;
|
|
|
|
public bool isExpand;
|
|
|
|
public Action<UI_MachineKPI> onClickKPI;
|
|
|
|
public void SetData(SimpleField data)
|
|
{
|
|
this.data = data;
|
|
|
|
eorate.SetText(DecimalPointCalculate(data.kpiDataInfo.eorate).ToString() + "%");
|
|
daynight.SetText(SetTextData(data.machineInfo.daynight));
|
|
workcd.SetText(SetTextData(data.machineInfo.workcd));
|
|
goodqtyrate.SetText(DecimalPointCalculate(data.kpiDataInfo.goodqtyrate).ToString() + "%");
|
|
porate.SetText(DecimalPointCalculate(data.kpiDataInfo.porate).ToString() +"%");
|
|
workdt.SetText(CorrectionTime(data.machineInfo.workdt, "yyyy-MM-dd"));
|
|
wordno.SetText(SetTextData(data.machineInfo.wordno));
|
|
|
|
DefaultMachineName.SetText(SetTextData(data.machineInfo.worknm));
|
|
ExpandMachineName.SetText(SetTextData(data.machineInfo.worknm));
|
|
|
|
Default_Status.color = SetStatusColor(SetTextData(data.machineInfo.statusnm));
|
|
Expand_Status.color = SetStatusColor(SetTextData(data.machineInfo.statusnm));
|
|
}
|
|
private Color SetStatusColor(string value)
|
|
{
|
|
var color = Color.white;
|
|
|
|
switch (value)
|
|
{
|
|
case "-":
|
|
color = Color.black;
|
|
break;
|
|
case "°¡µ¿Áß":
|
|
color = Color.green;
|
|
break;
|
|
case "ºñ°¡µ¿":
|
|
color = Color.red;
|
|
break;
|
|
default:
|
|
color = Color.yellow;
|
|
break;
|
|
}
|
|
return color;
|
|
}
|
|
private bool CheckDataExists(string value)
|
|
{
|
|
if (value == null || value == string.Empty)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
private float DecimalPointCalculate(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return 0f;
|
|
}
|
|
|
|
var originFloatValue = float.Parse(value);
|
|
var floatValue = Mathf.Round(originFloatValue * 10f) / 10f;
|
|
|
|
return floatValue;
|
|
}
|
|
private string SetTextData(string value)
|
|
{
|
|
if (!CheckDataExists(value))
|
|
{
|
|
return "-";
|
|
}
|
|
return value;
|
|
}
|
|
private string CorrectionTime(string value, string dateForm)
|
|
{
|
|
if(DateTime.TryParseExact(value, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var parsedDate))
|
|
{
|
|
return parsedDate.ToString(dateForm);
|
|
}
|
|
return "-";
|
|
}
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
{
|
|
onClickKPI?.Invoke(this);
|
|
}
|
|
|
|
public void Active()
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
public void Deactive()
|
|
{
|
|
isExpand = false;
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
if (!isExpand)
|
|
{
|
|
if (Expand_KPI == null && Default_KPI == null)
|
|
return;
|
|
|
|
Expand_KPI.gameObject.SetActive(true);
|
|
Default_KPI.gameObject.SetActive(false);
|
|
|
|
isExpand = true;
|
|
|
|
transform.SetAsLastSibling();
|
|
}
|
|
}
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
{
|
|
if (isExpand)
|
|
{
|
|
Default_KPI.gameObject.SetActive(true);
|
|
Expand_KPI.gameObject.SetActive(false);
|
|
isExpand = false;
|
|
}
|
|
}
|
|
} |