ShanxiKnowledgeBase/SXElectricity Marketing 2.0/Assets/Zion/Scripts/YL/Administrativefile.cs

379 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using static Writepdf;
public enum Derive
{
Residentcontract,
Transfercontract,
Lowpressurecontract,
Naturalcontract,
Highpressurecontract,
Temporarycontract,
Powergenerationproject
}
public class Administrativefile : MonoBehaviour
{
/// <summary>
/// 合同之间切换按钮
/// </summary>
public Toggle residentendorsementtoggle, switchpowersupplytoggle, lowpressuretoggle, artificialtoggle, hightensiontoggle, temporarilytoggle, naturalpersontoggle;
/// <summary>
/// 切换合同的不同状态
/// </summary>
Derive derive = Derive.Residentcontract;
/// <summary>
/// 需要生成的位置
/// </summary>
public RectTransform operatingarea;
/// <summary>
/// 导出pdf格式按钮
/// </summary>
public Button pdfbutton;
/// <summary>
/// 每个合同身上对应的脚本
/// </summary>
public Transfercontract transfercontract;
/// <summary>
/// 居民背书合同
/// </summary>
public GameObject residentcontract;
/// <summary>
/// 转供电合同
/// </summary>
public GameObject Transfercontract;
/// <summary>
/// 低压供电合同
/// </summary>
public GameObject Lowpowersupplycontract;
/// <summary>
/// 非自然人分布式光伏发电项目购售合同
/// </summary>
public GameObject Nonnaturalperson;
/// <summary>
/// 高压供电合同
/// </summary>
public GameObject highvoltagepowersupply;
/// <summary>
/// 临时供电合同
/// </summary>
public GameObject Temporarypowersupply;
/// <summary>
/// 自然人分布式光伏发电项目购售电合同
/// </summary>
public GameObject Contractofnaturalperson;
/// <summary>
/// 存取合同对象
/// </summary>
public List<GameObject> contract = new List<GameObject>();
/// <summary>
/// 存放的图片链表
/// </summary>
public List<Texture2D> pictures = new List<Texture2D>();
/// <summary>
/// 获取当前时间
/// </summary>
private string Time
{
get { return System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); }
}
/// <summary>
/// 提示导出路劲页面框
/// </summary>
public GameObject Overlay;
/// <summary>
/// 显示路径
/// </summary>
public InputField derivedpath;
/// <summary>
/// 把路劲页面失活
/// </summary>
public Button verify;
void Start()
{
Init();
Contractswitching();
}
private void Init()
{
residentcontract = Resources.Load<GameObject>("UIpanel/residentcontract");
Transfercontract = Resources.Load<GameObject>("UIpanel/Transfercontract");
Lowpowersupplycontract = Resources.Load<GameObject>("UIpanel/Lowpowersupplycontract");
Nonnaturalperson = Resources.Load<GameObject>("UIpanel/Nonnaturalperson");
highvoltagepowersupply = Resources.Load<GameObject>("UIpanel/highvoltagepowersupply");
Temporarypowersupply = Resources.Load<GameObject>("UIpanel/Temporarypowersupply");
Contractofnaturalperson = Resources.Load<GameObject>("UIpanel/Contractofnaturalperson");
if (derive == Derive.Residentcontract)
{
Deletecontract();
if (residentcontract)
{
GameObject residentcontracts = Instantiate(residentcontract, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
pdfbutton.onClick.AddListener(Printacontract);//打印按钮
verify.onClick.AddListener(() =>
{
derivedpath.text = "";
Overlay.SetActive(false);
});
}
/// <summary>
/// 判断打印不同的合同
/// </summary>
private void Printacontract()
{
switch (derive)
{
case Derive.Residentcontract:
EquippingItems();
derivedpath.text = "d:\\居民背书合同" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Transfercontract:
EquippingItems();
derivedpath.text = "d:\\转供电合同" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Lowpressurecontract:
EquippingItems();
derivedpath.text = "d:\\低压供用电合同2022版" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Naturalcontract:
EquippingItems();
derivedpath.text = "d:\\非自然人分布式光伏发电项目购售" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Highpressurecontract:
EquippingItems();
derivedpath.text = "d:\\高压供电合同" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Temporarycontract:
EquippingItems();
derivedpath.text = "d:\\临时供电合同2022版" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
case Derive.Powergenerationproject:
EquippingItems();
derivedpath.text = "d:\\自然人分布式光伏发电项目购售电合同" + Time + ".pdf";
StartCoroutine(CaptureScreenshot(transfercontract.inhabitants, derivedpath.text));//打印
break;
default:
break;
}
}
public void EquippingItems()
{
if (pictures.Count > 0)
{
for (int i = 0; i < pictures.Count; i++)
{
Destroy(pictures[i]);
}
pictures.Clear();
}
for (int i = 0; i < transfercontract.inhabitants.Length; i++)
{
Picture(transfercontract.inhabitants[i]);
}
}
/// <summary>
/// 合同切换按钮
/// </summary>
private void Contractswitching()
{
residentendorsementtoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Residentcontract;
Deletecontract();
if (residentcontract)
{
GameObject residentcontracts = Instantiate(residentcontract, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
switchpowersupplytoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Transfercontract;
Deletecontract();
if (Transfercontract)
{
GameObject residentcontracts = Instantiate(Transfercontract, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
lowpressuretoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Lowpressurecontract;
Deletecontract();
if (Lowpowersupplycontract)
{
GameObject residentcontracts = Instantiate(Lowpowersupplycontract, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
artificialtoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Naturalcontract;
Deletecontract();
if (Nonnaturalperson)
{
GameObject residentcontracts = Instantiate(Nonnaturalperson, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
hightensiontoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Highpressurecontract;
Deletecontract();
if (highvoltagepowersupply)
{
GameObject residentcontracts = Instantiate(highvoltagepowersupply, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
temporarilytoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Temporarycontract;
Deletecontract();
if (Temporarypowersupply)
{
GameObject residentcontracts = Instantiate(Temporarypowersupply, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
naturalpersontoggle.onValueChanged.AddListener((ison) =>
{
if (ison)
{
derive = Derive.Powergenerationproject;
Deletecontract();
if (Contractofnaturalperson)
{
GameObject residentcontracts = Instantiate(Contractofnaturalperson, operatingarea);
contract.Add(residentcontracts);
if (residentcontracts)
{
transfercontract = residentcontracts.GetComponent<Transfercontract>();
}
}
}
});
}
/// <summary>
/// 把图片转成pdf格式
/// </summary>
/// <param name="images"></param>
/// <returns></returns>
private IEnumerator CaptureScreenshot(Image[] images, string path)
{
for (int i = 0; i < images.Length; i++)
{
Picture2(images[i]);
yield return new WaitForEndOfFrame();
// 创建一个新的Texture2D对象尺寸为屏幕分辨率
Texture2D screenshot = new Texture2D(1080, 814, TextureFormat.RGB24, false);
// 从屏幕读取像素数据到Texture2D对象中
screenshot.ReadPixels(new Rect(445, 55, 1080, 814), 0, 0);
screenshot.Apply();
pictures.Add(screenshot);
Picture(images[i]);
}
Texture2D[] intArray = pictures.ToArray();
Convert2PDF(intArray, path);
transfercontract.Restore(0);
Overlay.SetActive(true);
}
/// <summary>
/// 把图片失活
/// </summary>
public void Picture(Image images)
{
images.gameObject.SetActive(false);
}
/// <summary>
/// 把图片激活
/// </summary>
public void Picture2(Image images)
{
images.gameObject.SetActive(true);
}
/// <summary>
/// 删除方法
/// </summary>
public void Deletecontract()
{
if (contract.Count > 0)
{
for (int i = 0; i < contract.Count; i++)
{
Destroy(contract[i].gameObject);
}
contract.Clear();
}
}
void Update()
{
}
}