From 452f7aa3fdd30953b53de1ac0c137db64857b400 Mon Sep 17 00:00:00 2001 From: lg <999544862qq.com> Date: 星期三, 28 八月 2024 10:25:27 +0800 Subject: [PATCH] 暂无 --- WebApi/Gs.User/Service/OrganizationController.cs | 199 ++++++++++++++++++++++++ DevApp/Gs.DevApp/ToolBox/MsgHelper.cs | 100 ++++++++++++ WebApi/Gs.User/Modes/MenuAction.cs | 15 + DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs | 154 +++++++++++++++++++ 4 files changed, 463 insertions(+), 5 deletions(-) diff --git a/DevApp/Gs.DevApp/ToolBox/MsgHelper.cs b/DevApp/Gs.DevApp/ToolBox/MsgHelper.cs new file mode 100644 index 0000000..e129883 --- /dev/null +++ b/DevApp/Gs.DevApp/ToolBox/MsgHelper.cs @@ -0,0 +1,100 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace Gs.DevApp.ToolBox +{ + /// <summary> + /// 绯荤粺娑堟伅鎻愮ず绐椾綋 + /// </summary> + public class MsgHelper + { + /// <summary> + /// 鎵撳紑瀵硅瘽妗� + /// </summary> + /// <param name="msg">鏈瀵硅瘽鍐呭</param> + /// <returns></returns> + public static bool AskQuestion(string msg) + { + DialogResult r; + r = MessageBox.Show(msg, "纭", + MessageBoxButtons.YesNo, + MessageBoxIcon.Question, + MessageBoxDefaultButton.Button2); + return r == DialogResult.Yes; + } + + /// <summary> + /// 閿欒娑堟伅鎻愮ず妗� + /// </summary> + /// <param name="msg">閿欒娑堟伅鍐呭</param> + public static void ShowError(string msg) + { + MessageBox.Show(msg, "璀﹀憡", + MessageBoxButtons.OK, + MessageBoxIcon.Hand, + MessageBoxDefaultButton.Button1); + } + + /// <summary> + /// 鏄剧ず绯荤粺寮傚父 + /// </summary> + /// <param name="e">绯荤粺寮傚父</param> + public static void ShowException(Exception e) + { + var s = e.Message; + var innerMsg = string.Empty; + + if (e.InnerException != null) + { + innerMsg = e.InnerException.Message; + s += "\n" + innerMsg; + } + + Warning(s); + } + + public static void ShowException(Exception ex, string customMessage) + { + //if (ex is CustomException) + //{ + // ShowException(ex); + //} + //else if (customMessage != "") + //{ + // Warning(customMessage); + //} + //else + //{ + // Warning(ex.Message); + //} + } + + /// <summary> + /// 淇℃伅鎻愮ず妗� + /// </summary> + /// <param name="msg">鏈鏄剧ず鐨勬秷鎭�</param> + public static void ShowInformation(string msg) + { + MessageBox.Show(msg, "淇℃伅", + MessageBoxButtons.OK, + MessageBoxIcon.Asterisk, + MessageBoxDefaultButton.Button1); + } + + /// <summary> + /// 璀﹀憡鎻愮ず妗� + /// </summary> + /// <param name="msg">璀﹀憡鍐呭</param> + public static void Warning(string msg) + { + MessageBox.Show(msg, "璀﹀憡", + MessageBoxButtons.OK, + MessageBoxIcon.Exclamation, + MessageBoxDefaultButton.Button1); + } + } +} diff --git a/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs new file mode 100644 index 0000000..0274d05 --- /dev/null +++ b/DevApp/Gs.DevApp/ToolBox/UtilityHelper.cs @@ -0,0 +1,154 @@ +锘縰sing Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Gs.DevApp.ToolBox; +using System.Resources; +using System.Drawing; +using Newtonsoft.Json; +using Gs.DevApp.Models; + +namespace Gs.DevApp.ToolBox +{ + /// <summary> + /// 閫氱敤绫� + /// </summary> + public class UtilityHelper + { + private static string WebApiUrl = System.Configuration.ConfigurationSettings.AppSettings.Get("WebApiUrl").ToString(); + + /// <summary> + /// httpPost璁块棶鏈嶅姟 + /// </summary> + /// <param name="url">鏈嶅姟鍦板潃</param> + /// <param name="meth">鏂规硶鍚嶇О</param> + /// <param name="param">鍙傛暟</param> + /// <returns></returns> + public static string HttpPost(string url, string meth, string param) + { + if (string.IsNullOrEmpty(url)) + url = WebApiUrl; + url += meth; + HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); + request.Method = "POST"; + request.ContentType = "application/json"; + request.Headers.Add("token", GetBasicAuthTicket()); + request.Accept = "*/*"; + request.Timeout = 15000; + request.AllowAutoRedirect = false; + StreamWriter requestStream = null; + WebResponse response = null; + string responseStr = null; + try + { + requestStream = new StreamWriter(request.GetRequestStream()); + requestStream.Write(param); + requestStream.Close(); + response = request.GetResponse(); + if (response != null) + { + StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); + responseStr = reader.ReadToEnd(); + //File.WriteAllText(Server.MapPath("~/") + @"\test.txt", responseStr); + reader.Close(); + } + } + catch (Exception ex) + { + throw ex; + } + finally + { + request = null; + requestStream = null; + response = null; + } + return responseStr; + } + /// <summary> + /// 鏍规嵁鍥剧墖鍚嶈鍙栬祫婧愭枃浠�,涓嶅甫鍚庣紑鍚� + /// </summary> + /// <param name="imageName"></param> + /// <param name="lay">1涓哄ぇ鍥�</param> + /// <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; + if (image != null) + { + return image; + } + } + catch (Exception ex) + { + } + Image image2 = resourceManager.GetObject(lay == 1 ? "chartsshowlegend_32x32" : "linktoprevious_16x16") as Image; + return image2; + } + /// <summary> + /// 璇诲彇token + /// </summary> + /// <returns></returns> + public static string GetBasicAuthTicket() + { + string token = Guid.NewGuid().ToString(); + return token; + } + /// <summary> + /// 鏍囧噯json涓茶繑鍥濺eturnModel-->table锛� + /// </summary> + /// <param name="strReturn"></param> + /// <returns></returns> + public static ReturnModel<PageListModel> GetTableByJson(string strReturn) + { + ReturnModel<PageListModel> rto = new ReturnModel<PageListModel>(); + JObject json = JObject.Parse(strReturn); + rto.rtnCode =int.Parse( json["rtnCode"].ToString()); + rto.rtnMsg = json["rtnMsg"].ToString(); + rto.rtnData = new PageListModel(); + rto.rtnData.pages = int.Parse(json["rtnData"]["pages"].ToString()); + rto.rtnData.total = int.Parse(json["rtnData"]["total"].ToString()); + rto.rtnData.everyPageSize = int.Parse(json["rtnData"]["everyPageSize"].ToString()); + JArray array = new JArray(); + var d = json["rtnData"]["list"]; + foreach (var a in d) + { + array.Add(a); + } + DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString()); + rto.rtnData.list = dt; + return rto; + } + + + + + /// <summary> + /// 鏍囧噯json涓茶繑鍥濺eturnModel->瀛楃涓诧紝 + /// </summary> + /// <param name="strReturn"></param> + /// <returns></returns> + public static ReturnModel<dynamic> GetDataByJson(string strReturn) + { + ReturnModel<dynamic> rto = new ReturnModel<dynamic>(); + JObject json = JObject.Parse(strReturn); + rto.rtnCode =int.Parse( json["rtnCode"].ToString()); + rto.rtnMsg = json["rtnMsg"].ToString(); + rto.rtnData = json["rtnData"]; + return rto; + } + } +} diff --git a/WebApi/Gs.User/Modes/MenuAction.cs b/WebApi/Gs.User/Modes/MenuAction.cs index 6e1c262..2aeb2e8 100644 --- a/WebApi/Gs.User/Modes/MenuAction.cs +++ b/WebApi/Gs.User/Modes/MenuAction.cs @@ -23,10 +23,6 @@ /// </summary> public string name { get; set; } - /// <summary> - /// 缂栧彿 - /// </summary> - public string serialNumber { get; set; } /// <summary> /// 鑿滃崟鍥炬爣 @@ -38,10 +34,12 @@ /// </summary> public int status { get; set; } + public string statusTxt { get; set; } + /// <summary> /// 绐椾綋璺緞 /// </summary> - public string fromPath { get; set; } + public string formPath { get; set; } /// <summary> /// 鎺掑簭 /// </summary> @@ -52,5 +50,12 @@ /// </summary> public int category { get; set; } + public string categoryTxt { get; set; } + + /// <summary> + /// 鏄惁鍐呯疆 + /// </summary> + public int isSys { get; set; } + } } diff --git a/WebApi/Gs.User/Service/OrganizationController.cs b/WebApi/Gs.User/Service/OrganizationController.cs new file mode 100644 index 0000000..3ada6a5 --- /dev/null +++ b/WebApi/Gs.User/Service/OrganizationController.cs @@ -0,0 +1,199 @@ +锘縰sing Gs.Toolbox; +using Gs.User.Modes; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gs.User.Service +{ + [ApiGroup(ApiGroupNames.Auth)] + public class OrganizationController : IRomteService + { + /// <summary> + /// 璇诲彇鏈烘瀯鍒楄〃锛屾敮鎸佸垎椤� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [RequestMethod(RequestMethods.POST)] + public ReturnDto<PageList<dynamic>> GetListPage([FromBody] PageQuery model) + { + int currentPage = model.currentPage; + int everyPageSize = model.everyPageSize; + string sortName = string.IsNullOrEmpty(model.sortName) ? "a.name" : model.sortName; + System.Text.StringBuilder sbSql = new StringBuilder(); + sbSql.Append("select * from "); + sbSql.Append("( "); + sbSql.Append("select top 100000 ROW_NUMBER() over(order by " + sortName + " " + model.sortOrder + ") as rowIndex,* from sys_Organization a where 1=1" + model.keyWhere); + sbSql.Append(") as T "); + sbSql.Append(" where T.rowindex>(" + currentPage + "-1)*" + everyPageSize + " and T.rowindex<=" + currentPage + "*" + everyPageSize + ""); + sbSql.Append(" select count(1) as intTotal from sys_Organization a where 1=1 " + model.keyWhere).ToString(); + DataSet dset = new DataSet(); + try + { + dset = Gs.Toolbox.DbHelperSQL.Query(sbSql.ToString()); + } + catch (Exception ex) + { + Gs.Toolbox.LogHelper.Debug(this.ToString(), "GetListPage error锛�" + ex.Message); + return ReturnDto<PageList<dynamic>>.QuickReturn(default(PageList<dynamic>), ReturnCode.Exception, "璇诲彇澶辫触"); + } + PageList<dynamic> _pglist = new PageList<dynamic> + { + total = 0, + everyPageSize = 0, + pages = 0, + list = new List<dynamic>() + }; + if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0)//鏈夋暟鎹� + { + int intTotal = int.Parse(dset.Tables[1].Rows[0]["intTotal"].ToString()); + int pages = (intTotal % everyPageSize != 0) ? (intTotal / everyPageSize + 1) : (intTotal / everyPageSize); + _pglist.total = intTotal; + _pglist.everyPageSize = everyPageSize; + _pglist.pages = pages; + foreach (DataRow dr in dset.Tables[0].Rows) + { + _pglist.list.Add( + new + { + guid = Guid.Parse(dr["guid"].ToString()), + upGuid = dr["upGuid"].ToString(), + name = dr["name"].ToString(), + conPeople = dr["conPeople"].ToString(), + conTel = int.Parse(dr["conTel"].ToString()), + status = int.Parse(dr["status"].ToString()), + } + ); + } + } + return ReturnDto<PageList<dynamic>>.QuickReturn(_pglist, ReturnCode.Success, "璇诲彇鎴愬姛"); + } + + + /// <summary> + /// 鍒犻櫎鏈烘瀯 + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [RequestMethod(RequestMethods.POST)] + public ReturnDto<int?> DeleteModel([FromBody] MenuAction model) + { + int rtnInt = (int)ReturnCode.Default; + int cont = 0; + try + { + //鏄惁鍐呯疆 + cont = int.Parse(DbHelperSQL.GetSingle("select count(1) from sys_Organization where guid='" + model.guid.ToString() + "' and [isSys]=1").ToString()); + if (cont > 0) + { + return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "鍒犻櫎澶辫触锛岃鏉$洰涓虹郴缁熷唴缃紝涓嶅彲鍒犻櫎锛�"); + } + rtnInt = DbHelperSQL.ExecuteSql("delete from sys_Organization where guid='" + model.guid.ToString() + "'"); + } + catch (Exception ex) + { + LogHelper.Debug(this.ToString(), "DeleteModel error锛�" + ex.Message); + rtnInt = (int)ReturnCode.Exception; + } + if (rtnInt > 0) + return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Success, "鎿嶄綔鎴愬姛锛屽叡鍒犻櫎" + rtnInt.ToString() + "鏉℃暟鎹紒"); + else + return ReturnDto<int>.QuickReturn(default(int?), ReturnCode.Exception, "鍒犻櫎澶辫触锛岃閲嶈瘯锛�"); + } + + /// <summary> + /// 澧炲姞鏈烘瀯 + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [RequestMethod(RequestMethods.POST)] + public ReturnDto<int?> EditModel([FromBody] dynamic model) + { + Guid? guid = model.guid; + Guid? upGuid = model.upGuid; + string name = model.name; + string conPeople = model.conPeople; + string conTel = model.conTel; + int status = model.status; + int? rtnInt = (int)ReturnCode.Default; + StringBuilder strSql = new StringBuilder(); + if (guid != null) + { + strSql.Append(" update sys_Organization"); + strSql.Append(" set upGuid=@upGuid,name=@name,conPeople=@conPeople,status=@status,conTel=@conTel"); + strSql.Append(" where guid='" + guid + "'"); + } + else + { + guid = Guid.NewGuid(); + strSql.Append("insert into sys_Organization("); + strSql.Append(" guid,upGuid,name,conPeople,status,conTel)"); + strSql.Append(" values ("); + strSql.Append("'" + guid + "',@upGuid,@name,@conPeople,@status,@conTel)"); + } + SqlParameter[] parameters = { + new SqlParameter("@upGuid", upGuid), + new SqlParameter("@name", name), + new SqlParameter("@conPeople",conPeople), + new SqlParameter("@status",status), + new SqlParameter("@conTel",conTel), + }; + try + { + rtnInt = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); + } + catch (Exception ex) + { + LogHelper.Debug(this.ToString(), "EditModel error锛�" + ex.Message); + rtnInt = (int)ReturnCode.Exception; + } + if (rtnInt > 0) + return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Success, "鎿嶄綔鎴愬姛锛�"); + else + return ReturnDto<int>.QuickReturn(rtnInt, ReturnCode.Exception, "澧炲姞澶辫触锛岃閲嶈瘯锛�"); + } + + /// <summary> + /// 璇诲彇鏈烘瀯 + /// </summary> + /// <param name="guid"></param> + /// <returns></returns> + [RequestMethod(RequestMethods.POST)] + [AllowAnonymous] + public ReturnDto<MenuAction> GetModel([FromBody] dynamic model) + { + dynamic m = new System.Dynamic.ExpandoObject(); + System.Text.StringBuilder sbSql = new StringBuilder(); + sbSql.Append("select top 1 * from sys_Organization where 1=1 and guid='" + model.guid.ToString() + "' "); + try + { + DataSet dset = new DataSet(); + dset = DbHelperSQL.Query(sbSql.ToString()); + if (dset != null && dset.Tables.Count > 0 && dset.Tables[0].Rows.Count > 0) + { + System.Data.DataRow dr = dset.Tables[0].Rows[0]; + m.guid = Guid.Parse(dr["guid"].ToString()); + m.upGuid = dr["upGuid"].ToString(); + m.name = dr["name"].ToString(); + m.conPeople = dr["conPeople"].ToString(); + m.status = int.Parse(dr["status"].ToString()); + m.conTel = dr["conTel"].ToString(); + return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Success, "璇诲彇鎴愬姛锛�"); + } + else + return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "璇诲彇澶辫触锛�"); + } + catch (Exception ex) + { + LogHelper.Debug(this.ToString(), "GetModel error:" + ex.Message); + return ReturnDto<dynamic>.QuickReturn(m, ReturnCode.Default, "璇诲彇澶辫触锛�"); + } + } + } +} -- Gitblit v1.9.3