添加项目文件。
This commit is contained in:
56
ExportExcelTest/Models/DetailItem.cs
Normal file
56
ExportExcelTest/Models/DetailItem.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 细类
|
||||
/// </summary>
|
||||
public class DetailItem : BaseItem
|
||||
{
|
||||
public DetailItem(string name, SubItem subItem) : base(name)
|
||||
{
|
||||
SubItem = subItem;
|
||||
MeasureTypes = new HashSet<Measurement>();
|
||||
}
|
||||
|
||||
public Measurement this[int index]
|
||||
{
|
||||
get => MeasureTypes.ElementAt(index);
|
||||
}
|
||||
/// <summary>
|
||||
/// 细类,父级
|
||||
/// </summary>
|
||||
public SubItem SubItem { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder($"{nameof(DetailItem)}:{Name};");
|
||||
if (MeasureTypes.Count == 0)
|
||||
{
|
||||
return sb.Append("无;").ToString();
|
||||
}
|
||||
foreach (var item in MeasureTypes)
|
||||
{
|
||||
sb.AppendLine($"{item}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public HashSet<Measurement> MeasureTypes { get; private set; }
|
||||
|
||||
public Measurement AddMeature(MeasurementUnit unit)
|
||||
{
|
||||
Measurement measure = new Measurement(unit, this);
|
||||
if (MeasureTypes == null)
|
||||
{
|
||||
MeasureTypes = new HashSet<Measurement>();
|
||||
}
|
||||
MeasureTypes.Add(measure);
|
||||
return measure;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
17
ExportExcelTest/Models/EnumExtensions.cs
Normal file
17
ExportExcelTest/Models/EnumExtensions.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
static class EnumExtensions
|
||||
{
|
||||
public static string GetDescription(this Enum val)
|
||||
{
|
||||
var field = val.GetType().GetField(val.ToString());
|
||||
var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
|
||||
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
154
ExportExcelTest/Models/Measurement.cs
Normal file
154
ExportExcelTest/Models/Measurement.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using CustomOpenItemAddins;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
public class Measurement
|
||||
{
|
||||
/// <summary>
|
||||
/// 备注说明
|
||||
/// </summary>
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
public Measurement(MeasurementUnit measurementUnit, DetailItem detail)
|
||||
{
|
||||
Detail = detail;
|
||||
Unit = measurementUnit;
|
||||
//根据围岩类型设置支护类型
|
||||
switch (Detail.SubItem.Primary.Table.TypeOfSurrounding)
|
||||
{
|
||||
case TypeOfSurrounding.LevelTwo:
|
||||
Proofs = new HashSet<Proof>(1) { new Proof("Ⅱ级限排型") };
|
||||
break;
|
||||
case TypeOfSurrounding.LevelThree:
|
||||
Proofs = new HashSet<Proof>(9)
|
||||
{
|
||||
new Proof("Ⅲ级限排型"),
|
||||
new Proof("Ⅲ级防水型"),
|
||||
new Proof("Ⅲ级抗水压Ⅰ型"),
|
||||
new Proof("Ⅲ级抗水压Ⅱ型"),
|
||||
new Proof("Ⅲ级抗水压Ⅲ型"),
|
||||
new Proof("Ⅲ级导洞1"),
|
||||
new Proof("Ⅲ级导洞2"),
|
||||
new Proof("Ⅲ级盾构拆解段"),
|
||||
new Proof("Ⅲ级"),
|
||||
};
|
||||
break;
|
||||
case TypeOfSurrounding.LevelFour:
|
||||
Proofs = new HashSet<Proof>(6)
|
||||
{
|
||||
new Proof("Ⅳ a级限排型"),
|
||||
new Proof("Ⅳ b级限排型"),
|
||||
new Proof("Ⅳ a级防水型"),
|
||||
new Proof("Ⅳ级平移横通道防水型"),
|
||||
new Proof("Ⅳ级盾构拆解段"),
|
||||
new Proof("Ⅳ级"),
|
||||
};
|
||||
break;
|
||||
case TypeOfSurrounding.LevelFive:
|
||||
Proofs = new HashSet<Proof>(7)
|
||||
{
|
||||
new Proof("Ⅴ a级限排型"),
|
||||
new Proof("Ⅴ b级限排型"),
|
||||
new Proof("Ⅴ a级防水型"),
|
||||
new Proof("Ⅴ a级防水型"),
|
||||
new Proof("Ⅴ级导洞1"),
|
||||
new Proof("Ⅴ级导洞2"),
|
||||
new Proof("Ⅴ级"),
|
||||
};
|
||||
break;
|
||||
case TypeOfSurrounding.LevelSix:
|
||||
Proofs = new HashSet<Proof>(4)
|
||||
{
|
||||
new Proof("Ⅵ级防水型"),
|
||||
new Proof("Ⅵ级导洞1"),
|
||||
new Proof("Ⅵ级导洞2"),
|
||||
new Proof("Ⅵ级"),
|
||||
};
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder($"计量方式:{Mode.GetDescription()};计量单位{Unit.GetDescription()};");
|
||||
foreach (var item in Proofs)
|
||||
{
|
||||
sb.AppendLine($"{item}");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 父级细类
|
||||
/// </summary>
|
||||
public DetailItem Detail { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 计量方式
|
||||
/// </summary>
|
||||
public MeasurementMode Mode
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Unit)
|
||||
{
|
||||
case MeasurementUnit.Count:
|
||||
case MeasurementUnit.Set:
|
||||
case MeasurementUnit.Stick:
|
||||
case MeasurementUnit.Hole:
|
||||
return MeasurementMode.Count;
|
||||
case MeasurementUnit.Meter:
|
||||
case MeasurementUnit.Millimeter:
|
||||
case MeasurementUnit.Centimeter:
|
||||
return MeasurementMode.Length;
|
||||
case MeasurementUnit.SquareMeter:
|
||||
return MeasurementMode.Area;
|
||||
case MeasurementUnit.CubicMeter:
|
||||
return MeasurementMode.Volume;
|
||||
default:
|
||||
return MeasurementMode.Unknow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算规则
|
||||
/// </summary>
|
||||
public string CalculationRule { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 计量单位
|
||||
/// </summary>
|
||||
public MeasurementUnit Unit { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 合计计算结果
|
||||
/// </summary>
|
||||
public object Total { get { return Proofs.Sum(x => x.Amount); } }
|
||||
|
||||
/// <summary>
|
||||
/// 防水类型
|
||||
/// </summary>
|
||||
public HashSet<Proof> Proofs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置值
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public Measurement SetProof(int index, double value)
|
||||
{
|
||||
var proof = Proofs.ElementAt(index);
|
||||
proof.Measurement = this;
|
||||
proof.Amount = value;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
52
ExportExcelTest/Models/MeasurementUnit.cs
Normal file
52
ExportExcelTest/Models/MeasurementUnit.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.ComponentModel;
|
||||
|
||||
/// <summary>
|
||||
/// 计算单位
|
||||
/// </summary>
|
||||
public enum MeasurementUnit
|
||||
{
|
||||
[Description("个")]
|
||||
Count,
|
||||
[Description("套")]
|
||||
Set,
|
||||
[Description("根")]
|
||||
Stick,
|
||||
[Description("孔")]
|
||||
Hole,
|
||||
/// <summary>
|
||||
/// 米
|
||||
/// </summary>
|
||||
[Description("m")]
|
||||
Meter,
|
||||
/// <summary>
|
||||
/// 毫米
|
||||
/// </summary>
|
||||
[Description("mm")]
|
||||
Millimeter,
|
||||
/// <summary>
|
||||
/// 厘米
|
||||
/// </summary>
|
||||
[Description("cm")]
|
||||
Centimeter,
|
||||
/// <summary>
|
||||
/// 吨
|
||||
/// </summary>
|
||||
[Description("t")]
|
||||
Kilonewton,
|
||||
/// <summary>
|
||||
/// 千克
|
||||
/// </summary>
|
||||
[Description("kg")]
|
||||
Kilogram,
|
||||
/// <summary>
|
||||
/// 平方米
|
||||
/// </summary>
|
||||
[Description("m²")]
|
||||
SquareMeter,
|
||||
/// <summary>
|
||||
/// 立方米
|
||||
/// </summary>
|
||||
[Description("m³")]
|
||||
CubicMeter,
|
||||
}
|
||||
|
||||
80
ExportExcelTest/Models/PrimaryItem.cs
Normal file
80
ExportExcelTest/Models/PrimaryItem.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
public class BaseItem
|
||||
{
|
||||
public BaseItem(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 一级开项
|
||||
/// </summary>
|
||||
public class PrimaryItem : BaseItem
|
||||
{
|
||||
public PrimaryItem(string name, SheetTable table) : base(name)
|
||||
{
|
||||
Table = table;
|
||||
SubCategories = new HashSet<SubItem>();
|
||||
}
|
||||
/// <summary>
|
||||
/// 表名
|
||||
/// </summary>
|
||||
public SheetTable Table { get; set; }
|
||||
public SubItem this[int index]
|
||||
{
|
||||
get => SubCategories.ElementAt(index);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder($"<主项>{Name};");
|
||||
if (SubCategories.Count == 0)
|
||||
{
|
||||
return sb.Append("无;").ToString();
|
||||
}
|
||||
foreach (var item in SubCategories)
|
||||
{
|
||||
sb.AppendLine($"{item}");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
/// <summary>
|
||||
/// 子类项目
|
||||
/// </summary>
|
||||
public HashSet<SubItem> SubCategories { get; private set; }
|
||||
|
||||
public SubItem AddSub(string subName)
|
||||
{
|
||||
var sub = new SubItem(subName, this);
|
||||
|
||||
if (SubCategories == null)
|
||||
{
|
||||
SubCategories = new HashSet<SubItem>();
|
||||
}
|
||||
SubCategories.Add(sub);
|
||||
return sub;
|
||||
}
|
||||
public void AddSubCategories(List<SubItem> subs)
|
||||
{
|
||||
if (SubCategories == null)
|
||||
{
|
||||
SubCategories = new HashSet<SubItem>();
|
||||
}
|
||||
|
||||
subs.ForEach(x =>
|
||||
{
|
||||
x.Primary = this;
|
||||
SubCategories.Add(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
ExportExcelTest/Models/Proof.cs
Normal file
36
ExportExcelTest/Models/Proof.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
|
||||
using System.Linq;
|
||||
|
||||
using CustomOpenAddins.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 支护类型
|
||||
/// </summary>
|
||||
public class Proof
|
||||
{
|
||||
public Proof(string typeOfSupport)
|
||||
{
|
||||
TypeOfSupport = typeOfSupport;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"支护类型:{TypeOfSupport};工程量:{Amount}{Measurement.Unit.GetDescription()}";
|
||||
}
|
||||
/// <summary>
|
||||
/// 所属计量方式
|
||||
/// </summary>
|
||||
public Measurement Measurement { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工程量
|
||||
/// </summary>
|
||||
public double Amount { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 支护类型
|
||||
/// </summary>
|
||||
public string TypeOfSupport { get; }
|
||||
}
|
||||
|
||||
60
ExportExcelTest/Models/SheetTable.cs
Normal file
60
ExportExcelTest/Models/SheetTable.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 表单
|
||||
/// </summary>
|
||||
public class SheetTable
|
||||
{
|
||||
public SheetTable(TypeOfSurrounding typeOfSurrounding)
|
||||
{
|
||||
TypeOfSurrounding = typeOfSurrounding;
|
||||
MainCategories = new HashSet<PrimaryItem>();
|
||||
}
|
||||
|
||||
public PrimaryItem this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (index < 0 || index > MainCategories.Count - 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("索引越界");
|
||||
}
|
||||
return MainCategories.ElementAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
public HashSet<PrimaryItem> MainCategories { get; private set; }
|
||||
public string Name => $"{TypeOfSurrounding.GetDescription()}工程量";
|
||||
|
||||
public TypeOfSurrounding TypeOfSurrounding { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 围岩类型
|
||||
///// </summary>
|
||||
//public TypeOfSurrounding TypeOfSurrounding { get; }
|
||||
//TypeOfSurrounding IItem.TypeOfSurrounding { get => TypeOfSurrounding; set => throw new NotImplementedException(); }
|
||||
|
||||
public PrimaryItem AddMain(string mainName)
|
||||
{
|
||||
PrimaryItem mainCategory = new PrimaryItem(mainName, this);
|
||||
if (MainCategories == null)
|
||||
{
|
||||
MainCategories = new HashSet<PrimaryItem>();
|
||||
}
|
||||
MainCategories.Add(mainCategory);
|
||||
return mainCategory;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
65
ExportExcelTest/Models/SubItem.cs
Normal file
65
ExportExcelTest/Models/SubItem.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 二级开项
|
||||
/// </summary>
|
||||
public class SubItem : BaseItem
|
||||
{
|
||||
public SubItem(string name, PrimaryItem primary) : base(name)
|
||||
{
|
||||
Primary = primary;
|
||||
DetailCategories = new HashSet<DetailItem>();
|
||||
}
|
||||
|
||||
public DetailItem this[int index]
|
||||
{
|
||||
get => DetailCategories.ElementAt(index);
|
||||
}
|
||||
public PrimaryItem Primary { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder($"<子项>{Name};");
|
||||
if (DetailCategories.Count == 0)
|
||||
{
|
||||
return sb.Append("无;").ToString();
|
||||
}
|
||||
foreach (var item in DetailCategories)
|
||||
{
|
||||
sb.AppendLine($"{item}");
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public HashSet<DetailItem> DetailCategories { get; private set; }
|
||||
|
||||
public DetailItem AddDetail(string detailName)
|
||||
{
|
||||
DetailItem detail = new DetailItem(detailName, this);
|
||||
if (DetailCategories == null)
|
||||
{
|
||||
DetailCategories = new HashSet<DetailItem>();
|
||||
}
|
||||
DetailCategories.Add(detail);
|
||||
return detail;
|
||||
}
|
||||
public void AddDetails(List<DetailItem> details)
|
||||
{
|
||||
if (DetailCategories == null)
|
||||
{
|
||||
DetailCategories = new HashSet<DetailItem>();
|
||||
}
|
||||
details.ForEach(x =>
|
||||
{
|
||||
x.SubItem = this;
|
||||
DetailCategories.Add(x);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
ExportExcelTest/Models/TypeOfSurrounding.cs
Normal file
24
ExportExcelTest/Models/TypeOfSurrounding.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace CustomOpenAddins.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 围岩等级
|
||||
/// </summary>
|
||||
public enum TypeOfSurrounding
|
||||
{
|
||||
[Description("Ⅱ级")]
|
||||
LevelTwo = 2,
|
||||
[Description("Ⅲ级")]
|
||||
LevelThree,
|
||||
[Description("Ⅳ级")]
|
||||
LevelFour,
|
||||
[Description("Ⅴ级")]
|
||||
LevelFive,
|
||||
[Description("Ⅵ级")]
|
||||
LevelSix,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user