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