From 437425784b7612e10d4a54bd64905c508347514d Mon Sep 17 00:00:00 2001
From: lu <99954486@qq.com>
Date: 星期二, 06 五月 2025 15:12:50 +0800
Subject: [PATCH] fqc

---
 DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs |  326 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 275 insertions(+), 51 deletions(-)

diff --git a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
index f9529c2..451a40b 100644
--- a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
+++ b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -1,4 +1,18 @@
-锘縰sing System;
+锘縰sing DevExpress.Utils;
+using DevExpress.XtraEditors;
+using DevExpress.XtraEditors.Controls;
+using DevExpress.XtraGrid;
+using DevExpress.XtraGrid.Columns;
+using DevExpress.XtraGrid.Menu;
+using DevExpress.XtraGrid.Views.Grid;
+using DevExpress.XtraGrid.Views.Grid.ViewInfo;
+using DevExpress.XtraTab;
+using DevExpress.XtraTreeList;
+using Gs.DevApp.Entity;
+using Gs.DevApp.UserControl;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System;
 using System.Collections.Generic;
 using System.Configuration;
 using System.Data;
@@ -14,20 +28,7 @@
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
 using System.Windows.Forms;
-using DevExpress.Utils;
-using DevExpress.XtraEditors;
-using DevExpress.XtraEditors.Controls;
-using DevExpress.XtraGrid;
-using DevExpress.XtraGrid.Columns;
-using DevExpress.XtraGrid.Menu;
-using DevExpress.XtraGrid.Views.Grid;
-using DevExpress.XtraGrid.Views.Grid.ViewInfo;
-using DevExpress.XtraTab;
-using DevExpress.XtraTreeList;
-using Gs.DevApp.Entity;
-using Gs.DevApp.UserControl;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
+using System.Windows.Forms.VisualStyles;
 using UserControls.Data;
 using static System.Windows.Forms.Control;
 
@@ -41,7 +42,6 @@
     {
         private static readonly string WebApiUrl =
             ConfigurationManager.AppSettings["WebApiUrl"];
-
 
         public static async Task<string> UploadFileAsync(string filePath)
         {
@@ -489,7 +489,6 @@
                                 txt.Text = strVal;
                             }
                         }
-
                         //鑷畾涔変粨搴�
                         if (colType is UcLookCk)
                         {
@@ -613,7 +612,10 @@
                         if (colType is SimpleButton)
                         {
                             var txt = colType as SimpleButton;
-                            txt.Enabled = !isEdt;
+                            if (txt.Tag != null && txt.Tag.ToString() == "gvBtnAlawys")
+                                txt.Enabled = true;
+                            else
+                                txt.Enabled = !isEdt;
                             continue;
                         }
                         //鑷畾宸ュ簭
@@ -628,6 +630,14 @@
                         if (colType is UcDictionary)
                         {
                             var txt = colType as UcDictionary;
+                            txt.TextTxt = (strVal);
+                            txt.IsReadly = isEdt;
+                            continue;
+                        }
+                        //鑷畾鍗曟嵁绫诲瀷涓嬫媺
+                        if (colType is UcDictionaryComBox)
+                        {
+                            var txt = colType as UcDictionaryComBox;
                             txt.TextTxt = (strVal);
                             txt.IsReadly = isEdt;
                             continue;
@@ -726,6 +736,7 @@
                     var txt = ctrl as ButtonEdit;
                     txt.Text = "";
                     txt.Enabled = !isEdt;
+                    txt.ReadOnly = isEdt;
                     continue;
                 }
                 //鏂囨湰
@@ -908,10 +919,21 @@
                     txt.IsReadly = isEdt;
                     continue;
                 }
+                //鑷畾涔夊崟鎹被鍨嬩笅鎷�
+                if (ctrl is UcDictionaryComBox)
+                {
+                    var txt = ctrl as UcDictionaryComBox;
+                    //txt.SetIdOrCode("-1");
+                    txt.IsReadly = isEdt;
+                    continue;
+                }
                 if (ctrl is SimpleButton)
                 {
                     var txt = ctrl as SimpleButton;
-                    txt.Enabled = !isEdt;
+                    if (txt.Tag != null && txt.Tag.ToString() == "gvBtnAlawys")
+                        txt.Enabled = true;
+                    else
+                        txt.Enabled = !isEdt;
                     continue;
                 }
             }
