| | |
| | | using Newtonsoft.Json.Linq; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.IO; |
| | | using System.Linq; |
| | |
| | | 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 = json["rtnData"]; |
| | | return rto; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置系统字体大小,目前并不通用 |
| | | /// 标准json串返回ReturnModel-->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:为groupBox1.Controls/panel1.Controls</param> |
| | | /// <param name="dynamicObject">对像</param> |
| | | /// <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(); |
| | | 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; |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | MessageBox.Show(strName + ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清空容器里面的控件 |
| | | /// </summary> |
| | | /// <param name="controls">controls:为groupBox1.Controls/panel1.Controls</param> |
| | | /// <param name="isEdt">是否可编辑</param> |
| | | public static void CleanValue(ControlCollection controls, Boolean 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:为groupBox1.Controls/panel1.Controls</param> |
| | | /// <param name="isEdt">是否可编辑</param> |
| | | public static void ChangeEnable(ControlCollection controls, Boolean isEdt) |
| | | { |
| | | foreach (Control ctrl in controls) |
| | | { |
| | | //文本 |
| | | if (ctrl is TextEdit) |
| | | { |
| | | ctrl.Enabled = isEdt; |
| | | continue; |
| | | } |
| | | //数字卡 |
| | | if (ctrl is NumericUpDown) |
| | | { |
| | | 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(); |
| | | } |
| | | } |
| | | } |