添加自动更新检查

Former-commit-id: dafa9111b57c9251a5372c9a779f0b3665803163
TangShanKaiPing
wanggang 5 years ago
parent 74be0c8c97
commit 446f8246c8

@ -1,11 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="home" value="http://localhost:5000/" />
<add key="service" value="http://localhost:5000/" />
<add key="login" value="http://localhost:5000/api/login" /> <add key="login" value="http://localhost:5000/api/login" />
<add key="pull" value="http://localhost:5000/api/pull" /> <add key="pull" value="http://localhost:5000/api/pull" />
<add key="push" value="http://localhost:5000/api/push" /> <add key="push" value="http://localhost:5000/api/push" />
<add key="update" value="http://localhost:5000/api/update" /> <add key="update" value="http://localhost:5000/api/update" />
<add key="version" value="1.0.0" /> <add key="version" value="1.0.0" />
<add key="check" value="自动更新" />
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />

@ -169,18 +169,21 @@
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Mapster">
<Version>5.0.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNet.WebApi.Client"> <PackageReference Include="Microsoft.AspNet.WebApi.Client">
<Version>5.2.7</Version> <Version>5.2.7</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite"> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite">
<Version>3.1.2</Version> <Version>3.1.2</Version>
</PackageReference> </PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.3</Version>
</PackageReference>
<PackageReference Include="OpenCvSharp4.Windows"> <PackageReference Include="OpenCvSharp4.Windows">
<Version>4.2.0.20200208</Version> <Version>4.2.0.20200208</Version>
</PackageReference> </PackageReference>
<PackageReference Include="ValueInjecter">
<Version>3.2.0</Version>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="lib\DirectShowLib-2005.dll" /> <Content Include="lib\DirectShowLib-2005.dll" />

@ -2,8 +2,8 @@
{ {
public class LoginResponse public class LoginResponse
{ {
public int code { get; set; } public int Code { get; set; }
public string message { get; set; } public string Message { get; set; }
public string data { get; set; } public UserModel Data { get; set; }
} }
} }

@ -5,5 +5,15 @@
public string UserName { get; set; } public string UserName { get; set; }
public string Password { get; set; } public string Password { get; set; }
public string PasswordHash { 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; }
} }
} }

@ -1,13 +1,13 @@
using CameraCard.Data; using CameraCard.Data;
using Omu.ValueInjecter;
using Newtonsoft.Json;
using System; using System;
using System.Configuration; using System.Configuration;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms; using System.Windows.Forms;
namespace CameraCard namespace CameraCard
@ -110,25 +110,26 @@ namespace CameraCard
{ {
var url = ConfigurationManager.AppSettings["login"]; var url = ConfigurationManager.AppSettings["login"];
var client = HttpClientFactory.Create(); 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 response = client.PostAsync(url, content).Result;
var resultValue = response.Content.ReadAsStringAsync().Result;
if (response.StatusCode == HttpStatusCode.OK) if (response.StatusCode == HttpStatusCode.OK)
{ {
var result = new JavaScriptSerializer().Deserialize<LoginResponse>(response.Content.ReadAsStringAsync().Result); var result = JsonConvert.DeserializeObject<LoginResponse>(resultValue);
if (result.code == 0) if (result.Code == 0)
{ {
using (var db = new MyDbContext()) using (var db = new MyDbContext())
{ {
var user = db.Users.FirstOrDefault(o => o.UserName == userName); var user = db.Users.FirstOrDefault(o => o.UserName == userName);
if (user == null) 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); db.Users.Add(user);
} }
else else
{ {
user.Password = password; user.InjectFrom(result.Data);
user.PasswordHash = result.data;
} }
db.SaveChanges(); db.SaveChanges();
MainForm.User = user; MainForm.User = user;
@ -136,12 +137,12 @@ namespace CameraCard
} }
else else
{ {
MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); MessageBox.Show($"错误代码:{result.Code},错误消息:{result.Message}");
} }
} }
else else
{ {
MessageBox.Show(response.Content.ReadAsStringAsync().Result); MessageBox.Show(resultValue);
} }
} }

