Beispiel #1
0
        /// <summary>
        /// 执行网站同步
        /// </summary>
        private void DataUpload()
        {
            int strart = 0, end = 200, total = 0, amount = 0;

            total = GetPostHttpCount();

            progressBar1.Maximum = total;
            labCountnum.Text     = total.ToString();

            BackgroundWorker dgWorker = new BackgroundWorker();

            dgWorker.DoWork += (senderdg, edg) =>
            {
                while (total > 0)
                {
                    List <DataModel> model  = GetPostHttp(strart, end);
                    DataTable        dtInfo = new DataTable();

                    if (model != null && model.Count > 0)
                    {
                        dtInfo = ModelConvertHelper <DataModel> .ToDataTable(model);
                    }

                    amount += DataUpload(dtInfo);

                    strart = end;
                    end   += 200;
                    total -= 200;

                    dgWorker.ReportProgress(amount);
                }
            };

            dgWorker.ProgressChanged += (senderdg, edg) =>
            {
                progressBar1.Value = edg.ProgressPercentage;
            };

            dgWorker.RunWorkerCompleted += (senderdg, edg) =>
            {
                MessageBox.Show(String.Format("成功匹配:{0}条数据!", amount), "提示");

                progressBar1.Visible   = false;
                btnDataUpload.Enabled  = true;
                this.labUploadnum.Text = amount.ToString();

                if (this.cud.dtData.Rows.Count > 0)
                {
                    UploadData ud = new UploadData {
                        dtData = cud.dtData
                    };
                    ud.ShowDialog();
                }
            };

            dgWorker.WorkerReportsProgress = true;
            dgWorker.RunWorkerAsync();
        }
Beispiel #2
0
        public bool UpdateData(string date)
        {
            JsonClass jclass = JsonH.DeserializeJsonToObject <JsonClass>(date);
            DataModel model  = jclass.Data;

            if (jclass.Message.ToUpper() == "CONNECTFAIL") //数据查询失败
            {
                MessageBox.Show("读取数据失败...");
                return(false);
            }
            else if (jclass.Message.ToUpper() == "CONNECTOK") //数据查询成功
            {
                this.ControlTextRefresh(this.labCountnum, jclass.Status);
                this.ProcessBarRefresh(this.progressBar1, int.Parse(jclass.Status) + 5, true);
                return(true);
            }
            else if (jclass.Message.ToUpper() == "OVER") //数据传送完毕
            {
                socketSend.Close();

                this.ProcessBarRefresh(this.progressBar1, int.Parse(jclass.Status), false);
                DialogResult dr = MessageBox.Show("成功匹配:" + UploadCount + "条数据!", "提示");

                if (dr == DialogResult.OK)
                {
                    if (this.cud.dtData.Rows.Count > 0)
                    {
                        UploadData ud = new UploadData {
                            dtData = cud.dtData
                        };
                        ud.ShowDialog();
                    }
                    return(false);
                }
            }

            if (model == null)
            {
                return(true);
            }

            if (recordsAssistCheckBLL.UpdateXQ(model) <= 0)
            {
                recordsXQBll.AddRow(model);
            }

            int successNum = recordsAssistCheckBLL.UpdateAssistCheck(model);

            if (successNum > 0)
            {
                UploadCount++;
                this.ControlTextRefresh(this.labUploadnum, UploadCount.ToString());
                this.ProcessBarValueRefresh(this.progressBar1, UploadCount);
                Application.DoEvents();
            }
            else
            {
                this.cud.ConbinData(model.IDCardNo);
            }

            return(true);
        }