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; }
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; }
private void Button1_Click(object sender, EventArgs e) { byte[] cardbuf = new byte[250]; if (Program.HotelId != 0) { if (M1Enc.InitializeUSB(1) != 0) { MessageBox.Show("Проблемы с авторизатором"); Close(); return; } if ((M1Enc.ReadCard(1, cardbuf) == 0) && (cardbuf[5] != 48)) { string Card = Encoding.ASCII.GetString(cardbuf).Substring(24, 8); if (Card == "FFFFFFFF") { MessageBox.Show("Карта уже чистая!"); return; } else { if (M1Enc.CardErase(1, Program.HotelId, cardbuf) == 0) { MessageBox.Show("Карта стерта"); DialogResult = DialogResult.OK; //Close(); } } } } }
private void Button1_Click(object sender, EventArgs e) { byte[] cardbuf = new byte[250]; string Bdate = DateTime.Now.ToString("yyMMddHHmm"); string Edate = DateTime.Now.AddMonths(4).ToString("yyMMddHHmm"); if (M1Enc.InitializeUSB(1) != 0) { MessageBox.Show("Проблемы с авторизатором"); Close(); return; } if ((M1Enc.ReadCard(1, cardbuf) == 0) && (cardbuf[5] != 48)) { if (M1Enc.BuildingCard(1, Program.HotelId, 1, 1, 1, 1, 127, Bdate.ToCharArray(0, 10), "0001".ToCharArray(0, 4), (Edate.Substring(0, 6) + "2359").ToCharArray(0, 10), $"{HR[0].Building:00}".ToCharArray(0, 2), cardbuf) == 0) { if (M1Enc.ReadCard(1, cardbuf) == 0) { // [todo] записывать в базу номер карты и держателя для последующего аннулирования карты } this.Close(); } else { MessageBox.Show("Ошибка записи"); } } }
public Поселение(HotelRooms R, List <HotelRooms> h) : this() { HR = h; Building = R.Building; Floor = R.Floor; Room = R.Room; InitializeComponent(); label2.Text = $"{R.HumanReadableRoom}"; label5.Text = DateTime.Now.ToString("dd MMM yyyy HH:mm"); dateTimePicker2.MinDate = DateTime.Today; if (DateTime.Today == dateTimePicker2.Value.Date) { dateTimePicker2.Value = DateTime.Today.AddHours(DateTime.Now.Hour + 1).AddMinutes(00); } else { dateTimePicker2.Value = DateTime.Today.AddHours(12).AddMinutes(00); } if (M1Enc.InitializeUSB(1) != 0) { //MessageBox.Show("Проблемы с авторизатором"); button1.Enabled = false; return; } if (Convert.ToBoolean(Program.Config["Depo"] ?? false)) { textBox2.Visible = Convert.ToBoolean(Program.Config["Depo"] ?? false); } }
private void Стереть_карту_Load(object sender, EventArgs e) { if (M1Enc.InitializeUSB(1) != 0) { MessageBox.Show("Проблемы с авторизатором"); Close(); return; } }
private void Button1_Click(object sender, EventArgs e) { byte[] cardbuf = new byte[250]; string Card = Convert.ToString(Tag); if ((M1Enc.ReadCard(1, cardbuf) == 0) && (cardbuf[5] != 48)) { if (M1Enc.LimitCard(1, Program.HotelId, 1, 0, DateTime.Now.AddDays(1).ToString("yyMMddHHmm").ToCharArray(0, 10), Card_Pack(Card.Trim()), cardbuf) == 0) { DialogResult = DialogResult.OK; } } }
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); } } } } } }
public Выселение(List <HotelRooms> h, HotelRooms c) : this() { label6.Visible = false; HR = h; if (c != null) { current = c; label2.Text = c.HumanReadableRoom; label5.Text = $"{DateTime.Now:dd MMM yyyy HH:mm}"; } else { MessageBox.Show("Карта не от номера"); button1.Enabled = false; } if (M1Enc.InitializeUSB(1) != 0) { timer1.Stop(); //MessageBox.Show("Проблемы с авторизатором"); button1.Enabled = false; } }
public static string ReadCard(out byte[] cardbuf) { cardbuf = null; if (M1Enc.InitializeUSB(1) != 0) { MessageBox.Show("Проблемы с авторизатором"); return(string.Empty); } string Crd = string.Empty; cardbuf = new byte[250]; 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") { return(Encoding.ASCII.GetString(cardbuf).Substring(24, 8)); } else { //MessageBox.Show("В авторизаторе неверная карта"); return(string.Empty); } } else { return(string.Empty); } } else { return(string.Empty); } }
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("Ошибка записи"); } } }
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(); }