コード例 #1
0
        private void _FetchServiceWorkOrderContinuously()
        {
            _FetchServiceWorkOrderThread = ThreadAdapter.DoCircleTask(
                () =>
            {
                #region 执行任务=》获取需要同步到其他系统的工单

                dOnAppendToOutput dc = new dOnAppendToOutput(_OnAppendToOutput);
                this.Invoke(dc, new object[] { "获取需要同步到其他系统的工单..." });

                //同步请求
                string url = _SourceAddress + "/p12/c07/A01/GetSyncOutWorkOrders";

                HttpAdapter.getSyncTo(url, (result, response) =>
                {
                    if ((bool)result.Success)
                    {
                        this.Invoke(dc, new object[] { string.Format("###获取工单成功:{0}条 ", result.rows.Count) });
                        foreach (var row in result.rows)
                        {
                            queues.Enqueue(row);
                        }
                    }
                    else
                    {
                        this.Invoke(dc, new object[] { string.Format("#####获取工单出错:{0} ", result.ErrorMessage) });
                    }
                });

                #endregion
            },
                1000,//1秒执行一次
                () =>
            {
                return(!isEnableFetchServiceWorkOrder);
            },    //没有允许取数据则停止
                () =>
            {
                return(queues.Count > 0 || isPauseFetchServiceWorkOrder);
            }    //当数据队列不为空则跳过
                );
        }
コード例 #2
0
        private void _SaveOrderToRemoteContinuously()
        {
            _SaveOrderToRemoteThread = ThreadAdapter.DoCircleTask(
                () =>
            {
                #region 执行任务=》将工单提交到远程服务器

                if (queues.Count == 0)
                {
                    return;
                }

                dOnAppendToOutput dc = new dOnAppendToOutput(_OnAppendToOutput);
                this.Invoke(dc, new object[] { "将工单提交到远程服务器..." });

                isSaving = true;
                var item = queues.Dequeue();
                try
                {
                    HttpAdapter.postSyncAsForm(_TargetAddressToSaveOrder, new
                    {
                        unique         = item.WorkOrderNo,
                        service        = item.Service,
                        linkman        = item.LinkMan,
                        linkphone      = (item.LinkPhone == "" ? "没有linkphone" : item.LinkPhone),
                        note           = item.Note,
                        accept_time    = item.AcceptTime,
                        pie_time       = item.PieTime,
                        finish_time    = item.FinishTime,
                        service_time   = item.ServieTime,
                        back_note      = item.BackNote,
                        status         = item.Status,
                        satisficing    = item.Satisficing,
                        old_man_unique = item.OldManUnique,
                        longitude      = item.LongitudeS,
                        latitude       = item.LatitudeS
                    }.ToStringObjectDictionary(), (result, response) =>
                    {
                        if ((bool)result.flag)
                        {
                            this.Invoke(dc, new object[] { string.Format("#####提交工单成功:<{0}> ", item.WorkOrderNo) });

                            string url = _SourceAddress + "/p12/c07/A01/MarkSyncOutWorkOrder";

                            HttpAdapter.postSyncAsJSON(url, new { Id = item.Id }.ToStringObjectDictionary(), (result1, response1) =>
                            {
                                if ((bool)result1.Success)
                                {
                                    //将提交成功的工单设置同步标识
                                    this.Invoke(dc, new object[] { string.Format("###设置工单同步标识成功:<{0}> ", item.WorkOrderNo) });
                                }
                                else
                                {
                                    this.Invoke(dc, new object[] { string.Format("#####设置工单同步标识出错:{0} ", result1.ErrorMessage) });
                                }
                            });
                        }
                        else
                        {
                            this.Invoke(dc, new object[] { string.Format("#####提交工单出错:{0} ", result.msg) });
                        }
                    });
                }
                catch (Exception ex) {
                    this.Invoke(dc, new object[] { ex.Message });
                }
                finally
                {
                    isSaving = false;
                }
                #endregion
            },
                5000,//5秒执行一次
                () =>
            {
                return(false);
            },    //一直运行
                () =>
            {
                return(queues.Count == 0 || isSaving);
            }    //当数据队列为空时跳过
                );
        }