Beispiel #1
0
        public static int IshueCard(DateTime D)
        {
            byte[] cardbuf = new byte[250];
            int    ret     = 0;
            string Bdate   = DateTime.Now.ToString("yyMMddHHmm");
            string Edate   = D.ToString("yyMMddHHmm");

            byte[] lockno = new byte[8];

            if (M1Enc.InitializeUSB(1) != 0)
            {
                MessageBox.Show("Проблемы с авторизатором");
                return(1);
            }
            if ((Building != 0) && (Floor != 0) && (Room != 0))
            {
                if ((M1Enc.ReadCard(1, cardbuf) == 0) && (cardbuf[5] != 48))
                {
                    byte b = cardbuf[5];
                    if (M1Enc.GetGuestLockNoByCardDataStr(Program.HotelId, cardbuf, lockno) == 0)
                    {
                        string R = Encoding.ASCII.GetString(lockno).Substring(0, 6);
                        Building = int.Parse(R.Substring(0, 2));
                        Floor    = int.Parse(R.Substring(2, 2));
                        Room     = int.Parse(R.Substring(4, 2));
                    }
                }
            }
            return(M1Enc.GuestCard(1, Program.HotelId,
                                   1, 0, 0, 0, Bdate.ToCharArray(0, 10), Edate.ToCharArray(0, 10),
                                   ($"{Building:00}{Floor:00}{Room:00}" + "99").ToCharArray(0, 8), cardbuf));

            //return 1;
        }
Beispiel #2
0
        public static byte[] ReadLockNo(byte[] cardbuf)
        {
            //cardbuf = new byte[250];

            //if (M1Enc.InitializeUSB(1) != 0)
            //{
            //    MessageBox.Show("Проблемы с авторизатором");
            //    return null;
            //}
            byte[] lockno = new byte[8];
            //if ((M1Enc.ReadCard(1, cardbuf) == 0) /*&& (cardbuf[5] != 48)*/)
            //{
            //    string Signature = Encoding.ASCII.GetString(cardbuf);
            //    if (Signature.Length > 6)
            //    {
            //        if (Signature.Substring(0, 6) == "551501")
            //        {
            if (cardbuf != null)
            {
                M1Enc.GetGuestLockNoByCardDataStr(Program.HotelId, cardbuf, lockno);
            }
            return(lockno);
            //        }
            //    }
            //}
            //return null;
        }
Beispiel #3
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            byte[] cardbuf = new byte[250];
            byte[] lockno  = new byte[8];
            string R;

            if (M1Enc.InitializeUSB(1) != 0)
            {
                timer1.Stop();
                //MessageBox.Show("Проблемы с авторизатором");
                button1.Enabled = false;
                return;
            }
            if (M1Enc.ReadCard(1, cardbuf) != 0)
            {
                MessageBox.Show("Ошибка чтения");
            }
            else
            {
                string Signature = Encoding.ASCII.GetString(cardbuf);
                if (Signature.Length > 6)
                {
                    if (Signature.Substring(0, 6) == "551501")
                    {
                        Card = Encoding.ASCII.GetString(cardbuf).Substring(24, 8);
                        if (Card != "FFFFFFFF")
                        {
                            timer1.Stop();
                            if (M1Enc.GetGuestLockNoByCardDataStr(Program.HotelId, cardbuf, lockno) == 0)
                            {
                                R           = Encoding.ASCII.GetString(lockno).Substring(0, 6);
                                Building    = int.Parse(R.Substring(0, 2));
                                Floor       = int.Parse(R.Substring(2, 2));
                                Room        = int.Parse(R.Substring(4, 2));
                                label2.Text = Find(R);
                            }
                            if (current == null)
                            {
                                current = HR.Find(x => x.Building == Building && x.Floor == Floor && x.Room == Room);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private void Info_Load(object sender, EventArgs e)
        {
            label5.Visible = Convert.ToBoolean(Program.Config["Depo"] ?? false);
            byte[] lockno = new byte[8];
            string R;

            byte[] Edate    = new byte[10];
            byte[] cardtype = new byte[16];

            if (M1Enc.GetGuestLockNoByCardDataStr(Program.HotelId, cardbuf, lockno) == 0)
            {
                R        = Encoding.ASCII.GetString(lockno).Substring(0, 6);
                Building = int.Parse(R.Substring(0, 2));
                Floor    = int.Parse(R.Substring(2, 2));
                Room     = int.Parse(R.Substring(4, 2));
                _GP      = Find(R);
                string r = (_GP == null) ? string.Empty : _GP.HumanReadableRoom;
                label2.Text = r;
            }
            if (M1Enc.GetCardTypeByCardDataStr(cardbuf, cardtype) == 0)
            {
                label3.Text = M1Enc.Card_type(cardtype[0]);
            }

            if (M1Enc.GetGuestETimeByCardDataStr(Program.HotelId, cardbuf, Edate) == 0)
            {
                label7.Text = GetTime(Encoding.ASCII.GetString(Edate)).ToString();
            }
            using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"])))
            {
                DateTime Now = DateTime.Now;
                var      H   = Db.Rooms.Where(x => x.Building == Building && x.Floor == Floor && x.Room == Room).OrderByDescending(x => x.Id);
                string   h   = string.Empty;
                if (H.Count() > 0)
                {
                    var H1 = Db.Cards.Where(x => x.Ci.Value <= Now && Now <= x.Co.Value && x.RoomId == H.First().Id);
                    foreach (var h1 in H1)
                    {
                        dataGridView1.Rows.Add(new object[] { h1.Id, h1.Holder, h1.Card, h1.Ci.Value, h1.Co.Value });
                        if (h1.Card.Trim().ToUpper() == Card.Trim().ToUpper())
                        {
                            if (dataGridView1.Rows.Count > 0)
                            {
                                dataGridView1.Rows[0].Selected = false;
                            }
                            if (dataGridView1.Rows.Count > 0)
                            {
                                dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
                            }
                        }
                    }
                }
            }

            if (Convert.ToBoolean(Program.Config["Depo"] ?? false))
            {
                try
                {
                    label5.Visible = false;
                    label8.Text    = string.Empty;

                    IDepo c = (new Depo.Depo()).Connect(Convert.ToString(Program.Config["DepoServerAddress"]));
                    if (c.Holder(Card, out string Holder) == Results.Succsess)
                    {
                        CiCol.Visible = false;
                        CoCol.Visible = false;
                        dataGridView1.Rows.Add(new object[] { 0, Holder, Card });
                    }
                    if (c.CheckAmount(Card, out decimal Amount) == Results.Succsess)
                    {
                        label5.Visible = (Amount > 0);
                        label8.Text    = $"{Amount:C2}";
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show($"{err.Message}");
                }
            }
            timer2.Start();
        }