123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Text.RegularExpressions;
- using System.Data.SqlClient;
- using TMPro;
- using System;
- using System.IO;
- using ZXing;
- using ZXing.QrCode;
- using System.Net;
- using SimpleJSON;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
-
-
- public class 電子簽章 : MonoBehaviour
- {
- public RawImage rawImage1;
- public RawImage rawImage;
- public Texture2D canvasTexture;
- public Color drawColor = Color.black;
- public float brushSize = 10f;
-
- private bool isDrawing = false;
- private Vector2 lastPos;
-
- [SerializeField] GameObject 條跳面板;
-
- [SerializeField] GameObject 寫面板;
- [SerializeField] GameObject 看面板;
-
- public CanvasScaler canvasScaler;
- float screenWidth;
- float screenHeight;
-
- public GameObject buttonPrefab;
- public Transform buttonParent;
- public GameObject buttonceneter;
- private List<GameObject> copy = new List<GameObject>();
- void Start()
- {
- Screen.autorotateToPortrait = false;
- Screen.orientation = ScreenOrientation.LandscapeLeft;
- float rate = 900.0f / 1900.0f;
- if (canvasScaler == null)
- {
- canvasScaler = GetComponent<CanvasScaler>();
- }
-
- if (Main.Global.rate<rate)
- {
- canvasScaler.matchWidthOrHeight = 1f;
- }
- else
- {
- canvasScaler.matchWidthOrHeight = 0f;
- }
-
- ddd();
- }
-
- void ddd()
- {
- canvasTexture = new Texture2D((int)rawImage.rectTransform.rect.width, (int)rawImage.rectTransform.rect.height);
-
- Color[] fillColorArray = canvasTexture.GetPixels();
-
- for (int i = 0; i < fillColorArray.Length; ++i)
- {
- fillColorArray[i] = Color.white;
- }
-
- canvasTexture.SetPixels(fillColorArray);
- canvasTexture.Apply();
- rawImage.texture = canvasTexture;
- }
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- isDrawing = true;
- lastPos = GetMousePosition();
- }
- else if (Input.GetMouseButtonUp(0))
- {
- isDrawing = false;
- }
-
- if (isDrawing)
- {
- Vector2 currentPos = GetMousePosition();
- DrawLine(lastPos, currentPos);
- lastPos = currentPos;
- }
- }
-
- void DrawLine(Vector2 from, Vector2 to)
- {
- Vector2 diff = to - from;
- float distance = diff.magnitude;
- int steps = Mathf.RoundToInt(distance);
- for (int i = 0; i < steps; i++)
- {
- float t = i / distance;
- Vector2 point = Vector2.Lerp(from, to, t);
- DrawPoint((int)point.x, (int)point.y);
- }
- canvasTexture.Apply();
- }
-
- void DrawPoint(int x, int y)
- {
- for (int i = -Mathf.RoundToInt(brushSize / 2); i < Mathf.RoundToInt(brushSize / 2); i++)
- {
- for (int j = -Mathf.RoundToInt(brushSize / 2); j < Mathf.RoundToInt(brushSize / 2); j++)
- {
- if (x + i >= 0 && x + i < canvasTexture.width && y + j >= 0 && y + j < canvasTexture.height)
- {
- canvasTexture.SetPixel(x + i, y + j, drawColor);
- }
- }
- }
- }
-
- Vector2 GetMousePosition()
- {
- Vector2 localMousePos;
- RectTransformUtility.ScreenPointToLocalPointInRectangle(rawImage.rectTransform, Input.mousePosition, null, out localMousePos);
- return localMousePos + rawImage.rectTransform.rect.size / 2;
- }
-
- public void SaveImage()
- {
- 條跳面板.SetActive(true);
- byte[] bytes = canvasTexture.EncodeToPNG();
- System.IO.File.WriteAllBytes(Application.persistentDataPath + "/drawnImage.png", bytes);
- string asd =System.Convert.ToBase64String(bytes);
- StartCoroutine(電簽流水查詢(asd));
- }
- IEnumerator 電簽流水查詢(string asd)
- {
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
- //Main.Global.預設伺服器路徑="test";
- 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;
- }
- string num = request.downloadHandler.text.ToString();
- Debug.Log(num);
- string 流水號 = "PC";
-
- if (num == "n")
- {
- 流水號 ="PC00000001";
- }
- else
- {
- string cnum = num.Substring(2);
- int inum = int.Parse(cnum);
- inum+=1;
- if (inum<10)
- {
- 流水號+="0000000"+inum.ToString();
- }
- if (inum>9 && inum<100)
- {
- 流水號+="000000"+inum.ToString();
- }
- if (inum>99 && inum<1000)
- {
- 流水號+="00000"+inum.ToString();
- }
- if (inum>999 && inum<10000)
- {
- 流水號+="0000"+inum.ToString();
- }
- if (inum>9999 && inum<100000)
- {
- 流水號+="000"+inum.ToString();
- }
- if (inum>99999 && inum<10000000)
- {
- 流水號+="00"+inum.ToString();
- }
- if (inum>999999 && inum<10000000)
- {
- 流水號+="0"+inum.ToString();
- }
- if (inum>9999999 && inum<100000000)
- {
- 流水號+=inum.ToString();
- }
- }
- Debug.Log(流水號);
- StartCoroutine(電簽上傳(asd,流水號));
- }
- IEnumerator 電簽上傳(string pa1,string pa2)
- {
- string 阿帕契路徑1 = "";
- if (Main.Global.阿帕契路徑=="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?")
- {
- 阿帕契路徑1="http://106.1.48.106:8080/wp-content/themes/event-star/shto_update.php?";
- }
- else
- {
- 阿帕契路徑1="http://210.61.41.234/ShTo/wp-content/themes/event-star/shto_update.php?";
- }
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_update.php?";
- //Main.Global.預設伺服器路徑="test";
- string se = Main.Global.預設伺服器路徑;
- string pa = "王詩文";
-
- WWWForm form = new WWWForm();
- form.AddField("se", se);
- form.AddField("PA", pa);
- form.AddField("PA1", pa1);
- form.AddField("PA2", pa2);
-
- using (UnityWebRequest request = UnityWebRequest.Post(阿帕契路徑1, form))
- {
- yield return request.SendWebRequest();
-
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- }
- else
- {
- Debug.Log("Image uploaded successfully");
- }
- }
- }
- IEnumerator 電簽清單()
- {
- //Main.Global.阿帕契路徑="http://106.1.48.106:8080/wp-content/themes/event-star/shto_main.php?";
- //Main.Global.預設伺服器路徑="test";
- string strcon = "電簽清單";
- string se = Main.Global.預設伺服器路徑;
- string strUrl = string.Format(Main.Global.阿帕契路徑+"comm={0}&se={1}", strcon, se);
- Debug.Log(strUrl);
- UnityWebRequest request = UnityWebRequest.Get(strUrl);
- yield return request.SendWebRequest();
- if (request.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(request.error);
- yield break;
- }
- JSONNode json = JSON.Parse(request.downloadHandler.text);
- Debug.Log(json);
- int sum = 0;
- for (int i = 0; i < json.Count; i++)
- {
- GameObject buttonObj = Instantiate(buttonPrefab) as GameObject;
- buttonObj.GetComponent<RectTransform>().anchoredPosition = new Vector2(3, -sum);
- buttonObj.transform.SetParent(buttonParent, false);
- string idname = json[i][0].ToString().Trim('"');
- TextMeshProUGUI text = buttonObj.GetComponentInChildren<TextMeshProUGUI>();
- text.text = idname;
- Button newButton = buttonObj.GetComponentInChildren<Button>();
- int index = i;
- newButton.onClick.AddListener(() =>
- {
- string pa1 = json[index][2].ToString().Trim('"');
- byte[] bytes = System.Convert.FromBase64String(pa1);
- Texture2D texture = new Texture2D(2, 2);
- texture.LoadImage(bytes);
- rawImage1.texture = texture;
-
- });
- sum+=50;
- copy.Add(buttonObj);
- }
- buttonceneter.GetComponent<RectTransform>().sizeDelta = new Vector2(buttonceneter.GetComponent<RectTransform>().sizeDelta.x, sum);
-
-
-
- }
- public void 看()
- {
- StartCoroutine(電簽清單());
- rawImage1.texture = Texture2D.blackTexture;
- 寫面板.SetActive(false);
- 看面板.SetActive(true);
- }
- public void 寫()
- {
-
- 寫面板.SetActive(true);
- 看面板.SetActive(false);
- if (copy != null)
- {
- DeletetextCopy();
- }
- ClearCanvas();
- }
- public void DeletetextCopy()
- {
- // 刪除複製出來的物件
- foreach (GameObject i in copy)
- {
- Destroy(i);
- }
- copy.Clear();
- }
- public void 彈關()
- {
- 條跳面板.SetActive(false);
- ClearCanvas();
- }
- public void back()
- {
- change_Secen(1);
- }
- public void ClearCanvas()
- {
- Color[] clearColorArray = new Color[canvasTexture.width * canvasTexture.height];
- for (int i = 0; i < clearColorArray.Length; i++)
- {
- clearColorArray[i] = Color.clear;
- }
- canvasTexture.SetPixels(clearColorArray);
- canvasTexture.Apply();
- ddd();
- }
- public void change_Secen(int _screenNum)
- {
-
- SceneManager.LoadScene(_screenNum);
- }
- }
|