fqc
lu
2025-05-06 437425784b7612e10d4a54bd64905c508347514d
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -28,6 +28,7 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
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;
@@ -909,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;
                }
            }
@@ -1006,7 +1027,6 @@
                    ctrl.Enabled = !isEdt;
                    continue;
                }
                //
                if (ctrl is CheckEdit)
                {
                    var txt = ctrl as CheckEdit;
@@ -1090,7 +1110,6 @@
                    txt.IsReadly = isEdt;
                    continue;
                }
                //自定部门
                if (ctrl is UcLookDepartment)
                {
@@ -1133,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;
                }
            }
@@ -1352,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的当前行
@@ -1618,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)
        {
@@ -1634,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;
        }
@@ -1668,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>
@@ -1747,9 +1801,9 @@
                    column.OptionsColumn.ReadOnly = false;
                else
                    column.OptionsColumn.ReadOnly = true;
                if(isPostSearch==false)
                    column.OptionsColumn.ReadOnly = true;
                //if(isPostSearch==false)
                //    column.OptionsColumn.ReadOnly = true;
                if (isPostSearch == true)
                {
@@ -2023,12 +2077,21 @@
        }
        #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>
        /// 判断是不是一个有效果的decimal数值
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsNumeric2(string str)
        {
            string input = str;
@@ -2036,7 +2099,20 @@
            bool isNumeric = decimal.TryParse(input, out number);
            return isNumeric;
        }
        /// <summary>
        /// 判断是不是一个有效的正整数
        /// </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)
@@ -2090,6 +2166,75 @@
                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>