123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using UnityEngine.EventSystems;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using System.Runtime.InteropServices;
- using System.Text;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using System.Data;
- using SimpleJSON;
- using System.Linq;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- using System.Globalization;
- using XCharts.Runtime;
- public class 庫存盤營盤損 : MonoBehaviour
- {
- [SerializeField] Toggle 非零切換;
- [SerializeField] Toggle 零切換;
- [SerializeField] GameObject 非零清單面板;
- [SerializeField] GameObject 零清單面板;
-
- private JSONNode 非零清單;
- private JSONNode 零清單;
- private JSONNode 非零清單計算;
- private JSONNode 零清單計算;
-
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
-
- public GameObject buttonPrefab1;
- public Transform buttonParent1;
- public GameObject buttonceneter1;
- private List<GameObject> copy1 = new List<GameObject>();
-
- public CanvasScaler canvasScaler;
- [SerializeField] GameObject 讀取面板;
- [SerializeField] TextMeshProUGUI 讀取;
-
- [SerializeField] GameObject 彈跳面板;
- [SerializeField] TextMeshProUGUI 彈跳文字;
- private string loadingText = "";
- private int dotCount = 0;
- private int itemsPerPage = 17;
- private int currentPage = 0;
- private int currentPage1 = 0;
- // Start is called before the first frame update
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.Portrait;
- float rate = 1000.0f / 1600.0f;
- if (canvasScaler == null)
- {
- canvasScaler = GetComponent<CanvasScaler>();
- }
- if (Main.Global.rate>rate)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
-
- StartCoroutine(AnimateText());
- //Main.Global.人員="李協叡";
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/GF_main.php?";
- //Main.Global.預設伺服器路徑="GF99";
- 非零切換.isOn = true;
- 零切換.isOn = false;
- 非零清單面板.SetActive(true);
- 零清單面板.SetActive(false);
- StartCoroutine(庫存盤營盤損1());
- }
- public void 非零_click()
- {
- if (非零切換.isOn==false && 零切換.isOn==false)
- {
- 非零切換.isOn = true;
- 零切換.isOn = false;
- }
- else if (非零切換.isOn==true && 零切換.isOn==true)
- {
- 非零切換.isOn = true;
- 零切換.isOn = false;
- 非零清單面板.SetActive(true);
- 零清單面板.SetActive(false);
- }
- }
- public void 零_click()
- {
- if (非零切換.isOn==false && 零切換.isOn==false)
- {
- 非零切換.isOn = false;
- 零切換.isOn = true;
- }
- else if (非零切換.isOn==true && 零切換.isOn==true)
- {
- 非零切換.isOn = false;
- 零切換.isOn = true;
- 非零清單面板.SetActive(false);
- 零清單面板.SetActive(true);
- }
-
- }
- IEnumerator AnimateText()
- {
- string qqq = 讀取.text.ToString();
- while (true)
- {
- yield return new WaitForSeconds(0.5f);
-
- if (dotCount < 3)
- {
- loadingText += ".";
- dotCount++;
- }
- else
- {
- loadingText = "";
- dotCount = 0;
- }
- 讀取.text = qqq+loadingText;
- }
- }
- IEnumerator 庫存盤營盤損1()
- {
- 讀取面板.SetActive(true);
- string strcon = "庫存盤營盤損";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- 非零清單 = JSON.Parse(request.downloadHandler.text);
- 非零清單計算 = JSON.Parse(request.downloadHandler.text);
-
- yield return StartCoroutine(庫存盤營盤損2());
- }
- IEnumerator 庫存盤營盤損2()
- {
-
- string strcon = "庫存盤營盤損1";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- 零清單 = JSON.Parse(request.downloadHandler.text);
- 零清單計算 = JSON.Parse(request.downloadHandler.text);
- 非零();
- 零();
- 讀取面板.SetActive(false);
- }
- private void 非零()
- {
- if (copy != null)
- {
- DeleteCopies(copy);
- }
- int startIndex = currentPage * itemsPerPage;
- int endIndex = Mathf.Min((currentPage + 1) * itemsPerPage, 非零清單.Count);
-
- int sum = 2;
- for (int i = startIndex; i < endIndex; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- TMP_InputField text1 = buttonObj.GetComponentInChildren<TMP_InputField>();
- Button[] bt = buttonObj.GetComponentsInChildren<Button>();
- int index = i;
- text1.onValueChanged.AddListener((newValue) =>
- {
- if (string.IsNullOrEmpty(newValue))
- {
- text1.text = "0";
- }
- 非零清單[index][4] = newValue.ToString();
- });
- bt[0].onClick.AddListener(() =>
- {
- int intValue;
- if (int.TryParse(text1.text, out intValue) && intValue >= 0)
- {
- text1.text = (intValue + 1).ToString();
- }
- });
- bt[1].onClick.AddListener(() =>
- {
- int intValue;
- if (int.TryParse(text1.text, out intValue) && intValue > 0)
- {
- text1.text = (intValue - 1).ToString();
- }
- });
- text[0].text =非零清單[i][1].ToString().Trim('"');
- text[1].text =非零清單[i][2].ToString().Trim('"');
- text[2].text =非零清單[i][3].ToString().Trim('"');
- text1.text =非零清單[i][4].ToString().Trim('"');
- sum+=75;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
- }
- private void 零()
- {
- if (copy1 != null)
- {
- DeleteCopies(copy1);
- }
- int startIndex = currentPage1 * itemsPerPage;
- int endIndex = Mathf.Min((currentPage1 + 1) * itemsPerPage, 零清單.Count);
- int sum = 2;
- for (int i = startIndex; i < endIndex; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab1) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(2, -sum);
- buttonObj.transform.SetParent(buttonParent1, false);
- TextMeshProUGUI[] text = buttonObj.GetComponentsInChildren<TextMeshProUGUI>();
- TMP_InputField text1 = buttonObj.GetComponentInChildren<TMP_InputField>();
- Button[] bt = buttonObj.GetComponentsInChildren<Button>();
- int index = i;
- text1.onValueChanged.AddListener((newValue) =>
- {
- if (string.IsNullOrEmpty(newValue))
- {
- text1.text = "0";
- }
- 零清單[index][4] = newValue.ToString();
- });
- bt[0].onClick.AddListener(() =>
- {
- int intValue;
- if (int.TryParse(text1.text, out intValue) && intValue >= 0)
- {
- text1.text = (intValue + 1).ToString();
- }
- });
- bt[1].onClick.AddListener(() =>
- {
- int intValue;
- if (int.TryParse(text1.text, out intValue) && intValue > 0)
- {
- text1.text = (intValue - 1).ToString();
- }
- });
- text[0].text =零清單[i][1].ToString().Trim('"');
- text[1].text =零清單[i][2].ToString().Trim('"');
- text[2].text =零清單[i][3].ToString().Trim('"');
- text1.text =零清單[i][4].ToString().Trim('"');
- sum+=75;
- copy1.Add(buttonObj);
- }
- buttonceneter1.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter1.GetComponent<RectTransform>().sizeDelta.x, sum);
- }
- public void 下一頁()
- {
- if (非零切換.isOn=true && 零切換.isOn==false)
- {
- ChangePage(1);
- }
- else
- {
- ChangePage1(1);
- }
- }
- public void 上一頁()
- {
- if (非零切換.isOn=true && 零切換.isOn==false)
- {
- ChangePage(-1);
- }
- else
- {
- ChangePage1(-1);
- }
- }
- private void ChangePage(int offset)
- {
- currentPage = Mathf.Clamp(currentPage + offset, 0, Mathf.CeilToInt((float)非零清單.Count / itemsPerPage) - 1);
- // 调用刷新页面的方法
- 非零();
- }
- private void ChangePage1(int offset)
- {
- currentPage1 = Mathf.Clamp(currentPage1 + offset, 0, Mathf.CeilToInt((float)零清單.Count / itemsPerPage) - 1);
- // 调用刷新页面的方法
- 零();
- }
- public void 存檔()
- {
- 彈跳面板.SetActive(true);
- 彈跳文字.text = "儲存完成!!";
- 讀取面板.SetActive(true);
- StartCoroutine(存檔流程());
- }
- IEnumerator 存檔流程()
- {
- for (int i = 0; i < 非零清單.Count; i++)
- {
- double str = double.Parse(非零清單[i][4]);
- double str1 = double.Parse(非零清單計算[i][4]);
- double sum = 0;
- if (str != str1)
- {
- if (str >str1)
- {
- sum = str - str1;
- string aa = 非零清單[i][0].ToString().Trim('"');
- yield return StartCoroutine(倉儲明細表流水號查詢(aa,sum.ToString(),"0","盤營入庫"));
- }
- else
- {
- sum = str1 - str;
- string aa = 非零清單[i][0].ToString().Trim('"');
- yield return StartCoroutine(倉儲明細表流水號查詢(aa, "0", sum.ToString(), "盤損出庫"));
- }
-
- }
- }
- for (int j = 0; j < 零清單.Count; j++)
- {
- double str = double.Parse(零清單[j][4]);
- double str1 = double.Parse(零清單計算[j][4]);
- double sum = 0;
- if (str != str1)
- {
- if (str >str1)
- {
- sum = str - str1;
- string aa = 零清單[j][0].ToString().Trim('"');
- yield return StartCoroutine(倉儲明細表流水號查詢(aa, sum.ToString(), "0", "盤營入庫"));
- }
- else
- {
- sum = str1 - str;
- string aa = 零清單[j][0].ToString().Trim('"');
- yield return StartCoroutine(倉儲明細表流水號查詢(aa, "0", sum.ToString(), "盤損出庫"));
- }
-
- }
- }
- 非零切換.isOn = true;
- 零切換.isOn = false;
- 非零清單面板.SetActive(true);
- 零清單面板.SetActive(false);
- currentPage = 0;
- currentPage1 = 0;
- yield return StartCoroutine(庫存盤營盤損1());
- }
- IEnumerator 倉儲明細表流水號查詢(string 料號 , string 入庫, string 出庫, string 狀態)
- {
- string strcon = "倉儲明細表流水號查詢";
- string se = Main.Global.預設伺服器路徑;
- DateTime currentDate = DateTime.Now;
- string pa1 = currentDate.ToString("yyyyMMdd");
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}", strcon, se, pa1);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- string str = request.downloadHandler.text.ToString();
- string 流水;
- if (str == "n")
- {
- 流水="Z"+currentDate.ToString("yyyyMMdd") +"000";
- }
- else
- {
- int NUM1 = int.Parse(str.Substring(str.Length - 3)) + 1;
- 流水 = "Z"+currentDate.ToString("yyyyMMdd") + NUM1.ToString().PadLeft(3, '0');
- }
- yield return StartCoroutine(倉儲明細表盤營盤損(流水, 料號, 入庫, 出庫, 狀態));
-
- }
- IEnumerator 倉儲明細表盤營盤損(string 流水號 , string 料號, string 入庫, string 出庫, string 狀態)
- {
- string strcon = "倉儲明細表盤營盤損";
- string se = Main.Global.預設伺服器路徑;
- DateTime currentDate = DateTime.Now;
- string pa1 = 流水號;
- string pa2 = Main.Global.人員;
- string pa3 = currentDate.ToString("yyyy/MM/dd");
- string pa4 = 料號;
- string pa5 = 入庫;
- string pa6 = 出庫;
- string pa7 = 狀態;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}&PA1={2}&PA2={3}&PA3={4}&PA4={5}&PA5={6}&PA6={7}&PA7={8}", strcon, se, pa1, pa2, pa3, pa4, pa5, pa6, pa7);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- }
- public void 彈跳面板關閉()
- {
- 彈跳面板.SetActive(false);
- 彈跳文字.text = "";
- }
- private void DeleteCopies(List<GameObject> copyList)
- {
- foreach (GameObject copy in copyList)
- {
- Destroy(copy);
- }
- copyList.Clear();
- }
- public void exit()
- {
- change_Secen(1);
- }
- public void change_Secen(int _screenNum)
- {
- //Main.Global.判斷是否第一次=true;
- SceneManager.LoadScene(_screenNum);
- }
- }
|