private void btn_Enter_Click(object sender, EventArgs e) { DateTime newtime = t_NewTime.Value; int partition = GetSelectedPartition(); if (_mCardInfo != null) { _mCardInfo.CardTime = newtime; _mCardInfo.CardPartition = partition; TypeParameter typeparameter = new TypeParameter() { Lock = _mCardInfo.CardLock, Distance = _mCardInfo.CardDistance }; FunctionByteParameter functionbyteparameter = new FunctionByteParameter() { Loss = _mCardInfo.CardReportLoss, Synchronous = _mCardInfo.Synchronous, RegistrationType = (CardType)_mCardInfo.CardType, ViceCardCount = _mCardInfo.ViceCardCount, ParkingRestrictions = _mCardInfo.ParkingRestrictions, InOutState = _mCardInfo.InOutState }; DistanceParameterContent distancecontent = new DistanceParameterContent() { CardNumber = _mCardInfo.CardNumber, Type = typeparameter, Function = functionbyteparameter, Count = ++_mCardInfo.CardCount }; SingleCardData singlecarddata = new SingleCardData() { Time = _mCardInfo.CardTime, Partition = _mCardInfo.CardPartition }; byte[] by = DataCombination.CombinationDistanceCard(distancecontent, singlecarddata); if (_mPort.IsOpen) { _mPort.Write(by); } } else { DelayParamValue param = new DelayParamValue() { DelayTime = newtime, Partition = partition }; this.Tag = param; Close(); } }
private void RegisterCards(string cardnumber, int auxiliarycommand) { int index = -1; foreach (KeyValuePair <int, CardInfo> item in DicRegisterList) { index++; if (!string.IsNullOrEmpty(cardnumber) && cardnumber == item.Value.CardNumber) { if (auxiliarycommand == 0) { item.Value.Cid = DbHelper.Db.Insert <CardInfo>(item.Value); OnRegisterComplete(item.Key, item.Value); dgv_RegisterList.Rows[_rowIndex].Cells["c_State"].Value = Properties.Resources.check; } cardnumber = string.Empty; continue; } if (!string.IsNullOrEmpty(cardnumber)) { continue; } if (item.Value.Cid > 0) { continue; } _rowIndex = index; TypeParameter typeparam = new TypeParameter() { Lock = item.Value.CardLock, Distance = item.Value.CardDistance }; FunctionByteParameter functionparam = new FunctionByteParameter() { Loss = item.Value.CardReportLoss, InOutState = item.Value.InOutState, ParkingRestrictions = item.Value.ParkingRestrictions, RegistrationType = (CardType)item.Value.CardType, Synchronous = item.Value.Synchronous, ViceCardCount = 0 }; DistanceParameterContent parameter = new DistanceParameterContent() { CardNumber = item.Value.CardNumber, Count = item.Value.CardCount, Function = functionparam, Type = typeparam }; SingleCardData singlecard = new SingleCardData() { Partition = item.Value.CardPartition, Time = item.Value.CardTime }; byte[] by = DataCombination.CombinationDistanceCard(parameter, singlecard); if (Port.IsOpen) { Port.Write(by); return; } } btn_Enter.Enabled = true; btn_Param.Enabled = true; if (GetIsCompleteRegister()) { Close(); } }
private void btn_Enter_Click(object sender, EventArgs e) { if (_mBundledViceCard.Count > 0) { TypeParameter typeparameter = new TypeParameter() { Lock = _mCardInfo.CardLock, Distance = _mCardInfo.CardDistance }; FunctionByteParameter functionbyteparameter = new FunctionByteParameter() { Loss = _mCardInfo.CardReportLoss, Synchronous = _mCardInfo.Synchronous, RegistrationType = (CardType)_mCardInfo.CardType, ViceCardCount = _mCardInfo.ViceCardCount, ParkingRestrictions = _mCardInfo.ParkingRestrictions, InOutState = _mCardInfo.InOutState }; DistanceParameterContent distancecontent = new DistanceParameterContent() { CardNumber = _mCardInfo.CardNumber, Type = typeparameter, Function = functionbyteparameter, Count = ++_mCardInfo.CardCount }; byte[] by = null; switch (_mCardInfo.CardType) { case 1: List <ViceCardData> vicecarddatas = new List <ViceCardData>(); foreach (CardInfo item in _mBundledViceCard) { ViceCardData vicecarddata = new ViceCardData() { ViceNumber = item.CardNumber, Time = item.CardTime, Partition = item.ParkingRestrictions, Count = ++item.CardCount }; vicecarddatas.Add(vicecarddata); } by = DataCombination.CombinationDistanceCard(distancecontent, vicecarddatas); break; case 2: List <PlateCardData> platecarddatas = new List <PlateCardData>(); foreach (CardInfo item in _mBundledViceCard) { PlateCardData platecarddata = new PlateCardData() { Plate = item.CardNumber, Time = item.CardTime, Partition = item.CardPartition }; platecarddatas.Add(platecarddata); } by = DataCombination.CombinationDistanceCard(distancecontent, platecarddatas); break; } if (_mPort.IsOpen) { _mPort.Write(by); } } else { Close(); } }
/// <summary> /// 端口数据接收方法 /// </summary> /// <param name="parameter"></param> public void PortDataReceived(DistanceParameter parameter) { if (_mViceCard == null) { if (parameter.AuxiliaryCommand != 0) //主卡发行失败提示下面内容 { this.Invoke(new EventHandler(delegate { btn_Enter.Enabled = true; MessageBox.Show(@"定距卡发行失败,请将定距卡放置在多功能操作平台上。", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); })); return; } else //主卡发行成功 { if (parameter.CardNumber == _mCardInfo.CardNumber) { //更新数据库数据 UpdateDistanceData(); this.Tag = _mCardInfo; } } } if (_mCardInfo.CardType == 1)//组合卡 { int index = -1; //解锁副卡 foreach (CardInfo item in _mBundledCardinfo) { index++; if (_mViceCard != null && item == _mViceCard) { if (item.CardNumber.Equals(parameter.CardNumber)) { if (parameter.AuxiliaryCommand == 0) { item.CardLock = 0; Dal.DbHelper.Db.Update <CardInfo>(item); dgv_BundledList["c_LockState", index].Value = Properties.Resources.check; //dgv_BundledList.Rows[_lockindex].DefaultCellStyle.ForeColor = Color.Green; } else { dgv_BundledList["c_LockState", index].Value = Properties.Resources.block; //dgv_BundledList.Rows[_lockindex].DefaultCellStyle.ForeColor = Color.Red; } } _mViceCard = null; continue; } if (_mViceCard != null) { continue; } if (item.CardLock != 1) { continue; } _mViceCard = item; CreateMessageLabel(); TypeParameter typeparameter = new TypeParameter() { Lock = 0, Distance = 0 }; DistanceParameterContent distanceparameter = new DistanceParameterContent() { CardNumber = item.CardNumber, Type = typeparameter, Function = null, Count = 0 }; SingleCardData?singlecarddata = null; byte[] by = DataCombination.CombinationDistanceCard(distanceparameter, singlecarddata); if (_mPort.IsOpen) { _mPort.Write(by); } return; } foreach (CardInfo item in _mViceCardInfo) { if (item.CardLock == 1) { if (_lMessage != null) { this.Controls.Remove(_lMessage); _lMessage.Dispose(); _lMessage = null; } btn_Enter.Enabled = true; MessageBox.Show("解锁副卡失败,将新添加的副卡放置在发行器可读写区域内", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } } btn_Enter.Enabled = true; Close(); }
/// <summary> /// 确认 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Enter_Click(object sender, EventArgs e) { try { btn_Enter.Enabled = false; _mViceCard = null; //判断定距卡是否挂失 if (_mCardInfo.CardReportLoss == 1) { //定距卡解挂必须修改定距卡的同步位数据 _mCardInfo.Synchronous = _mCardInfo.Synchronous == 0 ? 1 : 0; _mCardInfo.CardReportLoss = 0; } //解锁 _mCardInfo.CardLock = 0; //定距卡时间 _mCardInfo.CardTime = cb_CardType.SelectedIndex == 0 ? t_CardTime.Value : GetViceMaxTime(); //定距卡类型 _mCardInfo.CardType = cb_CardType.SelectedIndex; //定距卡距离 _mCardInfo.CardDistance = cb_CardDistance.SelectedIndex; //定距卡车位限制 _mCardInfo.ParkingRestrictions = cb_ParkingRestrictions.SelectedIndex; //定距卡车场分区 _mCardInfo.CardPartition = cb_CardPartition.SelectedIndex == 0 ? 0 : GetSelectedPartition(); //定距卡计数 _mCardInfo.CardCount = DataCombination.SetCount(_mCardInfo.CardCount); //定距卡副卡数量 _mCardInfo.ViceCardCount = _mBoundAdd.Count + _mBundledCardinfo.Count; TypeParameter typeparameter = new TypeParameter() { Lock = _mCardInfo.CardLock, Distance = _mCardInfo.CardDistance }; FunctionByteParameter functionbyteparameter = new FunctionByteParameter() { Loss = _mCardInfo.CardReportLoss, Synchronous = _mCardInfo.Synchronous, RegistrationType = (CardType)_mCardInfo.CardType, ViceCardCount = _mCardInfo.ViceCardCount, ParkingRestrictions = _mCardInfo.ParkingRestrictions, InOutState = _mCardInfo.InOutState }; DistanceParameterContent distancecontent = new DistanceParameterContent() { CardNumber = _mCardInfo.CardNumber, Type = typeparameter, Function = functionbyteparameter, Count = ++_mCardInfo.CardCount }; byte[] by; switch (_mCardInfo.CardType) { case 0: SingleCardData singlecarddata = new SingleCardData() { Time = _mCardInfo.CardTime, Partition = _mCardInfo.CardPartition }; by = DataCombination.CombinationDistanceCard(distancecontent, singlecarddata); break; case 1: //组合卡 List <ViceCardData> vicecarddatas = new List <ViceCardData>(); foreach (CardInfo item in _mBundledCardinfo) { ViceCardData vicecard = new ViceCardData() { ViceNumber = item.CardNumber, Time = item.CardTime, Partition = item.CardPartition, Count = item.CardCount }; vicecarddatas.Add(vicecard); } foreach (CardInfo item in _mBoundAdd) { item.CardCount = DataCombination.SetCount(item.CardCount); ViceCardData vicecard = new ViceCardData() { ViceNumber = item.CardNumber, Time = item.CardTime, Partition = item.CardPartition, Count = item.CardCount }; vicecarddatas.Add(vicecard); } by = DataCombination.CombinationDistanceCard(distancecontent, vicecarddatas); break; default: //车牌识别卡 List <PlateCardData> platecarddatas = new List <PlateCardData>(); foreach (CardInfo item in _mBundledCardinfo) { PlateCardData platecarddata = new PlateCardData() { Plate = item.CardNumber, Time = item.CardTime, Partition = item.CardPartition }; platecarddatas.Add(platecarddata); } foreach (CardInfo item in _mBoundAdd) { PlateCardData platecarddata = new PlateCardData() { Plate = item.CardNumber, Time = item.CardTime, Partition = item.CardPartition }; platecarddatas.Add(platecarddata); } by = DataCombination.CombinationDistanceCard(distancecontent, platecarddatas); break; } if (_mPort.IsOpen) { _mPort.Write(by); } } catch (Exception ex) { btn_Enter.Enabled = true; MessageBox.Show(ex.Message, @"提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }