Tz2/Assets/Zion/Scripts/ERP/查询合同执行状态报表/ContractStatusReportManager.cs

194 lines
6.6 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 UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using DefaultNamespace;
using DefaultNamespace.ProcessMode;
using Framework.Manager;
using Framework.Utils;
using MotionFramework;
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
using Zion.ERP.Inventory;
using Task = System.Threading.Tasks.Task;
namespace Zion.Scripts.ERP.
{
public class ContractStatusReportManager : MonoBehaviour
{
// 工厂输入框
public InputField factoryInputField;
// 公司代码输入框
public InputField companyCodeInputField;
// 采购订单输入框
public InputField purchaseOrderInputField;
// 合同日期开始输入框
public InputField contractStartDateInputField;
// 合同日期结束输入框
public InputField contractEndDateInputField;
// 查询按钮
public Button queryButton;
public GameObject okPlane;
public GameObject errorPlane;
public bool isOK = false;
// public GameObject AnswerSheet;
void Start()
{
//localFilePath = Application.streamingAssetsPath + "/Excel/" + $"合同执行状态报表_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx";
//Debug.Log("本地文件路径:" + localFilePath);
// 绑定查询按钮点击事件
if (queryButton != null)
{
queryButton.onClick.AddListener(OnQueryButtonClicked);
}
//await Task.Delay(1000);
// UploadFileAsync();
}
/// <summary>
/// 处理查询按钮点击事件
/// </summary>
private void OnQueryButtonClicked()
{
// // 验证日期区间
// if (!ValidateDateRange())
// {
// Debug.LogError("错误日期必须大于等于2025.1.1-2025.12.31区间!");
// }
// 这里添加查询逻辑
string factory = factoryInputField.text;
string companyCode = companyCodeInputField.text;
string purchaseOrder = purchaseOrderInputField.text;
string contractStartDate = contractStartDateInputField.text;
string contractEndDate = contractEndDateInputField.text;
List<string> parameters = new List<string>();
parameters.Add(factory);
parameters.Add(companyCode);
parameters.Add(purchaseOrder);
parameters.Add(contractStartDate);
parameters.Add(contractEndDate);
if (MotionEngine.GetModule<ProcessManager>().HandleClick(parameters))
{
Debug.Log("查询成功");
okPlane.SetActive(true);
isOK = true;
TutorialGuideManager.Instance.TriggerNextGuide(queryButton.name);
}
else
{
Debug.Log("查询失败");
errorPlane.SetActive(true);
isOK = false;
}
Debug.Log($"工厂: {factory}, 公司代码: {companyCode}, 采购订单: {purchaseOrder}, 合同开始日期: {contractStartDate}, 合同结束日期: {contractEndDate}");
//查询合同执行状态报表
// FileComponent.DownloadSingleFile("附件1-合同变更申请_合同1");
FileComponent.DownloadSingleFile("合同执行情况数据反馈_8行");
// AnswerSheet.SetActive(true);
}
/// <summary>
/// 验证日期区间是否有效
/// </summary>
private bool ValidateDateRange()
{
// 如果日期为空,不进行验证
if (string.IsNullOrEmpty(contractStartDateInputField.text) || string.IsNullOrEmpty(contractEndDateInputField.text))
{
return true;
}
DateTime startDate, endDate;
// 尝试解析开始日期
if (!TryParseDate(contractStartDateInputField.text, out startDate))
{
Debug.LogError("开始日期格式不正确请使用yyyy.MM.dd或yyyy-MM-dd格式");
return false;
}
// 尝试解析结束日期
if (!TryParseDate(contractEndDateInputField.text, out endDate))
{
Debug.LogError("结束日期格式不正确请使用yyyy.MM.dd或yyyy-MM-dd格式");
return false;
}
// 检查日期区间是否为一年
TimeSpan span = endDate - startDate;
int dayDifference = (int)span.TotalDays;
// 允许364-366天的区间考虑闰年
bool isValidSpan = dayDifference >= 364 && dayDifference <= 366;
if (!isValidSpan)
{
Debug.LogError("日期区间必须为1年例如2024.01.01-2025.01.01");
return false;
}
return true;
}
/// <summary>
/// 尝试解析日期,支持多种格式
/// </summary>
private bool TryParseDate(string dateString, out DateTime date)
{
string[] formats = { "yyyy.MM.dd", "yyyy-MM-dd", "yyyy/MM/dd" };
return DateTime.TryParseExact(
dateString,
formats,
CultureInfo.InvariantCulture,
DateTimeStyles.None,
out date);
}
// private async void UploadFileAsync()
// {
// // 上传文件
// string uploadUrl = ApiUrls.TransitInventory.UploadFileAndParam;
// // string filePath = @"E:\Unity Projects\GitLab\2025\TaizhouWarehousePhaseII\Assets\StreamingAssets\Excel\合同执行状态报表_20250509_150748.xlsx";
// string filePath = localFilePath;
// // 获取访问令牌
// // string token = "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijg4YTRlYTM1LTdkMDQtNDBhMC04ZTA0LTg4ZWMzNTE2NGY3YiJ9.2ldil6bEqNwGdOhEuxEn5XRuDkZZl1fhqLjSNBzrisRrm4wInR1BG76PsHt1ZgMonNVcopvtY9eAVc4WFKpg7g";
// string token = MotionEngine.GetModule<GlobalDataStorage>().ExamInfo.Token;
//
// // 使用辅助类上传文件
// string result = await UploadFileHelper.UploadFileWithFormData(uploadUrl, filePath, token);
//
// if (!string.IsNullOrEmpty(result))
// {
// Debug.Log("上传文件结果: " + result);
// }
// }
/// <summary>
/// 下载文件并保存到本地
/// </summary>
}
}