Beispiel #1
0
        public int Updata_IcData(cIC_Card_Data icData)
        {
            int intFalg = 0;

            try
            {
                oledCon = DBHelper.getCon();
                oledCon.Open();
                string strAdd = "update tb_ICCard_Data ";
                strAdd += "set 写卡时间='" + DateTime.Now.ToString() + "'," +
                          "Block_8='" + BitConverter.ToString(icData.Block_8) + "'," +
                          "Block_9='" + BitConverter.ToString(icData.Block_9) + "'," +
                          "Block_10='" + BitConverter.ToString(icData.Block_10) + "'," +
                          "卡号='" + icData.ic_num + "'," +
                          "持卡人='" + icData.持卡人 + "'," +
                          "电梯ID='" + icData.电梯ID + "'" +
                          "where IC_ID='" + icData.IC_ID + "'";

                OleDbCommand oledCmd = new OleDbCommand(strAdd, oledCon);
                if (oledCmd.ExecuteNonQuery() != 0)
                {
                    intFalg = 1;//添加成功
                }
                return(intFalg);
            }
            catch (Exception ee)
            {
                return(intFalg);
            }
        }
Beispiel #2
0
        public int Add_IcData(cIC_Card_Data icData)
        {
            int intFalg = 0;

            try
            {
                oledCon = DBHelper.getCon();
                oledCon.Open();
                string strAdd = "insert into tb_ICCard_Data (IC_ID,写卡时间,Block_8,Block_9,Block_10,卡号,持卡人,电梯ID)";
                //string strAdd = "insert into tb_ICCard_Data (IC_ID,写卡时间,Block_8,Block_9,Block_10)";
                strAdd += "values('" + icData.IC_ID + "','" + DateTime.Now.ToString() + "','" +
                          BitConverter.ToString(icData.Block_8) + "','" +
                          BitConverter.ToString(icData.Block_9) + "','" +
                          BitConverter.ToString(icData.Block_10) + "','" +
                          icData.ic_num + "','" +
                          icData.持卡人 + "','" +
                          icData.电梯ID + "')"
                ;
                //strAdd += "values('" + icData.IC_ID + "','" + icData.IC_Fun + "',";
                //strAdd += "'" + icData.Floor_Data + "','" + icData.IC_FunA + "','" + icData.Add_ID + "')";
                OleDbCommand oledCmd = new OleDbCommand(strAdd, oledCon);
                if (oledCmd.ExecuteNonQuery() != 0)
                {
                    intFalg = 1;//添加成功
                }
                return(intFalg);
            }
            catch (Exception ee)
            {
                return(intFalg);
            }
        }
Beispiel #3
0
        public int Find_IcData(cIC_Card_Data icData)
        {
            int intFalg = 0;

            try
            {
                string strcmd = "select * from tb_ICCard_Data where IC_ID='" + icData.IC_ID + "'";

                DataSet ds = DBHelper.getDs(strcmd, "tb_Data");

                if (ds.Tables[0].Rows.Count > 0)
                {
                    intFalg = 1;
                }
                return(intFalg);
            }
            catch (Exception ee)
            {
                return(intFalg);
            }
        }
Beispiel #4
0
        private void btn_deleteRecord_Click(object sender, EventArgs e)
        {
            DBOperation   bf      = new DBOperation();
            cIC_Card_Data ic_data = new cIC_Card_Data();

            ic_data.IC_ID = this.IC_ID;

            DataBase data = new DataBase();//创建DataBase类的对象
            DataSet  ds   = data.getDs("select * from tb_ICCard_Data", "tb_Data");

            form1.dgv_IcData.DataSource = ds.Tables[0];


            if (bf.Delete_IcData(ic_data) == 1)
            {
                MessageBox.Show("delete ok");
            }
            else
            {
                MessageBox.Show("delete error");
            }
        }