@ -29,10 +29,10 @@
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.TabPage tab1; System.Windows.Forms.TabPage tab1;
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
this.save = new System.Windows.Forms.Button(); this.save = new System.Windows.Forms.Button();
this.idcGroupBox = new System.Windows.Forms.GroupBox(); this.idcGroupBox = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
@ -118,13 +118,24 @@
this.tab4 = new System.Windows.Forms.TabPage(); this.tab4 = new System.Windows.Forms.TabPage();
this.tabControl2 = new System.Windows.Forms.TabControl(); this.tabControl2 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.checkUpdate = new System.Windows.Forms.Button();
this.tabPage2 = new System.Windows.Forms.TabPage(); this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabPage3 = new System.Windows.Forms.TabPage(); this.tabPage3 = new System.Windows.Forms.TabPage();
this.tabPage4 = new System.Windows.Forms.TabPage(); this.tabPage4 = new System.Windows.Forms.TabPage();
this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel(); this.statusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.versionLabel = 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(); this.idCard = new CameraCard.IdCard();
tab1 = new System.Windows.Forms.TabPage(); tab1 = new System.Windows.Forms.TabPage();
tab1.SuspendLayout(); tab1.SuspendLayout();
@ -141,6 +152,7 @@
this.tab4.SuspendLayout(); this.tab4.SuspendLayout();
this.tabControl2.SuspendLayout(); this.tabControl2.SuspendLayout();
this.tabPage1.SuspendLayout(); this.tabPage1.SuspendLayout();
this.tabPage4.SuspendLayout();
this.statusStrip1.SuspendLayout(); this.statusStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -628,23 +640,23 @@
this.groupGrid.AllowUserToAddRows = false; this.groupGrid.AllowUserToAddRows = false;
this.groupGrid.AllowUserToDeleteRows = false; this.groupGrid.AllowUserToDeleteRows = false;
this.groupGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.groupGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle5.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle5.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle5.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle5.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle5.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.groupGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1; this.groupGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle5;
this.groupGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.groupGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle2.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle6.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.groupGrid.DefaultCellStyle = dataGridViewCellStyle2; this.groupGrid.DefaultCellStyle = dataGridViewCellStyle6;
this.groupGrid.Dock = System.Windows.Forms.DockStyle.Fill; this.groupGrid.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupGrid.Location = new System.Drawing.Point(3, 3); this.groupGrid.Location = new System.Drawing.Point(3, 3);
this.groupGrid.Name = "groupGrid"; 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.pageIndexSelector.DisplayMember = "Text"; this.pageIndexSelector.DisplayMember = "Text";
this.pageIndexSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.pageIndexSelector.FormattingEnabled = true; this.pageIndexSelector.FormattingEnabled = true;
this.pageIndexSelector.Location = new System.Drawing.Point(868, 655); this.pageIndexSelector.Location = new System.Drawing.Point(868, 655);
this.pageIndexSelector.Name = "pageIndexSelector"; 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.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.pageSizeSelector.DisplayMember = "Text"; this.pageSizeSelector.DisplayMember = "Text";
this.pageSizeSelector.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.pageSizeSelector.FormattingEnabled = true; this.pageSizeSelector.FormattingEnabled = true;
this.pageSizeSelector.Location = new System.Drawing.Point(90, 655); this.pageSizeSelector.Location = new System.Drawing.Point(90, 655);
this.pageSizeSelector.Name = "pageSizeSelector"; this.pageSizeSelector.Name = "pageSizeSelector";
@ -917,14 +931,14 @@
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dataGrid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
dataGridViewCellStyle3.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle3.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle7.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle3.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle3.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle3.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle3.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle3; this.dataGrid.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7;
this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.StudentName, this.StudentName,
@ -939,14 +953,14 @@
this.HasChedked, this.HasChedked,
this.HasUploaded, this.HasUploaded,
this.StudentId}); this.StudentId});
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Window; dataGridViewCellStyle8.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle4.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); dataGridViewCellStyle8.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.ControlText; dataGridViewCellStyle8.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle8.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle8.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False; dataGridViewCellStyle8.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGrid.DefaultCellStyle = dataGridViewCellStyle4; this.dataGrid.DefaultCellStyle = dataGridViewCellStyle8;
this.dataGrid.Location = new System.Drawing.Point(-4, 53); this.dataGrid.Location = new System.Drawing.Point(-4, 53);
this.dataGrid.Name = "dataGrid"; this.dataGrid.Name = "dataGrid";
this.dataGrid.ReadOnly = true; this.dataGrid.ReadOnly = true;
@ -1073,7 +1087,10 @@
// //
// tabPage1 // 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.Location = new System.Drawing.Point(44, 4);
this.tabPage1.Name = "tabPage1"; this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
@ -1082,16 +1099,6 @@
this.tabPage1.Text = "账号"; this.tabPage1.Text = "账号";
this.tabPage1.UseVisualStyleBackColor = true; 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 // tabPage2
// //
this.tabPage2.Location = new System.Drawing.Point(44, 4); this.tabPage2.Location = new System.Drawing.Point(44, 4);
@ -1113,6 +1120,14 @@
// //
// tabPage4 // 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.Location = new System.Drawing.Point(44, 4);
this.tabPage4.Name = "tabPage4"; this.tabPage4.Name = "tabPage4";
this.tabPage4.Size = new System.Drawing.Size(946, 671); this.tabPage4.Size = new System.Drawing.Size(946, 671);
@ -1145,6 +1160,127 @@
this.versionLabel.Size = new System.Drawing.Size(14, 17); this.versionLabel.Size = new System.Drawing.Size(14, 17);
this.versionLabel.Text = "v"; 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 // idCard
// //
this.idCard.Location = new System.Drawing.Point(-1, 16); this.idCard.Location = new System.Drawing.Point(-1, 16);
@ -1184,6 +1320,9 @@
this.tab4.ResumeLayout(false); this.tab4.ResumeLayout(false);
this.tabControl2.ResumeLayout(false); this.tabControl2.ResumeLayout(false);
this.tabPage1.ResumeLayout(false); this.tabPage1.ResumeLayout(false);
this.tabPage1.PerformLayout();
this.tabPage4.ResumeLayout(false);
this.tabPage4.PerformLayout();
this.statusStrip1.ResumeLayout(false); this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout(); this.statusStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -1219,7 +1358,6 @@
private System.Windows.Forms.TabPage tabPage2; private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.TabPage tabPage3;
private System.Windows.Forms.TabPage tabPage4; private System.Windows.Forms.TabPage tabPage4;
private System.Windows.Forms.Button checkUpdate;
private System.Windows.Forms.ToolStripStatusLabel versionLabel; private System.Windows.Forms.ToolStripStatusLabel versionLabel;
private System.Windows.Forms.ToolStripStatusLabel statusLabel; private System.Windows.Forms.ToolStripStatusLabel statusLabel;
private IdCard idCard; private IdCard idCard;
@ -1286,5 +1424,17 @@
private System.Windows.Forms.DataGridViewCheckBoxColumn HasChedked; private System.Windows.Forms.DataGridViewCheckBoxColumn HasChedked;
private System.Windows.Forms.DataGridViewCheckBoxColumn HasUploaded; private System.Windows.Forms.DataGridViewCheckBoxColumn HasUploaded;
private System.Windows.Forms.DataGridViewTextBoxColumn StudentId; 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;
} }
} }

