Tz2/Assets/Zion/Scripts/ERP/系统入库冲销凭证分析/InventoryReversalVoucherAna...

300 lines
11 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.Generic;
using System.Globalization;
using DefaultNamespace;
using DefaultNamespace.ProcessMode;
using Framework.Manager;
using Framework.Utils;
using MotionFramework;
using NaughtyAttributes;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Zion.Scripts.ERP.
{
/// <summary>
/// 月份状态枚举
/// </summary>
public enum MonthStatus
{
None, // 无状态
June, // 6月
December // 12月
}
/// <summary>
///
/// </summary>
public class InventoryReversalVoucherAnalyzerManager : MonoBehaviour
{
public TMP_InputField factroyCodeInputField;
public TMP_InputField moveTypeInputField;
public TMP_InputField starTimeInputField;
public TMP_InputField endTimeInputField;
public GameObject queryPlane;
public Button queryButton;
public Button saveButton;
public Button saveButto2;
public GameObject plane6;
public GameObject plane12;
public GameObject datika;
public TMP_InputField tiaomu1;
public TMP_InputField tiaomu2;
public TMP_InputField jine1;
public TMP_InputField jine2;
// 当前月份状态
private MonthStatus currentMonthStatus = MonthStatus.None;
private Framework.Dto.InventoryReversalVoucherAnalyzer inventoryReversalVoucherAnalyzer;
public Button datikaanniu;
/// <summary>
/// 获取当前月份状态
/// </summary>
public MonthStatus CurrentMonthStatus => currentMonthStatus;
public Button btclose;
void Start()
{
queryButton.onClick.AddListener(OnQueryButtonClicked);
saveButton.onClick.AddListener(OnSaveButtonClicked);
saveButto2.onClick.AddListener(OnSaveButtonClicked);
datikaanniu.onClick.AddListener(OnDatikaSave);
inventoryReversalVoucherAnalyzer = (Framework.Dto.InventoryReversalVoucherAnalyzer)MotionEngine.GetModule<GlobalDataStorage>().materialTaskObj;
btclose.onClick.AddListener(OnCloseButtonClicked);
}
private void OnCloseButtonClicked()
{
TutorialGuideManager.Instance.HideGuide();
}
private void OnSaveDatika()
{
List<string> list = new List<string>();
list.Add(tiaomu1.text);
list.Add(jine1.text);
list.Add(tiaomu2.text);
list.Add(jine2.text);
if (MotionEngine.GetModule<ProcessManager>().HandleClick(list))
{
TutorialGuideManager.Instance.TriggerNextGuide();
}
}
private void OnQueryButtonClicked()
{
List<string> parameters = new List<string>();
parameters.Add(factroyCodeInputField.text);
parameters.Add(moveTypeInputField.text);
parameters.Add(starTimeInputField.text);
parameters.Add(endTimeInputField.text);
// 根据月份显示对应的面板并更新状态
if (inventoryReversalVoucherAnalyzer.formselection == "6月")
{
plane6.SetActive(true);
plane12.SetActive(false);
currentMonthStatus = MonthStatus.June;
Debug.Log("检测到6月份日期显示6月面板状态设置为June");
}
else if (inventoryReversalVoucherAnalyzer.formselection == "12月")
{
plane6.SetActive(false);
plane12.SetActive(true);
currentMonthStatus = MonthStatus.December;
Debug.Log("检测到12月份日期显示12月面板状态设置为December");
}
if(MotionEngine.GetModule<ProcessManager>().HandleClick(parameters)){ TutorialGuideManager.Instance.TriggerNextGuide(queryButton.name);}
Debug.Log("查询成功");
// queryPlane.SetActive(true);
}
private void OnSaveButtonClicked()
{
datika.SetActive(true);
if (inventoryReversalVoucherAnalyzer.formselection == "6月")
{
FileComponent.DownloadSingleFile("附件12024年6月入库冲销凭证");
}
else
{
FileComponent.DownloadSingleFile("附件12024年12月入库冲销凭证");
}
}
public void OnDatikaSave()
{
// 添加日期范围判断
string startTime = starTimeInputField.text;
string endTime = endTimeInputField.text;
// 判断是否为6月份或12月份
bool isJune = IsDateInMonth(startTime, 6) || IsDateInMonth(endTime, 6);
bool isDecember = IsDateInMonth(startTime, 12) || IsDateInMonth(endTime, 12);
// 判断输入的月份和当前状态是否相同
bool monthMatches = false;
if (isJune && currentMonthStatus == MonthStatus.June)
{
monthMatches = true;
Debug.Log("月份匹配当前为6月份状态");
}
else if (isDecember && currentMonthStatus == MonthStatus.December)
{
monthMatches = true;
Debug.Log("月份匹配当前为12月份状态");
}
else
{
Debug.LogWarning("月份不匹配:输入日期月份与当前状态不符");
}
// 如果月份匹配,验证输入的条目和金额数据
if (monthMatches)
{
bool dataValid = ValidateInputData(isJune);
if (dataValid)
{
Debug.Log("数据验证通过,保存成功");
// 创建参数列表将验证通过的数据传递给ProcessManager
List<string> parameters = new List<string>();
parameters.Add("102"); // 条目1
parameters.Add("31734409.36"); // 金额1
parameters.Add("18"); // 条目2
parameters.Add("994015.01"); // 金额2
// 调用ProcessManager处理数据
MotionEngine.GetModule<ProcessManager>().HandleClick(parameters);
Debug.Log("数据已传递给ProcessManager处理");
}
else
{
List<string> parameters = new List<string>();
parameters.Add(tiaomu1.text);
parameters.Add(jine1.text);
parameters.Add(tiaomu2.text);
parameters.Add(jine2.text);
MotionEngine.GetModule<ProcessManager>().HandleClick(parameters);
Debug.LogError("数据验证失败,请检查输入的条目和金额数据");
}
}
}
/// <summary>
/// 验证输入数据是否与标准数据匹配
/// </summary>
/// <param name="isJune">是否为6月份</param>
/// <returns>数据是否有效</returns>
private bool ValidateInputData(bool isJune)
{
try
{
// 获取输入值
string tiaomu1Text = tiaomu1.text;
string tiaomu2Text = tiaomu2.text;
string jine1Text = jine1.text;
string jine2Text = jine2.text;
// 解析输入的数值
if (!int.TryParse(tiaomu1Text, out int inputTiaomu1) ||
!int.TryParse(tiaomu2Text, out int inputTiaomu2) ||
!decimal.TryParse(jine1Text, out decimal inputJine1) ||
!decimal.TryParse(jine2Text, out decimal inputJine2))
{
Debug.LogError("输入数据格式错误,请确保条目为整数,金额为数字");
return false;
}
if (isJune)
{
// 6月份标准数据条目141金额19202094.91条目23金额2102843.85
bool valid = (inputTiaomu1 == 41 && inputJine1 == 9202094.91m &&
inputTiaomu2 == 3 && inputJine2 == 102843.85m);
if (valid)
{
Debug.Log("6月份数据验证通过");
}
else
{
Debug.LogError($"6月份数据不匹配。标准值条目1=41, 金额1=9202094.91, 条目2=3, 金额2=102843.85\n" +
$"输入值条目1={inputTiaomu1}, 金额1={inputJine1}, 条目2={inputTiaomu2}, 金额2={inputJine2}");
}
return valid;
}
else
{
// 12月份标准数据条目1102金额131734409.36条目218金额2994015.01
bool valid = (inputTiaomu1 == 102 && inputJine1 == 31734409.36m &&
inputTiaomu2 == 18 && inputJine2 == 994015.01m);
if (valid)
{
Debug.Log("12月份数据验证通过");
}
else
{
Debug.LogError($"12月份数据不匹配。标准值条目1=102, 金额1=31734409.36, 条目2=18, 金额2=994015.01\n" +
$"输入值条目1={inputTiaomu1}, 金额1={inputJine1}, 条目2={inputTiaomu2}, 金额2={inputJine2}");
}
return valid;
}
}
catch (Exception ex)
{
Debug.LogError($"数据验证过程中发生错误: {ex.Message}");
return false;
}
}
/// <summary>
/// 判断日期字符串是否属于指定月份
/// </summary>
/// <param name="dateString">日期字符串</param>
/// <param name="targetMonth">目标月份(1-12)</param>
/// <returns>如果日期属于指定月份返回true否则返回false</returns>
private bool IsDateInMonth(string dateString, int targetMonth)
{
if (string.IsNullOrEmpty(dateString))
return false;
try
{
// 尝试多种日期格式解析
DateTime date;
string[] formats = { "yyyy-MM-dd", "yyyy/MM/dd", "MM/dd/yyyy", "dd/MM/yyyy", "yyyy-MM-dd HH:mm:ss", "MM-dd-yyyy" };
if (DateTime.TryParseExact(dateString, formats, CultureInfo.InvariantCulture, DateTimeStyles.None, out date) ||
DateTime.TryParse(dateString, out date))
{
return date.Month == targetMonth;
}
}
catch (Exception ex)
{
Debug.LogWarning($"日期解析失败: {dateString}, 错误: {ex.Message}");
}
return false;
}
}
}