From 86e875b896d74dce8757ad693eb5dd336a7645cf Mon Sep 17 00:00:00 2001 From: cnf <3200815559@qq.com> Date: 星期二, 16 九月 2025 13:14:03 +0800 Subject: [PATCH] Merge branch 'master' of http://43.142.96.171:8080/r/~kyy/LW_MesClient --- DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs | 992 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 975 insertions(+), 17 deletions(-) diff --git a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs index 0bac2a1..ecf808f 100644 --- a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs +++ b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs @@ -43,6 +43,20 @@ ConfigurationManager.AppSettings["WebApiUrl"]; /// <summary> + /// 鏁版嵁杩囨护 + /// </summary> + /// <returns></returns> + public static string GetOrgWhere() + { + System.Text.StringBuilder sb = new System.Text.StringBuilder(); + //sb.Append(" (select aboutGuid as fid from SYS_USER_BIND where userGuid='" + LoginInfoModel.CurrentUser.LoginUserGuid + "' and ftype='缁勭粐')"); + //榫欏穽鍗曠粍缁囩洿鎺ヨ繃婊わ紝骞朵笖鍗曠粍缁囦紶鍏ョ殑鈥�1鈥欎笌guid绫诲瀷涓嶇杩欓噷寰呬慨鏀� + sb.Append(" (select 1 as fid from SYS_USER_BIND where userGuid='" + LoginInfoModel.CurrentUser.LoginUserGuid + "' and ftype='缁勭粐')"); + return sb.ToString(); + } + + + /// <summary> /// 璇诲彇鍔犺浇淇℃伅 /// </summary> /// <returns></returns> @@ -268,12 +282,13 @@ { colmn.Visible = true; colmn.OptionsColumn.ReadOnly = false; - }; + } + ; if (colmn.Name.ToString().Contains("gvMxDel") || colmn.Name.ToString().Contains("gvMxTui")) { colmn.Visible = !isEdt; if (colmn.Visible == true) - colmn.VisibleIndex = 99999; + colmn.VisibleIndex = 1; } else { @@ -545,6 +560,13 @@ if (colType is UcLookOrg) { var txt = colType as UcLookOrg; + txt.SetIdOrCode(strVal); + txt.IsReadly = isEdt; + continue; + } + if (colType is UcLookKw) + { + var txt = colType as UcLookKw; txt.SetIdOrCode(strVal); txt.IsReadly = isEdt; continue; @@ -909,6 +931,14 @@ txt.IsReadly = isEdt; continue; } + // + if (ctrl is UcLookKw) + { + var txt = ctrl as UcLookKw; + txt.SetIdOrCode("-1"); + txt.IsReadly = isEdt; + continue; + } //鑷畾涔夊崟鎹被鍨嬩笅鎷� if (ctrl is UcDictionaryComBox) { @@ -1029,6 +1059,13 @@ if (ctrl is UcLookCk) { var txt = ctrl as UcLookCk; + txt.IsReadly = isEdt; + continue; + } + //鑷畾涔変粨搴� + if (ctrl is UcLookKw) + { + var txt = ctrl as UcLookKw; txt.IsReadly = isEdt; continue; } @@ -1678,17 +1715,20 @@ public delegate void DelegateGetModel(string guid); public delegate void DelegateGetList(int currentPage); /// <summary> - /// 璁剧疆涓昏〃鐨勬牱寮� + /// /// </summary> /// <param name="gridView1">gridview</param> /// <param name="picCheckBox">鍥炬爣鎸夐挳</param> - /// <param name="fm"></param> + /// <param name="fm">绐椾綋</param> /// <param name="fileName">瀛楁</param> /// <param name="icoName">鍥炬爣璺緞</param> - /// <param name="action"></param> - public static void SetGridViewParameter(GridView gridView1, PictureBox picCheckBox = null, Form fm = null, string fileName = "checkStatus", string icoName = "", DelegateGetModel action = null, DevExpress.Utils.ToolTipController tips = null, bool isPostSearch = true) - { - gridView1.PopupMenuShowing += (s, e) => + /// <param name="action">濮旀墭1</param> + /// <param name="tips">楦熷槾鎻愮ず</param> + /// <param name="isPostSearch"></param> + /// <param name="action2">濮旀墭2锛堝垪琛ㄦ樉绀烘槑缁嗭級</param> + public static void SetGridViewParameter(GridView gridView1, PictureBox picCheckBox = null, Form fm = null, string fileName = "checkStatus", string icoName = "", DelegateGetModel action = null, DevExpress.Utils.ToolTipController tips = null, bool isPostSearch = true, DelegateGetModel action2 = null) + { //2025-09-04 kyy 寮曞叆涓枃鎻掍欢娉� + /*gridView1.PopupMenuShowing += (s, e) => { if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column) { @@ -1706,9 +1746,8 @@ } } } - }; + };*/ gridView1.OptionsView.ColumnAutoWidth = false;//鑷姩璋冩暣鍒楀 - if (isPostSearch == true) { gridView1.OptionsView.ShowGroupPanel = false; @@ -1725,7 +1764,6 @@ //鏄惁鏄剧ず搴曢儴鐨勮繃婊ゆ潯 // gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never; } - // gridView1.Appearance.HeaderPanel.ForeColor = DevExpress.LookAndFeel.DXSkinColors.ForeColors.ControlText; foreach (GridColumn column in gridView1.Columns) { @@ -1751,7 +1789,6 @@ column.OptionsFilter.AllowAutoFilter = false; } } - gridView1.IndicatorWidth = 60; gridView1.CustomDrawRowIndicator += (s, e) => { @@ -1793,6 +1830,22 @@ }; if (view.ActiveEditor is TextEdit) view.ActiveEditor.MouseUp += ActiveEditor_MouseUp; + }; + } + if (action2 != null) + { + gridView1.FocusedRowChanged += (s, e) => + { + int _handle = gridView1.FocusedRowHandle; + if (_handle == -1) + return; + DataRow row = gridView1.GetDataRow(_handle); + if (row == null) + return; + string _guid = row["guid"].ToString(); + if (string.IsNullOrEmpty(_guid)) + return; + action2(_guid); }; } gridView1.RowStyle += (s, e) => @@ -1879,6 +1932,7 @@ }; } } + private static void ActiveEditor_MouseUp(object sender, MouseEventArgs e) { BaseEdit edit = sender as BaseEdit; @@ -1911,7 +1965,8 @@ { int _handle = gridView1.FocusedRowHandle; bool _bl = xtraTabControl1.TabPages[0].PageEnabled; - if (_bl == false) { return; }; + if (_bl == false) { return; } + ; if (_handle < 0) { xtraTabControl1.SelectedTabPageIndex = -1; @@ -1956,7 +2011,8 @@ /// <param name="icoName"></param> public static void SetGridViewParameterMx(GridView gridView1, DevExpress.Utils.ToolTipController tips = null) { - gridView1.PopupMenuShowing += (s, e) => + //2025-09-04 kyy 娉� + /* gridView1.PopupMenuShowing += (s, e) => { if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Column) { @@ -1973,10 +2029,11 @@ } } } + } }; gridView1.OptionsView.ShowGroupPanel = false; - gridView1.OptionsCustomization.AllowGroup = false; + gridView1.OptionsCustomization.AllowGroup = false;*/ // gridView1.OptionsView.Alignment = DataGridViewContentAlignment.MiddleLeft; foreach (GridColumn column in gridView1.Columns) @@ -2294,6 +2351,13 @@ } } + /// <summary> + /// gridview 鍏ㄩ�夛紝鍙栨秷鍏ㄩ�� + /// </summary> + /// <param name="sender"></param> + /// <param name="e"></param> + /// <param name="gcMain"></param> + /// <param name="gridView1"></param> public static void CustomMouseUp(object sender, MouseEventArgs e, DevExpress.XtraGrid.GridControl gcMain, DevExpress.XtraGrid.Views.Grid.GridView gridView1) { GridColumn checkBoxColumn = gridView1.Columns[0]; @@ -2314,10 +2378,27 @@ else { checkBoxColumn.Tag = "1"; + /********2025-07-23淇ˉ杩囨护bug 鏁呮敞閲� beg ************/ + //foreach (DataRow row in _Table.Rows) + //{ + // row["chkInt"] = true; + //} + /********2025-07-23淇ˉ杩囨护bug 鏁呮敞閲� end ************/ + + /********2025-07-23淇ˉ杩囨护bug beg ************/ + System.Collections.IList ftRow = gridView1.DataController.GetAllFilteredAndSortedRows(); + System.Collections.ArrayList ftAry = new System.Collections.ArrayList(); + foreach (System.Data.DataRowView _ft in ftRow) + { + string guid = _ft["guid"].ToString(); + ftAry.Add(guid); + } foreach (DataRow row in _Table.Rows) { - row["chkInt"] = true; + if (ftAry.Contains(row["guid"].ToString())) + row["chkInt"] = true; } + /********2025-07-23淇ˉ杩囨护bug end ************/ } gcMain.BindingContext = new BindingContext(); gcMain.DataSource = _Table; @@ -2356,6 +2437,867 @@ return ""; } } + + #region GridView姹囨�婚厤缃伐鍏锋柟娉� + /// <summary> + /// 2025-08-14 kyy 蹇�熼厤缃瓽ridView搴曢儴姹囨�伙紙鍚敤姹囨�昏+璁剧疆鍒楁眰鍜屾眹鎬伙級 + /// </summary> + /// <param name="gridView">鐩爣GridView鎺т欢</param> + /// <param name="summaryColumns">闇�瑕佽繘琛屾眰鍜屾眹鎬荤殑鍒楀悕鏁扮粍</param> + public static void SetupGridSummary(DevExpress.XtraGrid.Views.Grid.GridView gridView, params string[] summaryColumns) + { + // 鍚敤搴曢儴姹囨�昏 + gridView.OptionsView.ShowFooter = true; + + // 涓烘瘡涓寚瀹氬垪璁剧疆姹傚拰姹囨�� + foreach (var columnName in summaryColumns) + { + // 楠岃瘉鍒楁槸鍚﹀瓨鍦紙閬垮厤寮傚父锛� + if (gridView.Columns[columnName] != null) + { + gridView.Columns[columnName].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; + gridView.Columns[columnName].SummaryItem.DisplayFormat = "鍚堣: {0}"; + } + } + } + + /// <summary> + /// 2025-08-15 kyy 蹇�熼厤缃瓽ridView鏉′欢姹囨�伙紙鍙眹鎬绘弧瓒虫潯浠剁殑琛岋級 + /// 浣跨敤绠�鍗曠殑鏍囩鏄剧ず鏂瑰紡锛岄伩鍏嶅鏉傜殑姹囨�婚」閰嶇疆 + /// </summary> + /// <param name="gridView">鐩爣GridView鎺т欢</param> + /// <param name="conditionFieldName">鏉′欢瀛楁鍚嶏紙濡俢hkInt锛�</param> + /// <param name="conditionValue">鏉′欢鍊硷紙濡倀rue銆�1绛夎〃绀洪�変腑锛�</param> + /// <param name="summaryColumns">闇�瑕佽繘琛屾眰鍜屾眹鎬荤殑鍒楀悕鏁扮粍</param> + public static void SetupGridSummaryWithCondition(DevExpress.XtraGrid.Views.Grid.GridView gridView, string conditionFieldName, object conditionValue, params string[] summaryColumns) + { + // 鍚敤搴曢儴姹囨�昏 + gridView.OptionsView.ShowFooter = true; + + // 瀛樺偍鏉′欢姹囨�婚厤缃埌GridView鐨凾ag涓� + var conditionSummaryConfig = new + { + ConditionField = conditionFieldName, + ConditionValue = conditionValue, + SummaryColumns = summaryColumns + }; + + // 灏嗛厤缃瓨鍌ㄥ埌GridView鐨凾ag涓紙濡傛灉宸叉湁鍏朵粬Tag锛岄渶瑕佸悎骞讹級 + if (gridView.Tag == null) + { + gridView.Tag = conditionSummaryConfig; + } + else + { + // 濡傛灉宸叉湁Tag锛屽垱寤轰竴涓鍚堝璞� + gridView.Tag = new { Existing = gridView.Tag, ConditionSummary = conditionSummaryConfig }; + } + + // 涓烘瘡涓寚瀹氬垪璁剧疆鑷畾涔夋眹鎬昏绠� + foreach (var columnName in summaryColumns) + { + if (gridView.Columns[columnName] != null) + { + // 浣跨敤鏍囧噯鐨勬眰鍜屾眹鎬伙紝浣嗘樉绀鸿嚜瀹氫箟鏍煎紡 + gridView.Columns[columnName].SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; + gridView.Columns[columnName].SummaryItem.DisplayFormat = "閫変腑鍚堣: {0}"; + } + } + + // 缁戝畾鏁版嵁鍙樺寲浜嬩欢锛屾墜鍔ㄨ绠楁潯浠舵眹鎬� + gridView.CustomDrawFooterCell -= GridView_CustomDrawFooterForCondition; + gridView.CustomDrawFooterCell += GridView_CustomDrawFooterForCondition; + } + + /// <summary> + /// 鑷畾涔夌粯鍒堕〉鑴氬崟鍏冩牸锛屾樉绀烘潯浠舵眹鎬荤粨鏋� + /// </summary> + private static void GridView_CustomDrawFooterForCondition(object sender, DevExpress.XtraGrid.Views.Grid.FooterCellCustomDrawEventArgs e) + { + var gridView = sender as DevExpress.XtraGrid.Views.Grid.GridView; + if (gridView?.Tag == null) return; + + try + { + // 鑾峰彇鏉′欢姹囨�婚厤缃� + dynamic config = GetConditionSummaryConfig(gridView.Tag); + if (config == null) return; + + string conditionField = config.ConditionField; + object conditionValue = config.ConditionValue; + string[] summaryColumns = config.SummaryColumns; + + // 妫�鏌ュ綋鍓嶅垪鏄惁闇�瑕佹潯浠舵眹鎬� + if (summaryColumns != null && Array.IndexOf(summaryColumns, e.Column.FieldName) >= 0) + { + // 璁$畻鏉′欢姹囨�诲�� + decimal totalValue = CalculateConditionalSum(gridView, conditionField, conditionValue, e.Column.FieldName); + + // 璁剧疆鏄剧ず鏂囨湰 + e.Info.DisplayText = $"{totalValue:F2}"; + + // 鍙互鑷畾涔夋樉绀烘牱寮� + e.Appearance.ForeColor = System.Drawing.Color.Blue; + e.Appearance.Font = new System.Drawing.Font(e.Appearance.Font, System.Drawing.FontStyle.Bold); + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"鏉′欢姹囨�荤粯鍒堕敊璇�: {ex.Message}"); + } + } + + /// <summary> + /// 鑾峰彇鏉′欢姹囨�婚厤缃� + /// </summary> + private static dynamic GetConditionSummaryConfig(object tag) + { + if (tag == null) return null; + + // 妫�鏌ユ槸鍚︽槸鐩存帴鐨勯厤缃璞� + var tagType = tag.GetType(); + if (tagType.GetProperty("ConditionField") != null) + { + return tag; + } + + // 妫�鏌ユ槸鍚︽槸澶嶅悎瀵硅薄 + if (tagType.GetProperty("ConditionSummary") != null) + { + dynamic composite = tag; + return composite.ConditionSummary; + } + + return null; + } + + /// <summary> + /// 璁$畻鏉′欢姹囨�诲�� + /// </summary> + private static decimal CalculateConditionalSum(DevExpress.XtraGrid.Views.Grid.GridView gridView, string conditionField, object conditionValue, string summaryField) + { + decimal total = 0; + + try + { + // 閬嶅巻鎵�鏈夊彲瑙佽 + for (int i = 0; i < gridView.DataRowCount; i++) + { + // 鑾峰彇鏉′欢瀛楁鍊� + object conditionFieldValue = gridView.GetRowCellValue(i, conditionField); + + // 妫�鏌ユ潯浠舵槸鍚﹀尮閰� + if (IsConditionMatched(conditionFieldValue, conditionValue)) + { + // 鑾峰彇姹囨�诲瓧娈靛�� + object summaryFieldValue = gridView.GetRowCellValue(i, summaryField); + + // 绱姞鏁板�� + if (summaryFieldValue != null && decimal.TryParse(summaryFieldValue.ToString(), out decimal value)) + { + total += value; + } + } + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"鏉′欢姹囨�昏绠楅敊璇�: {ex.Message}"); + } + + return Math.Round(total, 2); + } + + /// <summary> + /// 鎵嬪姩鍒锋柊鏉′欢姹囨�绘樉绀� - 浼樺寲鐗堟湰锛岀珛鍗崇敓鏁� + /// </summary> + public static void RefreshConditionalSummary(DevExpress.XtraGrid.Views.Grid.GridView gridView) + { + try + { + if (gridView != null) + { + // 鍏堝埛鏂版暟鎹粦瀹� + gridView.PostEditor(); + gridView.UpdateCurrentRow(); + + // 寮哄埗閲嶇粯搴曢儴姹囨�诲尯鍩� + gridView.InvalidateFooter(); + + // 绔嬪嵆鍒锋柊甯冨眬 + gridView.LayoutChanged(); + + // 寮哄埗閲嶇粯鏁翠釜瑙嗗浘 + gridView.Invalidate(); + + // 纭繚鐣岄潰绔嬪嵆鏇存柊 + System.Windows.Forms.Application.DoEvents(); + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"鍒锋柊鏉′欢姹囨�婚敊璇�: {ex.Message}"); + } + } + + /// <summary> + /// 鍒ゆ柇鏉′欢鏄惁鍖归厤锛堢敤浜庢眹鎬伙級 + /// </summary> + private static bool IsConditionMatched(object fieldValue, object targetValue) + { + if (fieldValue == null && targetValue == null) return true; + if (fieldValue == null || targetValue == null) return false; + + string fieldStr = fieldValue.ToString().Trim(); + string targetStr = targetValue.ToString().Trim(); + + // 澶勭悊甯冨皵鍊肩被鍨嬬殑鍖归厤 + if (IsBooleanValue(fieldStr) || IsBooleanValue(targetStr)) + { + bool fieldBool = ConvertToBoolean(fieldStr); + bool targetBool = ConvertToBoolean(targetStr); + return fieldBool == targetBool; + } + + // 澶勭悊鏁板�肩被鍨嬬殑鍖归厤 + if (decimal.TryParse(fieldStr, out decimal fieldNum) && decimal.TryParse(targetStr, out decimal targetNum)) + { + return fieldNum == targetNum; + } + + // 瀛楃涓插尮閰� + return string.Equals(fieldStr, targetStr, StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// 妫�鏌ユ槸鍚︿负甯冨皵鍊� + /// </summary> + private static bool IsBooleanValue(string value) + { + if (string.IsNullOrEmpty(value)) return false; + string lower = value.ToLower(); + return lower == "true" || lower == "false" || lower == "1" || lower == "0"; + } + + /// <summary> + /// 杞崲涓哄竷灏斿�� + /// </summary> + private static bool ConvertToBoolean(string value) + { + if (string.IsNullOrEmpty(value)) return false; + string lower = value.ToLower(); + return lower == "true" || lower == "1"; + } + #endregion + + #region 绠�鍖栫増GridView棰滆壊璁剧疆鏂规硶 - 鍒涘缓鏃堕棿锛�2024骞�8鏈�15鏃� 鍒朵綔浜猴細kyy + + /// <summary> + /// 涓�琛屼唬鐮佽缃瓽ridView棰滆壊鐨勬柟娉� + /// 鍒涘缓鏃堕棿锛�2024骞�8鏈�15鏃� 鍒朵綔浜猴細kyy + /// 浣跨敤绀轰緥锛� + /// SetSimpleGridColor(gridView1, "checkStatus", "=1", "Cell", Color.Blue); + /// SetSimpleGridColor(gridView1, "jyjg", "contains鍚堟牸", "Cell", Color.Green); + /// SetSimpleGridColor(gridView1, "status", "=宸插鏍�", "Row", Color.Blue); + /// SetSimpleGridColor(gridView1, "", "quantity-okRkqty>100", "Row", Color.Red); // 瀛楁杩愮畻琛ㄨ揪寮� + /// </summary> + /// <param name="gridView">GridView鎺т欢</param> + /// <param name="fieldName">瀛楁鍚嶏紙杩愮畻琛ㄨ揪寮忔椂鍙负绌哄瓧绗︿覆锛�</param> + /// <param name="condition">鏉′欢锛堟敮鎸�: =1, contains鍚堟牸, >5, >=10, 鎴栧瓧娈佃繍绠楀 fieldA+fieldB>100锛�</param> + /// <param name="scope">鑼冨洿锛圕ell/鍗曞厓鏍�, Row/琛�, Column/鍒楋級</param> + /// <param name="color">棰滆壊</param> + public static void SetSimpleGridColor(GridView gridView, string fieldName, string condition, string scope, Color color) + { + if (gridView == null || string.IsNullOrEmpty(condition)) + return; + + // 妫�鏌ユ槸鍚︿负杩愮畻琛ㄨ揪寮� + bool isCalculationExpression = IsCalculationExpression(condition); + + // 濡傛灉鏄繍绠楄〃杈惧紡浣嗘病鏈夋寚瀹歠ieldName锛宖ieldName璁句负绌� + if (isCalculationExpression && string.IsNullOrEmpty(fieldName)) + { + fieldName = ""; // 杩愮畻琛ㄨ揪寮忎笉闇�瑕佺壒瀹氬瓧娈靛悕 + } + else if (!isCalculationExpression && string.IsNullOrEmpty(fieldName)) + { + return; // 鏅�氭潯浠跺繀椤绘寚瀹氬瓧娈靛悕 + } + + // 绉婚櫎涔嬪墠鍙兘缁戝畾鐨勪簨浠讹紙閬垮厤閲嶅缁戝畾锛� + gridView.RowCellStyle -= SimpleGridColor_RowCellStyle; + + // 鍒涘缓绠�鍗曠殑棰滆壊閰嶇疆骞跺瓨鍌ㄥ埌Tag + var colorConfigs = gridView.Tag as List<SimpleColorConfig> ?? new List<SimpleColorConfig>(); + + // 娣诲姞鏂伴厤缃� + colorConfigs.Add(new SimpleColorConfig + { + FieldName = fieldName, + Condition = condition, + Scope = scope, + Color = color + }); + + gridView.Tag = colorConfigs; + + // 缁戝畾棰滆壊璁剧疆浜嬩欢 + gridView.RowCellStyle += SimpleGridColor_RowCellStyle; + } + + /// <summary> + /// 绠�鍗曢鑹查厤缃被 + /// </summary> + private class SimpleColorConfig + { + public string FieldName { get; set; } + public string Condition { get; set; } + public string Scope { get; set; } + public Color Color { get; set; } + } + + /// <summary> + /// 绠�鍖栫殑棰滆壊璁剧疆浜嬩欢澶勭悊 + /// </summary> + private static void SimpleGridColor_RowCellStyle(object sender, RowCellStyleEventArgs e) + { + var gridView = sender as GridView; + if (gridView?.Tag is List<SimpleColorConfig> configs) + { + foreach (var config in configs) + { + // 鍒ゆ柇鏄惁搴旇搴旂敤棰滆壊 + bool shouldApply = false; + + // 妫�鏌ユ槸鍚︿负杩愮畻琛ㄨ揪寮� + bool isCalculationExpression = IsCalculationExpression(config.Condition); + + if (isCalculationExpression) + { + // 杩愮畻琛ㄨ揪寮忔牴鎹寖鍥村喅瀹氭槸鍚﹀簲鐢� + if (config.Scope.ToLower() == "row") + shouldApply = true; // 鏁磋搴旂敤 + else if (config.Scope.ToLower() == "cell") + shouldApply = true; // 鎵�鏈夊崟鍏冩牸閮藉皾璇曞簲鐢� + else if (config.Scope.ToLower() == "column") + shouldApply = true; // 鎵�鏈夊垪閮藉皾璇曞簲鐢� + } + else + { + // 鏅�氬瓧娈垫潯浠� + if (config.Scope.ToLower() == "cell" && e.Column.FieldName == config.FieldName) + shouldApply = true; + else if (config.Scope.ToLower() == "row") + shouldApply = true; + else if (config.Scope.ToLower() == "column" && e.Column.FieldName == config.FieldName) + shouldApply = true; + } + + if (!shouldApply) continue; + + bool conditionMatched = false; + + if (isCalculationExpression) + { + // 澶勭悊瀛楁杩愮畻琛ㄨ揪寮� + try + { + decimal result = EvaluateExpression(gridView, e.RowHandle, config.Condition); + conditionMatched = result == 1; // 1琛ㄧず鏉′欢婊¤冻锛�0琛ㄧず涓嶆弧瓒� + + if (conditionMatched) + { + System.Diagnostics.Debug.WriteLine($"杩愮畻琛ㄨ揪寮忓尮閰嶆垚鍔� - 琛ㄨ揪寮�: {config.Condition}, 琛�: {e.RowHandle}"); + } + } + catch (Exception ex) + { + System.Diagnostics.Debug.WriteLine($"杩愮畻琛ㄨ揪寮忚绠楀け璐� - 琛ㄨ揪寮�: {config.Condition}, 閿欒: {ex.Message}"); + } + } + else + { + // 澶勭悊鍗曞瓧娈垫潯浠� + object cellValue = gridView.GetRowCellValue(e.RowHandle, config.FieldName); + if (cellValue != null) + { + string stringValue = cellValue.ToString().Trim(); + + // 璋冭瘯淇℃伅锛氳緭鍑哄疄闄呯殑瀛楁鍊� + if (config.FieldName == "checkStatus" && e.RowHandle < 3) // 鍙緭鍑哄墠鍑犺閬垮厤澶鏃ュ織 + { + System.Diagnostics.Debug.WriteLine($"瀛楁鍊艰皟璇� - 瀛楁: {config.FieldName}, 瀹為檯鍊�: '{stringValue}', 绫诲瀷: {cellValue.GetType().Name}, 鏉′欢: {config.Condition}"); + } + + // 鍒ゆ柇鏉′欢鏄惁鍖归厤 + conditionMatched = IsConditionMatch(stringValue, config.Condition); + } + } + + if (conditionMatched) + { + e.Appearance.ForeColor = config.Color; + System.Diagnostics.Debug.WriteLine($"棰滆壊鍖归厤鎴愬姛 - 瀛楁/琛ㄨ揪寮�: {config.FieldName ?? config.Condition}, 鏉′欢: {config.Condition}"); + break; // 鍖归厤鍒扮涓�涓潯浠跺氨鍋滄 + } + } + } + } + + /// <summary> + /// 妫�鏌ユ槸鍚︿负璁$畻琛ㄨ揪寮忥紙鍖呭惈瀛楁杩愮畻锛� + /// </summary> + private static bool IsCalculationExpression(string condition) + { + if (string.IsNullOrEmpty(condition)) + return false; + + // 妫�鏌ユ槸鍚﹀寘鍚暟瀛﹁繍绠楃鍜屾瘮杈冭繍绠楃鐨勭粍鍚� + char[] mathOperators = { '+', '-', '*', '/' }; + string[] comparisonOperators = { ">=", "<=", ">", "<", "=", "!=" }; + + bool hasMathOperator = condition.IndexOfAny(mathOperators) >= 0; + bool hasComparisonOperator = comparisonOperators.Any(op => condition.Contains(op)); + + // 濡傛灉鍚屾椂鍖呭惈鏁板杩愮畻绗﹀拰姣旇緝杩愮畻绗︼紝灏辫涓烘槸璁$畻琛ㄨ揪寮� + return hasMathOperator && hasComparisonOperator; + } + + /// <summary> + /// 鍒ゆ柇鏉′欢鏄惁鍖归厤 + /// </summary> + private static bool IsConditionMatch(string value, string condition) + { + if (string.IsNullOrEmpty(value) || string.IsNullOrEmpty(condition)) + return false; + + condition = condition.Trim(); + value = value.Trim(); + + // 澶勭悊contains鏉′欢 + if (condition.StartsWith("contains", StringComparison.OrdinalIgnoreCase)) + { + string matchText = condition.Substring(8).Trim(); + + // 绉婚櫎鍓嶇紑澶勭悊锛堝"M:鍏嶆"涓殑"M:"锛� + string processedValue = value; + int colonIndex = processedValue.IndexOf(':'); + if (colonIndex >= 0 && colonIndex < processedValue.Length - 1) + { + processedValue = processedValue.Substring(colonIndex + 1).Trim(); + } + + return processedValue.IndexOf(matchText, StringComparison.OrdinalIgnoreCase) >= 0; + } + + // 澶勭悊绛変簬鏉′欢 + if (condition.StartsWith("=")) + { + string targetValue = condition.Substring(1).Trim(); + + // 鐗规畩澶勭悊bit绫诲瀷瀛楁锛圔oolean鍊硷級 + if (IsBooleanCondition(targetValue)) + { + return IsBooleanMatch(value, targetValue); + } + + return string.Equals(value, targetValue, StringComparison.OrdinalIgnoreCase); + } + + // 澶勭悊鏁板�兼瘮杈冩潯浠� + if (decimal.TryParse(value, out decimal numericValue)) + { + if (condition.StartsWith(">=")) + { + if (decimal.TryParse(condition.Substring(2).Trim(), out decimal target)) + return numericValue >= target; + } + else if (condition.StartsWith("<=")) + { + if (decimal.TryParse(condition.Substring(2).Trim(), out decimal target)) + return numericValue <= target; + } + else if (condition.StartsWith(">")) + { + if (decimal.TryParse(condition.Substring(1).Trim(), out decimal target)) + return numericValue > target; + } + else if (condition.StartsWith("<")) + { + if (decimal.TryParse(condition.Substring(1).Trim(), out decimal target)) + return numericValue < target; + } + else if (decimal.TryParse(condition, out decimal target)) + { + return numericValue == target; + } + } + + // 妫�鏌ユ槸鍚︽槸甯冨皵鍊兼潯浠� + if (IsBooleanCondition(condition)) + { + return IsBooleanMatch(value, condition); + } + + // 榛樿鎸夊瓧绗︿覆鐩哥瓑澶勭悊 + return string.Equals(value, condition, StringComparison.OrdinalIgnoreCase); + } + + /// <summary> + /// 鍒ゆ柇澶氬瓧娈佃繍绠楁潯浠舵槸鍚﹀尮閰嶏紙鏀寔瀛楁闂磋繍绠楋級 + /// </summary> + private static bool IsConditionMatchWithCalculation(GridView gridView, int rowHandle, string condition) + { + if (string.IsNullOrEmpty(condition)) + return false; + + condition = condition.Trim(); + + try + { + // 瑙f瀽骞惰绠楄〃杈惧紡 + decimal calculatedValue = EvaluateExpression(gridView, rowHandle, condition); + + // 濡傛灉琛ㄨ揪寮忚绠楁垚鍔燂紝杩斿洖true锛堣〃绀烘潯浠舵弧瓒筹級 + return true; + } + catch + { + // 濡傛灉璁$畻澶辫触锛岃繑鍥瀎alse + return false; + } + } + + /// <summary> + /// 璁$畻鍖呭惈瀛楁鍚嶇殑琛ㄨ揪寮� + /// 鏀寔鏍煎紡锛歠ieldA+fieldB>100, fieldA-fieldB<=50, fieldA*fieldB>=fieldC绛� + /// </summary> + private static decimal EvaluateExpression(GridView gridView, int rowHandle, string expression) + { + // 鎻愬彇姣旇緝杩愮畻绗﹀拰鐩爣鍊� + string[] operators = { ">=", "<=", ">", "<", "=", "!=" }; + string op = ""; + string leftExpression = ""; + string rightExpression = ""; + + foreach (var oper in operators) + { + if (expression.Contains(oper)) + { + string[] parts = expression.Split(new string[] { oper }, StringSplitOptions.None); + if (parts.Length == 2) + { + op = oper; + leftExpression = parts[0].Trim(); + rightExpression = parts[1].Trim(); + break; + } + } + } + + if (string.IsNullOrEmpty(op)) + throw new ArgumentException("鏃犳晥鐨勮〃杈惧紡鏍煎紡"); + + // 璁$畻宸︿晶琛ㄨ揪寮忕殑鍊� + decimal leftValue = CalculateFieldExpression(gridView, rowHandle, leftExpression); + + // 璁$畻鍙充晶琛ㄨ揪寮忕殑鍊硷紙鍙兘鏄暟瀛楁垨瀛楁琛ㄨ揪寮忥級 + decimal rightValue; + if (decimal.TryParse(rightExpression, out rightValue)) + { + // 鍙充晶鏄暟瀛� + } + else + { + // 鍙充晶鏄瓧娈佃〃杈惧紡 + rightValue = CalculateFieldExpression(gridView, rowHandle, rightExpression); + } + + // 鏍规嵁杩愮畻绗﹀垽鏂潯浠舵槸鍚︽弧瓒� + switch (op) + { + case ">=": + return leftValue >= rightValue ? 1 : 0; + case "<=": + return leftValue <= rightValue ? 1 : 0; + case ">": + return leftValue > rightValue ? 1 : 0; + case "<": + return leftValue < rightValue ? 1 : 0; + case "=": + return leftValue == rightValue ? 1 : 0; + case "!=": + return leftValue != rightValue ? 1 : 0; + default: + throw new ArgumentException($"涓嶆敮鎸佺殑杩愮畻绗�: {op}"); + } + } + + /// <summary> + /// 璁$畻鍖呭惈瀛楁杩愮畻鐨勮〃杈惧紡锛堝锛歠ieldA+fieldB-fieldC*2锛� + /// </summary> + private static decimal CalculateFieldExpression(GridView gridView, int rowHandle, string expression) + { + expression = expression.Trim(); + + // 绠�鍗曠殑琛ㄨ揪寮忚В鏋愬櫒 - 鎸夎繍绠椾紭鍏堢骇澶勭悊 + // 鍏堝鐞嗕箻闄わ紝鍐嶅鐞嗗姞鍑� + + // 鍒嗗壊鍔犲噺杩愮畻 + var addSubTerms = SplitExpression(expression, new[] { '+', '-' }); + decimal result = 0; + char lastOp = '+'; + + foreach (var term in addSubTerms) + { + string cleanTerm = term.Key.Trim(); + char op = term.Value; + + // 澶勭悊涔橀櫎杩愮畻 + decimal termValue = CalculateMultiplyDivide(gridView, rowHandle, cleanTerm); + + if (lastOp == '+') + result += termValue; + else if (lastOp == '-') + result -= termValue; + + lastOp = op; + } + + return result; + } + + /// <summary> + /// 澶勭悊涔橀櫎杩愮畻 + /// </summary> + private static decimal CalculateMultiplyDivide(GridView gridView, int rowHandle, string expression) + { + var mulDivTerms = SplitExpression(expression, new[] { '*', '/' }); + decimal result = 0; + char lastOp = '*'; + bool isFirst = true; + + foreach (var term in mulDivTerms) + { + string cleanTerm = term.Key.Trim(); + char op = term.Value; + + decimal termValue = GetFieldOrNumericValue(gridView, rowHandle, cleanTerm); + + if (isFirst) + { + result = termValue; + isFirst = false; + } + else if (lastOp == '*') + result *= termValue; + else if (lastOp == '/') + result /= termValue; + + lastOp = op; + } + + return result; + } + + /// <summary> + /// 鍒嗗壊琛ㄨ揪寮� + /// </summary> + private static List<KeyValuePair<string, char>> SplitExpression(string expression, char[] operators) + { + var result = new List<KeyValuePair<string, char>>(); + string currentTerm = ""; + + for (int i = 0; i < expression.Length; i++) + { + char c = expression[i]; + + if (operators.Contains(c)) + { + if (!string.IsNullOrEmpty(currentTerm)) + { + result.Add(new KeyValuePair<string, char>(currentTerm, i < expression.Length - 1 ? c : '\0')); + currentTerm = ""; + } + } + else + { + currentTerm += c; + } + } + + if (!string.IsNullOrEmpty(currentTerm)) + { + result.Add(new KeyValuePair<string, char>(currentTerm, '\0')); + } + + return result; + } + + /// <summary> + /// 鑾峰彇瀛楁鍊兼垨鏁板�� + /// </summary> + private static decimal GetFieldOrNumericValue(GridView gridView, int rowHandle, string valueExpression) + { + valueExpression = valueExpression.Trim(); + + // 灏濊瘯瑙f瀽涓烘暟瀛� + if (decimal.TryParse(valueExpression, out decimal numValue)) + { + return numValue; + } + + // 浣滀负瀛楁鍚嶅鐞� + try + { + object cellValue = gridView.GetRowCellValue(rowHandle, valueExpression); + if (cellValue != null && decimal.TryParse(cellValue.ToString(), out decimal fieldValue)) + { + return fieldValue; + } + } + catch + { + // 瀛楁涓嶅瓨鍦ㄦ垨鏃犳硶杞崲涓烘暟瀛� + } + + return 0; // 榛樿鍊� + } + + /// <summary> + /// 妫�鏌ユ槸鍚︽槸甯冨皵鍊兼潯浠� + /// </summary> + private static bool IsBooleanCondition(string condition) + { + string lowerCondition = condition.ToLower(); + return lowerCondition == "true" || lowerCondition == "false" || + lowerCondition == "1" || lowerCondition == "0"; + } + + /// <summary> + /// 甯冨皵鍊煎尮閰嶆鏌� + /// </summary> + private static bool IsBooleanMatch(string value, string condition) + { + // 鏍囧噯鍖栧竷灏斿�� + bool conditionBool = NormalizeBooleanValue(condition); + bool valueBool = NormalizeBooleanValue(value); + + return conditionBool == valueBool; + } + + /// <summary> + /// 鏍囧噯鍖栧竷灏斿�� + /// </summary> + private static bool NormalizeBooleanValue(string value) + { + if (string.IsNullOrEmpty(value)) + return false; + + string lowerValue = value.Trim().ToLower(); + + // 澶勭悊鍚勭鍙兘鐨則rue鍊� + if (lowerValue == "true" || lowerValue == "1" || lowerValue == "鏄�" || lowerValue == "宸插鏍�") + return true; + + // 澶勭悊鍚勭鍙兘鐨刦alse鍊� + if (lowerValue == "false" || lowerValue == "0" || lowerValue == "鍚�" || lowerValue == "鏈鏍�" || lowerValue == "") + return false; + + // 榛樿涓篺alse + return false; + } + + + + /// <summary> + /// 璁剧疆GridView澶嶉�夋鍒楃偣鍑绘椂鑷姩鍒锋柊鏉′欢姹囨�� + /// 2025-08-15 kyy 鏂板鍏敤鏂规硶 + /// </summary> + /// <param name="gridView">鐩爣GridView鎺т欢</param> + /// <param name="checkboxFieldName">澶嶉�夋瀛楁鍚嶏紙榛樿涓篶hkInt锛�</param> + /// <param name="delayMs">寤惰繜鍒锋柊鏃堕棿锛堟绉掞紝榛樿100ms锛�</param> + public static void SetupCheckboxClickRefresh(DevExpress.XtraGrid.Views.Grid.GridView gridView, string checkboxFieldName = "chkInt", int delayMs = 100) + { + if (gridView == null) return; + + // 娣诲姞榧犳爣鐐瑰嚮浜嬩欢锛屾娴嬪閫夋鍒楃偣鍑� + gridView.MouseDown += (s, e) => + { + var hitInfo = gridView.CalcHitInfo(e.Location); + if (hitInfo.InRowCell && hitInfo.Column?.FieldName == checkboxFieldName) + { + // 澶嶉�夋鍒楄鐐瑰嚮锛屽欢杩熷埛鏂版眹鎬荤‘淇濆�煎凡鏇存柊 + System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + timer.Interval = delayMs; + timer.Tick += (sender, args) => + { + timer.Stop(); + timer.Dispose(); + RefreshConditionalSummary(gridView); + }; + timer.Start(); + } + }; + } + + /// <summary> + /// 涓�閿缃瓽ridView鏉′欢姹囨�荤殑瀹屾暣鍔熻兘锛堝寘鍚潯浠舵眹鎬�+瀹炴椂鍒锋柊锛� + /// 2025-08-15 kyy 鏂板渚挎嵎鏂规硶 + /// </summary> + /// <param name="gridView">鐩爣GridView鎺т欢</param> + /// <param name="conditionFieldName">鏉′欢瀛楁鍚嶏紙濡俢hkInt锛�</param> + /// <param name="conditionValue">鏉′欢鍊硷紙濡倀rue琛ㄧず閫変腑锛�</param> + /// <param name="summaryColumns">闇�瑕佹眹鎬荤殑鍒楀悕鏁扮粍</param> + /// <param name="enableRealTimeRefresh">鏄惁鍚敤瀹炴椂鍒锋柊锛堥粯璁rue锛�</param> + /// <param name="refreshDelayMs">鍒锋柊寤惰繜鏃堕棿锛堟绉掞紝榛樿100ms锛�</param> + public static void SetupCompleteConditionalSummary(DevExpress.XtraGrid.Views.Grid.GridView gridView, + string conditionFieldName, object conditionValue, string[] summaryColumns, + bool enableRealTimeRefresh = true, int refreshDelayMs = 100) + { + if (gridView == null || summaryColumns == null || summaryColumns.Length == 0) return; + + // 1. 璁剧疆鏉′欢姹囨�� + SetupGridSummaryWithCondition(gridView, conditionFieldName, conditionValue, summaryColumns); + + if (!enableRealTimeRefresh) return; + + // 2. 璁剧疆瀹炴椂鍒锋柊浜嬩欢 + // 鍗曞厓鏍煎�煎彉鍖栦簨浠� + gridView.CellValueChanged += (s, e) => + { + if (e.Column.FieldName == conditionFieldName) + { + RefreshConditionalSummary(gridView); + } + }; + + // 鏁版嵁婧愬彉鍖栦簨浠� + gridView.DataSourceChanged += (s, e) => + { + RefreshConditionalSummary(gridView); + }; + + // 缂栬緫鍣ㄩ殣钘忎簨浠� + gridView.HiddenEditor += (s, e) => + { + System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer(); + timer.Interval = 50; + timer.Tick += (sender, args) => + { + timer.Stop(); + timer.Dispose(); + RefreshConditionalSummary(gridView); + }; + timer.Start(); + }; + + // 3. 璁剧疆澶嶉�夋鐐瑰嚮鍒锋柊 + SetupCheckboxClickRefresh(gridView, conditionFieldName, refreshDelayMs); + } + + #endregion + } /// <summary> @@ -2391,6 +3333,7 @@ return Text.ToString(); } + } /// <summary> @@ -2437,9 +3380,24 @@ ipqc棣栨, fqc, 鐢熶骇閫�鏂欏叆搴撴, - 鍏跺畠鍏ュ簱妫� + 鍏跺畠鍏ュ簱妫�, + 閿�鍞��璐у叆搴撴, + 瓒呮湡妫�, + 濮斿閫�鏂欏叆搴撴, + cqcjyes,//閲嶆鏂规 + cqcjno,//閲嶆鏂规 + 浜х嚎绉伴噸, + iqc绉伴噸, + 鍙楁墭鍏ュ簱 } + public enum OrderType + { + 鍏跺畠鍏ュ簱, + 鐗╂枡璋冩嫧, + 鍏跺畠鍑哄簱 + } + } \ No newline at end of file -- Gitblit v1.9.3