249 lines
7.9 KiB
C#
249 lines
7.9 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Collections.ObjectModel;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text.RegularExpressions;
|
|||
|
|
using System.Windows;
|
|||
|
|
using Autodesk.Revit.UI;
|
|||
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|||
|
|
using CommunityToolkit.Mvvm.Input;
|
|||
|
|
using Sai.Database.Shared;
|
|||
|
|
|
|||
|
|
namespace Sai.Common.Shared.WBSCoder
|
|||
|
|
{
|
|||
|
|
public partial class WbsCodeGeneratorViewModel : ObservableObject
|
|||
|
|
{
|
|||
|
|
public WbsCodeGeneratorViewModel(CheckCodeViewModel viewModel)
|
|||
|
|
{
|
|||
|
|
sqliteUtil = viewModel.SqliteUtil;
|
|||
|
|
EngineerCategories = viewModel.EngineerCategories;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private readonly SqliteUtil sqliteUtil;
|
|||
|
|
|
|||
|
|
private ObservableCollection<WBSData> engineerCategories;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private string projectCode;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private string regionCode;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedCategory;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedComponentCode;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedSection;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedSubSection;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedSubUnit;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private WBSData selectedUnit;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private string sequenceCode;
|
|||
|
|
|
|||
|
|
[ObservableProperty] private string wbsCode;
|
|||
|
|
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> UnitEngineers { get; set; } = new();
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> SubUnitEngineers { get; set; } = new();
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> SectionEngineers { get; set; } = new();
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> SubSectionEngineers { get; set; } = new();
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> ComponentCodes { get; set; } = new();
|
|||
|
|
|
|||
|
|
public ObservableCollection<WBSData> EngineerCategories { get; set; }
|
|||
|
|
|
|||
|
|
[RelayCommand(CanExecute = nameof(ExistCode))]
|
|||
|
|
private void CopyToClipBoard(object obj)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
Clipboard.SetText(obj.ToString());
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
TaskDialog.Show("错误", "剪切板无法使用");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private bool ExistCode()
|
|||
|
|
{
|
|||
|
|
return !string.IsNullOrEmpty(WbsCode);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetComponentCodes()
|
|||
|
|
{
|
|||
|
|
ComponentCodes?.Clear();
|
|||
|
|
|
|||
|
|
if (SelectedSubSection != null)
|
|||
|
|
{
|
|||
|
|
var str = SelectedSubSection.HierarchicalCode;
|
|||
|
|
var value = str.Remove(str.Length - 1, 1) + "x";
|
|||
|
|
var wbsdatas = from array in sqliteUtil.QueryTable("COM")
|
|||
|
|
where array[2].StartsWith(str) ^ array[2].StartsWith(value)
|
|||
|
|
select new WBSData { Name = array[4], WbsCode = array[3], HierarchicalCode = array[2] };
|
|||
|
|
|
|||
|
|
foreach (var data in wbsdatas)
|
|||
|
|
{
|
|||
|
|
ComponentCodes.Add(data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
OverrideWbsCode();
|
|||
|
|
|
|||
|
|
//if (selectedSubSection != null)
|
|||
|
|
//{
|
|||
|
|
// var wbsdatas = from array in sQLiteUtil.QueryTable("COM")
|
|||
|
|
// where array[2].StartsWith(selectedSubSection.HierarchicalCode)
|
|||
|
|
// select new WBSData() { Name = array[4], WbsCode = array[3], HierarchicalCode = array[2] };
|
|||
|
|
// if (wbsdatas.Count() == 0)
|
|||
|
|
// {
|
|||
|
|
// var str = selectedSubSection.HierarchicalCode;
|
|||
|
|
// var mappingstr = str.Remove(str.Length - 1, 1) + "x";
|
|||
|
|
// wbsdatas = from array in sQLiteUtil.QueryTable("COM")
|
|||
|
|
// where array[2].StartsWith(mappingstr)
|
|||
|
|
// select new WBSData() { Name = array[4], WbsCode = array[3], HierarchicalCode = array[2] };
|
|||
|
|
// }
|
|||
|
|
// foreach (var data in wbsdatas)
|
|||
|
|
// {
|
|||
|
|
// ComponentCodes.Add(data);
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取数据
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="tableName"></param>
|
|||
|
|
/// <param name="selectedData"></param>
|
|||
|
|
/// <param name="datas"></param>
|
|||
|
|
private void GetData(string tableName, WBSData selectedData, ObservableCollection<WBSData> datas)
|
|||
|
|
{
|
|||
|
|
datas?.Clear();
|
|||
|
|
|
|||
|
|
if (selectedData != null)
|
|||
|
|
{
|
|||
|
|
IEnumerable<WBSData> wbsdatas = from array in sqliteUtil.QueryTable(tableName)
|
|||
|
|
where array[2].StartsWith(selectedData.HierarchicalCode)
|
|||
|
|
select new WBSData { Name = array[4], WbsCode = array[3], HierarchicalCode = array[2] };
|
|||
|
|
|
|||
|
|
foreach (var data in wbsdatas)
|
|||
|
|
{
|
|||
|
|
datas.Add(data);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
OverrideWbsCode();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetSectionEngineers()
|
|||
|
|
{
|
|||
|
|
GetData("SECTION", SelectedSubUnit, SectionEngineers);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetSubSectionEngineers()
|
|||
|
|
{
|
|||
|
|
GetData("SUB_SECTION", SelectedSection, SubSectionEngineers);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetSubUnitEngineers()
|
|||
|
|
{
|
|||
|
|
GetData("SUB_UNIT", SelectedUnit, SubUnitEngineers);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void GetUnits()
|
|||
|
|
{
|
|||
|
|
GetData("UNIT", SelectedCategory, UnitEngineers);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[RelayCommand]
|
|||
|
|
private void OverrideWbsCode()
|
|||
|
|
{
|
|||
|
|
string str = string.Empty;
|
|||
|
|
if (!string.IsNullOrEmpty(projectCode) && Regex.IsMatch(projectCode, @"[A-Z]{2,}\d*"))
|
|||
|
|
{
|
|||
|
|
str = $"{projectCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (SelectedCategory != null)
|
|||
|
|
{
|
|||
|
|
str += $"-{SelectedCategory.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (SelectedUnit != null)
|
|||
|
|
{
|
|||
|
|
str += $"{SelectedUnit.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (SelectedSubUnit != null)
|
|||
|
|
{
|
|||
|
|
str += $"{SelectedSubUnit.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (SelectedSection != null)
|
|||
|
|
{
|
|||
|
|
str += $"{selectedSection.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (SelectedSubSection != null)
|
|||
|
|
{
|
|||
|
|
str += $"{SelectedSubSection.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(regionCode) || SelectedComponentCode != null || !string.IsNullOrEmpty(sequenceCode))
|
|||
|
|
{
|
|||
|
|
str += "-";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(regionCode))
|
|||
|
|
{
|
|||
|
|
str += $"({regionCode})";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (selectedComponentCode != null)
|
|||
|
|
{
|
|||
|
|
str += $"{selectedComponentCode.WbsCode}";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(sequenceCode))
|
|||
|
|
{
|
|||
|
|
var canParse = int.TryParse(SequenceCode, out int i);
|
|||
|
|
if (canParse && i.ToString().Length < 5)
|
|||
|
|
{
|
|||
|
|
str += $"{i:0000}";
|
|||
|
|
//if (i < 10 && i > 0)
|
|||
|
|
//{
|
|||
|
|
// str += $"000{i}";
|
|||
|
|
//}
|
|||
|
|
//else if (i >= 10 && i < 100)
|
|||
|
|
//{
|
|||
|
|
// str += $"00{i}";
|
|||
|
|
//}
|
|||
|
|
//else if (i >= 100 && i < 1000)
|
|||
|
|
//{
|
|||
|
|
// str += $"0{i}";
|
|||
|
|
//}
|
|||
|
|
//else
|
|||
|
|
//{
|
|||
|
|
// str += "0001";
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
str += "0001";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WbsCode = str;
|
|||
|
|
//WBSCODE = $"{projectCode}-{selectedCategory?.WbsCode}-{selectedUnit?.WbsCode}-{selectedSubUnit?.WbsCode}-{selectedSection?.WbsCode}-{selectedSubSection?.WbsCode}-({regionCode}){selectedComponentCode?.WbsCode}";
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|