Exemple #1
0
        private void ClearInvalidWaitingCommand()
        {
            if (ParkBuffer.Current != null)
            {
                WaitingCommandBLL         wb        = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
                List <WaitingCommandInfo> wcs       = wb.GetAllCommands().QueryObjects;
                List <EntranceInfo>       entrances = ParkBuffer.Current.GetEntrances();

                int  entranceID      = 0;     //当前控制器id
                bool invalidEntrance = false; //当前控制器是否无效控制器
                foreach (var wc in wcs)
                {
                    if (wc.EntranceID != entranceID)
                    {
                        EntranceInfo entrance = entrances.FirstOrDefault(e => e.EntranceID == wc.EntranceID);
                        entranceID      = wc.EntranceID;
                        invalidEntrance = entrance == null;
                    }
                    if (invalidEntrance)
                    {
                        wb.Delete(wc);
                    }
                }
            }
        }
        private bool Sync_TarrifSetting()
        {
            bool success = true;
            Dictionary <int, List <EntranceInfo> > parksIDAndEntrances = this.hardwareTree1.GetSelectedParksIDAndEntrances();

            if (parksIDAndEntrances != null)
            {
                foreach (int parkID in parksIDAndEntrances.Keys)
                {
                    foreach (EntranceInfo entrance in parksIDAndEntrances[parkID])
                    {
                        IParkingAdapter pad = ParkingAdapterManager.Instance[entrance.RootParkID];
                        bool            ret = false;
                        if (pad != null)
                        {
                            NotifyMessage(string.Format(Resources.Resource1.FrmDownLoadTariffSetting_Download, entrance.EntranceName));
                            ret = pad.DownloadTariffSettingToEntrance(entrance.EntranceID, TariffSetting.Current);
                            if (!ret)
                            {
                                WaitingCommandBLL  wcBll  = new WaitingCommandBLL(AppSettings.CurrentSetting.CurrentMasterConnect);
                                WaitingCommandInfo wcInfo = new WaitingCommandInfo();
                                wcInfo.EntranceID = entrance.EntranceID;
                                wcInfo.Command    = BusinessModel.Enum.CommandType.DownloadTariffs;
                                wcBll.DeleteAndInsert(wcInfo);
                            }
                        }
                        success = ret ? success : false;
                        NotifyHardwareTreeEntrance(entrance.EntranceID, ret);
                    }
                }
            }
            return(success);
        }
Exemple #3
0
        private void ExecuteWaitingCommand_Thread()
        {
            CardBll           cb = new CardBll(AppSettings.CurrentSetting.ParkConnect);
            WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);

            while (true)
            {
                List <WaitingCommandInfo> wcs = wb.GetCommands(this.ParkID).QueryObjects;
                foreach (var wc in wcs)
                {
                    CardInfo card = cb.GetCardByID(wc.CardID).QueryObject;
                    if (card != null)
                    {
                        if (SaveCard(card, ActionType.Upate))
                        {
                            wb.Delete(wc);
                        }
                    }
                    else
                    {
                        wb.Delete(wc);
                    }
                }
                Thread.Sleep(60000);
            }
        }
Exemple #4
0
        private void Delete()
        {
            FrmProcessing          frmP       = new FrmProcessing();
            string                 msg        = string.Empty;
            List <DataGridViewRow> deleteRows = new List <DataGridViewRow>();
            Action action = delegate()
            {
                try
                {
                    int success           = 0;
                    int fail              = 0;
                    WaitingCommandBLL bll = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
                    foreach (DataGridViewRow item in this.GridView.SelectedRows)
                    {
                        if (item.Tag is WaitingCommandInfo)
                        {
                            WaitingCommandInfo info = item.Tag as WaitingCommandInfo;
                            BusinessModel.Enum.WaitingCommandStatus oldStatus = info.Status;
                            info.Status = BusinessModel.Enum.WaitingCommandStatus.Waiting;
                            if (bll.Delete(info).Result == ResultCode.Successful)
                            {
                                success++;
                                deleteRows.Add(item);
                            }
                            else
                            {
                                fail++;
                            }
                        }
                        msg = string.Format(Resource1.Form_Total + ":{0}/{1} " + Resource1.Form_Success + ":{2} " + Resource1.Form_Fail + ":{3}", success + fail, this.GridView.SelectedRows.Count, success, fail);
                        frmP.ShowProgress(msg, (success + fail) / this.GridView.SelectedRows.Count);
                    }
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception ex)
                {
                    frmP.ShowProgress(ex.Message, 1);
                }
            };
            Thread t = new Thread(new ThreadStart(action));

            t.CurrentCulture   = Thread.CurrentThread.CurrentCulture;
            t.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
            t.Start();
            if (frmP.ShowDialog() != DialogResult.OK)
            {
                t.Abort();
            }
            if (!string.IsNullOrEmpty(msg))
            {
                foreach (DataGridViewRow item in deleteRows)
                {
                    this.GridView.Rows.Remove(item);
                }
                MessageBox.Show(msg);
            }
        }
