Exemplo n.º 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            CardPaymentRecordBll     cbll  = new CardPaymentRecordBll(AppSettings.CurrentSetting.CurrentMasterConnect);
            LDB_CardPaymentRecordBll lcbll = new LDB_CardPaymentRecordBll(LDB_AppSettings.Current.LDBConnect);

            InitProgress();
            NotifyProgress(0);
            foreach (DataGridViewRow row in GridView.Rows)
            {
                LDB_CardPaymentInfo info    = row.Tag as LDB_CardPaymentInfo;
                CardPaymentInfo     payment = LDB_InfoFactory.CreateCardPaymentInfo(info);
                CommandResult       result  = cbll.InsertRecordWithCheck(payment);
                if (result.Result == ResultCode.Successful)
                {
                    info.UpdateFlag = true;
                    lcbll.Update(info);
                    ShowCardPaymentOnRow(info, row.Index);
                    row.DefaultCellStyle.ForeColor = Color.Green;
                }
                else
                {
                    row.DefaultCellStyle.ForeColor = Color.Red;
                }
                GridView.Refresh();
                NotifyProgress(null);
            }
            NotifyProgress(this.progressBar1.Maximum);
            this.progressBar1.Visible = false;
        }
        private void UpdateLocalData_Thread()
        {
            try
            {
                while (true)
                {
                    _UpdateLoaclDataEvent.WaitOne(UpdateInterval * 60 * 1000);

                    if (AppSettings.CurrentSetting.EnableWriteCard)
                    {
                        LDB_CardPaymentRecordBll bll = new LDB_CardPaymentRecordBll(LDB_AppSettings.Current.LDBConnect);
                        try
                        {
                            //如果是主数据库时,需要主数据库连接上
                            if (!DataBaseConnectionsManager.Current.IsMasterConnectionString(_DataBaseUri) ||
                                DataBaseConnectionsManager.Current.MasterConnected)
                            {
                                LDB_CardPaymentRecordSearchCondition con = new LDB_CardPaymentRecordSearchCondition();
                                con.UpdateFlag = false;
                                List <LDB_CardPaymentInfo> records = bll.GetItems(con).QueryObjects;
                                if (records != null && records.Count > 0)
                                {
                                    CommandResult result = null;
                                    foreach (LDB_CardPaymentInfo record in records)
                                    {
                                        CardPaymentInfo info = LDB_InfoFactory.CreateCardPaymentInfo(record);
                                        info.UpdateFlag = true;

                                        CardPaymentRecordSearchCondition searchCondition = new CardPaymentRecordSearchCondition();
                                        searchCondition.CardID         = info.CardID;
                                        searchCondition.ChargeDateTime = info.ChargeDateTime;

                                        List <CardPaymentInfo> check = _CardPaymentProvider.GetItems(searchCondition).QueryObjects;
                                        if (check == null || check.Count == 0)
                                        {
                                            result = _CardPaymentProvider.Insert(info);
                                        }
                                        else
                                        {
                                            //已存在该记录,可认为插入成功
                                            result = new CommandResult(ResultCode.Successful, string.Empty);
                                        }

                                        if (result.Result == ResultCode.Successful)
                                        {
                                            record.UpdateFlag = true;
                                            bll.Update(record);
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                        }
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                Ralid.GeneralLibrary.LOG.FileLog.Log("系统", "上传本地数据库数据服务停止");
            }
        }