@ -1,5 +1,6 @@
using CameraCard.Data; using CameraCard.Data;
using Mapster; using Newtonsoft.Json;
using Omu.ValueInjecter;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Configuration; using System.Configuration;
@ -9,11 +10,11 @@ using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms; using System.Windows.Forms;
namespace CameraCard namespace CameraCard
@ -28,6 +29,10 @@ namespace CameraCard
InitializeComponent(); InitializeComponent();
this.versionLabel.Alignment = ToolStripItemAlignment.Right; this.versionLabel.Alignment = ToolStripItemAlignment.Right;
this.versionLabel.Text += Assembly.GetExecutingAssembly().GetName().Version.ToString(); 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 //init
if (this.pageSizeSelector.DataSource == null) if (this.pageSizeSelector.DataSource == null)
{ {
@ -171,6 +176,11 @@ namespace CameraCard
})); }));
}); });
this._cvrHelper.Start(); this._cvrHelper.Start();
//自动更新
if (this.autoUpdateOption.Checked)
{
this.checkUpdate_Click(null, null);
}
} }
private void cameraSelector_SelectedIndexChanged(object sender, EventArgs e) private void cameraSelector_SelectedIndexChanged(object sender, EventArgs e)
@ -207,9 +217,12 @@ namespace CameraCard
{ {
var url = ConfigurationManager.AppSettings["pull"]; var url = ConfigurationManager.AppSettings["pull"];
var client = HttpClientFactory.Create(); 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 response = client.PostAsync(url, content).Result;
var result = new JavaScriptSerializer().Deserialize<PullResponse>(response.Content.ReadAsStringAsync().Result); var resultValue = response.Content.ReadAsStringAsync().Result;
if (response.StatusCode == HttpStatusCode.OK)
{
var result = JsonConvert.DeserializeObject<PullResponse>(resultValue);
if (result.code == 0) if (result.code == 0)
{ {
using (var db = new MyDbContext()) using (var db = new MyDbContext())
@ -227,7 +240,7 @@ namespace CameraCard
else else
{ {
progress?.SetProgress($"正在更新{entity.Name}", i * 100 / result.data.Count); progress?.SetProgress($"正在更新{entity.Name}", i * 100 / result.data.Count);
entity.Adapt(item); entity.InjectFrom(item);
} }
db.SaveChanges(); db.SaveChanges();
i++; i++;
@ -239,6 +252,11 @@ namespace CameraCard
MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}");
} }
} }
else
{
MessageBox.Show(resultValue);
}
}
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message); MessageBox.Show(ex.Message);
@ -364,9 +382,9 @@ namespace CameraCard
{ {
var url = ConfigurationManager.AppSettings["update"]; var url = ConfigurationManager.AppSettings["update"];
var client = HttpClientFactory.Create(); 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 response = client.PostAsync(url, content).Result;
var result = new JavaScriptSerializer().Deserialize<UpdateResponse>(response.Content.ReadAsStringAsync().Result); var result = JsonConvert.DeserializeObject<UpdateResponse>(response.Content.ReadAsStringAsync().Result);
if (result.code == 0) if (result.code == 0)
{ {
if (result.data.version == this.versionLabel.Text) if (result.data.version == this.versionLabel.Text)
@ -743,9 +761,9 @@ namespace CameraCard
try try
{ {
var client = HttpClientFactory.Create(); 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 response = client.PostAsync(url, content).Result;
var result = new JavaScriptSerializer().Deserialize<PullResponse>(response.Content.ReadAsStringAsync().Result); var result = JsonConvert.DeserializeObject<PullResponse>(response.Content.ReadAsStringAsync().Result);
if (result.code == 0) if (result.code == 0)
{ {
progress?.SetProgress($"进度{i}/{total}", i * 100 / total); progress?.SetProgress($"进度{i}/{total}", i * 100 / total);
@ -770,5 +788,27 @@ namespace CameraCard
MessageBox.Show(ex.Message); 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");
}
}
} }
} }

@ -1,4 +1,6 @@
using System; using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Threading;
using System.Windows.Forms; using System.Windows.Forms;
@ -22,6 +24,15 @@ namespace CameraCard
return; return;
} }
JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
{
return new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
});
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new LoginForm()); Application.Run(new LoginForm());

