From a9c9f13461dbe9ab88677d94f9033db30a6558b0 Mon Sep 17 00:00:00 2001
From: lu <99954486@qq.com>
Date: 星期三, 23 十月 2024 16:40:09 +0800
Subject: [PATCH] 增加了一个测试窗体
---
DevApp/Gs.DevApp/DevFrm/Sys/SysMenu.cs | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 357 insertions(+), 0 deletions(-)
diff --git a/DevApp/Gs.DevApp/DevFrm/Sys/SysMenu.cs b/DevApp/Gs.DevApp/DevFrm/Sys/SysMenu.cs
new file mode 100644
index 0000000..bb90c0c
--- /dev/null
+++ b/DevApp/Gs.DevApp/DevFrm/Sys/SysMenu.cs
@@ -0,0 +1,357 @@
+锘縰sing DevExpress.XtraEditors;
+using DevExpress.XtraEditors.Controls;
+using Gs.DevApp.Entity;
+using Gs.DevApp.ToolBox;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Drawing;
+using System.Reflection;
+using System.Resources;
+using System.Windows.Forms;
+
+namespace Gs.DevApp.DevFrm.User
+{
+ public partial class SysMenu : DevExpress.XtraEditors.XtraForm
+ {
+ public SysMenu()
+ {
+ InitializeComponent();
+ getImg();
+ txt_upGuid.Properties.PopupFormSize = new System.Drawing.Size(txt_upGuid.Width, 300);
+ txt_upGuid.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
+ this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
+ this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
+ this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
+ this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
+ this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
+ this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
+ txt_category.TextChanged += Txt_category_TextChanged;
+ tlMenu.MouseDoubleClick += TlMenu_MouseDoubleClick;
+ txt_upGuid.Properties.TreeList.IndicatorWidth = 50;
+ txt_upGuid.Properties.TreeList.CustomDrawNodeIndicator += (s, ee) =>
+ {
+ if (ee.IsNodeIndicator)
+ {
+ var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node);
+ ee.Info.DisplayText = (index + 1).ToString();
+ }
+ };
+ tlMenu.IndicatorWidth = 50;
+ tlMenu.CustomDrawNodeIndicator += (s, ee) =>
+ {
+ if (ee.IsNodeIndicator)
+ {
+ var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node);
+ ee.Info.DisplayText = (index + 1).ToString();
+ }
+ };
+ getTree();
+ getDownList();
+ getActionList();
+ }
+
+ /// <summary>
+ /// 鑿滃崟绫诲瀷鏀瑰彉浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void Txt_category_TextChanged(object sender, EventArgs e)
+ {
+ if (txt_category.SelectedIndex == 1)
+ {
+ this.txt_formPath.Enabled = true;
+ this.txt_icon.Enabled = true;
+ }
+ else
+ {
+ this.txt_formPath.Enabled = false;
+ this.txt_icon.Enabled = false;
+ this.txt_formPath.Text = "";
+ }
+ }
+ /// <summary>
+ /// 鍙屽嚮琛屼簨浠�
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void TlMenu_MouseDoubleClick(object sender, System.Windows.Forms.MouseEventArgs e)
+ {
+ string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(tlMenu, e, "guid");
+ if (!string.IsNullOrEmpty(rowGuid))
+ getModel(rowGuid, false, 999);
+ }
+ /// <summary>
+ /// 鍙栨秷浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
+ {
+ UtilityHelper.JumpToTab(xtraTabControl1, 0);
+ }
+
+ /// <summary>
+ /// 鍒犻櫎浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
+ {
+ string rowGuid, rowName;
+ (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_name, tlMenu);
+ if (string.IsNullOrEmpty(rowGuid))
+ {
+ ToolBox.MsgHelper.Warning("璇峰厛閫夋嫨浣犺鎿嶄綔鐨勮锛�");
+ return;
+ }
+ if (!MsgHelper.AskQuestion("浣犻�夋嫨浜嗐��" + rowName + "銆戯紝纭畾鍒犻櫎鍚楋紵"))
+ {
+ return;
+ }
+ List<string> lst = new List<string>();
+ lst.Add(rowGuid);
+ var _obj = lst;
+ try
+ {
+ string strJson = UtilityHelper.HttpPost("", "MenuAction/DeleteModel", JsonConvert.SerializeObject(_obj));
+ ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
+ if (_rtn.rtnCode > 0)
+ {
+ UtilityHelper.JumpToTab(xtraTabControl1, 0);
+ getTree();
+ }
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + _rtn.rtnMsg);
+ }
+ catch (Exception ex)
+ {
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 鍒锋柊浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
+ {
+ UtilityHelper.JumpToTab(xtraTabControl1, 0);
+ getTree();
+ }
+ /// <summary>
+ /// 淇敼浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
+ {
+ string rowGuid, rowName;
+ (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_name, tlMenu);
+ if (string.IsNullOrEmpty(rowGuid))
+ {
+ ToolBox.MsgHelper.Warning("璇峰厛閫夋嫨浣犺鎿嶄綔鐨勮锛�");
+ return;
+ }
+ getModel(rowGuid, true, 1);
+ if (txt_category.SelectedIndex == 1)
+ {
+ this.txt_formPath.Enabled = true;
+ this.txt_icon.Enabled = true;
+ }
+ else
+ {
+ this.txt_formPath.Enabled = false;
+ this.txt_icon.Enabled = false;
+ }
+ }
+ /// <summary>
+ /// 鏂板浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
+ {
+ UtilityHelper.JumpToTab(xtraTabControl1, 1);
+ lbGuid.Text = "";
+ UtilityHelper.CleanValueByControl(this.panel1.Controls, true);
+ }
+ /// <summary>
+ /// 淇濆瓨浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
+ {
+ toolBarMenu1.isSetBtn = false;
+ if (string.IsNullOrEmpty(txt_category.Text.Trim()) || txt_category.SelectedIndex == 0)
+ {
+ Gs.DevApp.ToolBox.MsgHelper.Warning("鑿滃崟绫诲瀷涓嶈兘涓虹┖锛�");
+ txt_category.Focus();
+ return;
+ }
+ if (string.IsNullOrEmpty(txt_name.Text.Trim()))
+ {
+ Gs.DevApp.ToolBox.MsgHelper.Warning("鑿滃崟鍚嶇О涓嶈兘涓虹┖锛�");
+ txt_name.Focus();
+ return;
+ }
+ string _upGuid = txt_upGuid.EditValue.ToString();
+ if (txt_category.SelectedIndex == 2 && string.IsNullOrEmpty(_upGuid))
+ {
+ Gs.DevApp.ToolBox.MsgHelper.Warning("鎸夐挳绫诲瀷蹇呴』閫夋嫨鐖剁骇鑿滃崟锛�");
+ txt_upGuid.Focus();
+ return;
+ }
+ var _obj = new
+ {
+ guid = lbGuid.Text.Trim(),//涓诲缓
+ upGuid = _upGuid,//涓婄骇鐨勪富寤�
+ name = txt_name.Text.Trim(),//鍚嶇О
+ icon = txt_icon.Text,//鑿滃崟鍥炬爣
+ isStatus = txt_isStatus.Checked,//鐘舵��
+ formPath = txt_formPath.Text.Trim(),//绐椾綋璺緞
+ idx = int.Parse(txt_idx.Value.ToString()),//鎺掑簭
+ category = txt_category.SelectedIndex,//绫诲瀷
+ };
+ try
+ {
+ string strJson = UtilityHelper.HttpPost("", "MenuAction/EditModel", JsonConvert.SerializeObject(_obj));
+ ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + _rtn.rtnMsg);
+ if (_rtn.rtnCode > 0)
+ {
+ lbGuid.Text = _rtn.rtnData;
+ toolBarMenu1.isSetBtn = true;
+ UtilityHelper.ChangeEnableByControl(this.panel1.Controls, false);
+ }
+ }
+ catch (Exception ex)
+ {
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+ }
+ }
+
+ /// <summary>
+ /// 璇诲彇鍒楄〃
+ /// </summary>
+ private void getTree()
+ {
+ PageQueryModel pgq = new PageQueryModel(1, 999999, "idx", "asc", "", "");
+ string json = JsonConvert.SerializeObject(pgq);
+ try
+ {
+ string strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPage", json);
+ ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
+ DataTable dt = dd.rtnData.list;
+ this.tlMenu.DataSource = dt;
+ this.tlMenu.KeyFieldName = "guid";
+ this.tlMenu.ParentFieldName = "upGuid";
+ this.tlMenu.Tag = "name";
+ this.tlMenu.EndUpdate();
+ // this.tlMenu.ExpandAll();
+ tlMenu.OptionsView.CheckBoxStyle = DevExpress.XtraTreeList.DefaultNodeCheckBoxStyle.Default;
+ }
+ catch (Exception ex)
+ {
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+ }
+ }
+
+ private void getModel(string strGuid, bool isEdit, int tabIdx)
+ {
+ if (string.IsNullOrEmpty(strGuid))
+ {
+ ToolBox.MsgHelper.Warning("璇峰厛閫夋嫨浣犺鎿嶄綔鐨勮锛�");
+ return;
+ }
+ UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
+ var _obj = new
+ {
+ guid = strGuid,//涓诲缓
+ };
+ try
+ {
+ string strJson = UtilityHelper.HttpPost("", "MenuAction/GetModel", JsonConvert.SerializeObject(_obj));
+ ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
+ if (_rtn.rtnCode > 0)
+ {
+ dynamic dy = _rtn.rtnData;
+ lbGuid.Text = strGuid;
+ UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit);
+ txt_upGuid.EditValue = dy.upGuid.ToString();
+ }
+ else
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + _rtn.rtnMsg);
+ }
+ catch (Exception ex)
+ {
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+ }
+ }
+ /// <summary>
+ /// 璇诲彇涓婄骇鏍�
+ /// </summary>
+ private void getDownList()
+ {
+ PageQueryModel pgq = new PageQueryModel(1, 999999, "idx", "asc", "", " and category=1");
+ string json = JsonConvert.SerializeObject(pgq);
+ try
+ {
+ string strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPage", json);
+ ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
+ DataTable dt = dd.rtnData.list;
+ txt_upGuid.Properties.TreeList.KeyFieldName = "guid";
+ txt_upGuid.Properties.TreeList.ParentFieldName = "upGuid";
+ txt_upGuid.Properties.ValueMember = "guid";
+ txt_upGuid.Properties.DisplayMember = "name";
+ txt_upGuid.Properties.DataSource = dt;
+ }
+ catch (Exception ex)
+ {
+ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message);
+ }
+ }
+ private void getActionList()
+ {
+ List<string> lst = new List<string>();
+ lst = toolBarMenu1.actions;
+ txt_name.Properties.Items.AddRange(toolBarMenu1.actions);
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ Type[] types = assembly.GetTypes();
+ foreach (Type type in types)
+ {
+ if (type.IsSubclassOf(typeof(Form)))
+ {
+ txt_formPath.Properties.Items.Add(type.FullName);
+ }
+ }
+ }
+
+ private void getImg()
+ {
+ Assembly assembly = Assembly.GetExecutingAssembly();
+ ResourceManager resourceManager = new ResourceManager("Gs.DevApp.Properties.Resources", assembly);
+ int i = 0;
+ DevExpress.Utils.ImageCollection dicImg = new DevExpress.Utils.ImageCollection();
+ Properties.Resources res = new Properties.Resources();
+ PropertyInfo[] properInfo = res.GetType().GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance);
+ foreach (PropertyInfo item in properInfo)
+ {
+ if (item.Name.Contains("_"))
+ {
+ Image image = resourceManager.GetObject(item.Name) as Image;
+ if (image != null)
+ {
+ dicImg.AddImage(image);
+ txt_icon.Properties.Items.Add(new DevExpress.XtraEditors.Controls.ImageComboBoxItem(item.Name, i, i));
+ i++;
+ }
+ }
+ }
+ txt_icon.Properties.LargeImages = dicImg;
+ txt_icon.Properties.SmallImages = dicImg;
+ }
+ }
+}
\ No newline at end of file
--
Gitblit v1.9.3