public bool SaveCardsToEntrance(int entranceID, List <CardInfo> cards, ActionType action) { try { if (_Channel != null) { return(_Channel.SaveCardsToEntrance(entranceID, cards, action)); } } catch (CommunicationException ex) { if (ParkAdapterConnectFail != null) { ParkAdapterConnectFail(this, EventArgs.Empty); } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(false); }
/// <summary> /// 网络型下载卡片 /// </summary> private bool SyncCards(List <CardInfo> cards) { bool result = true; foreach (EntranceInfo entrance in _Entrances) { IParkingAdapter pad = ParkingAdapterManager.Instance[entrance.RootParkID]; if (pad != null) { pad.WaitingCommandServiceEnable(false); try { bool success = true; if (_DownLoadAll) { //全部下载时,下载前需要清空卡片名单 CancelNeedWaiting = true; NotifyMessage(string.Format("{0} {1} {2}", Resources.Resource1.FrmDownLoadAllCards_Entrance, entrance.EntranceName, Resources.Resource1.FrmDownloadAllCards_Clear)); success = pad.ClearCardsToEntrance(entrance.EntranceID);//删除所有卡片 CancelWaitingEvent.Set(); CancelNeedWaiting = false; } if (success) { int currentcount = 0; int savecount = 16; int failcount = 0; do { List <CardInfo> infos = new List <CardInfo>(); for (int i = 0; i < savecount && currentcount < cards.Count; i++) { infos.Add(cards[currentcount]); currentcount++; } if (!pad.SaveCardsToEntrance(entrance.EntranceID, infos, _DownLoadCard ? ActionType.Add : ActionType.Delete)) { success = false; failcount += infos.Count; } string msg = _DownLoadCard ? Resources.Resource1.FrmDownloadAllCards_CardProcessing : Resources.Resource1.FrmDownLoadAllCards_Delete; msg = string.Format(msg, string.Format(" {0}/{1} {2}:{3}", currentcount, cards.Count, Resources.Resource1.FrmDownLoadAllCards_Fail, failcount)); NotifyMessage(string.Format("{0} {1} {2}", Resources.Resource1.FrmDownLoadAllCards_Entrance, entrance.EntranceName, msg)); NotifyProgress(currentcount); TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - _Begin.Ticks); NotifyTime((int)ts.TotalSeconds); }while (currentcount < cards.Count); } result = success ? result : false; NotifyHardwareTreeEntrance(entrance.EntranceID, success); } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } pad.WaitingCommandServiceEnable(true); } } return(result); }
/// <summary> /// 网络型下载卡片 /// </summary> private bool SyncCards(List <CardInfo> cards) { bool result = true; int entranceCount = 0; foreach (EntranceInfo entrance in _Entrances) { IParkingAdapter pad = ParkingAdapterManager.Instance[entrance.RootParkID]; if (pad != null) { pad.WaitingCommandServiceEnable(false); try { bool success = true; if (_DownLoadAll) { //全部下载时,下载前需要清空卡片名单 CancelNeedWaiting = true; NotifyMessage(string.Format("{0} {1} {2}", Resources.Resource1.FrmDownLoadAllCards_Entrance, entrance.EntranceName, Resources.Resource1.FrmDownloadAllCards_Clear)); success = pad.ClearCardsToEntrance(entrance.EntranceID);//删除所有卡片 CancelWaitingEvent.Set(); CancelNeedWaiting = false; } if (success) { int currentcount = 0; int savecount = 16; int failcount = 0; List <CardInfo> FailCards = new List <CardInfo>(); do { List <CardInfo> infos = new List <CardInfo>(); for (int i = 0; i < savecount && currentcount < cards.Count; i++) { infos.Add(cards[currentcount]); currentcount++; } if (!pad.SaveCardsToEntrance(entrance.EntranceID, infos, _DownLoadCard ? ActionType.Add : ActionType.Delete)) { success = false; failcount += infos.Count; FailCards.AddRange(infos); } string msg = _DownLoadCard ? Resources.Resource1.FrmDownloadAllCards_CardProcessing : Resources.Resource1.FrmDownLoadAllCards_Delete; msg = string.Format(msg, string.Format(" {0}/{1} {2}:{3}", currentcount, cards.Count, Resources.Resource1.FrmDownLoadAllCards_Fail, failcount)); NotifyMessage(string.Format("{0} {1} {2}", Resources.Resource1.FrmDownLoadAllCards_Entrance, entrance.EntranceName, msg)); NotifyProgress(entranceCount * cards.Count + currentcount); TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - _Begin.Ticks); NotifyTime(ts); //Thread.Sleep(50); }while (currentcount < cards.Count); //if (FailCards.Count > 0) //{ // WaitingCommandBLL wcBll = new WaitingCommandBLL(AppSettings.CurrentSetting.CurrentMasterConnect); // foreach (CardInfo fcard in FailCards) // { // WaitingCommandInfo wcInfo = new WaitingCommandInfo(); // wcInfo.EntranceID = entrance.EntranceID; // wcInfo.Command = _DownLoadCard ? BusinessModel.Enum.CommandType.AddCard : BusinessModel.Enum.CommandType.DeleteCard; // wcInfo.CardID = fcard.CardID; // wcBll.DeleteAndInsert(wcInfo); // } //} } result = success ? result : false; NotifyHardwareTreeEntrance(entrance.EntranceID, success); } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } pad.WaitingCommandServiceEnable(true); } entranceCount++; } return(result); }