示例#1
0
        public DistanceDelay_Form(CbCardInfo mcardinfo)
        {
            InitializeComponent();

            _mCardInfo = mcardinfo;

            this.Load        += DistanceDelay_Form_Load;
            this.FormClosing += DistanceDelay_Form_FormClosing;

            cb_AllSelected.CheckedChanged += Cb_AllSelected_CheckedChanged;
            cb_AllSelected.MouseDown      += Cb_AllSelected_MouseDown;

            dgv_DataList.CellPainting                 += Dgv_DataList_CellPainting;
            dgv_DataList.CellMouseEnter               += Dgv_DataList_CellMouseEnter;
            dgv_DataList.CellMouseLeave               += Dgv_DataList_CellMouseLeave;
            dgv_DataList.CellMouseDown                += Dgv_DataList_CellMouseDown;
            dgv_DataList.CellMouseUp                  += Dgv_DataList_CellMouseUp;
            dgv_DataList.CellContentClick             += Dgv_DataList_CellContentClick;
            dgv_DataList.Paint                        += Dgv_DataList_Paint;
            dgv_DataList.CellValueChanged             += Dgv_DataList_CellValueChanged;
            dgv_DataList.CurrentCellDirtyStateChanged += Dgv_DataList_CurrentCellDirtyStateChanged;
            dgv_DataList.RowsAdded                    += Dgv_DataList_RowsAdded;
            dgv_DataList.CellFormatting               += Dgv_DataList_CellFormatting;
            dgv_DataList.AutoGenerateColumns           = false;

            btn_Delays.Click += Btn_Delays_Click;
            btn_Delays.Paint += FormComm.DrawBtnEnabled;
            btn_Enter.Click  += Btn_Enter_Click;
            btn_Enter.Paint  += FormComm.DrawBtnEnabled;
        }
示例#2
0
        /// <summary>
        /// 解锁
        /// </summary>
        /// <param name="cardnumber"></param>
        /// <param name="flag"></param>
        private void UnlockDistanceCard(int flag)
        {
            try
            {
                StopTimeOutThread();
                int index = -1;
                foreach (KeyValuePair <CbCardInfo, int> item in _mUnLockList)
                {
                    index++;
                    if (_mUnLockCardInfo != null && item.Key == _mUnLockCardInfo)
                    {
                        if (flag == 0)
                        {
                            item.Key.Unlocked = 0;
                            Dbhelper.Db.Update <CbCardInfo>(item.Key);
                            dgv_UnlockList["c_State", index].Value = Properties.Resources.check;
                            OnLockChange(item);
                        }
                        _mUnLockCardInfo = null;
                        continue;
                    }
                    if (_mUnLockCardInfo != null)
                    {
                        continue;
                    }
                    if (item.Key.Unlocked == 0)
                    {
                        continue;
                    }
                    _mUnLockCardInfo = item.Key;
                    DistanceTypeParameter typeparam = new DistanceTypeParameter()
                    {
                        Lock = 0, Distance = item.Key.Distance
                    };
                    int    typebyte = DistanceCardHelper.SetCardTypeByte(typeparam, 1);
                    byte[] by       = PortAgreement.GetDistanceContent(item.Key.CardNumber, typebyte);
                    PortHelper.SerialPortWrite(by);

                    StartTimeOutThread();
                    return;
                }
                foreach (KeyValuePair <CbCardInfo, int> item in _mUnLockList)
                {
                    if (item.Key.Unlocked != 0)
                    {
                        UseControlEnabled();
                        return;
                    }
                }
                dgv_UnlockList.Rows.Clear();
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                UseControlEnabled();
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            string username    = tb_UserName.Text.Trim();
            string platenumber = tb_PlateNumber.Text.Trim();
            int    sex         = cb_Sex.SelectedIndex;
            int    age         = (int)ud_Age.Value;
            string phone       = tb_Phone.Text.Trim();
            string address     = tb_Address.Text.Trim();

            if (username.Length == 0)
            {
                //l_UserNameTitle.Text = "用户名称不能为空";
                //l_UserNameTitle.ForeColor = Color.Red;
                tb_UserName.Focus();
                return;
            }
            //if (platenumber.Length == 0)
            //{
            //    l_PlateNumberTitle.Text = "车牌号码不能为空";
            //    l_PlateNumberTitle.ForeColor = Color.Red;
            //    tb_PlateNumber.Focus();
            //    return;
            //}
            //if (phone.Length == 0)
            //{
            //    l_PhoneTitle.Text = "电话号码不能为空";
            //    l_PhoneTitle.ForeColor = Color.Red;
            //    tb_Phone.Focus();
            //    return;
            //}
            CbCardInfo mCardInfo = new CbCardInfo()
            {
                UserName         = username,
                PlateNumber      = platenumber,
                UserSex          = sex,
                UserAge          = age,
                UserPhone        = phone,
                UserAddress      = address,
                CardNumber       = string.Empty,
                StartTime        = DateTime.Now,
                StopTime         = DateTime.Now,
                RegistrationTime = DateTime.Now
            };

            try
            {
                mCardInfo.ID      = Dbhelper.Db.Insert <CbCardInfo>(mCardInfo);
                this.Tag          = mCardInfo;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            btn_Enter.Enabled      = false;
            cb_AllSelected.Enabled = false;
            btn_Remove.Enabled     = false;

            _mCardInfo = null;

            SetUpdateCardData(0);
        }
示例#5
0
        /// <summary>
        /// 确认解锁
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Btn_Enter_Click(object sender, EventArgs e)
        {
            btn_Enter.Enabled      = false;
            cb_AllSelected.Enabled = false;
            btn_Remove.Enabled     = false;

            _mLockCardInfo = null;

            UnlockDistanceCard(0);
        }
示例#6
0
        private void Btn_Edit_Click(object sender, EventArgs e)
        {
            int        index     = 0;
            CbCardInfo mCardInfo = FormComm.GetDataSourceToClass <CbCardInfo>(dgv_InfoList, ref index);

            using (EditInfo_Form edit = new EditInfo_Form(mCardInfo))
            {
                if (edit.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                mCardInfo = edit.Tag as CbCardInfo;
                FormComm.UpdateDgvDataSource <CbCardInfo>(mCardInfo, dgv_InfoList, index);
            }
        }
示例#7
0
        private void Btn_Del_Click(object sender, EventArgs e)
        {
            int        index     = 0;
            CbCardInfo mCardInfo = FormComm.GetDataSourceToClass <CbCardInfo>(dgv_InfoList, ref index);

            if (MessageBox.Show("确认删除用户:" + mCardInfo.UserName + " 的信息吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) != DialogResult.OK)
            {
                return;
            }
            try
            {
                Dbhelper.Db.Del <CbCardInfo>(mCardInfo.ID);
                GetRecordCount();
                //DataTable dt = dgv_InfoList.DataSource as DataTable;
                //dt.Rows.RemoveAt(index);
            }
            catch (Exception ex)
            {
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#8
0
        public EditInfo_Form(CbCardInfo mcardinfo)
        {
            InitializeComponent();

            this.mCardInfo = mcardinfo;

            this.Load    += AddInfo_Load;
            this.KeyDown += EditInfo_Form_KeyDown;

            l_UserNameTitle.MouseDown    += L_UserNameTitle_MouseDown;
            tb_UserName.TextChanged      += Tb_UserName_TextChanged;
            tb_UserName.KeyPress         += Tb_UserName_KeyPress;
            l_PlateNumberTitle.MouseDown += L_PlateNumberTitle_MouseDown;
            tb_PlateNumber.TextChanged   += Tb_PlateNumber_TextChanged;
            tb_PlateNumber.KeyPress      += Tb_PlateNumber_KeyPress;
            cb_Sex.KeyPress        += Cb_Sex_KeyPress;
            ud_Age.KeyPress        += ud_Age_KeyPress;
            l_PhoneTitle.MouseDown += L_PhoneTitle_MouseDown;
            tb_Phone.TextChanged   += Tb_Phone_TextChanged;
            tb_Phone.KeyPress      += Tb_Phone_KeyPress;
            tb_Address.KeyPress    += Tb_Address_KeyPress;
            btn_Enter.Click        += Btn_Enter_Click;
            btn_SetPlate.Click     += Btn_SetPlate_Click;
        }
        /// <summary>
        /// 延期更新
        /// </summary>
        /// <param name="cardnumber"></param>
        /// <param name="flag"></param>
        private void SetUpdateCardData(int flag)
        {
            try
            {
                StopTimeOutThread();
                int index = -1;
                //遍历更新的集合
                foreach (KeyValuePair <CbCardInfo, int> item in _mUpdateList)
                {
                    index++;
                    if (_mCardInfo != null && item.Key == _mCardInfo)
                    {
                        if (flag != 0) //失败
                        {
                            dgv_DelayList["c_State", index].Value = Properties.Resources.block;
                        }
                        else
                        {
                            DateTime maxtime = DateTime.MinValue;
                            foreach (CbAssociateCard vicecarditem in _mViceCard)
                            {
                                if (vicecarditem.UseState == 1)
                                {
                                    vicecarditem.UseState          = 0;
                                    vicecarditem.AssociateCardTime = vicecarditem.UpdateTime;
                                }
                                if (vicecarditem.UpdateTime.Date > maxtime.Date)
                                {
                                    maxtime = vicecarditem.UpdateTime;
                                }
                            }
                            if (item.Key.StopTime.Date != maxtime.Date)
                            {
                                item.Key.StopTime = maxtime;
                                //更新主卡数据
                                Dbhelper.Db.Update <CbCardInfo>(item.Key);
                            }
                            //更新副卡数据
                            Dbhelper.Db.Update <CbAssociateCard>(_mViceCard.ToArray());
                            //更新计数数据
                            if (_mViceCardCounting != null)
                            {
                                _mViceCardCounting.Add(_mCardCounting);
                                Dbhelper.Db.Update <CbCardCountingState>(_mViceCardCounting.ToArray());
                            }
                            else
                            {
                                Dbhelper.Db.Update <CbCardCountingState>(_mCardCounting);
                            }
                            dgv_DelayList["c_State", index].Value = Properties.Resources.check;
                            OnUpdateChanage(item);
                        }
                        _mCardInfo = null;
                        continue;
                    }
                    if (_mCardInfo != null)
                    {
                        continue;
                    }
                    if (dgv_DelayList["c_State", index].Value == Properties.Resources.check)
                    {
                        continue;
                    }
                    _mCardInfo = item.Key;
                    //获取主卡计数字节数据
                    _mCardCounting = Dbhelper.Db.FirstDefault <CbCardCountingState>(" and UseNumber='" + item.Key.CardNumber + "' ");
                    //计数字节+1
                    _mCardCounting.UseCounting = DistanceCardHelper.LimitCount(_mCardCounting.UseCounting);
                    //获取副卡数据集
                    _mViceCard = Dbhelper.Db.ToList <CbAssociateCard>(" and CardID =" + item.Key.ID + " ");
                    byte[] by = null;
                    if (item.Key.CardType == (int)CardTypes.CombinationCard) //组合卡
                    {
                        StringBuilder sb = new StringBuilder();
                        foreach (CbAssociateCard vicecarditem in _mViceCard)
                        {
                            sb.AppendFormat(" UseNumber='{0}' or", vicecarditem.AssociateCardNumber);
                        }
                        if (sb.Length > 0)
                        {
                            sb.Remove(sb.Length - 2, 2);
                        }
                        //获取副卡集合的计数字节数据集
                        _mViceCardCounting = Dbhelper.Db.ToList <CbCardCountingState>(string.Format(" and ({0}) ", sb.ToString()));

                        List <CombinationCardViceCardDataParam> ViceCardParam = new List <CombinationCardViceCardDataParam>();
                        foreach (CbAssociateCard vicecarditem in _mViceCard)
                        {
                            CbCardCountingState vicecardcounting = GetViceCardCounting(vicecarditem.AssociateCardNumber);
                            ViceCardParam.Add(new CombinationCardViceCardDataParam()
                            {
                                ViceCardCount     = vicecardcounting.UseCounting,
                                ViceCardNumber    = vicecarditem.AssociateCardNumber,
                                ViceCardPartition = vicecarditem.SubCardDivision,
                                ViceCardTime      = vicecarditem.UpdateTime
                            });
                        }
                        by = DistanceCardHelper.SetDistanceData(item.Key.CardNumber, _mCardCounting.UseCounting, ViceCardParam);
                    }
                    else//车牌识别卡
                    {
                        List <LprCardViceCardParam> ViceCardParam = new List <LprCardViceCardParam>();
                        foreach (CbAssociateCard vicecarditem in _mViceCard)
                        {
                            ViceCardParam.Add(new LprCardViceCardParam()
                            {
                                PlateNumber       = vicecarditem.AssociateCardNumber,
                                ViceCardPartition = vicecarditem.SubCardDivision,
                                ViceCardTime      = vicecarditem.UpdateTime
                            });
                        }
                        by = DistanceCardHelper.SetDistanceData(item.Key.CardNumber, _mCardCounting.UseCounting, ViceCardParam);
                    }
                    //发送数据
                    PortHelper.SerialPortWrite(by);
                    //开始超时线程
                    StartTimeOutThread();
                    return;
                }
                btn_Enter.Enabled = PortHelper.IsConnection;
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                SetControlEnabled();
                CustomExceptionHandler.GetExceptionMessage(ex);
                MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#10
0
        /// <summary>
        /// 构造函数 单卡延期
        /// </summary>
        /// <param name="mcardinfo"></param>
        public DelayParam_Form(CbCardInfo mcardinfo)
        {
            InitializeComponent();

            _mCardInfo = mcardinfo;
        }