Ejemplo 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;
        }
        /// <summary>
        /// 收取卡片的停车费
        /// </summary>
        /// <param name="info">缴费卡片,为空值时从数据库中获取,主要用于写卡模式时读取到卡片的数据</param>
        /// <param name="payment">缴费记录</param>
        /// <returns></returns>
        public CommandResult PayParkFee(CardInfo info, CardPaymentInfo payment)
        {
            if (info != null)
            {
                LDB_CardPaymentInfo ldbRecord = LDB_InfoFactory.CreateLDBCardPaymentInfo(payment);
                CommandResult       result    = _Provider.Insert(ldbRecord);
                if (result.Result == ResultCode.Successful)
                {
                    if (payment.PaymentMode == PaymentMode.Prepay)
                    {
                        info.Balance -= payment.Paid;
                    }

                    //只有卡片在场或可重复出场,并且与缴费记录的进场时间相同,才会更新卡片信息
                    if ((info.IsInPark || info.CanRepeatOut) &&
                        payment.EnterDateTime.HasValue &&
                        info.LastDateTime == payment.EnterDateTime.Value)
                    {
                        //设置卡片缴费信息
                        info.SetPaidData(payment);
                    }
                }

                return(result);
            }

            return(new CommandResult(ResultCode.NoRecord, ResultCodeDecription.GetDescription(ResultCode.NoRecord)));
        }
        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("系统", "上传本地数据库数据服务停止");
            }
        }