@@ -1005,7 +1027,6 @@
                     ctrl.Enabled = !isEdt;
                     continue;
                 }
-                //
                 if (ctrl is CheckEdit)
                 {
                     var txt = ctrl as CheckEdit;
@@ -1089,7 +1110,6 @@
                     txt.IsReadly = isEdt;
                     continue;
                 }
-
                 //鑷畾閮ㄩ棬
                 if (ctrl is UcLookDepartment)
                 {
@@ -1132,10 +1152,20 @@
                     txt.IsReadly = isEdt;
                     continue;
                 }
+                //鑷畾鍗曟嵁绫诲瀷涓嬫媺
+                if (ctrl is UcDictionaryComBox)
+                {
+                    var txt = ctrl as UcDictionaryComBox;
+                    txt.IsReadly = isEdt;
+                    continue;
+                }
                 if (ctrl is SimpleButton)
                 {
                     var txt = ctrl as SimpleButton;
-                    txt.Enabled = !isEdt;
+                    if (txt.Tag != null && txt.Tag.ToString() == "gvBtnAlawys")
+                        txt.Enabled = true;
+                    else
+                        txt.Enabled = !isEdt;
                     continue;
                 }
             }
@@ -1351,6 +1381,14 @@
             return false;
         }
 
+        public static bool ToCheck(string str)
+        {
+            if (str.ToUpper() == "true".ToUpper())
+                return true;
+            if (str.ToUpper() == "1".ToUpper())
+                return true;
+            return false;
+        }
 
         /// <summary>
         /// 璇诲彇grid鐨勫綋鍓嶈
@@ -1617,7 +1655,17 @@
 
         public static FilterEntity getFilterEntityWord(string id, string idDec, string val, string type)
         {
-            return new FilterEntity(id, idDec + ")", " like ", "鍖呭惈)", "%" + val + "%", type);
+            switch (type)
+            {
+                case "Bit绫诲瀷":
+                    string _val = (val.ToUpper() == "true".ToUpper() ? "1" : "0");
+                    return new FilterEntity(id, idDec + ")", "=", "绛変簬)", "" + _val + "", type);
+                    break;
+                default:
+                    return new FilterEntity(id, idDec + ")", "like", "鍖呭惈)", "%" + val + "%", type);
+                    break;
+            }
+
         }
         public static List<FilterEntity> GetDilter(GridColumnCollection Columns, GridView gridView1 = null)
         {
@@ -1633,10 +1681,19 @@
                 ColumnFilterInfo filter = col.FilterInfo;
                 if (string.IsNullOrEmpty(filter.FilterString))
                     continue;
-                //  fiList.Add(new FilterEntity("b.FNumber", "浣跨敤缁勭粐", " like ", "鍖呭惈", "%" + filter.Value + "%"));
-                string[] ddd = filter.FilterString.Replace("Contains", "").Replace("(", "").Replace(")", "").Replace("'", "").Replace("'", "").Split(',');
-                //Contains([fSubsidiary], '005')
-                fiList.Add(getFilterEntityWord(col.Tag.ToString(), col.Caption.Trim(), ddd[1].Trim(), col.UnboundExpression));
+                string _filterString = filter.FilterString.Replace("Contains", "").Replace("(", "").Replace(")", "").Replace("'", "").Replace("'", "");
+                string[] ddd = _filterString.Split(',');
+                string _val = "";
+                if (ddd.Length > 1)
+                {
+                    _val = ddd[1].Trim();
+                }
+                else
+                {
+                    ddd = _filterString.Split('=');
+                    _val = ddd[1].Trim();
+                }
+                fiList.Add(getFilterEntityWord(col.Tag.ToString(), col.Caption.Trim(), _val, col.UnboundExpression));
             }
             return fiList;
         }
