Пример #1
0
        private void Button1_Click(object sender, EventArgs e)
        {
            int ret;

            byte[] cardbuf = new byte[250];
            string Bdate   = DateTime.Now.ToString("yyMMddHHmm");
            string Edate   = dateTimePicker2.Value.ToString("yyMMddHHmm");


            if (M1Enc.InitializeUSB(1) != 0)
            {
                //MessageBox.Show("Проблемы с авторизатором");
                button1.Enabled = false;
                return;
            }
            string Crd = string.Empty;

            if ((M1Enc.ReadCard(1, cardbuf) == 0) && (cardbuf[5] != 48))
            {
                byte b = cardbuf[5];
                if ((ret = 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)) == 0)
                {
                    if ((ret = M1Enc.ReadCard(1, cardbuf)) != 0)
                    {
                        MessageBox.Show("Ошибка чтения карты");
                    }
                    else
                    {
                        DateTime Ci = DateTime.Now;
                        DateTime Co;
                        byte[]   E = new byte[10];
                        if ((M1Enc.GetGuestETimeByCardDataStr(Program.HotelId, cardbuf, E)) == 0)
                        {
                            string p = Encoding.ASCII.GetString(E);
                            Co = new DateTime(2000 + Int16.Parse(p.Substring(0, 2)),
                                              Int16.Parse(p.Substring(2, 2)), Int16.Parse(p.Substring(4, 2)), Int16.Parse(p.Substring(6, 2)), Int16.Parse(p.Substring(8, 2)), 0);
                        }
                        else
                        {
                            Co = DateTime.Today;
                        }
                        string Card   = Encoding.ASCII.GetString(cardbuf).Substring(24, 8);
                        string Holder = (textBox1.Text.Length > 0) ? textBox1.Text.Trim() : string.Empty;

                        using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"])))
                        {
                            //var r1 = HR.Where(x => x.Building == Building && x.Floor == Floor && x.Room == Room);
                            //if (r1.Count() > 0)
                            //{
                            //    r1.First().State = RoomStates.Busy;
                            //}

                            var r = Db.Rooms.Where(x => x.Building == Building && x.Floor == Floor && x.Room == Room);
                            if (r.Count() > 0)
                            {
                                r.First().State = (int)RoomStates.Busy;
                            }

                            //if (r.First().Cards.Count() > 0)
                            //{
                            //    Cards C = r.First().Cards.First();
                            //    C.Ci = Ci;
                            //    C.Co = Co;
                            //    C.Card = Card;
                            //    C.RoomId = r.First().Id;
                            //    C.Holder = Holder;
                            //}
                            //else
                            {
                                Cards C = new Cards
                                {
                                    Ci     = Ci,
                                    Co     = Co,
                                    Card   = Card,
                                    RoomId = r.First().Id,
                                    Holder = Holder
                                };
                                //Db.Cards.InsertOnSubmit(C);
                                r.First().Cards.Add(C);
                            }
                            Db.SubmitChanges();
                            Db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues);
                        }
                        // работаем с депозитной системой
                        if (Convert.ToBoolean(Program.Config["Depo"] ?? false))
                        {
                            if (decimal.TryParse(textBox2.Text, out decimal Deposite))
                            {
                                // прверяем существование счета пользователя
                                string address = Convert.ToString(Program.Config["DepoServerAddress"]);
                                IDepo  c       = (new Depo.Depo()).Connect(address);
                                try
                                {
                                    if (c.CheckAmount(Card, out decimal Amount) == Results.Succsess)
                                    {
                                        // Счет существует, пополняем его
                                        if (c.Plus(Card, Deposite) == Results.Succsess)
                                        {
                                            // Пополнение успешно
                                            MessageBox.Show("Пополнение успешно");
                                        }
                                        else
                                        {
                                            MessageBox.Show("Ошибка ополнения счета");
                                        }
                                    }
                                    else
                                    {
                                        // Счета нет, создаем его
                                        if (c.CreateAccount(Card, Holder, Deposite) == Results.Succsess)
                                        {
                                            // Счет создан
                                            MessageBox.Show("Счет создан");
                                        }
                                        else
                                        {
                                            MessageBox.Show("Ошибка создания счета");
                                        }
                                    }
                                }
                                catch (Exception err)
                                {
                                    MessageBox.Show($"{err.Message}");
                                }
                            }
                        }
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Ошибка записи");
                }
            }
        }
Пример #2
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();
        }