191 lines
7.2 KiB
C#
191 lines
7.2 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
using Sai.Database.Shared;
|
|||
|
|
|
|||
|
|
namespace Sai.Common.Shared.WBSCoder
|
|||
|
|
{
|
|||
|
|
public partial class ProjectFileCheckerViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
public ProjectFileCheckerViewModel(CheckCodeViewModel viewModel)
|
|||
|
|
{
|
|||
|
|
this.viewModel = viewModel;
|
|||
|
|
sqliteUtil = viewModel.SqliteUtil;
|
|||
|
|
lastTaskItems = viewModel.LastTaskItems;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private readonly ObservableCollection<TaskItem> lastTaskItems;
|
|||
|
|
private readonly SqliteUtil sqliteUtil;
|
|||
|
|
private readonly CheckCodeViewModel viewModel;
|
|||
|
|
|
|||
|
|
public ObservableCollection<TaskItem> ErrorTaskItems { get; set; } = new();
|
|||
|
|
|
|||
|
|
public string PjFileName { get; set; }
|
|||
|
|
|
|||
|
|
public static string InsertFormat(string input, int interval, string value)
|
|||
|
|
{
|
|||
|
|
for (int i = interval - 1; i < input.Length; i += interval + 1)
|
|||
|
|
input = input.Insert(i, value);
|
|||
|
|
return input;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 校验mpp文件编码是否符合标准
|
|||
|
|
/// </summary>
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void CheckProjectFile(object obj)
|
|||
|
|
{
|
|||
|
|
ErrorTaskItems.Clear();
|
|||
|
|
PjFileName = viewModel.ProjectPath;
|
|||
|
|
int? index = viewModel.Index;
|
|||
|
|
if (PjFileName == null || index == null)
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("提示", "未选择Project文件或标准");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (var item in lastTaskItems)
|
|||
|
|
{
|
|||
|
|
item.ErrorMessages = string.Empty;
|
|||
|
|
item.IsError = false;
|
|||
|
|
if (item.WBSCode.Contains(" "))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "编码中存在空格;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!item.WBSCode.Contains("-"))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "编码未分段或分段符号错误;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
string[] chars = item.WBSCode.Split('-');
|
|||
|
|
if (chars.Count() != 3)
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages = "编码分段数错误;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (item.WBSCode.Contains("(") || item.WBSCode.Contains(")") ||
|
|||
|
|
!(item.WBSCode.Contains("(") && item.WBSCode.Contains(")")))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages = "区域码未使用括号或缺少区域码;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var projectCode = chars[0];
|
|||
|
|
var classfiyCode = chars[1];
|
|||
|
|
var lastCode = chars[2];
|
|||
|
|
//项目代码模式
|
|||
|
|
//var wbscodepattern = @"^[A-Z]{2,}\d*-[1-9]{5}-\((((B|0)\d{2}){2}\d)|(\d{3})\)|[A-Z]*\d{4}$";
|
|||
|
|
|
|||
|
|
var projectCodeIsMatch = Regex.IsMatch(projectCode, @"^[A-Z]+\d*");
|
|||
|
|
if (!projectCodeIsMatch)
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "项目代码格式错误;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var classCodeIsMatch = Regex.IsMatch(classfiyCode, "^[1-9]{5}$"); //匹配5个数字字符
|
|||
|
|
if (!classCodeIsMatch)
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "分类编码格式错误;";
|
|||
|
|
goto result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var modifyclassfiycode = InsertFormat(classfiyCode, 1, "0"); //间隔插入0
|
|||
|
|
var subsectioncode = from array in sqliteUtil.QueryTable("SUB_SECTION")
|
|||
|
|
where array[2] == modifyclassfiycode
|
|||
|
|
select array; //找到子分部工程的值
|
|||
|
|
if (!subsectioncode.Any())
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "分类编码不存在;";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
Regex regionPattern = null;
|
|||
|
|
if (index == 0)
|
|||
|
|
{
|
|||
|
|
regionPattern = new Regex(@"^\((((B|0)\d{2}){2}\d)|(\d{3})\)$");
|
|||
|
|
}
|
|||
|
|
else if (index == 1)
|
|||
|
|
{
|
|||
|
|
regionPattern = new Regex(@"^\((\d+[A-Z]+)|((\d+[A-Z]+){2})\)$");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (regionPattern == null)
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("提示", "未选择标准");
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var regionCode = regionPattern.Match(lastCode);
|
|||
|
|
if (string.IsNullOrEmpty(regionCode.Value))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "预留区域码格式错误或不存在;";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
lastCode = lastCode.Substring(lastCode.IndexOf(")", StringComparison.Ordinal) + 1);
|
|||
|
|
|
|||
|
|
Regex componentPattern = new Regex("^[A-Z]+");
|
|||
|
|
var componentCode = componentPattern.Match(lastCode);
|
|||
|
|
|
|||
|
|
var mappingstr = modifyclassfiycode.Remove(modifyclassfiycode.Length - 1, 1) + "x";
|
|||
|
|
var enumerable = from array in sqliteUtil.QueryTable("COM")
|
|||
|
|
where (array[2] == modifyclassfiycode) ^ (mappingstr == array[2])
|
|||
|
|
select array[3]; //查找分类下的构件编码
|
|||
|
|
if (string.IsNullOrEmpty(componentCode.Value))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "构件码格式错误;";
|
|||
|
|
var list = enumerable.ToList();
|
|||
|
|
if (!list.Contains(componentCode.Value))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "构件码不存在;";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
lastCode = lastCode.TrimStart(componentCode.Value.ToCharArray());
|
|||
|
|
|
|||
|
|
Regex sequePattern = new Regex(@"^\d{4}$");
|
|||
|
|
var sequeCode = sequePattern.Match(lastCode);
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(sequeCode.Value))
|
|||
|
|
{
|
|||
|
|
item.IsError = true;
|
|||
|
|
item.ErrorMessages += "序列码错误;";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
result:
|
|||
|
|
if (item.IsError)
|
|||
|
|
{
|
|||
|
|
ErrorTaskItems.Add(item);
|
|||
|
|
}
|
|||
|
|
//string region = lastCode.Substring(lastCode.IndexOf("(") + 1, lastCode.IndexOf(")"));
|
|||
|
|
//if (!Regex.IsMatch(region, @"((B|0)\d{2}){2}\d") || !Regex.IsMatch(region, @"\d{3}"))
|
|||
|
|
//{
|
|||
|
|
// item.ErrorMessages += "预留区域码有误";
|
|||
|
|
//}
|
|||
|
|
//string componentcode = lastCode.Substring(lastCode.IndexOf(")"), lastCode.Length - 4);
|
|||
|
|
//if (componentcode)
|
|||
|
|
//{
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TaskDialog.Show("提示", "校验完成");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|