Exemple #5
0
        private void ItemSearching_Handler(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            WaitingCommandSearchCondition con = new WaitingCommandSearchCondition();

            con.EntranceID  = this.comEntrances.SelectedEntranceID;
            con.CommandType = this.comCommandType.SelectedCommandType;
            con.CardID      = this.txtCardID.Text.Trim();
            con.Status      = this.comWaitingCommandStatus.SelectedStatus;
            WaitingCommandBLL         bll   = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
            List <WaitingCommandInfo> items = bll.GetCommands(con).QueryObjects;

            ShowReportsOnGrid(items);
            this.Cursor = Cursors.Arrow;
        }
Exemple #6
0
        private void ExecuteWaitingCommand_Thread()
        {
            ClearInvalidWaitingCommand();//清除已删除的控制器的等待命令
            WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);

            while (true)
            {
                List <WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects;
                EntranceBase entrance         = null;
                int          entranceID       = -1;
                foreach (var wc in wcs)
                {
                    if (entranceID != wc.EntranceID)
                    {
                        entrance   = GetEntrance(wc.EntranceID);
                        entranceID = wc.EntranceID;
                    }

                    if (entrance != null)
                    {
                        bool ret = false;

                        if (wc.Command == CommandType.DownloadAccesses)
                        {
                            ret = entrance.ApplyAccessSetting(AccessSetting.Current);
                        }
                        else if (wc.Command == CommandType.DownloadHolidays)
                        {
                            ret = entrance.ApplyHolidaySetting(HolidaySetting.Current);
                        }
                        else if (wc.Command == CommandType.DownloadTariffs)
                        {
                            ret = entrance.ApplyTariffSetting(TariffSetting.Current);
                        }
                        else if (wc.Command == CommandType.ClearCard)
                        {
                            ret = entrance.ClearCard();
                        }
                        else if (wc.Command == CommandType.DeleteCard)
                        {
                            CardInfo card = new CardInfo();
                            card.CardID = wc.CardID;
                            ret         = entrance.DeleteCard(card);
                        }
                        else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard)
                        {
                            CardBll  cb   = new CardBll(AppSettings.CurrentSetting.ParkConnect);
                            CardInfo card = cb.GetCardByID(wc.CardID).QueryObject;
                            if (card != null)
                            {
                                ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate);
                            }
                            else
                            {
                                ret = true;
                            }
                        }
                        if (ret)
                        {
                            wb.Delete(wc);
                        }
                    }
                }
                Thread.Sleep(60 * 1000);
            }
        }
