CommonHelper还原
This commit is contained in:
@@ -112,11 +112,11 @@ namespace Pilot_KD_Parino.Common
|
|||||||
}
|
}
|
||||||
else if (FType == "SX-1" || FType == "SX-2")
|
else if (FType == "SX-1" || FType == "SX-2")
|
||||||
{
|
{
|
||||||
#region SX类型:按五大类结构生成(设备层、通讯层、应用管理层、线缆施工费用、技术服务费)
|
#region 这里开始复制
|
||||||
// 存储过程返回的第3个结果集(Tables[2])字段顺序:
|
// 假设模板中的表格是第一个表格
|
||||||
// 0=fseq, 1=fname, 2=FSPECIFICATION, 3=F_103(品牌), 4=FLOOR(FQTY), 5=FNAME(单位),
|
|
||||||
// 6=FTAXPRICE, 7=FALLAMOUNT_LC, 8=FNOTE, 9=FType(F_Projecttype), 10=FALLAMOUNT, 11=FALLAMOUNT2
|
|
||||||
var table = document.Tables[2];
|
var table = document.Tables[2];
|
||||||
|
//// 清空表格中的所有行(除了表头,如果有的话)
|
||||||
|
//// 注意:这里假设第一行是表头,不删除
|
||||||
Row previousRowNew = (Row)table.Rows[1];
|
Row previousRowNew = (Row)table.Rows[1];
|
||||||
Row previousRowthreeNew = (Row)table.Rows[2];
|
Row previousRowthreeNew = (Row)table.Rows[2];
|
||||||
Row previousRowfourNew = (Row)table.Rows[3];
|
Row previousRowfourNew = (Row)table.Rows[3];
|
||||||
@@ -125,140 +125,46 @@ namespace Pilot_KD_Parino.Common
|
|||||||
table.Rows[i].Remove();
|
table.Rows[i].Remove();
|
||||||
}
|
}
|
||||||
var datatable2 = data.Tables[2];
|
var datatable2 = data.Tables[2];
|
||||||
|
|
||||||
// 定义五大类及其名称(顺序:1-5对应F_Projecttype的值)
|
// 使用LINQ来获取去重后的FType字段
|
||||||
List<string> categoryList = new List<string> { "设备层", "通讯层", "应用管理层", "线缆施工费用", "技术服务费" };
|
var DistinctFTypes = datatable2.AsEnumerable()
|
||||||
|
.Select(row => row.Field<string>("FType"))
|
||||||
// 获取系统总价(从第一行数据获取,所有行的FALLAMOUNT值相同)
|
.Distinct()
|
||||||
string systemTotalAmount = "0.00";
|
.ToList();
|
||||||
if (datatable2.Rows.Count > 0)
|
int Index = DistinctFTypes.Count;
|
||||||
|
foreach (var item in DistinctFTypes)
|
||||||
{
|
{
|
||||||
systemTotalAmount = Convert.ToString(datatable2.Rows[0][10]); // FALLAMOUNT
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按F_Projecttype分类处理(从5到1倒序插入,确保最终显示顺序为1→5)
|
|
||||||
for (int categoryIndex = 5; categoryIndex >= 1; categoryIndex--)
|
|
||||||
{
|
|
||||||
// 筛选当前类别的数据(FType字段对应F_Projecttype,索引9)
|
|
||||||
var Rows = datatable2.AsEnumerable()
|
|
||||||
.Where(t => Convert.ToInt32(t[9]) == categoryIndex) // FType字段(索引9)
|
|
||||||
.OrderBy(t => Convert.ToInt32(t[0])) // 按fseq排序
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
string categoryName = categoryList[categoryIndex - 1];
|
|
||||||
Row previousRow = previousRowNew;
|
Row previousRow = previousRowNew;
|
||||||
var previousRowthree = previousRowthreeNew;
|
var previousRowthree = previousRowthreeNew;
|
||||||
var previousRowfour = previousRowfourNew;
|
var previousRowfour = previousRowfourNew;
|
||||||
|
//插入组合中具体的数据行
|
||||||
// 如果该类别没有数据,创建空行
|
var Rows = datatable2.AsEnumerable().Where(t => Convert.ToString(t["FType"]) == item).ToList();
|
||||||
if (Rows == null || Rows.Count == 0)
|
//插入一个组合
|
||||||
|
#region
|
||||||
|
Row newRowfour = table.InsertRow(previousRowfour, 1);
|
||||||
|
newRowfour.Cells[1].ReplaceText("{9}", Convert.ToString(Rows[0][11]));
|
||||||
|
int j = 0;
|
||||||
|
foreach (var Row in Rows)
|
||||||
{
|
{
|
||||||
// 1. 插入小计行(显示"小计"和0.00)
|
Row newRowthree = table.InsertRow(previousRowthree, 1 + j);
|
||||||
Row newRowfour = table.InsertRow(previousRowfour, 1);
|
|
||||||
SetRowBorder(newRowfour);
|
|
||||||
newRowfour.Cells[0].ReplaceText("{0}", "");
|
|
||||||
newRowfour.Cells[1].ReplaceText("{1}", "小计");
|
|
||||||
for (int i = 2; i < 7; i++)
|
|
||||||
{
|
|
||||||
if (i < newRowfour.Cells.Count)
|
|
||||||
{
|
|
||||||
newRowfour.Cells[i].ReplaceText("{" + i.ToString() + "}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newRowfour.Cells.Count > 7)
|
|
||||||
{
|
|
||||||
newRowfour.Cells[7].ReplaceText("{7}", "0.00"); // 总价列显示0.00
|
|
||||||
}
|
|
||||||
if (newRowfour.Cells.Count > 8)
|
|
||||||
{
|
|
||||||
newRowfour.Cells[8].ReplaceText("{8}", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 插入空明细行(所有占位符清空)
|
|
||||||
Row newRowthree = table.InsertRow(previousRowthree, 1);
|
|
||||||
SetRowBorder(newRowthree);
|
|
||||||
for (int i = 0; i < 9; i++)
|
for (int i = 0; i < 9; i++)
|
||||||
{
|
{
|
||||||
if (i < newRowthree.Cells.Count)
|
newRowthree.Cells[i].ReplaceText("{" + i.ToString() + "}", Convert.ToString(Row[i]));
|
||||||
{
|
|
||||||
newRowthree.Cells[i].ReplaceText("{" + i.ToString() + "}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 插入分类标题行
|
|
||||||
Row newRow = table.InsertRow(previousRow, 1);
|
|
||||||
SetRowBorder(newRow);
|
|
||||||
newRow.Cells[0].ReplaceText("{0}", string.Format("{0}、{1}", ConvertToChineseUppercase(categoryIndex), categoryName));
|
|
||||||
for (int i = 1; i < newRow.Cells.Count; i++)
|
|
||||||
{
|
|
||||||
if (i < newRow.Cells.Count)
|
|
||||||
{
|
|
||||||
newRow.Cells[i].ReplaceText("{" + i.ToString() + "}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// 1. 插入小计行(显示"小计"和类别小计金额)
|
|
||||||
Row newRowfour = table.InsertRow(previousRowfour, 1);
|
|
||||||
SetRowBorder(newRowfour);
|
|
||||||
newRowfour.Cells[0].ReplaceText("{0}", "");
|
|
||||||
newRowfour.Cells[1].ReplaceText("{1}", "小计");
|
|
||||||
for (int i = 2; i < 7; i++)
|
|
||||||
{
|
|
||||||
if (i < newRowfour.Cells.Count)
|
|
||||||
{
|
|
||||||
newRowfour.Cells[i].ReplaceText("{" + i.ToString() + "}", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 小计金额从FALLAMOUNT2获取(索引11),显示在总价列(索引7)
|
|
||||||
if (newRowfour.Cells.Count > 7)
|
|
||||||
{
|
|
||||||
string subtotalAmount = Convert.ToString(Rows[0][11]); // FALLAMOUNT2
|
|
||||||
newRowfour.Cells[7].ReplaceText("{7}", subtotalAmount);
|
|
||||||
}
|
|
||||||
if (newRowfour.Cells.Count > 8)
|
|
||||||
{
|
|
||||||
newRowfour.Cells[8].ReplaceText("{8}", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. 插入明细行(字段映射:索引0-8对应模板占位符{0}-{8})
|
|
||||||
int j = 0;
|
|
||||||
foreach (var Row in Rows)
|
|
||||||
{
|
|
||||||
Row newRowthree = table.InsertRow(previousRowthree, 1 + j);
|
|
||||||
SetRowBorder(newRowthree);
|
|
||||||
for (int i = 0; i < 9; i++)
|
|
||||||
{
|
|
||||||
if (i < newRowthree.Cells.Count)
|
|
||||||
{
|
|
||||||
newRowthree.Cells[i].ReplaceText("{" + i.ToString() + "}", Convert.ToString(Row[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. 插入分类标题行
|
|
||||||
Row newRow = table.InsertRow(previousRow, 1);
|
|
||||||
SetRowBorder(newRow);
|
|
||||||
newRow.Cells[0].ReplaceText("{0}", string.Format("{0}、{1}", ConvertToChineseUppercase(categoryIndex), categoryName));
|
|
||||||
for (int i = 1; i < newRow.Cells.Count; i++)
|
|
||||||
{
|
|
||||||
if (i < newRow.Cells.Count)
|
|
||||||
{
|
|
||||||
newRow.Cells[i].ReplaceText("{" + i.ToString() + "}", "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
document.ReplaceText("{10}", Convert.ToString(Row[10]));
|
||||||
|
j++;
|
||||||
}
|
}
|
||||||
|
Row newRow = table.InsertRow(previousRow, 1);
|
||||||
|
newRow.Cells[0].ReplaceText("{0}", string.Format("{0}、{1}", ConvertToChineseUppercase(Index), Convert.ToString(item)));
|
||||||
|
#endregion
|
||||||
|
Index--;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 替换系统总价占位符(在文档中全局替换{10})
|
|
||||||
document.ReplaceText("{10}", systemTotalAmount);
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
else if (!List.Contains(FType) && FType != "HH" && FType != "TH")
|
else if (!List.Contains(FType) && FType != "HH" && FType != "TH")
|
||||||
{
|
{
|
||||||
|
// 假设模板中的表格是第一个表格
|
||||||
var table = document.Tables[1];
|
var table = document.Tables[1];
|
||||||
Row previousRow = (Row)table.Rows[1];
|
Row previousRow = (Row)table.Rows[1];
|
||||||
//for (int i = table.Rows.Count - 4; i >= 1; i--) // 从最后一行开始删除,避免索引超出范围
|
//for (int i = table.Rows.Count - 4; i >= 1; i--) // 从最后一行开始删除,避免索引超出范围
|
||||||
@@ -273,7 +179,7 @@ namespace Pilot_KD_Parino.Common
|
|||||||
foreach (var cell in newRow.Cells)
|
foreach (var cell in newRow.Cells)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
// 注意:如果单元格中有多个段落或更复杂的结构,你可能需要遍历它们并分别复制样式
|
||||||
Border Border = new Border() { Size = BorderSize.four, Color = Color.Black };
|
Border Border = new Border() { Size = BorderSize.four, Color = Color.Black };
|
||||||
cell.SetBorder(TableCellBorderType.Left, Border);
|
cell.SetBorder(TableCellBorderType.Left, Border);
|
||||||
cell.SetBorder(TableCellBorderType.Right, Border);
|
cell.SetBorder(TableCellBorderType.Right, Border);
|
||||||
@@ -1113,7 +1019,7 @@ namespace Pilot_KD_Parino.Common
|
|||||||
{
|
{
|
||||||
FBILLNO = "";
|
FBILLNO = "";
|
||||||
Id = "";
|
Id = "";
|
||||||
|
|
||||||
// 调用保存操作
|
// 调用保存操作
|
||||||
IOperationResult saveResult = BusinessDataServiceHelper.Save(
|
IOperationResult saveResult = BusinessDataServiceHelper.Save(
|
||||||
ctx,
|
ctx,
|
||||||
@@ -1152,10 +1058,10 @@ namespace Pilot_KD_Parino.Common
|
|||||||
else if (saveResult.IsSuccess == false)
|
else if (saveResult.IsSuccess == false)
|
||||||
{
|
{
|
||||||
saveResult.IsShowMessage = true;
|
saveResult.IsShowMessage = true;
|
||||||
|
|
||||||
//billView.ShowErrMessage(saveResult.InteractionContext.SimpleMessage);
|
//billView.ShowErrMessage(saveResult.InteractionContext.SimpleMessage);
|
||||||
|
|
||||||
var dd=saveResult.ValidationErrors.FirstOrDefault();
|
var dd = saveResult.ValidationErrors.FirstOrDefault();
|
||||||
if (dd != null)
|
if (dd != null)
|
||||||
billView.ShowErrMessage(dd.Message);
|
billView.ShowErrMessage(dd.Message);
|
||||||
else
|
else
|
||||||
@@ -1614,21 +1520,5 @@ namespace Pilot_KD_Parino.Common
|
|||||||
CommonHelper.SaveBill(ctx, billView, saveOption, true, out FID, out FBILLNO);
|
CommonHelper.SaveBill(ctx, billView, saveOption, true, out FID, out FBILLNO);
|
||||||
return FBILLNO;
|
return FBILLNO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 设置Word表格行的边框样式
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="row">表格行</param>
|
|
||||||
private static void SetRowBorder(Row row)
|
|
||||||
{
|
|
||||||
foreach (var cell in row.Cells)
|
|
||||||
{
|
|
||||||
Border border = new Border() { Size = BorderSize.four, Color = Color.Black };
|
|
||||||
cell.SetBorder(TableCellBorderType.Left, border);
|
|
||||||
cell.SetBorder(TableCellBorderType.Right, border);
|
|
||||||
cell.SetBorder(TableCellBorderType.Top, border);
|
|
||||||
cell.SetBorder(TableCellBorderType.Bottom, border);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user