From c6cec258cd89de9a2d241a755a4b41d57593b726 Mon Sep 17 00:00:00 2001 From: Chunkit Yeung Date: Fri, 23 Feb 2024 22:39:15 +0800 Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9EJSON=E8=BD=AC?= =?UTF-8?q?=E6=8D=A2=E6=96=B9=E6=B3=95=E3=80=822=E3=80=81=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E5=8A=A0=E5=AF=86=E6=96=B9=E6=B3=95=E3=80=823?= =?UTF-8?q?=E3=80=81=E6=9B=B4=E6=94=B9Swagger=20xml=E4=BB=A5=E9=80=82?= =?UTF-8?q?=E5=BA=94=E5=AD=90=E6=A8=A1=E5=9D=97=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SYS.Common/HttpHelper.cs | 73 +++++++++++++++++-- SYS.Common/SYS.Common.csproj | 2 +- SYS.Common/packages.config | 14 +--- SYS.FormUI/AppFunction/FrmDepartment.cs | 7 +- .../AppFunction/FrmOperation.Designer.cs | 16 +++- 5 files changed, 86 insertions(+), 26 deletions(-) diff --git a/SYS.Common/HttpHelper.cs b/SYS.Common/HttpHelper.cs index d495dae..efdc84c 100644 --- a/SYS.Common/HttpHelper.cs +++ b/SYS.Common/HttpHelper.cs @@ -1,7 +1,5 @@ -using jvncorelib_fr.EncryptorLib; -using jvncorelib_fr.EntityLib; -using jvncorelib_fr.HttpLib; -using Newtonsoft.Json; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.IO; @@ -15,6 +13,8 @@ using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Web; using System.Web.Script.Serialization; +using jvncorelib_fr.EncryptorLib; +using jvncorelib_fr.EntityLib; namespace SYS.Common { @@ -23,7 +23,7 @@ namespace SYS.Common /// public static class HttpHelper { - static EncryptLib encryptLib = new EncryptLib(); + static EncryptLib encrypt = new EncryptLib(); #region 受限于打包插件的限制才放在这,个人开发时建议统一在App.Config进行配置 @@ -41,12 +41,65 @@ namespace SYS.Common /// public const string postUrl = ""; /// - /// WebApi URL + /// WebApi URL(release) /// + //public const string apiUrl = ""; + + + + // Debug public const string apiUrl = ""; #endregion + public class IgnoreNullValuesConverter : JsonConverter + { + private readonly bool _convertEmptyStringToNull; + + // 添加一个构造函数,允许在创建转换器实例时指定是否将空字符串转换为 null + public IgnoreNullValuesConverter(bool convertEmptyStringToNull = false) + { + _convertEmptyStringToNull = convertEmptyStringToNull; + } + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + JObject obj = JObject.FromObject(value, serializer); + + foreach (var prop in obj.Properties().ToList()) + { + if (prop.Value == null || string.IsNullOrEmpty(prop.Value.ToString())) + { + // 根据 _convertEmptyStringToNull 决定是移除属性还是设置为 null + if (_convertEmptyStringToNull && prop.Value?.Type == JTokenType.String) + { + prop.Value = JValue.CreateNull(); + } + else + { + prop.Remove(); + } + } + } + + obj.WriteTo(writer); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + // 实现这个方法是必要的,但是本例中不需要修改 + throw new NotImplementedException(); + } + + public override bool CanConvert(Type objectType) + { + // 仅为示例,根据实际情况调整 + return objectType == typeof(JObject); + } + + public override bool CanRead => false; // 设置为 false,因为我们不需要修改反序列化的行为 + } + /// /// WebClient上传文件至服务器 /// @@ -77,7 +130,7 @@ namespace SYS.Common var sourceStr = url.Replace("​", string.Empty); //解密原始URL - var api = encryptLib.Decryption(apiUrl); + var api = encrypt.Decryption(apiUrl); var requestUrl = api + sourceStr; @@ -404,7 +457,11 @@ namespace SYS.Common { try { - return Newtonsoft.Json.JsonConvert.SerializeObject(input); + return Newtonsoft.Json.JsonConvert.SerializeObject(input, new JsonSerializerSettings + { + Converters = { new IgnoreNullValuesConverter(true) }, + Formatting = Formatting.Indented // 如果需要格式化输出 + }); } catch (Exception ex) { diff --git a/SYS.Common/SYS.Common.csproj b/SYS.Common/SYS.Common.csproj index 6b385fa..b9e6459 100644 --- a/SYS.Common/SYS.Common.csproj +++ b/SYS.Common/SYS.Common.csproj @@ -43,7 +43,7 @@ - + ..\packages\jvncorelib.1.0.1.7\lib\net461\jvncorelib-fr.dll diff --git a/SYS.Common/packages.config b/SYS.Common/packages.config index f1e0447..86b3d10 100644 --- a/SYS.Common/packages.config +++ b/SYS.Common/packages.config @@ -1,17 +1,7 @@  - - - - \ No newline at end of file diff --git a/SYS.FormUI/AppFunction/FrmDepartment.cs b/SYS.FormUI/AppFunction/FrmDepartment.cs index 7c5ec46..fa04f57 100644 --- a/SYS.FormUI/AppFunction/FrmDepartment.cs +++ b/SYS.FormUI/AppFunction/FrmDepartment.cs @@ -35,6 +35,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using jvncorelib_fr.EntityLib; namespace SYS.FormUI { @@ -256,9 +257,9 @@ namespace SYS.FormUI { if (dgvDeptList.SelectedRows.Count == 1) { - txtDeptNo.Text = dgvDeptList.SelectedRows[0].Cells["clDeptNo"].Value.ToString(); - txtDeptName.Text = dgvDeptList.SelectedRows[0].Cells["clDeptName"].Value.ToString(); - txtDeptDesc.Text = dgvDeptList.SelectedRows[0].Cells["clDeptDesc"].Value.ToString(); + txtDeptNo.Text = dgvDeptList.SelectedRows[0].Cells["clDeptNo"].Value.IsNullOrEmpty() ? "" : dgvDeptList.SelectedRows[0].Cells["clDeptNo"].Value.ToString(); + txtDeptName.Text = dgvDeptList.SelectedRows[0].Cells["clDeptName"].Value.IsNullOrEmpty() ? "" : dgvDeptList.SelectedRows[0].Cells["clDeptName"].Value.ToString(); + txtDeptDesc.Text = dgvDeptList.SelectedRows[0].Cells["clDeptDesc"].Value.IsNullOrEmpty() ? "" : dgvDeptList.SelectedRows[0].Cells["clDeptDesc"].Value.ToString(); } } } diff --git a/SYS.FormUI/AppFunction/FrmOperation.Designer.cs b/SYS.FormUI/AppFunction/FrmOperation.Designer.cs index db251f7..a5815a7 100644 --- a/SYS.FormUI/AppFunction/FrmOperation.Designer.cs +++ b/SYS.FormUI/AppFunction/FrmOperation.Designer.cs @@ -106,6 +106,7 @@ dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; this.dgvOperationlog.RowHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dgvOperationlog.RowHeadersVisible = false; + this.dgvOperationlog.RowHeadersWidth = 72; this.dgvOperationlog.RowHeight = 29; dataGridViewCellStyle5.BackColor = System.Drawing.Color.White; this.dgvOperationlog.RowsDefaultCellStyle = dataGridViewCellStyle5; @@ -113,13 +114,14 @@ this.dgvOperationlog.SelectedIndex = -1; this.dgvOperationlog.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgvOperationlog.ShowGridLine = true; - this.dgvOperationlog.Size = new System.Drawing.Size(998, 582); + this.dgvOperationlog.Size = new System.Drawing.Size(998, 522); this.dgvOperationlog.TabIndex = 1; // // clOperationTime // this.clOperationTime.DataPropertyName = "OperationTime"; this.clOperationTime.HeaderText = "操作时间"; + this.clOperationTime.MinimumWidth = 9; this.clOperationTime.Name = "clOperationTime"; this.clOperationTime.ReadOnly = true; // @@ -127,6 +129,7 @@ // this.clSoftwareVersion.DataPropertyName = "SoftwareVersion"; this.clSoftwareVersion.HeaderText = "软件版本"; + this.clSoftwareVersion.MinimumWidth = 9; this.clSoftwareVersion.Name = "clSoftwareVersion"; this.clSoftwareVersion.ReadOnly = true; // @@ -134,6 +137,7 @@ // this.clOperationlog.DataPropertyName = "LogContent"; this.clOperationlog.HeaderText = "操作日志"; + this.clOperationlog.MinimumWidth = 9; this.clOperationlog.Name = "clOperationlog"; this.clOperationlog.ReadOnly = true; // @@ -141,6 +145,7 @@ // this.clOperationAccount.DataPropertyName = "OperationAccount"; this.clOperationAccount.HeaderText = "操作人"; + this.clOperationAccount.MinimumWidth = 9; this.clOperationAccount.Name = "clOperationAccount"; this.clOperationAccount.ReadOnly = true; // @@ -148,6 +153,7 @@ // this.Column1.DataPropertyName = "delete_mk"; this.Column1.HeaderText = "Column1"; + this.Column1.MinimumWidth = 9; this.Column1.Name = "Column1"; this.Column1.ReadOnly = true; this.Column1.Visible = false; @@ -156,6 +162,7 @@ // this.Column2.DataPropertyName = "datains_usr"; this.Column2.HeaderText = "Column2"; + this.Column2.MinimumWidth = 9; this.Column2.Name = "Column2"; this.Column2.ReadOnly = true; this.Column2.Visible = false; @@ -164,6 +171,7 @@ // this.Column3.DataPropertyName = "datains_date"; this.Column3.HeaderText = "Column3"; + this.Column3.MinimumWidth = 9; this.Column3.Name = "Column3"; this.Column3.ReadOnly = true; this.Column3.Visible = false; @@ -172,6 +180,7 @@ // this.Column4.DataPropertyName = "datachg_usr"; this.Column4.HeaderText = "Column4"; + this.Column4.MinimumWidth = 9; this.Column4.Name = "Column4"; this.Column4.ReadOnly = true; this.Column4.Visible = false; @@ -180,6 +189,7 @@ // this.Column5.DataPropertyName = "datachg_date"; this.Column5.HeaderText = "Column5"; + this.Column5.MinimumWidth = 9; this.Column5.Name = "Column5"; this.Column5.ReadOnly = true; this.Column5.Visible = false; @@ -188,6 +198,7 @@ // this.clOperationLevel.DataPropertyName = "OperationLevelNm"; this.clOperationLevel.HeaderText = "日志级别"; + this.clOperationLevel.MinimumWidth = 9; this.clOperationLevel.Name = "clOperationLevel"; this.clOperationLevel.ReadOnly = true; // @@ -195,13 +206,14 @@ // this.Column6.DataPropertyName = "OperationLevel"; this.Column6.HeaderText = "Column6"; + this.Column6.MinimumWidth = 9; this.Column6.Name = "Column6"; this.Column6.ReadOnly = true; this.Column6.Visible = false; // // FrmOperation // - this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F); + this.AutoScaleDimensions = new System.Drawing.SizeF(17F, 36F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(235)))), ((int)(((byte)(243)))), ((int)(((byte)(255))))); this.ClientSize = new System.Drawing.Size(1005, 623); -- Gitee From 45e04ef97ad7b201c0707337bb22094b1cc0628f Mon Sep 17 00:00:00 2001 From: Chunkit Yeung Date: Fri, 23 Feb 2024 22:39:33 +0800 Subject: [PATCH 2/2] add submodule --- topsky-hotel-manager-system-web-api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/topsky-hotel-manager-system-web-api b/topsky-hotel-manager-system-web-api index 0cb470d..362105e 160000 --- a/topsky-hotel-manager-system-web-api +++ b/topsky-hotel-manager-system-web-api @@ -1 +1 @@ -Subproject commit 0cb470d901a0376335da1c52bc9ac206a6bc8107 +Subproject commit 362105ec9f3044a9038dd66d6addec6dd0e09384 -- Gitee