@@ -1667,19 +1724,17 @@
                         case "鏃堕棿绫诲瀷":
                             _sbSqlWhere.Append(" and CONVERT(nvarchar(30)," + itm.fileId + ",23)" + itm.fileOper + "'" + itm.fileValue + "'");
                             break;
-                        //case "鏁板�肩被鍨�":
-                        //    _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" + itm.fileValue + "'");
-                        //    break;
+                        case "Bit绫诲瀷":
+                            _sbSqlWhere.Append(" and isnull(" + itm.fileId + ",0) =" + itm.fileValue + "");
+                            break;
                         default:
-                            _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" + itm.fileValue + "'");
+                            _sbSqlWhere.Append(" and " + itm.fileId + " " + itm.fileOper + " '" + itm.fileValue + "'");
                             break;
                     }
                 }
             }
             return _sbSqlWhere.ToString();
         }
-
-
         public delegate void DelegateGetModel(string guid);
         public delegate void DelegateGetList(int currentPage);
         /// <summary>
@@ -1691,7 +1746,7 @@
         /// <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)
+        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) =>
             {
@@ -1712,12 +1767,31 @@
                     }
                 }
             };
-            gridView1.OptionsView.ShowGroupPanel = false;
-            gridView1.OptionsCustomization.AllowGroup = false;
-            // gridView1.Appearance.HeaderPanel.ForeColor = DevExpress.LookAndFeel.DXSkinColors.ForeColors.ControlText;
             gridView1.OptionsView.ColumnAutoWidth = false;//鑷姩璋冩暣鍒楀
+
+            if (isPostSearch == true)
+            {
+                gridView1.OptionsView.ShowGroupPanel = false;
+                gridView1.OptionsCustomization.AllowGroup = false;
+                gridView1.OptionsFilter.AllowAutoFilterConditionChange = DevExpress.Utils.DefaultBoolean.False;
+                gridView1.OptionsView.ShowAutoFilterRow = true;
+                gridView1.OptionsFilter.AllowFilterEditor = false;
+                gridView1.OptionsFilter.ShowCustomFunctions = DevExpress.Utils.DefaultBoolean.False;
+                gridView1.OptionsFilter.AllowColumnMRUFilterList = false;
+                gridView1.OptionsFilter.AllowMRUFilterList = false;
+                gridView1.OptionsCustomization.AllowFilter = false;
+                gridView1.OptionsFind.ShowSearchNavButtons = false;
+                gridView1.OptionsView.ShowGroupPanel = false;
+                //鏄惁鏄剧ず搴曢儴鐨勮繃婊ゆ潯
+                // gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;
+            }
+
+            // gridView1.Appearance.HeaderPanel.ForeColor = DevExpress.LookAndFeel.DXSkinColors.ForeColors.ControlText;
             foreach (GridColumn column in gridView1.Columns)
             {
+                column.MinWidth = 10;
+                column.MaxWidth = 0;
+
                 column.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
                 column.OptionsColumn.AllowEdit = true;
                 // column.OptionsFilter.AutoFilterCondition = AutoFilterCondition.Contains;
@@ -1727,20 +1801,17 @@
                     column.OptionsColumn.ReadOnly = false;
                 else
                     column.OptionsColumn.ReadOnly = true;
-                if (column.Tag == null || column.Tag.ToString().Length <= 0)
-                    column.OptionsFilter.AllowAutoFilter = false;
+
+                //if(isPostSearch==false)
+                //    column.OptionsColumn.ReadOnly = true;
+
+                if (isPostSearch == true)
+                {
+                    if (column.Tag == null || column.Tag.ToString().Length <= 0)
+                        column.OptionsFilter.AllowAutoFilter = false;
+                }
             }