Exemple #7
0
        //private void SyncTime_Thread()
        //{
        //    while (true)
        //    {
        //        Thread.Sleep(5 * 60 * 1000);
        //        try
        //        {
        //            foreach (EntranceBase entrance in _Entrances)
        //            {
        //                entrance.SyncTime();
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
        //        }

        //    }
        //}


        private void ExecuteWaitingCommand_Thread()
        {
            try
            {
                ClearInvalidWaitingCommand();//清除已删除的控制器的等待命令
                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
                while (true)
                {
                    try
                    {
                        if (!_WaitingCommandPause && DataBaseConnectionsManager.Current.MasterConnected)
                        {
                            WaitingCommandBLL         wb  = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
                            List <WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects;
                            EntranceBase entrance         = null;
                            int          entranceID       = -1;
                            foreach (var wc in wcs)
                            {
                                if (entranceID != wc.EntranceID)
                                {
                                    entrance   = GetEntrance(wc.EntranceID);
                                    entranceID = wc.EntranceID;
                                }

                                if (entrance != null)
                                {
                                    bool ret = false;

                                    if (wc.Command == CommandType.DownloadAccesses)
                                    {
                                        ret = entrance.ApplyAccessSetting(AccessSetting.Current);
                                    }
                                    else if (wc.Command == CommandType.DownloadHolidays)
                                    {
                                        ret = entrance.ApplyHolidaySetting(HolidaySetting.Current);
                                    }
                                    else if (wc.Command == CommandType.DownloadTariffs)
                                    {
                                        ret = entrance.ApplyTariffSetting(TariffSetting.Current);
                                    }
                                    else if (wc.Command == CommandType.ClearCard)
                                    {
                                        ret = entrance.ClearCard();
                                    }
                                    else if (wc.Command == CommandType.DeleteCard)
                                    {
                                        CardInfo card = new CardInfo();
                                        card.CardID = wc.CardID;
                                        ret         = entrance.SaveCard(card, ActionType.Delete);
                                    }
                                    else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard)
                                    {
                                        CardBll  cb   = new CardBll(AppSettings.CurrentSetting.CurrentMasterConnect);
                                        CardInfo card = cb.GetCardByID(wc.CardID).QueryObject;
                                        if (card != null)
                                        {
                                            ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate, false);
                                        }
                                        else
                                        {
                                            ret = true;
                                        }
                                    }
                                    if (ret)
                                    {
                                        CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer);
                                        if (DataBaseConnectionsManager.Current.MasterConnected)
                                        {
                                            dresult = wb.Delete(wc);
                                        }
                                        if (AppSettings.CurrentSetting.Debug)
                                        {
                                            if (dresult.Result == ResultCode.Successful)
                                            {
                                                string msg = string.Format("控制器{0}[{1}] 命令 {2} {3} 成功,删除命令 {4}", entrance.EntranceName, entrance.EntranceID, wc.Command, wc.CardID, dresult.Result == ResultCode.Successful ? "成功" : dresult.Result.ToString());
                                                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", msg);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                        Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
                    }
                    Thread.Sleep(60 * 1000);
                }
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
            }
        }
Exemple #8
0
        //private void SyncTime_Thread()
        //{
        //    while (true)
        //    {
        //        Thread.Sleep(5 * 60 * 1000);
        //        try
        //        {
        //            foreach (EntranceBase entrance in _Entrances)
        //            {
        //                entrance.SyncTime();
        //            }
        //        }
        //        catch (Exception ex)
        //        {
        //            Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
        //        }

        //    }
        //}


        //private void ExecuteWaitingCommand_Thread()
        //{
        //    try
        //    {
        //        ClearInvalidWaitingCommand();//清除已删除的控制器的等待命令
        //        Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
        //        while (true)
        //        {
        //            try
        //            {
        //                if (!_WaitingCommandPause && DataBaseConnectionsManager.Current.MasterConnected)
        //                {
        //                    WaitingCommandBLL wb = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
        //                    List<WaitingCommandInfo> wcs = wb.GetAllCommands().QueryObjects;
        //                    EntranceBase entrance = null;
        //                    int entranceID = -1;
        //                    foreach (var wc in wcs)
        //                    {
        //                        if (entranceID != wc.EntranceID)
        //                        {
        //                            entrance = GetEntrance(wc.EntranceID);
        //                            entranceID = wc.EntranceID;
        //                        }

        //                        if (entrance != null)
        //                        {
        //                            bool ret = false;

        //                            if (wc.Command == CommandType.DownloadAccesses)
        //                            {
        //                                ret = entrance.ApplyAccessSetting(AccessSetting.Current);
        //                            }
        //                            else if (wc.Command == CommandType.DownloadHolidays)
        //                            {
        //                                ret = entrance.ApplyHolidaySetting(HolidaySetting.Current);
        //                            }
        //                            else if (wc.Command == CommandType.DownloadTariffs)
        //                            {
        //                                ret = entrance.ApplyTariffSetting(TariffSetting.Current);
        //                            }
        //                            else if (wc.Command == CommandType.ClearCard)
        //                            {
        //                                ret = entrance.ClearCard();
        //                            }
        //                            else if (wc.Command == CommandType.DeleteCard)
        //                            {
        //                                CardInfo card = new CardInfo();
        //                                card.CardID = wc.CardID;
        //                                ret = entrance.SaveCard(card, ActionType.Delete);
        //                            }
        //                            else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard)
        //                            {
        //                                CardBll cb = new CardBll(AppSettings.CurrentSetting.CurrentMasterConnect);
        //                                CardInfo card = cb.GetCardByID(wc.CardID).QueryObject;
        //                                if (card != null)
        //                                {
        //                                    ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate, false);
        //                                }
        //                                else
        //                                {
        //                                    ret = true;
        //                                }
        //                            }
        //                            if (ret)
        //                            {
        //                                CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer);
        //                                if (DataBaseConnectionsManager.Current.MasterConnected)
        //                                {
        //                                    dresult = wb.Delete(wc);
        //                                }
        //                                if (AppSettings.CurrentSetting.Debug)
        //                                {
        //                                    if (dresult.Result == ResultCode.Successful)
        //                                    {
        //                                        string msg = string.Format("控制器{0}[{1}] 命令 {2} {3} 成功,删除命令 {4}", entrance.EntranceName, entrance.EntranceID, wc.Command, wc.CardID, dresult.Result == ResultCode.Successful ? "成功" : dresult.Result.ToString());
        //                                        Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", msg);
        //                                    }
        //                                }
        //                            }
        //                        }
        //                    }
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
        //                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
        //            }
        //            Thread.Sleep(60 * 1000);
        //        }

        //    }
        //    catch (Exception ex)
        //    {
        //        Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
        //        Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
        //    }
        //}

        private void ExecuteWaitingCommand_Thread()
        {
            try
            {
                //开始前先等待10分钟,用于等待硬件设备连接状态检测完成
                Thread.Sleep(10 * 60 * 1000);
                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "开始WaitingCommand服务");
                while (true)
                {
                    try
                    {
                        if (!_WaitingCommandPause && DataBaseConnectionsManager.Current.MasterConnected)
                        {
                            WaitingCommandBLL         wb  = new WaitingCommandBLL(AppSettings.CurrentSetting.ParkConnect);
                            List <WaitingCommandInfo> wcs = wb.GetWaitingCommands().QueryObjects;
                            EntranceBase entrance         = null;
                            int          entranceID       = -1;
                            foreach (var wc in wcs)
                            {
                                if (entranceID != wc.EntranceID)
                                {
                                    entrance   = GetEntrance(wc.EntranceID);
                                    entranceID = wc.EntranceID;
                                }

                                if (entrance != null && entrance.Status != EntranceStatus.OffLine)
                                {
                                    bool ret = false;

                                    if (wc.Command == CommandType.DownloadAccesses)
                                    {
                                        ret = entrance.ApplyAccessSetting(AccessSetting.Current);
                                    }
                                    else if (wc.Command == CommandType.DownloadHolidays)
                                    {
                                        ret = entrance.ApplyHolidaySetting(HolidaySetting.Current);
                                    }
                                    else if (wc.Command == CommandType.DownloadTariffs)
                                    {
                                        ret = entrance.ApplyTariffSetting(TariffSetting.Current);
                                    }
                                    else if (wc.Command == CommandType.DownloadKeySetting)
                                    {
                                        ret = entrance.ApplyKeySetting(KeySetting.Current);
                                    }
                                    else if (wc.Command == CommandType.ClearCard)
                                    {
                                        ret = entrance.ClearCard();
                                    }
                                    else if (wc.Command == CommandType.DeleteCard)
                                    {
                                        //由于命令执行前已删除了卡片信息,所以如果是车牌名单时,cardid保存的是车牌名单的车牌号
                                        CardInfo card = new CardInfo();
                                        card.ListType = wc.CardIDType.HasValue && wc.CardIDType.Value == 1 ? CardListType.CarPlate : CardListType.Card;
                                        if (card.IsCardList)
                                        {
                                            card.CardID = wc.CardID;
                                        }
                                        else
                                        {
                                            card.CarPlate = wc.CardID;
                                        }
                                        ret = entrance.SaveCard(card, ActionType.Delete);
                                    }
                                    else if (wc.Command == CommandType.AddCard || wc.Command == CommandType.UpateCard)
                                    {
                                        CardBll  cb   = new CardBll(AppSettings.CurrentSetting.CurrentMasterConnect);
                                        CardInfo card = cb.GetCardByID(wc.CardID).QueryObject;
                                        if (card != null)
                                        {
                                            ret = entrance.SaveCard(card, wc.Command == CommandType.AddCard ? ActionType.Add : ActionType.Upate);
                                        }
                                        else
                                        {
                                            ret = true;
                                        }
                                    }
                                    if (ret)
                                    {
                                        CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer);
                                        if (DataBaseConnectionsManager.Current.MasterConnected)
                                        {
                                            dresult = wb.Delete(wc);
                                        }
                                        if (AppSettings.CurrentSetting.Debug)
                                        {
                                            if (dresult.Result == ResultCode.Successful)
                                            {
                                                string msg = string.Format("控制器{0}[{1}] 命令 {2} {3} 成功,删除命令 {4}", entrance.EntranceName, entrance.EntranceID, wc.Command, wc.CardID, dresult.Result == ResultCode.Successful ? "成功" : dresult.Result.ToString());
                                                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", msg);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        CommandResult dresult = new CommandResult(ResultCode.CannotConnectServer);
                                        if (DataBaseConnectionsManager.Current.MasterConnected)
                                        {
                                            wc.Status = WaitingCommandStatus.Fail;
                                            dresult   = wb.Update(wc);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                    }
                    Thread.Sleep(5 * 60 * 1000);
                }
            }
            catch (Exception ex)
            {
                Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex);
                Ralid.GeneralLibrary.LOG.FileLog.Log("WaitingCommand", "WaitingCommand服务异常终止");
            }
        }