From ab354260b4b9ca8cf1aa12573310ec2a9598e084 Mon Sep 17 00:00:00 2001
From: lg <999544862qq.com>
Date: 星期五, 20 九月 2024 22:04:35 +0800
Subject: [PATCH] 库位设置
---
DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 348 insertions(+), 9 deletions(-)
diff --git a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
index 2b078be..83f1141 100644
--- a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
+++ b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs
@@ -1,6 +1,5 @@
锘縰sing Newtonsoft.Json.Linq;
using System;
-using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
@@ -10,8 +9,14 @@
using System.Resources;
using System.Drawing;
using Newtonsoft.Json;
-using Gs.DevApp.Models;
+using Gs.DevApp.Entity;
using System.Windows.Forms;
+using static System.Windows.Forms.Control;
+using DevExpress.XtraEditors;
+using DevExpress.XtraTab;
+using System.Text.RegularExpressions;
+using System.Xml;
+using System.Collections.Generic;
namespace Gs.DevApp.ToolBox
{
@@ -147,17 +152,351 @@
rto.rtnData = json["rtnData"];
return rto;
}
+
/// <summary>
- /// 璁剧疆绯荤粺瀛椾綋澶у皬锛岀洰鍓嶅苟涓嶉�氱敤
+ /// 鏍囧噯json涓茶繑鍥濺eturnModel-->table锛�
/// </summary>
- public static float GetFontSize = 10;
- public static void SetFont(Control control)
+ /// <param name="strReturn"></param>
+ /// <returns></returns>
+ public static ReturnModel<DataTable> GetNoPageTableByJson(string strReturn)
{
- float size = GetFontSize;
- foreach (Control childControl in control.Controls)
+ ReturnModel<DataTable> rto = new ReturnModel<DataTable>();
+ JObject json = JObject.Parse(strReturn);
+ rto.rtnCode = int.Parse(json["rtnCode"].ToString());
+ rto.rtnMsg = json["rtnMsg"].ToString();
+ rto.rtnData = new DataTable();
+ JArray array = new JArray();
+ var d = json["rtnData"];
+ foreach (var a in d)
{
- childControl.Font = new Font(childControl.Font.FontFamily, size, childControl.Font.Style);
- SetFont(childControl);
+ array.Add(a);
+ }
+ DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString());
+ rto.rtnData = dt;
+ return rto;
+ }
+
+
+ /// <summary>
+ /// 璇诲彇榛樿椤靛ぇ灏�
+ /// </summary>
+ /// <returns></returns>
+ public static int GetPageSize()
+ {
+ return 50;
+ // return int.Parse(System.Configuration.ConfigurationSettings.AppSettings.Get("PageSize").ToString());
+ }
+
+ /// <summary>
+ /// 鏍规嵁瀵硅薄鎵归噺璁剧疆鏂囨湰鍊�
+ /// </summary>
+ /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param>
+ /// <param name="dynamicObject">瀵瑰儚</param>
+ /// <param name="isEdt">鏄惁鍙紪杈�</param>
+ public static void SetValueByObj(ControlCollection controls, dynamic dynamicObject, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
+ {
+ if (gridViews != null)
+ {
+ foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews)
+ {
+ gv.OptionsBehavior.Editable = isEdt;
+ }
+ }
+ foreach (JProperty property in dynamicObject.Properties())
+ {
+ string strName = property.Name;
+ string strVal = property.Value.ToString();
+ try
+ {
+ // // 濡傛灉value鏄竴涓璞★紝鍙互閫掑綊閬嶅巻
+ // if (property.Value is JObject)
+ // {
+ // JObject nestedObject = (JObject)property.Value;
+ // foreach (JProperty nestedProperty in nestedObject.Properties())
+ // {
+ // Console.WriteLine("\tName: {0}, Value: {1}", nestedProperty.Name, nestedProperty.Value);
+ // }
+ // }
+ Control[] cols = controls.Find("txt_" + strName, true);
+ if (cols.Length > 0)
+ {
+ Control colType = cols[0];
+ //LookUpEdit
+ if (colType is LookUpEdit)
+ {
+ LookUpEdit txt = colType as LookUpEdit;
+ if (txt != null)
+ {
+ txt.EditValue = strVal;
+ // txt.Text = strVal;
+ }
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //涓嬫媺
+ if (colType is ComboBoxEdit)
+ {
+ ComboBoxEdit txt = colType as ComboBoxEdit;
+ if (txt.Properties.TextEditStyle == DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor)
+ txt.SelectedIndex = int.Parse(strVal);
+ else
+ txt.Text = strVal;
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //鏂囨湰
+ if (colType is TextEdit)
+ {
+ TextEdit txt = colType as TextEdit;
+ if (txt != null)
+ txt.Text = strVal;
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //鏁板瓧鍗�
+ if (colType is NumericUpDown)
+ {
+ NumericUpDown txt = colType as NumericUpDown;
+ if (txt != null)
+ txt.Text = strVal;
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //鍗曢��
+ if (colType is CheckEdit)
+ {
+ CheckEdit txt = colType as CheckEdit;
+ if (txt != null)
+ txt.Checked = (strVal.ToString() == "1" ? true : false);
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //鏃堕棿
+ if (colType is DateTimePicker)
+ {
+ DateTimePicker txt = colType as DateTimePicker;
+ if (txt != null)
+ txt.Checked = (strVal.ToString() == "1" ? true : false);
+ txt.Enabled = isEdt;
+ continue;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+
+ MessageBox.Show(strName + ex.Message);
+ }
+
+ }
+
+ }
+
+ /// <summary>
+ /// 娓呯┖瀹瑰櫒閲岄潰鐨勬帶浠�
+ /// </summary>
+ /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param>
+ /// <param name="isEdt">鏄惁鍙紪杈�</param>
+ public static void CleanValue(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
+ {
+ if (gridViews != null)
+ {
+ foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews)
+ {
+ gv.OptionsBehavior.Editable = isEdt;
+ }
+ }
+ foreach (Control ctrl in controls)
+ {
+ ctrl.Enabled = isEdt;
+ //澶氳鏂囨湰
+ if (ctrl is MemoEdit)
+ {
+ MemoEdit txt = ctrl as MemoEdit;
+ txt.Text = "";
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //涓嬫媺
+ if (ctrl is ComboBoxEdit)
+ {
+ ComboBoxEdit txt = ctrl as ComboBoxEdit;
+ if (txt.Properties.TextEditStyle == DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor)
+ txt.SelectedIndex = 0;
+ else
+ txt.Text = "";
+ txt.Enabled = isEdt;
+ continue;
+ }
+ //鏂囨湰
+ if (ctrl is TextEdit)
+ {
+ ctrl.Text = "";
+ continue;
+ }
+ }
+ }
+
+ /// <summary>
+ /// 绂佺敤鎴栧惎鐢ㄥ鍣ㄩ噷闈㈢殑鎺т欢
+ /// </summary>
+ /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param>
+ /// <param name="isEdt">鏄惁鍙紪杈�</param>
+ public static void ChangeEnable(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null)
+ {
+ if (gridViews != null)
+ {
+ foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews)
+ {
+ gv.OptionsBehavior.Editable = isEdt;
+ }
+ }
+ foreach (Control ctrl in controls)
+ {
+ //鏂囨湰
+ if (ctrl is TextEdit)
+ {
+ ctrl.Enabled = isEdt;
+ continue;
+ }
+ //鏁板瓧鍗�
+ if (ctrl is NumericUpDown)
+ {
+ ctrl.Enabled = isEdt;
+ continue;
+ }
+ //鏃ユ湡
+ if (ctrl is DateTimePicker)
+ {
+ ctrl.Enabled = isEdt;
+ continue;
+ }
+ }
+ }
+
+ /// <summary>
+ ///鍒囨崲閫夐」鍗�
+ /// </summary>
+ /// <param name="tabControl">閫夐」鍗″鍣�</param>
+ /// <param name="idx">浠�0寮�濮嬶紝濡傛灉鏄�999锛屽垯鍏ㄩ儴鍙敤</param>
+ public static void ChangeTab(XtraTabControl tabControl, int idx)
+ {
+ if (idx == 999)
+ {
+ for (int i = 0; i < tabControl.TabPages.Count; i++)
+ {
+ tabControl.TabPages[i].PageEnabled = true;
+ }
+ tabControl.SelectedTabPageIndex = tabControl.TabPages.Count - 1;
+ return;
+ }
+ for (int i = 0; i < tabControl.TabPages.Count; i++)
+ {
+ tabControl.TabPages[i].PageEnabled = false;
+ }
+ tabControl.TabPages[idx].PageEnabled = true;
+ tabControl.SelectedTabPageIndex = idx;
+ }
+
+
+ public static void TreeViewCheck(TreeViewEventArgs e)
+ {
+ try
+ {
+ if (e.Node.Nodes.Count > 0)
+ {
+ bool NoFalse = true;
+ foreach (TreeNode tn in e.Node.Nodes)
+ {
+ if (tn.Checked == false)
+ {
+ NoFalse = false;
+ }
+ }
+ if (e.Node.Checked == true || NoFalse)
+ {
+ foreach (TreeNode tn in e.Node.Nodes)
+ {
+ if (tn.Checked != e.Node.Checked)
+ {
+ tn.Checked = e.Node.Checked;
+ }
+ }
+ }
+ }
+ if (e.Node.Parent != null && e.Node.Parent is TreeNode)
+ {
+ bool ParentNode = true;
+ foreach (TreeNode tn in e.Node.Parent.Nodes)
+ {
+ if (tn.Checked == false)
+ {
+ ParentNode = false;
+ }
+ }
+ if (e.Node.Parent.Checked != ParentNode && (e.Node.Checked == false || e.Node.Checked == true && e.Node.Parent.Checked == false))
+ {
+ e.Node.Parent.Checked = ParentNode;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+
+ }
+
+ /// <summary>
+ /// 杞┘宄板懡鍚�
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public static string ToCamelCase(string propertyName)
+ {
+ if (propertyName.Length > 0 && propertyName.All(char.IsUpper))
+ propertyName = propertyName.ToLower();
+ string dd = Regex.Replace(propertyName, @"_([a-z])", m => m.Groups[1].Value.ToUpper());
+ return dd;
+ }
+ public static void UpdateAppConfig(string key, string newValue)
+ {
+ string configFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.Load(configFile);
+
+ XmlNode node = xmlDoc.SelectSingleNode($"//appSettings//add[@key='{key}']");
+ if (node != null)
+ {
+ XmlAttribute attribute = node as XmlAttribute;
+ attribute.Value = newValue;
+ xmlDoc.Save(configFile);
+ }
+ }
+ public class CboItemEntity
+ {
+ private object _text = 0;
+ private object _Value = "";
+ /// <summary>
+ /// 鏄剧ず鍊�
+ /// </summary>
+ public object Text
+ {
+ get { return this._text; }
+ set { this._text = value; }
+ }
+ /// <summary>
+ /// 瀵硅薄鍊�
+ /// </summary>
+ public object Value
+ {
+ get { return this._Value; }
+ set { this._Value = value; }
+ }
+
+ public override string ToString()
+ {
+ return this.Text.ToString();
}
}
}
--
Gitblit v1.9.3