111 lines
4.1 KiB
C#
111 lines
4.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using System;
|
|
|
|
public class Uiika : MonoBehaviour
|
|
{
|
|
[Header("UIDocument")]
|
|
public UIDocument UI;
|
|
public VisualTreeAsset tabletemplate;
|
|
[Header("Parser")]
|
|
public ThanksStASSForTheNiceMethod Caller;
|
|
public Button RequestButton; // UI êîìïîíåíòû -->
|
|
public TextField datebegin;
|
|
public TextField dateend;
|
|
public TextField timebegin;
|
|
public TextField timeend;
|
|
public TextField SerialNumber;
|
|
public IMGUIContainer loadimg;
|
|
public DropdownField SerialNumberDrop;
|
|
public Label forcodes; // <-- UI êîìïîíåíòû
|
|
|
|
public DateTime DatBegin;
|
|
public DateTime DatEnd;
|
|
public TimeSpan TimeBegin;
|
|
public TimeSpan TimeEnd;
|
|
public string SerialNumberStr;
|
|
|
|
|
|
// Start is called before the first frame update
|
|
public void Start()
|
|
{
|
|
var root = UI.rootVisualElement;
|
|
loadimg = root.Q<IMGUIContainer>("loadimg");
|
|
forcodes = root.Q<Label>("forcodes");
|
|
datebegin = root.Q<TextField>("datebegin");
|
|
dateend = root.Q<TextField>("dateend");
|
|
timebegin = root.Q<TextField>("timebegin");
|
|
timeend = root.Q<TextField>("timeend");
|
|
SerialNumber = root.Q<TextField>("tagsn");
|
|
SerialNumberDrop = root.Q<DropdownField>("SerialNumberDrop");
|
|
RequestButton = root.Q<Button>("RequestButton");
|
|
RequestButton.clicked += RequestButtonPressed; //Áèíä êíîïêè RequestButton
|
|
}
|
|
public void Remember()
|
|
{
|
|
datebegin.value = string.Format("{0:dd.MM.yyyy}", DatBegin);
|
|
dateend.value = string.Format("{0:dd.MM.yyyy}", DatEnd);
|
|
timebegin.value = string.Format("{0:hh\\:mm\\:ss}", TimeBegin);
|
|
timeend.value = string.Format("{0:hh\\:mm\\:ss}", TimeEnd);
|
|
SerialNumber.value = SerialNumberStr;
|
|
|
|
}
|
|
void RequestButtonPressed()
|
|
{
|
|
DateTime dDateBegin;
|
|
DateTime dDateEnd;
|
|
TimeSpan dTimeBegin;
|
|
TimeSpan dTimeEnd;
|
|
|
|
RequestButton.SetEnabled(false); //Îòêëþ÷åíèå êíîïêè RequestButton, äëÿ èçáåæàíèÿ ïîâòîðíûõ äàííûõ
|
|
forcodes.visible = false;
|
|
Caller.ClearList();
|
|
Debug.Log(datebegin.text + " " + dateend.text + " " + timebegin.text + " " + timeend.text);
|
|
if (DateTime.TryParse(datebegin.text, out dDateBegin) && DateTime.TryParse(dateend.text, out dDateEnd) && TimeSpan.TryParse(timebegin.text, out dTimeBegin) && TimeSpan.TryParse(timeend.text, out dTimeEnd))
|
|
{
|
|
DatBegin = dDateBegin;
|
|
DatEnd = dDateEnd;
|
|
TimeBegin = dTimeBegin;
|
|
TimeEnd = dTimeEnd;
|
|
SerialNumberStr = SerialNumber.text;
|
|
Caller.URL = "http://192.168.10.3:8008/api/v2/service/get_tag_log_mo/?method=GetTagLogMo&date_start=" + string.Format("{0:yyyy-MM-dd}",dDateBegin) + "%20" + string.Format("{0:hh\\:mm\\:ss}", dTimeBegin) + "&date_end=" + string.Format("{0:yyyy-MM-dd}", dDateEnd) + "%20" + string.Format("{0:hh\\:mm\\:ss}", dTimeEnd) + "&tag=" + SerialNumber.text;
|
|
Caller.Request();
|
|
Debug.Log("Inputs fields OK");
|
|
loadimg.visible = true;
|
|
}
|
|
else
|
|
{
|
|
RequestButton.SetEnabled(true);
|
|
Debug.Log("Input fields no OK");
|
|
forcodes.visible = true;
|
|
forcodes.text = "Â äàííûõ îáíàðóæåíà îøèáêà.";
|
|
loadimg.visible = false;
|
|
}
|
|
|
|
}
|
|
public void SetResponseCode(string Code)
|
|
{
|
|
|
|
forcodes.text = "Îòâåò íà çàïðîñ: " + Code;
|
|
}
|
|
public void MakeTable()
|
|
{
|
|
foreach(string x in Caller.MarksTime)
|
|
{
|
|
TemplateContainer itemTableContainer = tabletemplate.Instantiate();
|
|
UI.rootVisualElement.Q<ScrollView>("TableBox2").Add(itemTableContainer);
|
|
string[] strArray = x.Split("!");
|
|
int second = int.Parse(strArray[1]);
|
|
TimeSpan timeSpan = TimeSpan.FromSeconds(second);
|
|
|
|
itemTableContainer.Q<Label>("MarkTimeSec").text = string.Format("{0:D2}:{1:D2}:{2:D2}ñ", timeSpan.Hours,timeSpan.Minutes,timeSpan.Seconds);
|
|
itemTableContainer.Q<Label>("MarkOtmetka").text = strArray[0];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|