Beispiel #5
0
        public int Delete_IcData(cIC_Card_Data icData)
        {
            int intFalg = 0;

            try
            {
                oledCon = DBHelper.getCon();
                oledCon.Open();
                string strcmd = "delete from tb_ICCard_Data where IC_ID='" + icData.IC_ID + "'";

                OleDbCommand oledCmd = new OleDbCommand(strcmd, oledCon);
                if (oledCmd.ExecuteNonQuery() != 0)
                {
                    intFalg = 1;//添加成功
                }
                return(intFalg);
            }
            catch (Exception ee)
            {
                return(intFalg);
            }
        }
        void OnDataRecieved(object sender, DataReceivedArgs e)
        {
            //uint t = e.Packet[1];
            //t = t * 256 + e.Packet[2];
            //t = t * 256 + e.Packet[3];
            //t = t * 256 + e.Packet[4];
            //textBox1.Text = textBox1.Text + e.Packet[0] + e.Packet[1] + e.Packet[2] + e.Packet[3] + e.Packet[4] + e.Packet[5] + e.Packet[6] + "\r\n\r\n";

            byte[] rbuf = new byte[100];
            int    i, num;

            //textBox1.Text += Encoding.ASCII.GetString(e.Packet.Length);
            //textBox1.Text += e.Packet.Length.ToString();
            for (i = 0; i < e.Packet.Length; i++)
            {
                rbuf[i] = e.Packet[i];
            }
            //rbuf[i] = (byte)(i + 97);
            //rbuf[0] = 97;
            //e.Packet[0] = 33;
            e.Packet[0] = 32;

            string str = BitConverter.ToString(e.Packet);
            //textBox1.Text  = str;


            //string str_id = e.Packet[51].ToString("D3") + " " +
            //                e.Packet[52].ToString("D3") + " " +
            //                e.Packet[53].ToString("D3") + " " +
            //                e.Packet[54].ToString("D3") + " " +
            //                e.Packet[55].ToString("D3");

            string str_id = e.Packet[51].ToString("X2") + " " +
                            e.Packet[52].ToString("X2") + " " +
                            e.Packet[53].ToString("X2") + " " +
                            e.Packet[54].ToString("X2");

            //e.Packet[55].ToString("X");

            if (e.Packet[1] == 0xBE)        //  写卡回应
            {
                //BaseInfo bf = new BaseInfo();
                cIC_Card_Data ic_data = new cIC_Card_Data();
                ic_data.IC_ID = str_id;
                //ic_data.IC_Fun = "";
                //ic_data.Floor_Data = "";
                //ic_data.IC_FunA = "";
                ////ic_data.Add_ID = "";

                if (tbxIcNum.Text != "")
                {
                    if (!int.TryParse((tbxIcNum.Text), out num))
                    {
                        MessageBox.Show("请输入卡号!");
                    }
                    else
                    {
                        ic_data.ic_num = num;
                    }
                }

                ic_data.持卡人  = tbxName.Text;
                ic_data.电梯ID = tbxCarNum.Text;


                for (i = 0; i < 16; i++)
                {
                    ic_data.Block_8[i]  = e.Packet[3 + i];
                    ic_data.Block_9[i]  = e.Packet[19 + i];
                    ic_data.Block_10[i] = e.Packet[35 + i];
                }

                if (bf.Find_IcData(ic_data) == 1)
                {
                    textBox1.Text += "\r\n access_db have data\r\n!";
                    if (bf.Updata_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db have up data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db updata error\r\n!";
                    }
                }
                else
                {
                    if (bf.Add_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db add data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db add data error\r\n!";
                    }
                    //bf.Add_IcData(ic_data);
                }

                //if (bf.Add_IcData(ic_data) == 1)
                //{
                //    //MessageBox.Show("add access_db ok!");
                //    textBox1.Text += "add access_db ok!";
                //}
                //else
                //    MessageBox.Show("add access_db error!");
            }
            else if (e.Packet[1] == 0xB5)
            {
                //BaseInfo bf = new BaseInfo();
                cIC_Card_Data ic_data = new cIC_Card_Data();
                ic_data.IC_ID = str_id;
                ic_data.电梯ID  = str_id;
                //ic_data.IC_Fun = "";
                //ic_data.Floor_Data = "";
                //ic_data.IC_FunA = "";
                ////ic_data.Add_ID = "";

                if (tbxIcNum.Text != "")
                {
                    if (!int.TryParse((tbxIcNum.Text), out num))
                    {
                        MessageBox.Show("请输入卡号!");
                    }
                    else
                    {
                        ic_data.ic_num = num;
                    }
                }

                ic_data.持卡人  = tbxName.Text;
                ic_data.电梯ID = tbxCarNum.Text;

                for (i = 0; i < 16; i++)
                {
                    ic_data.Block_8[i]  = e.Packet[3 + i];
                    ic_data.Block_9[i]  = e.Packet[19 + i];
                    ic_data.Block_10[i] = e.Packet[35 + i];
                }

                if (bf.Find_IcData(ic_data) == 1)
                {
                    textBox1.Text += "\r\n access_db have data\r\n!";
                    if (bf.Updata_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db have up data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db updata error\r\n!";
                    }
                }
                else
                {
                    bf.Add_IcData(ic_data);
                }
            }
            else if (e.Packet[1] == 0xBC)   //	采集 主板 ID
            {
                //e.Packet[3 + 0];
                FrmMBoardID frm_Mboard = new FrmMBoardID();
                //frm_Mboard.MBoard_ID = e.Packet[3 + 0].ToString("X2");
                //frm_Mboard.MBoard_ID = str.Substring(2,12);

                frm_Mboard.MBoard_ID = BitConverter.ToString(e.Packet, 3, 12);
                frm_Mboard.Show();
            }

            //if ((e.Packet[1] % 2) == 1)
            //    MessageBox.Show("卡号:" + str_id + "\r\n\r\n" +
            //                    "还剩次数:" + (e.Packet[7] + e.Packet[8] * 256).ToString() + "\r\n\r\n" +
            //                    "已刷卡的次数:" + (e.Packet[31] + e.Packet[32] * 256).ToString());
            //else
            //    MessageBox.Show("卡号:" + str_id + "\r\n\r\n" +
            //                    "刷卡无次数限制!" + "\r\n\r\n" +
            //                    "已刷卡的次数:" + (e.Packet[31] + e.Packet[32] * 256).ToString());

            //}
            //else
            //{
            //    MessageBox.Show("卡号:" + str_id );
            //}
            //textBox1.Text += Encoding.ASCII.GetString(e.Packet)+"\r\n";
            //textBox1.Text += e.Packet[1].ToString("X2") + e.Packet[2].ToString("X2");

            //textBox1.Text += Encoding.Unicode.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF7.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF8.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF32.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.BigEndianUnicode.GetString(e.Packet) + "\r\n";

            //textBox1.Text += Encoding.Default.GetString(e.Packet) + "\r\n";
        }