This commit is contained in:
2026-06-24 20:31:39 +08:00
parent d476c4f4a7
commit c2bc05c2ac
2 changed files with 97 additions and 69 deletions
+85 -61
View File
@@ -4,19 +4,20 @@ namespace BLL
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Data.Linq; using System.Data.Linq;
using System.Text.RegularExpressions;
/// <summary> /// <summary>
/// 通用方法类。 /// ͨ÷
/// </summary> /// </summary>
public static class Funs public static class Funs
{ {
/// <summary> /// <summary>
/// 维护一个DB集合 /// άһDB
/// </summary> /// </summary>
private static Dictionary<int, Model.SGGLDB> dataBaseLinkList = new System.Collections.Generic.Dictionary<int, Model.SGGLDB>(); private static Dictionary<int, Model.SGGLDB> dataBaseLinkList = new System.Collections.Generic.Dictionary<int, Model.SGGLDB>();
/// <summary> /// <summary>
/// 维护一个DB集合 /// άһDB
/// </summary> /// </summary>
public static System.Collections.Generic.Dictionary<int, Model.SGGLDB> DBList public static System.Collections.Generic.Dictionary<int, Model.SGGLDB> DBList
{ {
@@ -27,7 +28,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 数据库连接字符串 /// ݿַ
/// </summary> /// </summary>
private static string connString; private static string connString;
@@ -37,7 +38,7 @@ namespace BLL
public static string usingMatId; public static string usingMatId;
/// <summary> /// <summary>
/// 数据库连结字符串。 /// ݿַ
/// </summary> /// </summary>
public static string ConnString public static string ConnString
{ {
@@ -45,7 +46,7 @@ namespace BLL
{ {
if (connString == null) if (connString == null)
{ {
throw new NotSupportedException("请设置连接字符串!"); throw new NotSupportedException("ַ");
} }
return connString; return connString;
@@ -55,7 +56,7 @@ namespace BLL
{ {
if (connString != null) if (connString != null)
{ {
throw new NotSupportedException("连接已设置!"); throw new NotSupportedException("ã");
} }
connString = value; connString = value;
@@ -69,7 +70,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 单位设置 /// λ
/// </summary> /// </summary>
public static string UnitSet public static string UnitSet
{ {
@@ -78,7 +79,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 路径 /// ·
/// </summary> /// </summary>
public static string RootPath public static string RootPath
{ {
@@ -87,7 +88,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 系统名 /// ϵͳ
/// </summary> /// </summary>
public static string SystemName public static string SystemName
{ {
@@ -95,7 +96,7 @@ namespace BLL
set; set;
} }
/// <summary> /// <summary>
/// AD域名 /// AD
/// </summary> /// </summary>
public static string ADomainUrl public static string ADomainUrl
{ {
@@ -103,7 +104,7 @@ namespace BLL
set; set;
} }
/// <summary> /// <summary>
/// APP下载地址 /// APPصַ
/// </summary> /// </summary>
public static string APPUrl public static string APPUrl
{ {
@@ -121,7 +122,7 @@ namespace BLL
/// <summary> /// <summary>
/// 每页数量 /// ÿҳ
/// </summary> /// </summary>
public static int PageSize public static int PageSize
{ {
@@ -130,7 +131,7 @@ namespace BLL
} = 15; } = 15;
/// <summary> /// <summary>
/// 数据库上下文。 /// ݿġ
/// </summary> /// </summary>
public static Model.SGGLDB DB public static Model.SGGLDB DB
{ {
@@ -146,50 +147,50 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 为目标下拉框加上 "请选择" 项 /// ΪĿ "ѡ"
/// </summary> /// </summary>
/// <param name="DLL">目标下拉框</param> /// <param name="DLL">Ŀ</param>
public static void PleaseSelect(System.Web.UI.WebControls.DropDownList DDL) public static void PleaseSelect(System.Web.UI.WebControls.DropDownList DDL)
{ {
DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- 请选择 -", "0")); DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem("- ѡ -", "0"));
return; return;
} }
/// <summary> /// <summary>
/// 为目标下拉框加上 "请选择" 项 /// ΪĿ "ѡ"
/// </summary> /// </summary>
/// <param name="DLL">目标下拉框</param> /// <param name="DLL">Ŀ</param>
public static void FineUIPleaseSelect(FineUIPro.DropDownList DDL) public static void FineUIPleaseSelect(FineUIPro.DropDownList DDL)
{ {
DDL.Items.Insert(0, new FineUIPro.ListItem("- 请选择 -", BLL.Const._Null)); DDL.Items.Insert(0, new FineUIPro.ListItem("- ѡ -", BLL.Const._Null));
return; return;
} }
/// <summary> /// <summary>
/// 为目标下拉框加上 "重新编制" 项 /// ΪĿ "±"
/// </summary> /// </summary>
/// <param name="DLL">目标下拉框</param> /// <param name="DLL">Ŀ</param>
public static void ReCompileSelect(System.Web.UI.WebControls.DropDownList DDL) public static void ReCompileSelect(System.Web.UI.WebControls.DropDownList DDL)
{ {
DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem("重新编制", "0")); DDL.Items.Insert(0, new System.Web.UI.WebControls.ListItem("±", "0"));
return; return;
} }
/// <summary> /// <summary>
/// 为目标下拉框加上 "重新编制" 项 /// ΪĿ "±"
/// </summary> /// </summary>
/// <param name="DLL">目标下拉框</param> /// <param name="DLL">Ŀ</param>
public static void FineUIReCompileSelect(FineUIPro.DropDownList DDL) public static void FineUIReCompileSelect(FineUIPro.DropDownList DDL)
{ {
DDL.Items.Insert(0, new FineUIPro.ListItem("重新编制", "0")); DDL.Items.Insert(0, new FineUIPro.ListItem("±", "0"));
return; return;
} }
/// <summary> /// <summary>
/// 字符串是否为浮点数 /// ַǷΪ
/// </summary> /// </summary>
/// <param name="decimalStr">要检查的字符串</param> /// <param name="decimalStr">Ҫַ</param>
/// <returns>返回是或否</returns> /// <returns>ǻ</returns>
public static bool IsDecimal(string decimalStr) public static bool IsDecimal(string decimalStr)
{ {
if (String.IsNullOrEmpty(decimalStr)) if (String.IsNullOrEmpty(decimalStr))
@@ -210,10 +211,10 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 判断一个字符串是否是整数 /// жһַǷ
/// </summary> /// </summary>
/// <param name="integerStr">要检查的字符串</param> /// <param name="integerStr">Ҫַ</param>
/// <returns>返回是或否</returns> /// <returns>ǻ</returns>
public static bool IsInteger(string integerStr) public static bool IsInteger(string integerStr)
{ {
if (String.IsNullOrEmpty(integerStr)) if (String.IsNullOrEmpty(integerStr))
@@ -234,10 +235,10 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 获取新的数字 /// ȡµ
/// </summary> /// </summary>
/// <param name="number">要转换的数字</param> /// <param name="number">Ҫת</param>
/// <returns>新的数字</returns> /// <returns>µ</returns>
public static string InterceptDecimal(object number) public static string InterceptDecimal(object number)
{ {
if (number == null) if (number == null)
@@ -284,11 +285,11 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 判断字符串从第n位开始以后是否都为0 /// жַӵʼԺǷΪ0
/// </summary> /// </summary>
/// <param name="number">要判断的字符串</param> /// <param name="number">Ҫжϵַ</param>
/// <param name="n">开始的位数</param> /// <param name="n">ʼλ</param>
/// <returns>false不都为0true都为0</returns> /// <returns>falseΪ0trueΪ0</returns>
public static bool GetStr(string number, int n) public static bool GetStr(string number, int n)
{ {
for (int i = n; i < number.Length; i++) for (int i = n; i < number.Length; i++)
@@ -302,11 +303,11 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 截取字符串长度 /// ȡַ
/// </summary> /// </summary>
/// <param name="str">要截取的字符串</param> /// <param name="str">Ҫȡַ</param>
/// <param name="n">长度</param> /// <param name="n"></param>
/// <returns>截取后字符串</returns> /// <returns>ȡַ</returns>
public static string GetSubStr(object str, object n) public static string GetSubStr(object str, object n)
{ {
if (str != null) if (str != null)
@@ -325,7 +326,7 @@ namespace BLL
/// <summary> /// <summary>
/// 输入文本转换时间类型 /// ıתʱ
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static DateTime? GetNewDateTime(string time) public static DateTime? GetNewDateTime(string time)
@@ -349,7 +350,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 输入文本转换数字 /// ıת
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static decimal? GetNewDecimal(string value) public static decimal? GetNewDecimal(string value)
@@ -373,7 +374,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 输入文本转换数字 /// ıת
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static decimal GetNewDecimalOrZero(string value) public static decimal GetNewDecimalOrZero(string value)
@@ -385,19 +386,42 @@ namespace BLL
{ {
returnValue = decimal.Parse(value); returnValue = decimal.Parse(value);
} }
catch (Exception ex) catch (Exception)
{ {
ErrLogInfo.WriteLog(ex); // 如果直接解析失败(如带单位 "10M", "5KM", "3KG"),取前面的数字部分
return returnValue; try
{
Match match = Regex.Match(value, @"\d+\.?\d*");
if (match.Success && decimal.TryParse(match.Value, out decimal number))
{
returnValue = number;
}
}
catch (Exception ex)
{
ErrLogInfo.WriteLog(ex);
}
} }
} }
return returnValue; return returnValue;
} }
/// <summary>
/// 从qty字符串中提取单位(如 "10M" → "M", "5KG" → "KG", "33.4 mm" → "mm", "10" → ""
/// </summary>
public static string GetUnitFromQty(string value)
{
if (string.IsNullOrEmpty(value)) return "";
Match match = Regex.Match(value.Trim(), @"^\d+\.?\d*\s*(.*)$");
if (match.Success)
return match.Groups[1].Value.Trim();
return "";
}
/// <summary> /// <summary>
/// 输入文本转换数字类型 /// ıת
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static int? GetNewInt(string value) public static int? GetNewInt(string value)
@@ -421,7 +445,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 输入文本转换数字类型 /// ıת
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static int GetNewIntOrZero(string value) public static int GetNewIntOrZero(string value)
@@ -443,7 +467,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 指定上传文件的名称 /// ָϴļ
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static string GetNewFileName() public static string GetNewFileName()
@@ -453,7 +477,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 根据标识返回字符串list /// ݱʶַlist
/// </summary> /// </summary>
/// <param name="str"></param> /// <param name="str"></param>
/// <param name="n"></param> /// <param name="n"></param>
@@ -470,24 +494,24 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 根据第一页和第二页行数及总记录数,确定需要打印几页 /// ݵһҳ͵ڶҳܼ¼ȷҪӡҳ
/// </summary> /// </summary>
/// <param name="pageSize1">第一页行数</param> /// <param name="pageSize1">һҳ</param>
/// <param name="pageSize2">第二页行数</param> /// <param name="pageSize2">ڶҳ</param>
/// <param name="count">总记录数</param> /// <param name="count">ܼ¼</param>
/// <returns></returns> /// <returns></returns>
public static int GetPagesCountByPageSize(int pageSize1, int pageSize2, int count) public static int GetPagesCountByPageSize(int pageSize1, int pageSize2, int count)
{ {
int pagesCount = 0; int pagesCount = 0;
if (pageSize1 >= count) //总记录数小于等于第一页行数 if (pageSize1 >= count) //ܼ¼Сڵڵһҳ
{ {
pagesCount = 1; pagesCount = 1;
} }
else if (count > pageSize1 && count <= (pageSize1 + pageSize2)) //总记录数大于第一页行数且小于等于第一页加第二页总行数 else if (count > pageSize1 && count <= (pageSize1 + pageSize2)) //ܼ¼ڵһҳСڵڵһҳӵڶҳ
{ {
pagesCount = 2; pagesCount = 2;
} }
else //总记录数大于第一页加第二页总行数 else //ܼ¼ڵһҳӵڶҳ
{ {
int lastCount = count - pageSize1; int lastCount = count - pageSize1;
decimal c = Convert.ToDecimal(Math.Round(Convert.ToDecimal(lastCount) / Convert.ToDecimal(pageSize2), 2)); decimal c = Convert.ToDecimal(Math.Round(Convert.ToDecimal(lastCount) / Convert.ToDecimal(pageSize2), 2));
@@ -506,7 +530,7 @@ namespace BLL
} }
/// <summary> /// <summary>
/// 获取上次返修情况 /// ȡϴη
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public static string GetRepariMark(string repairMark) public static string GetRepariMark(string repairMark)
@@ -394,7 +394,7 @@ namespace FineUIPro.Web.HJGL.DataIn
row["category"] = item.Value<string>("category"); row["category"] = item.Value<string>("category");
row["description"] = item.Value<string>("description"); row["description"] = item.Value<string>("description");
row["spec"] = item.Value<string>("spec"); row["spec"] = item.Value<string>("spec");
row["qty"] = item.Value<string>("qty").Replace("M","").Replace("m",""); row["qty"] = item.Value<string>("qty");
row["page_no"] = item.Value<string>("page_no"); row["page_no"] = item.Value<string>("page_no");
row["remark"] = item.Value<string>("remark"); row["remark"] = item.Value<string>("remark");
if (string.IsNullOrEmpty(row["drawing_number"].ToString())) if (string.IsNullOrEmpty(row["drawing_number"].ToString()))
@@ -462,7 +462,8 @@ namespace FineUIPro.Web.HJGL.DataIn
g.Key.category, g.Key.category,
g.Key.spec, g.Key.spec,
g.Key.description, g.Key.description,
qty = g.Sum(r => Funs.GetNewDecimalOrZero(r.Field<string>("qty"))) qty = g.Sum(r => Funs.GetNewDecimalOrZero(r.Field<string>("qty"))),
unit = g.Select(r => Funs.GetUnitFromQty(r.Field<string>("qty") ?? "")).FirstOrDefault(u => !string.IsNullOrEmpty(u)) ?? ""
}); });
foreach (var g in groups2) foreach (var g in groups2)
{ {
@@ -471,7 +472,7 @@ namespace FineUIPro.Web.HJGL.DataIn
newRow["drawing_number"] = g.drawing_number; newRow["drawing_number"] = g.drawing_number;
newRow["category"] = g.category; newRow["category"] = g.category;
newRow["spec"] = g.spec; newRow["spec"] = g.spec;
newRow["qty"] = g.qty; newRow["qty"] = g.qty.ToString() + g.unit;
newRow["description"] = g.description; newRow["description"] = g.description;
dtGroupByDrawing.Rows.Add(newRow); dtGroupByDrawing.Rows.Add(newRow);
} }
@@ -507,7 +508,8 @@ namespace FineUIPro.Web.HJGL.DataIn
g.Key.category, g.Key.category,
g.Key.spec, g.Key.spec,
g.Key.description, g.Key.description,
qty = g.Sum(r => Funs.GetNewDecimalOrZero(r.Field<string>("qty"))) qty = g.Sum(r => Funs.GetNewDecimalOrZero(r.Field<string>("qty"))),
unit = g.Select(r => Funs.GetUnitFromQty(r.Field<string>("qty") ?? "")).FirstOrDefault(u => !string.IsNullOrEmpty(u)) ?? ""
}); });
foreach (var g in groups3) foreach (var g in groups3)
{ {
@@ -516,7 +518,7 @@ namespace FineUIPro.Web.HJGL.DataIn
newRow["pipe_no"] = g.pipe_no; newRow["pipe_no"] = g.pipe_no;
newRow["category"] = g.category; newRow["category"] = g.category;
newRow["spec"] = g.spec; newRow["spec"] = g.spec;
newRow["qty"] = g.qty; newRow["qty"] = g.qty.ToString() + g.unit;
newRow["description"] = g.description; newRow["description"] = g.description;
dtGroupByPipe.Rows.Add(newRow); dtGroupByPipe.Rows.Add(newRow);
} }
@@ -559,12 +561,14 @@ namespace FineUIPro.Web.HJGL.DataIn
row["description"] = g.Key.desc; row["description"] = g.Key.desc;
decimal totalQty = 0; decimal totalQty = 0;
string unit = "";
foreach (var r in g) foreach (var r in g)
{ {
if (decimal.TryParse(r["qty"].ToString(), out decimal qty)) totalQty += Funs.GetNewDecimalOrZero(r["qty"].ToString());
totalQty += qty; if (string.IsNullOrEmpty(unit))
unit = Funs.GetUnitFromQty(r["qty"].ToString());
} }
row["qty"] = totalQty.ToString(); row["qty"] = totalQty.ToString() + unit;
dtSummary.Rows.Add(row); dtSummary.Rows.Add(row);
} }
} }