From 446f8246c81de9e2ca49375fd071cb2edf0daf67 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Mon, 2 Mar 2020 10:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: dafa9111b57c9251a5372c9a779f0b3665803163 --- labs/CameraCard/CameraCard/App.config | 3 + labs/CameraCard/CameraCard/CameraCard.csproj | 9 +- .../CameraCard/Data/LoginResponse.cs | 6 +- labs/CameraCard/CameraCard/Data/User.cs | 10 + labs/CameraCard/CameraCard/LoginForm.cs | 21 +- .../CameraCard/MainForm.Designer.cs | 248 ++++++++++++++---- labs/CameraCard/CameraCard/MainForm.cs | 90 +++++-- labs/CameraCard/CameraCard/Program.cs | 13 +- labs/CameraCard/CameraCard/ProgressForm.cs | 13 +- .../WebApi/Controllers/TestController.cs | 35 ++- 10 files changed, 336 insertions(+), 112 deletions(-) diff --git a/labs/CameraCard/CameraCard/App.config b/labs/CameraCard/CameraCard/App.config index eca7ace0..60dd4295 100644 --- a/labs/CameraCard/CameraCard/App.config +++ b/labs/CameraCard/CameraCard/App.config @@ -1,11 +1,14 @@ + + + diff --git a/labs/CameraCard/CameraCard/CameraCard.csproj b/labs/CameraCard/CameraCard/CameraCard.csproj index f6e3dbdc..94821d75 100644 --- a/labs/CameraCard/CameraCard/CameraCard.csproj +++ b/labs/CameraCard/CameraCard/CameraCard.csproj @@ -169,18 +169,21 @@ - - 5.0.0 - 5.2.7 3.1.2 + + 12.0.3 + 4.2.0.20200208 + + 3.2.0 + diff --git a/labs/CameraCard/CameraCard/Data/LoginResponse.cs b/labs/CameraCard/CameraCard/Data/LoginResponse.cs index 44aaa4d5..28a5d4e8 100644 --- a/labs/CameraCard/CameraCard/Data/LoginResponse.cs +++ b/labs/CameraCard/CameraCard/Data/LoginResponse.cs @@ -2,8 +2,8 @@ { public class LoginResponse { - public int code { get; set; } - public string message { get; set; } - public string data { get; set; } + public int Code { get; set; } + public string Message { get; set; } + public UserModel Data { get; set; } } } \ No newline at end of file diff --git a/labs/CameraCard/CameraCard/Data/User.cs b/labs/CameraCard/CameraCard/Data/User.cs index 256f93db..9fa7acd7 100644 --- a/labs/CameraCard/CameraCard/Data/User.cs +++ b/labs/CameraCard/CameraCard/Data/User.cs @@ -5,5 +5,15 @@ public string UserName { get; set; } public string Password { get; set; } public string PasswordHash { get; set; } + public string RealName { get; set; } + public string Organ { get; set; } + } + + public class UserModel : Entity + { + public string UserName { get; set; } + public string PasswordHash { get; set; } + public string RealName { get; set; } + public string Organ { get; set; } } } \ No newline at end of file diff --git a/labs/CameraCard/CameraCard/LoginForm.cs b/labs/CameraCard/CameraCard/LoginForm.cs index a402486b..b8f19ea4 100644 --- a/labs/CameraCard/CameraCard/LoginForm.cs +++ b/labs/CameraCard/CameraCard/LoginForm.cs @@ -1,13 +1,13 @@ using CameraCard.Data; +using Omu.ValueInjecter; +using Newtonsoft.Json; using System; using System.Configuration; using System.Linq; using System.Net; using System.Net.Http; using System.Text; -using System.Threading; using System.Threading.Tasks; -using System.Web.Script.Serialization; using System.Windows.Forms; namespace CameraCard @@ -110,25 +110,26 @@ namespace CameraCard { var url = ConfigurationManager.AppSettings["login"]; var client = HttpClientFactory.Create(); - var content = new StringContent(new JavaScriptSerializer().Serialize(new { userName = userName, password = password }), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(new { userName = userName, password = password }), Encoding.UTF8, "application/json"); var response = client.PostAsync(url, content).Result; + var resultValue = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == HttpStatusCode.OK) { - var result = new JavaScriptSerializer().Deserialize(response.Content.ReadAsStringAsync().Result); - if (result.code == 0) + var result = JsonConvert.DeserializeObject(resultValue); + if (result.Code == 0) { using (var db = new MyDbContext()) { var user = db.Users.FirstOrDefault(o => o.UserName == userName); if (user == null) { - user = new User { UserName = userName, Password = password, PasswordHash = result.data }; + user = new User { Password = password }; + user.InjectFrom(result.Data); db.Users.Add(user); } else { - user.Password = password; - user.PasswordHash = result.data; + user.InjectFrom(result.Data); } db.SaveChanges(); MainForm.User = user; @@ -136,12 +137,12 @@ namespace CameraCard } else { - MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); + MessageBox.Show($"错误代码:{result.Code},错误消息:{result.Message}"); } } else { - MessageBox.Show(response.Content.ReadAsStringAsync().Result); + MessageBox.Show(resultValue); } } diff --git a/labs/CameraCard/CameraCard/MainForm.Designer.cs b/labs/CameraCard/CameraCard/MainForm.Designer.cs index 28518b70..8ea93639 100644 --- a/labs/CameraCard/CameraCard/MainForm.Designer.cs +++ b/labs/CameraCard/CameraCard/MainForm.Designer.cs @@ -29,10 +29,10 @@ private void InitializeComponent() { System.Windows.Forms.TabPage tab1; - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle(); this.save = new System.Windows.Forms.Button(); this.idcGroupBox = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); @@ -118,13 +118,24 @@ this.tab4 = new System.Windows.Forms.TabPage(); this.tabControl2 = new System.Windows.Forms.TabControl(); this.tabPage1 = new System.Windows.Forms.TabPage(); - this.checkUpdate = new System.Windows.Forms.Button(); this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage3 = new System.Windows.Forms.TabPage(); this.tabPage4 = new System.Windows.Forms.TabPage(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.versionLabel = new System.Windows.Forms.ToolStripStatusLabel(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.autoUpdateOption = new System.Windows.Forms.RadioButton(); + this.serviceLink = new System.Windows.Forms.LinkLabel(); + this.homepageLink = new System.Windows.Forms.LinkLabel(); + this.button1 = new System.Windows.Forms.Button(); + this.label8 = new System.Windows.Forms.Label(); + this.currentVersion = new System.Windows.Forms.Label(); + this.checkUpdate = new System.Windows.Forms.Button(); + this.label9 = new System.Windows.Forms.Label(); + this.loginUserName = new System.Windows.Forms.Label(); + this.userRealName = new System.Windows.Forms.Label(); + this.userOrgan = new System.Windows.Forms.Label(); this.idCard = new CameraCard.IdCard(); tab1 = new System.Windows.Forms.TabPage(); tab1.SuspendLayout(); @@ -141,6 +152,7 @@ this.tab4.SuspendLayout(); this.tabControl2.SuspendLayout(); this.tabPage1.SuspendLayout(); + this.tabPage4.SuspendLayout(); this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -628,23 +640,23 @@ this.groupGrid.AllowUserToAddRows = false; this.groupGrid.AllowUserToDeleteRows = false; this.groupGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.groupGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; + dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.groupGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle5; this.groupGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.groupGrid.DefaultCellStyle = dataGridViewCellStyle2; + dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.groupGrid.DefaultCellStyle = dataGridViewCellStyle6; this.groupGrid.Dock = System.Windows.Forms.DockStyle.Fill; this.groupGrid.Location = new System.Drawing.Point(3, 3); this.groupGrid.Name = "groupGrid"; @@ -808,6 +820,7 @@ // this.pageIndexSelector.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.pageIndexSelector.DisplayMember = "Text"; + this.pageIndexSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.pageIndexSelector.FormattingEnabled = true; this.pageIndexSelector.Location = new System.Drawing.Point(868, 655); this.pageIndexSelector.Name = "pageIndexSelector"; @@ -828,6 +841,7 @@ // this.pageSizeSelector.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.pageSizeSelector.DisplayMember = "Text"; + this.pageSizeSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.pageSizeSelector.FormattingEnabled = true; this.pageSizeSelector.Location = new System.Drawing.Point(90, 655); this.pageSizeSelector.Name = "pageSizeSelector"; @@ -917,14 +931,14 @@ | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.dataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; - dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.dataGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle3; + dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.dataGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7; this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.StudentName, @@ -939,14 +953,14 @@ this.HasChedked, this.HasUploaded, this.StudentId}); - dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; - dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.dataGrid.DefaultCellStyle = dataGridViewCellStyle4; + dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; + dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dataGrid.DefaultCellStyle = dataGridViewCellStyle8; this.dataGrid.Location = new System.Drawing.Point(-4, 53); this.dataGrid.Name = "dataGrid"; this.dataGrid.ReadOnly = true; @@ -1073,7 +1087,10 @@ // // tabPage1 // - this.tabPage1.Controls.Add(this.checkUpdate); + this.tabPage1.Controls.Add(this.userOrgan); + this.tabPage1.Controls.Add(this.userRealName); + this.tabPage1.Controls.Add(this.loginUserName); + this.tabPage1.Controls.Add(this.label9); this.tabPage1.Location = new System.Drawing.Point(44, 4); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); @@ -1082,16 +1099,6 @@ this.tabPage1.Text = "账号"; this.tabPage1.UseVisualStyleBackColor = true; // - // checkUpdate - // - this.checkUpdate.Location = new System.Drawing.Point(95, 63); - this.checkUpdate.Name = "checkUpdate"; - this.checkUpdate.Size = new System.Drawing.Size(89, 32); - this.checkUpdate.TabIndex = 0; - this.checkUpdate.Text = "检查更新"; - this.checkUpdate.UseVisualStyleBackColor = true; - this.checkUpdate.Click += new System.EventHandler(this.checkUpdate_Click); - // // tabPage2 // this.tabPage2.Location = new System.Drawing.Point(44, 4); @@ -1113,6 +1120,14 @@ // // tabPage4 // + this.tabPage4.Controls.Add(this.radioButton2); + this.tabPage4.Controls.Add(this.autoUpdateOption); + this.tabPage4.Controls.Add(this.serviceLink); + this.tabPage4.Controls.Add(this.homepageLink); + this.tabPage4.Controls.Add(this.button1); + this.tabPage4.Controls.Add(this.label8); + this.tabPage4.Controls.Add(this.currentVersion); + this.tabPage4.Controls.Add(this.checkUpdate); this.tabPage4.Location = new System.Drawing.Point(44, 4); this.tabPage4.Name = "tabPage4"; this.tabPage4.Size = new System.Drawing.Size(946, 671); @@ -1145,6 +1160,127 @@ this.versionLabel.Size = new System.Drawing.Size(14, 17); this.versionLabel.Text = "v"; // + // radioButton2 + // + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(51, 143); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(119, 16); + this.radioButton2.TabIndex = 15; + this.radioButton2.Text = "有新版本时提醒我"; + this.radioButton2.UseVisualStyleBackColor = true; + this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); + // + // autoUpdateOption + // + this.autoUpdateOption.AutoSize = true; + this.autoUpdateOption.Checked = true; + this.autoUpdateOption.Location = new System.Drawing.Point(51, 110); + this.autoUpdateOption.Name = "autoUpdateOption"; + this.autoUpdateOption.Size = new System.Drawing.Size(71, 16); + this.autoUpdateOption.TabIndex = 14; + this.autoUpdateOption.TabStop = true; + this.autoUpdateOption.Text = "自动更新"; + this.autoUpdateOption.UseVisualStyleBackColor = true; + this.autoUpdateOption.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); + // + // serviceLink + // + this.serviceLink.AutoSize = true; + this.serviceLink.Location = new System.Drawing.Point(96, 183); + this.serviceLink.Name = "serviceLink"; + this.serviceLink.Size = new System.Drawing.Size(53, 12); + this.serviceLink.TabIndex = 13; + this.serviceLink.TabStop = true; + this.serviceLink.Text = "服务条款"; + this.serviceLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.serviceLink_LinkClicked); + // + // homepageLink + // + this.homepageLink.AutoSize = true; + this.homepageLink.Location = new System.Drawing.Point(49, 183); + this.homepageLink.Name = "homepageLink"; + this.homepageLink.Size = new System.Drawing.Size(29, 12); + this.homepageLink.TabIndex = 12; + this.homepageLink.TabStop = true; + this.homepageLink.Text = "官网"; + this.homepageLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.homepageLink_LinkClicked); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(320, 68); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(89, 32); + this.button1.TabIndex = 11; + this.button1.Text = "意见反馈?"; + this.button1.UseVisualStyleBackColor = true; + // + // label8 + // + this.label8.AutoSize = true; + this.label8.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label8.Location = new System.Drawing.Point(47, 40); + this.label8.Name = "label8"; + this.label8.Size = new System.Drawing.Size(72, 16); + this.label8.TabIndex = 10; + this.label8.Text = "关于应用"; + // + // currentVersion + // + this.currentVersion.AutoSize = true; + this.currentVersion.Location = new System.Drawing.Point(47, 78); + this.currentVersion.Name = "currentVersion"; + this.currentVersion.Size = new System.Drawing.Size(65, 12); + this.currentVersion.TabIndex = 9; + this.currentVersion.Text = "当前版本:"; + // + // checkUpdate + // + this.checkUpdate.Location = new System.Drawing.Point(201, 68); + this.checkUpdate.Name = "checkUpdate"; + this.checkUpdate.Size = new System.Drawing.Size(89, 32); + this.checkUpdate.TabIndex = 8; + this.checkUpdate.Text = "检查更新"; + this.checkUpdate.UseVisualStyleBackColor = true; + this.checkUpdate.Click += new System.EventHandler(this.checkUpdate_Click); + // + // label9 + // + this.label9.AutoSize = true; + this.label9.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.label9.Location = new System.Drawing.Point(60, 36); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(40, 16); + this.label9.TabIndex = 11; + this.label9.Text = "账号"; + // + // loginUserName + // + this.loginUserName.AutoSize = true; + this.loginUserName.Location = new System.Drawing.Point(63, 79); + this.loginUserName.Name = "loginUserName"; + this.loginUserName.Size = new System.Drawing.Size(53, 12); + this.loginUserName.TabIndex = 12; + this.loginUserName.Text = "登录名:"; + // + // userRealName + // + this.userRealName.AutoSize = true; + this.userRealName.Location = new System.Drawing.Point(61, 107); + this.userRealName.Name = "userRealName"; + this.userRealName.Size = new System.Drawing.Size(65, 12); + this.userRealName.TabIndex = 13; + this.userRealName.Text = "用户姓名:"; + // + // userOrgan + // + this.userOrgan.AutoSize = true; + this.userOrgan.Location = new System.Drawing.Point(61, 135); + this.userOrgan.Name = "userOrgan"; + this.userOrgan.Size = new System.Drawing.Size(65, 12); + this.userOrgan.TabIndex = 14; + this.userOrgan.Text = "所属机构:"; + // // idCard // this.idCard.Location = new System.Drawing.Point(-1, 16); @@ -1184,6 +1320,9 @@ this.tab4.ResumeLayout(false); this.tabControl2.ResumeLayout(false); this.tabPage1.ResumeLayout(false); + this.tabPage1.PerformLayout(); + this.tabPage4.ResumeLayout(false); + this.tabPage4.PerformLayout(); this.statusStrip1.ResumeLayout(false); this.statusStrip1.PerformLayout(); this.ResumeLayout(false); @@ -1219,7 +1358,6 @@ private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.TabPage tabPage4; - private System.Windows.Forms.Button checkUpdate; private System.Windows.Forms.ToolStripStatusLabel versionLabel; private System.Windows.Forms.ToolStripStatusLabel statusLabel; private IdCard idCard; @@ -1286,5 +1424,17 @@ private System.Windows.Forms.DataGridViewCheckBoxColumn HasChedked; private System.Windows.Forms.DataGridViewCheckBoxColumn HasUploaded; private System.Windows.Forms.DataGridViewTextBoxColumn StudentId; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.RadioButton autoUpdateOption; + private System.Windows.Forms.LinkLabel serviceLink; + private System.Windows.Forms.LinkLabel homepageLink; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label8; + private System.Windows.Forms.Label currentVersion; + private System.Windows.Forms.Button checkUpdate; + private System.Windows.Forms.Label loginUserName; + private System.Windows.Forms.Label label9; + private System.Windows.Forms.Label userRealName; + private System.Windows.Forms.Label userOrgan; } } \ No newline at end of file diff --git a/labs/CameraCard/CameraCard/MainForm.cs b/labs/CameraCard/CameraCard/MainForm.cs index 1f81d91d..b12e4aa1 100644 --- a/labs/CameraCard/CameraCard/MainForm.cs +++ b/labs/CameraCard/CameraCard/MainForm.cs @@ -1,5 +1,6 @@ using CameraCard.Data; -using Mapster; +using Newtonsoft.Json; +using Omu.ValueInjecter; using System; using System.Collections.Generic; using System.Configuration; @@ -9,11 +10,11 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.IO; using System.Linq; +using System.Net; using System.Net.Http; using System.Reflection; using System.Text; using System.Threading.Tasks; -using System.Web.Script.Serialization; using System.Windows.Forms; namespace CameraCard @@ -28,6 +29,10 @@ namespace CameraCard InitializeComponent(); this.versionLabel.Alignment = ToolStripItemAlignment.Right; this.versionLabel.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString(); + this.currentVersion.Text += this.versionLabel.Text; + this.loginUserName.Text += User.UserName; + this.userRealName.Text += User.RealName; + this.userOrgan.Text += User.Organ; //init if (this.pageSizeSelector.DataSource == null) { @@ -171,6 +176,11 @@ namespace CameraCard })); }); this._cvrHelper.Start(); + //自动更新 + if (this.autoUpdateOption.Checked) + { + this.checkUpdate_Click(null, null); + } } private void cameraSelector_SelectedIndexChanged(object sender, EventArgs e) @@ -207,36 +217,44 @@ namespace CameraCard { var url = ConfigurationManager.AppSettings["pull"]; var client = HttpClientFactory.Create(); - var content = new StringContent(new JavaScriptSerializer().Serialize(new { userName = MainForm.User.UserName }), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(new { userName = MainForm.User.UserName }), Encoding.UTF8, "application/json"); var response = client.PostAsync(url, content).Result; - var result = new JavaScriptSerializer().Deserialize(response.Content.ReadAsStringAsync().Result); - if (result.code == 0) + var resultValue = response.Content.ReadAsStringAsync().Result; + if (response.StatusCode == HttpStatusCode.OK) { - using (var db = new MyDbContext()) + var result = JsonConvert.DeserializeObject(resultValue); + if (result.code == 0) { - int i = 1; - foreach (var item in result.data) + using (var db = new MyDbContext()) { - var entity = db.Students.FirstOrDefault(o => o.Id == item.Id); - if (entity == null) + int i = 1; + foreach (var item in result.data) { - entity = item; - db.Students.Add(entity); - progress?.SetProgress($"正在加载{entity.Name}", i * 100 / result.data.Count); - } - else - { - progress?.SetProgress($"正在更新{entity.Name}", i * 100 / result.data.Count); - entity.Adapt(item); + var entity = db.Students.FirstOrDefault(o => o.Id == item.Id); + if (entity == null) + { + entity = item; + db.Students.Add(entity); + progress?.SetProgress($"正在加载{entity.Name}", i * 100 / result.data.Count); + } + else + { + progress?.SetProgress($"正在更新{entity.Name}", i * 100 / result.data.Count); + entity.InjectFrom(item); + } + db.SaveChanges(); + i++; } - db.SaveChanges(); - i++; } } + else + { + MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); + } } else { - MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); + MessageBox.Show(resultValue); } } catch (Exception ex) @@ -364,9 +382,9 @@ namespace CameraCard { var url = ConfigurationManager.AppSettings["update"]; var client = HttpClientFactory.Create(); - var content = new StringContent(new JavaScriptSerializer().Serialize(new { userName = MainForm.User.UserName }), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(new { userName = MainForm.User.UserName }), Encoding.UTF8, "application/json"); var response = client.PostAsync(url, content).Result; - var result = new JavaScriptSerializer().Deserialize(response.Content.ReadAsStringAsync().Result); + var result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result); if (result.code == 0) { if (result.data.version == this.versionLabel.Text) @@ -743,9 +761,9 @@ namespace CameraCard try { var client = HttpClientFactory.Create(); - var content = new StringContent(new JavaScriptSerializer().Serialize(item), Encoding.UTF8, "application/json"); + var content = new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"); var response = client.PostAsync(url, content).Result; - var result = new JavaScriptSerializer().Deserialize(response.Content.ReadAsStringAsync().Result); + var result = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result); if (result.code == 0) { progress?.SetProgress($"进度{i}/{total}", i * 100 / total); @@ -770,5 +788,27 @@ namespace CameraCard MessageBox.Show(ex.Message); } } + + private void homepageLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start(ConfigurationManager.AppSettings["home"]); + } + + private void serviceLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) + { + Process.Start(ConfigurationManager.AppSettings["service"]); + } + + private void radioButton1_CheckedChanged(object sender, EventArgs e) + { + var redioButton = sender as RadioButton; + if (redioButton.Checked) + { + Configuration configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); + configuration.AppSettings.Settings["check"].Value = redioButton.Text; + configuration.Save(); + ConfigurationManager.RefreshSection("appSettings"); + } + } } } \ No newline at end of file diff --git a/labs/CameraCard/CameraCard/Program.cs b/labs/CameraCard/CameraCard/Program.cs index 97911a4f..81c28d54 100644 --- a/labs/CameraCard/CameraCard/Program.cs +++ b/labs/CameraCard/CameraCard/Program.cs @@ -1,4 +1,6 @@ -using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; using System.Diagnostics; using System.Threading; using System.Windows.Forms; @@ -22,6 +24,15 @@ namespace CameraCard return; } + JsonConvert.DefaultSettings = new Func(() => + { + return new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver(), + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + }); + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm()); diff --git a/labs/CameraCard/CameraCard/ProgressForm.cs b/labs/CameraCard/CameraCard/ProgressForm.cs index 0477b88c..29be8ffb 100644 --- a/labs/CameraCard/CameraCard/ProgressForm.cs +++ b/labs/CameraCard/CameraCard/ProgressForm.cs @@ -5,24 +5,15 @@ namespace CameraCard { public partial class ProgressForm : Form { - private readonly Action _closed; - - public ProgressForm(string title, string status, int min, int max, int width = 0, Action action = null, bool control = true) + public ProgressForm(string title, string status, int min, int max, int width = 0) { InitializeComponent(); + this.ControlBox = false; this.Width = width == 0 ? this.Width : width; this.Text = title; this.status.Text = status; this.progressBar.Minimum = min; this.progressBar.Maximum = max; - this._closed = action; - this.ControlBox = control; - this.FormClosed += ProgressForm_FormClosed; - } - - private void ProgressForm_FormClosed(object sender, FormClosedEventArgs e) - { - this._closed?.Invoke(); } public void SetProgress(string label, int progress) diff --git a/labs/CameraCard/WebApi/Controllers/TestController.cs b/labs/CameraCard/WebApi/Controllers/TestController.cs index fe83f1ec..3f5360d0 100644 --- a/labs/CameraCard/WebApi/Controllers/TestController.cs +++ b/labs/CameraCard/WebApi/Controllers/TestController.cs @@ -30,9 +30,19 @@ namespace WebApi.Controllers { if (ModelState.IsValid) { - return new ApiResponse { Code = 0, Data = model.UserName }; + return new ApiResponse + { + Code = 0, + Data = new + { + model.UserName, + PasswordHash = "hash1", + RealName = "李某某", + Organ = "长春市》农安县》农安县第十中学" + } + }; } - return new ApiResponse { Code = 1, Message = "用户名或密码错误" }; + return new ApiResponse { Code = 1, Message = "数据验证失败" }; } [HttpPost] @@ -69,7 +79,7 @@ namespace WebApi.Controllers Data = list }; } - return new ApiResponse { Code = 1, Message = "用户名不能为空" }; + return new ApiResponse { Code = 1, Message = "数据验证失败" }; } [HttpPost] @@ -91,15 +101,20 @@ namespace WebApi.Controllers [Route("/api/[action]")] public ApiResponse Update([FromBody]PushRequest model) { - return new ApiResponse + if (ModelState.IsValid) { - Code = 0, - Data = new + Console.WriteLine(model.Name); + return new ApiResponse { - version = this._cfg["version"], - file = this._cfg["file"] - } - }; + Code = 0, + Data = new + { + version = this._cfg["version"], + file = this._cfg["file"] + } + }; + } + return new ApiResponse { Code = 1, Message = "数据验证失败" }; } } } \ No newline at end of file