-            gridView1.OptionsFilter.AllowAutoFilterConditionChange = DevExpress.Utils.DefaultBoolean.False;
-            gridView1.OptionsView.ShowAutoFilterRow = true;
-            gridView1.OptionsFilter.AllowFilterEditor = false;
-            gridView1.OptionsFilter.ShowCustomFunctions = DevExpress.Utils.DefaultBoolean.False;
-            gridView1.OptionsFilter.AllowColumnMRUFilterList = false;
-            gridView1.OptionsFilter.AllowMRUFilterList = false;
-            gridView1.OptionsCustomization.AllowFilter = false;
-            gridView1.OptionsFind.ShowSearchNavButtons = false;
-            gridView1.OptionsView.ShowGroupPanel = false;
-            //鏄惁鏄剧ず搴曢儴鐨勮繃婊ゆ潯
-            // gridView1.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Never;
+
             gridView1.IndicatorWidth = 50;
             gridView1.CustomDrawRowIndicator += (s, e) =>
             {
@@ -1961,6 +2032,8 @@
             {
                 // column.DefaultCellStyle.Alignment = true;
                 column.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
+                column.MinWidth = 10;
+                column.MaxWidth = 0;
             }
             gridView1.OptionsView.ColumnAutoWidth = false;//鑷姩璋冩暣鍒楀
             gridView1.OptionsFilter.AllowFilterEditor = false;
@@ -2004,13 +2077,164 @@
         }
 
         #endregion
-
+        /// <summary>
+        /// 鍒ゆ柇鏄笉鏄竴涓湁鏁堢殑鏁板��
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
         public static bool IsNumeric(string str)
         {
             Regex regex = new Regex("^[0-9]+$");
             return regex.IsMatch(str);
         }
