From 7887acbd57cd41cf5fec205013dc47a622d46727 Mon Sep 17 00:00:00 2001 From: wanggang <76527413@qq.com> Date: Fri, 28 Feb 2020 11:47:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=8A=E4=BC=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=9C=AC=E5=9C=B0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E7=8A=B6=E6=80=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: c0950a65ef733b93861d75fd1d85da3d61961b41 --- .../CameraCard/MainForm.Designer.cs | 17 ++-- labs/CameraCard/CameraCard/MainForm.cs | 94 ++++++++++++++++++- .../WebApi/Controllers/TestController.cs | 2 + labs/CameraCard/WebApi/Models/PushRequest.cs | 5 +- 4 files changed, 104 insertions(+), 14 deletions(-) diff --git a/labs/CameraCard/CameraCard/MainForm.Designer.cs b/labs/CameraCard/CameraCard/MainForm.Designer.cs index baf2cfc2..257c5b0a 100644 --- a/labs/CameraCard/CameraCard/MainForm.Designer.cs +++ b/labs/CameraCard/CameraCard/MainForm.Designer.cs @@ -113,7 +113,6 @@ this.stuClassValue = new System.Windows.Forms.Label(); this.stuYearValue = new System.Windows.Forms.Label(); this.stuSchoolValue = new System.Windows.Forms.Label(); - this.idCard = new CameraCard.IdCard(); this.StudentName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Sex = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.Nation = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -126,6 +125,7 @@ this.HasChedked = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.HasUploaded = new System.Windows.Forms.DataGridViewCheckBoxColumn(); this.StudentId = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.idCard = new CameraCard.IdCard(); tab1 = new System.Windows.Forms.TabPage(); tab1.SuspendLayout(); this.idcGroupBox.SuspendLayout(); @@ -595,6 +595,7 @@ this.push.TabIndex = 14; this.push.Text = "上传"; this.push.UseVisualStyleBackColor = true; + this.push.Click += new System.EventHandler(this.push_Click); // // totalPageValue // @@ -1050,13 +1051,6 @@ this.stuSchoolValue.TabIndex = 31; this.stuSchoolValue.Text = "空"; // - // idCard - // - this.idCard.Location = new System.Drawing.Point(-1, 16); - this.idCard.Name = "idCard"; - this.idCard.Size = new System.Drawing.Size(420, 200); - this.idCard.TabIndex = 8; - // // StudentName // this.StudentName.DataPropertyName = "Name"; @@ -1145,6 +1139,13 @@ this.StudentId.ReadOnly = true; this.StudentId.Visible = false; // + // idCard + // + this.idCard.Location = new System.Drawing.Point(-1, 16); + this.idCard.Name = "idCard"; + this.idCard.Size = new System.Drawing.Size(420, 200); + this.idCard.TabIndex = 8; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); diff --git a/labs/CameraCard/CameraCard/MainForm.cs b/labs/CameraCard/CameraCard/MainForm.cs index 6baabec5..b5f52091 100644 --- a/labs/CameraCard/CameraCard/MainForm.cs +++ b/labs/CameraCard/CameraCard/MainForm.cs @@ -450,7 +450,10 @@ namespace CameraCard private void tabControl1_Selected(object sender, TabControlEventArgs e) { - if (e.TabPage.Text == "采集进度") + if (e.TabPage.Text == "图像采集") + { + } + else if (e.TabPage.Text == "采集进度") { this.RunWithLoading(RefreshGroup); } @@ -636,7 +639,6 @@ namespace CameraCard { MainForm.LoadData(progress); progress.CloseForm(); - System.Threading.Thread.Sleep(2000); this.RunWithLoading(RefreshData); } catch (Exception ex) @@ -680,5 +682,93 @@ namespace CameraCard { this.RunWithLoading(RefreshData); } + + private void push_Click(object sender, EventArgs e) + { + var progress = new ProgressForm("更新中", "正在上传", 0, 100); + this.Run(() => progress.ShowDialog()); + Task.Run(() => + { + try + { + this.UploadData(progress); + progress.CloseForm(); + this.RunWithLoading(RefreshData); + } + catch (Exception ex) + { + progress.CloseForm(); + MessageBox.Show(ex.Message); + } + }); + } + + private void UploadData(ProgressForm progress) + { + try + { + using (var db = new MyDbContext()) + { + var query = db.Set().AsQueryable().Where(o => o.HasImage); + if (classSelector.Text != "全部") + { + var classValue = imageStatusSelector.SelectedValue as string; + query = query.Where(o => o.Class == classValue); + } + if (imageStatusSelector.Text != "全部") + { + var imageStatus = (bool)imageStatusSelector.SelectedValue; + query = query.Where(o => o.HasImage == imageStatus); + } + if (uploadStatusSelector.Text != "全部") + { + var uploadStatus = (bool)uploadStatusSelector.SelectedValue; + query = query.Where(o => o.HasUploaded == uploadStatus); + } + if (checkStatusSelector.Text != "全部") + { + var checkedStatus = (bool)checkStatusSelector.SelectedValue; + query = query.Where(o => o.HasChecked == checkedStatus); + } + if (cardStatusSelector.Text != "全部") + { + var cardStatus = (bool)cardStatusSelector.SelectedValue; + query = query.Where(o => o.HasIdCard == cardStatus); + } + var total = query.Count(); + var url = ConfigurationManager.AppSettings["push"]; + int i = 1; + foreach (var item in query) + { + try + { + var client = HttpClientFactory.Create(); + var content = new StringContent(new JavaScriptSerializer().Serialize(item), Encoding.UTF8, "application/json"); + var response = client.PostAsync(url, content).Result; + var result = new JavaScriptSerializer().Deserialize(response.Content.ReadAsStringAsync().Result); + if (result.code == 0) + { + progress?.SetProgress($"进度{i}/{total}", i * 100 / total); + item.HasUploaded = true; + db.SaveChanges(); + } + else + { + MessageBox.Show($"错误代码:{result.code},错误消息:{result.message}"); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + i++; + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } } } \ No newline at end of file diff --git a/labs/CameraCard/WebApi/Controllers/TestController.cs b/labs/CameraCard/WebApi/Controllers/TestController.cs index 9b566121..fe83f1ec 100644 --- a/labs/CameraCard/WebApi/Controllers/TestController.cs +++ b/labs/CameraCard/WebApi/Controllers/TestController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; +using System; using System.Collections.Generic; using WebApi.Models; @@ -77,6 +78,7 @@ namespace WebApi.Controllers { if (ModelState.IsValid) { + Console.WriteLine(model.Name); return new ApiResponse { Code = 0 diff --git a/labs/CameraCard/WebApi/Models/PushRequest.cs b/labs/CameraCard/WebApi/Models/PushRequest.cs index 2a8be053..7dcb4043 100644 --- a/labs/CameraCard/WebApi/Models/PushRequest.cs +++ b/labs/CameraCard/WebApi/Models/PushRequest.cs @@ -1,10 +1,7 @@ namespace WebApi.Models { - public class PushRequest + public class PushRequest : Student { - public string Id { get; set; } - public string Name { get; set; } - public string IdCardNo { get; set; } public string Image { get; set; } } } \ No newline at end of file