Exemple #1
0
        private void tsmiResetRecord_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = GetSelectRow();

            if (row == null)
            {
                WinInfoHelper.ShowInfoWindow(this, "未有选择控制器!");
                return;
            }
            Maticsoft.Model.SMT_CONTROLLER_INFO ctrlInfo = (Maticsoft.Model.SMT_CONTROLLER_INFO)row.Tag;
            if (MessageBox.Show("确定恢复该控制器" + ctrlInfo.NAME + "记录读取?", "确定", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            CtrlWaiting waiting = new CtrlWaiting(() =>
            {
                try
                {
                    IAccessCore acc = new WGAccess();
                    var c           = ControllerHelper.ToController(ctrlInfo);
                    bool ret        = acc.SetControllerReadedIndex(c, 0);
                    WinInfoHelper.ShowInfoWindow(this, "恢复控制器" + ctrlInfo.NAME + "记录" + (ret ? "成功!" : "失败!"));
                }
                catch (Exception ex)
                {
                    log.Error("恢复控制器记录异常:", ex);
                    WinInfoHelper.ShowInfoWindow(this, "恢复控制器" + ctrlInfo.NAME + "记录异常:" + ex.Message);
                }
            });

            waiting.Show(this);
        }
        public void StartReadRecord()
        {
            log.Info("开始读取记录:" + _controller.sn);
            using (IAccessCore acc = new WGAccess())
            {
                try
                {
                    if (acc.BeginReadRecord(Controller))
                    {
                        try
                        {
                            while (true)
                            {
                                ControllerState record = acc.ReadNextRecord();
                                if (record == null || record.recordType == RecordType.NoRecord)
                                {
                                    log.Info("记录读取完毕:" + _controller.sn);
                                    break;
                                }
                                try
                                {
                                    RecordTaskService.Instance.SaveRecord(_controller.id, record);
                                }
                                catch (Exception ex)
                                {
                                    if (record.lastRecordIndex <= 0)
                                    {
                                        record.lastRecordIndex = 0xffffffff;
                                    }
                                    else
                                    {
                                        record.lastRecordIndex--;
                                    }
                                    acc.SetControllerReadedIndex(Controller, record.lastRecordIndex);
                                    return;
                                }
                            }
                        }
                        finally
                        {
                            acc.EndReadRecord();
                        }
                    }

                    ControllerState state = acc.GetControllerState(Controller);
                    if (state != null)
                    {
                        RecordTaskService.Instance.SaveState(_controller.id, state);
                    }
                }
                catch (Exception ex)
                {
                    RecordTaskService.Instance.SaveState(_controller.id, null);
                    throw ex;
                }
            }
        }
Exemple #3
0
        private void btnResetRecord_Click(object sender, EventArgs e)
        {
            IAccessCore access = new WGAccess();
            Controller  ctrl   = GetSelectedController();

            if (ctrl == null)
            {
                return;
            }
            access.SetControllerReadedIndex(ctrl, 0);
        }