| | |
| | | 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; |
| | | |
| | | namespace Gs.DevApp.ToolBox |
| | | { |
| | |
| | | rto.rtnData = dt; |
| | | return rto; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 读取默认页大小 |
| | |
| | | /// <param name="isEdt">是否可编辑</param> |
| | | public static void SetValueByObj(ControlCollection controls, dynamic dynamicObject, Boolean isEdt) |
| | | { |
| | | |
| | | foreach (JProperty property in dynamicObject.Properties()) |
| | | { |
| | | string strName = property.Name; |
| | | string strVal = property.Value.ToString(); |
| | | // // 如果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) |
| | | try |
| | | { |
| | | Control colType = cols[0]; |
| | | //下拉 |
| | | if (colType is ComboBoxEdit) |
| | | // // 如果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) |
| | | { |
| | | 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; |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | MessageBox.Show(strName + ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public static string ToCamelCase(string input) |
| | | public static string ToCamelCase(string propertyName) |
| | | { |
| | | if (string.IsNullOrEmpty(input)) |
| | | return input; |
| | | |
| | | // 匹配非字母数字字符后的第一个字母,并将其转换为大写 |
| | | return Regex.Replace( |
| | | input, |
| | | "([a-z])([A-Z])", |
| | | "$1$2", |
| | | RegexOptions.CultureInvariant |
| | | ).Trim(); |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | } |