添加上传数据并更新本地上传状态功能

Former-commit-id: c0950a65ef733b93861d75fd1d85da3d61961b41
TangShanKaiPing
wanggang 5 years ago
parent 5f5e3b0b1e
commit 7887acbd57

@ -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);

@ -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<Student>().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<PullResponse>(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);
}
}
}
}

@ -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

@ -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; }
}
}
Loading…
Cancel
Save