From 4bc7030c4cea5b3deed0c938ec388ae94e33c51c Mon Sep 17 00:00:00 2001 From: lu <99954486@qq.com> Date: 星期五, 25 十月 2024 09:42:36 +0800 Subject: [PATCH] 修改会页 --- DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs | 459 +++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 376 insertions(+), 83 deletions(-) diff --git a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs index 38b4766..24cf5c3 100644 --- a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs +++ b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs @@ -16,6 +16,20 @@ using DevExpress.XtraTab; using System.Text.RegularExpressions; using System.Collections.Generic; +using Gs.DevApp.UserControl; +using DevExpress.XtraGrid.Columns; +using DevExpress.XtraGrid; +using DevExpress.XtraGrid.Views.Grid; +using System.Configuration; +using DevExpress.XtraGrid.Views.Grid.ViewInfo; +using DevExpress.XtraTreeList.Nodes; +using DevExpress.XtraTreeList; +using System.Net.Http; +using System.Threading.Tasks; +using DevExpress.Data.Helpers; +using DevExpress.Utils.About; +using DevExpress.Office.Model; + namespace Gs.DevApp.ToolBox { @@ -24,7 +38,26 @@ /// </summary> public class UtilityHelper { - private static string WebApiUrl = System.Configuration.ConfigurationSettings.AppSettings.Get("WebApiUrl").ToString(); + private static string WebApiUrl = ConfigurationManager.AppSettings["WebApiUrl"].ToString(); + + + + public static async Task<string> UploadFileAsync(string filePath) + { + using (var httpClient = new HttpClient()) + using (var form = new MultipartFormDataContent()) + { + httpClient.DefaultRequestHeaders.Add("token", ToolBox.UtilityHelper.GetBasicAuthTicket()); + using (var fs = File.OpenRead(filePath)) + using (var streamContent = new StreamContent(fs)) + { + form.Add(streamContent, "file", Path.GetFileName(filePath)); + var response = await httpClient.PostAsync(WebApiUrl + "Upload/UploadFile", form); + string responseString = await response.Content.ReadAsStringAsync(); + return responseString; + } + } + } /// <summary> /// httpPost璁块棶鏈嶅姟 @@ -64,6 +97,7 @@ } catch (Exception ex) { + LogHelper.Debug(url, param + ":" + ex.Message); throw ex; } finally @@ -76,13 +110,12 @@ } /// <summary> - /// 璇诲彇榛樿椤靛ぇ灏� + /// 榛樿椤靛ぇ灏� /// </summary> /// <returns></returns> public static int GetPageSize() { - return 50; - // return int.Parse(System.Configuration.ConfigurationSettings.AppSettings.Get("PageSize").ToString()); + return int.Parse(System.Configuration.ConfigurationSettings.AppSettings.Get("PageSize").ToString()); } /// <summary> @@ -93,11 +126,8 @@ /// <returns></returns> public static Image GetImgFromResource(string imageName, int lay) { - // 鑾峰彇褰撳墠绋嬪簭闆� Assembly assembly = Assembly.GetExecutingAssembly(); - // 鍒涘缓璧勬簮绠$悊鍣ㄦ潵璁块棶璧勬簮 ResourceManager resourceManager = new ResourceManager("Gs.DevApp.Properties.Resources", assembly); - // 灏濊瘯鑾峰彇鍥剧墖璧勬簮 try { Image image = resourceManager.GetObject(imageName) as Image; @@ -108,12 +138,30 @@ } catch (Exception ex) { + } Image image2 = resourceManager.GetObject(lay == 1 ? "chartsshowlegend_32x32" : "linktoprevious_16x16") as Image; return image2; } + /// <summary> - /// 鐢熸垚token + /// 鍒濆鍖栦竴涓〃 + /// </summary> + /// <param name="gc"></param> + /// <param name="gv"></param> + public static void SetDefaultTable(GridControl gc, GridView gv) + { + DataTable dt = new DataTable(); + foreach (GridColumn col in gv.Columns) + { + dt.Columns.Add(col.FieldName, typeof(string)); + } + gc.BindingContext = new BindingContext(); + gc.DataSource = dt; + gc.ForceInitialize(); + } + /// <summary> + /// 鐢熸垚璁块棶鏈嶅姟鐨則oken /// </summary> /// <returns></returns> public static string GetBasicAuthTicket() @@ -124,7 +172,7 @@ return token; } /// <summary> - /// 鏍囧噯json杩斿洖ReturnModel-->鍖呭惈TablePage鍒嗛〉锛� + /// 鏈嶅姟杩斿洖鐨刯son杞负ReturnModel-->鍖呭惈TablePage鍒嗛〉锛� /// </summary> /// <param name="strReturn"></param> /// <returns></returns> @@ -149,7 +197,7 @@ return rto; } /// <summary> - /// 鏍囧噯json杩斿洖ReturnModel锛� + /// 鏈嶅姟杩斿洖鐨刯son杩斿洖ReturnModel锛� /// </summary> /// <param name="strReturn"></param> /// <returns></returns> @@ -164,7 +212,7 @@ } /// <summary> - /// 鏍囧噯json涓茶繑鍥濺eturnModel-->浠呬粎鏈塴ist,涓嶅垎椤碉紝 + /// 鏈嶅姟杩斿洖鐨刯son涓茶繑鍥濺eturnModel-->浠呬粎鏈塴ist,涓嶅垎椤碉紝 /// </summary> /// <param name="strReturn"></param> /// <returns></returns> @@ -187,18 +235,20 @@ } /// <summary> - /// 鏍规嵁瀵硅薄鎵归噺璁剧疆鏂囨湰鍊� + /// 鏍规嵁瀵硅薄鎵归噺璁剧疆鏂囨湰妗嗙殑鍊� /// </summary> /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param> /// <param name="dynamicObject">瀵瑰儚</param> /// <param name="isEdt">鏄惁鍙紪杈�</param> + /// <param name="gridViews">鍏宠仈鐨刧rid</param> public static void SetValueByObj(ControlCollection controls, dynamic dynamicObject, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null) { + isEdt = !isEdt; if (gridViews != null) { foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews) { - gv.OptionsBehavior.Editable = isEdt; + gv.OptionsBehavior.Editable = !isEdt; } } foreach (JProperty property in dynamicObject.Properties()) @@ -207,29 +257,43 @@ 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); + string _dddddd = "txt_" + strName; + Control[] cols = controls.Find(_dddddd, 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; + txt.ReadOnly = isEdt; + continue; + } + if (colType is ImageComboBoxEdit) + { + ImageComboBoxEdit txt = colType as ImageComboBoxEdit; + for (int i = 0; i < txt.Properties.Items.Count; i++) + { + if (txt.Properties.Items[i].Description == strVal) + { + txt.ReadOnly = isEdt; + txt.SelectedIndex = i; + continue; + }; + } + 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.ReadOnly = isEdt; continue; } //涓嬫媺 @@ -240,7 +304,15 @@ txt.SelectedIndex = int.Parse(strVal); else txt.Text = strVal; - txt.Enabled = isEdt; + txt.ReadOnly = isEdt; + continue; + } + //鑷畾涔変笅鎷� + if (colType is UcComBox) + { + UcComBox txt = colType as UcComBox; + txt.Val = strVal; + txt.Enabled = !isEdt; continue; } //鏂囨湰 @@ -249,7 +321,7 @@ TextEdit txt = colType as TextEdit; if (txt != null) txt.Text = strVal; - txt.Enabled = isEdt; + txt.ReadOnly = isEdt; continue; } //鏁板瓧鍗� @@ -258,7 +330,7 @@ NumericUpDown txt = colType as NumericUpDown; if (txt != null) txt.Text = strVal; - txt.Enabled = isEdt; + txt.ReadOnly = isEdt; continue; } //鍗曢�� @@ -266,29 +338,65 @@ { CheckEdit txt = colType as CheckEdit; if (txt != null) - txt.Checked = (strVal.ToString() == "1" ? true : false); - txt.Enabled = isEdt; + { + switch (strVal) + { + case "True": + txt.Checked = true; + break; + case "1": + txt.Checked = true; + break; + case "False": + txt.Checked = false; + break; + default: + txt.Checked = false; + break; + } + } + txt.ReadOnly = isEdt; + continue; + } + //鍗曢�� + if (colType is CheckBox) + { + CheckBox txt = colType as CheckBox; + if (txt != null) + txt.Checked = bool.Parse(strVal); + 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; + txt.Text = strVal.ToString(); + txt.Enabled = !isEdt; + continue; + } + //Label + if (colType is Label) + { + Label txt = colType as Label; + if (_dddddd == "txt_checkStatus") + { + if (strVal.ToString() == "True") + txt.Text = "宸插鏍�"; + if (strVal.ToString() == "False") + txt.Text = "鏈鏍�"; + } + else + txt.Text = strVal.ToString(); continue; } } } catch (Exception ex) { - - MessageBox.Show(strName + ex.Message); + MessageBox.Show(ex.Message); } - } - } /// <summary> @@ -296,24 +404,25 @@ /// </summary> /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param> /// <param name="isEdt">鏄惁鍙紪杈�</param> + /// <param name="gridViews">鍏宠仈鐨刧rid</param> public static void CleanValueByControl(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null) { + isEdt = !isEdt; if (gridViews != null) { foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews) { - gv.OptionsBehavior.Editable = isEdt; + 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; + txt.ReadOnly = isEdt; continue; } //涓嬫媺 @@ -324,13 +433,38 @@ txt.SelectedIndex = 0; else txt.Text = ""; - txt.Enabled = isEdt; + txt.ReadOnly = isEdt; + continue; + } + //鑷畾涔夌殑涓嬫媺 + if (ctrl is UcComBox) + { + UcComBox txt = ctrl as UcComBox; + txt.Val = "0"; + txt.Enabled = !isEdt; continue; } //鏂囨湰 if (ctrl is TextEdit) { - ctrl.Text = ""; + TextEdit txt = ctrl as TextEdit; + txt.Text = ""; + txt.ReadOnly = isEdt; + continue; + } + //鏃堕棿 + if (ctrl is DateTimePicker) + { + DateTimePicker txt = ctrl as DateTimePicker; + txt.Enabled = !isEdt; + continue; + } + //鍗曢�� + if (ctrl is CheckBox) + { + CheckBox txt = ctrl as CheckBox; + txt.Checked = false; + txt.Enabled = !isEdt; continue; } } @@ -340,36 +474,52 @@ /// 绂佺敤鎴栧惎鐢ㄥ鍣ㄩ噷闈㈢殑鎺т欢 /// </summary> /// <param name="controls">controls:涓篻roupBox1.Controls/panel1.Controls</param> - /// <param name="isEdt">鏄惁鍙紪杈�</param> + /// <param name="isEdt"></param> + /// <param name="gridViews"></param> public static void ChangeEnableByControl(ControlCollection controls, Boolean isEdt, List<DevExpress.XtraGrid.Views.Grid.GridView> gridViews = null) { + isEdt = !isEdt; if (gridViews != null) { foreach (DevExpress.XtraGrid.Views.Grid.GridView gv in gridViews) { - gv.OptionsBehavior.Editable = isEdt; + gv.OptionsBehavior.Editable = !isEdt; } } - foreach (Control ctrl in controls) { - ctrl.Enabled = isEdt; //鏂囨湰 if (ctrl is TextEdit) { - ctrl.Enabled = isEdt; + TextEdit txt = ctrl as TextEdit; + txt.ReadOnly = isEdt; continue; } //鏁板瓧鍗� if (ctrl is NumericUpDown) { - ctrl.Enabled = isEdt; + NumericUpDown txt = ctrl as NumericUpDown; + txt.ReadOnly = isEdt; + continue; + } + //涓嬫媺 + if (ctrl is UcComBox) + { + UcComBox txt = ctrl as UcComBox; + txt.Val = "0"; + txt.Enabled = !isEdt; continue; } //鏃ユ湡 if (ctrl is DateTimePicker) { - ctrl.Enabled = isEdt; + ctrl.Enabled = !isEdt; + continue; + } + //鍗曢�� + if (ctrl is CheckBox) + { + ctrl.Enabled = !isEdt; continue; } } @@ -399,52 +549,43 @@ tabControl.SelectedTabPageIndex = idx; } + /// <summary> + /// TreeView鑱斿姩閫夋嫨 + /// </summary> + /// <param name="e"></param> 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) + tn.Checked = e.Node.Checked; + foreach (TreeNode x in tn.Nodes) { - NoFalse = false; - } - } - if (e.Node.Checked == true || NoFalse) - { - foreach (TreeNode tn in e.Node.Nodes) - { - if (tn.Checked != e.Node.Checked) + x.Checked = e.Node.Checked; + foreach (TreeNode y in x.Nodes) { - tn.Checked = e.Node.Checked; + y.Checked = e.Node.Checked; } } } } - if (e.Node.Parent != null && e.Node.Parent is TreeNode) + if (e.Node.Checked == true && e.Node.Parent != null && e.Node.Parent.Nodes.Count > 0) { - bool ParentNode = true; - foreach (TreeNode tn in e.Node.Parent.Nodes) + TreeNode currentNode = e.Node; + while (currentNode != null) { - 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; + currentNode.Checked = e.Node.Checked; + currentNode = currentNode.Parent; } } } catch (Exception ex) { - throw ex; + ToolBox.MsgHelper.ShowError(ex.Message); } - } /// <summary> @@ -452,22 +593,37 @@ /// </summary> /// <param name="input"></param> /// <returns></returns> - public static string ToCamelCase(string propertyName) + public static string ToCamelCase(string strItem) { - 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; + //濡傛灉鍖呭惈灏忓啓锛屼絾涓嶅寘鍚笅鍒掔嚎 + bool hasLowercase = Regex.IsMatch(strItem, @"[a-z]"); + if (hasLowercase && !strItem.Contains("_")) + { + char[] chars = strItem.ToCharArray(); + chars[0] = char.ToLower(chars[0]); + return new string(chars); + } + string[] strItems = strItem.ToLower().Split('_'); + string strItemTarget = strItems[0]; + for (int j = 1; j < strItems.Length; j++) + { + string temp = strItems[j].ToString(); + string temp1 = temp[0].ToString().ToUpper(); + string temp2 = ""; + temp2 = temp1 + temp.Remove(0, 1); + strItemTarget += temp2; + } + return strItemTarget; + } /// <summary> - /// + /// 璇诲彇grid鐨勫綋鍓嶈 /// </summary> /// <param name="xtraTabControl1"></param> /// <param name="lbGuid">缂栬緫妗嗕腑鐨勪富閿悕</param> /// <param name="txtName">缂栬緫妗嗕腑鐨勬枃鏈鍚�</param> /// <param name="gridView1"></param> - /// <param name="gridRowName">鍒楄〃涓殑鏂囨湰鍒楀悕</param> /// <param name="SelectedTabPageIndex"></param> /// <returns></returns> public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1 @@ -490,13 +646,23 @@ { } - else { + else + { _strGuid = dr["guid"].ToString(); - _strName = dr[1].ToString(); + _strName = dr[2].ToString(); } } return (_strGuid, _strName); } + /// <summary> + /// 璇诲彇TreeView鐨勫綋鍓嶈 + /// </summary> + /// <param name="xtraTabControl1"></param> + /// <param name="lbGuid"></param> + /// <param name="txtName"></param> + /// <param name="tlMenu"></param> + /// <param name="SelectedTabPageIndex"></param> + /// <returns></returns> public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1 , System.Windows.Forms.Label lbGuid , DevExpress.XtraEditors.TextEdit txtName @@ -521,6 +687,16 @@ } return (_strGuid, _strName); } + + /// <summary> + /// 璇诲彇TreeList鐨勫綋鍓嶈 + /// </summary> + /// <param name="xtraTabControl1"></param> + /// <param name="lbGuid"></param> + /// <param name="txtName"></param> + /// <param name="tlMenu"></param> + /// <param name="SelectedTabPageIndex"></param> + /// <returns></returns> public static (string, string) GetCurrentRow(XtraTabControl xtraTabControl1 , System.Windows.Forms.Label lbGuid , DevExpress.XtraEditors.TextEdit txtName @@ -541,10 +717,76 @@ } return (_strGuid, _strName); } + + /// <summary> + /// 璇诲彇GridView鍙屽嚮鐨勪富閿� + /// </summary> + /// <param name="gridView1"></param> + /// <param name="e"></param> + /// <param name="colName"></param> + /// <returns></returns> + public static string GetCurrentDoubleRow(DevExpress.XtraGrid.Views.Grid.GridView gridView1 + , MouseEventArgs e + , string colName) + { + GridHitInfo info = gridView1.CalcHitInfo(e.Location); + if (info.InRow) + { + GridView view = info.View as GridView; + if (view != null) + { + DataRow row = view.GetDataRow(info.RowHandle); + if (row != null) + { + string rowGuid = (row[colName].ToString()); + return rowGuid; + } + } + } + return ""; + } + + + /// <summary> + /// 璇诲彇GridView鍙屽嚮鐨勪富閿� + /// </summary> + /// <param name="gridView1"></param> + /// <param name="e"></param> + /// <param name="colName"></param> + /// <returns></returns> + public static string GetCurrentDoubleRow(DevExpress.XtraTreeList.TreeList tlMenu + , MouseEventArgs e + , string colName) + { + TreeListHitInfo info = tlMenu.CalcHitInfo(e.Location); + if (info.Node != null) + { + TreeListNode clickedNode = tlMenu.FocusedNode; + if (clickedNode.FirstNode == null) + { + string rowGuid = clickedNode.GetValue(colName).ToString(); + return rowGuid; + } + } + return ""; + } + + } + /// <summary> + /// 涓嬫媺妗嗘潯鐩被 + /// </summary> public class CboItemEntity { + public CboItemEntity() + { + } + public CboItemEntity(string val, string text) + { + this.Text = text; + this.Value = val; + } private object _text = 0; private object _Value = ""; /// <summary> @@ -569,4 +811,55 @@ return this.Text.ToString(); } } + + /// <summary> + /// 鏌ヨ妗� + /// </summary> + public class FilterEntity + { + /// <summary> + /// + /// </summary> + /// <param name="id">瀛楁鍚�</param> + /// <param name="idDec">瀛楁鍚嶅娉�</param> + /// <param name="oper">鎿嶄綔绗�</param> + /// <param name="operDec">鎿嶄綔绗﹀娉�</param> + /// <param name="val"></param> + public FilterEntity(string id, string idDec, string oper, string operDec, string val) + { + this.fileId = id; + this.fileIdDec = idDec; + this.fileOper = oper; + this.fileOperDec = operDec; + this.fileValue = val; + } + public string fileId + { + get; + set; + } + public string fileIdDec + { + get; + set; + } + public string fileOper + { + get; + set; + } + public string fileOperDec + { + get; + set; + } + public string fileValue + { + get; + set; + } + } + + + } -- Gitblit v1.9.3