@ -5,24 +5,15 @@ namespace CameraCard
{ {
public partial class ProgressForm : Form public partial class ProgressForm : Form
{ {
private readonly Action _closed; public ProgressForm(string title, string status, int min, int max, int width = 0)
public ProgressForm(string title, string status, int min, int max, int width = 0, Action action = null, bool control = true)
{ {
InitializeComponent(); InitializeComponent();
this.ControlBox = false;
this.Width = width == 0 ? this.Width : width; this.Width = width == 0 ? this.Width : width;
this.Text = title; this.Text = title;
this.status.Text = status; this.status.Text = status;
this.progressBar.Minimum = min; this.progressBar.Minimum = min;
this.progressBar.Maximum = max; 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) public void SetProgress(string label, int progress)

@ -30,9 +30,19 @@ namespace WebApi.Controllers
{ {
if (ModelState.IsValid) 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] [HttpPost]
@ -69,7 +79,7 @@ namespace WebApi.Controllers
Data = list Data = list
}; };
} }
return new ApiResponse { Code = 1, Message = "用户名不能为空" }; return new ApiResponse { Code = 1, Message = "数据验证失败" };
} }
[HttpPost] [HttpPost]
@ -91,6 +101,9 @@ namespace WebApi.Controllers
[Route("/api/[action]")] [Route("/api/[action]")]
public ApiResponse Update([FromBody]PushRequest model) public ApiResponse Update([FromBody]PushRequest model)
{ {
if (ModelState.IsValid)
{
Console.WriteLine(model.Name);
return new ApiResponse return new ApiResponse
{ {
Code = 0, Code = 0,
@ -101,5 +114,7 @@ namespace WebApi.Controllers
} }
}; };
} }
return new ApiResponse { Code = 1, Message = "数据验证失败" };
}
} }
} }
Loading…
Cancel
Save