117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using Cysharp.Threading.Tasks;
|
|
using Newtonsoft.Json;
|
|
using Runtime;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace HK.FUJIFILM
|
|
{
|
|
public class PrintReceiptUI : UIBase
|
|
{
|
|
[SerializeField] private TMP_Text txtName;
|
|
[SerializeField] private TMP_Text txtOrderID;
|
|
[SerializeField] private Button btnConfirm;
|
|
[SerializeField] private Button btnReprintReceipt;
|
|
[SerializeField] private TMP_Text txtWaitPrinter;
|
|
|
|
string filePath;
|
|
|
|
public override void OnInit()
|
|
{
|
|
base.OnInit();
|
|
|
|
#region AutoGen_Init
|
|
|
|
txtName = GetValue<TMP_Text>("txtName");
|
|
txtOrderID = GetValue<TMP_Text>("txtOrderID");
|
|
btnConfirm = GetValue<Button>("btnConfirm");
|
|
btnReprintReceipt = GetValue<Button>("btnReprintReceipt");
|
|
txtWaitPrinter = GetValue<TMP_Text>("txtWaitPrinter");
|
|
|
|
btnConfirm.onClick.AddListener(OnClickbtnConfirm);
|
|
btnReprintReceipt.onClick.AddListener(OnClickbtnReprintReceipt);
|
|
|
|
#endregion
|
|
}
|
|
|
|
public override void OnOpen(UIBase lastUI = null)
|
|
{
|
|
base.OnOpen(lastUI);
|
|
|
|
txtWaitPrinter.gameObject.SetActive(true);
|
|
btnConfirm.gameObject.SetActive(false);
|
|
btnReprintReceipt.gameObject.SetActive(false);
|
|
txtName.text = ShoppingCartManager.Instance.ShoppingCart.userName;
|
|
txtOrderID.text = ShoppingCartManager.Instance.ShoppingCart.orderID.ToString();
|
|
|
|
var serializeObject = JsonConvert.SerializeObject(ShoppingCartManager.Instance.ShoppingCart);
|
|
Debug.Log(serializeObject);
|
|
filePath = $"{Application.streamingAssetsPath}/Data/dataFile{DateTime.Now:yyyyMMddHHmmss}.json";
|
|
var fileInfo = new FileInfo(filePath);
|
|
if (!fileInfo.Directory.Exists)
|
|
{
|
|
fileInfo.Directory.Create();
|
|
}
|
|
|
|
fileInfo.CreateText().Close();
|
|
File.WriteAllText(filePath, serializeObject);
|
|
RunPrinting(filePath);
|
|
}
|
|
|
|
void RunPrinting(string str)
|
|
{
|
|
async UniTask PrintReceipt()
|
|
{
|
|
await UniTask.Yield();
|
|
await CitizenPrinterManager.StartPrintingAsync(str);
|
|
NetworkManager.Instance.Upload((b) => { PrintFinish(); });
|
|
}
|
|
|
|
PrintReceipt().Forget();
|
|
}
|
|
|
|
void PrintFinish()
|
|
{
|
|
txtWaitPrinter.gameObject.SetActive(false);
|
|
btnConfirm.gameObject.SetActive(true);
|
|
btnReprintReceipt.gameObject.SetActive(true);
|
|
ShoppingCartManager.Instance.ResetCart();
|
|
}
|
|
|
|
#region AutoGen_Method
|
|
|
|
private void OnClickbtnConfirm()
|
|
{
|
|
UIManager.Instance.CloseAll();
|
|
UIManager.Instance.ShowUI(nameof(HomeUI), null);
|
|
}
|
|
|
|
private void OnClickbtnReprintReceipt()
|
|
{
|
|
RunPrinting(filePath);
|
|
}
|
|
|
|
#endregion
|
|
|
|
public override void OnDispose()
|
|
{
|
|
base.OnDispose();
|
|
|
|
#region AutoGen_Dispose
|
|
|
|
btnConfirm.onClick.RemoveListener(OnClickbtnConfirm);
|
|
btnReprintReceipt.onClick.RemoveListener(OnClickbtnReprintReceipt);
|
|
|
|
txtName = null;
|
|
txtOrderID = null;
|
|
btnConfirm = null;
|
|
btnReprintReceipt = null;
|
|
txtWaitPrinter = null;
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
} |