+        /// <summary>
+        /// 鍒ゆ柇鏄笉鏄竴涓湁鏁堟灉鐨刣ecimal鏁板��
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsNumeric2(string str)
+        {
+            string input = str;
+            decimal number;
+            bool isNumeric = decimal.TryParse(input, out number);
+            return isNumeric;
+        }
+        /// <summary>
+        /// 鍒ゆ柇鏄笉鏄竴涓湁鏁堢殑姝f暣鏁�
+        /// </summary>
+        /// <param name="str"></param>
+        /// <returns></returns>
+        public static bool IsNumeric3(string str)
+        {
+            string input = str;
+            decimal number;
+            bool isNumeric = decimal.TryParse(input, out number);
+            if (isNumeric && number > 0)
+                return true;
+            return false;
+        }
+        public static void PrintJiSuan(DevExpress.XtraEditors.TextEdit box1, DevExpress.XtraEditors.TextEdit box2, string sum, DevExpress.XtraEditors.RadioGroup rd)
+        {
+            if (rd.SelectedIndex == 2)
+                return;
+            try
+            {
+                string t1 = box1.Text.Trim();
+                string t2 = box2.Text.Trim();
+                if (!Gs.DevApp.ToolBox.UtilityHelper.IsNumeric2(t1))
+                    return;
+                decimal? dc = Gs.DevApp.ToolBox.UtilityHelper.GetDecimal(sum);
+                decimal? dc1 = Gs.DevApp.ToolBox.UtilityHelper.GetDecimal(t1);
 
+                int dividend = int.Parse(sum); // 琚櫎鏁�
+                int divisor = int.Parse(t1);   // 闄ゆ暟
+
+                int quotient = dividend / divisor; // 鏁存暟閮ㄥ垎
+                int remainder = dividend % divisor; // 浣欐暟
+
+                box2.Text = quotient.ToString();
+
+                if (rd.SelectedIndex == 0)
+                    rd.Properties.Items[0].Description = "鍏ㄨ嚜鍔ㄣ��" + remainder.ToString() + "銆�";
+            }
+            catch (Exception ex)
+            {
+
+                Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message);
+            }
+
+        }
+        public static void PrintAuto(DevExpress.XtraEditors.TextEdit txt_psnQty_1, DevExpress.XtraEditors.TextEdit txt_iCount_1, DevExpress.XtraEditors.RadioGroup radOut)
+        {
+            txt_psnQty_1.Text = "";
+            txt_iCount_1.Text = "";
+            radOut.Properties.Items[0].Description = "鍏ㄨ嚜鍔�";
+            if (radOut.SelectedIndex == 2)
+                txt_iCount_1.ReadOnly = false;
+            else
+                txt_iCount_1.ReadOnly = true;
+        }
+        public static decimal PrintYuLiang(DevExpress.XtraEditors.RadioGroup rd)
+        {
+            decimal dc = 0;
+            if (rd.SelectedIndex != 0)
+                return 0;
+            string txt = rd.Properties.Items[0].Description;// = "鍏ㄨ嚜鍔ㄣ��" + remainder.ToString() + "銆�";
+            txt = txt.Trim().Replace("鍏ㄨ嚜鍔ㄣ��", "");
+            txt = txt.Replace("銆�", "");
+            if (string.IsNullOrEmpty(txt))
+                return 0;
+            return decimal.Parse(txt);
+        }
+
+        #region 缁樺埗琛ㄥご鍏ㄩ�夊嬀閫夋
+        /// <summary>
+        /// 缁樺埗琛ㄥご鍏ㄩ�夊嬀閫夋
+        /// </summary>
+        //  private Rectangle checkBoxColumnHeaderRect = Rectangle.Empty;
+        // private GridColumn checkBoxColumn = null;
+        public static void CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
+        {
+
+            Rectangle checkBoxColumnHeaderRect = new Rectangle(51, 1, 37, 57);
+            if (e.Column != null && e.Column.AbsoluteIndex == 0)
+            {
+                //X = 51 Y = 1 Width = 37 Height = 57
+                e.Column.Caption = ".";
+                checkBoxColumnHeaderRect = e.Bounds;
+                // checkBoxColumn = e.Column;
+                //椤绘妸鍒楀ご鏍囬璁剧疆涓虹┖
+                e.Painter.DrawObject(e.Info);
+                //鍦ㄥ垪澶翠腑蹇冩樉绀哄閫夋
+                int x = e.Bounds.X + (int)((e.Bounds.Width - CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.UncheckedNormal).Width) * 0.5);
+                int y = e.Bounds.Y + (int)((e.Bounds.Height - CheckBoxRenderer.GetGlyphSize(e.Graphics, CheckBoxState.UncheckedNormal).Height) * 0.5);
+                Point location = new Point(x, y);
+                CheckBoxState checkBoxState;
+                if (e.Column.Tag != null && e.Column.Tag.ToString() == "1")
+                    checkBoxState = CheckBoxState.CheckedPressed;
+                else
+                    checkBoxState = CheckBoxState.UncheckedNormal;
+                CheckBoxRenderer.DrawCheckBox(e.Graphics, location, checkBoxState);
+                e.Handled = true;
+            }
+        }
+
+        public static void CustomMouseUp(object sender, MouseEventArgs e, DevExpress.XtraGrid.GridControl gcMain, DevExpress.XtraGrid.Views.Grid.GridView gridView1)
+        {
+            GridColumn checkBoxColumn = gridView1.Columns[0];
+            Rectangle checkBoxColumnHeaderRect = new Rectangle(51, 1, 37, 57);
+            if (checkBoxColumnHeaderRect != Rectangle.Empty)
+            {
+                if (e.X > checkBoxColumnHeaderRect.X && e.X < (checkBoxColumnHeaderRect.X + checkBoxColumnHeaderRect.Width) && e.Y > checkBoxColumnHeaderRect.Y && e.Y < (checkBoxColumnHeaderRect.Y + checkBoxColumnHeaderRect.Height))
+                {
+                    DataTable _Table = (DataTable)gcMain.DataSource;
+                    if (checkBoxColumn.Tag != null && checkBoxColumn.Tag.ToString() == "1")
+                    {
+                        checkBoxColumn.Tag = "0";
+                        foreach (DataRow row in _Table.Rows)
+                        {
+                            row["chkInt"] = false;
+                        }
+                    }
+                    else
+                    {
+                        checkBoxColumn.Tag = "1";
+                        foreach (DataRow row in _Table.Rows)
+                        {
+                            row["chkInt"] = true;
+                        }
+                    }
+                    gcMain.BindingContext = new BindingContext();
+                    gcMain.DataSource = _Table;
+                    gcMain.ForceInitialize();
+                    gridView1.CloseEditor();
+                    gridView1.PostEditor();
+                    gridView1.UpdateCurrentRow();
+                    gridView1.InvalidateColumnHeader(checkBoxColumn);
+                }
+            }
+        }
+        #endregion
     }
 
     /// <summary>

--
Gitblit v1.9.3