/// <summary> /// DGV 单击单元格内容 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Dgv_DataList_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } if (!(dgv_DataList.Columns[e.ColumnIndex] is DataGridViewButtonColumn)) { return; } int index = 0; CbAssociateCard mAssociateCard = FormComm.GetDataSourceToClass <CbAssociateCard>(dgv_DataList, ref index); //单个延期 using (DelayParam_Form delayparam = new DelayParam_Form(mAssociateCard)) { if (delayparam.ShowDialog() != DialogResult.OK) { return; } mAssociateCard = delayparam.Tag as CbAssociateCard; if (mAssociateCard.AssociateCardTime.Date != mAssociateCard.UpdateTime.Date) { mAssociateCard.UseState = 3; } //更新列表中的显示 FormComm.UpdateDgvDataSource <CbAssociateCard>(mAssociateCard, dgv_DataList, index); } }
/// <summary> /// 获取副卡 /// </summary> /// <param name="cardnumber"></param> /// <returns></returns> private CbAssociateCard GetViceCard(string cardnumber) { CbAssociateCard vicecard = null; foreach (CbAssociateCard item in _mViceCard) { if (item.AssociateCardNumber != cardnumber) { continue; } vicecard = item; } return(vicecard); }
/// <summary> /// 批量延期 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_Delays_Click(object sender, EventArgs e) { //获取选择批量延期的副卡 List <CbAssociateCard> mAssociateCards = new List <CbAssociateCard>(); for (int i = 0; i < dgv_DataList.RowCount; i++) { bool flag = Utils.StrToBool(dgv_DataList["c_Selected", i].Value, false); if (!flag) { continue; } CbAssociateCard mAssociateCard = FormComm.GetDataSourceToClass <CbAssociateCard>(dgv_DataList, i); mAssociateCards.Add(mAssociateCard); } using (DelayParam_Form delayparam = new DelayParam_Form(mAssociateCards)) { if (delayparam.ShowDialog() != DialogResult.OK) { return; } mAssociateCards = delayparam.Tag as List <CbAssociateCard>; //延期后的时间和车牌分区显示在列表中 foreach (CbAssociateCard item in mAssociateCards) { for (int i = 0; i < dgv_DataList.RowCount; i++) { if (dgv_DataList["AssociateCardNumber", i].Value.Equals(item.AssociateCardNumber)) { if (item.AssociateCardTime.Date != item.UpdateTime.Date) { item.UseState = 3; } //更新列表中的显示 FormComm.UpdateDgvDataSource <CbAssociateCard>(item, dgv_DataList, i); break; } } } } }
/// <summary> /// 确认 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Btn_Enter_Click(object sender, EventArgs e) { btn_Enter.Enabled = false; byte[] by = null; try { if (_mCardCounting == null) { //获取主卡计数数据 _mCardCounting = Dbhelper.Db.FirstDefault <CbCardCountingState>(string.Format(" and UseNumber='{0}' ", _mCardInfo.CardNumber)); //当前计数+1 _mCardCounting.UseCounting = DistanceCardHelper.LimitCount(_mCardCounting.UseCounting); } //获取副卡集合 _mViceCard = new List <CbAssociateCard>(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < dgv_DataList.RowCount; i++) { CbAssociateCard mvicecard = FormComm.GetDataSourceToClass <CbAssociateCard>(dgv_DataList, i); _mViceCard.Add(mvicecard); sb.AppendFormat(" UseNumber='{0}' or", mvicecard.AssociateCardNumber); } if (sb.Length > 0) { sb = sb.Remove(sb.Length - 2, 2); } if (_mViceCardCounting == null && _mCardInfo.CardType == (int)CardTypes.CombinationCard) { //获取副卡的计数数据 _mViceCardCounting = Dbhelper.Db.ToList <CbCardCountingState>(string.Format(" and ({0}) ", sb.ToString())); List <CombinationCardViceCardDataParam> ViceCardParams = new List <CombinationCardViceCardDataParam>(); foreach (CbCardCountingState item in _mViceCardCounting) { //副卡计数+1 item.UseCounting = DistanceCardHelper.LimitCount(item.UseCounting); //获取副卡 CbAssociateCard vicecard = GetViceCard(item.UseNumber); ViceCardParams.Add(new CombinationCardViceCardDataParam() { ViceCardCount = item.UseCounting, ViceCardNumber = item.UseNumber, ViceCardPartition = vicecard.SubCardDivision, ViceCardTime = vicecard.UpdateTime }); } by = DistanceCardHelper.SetDistanceData(_mCardInfo.CardNumber, _mCardCounting.UseCounting, ViceCardParams); } else //车牌识别卡 { List <LprCardViceCardParam> ViceCardParams = new List <LprCardViceCardParam>(); foreach (CbAssociateCard item in _mViceCard) { ViceCardParams.Add(new LprCardViceCardParam() { PlateNumber = item.AssociateCardNumber, ViceCardPartition = item.SubCardDivision, ViceCardTime = item.UpdateTime }); } by = DistanceCardHelper.SetDistanceData(_mCardInfo.CardNumber, _mCardCounting.UseCounting, ViceCardParams); } PortHelper.SerialPortWrite(by); StartTimeOutThread(); } catch (Exception ex) { btn_Enter.Enabled = true; CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// DGV 单元格的值发生变化事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Dgv_ViceCardList_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (_isAddRow) { return; } try { bool check = Utils.StrToBool(dgv_ViceCardList[e.ColumnIndex, e.RowIndex].Value, false); string vicecardnumber = Utils.ObjectToStr(dgv_ViceCardList["c_ViceCardNumber", e.RowIndex].Value); if (check) { //组合副卡 CbAssociateCard vicecard = new CbAssociateCard() { AssociateCardNumber = vicecardnumber, AssociateCardTime = DateTime.Now, UpdateTime = DateTime.Now, SubCardDivision = 65535, UseState = 0 }; _mAddViceCard.Add(vicecard); //查询副卡的计数数据 CbCardCountingState cardcounting = Dbhelper.Db.FirstDefault <CbCardCountingState>(string.Format(" and UseNumber='{0}' ", vicecardnumber)); if (cardcounting != null) { return; } //获取副卡参数 ViceCardParam mViceCardParam = Tab3_Form.SubList[vicecardnumber]; //组合副卡的计数数据 cardcounting = new CbCardCountingState() { UseCounting = mViceCardParam.Count, UseFunction = 0, UseNumber = mViceCardParam.ViceCardNumber }; //添加副卡的计数数据 Dbhelper.Db.Insert <CbCardCountingState>(cardcounting); //副卡获取是否须要解锁 if (mViceCardParam.LockState == 1) { //修改状态添加 vicecard.UseState = 2; } } else { foreach (CbAssociateCard item in _mAddViceCard) { if (item.AssociateCardNumber.Equals(vicecardnumber)) { _mAddViceCard.Remove(item); break; } } } } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } finally { btn_Enter.Enabled = _mAddViceCard.Count > 0; } }
/// <summary> /// 构造函数 单张副卡延期 /// </summary> /// <param name="massociatecard"></param> public DelayParam_Form(CbAssociateCard massociatecard) { InitializeComponent(); _mAssociateCard = massociatecard; }