// Перевыпуск карты для управления депозитом (не номерной) private void ToolStripButton5_Click(object sender, EventArgs e) { DateTime Co = DateTime.MinValue; using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { var I = Db.Cards.Where(x => !x.RoomId.HasValue); if (I.Count() > 0) { SelectDepo f = new SelectDepo() { ShowIcon = false, ShowInTaskbar = false, StartPosition = FormStartPosition.CenterScreen, Tag = I }; if (f.ShowDialog() == DialogResult.OK) { var _C = Db.Cards.Where(x => x.Id == Convert.ToInt32(f.Tag)); if (_C.Count() > 0) { Card = _C.First().Card; Co = _C.First().Co.Value; //_GP.Building = 99; //_GP.Floor = 99; //_GP.Room = 99; //_C.First().Co = DateTime.Now; string Card1 = PregareNewDepo(99, 99, 99, Co); _C.First().Card = Card1; Db.SubmitChanges(); } } } } }
private void P3_Click(object sender, EventArgs e) { DateTime Co = DateTime.MinValue; int Id = 0; using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { Id = Db.Rooms.Where(x => x.Building.Value == _GP.Building && x.Floor.Value == _GP.Floor && x.Room.Value == _GP.Room).First().Id; Выбор_карты f = new Выбор_карты() { Tag = Id }; if (f.ShowDialog() == DialogResult.OK) { var _C = Db.Cards.Where(x => x.Id == Convert.ToInt32(f.Tag)); if (_C.Count() > 0) { LostForm lf = new LostForm() { Tag = _C.First().Card.Trim() }; if (lf.ShowDialog() == DialogResult.OK) { Card = _C.First().Card; Co = _C.First().Co.Value; Db.Cards.DeleteOnSubmit(_C.First()); Db.SubmitChanges(); } } } PregareNewDepo(_GP.Building, _GP.Floor, _GP.Room, Co); } }
public void DrawRooms(List <HotelRooms> HR) { using (Graphics G = panel1.CreateGraphics()) { //G.Clear(SystemColors.Control); using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { Db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues); LoadRoomState(); Point StartPoint = new Point(70, 20); foreach (var L in HR) { if (L.State != RoomStates.Busy) { G.FillPath(new SolidBrush(State2Color((int)L.State)), L.GP); } else { if (L.Co >= DateTime.Now) { G.FillPath(new SolidBrush(State2Color((int)L.State)), L.GP); } else { G.FillPath(new HatchBrush(HatchStyle.DarkVertical, State2Color((int)L.State)), L.GP); } } G.DrawPath(Pens.LightGray, L.GP); G.DrawString(L.HumanReadableRoom.Trim(), new Font(SystemFonts.DefaultFont.FontFamily, 18), Brushes.Black, L.GP.PathPoints.First()); } //G.DrawLine(Pens.Black, 0, startPoint.Y - 30, panel1.Width, startPoint.Y - 30); } } }
private void CheckOutWithOutCard_Click(object sender, EventArgs e) { using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { //int CardNo = 0; //Выбор_карты f = new Выбор_карты() { Tag = Db.Rooms.Where(x => x.Building.Value == current.Building && x.Floor.Value == current.Floor && x.Room.Value == current.Room).First().Id }; //if (f.ShowDialog() == DialogResult.OK) //{ //CardNo = Convert.ToInt32(f.Tag); DateTime Now = DateTime.Now; // пишем lost по количеству карт в номере var _C = Db.Cards.Where(x => x.Rooms.Building.Value == current.Building && x.Rooms.Floor.Value == current.Floor && x.Rooms.Room.Value == current.Room && x.Co.Value > Now); if (_C.Count() > 0) { int count = _C.Count(); foreach (var c in _C) { Hide(); LostForm lf = new LostForm() { Tag = c.Card, StartPosition = FormStartPosition.CenterScreen, ShowIcon = false, ShowInTaskbar = false, Text = $"Положите чистую карту в авторизатор" }; if (lf.ShowDialog() == DialogResult.OK) { count--; c.Co = DateTime.Now; //Db.Cards.DeleteOnSubmit(c); } } } //var r1 = HR.Where(x => x.Building == current.Building && x.Floor == current.Floor && x.Room == current.Room); //if (r1.Count() > 0) //{ // r1.First().State = RoomStates.Vacant; //} var _r = Db.Rooms.Where(x => x.Building.Value == current.Building && x.Floor.Value == current.Floor && x.Room.Value == current.Room && x.Cards.Where(y => y.Co.Value > Now).Count() > 0); if (_r.Count() > 0) { Rooms R = _r.First(); if (R.Cards.Count(x => x.Co.Value > DateTime.Now) <= 0) { R.State = (int)RoomStates.Vacant; } } Db.SubmitChanges(); } Close(); }
private List <HotelRooms> LoadRoomState() { List <HotelRooms> HR = new List <HotelRooms>(); using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { //HR.Clear(); var _S = Db.Rooms.OrderBy(x => x.HumanRoomNumber).GroupBy(x => x.Floor.Value); if (_S.Count() > 0) { Point StartPoint = new Point(Convert.ToInt32(Program.Config["StartX"] ?? 70), Convert.ToInt32(Program.Config["StartY"] ?? 50)); //Point StartPoint = new Point(70, 50); HotelRooms Room = new HotelRooms(); foreach (var L in _S) { foreach (var N in L) { Rectangle R = new Rectangle(StartPoint, new Size(Convert.ToInt32(Program.Config["SizeX"] ?? 50), Convert.ToInt32(Program.Config["SizeY"] ?? 50))); GraphicsPath GP = new GraphicsPath(); GP.AddRectangle(R); P.Add(GP); DateTime Checkout; if (N.Cards.Count() > 0) { Checkout = N.Cards.Max(x => x.Co.Value); } //Checkout = N.Cards.First().Co.Value; else { Checkout = DateTime.MaxValue; } Room = new HotelRooms { HumanReadableRoom = N.HumanRoomNumber, Room = N.Room.Value, Building = N.Building.Value, Floor = N.Floor.Value, GP = GP, State = (RoomStates)N.State.Value, Co = Checkout//N.Cards.First().Ci.Value }; HR.Add(Room); StartPoint = NewPosition(StartPoint); } StartPoint = NewLine(StartPoint); } } } return(HR); }
private void Room2HotelRooms(int roomId) { using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { var _r = Db.Rooms.Where(x => x.Id == roomId); if (_r.Count() > 0) { Rooms R = _r.First(); Building = R.Building.Value; Floor = R.Floor.Value; Room = R.Room.Value; } } }
public static void FillDbCountries() { Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("ru-RU"); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ru-RU"); //create a new Generic list to hold the country names returned List <string> cultureList = new List <string>(); //create an array of CultureInfo to hold all the cultures found, these include the users local cluture, and all the //cultures installed with the .Net Framework CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures); //loop through all the cultures found foreach (CultureInfo culture in cultures) { try { //pass the current culture's Locale ID (http://msdn.microsoft.com/en-us/library/0h88fahh.aspx) //to the RegionInfo contructor to gain access to the information for that culture RegionInfo region = new RegionInfo(culture.LCID); //make sure out generic list doesnt already //contain this country if (!(cultureList.Contains(region.DisplayName))) { //not there so add the EnglishName (http://msdn.microsoft.com/en-us/library/system.globalization.regioninfo.englishname.aspx) //value to our generic list cultureList.Add(region.EnglishName); } } catch (ArgumentException ex) { // just ignor this continue; } } cultureList.Sort(); using (LockDbDataContext db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { foreach (var country in cultureList.Distinct()) { db.Countries.InsertOnSubmit(new Countries { Title = country }); } db.SubmitChanges(); } }
private void P1_Load(object sender, EventArgs e) { if (!DesignMode) { using (LockDbDataContext db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { comboBox1.DisplayMember = "Title"; comboBox1.ValueMember = "Id"; comboBox1.DataSource = db.Countries.Select(x => new { Id = x.Id, Title = x.Title.Trim() }).ToList(); comboBox2.DisplayMember = "Title"; comboBox2.ValueMember = "Id"; comboBox2.DataSource = db.Docs.Select(x => new { Id = x.Id, Title = x.Title.Trim() }).ToList(); } label10.Visible = textBox9.Visible = Convert.ToBoolean(Program.Config["Depo"] ?? false); } }
private void Timer1_Tick(object sender, EventArgs e) { DrawRooms(LoadRoomState()); if (Convert.ToBoolean(Program.Config["AutoCheckOut"] ?? false)) { using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { var R = Db.Rooms.Where(x => x.State.Value != (int)RoomStates.Vacant && x.Cards.Max(y => y.Co.Value) < DateTime.Now); if (R.Count() > 0) { foreach (var r in R) { r.State = (int)RoomStates.Vacant; } Db.SubmitChanges(); } } } }
private void PanelGuest_Load(object sender, EventArgs e) { NewBTN.Visible = false; // (_GuestNew != null); SaveBTN.Visible = false; // (_GuestSave != null); AddButton1.Visible = true; //toolStrip1.Visible = (NewBTN.Visible || SaveBTN.Visible); Text += $" {Room}"; if (!DesignMode) { using (LockDbDataContext db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { comboBox1.DisplayMember = "Title"; comboBox1.ValueMember = "Id"; comboBox1.DataSource = db.Countries.Select(x => x.Title.Trim()).ToList(); comboBox2.DisplayMember = "Title"; comboBox2.ValueMember = "Id"; comboBox2.DataSource = db.Docs.Select(x => x.Title.Trim()).ToList(); } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (File.Exists(@"c:\Pos\Locks.xml")) { Parse_Config(@"c:\Pos\Locks.xml"); } else { MessageBox.Show("Нет конфигурационного файла"); return; } try { Thread.CurrentThread.CurrentUICulture = new CultureInfo(Config["Lang"].ToString()); } catch (Exception) { MessageBox.Show("<Lang> отсутствует в конфигурационном файле. Используется язык по умолчанию"); } if ((!Config.ContainsKey("License")) || (!Licensing.CheckLicense(Config["License"].ToString()))) { MessageBox.Show($"Ошибка {Licensing.CPU()}: Нет лиензии"); using (StreamWriter w = new StreamWriter(@"C:\pos\Error.txt")) { w.WriteLine($"Ошибка {Licensing.CPU()}: Нет лиензии"); } return; } HotelId = int.Parse(Config["HId"].ToString()); if (HotelId == 0) { MessageBox.Show("Не задан идентификатор отеля"); return; } try { using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Config["ConnectionString"]))) { if (!Db.DatabaseExists()) { Db.CreateDatabase(); MessageBox.Show("База данных создана. Заполните базу."); return; } } } catch (Exception err) { MessageBox.Show($"Ошибка SQL {err.Message}"); return; } // Проверяем не запущен ли уже экземпляр программы using (var mutex = new Mutex(false, "Lock")) { if (mutex.WaitOne(TimeSpan.FromSeconds(3))) // Подождать три секунды - вдруг предыдущий экземпляр еще закрывается { Application.Run(new Form1() { WindowState = FormWindowState.Maximized }); } else { MessageBox.Show("Другая копия программы запущена на этом компьютере. Используйте Alt+Tab для переключения между приложениями"); return; } } }
private void Button1_Click(object sender, EventArgs e) { // проверяем депозит if (Convert.ToBoolean(Program.Config["Depo"] ?? false)) { IDepo c = (new Depo.Depo()).Connect(Convert.ToString(Program.Config["DepoServerAddress"])); if (c.CheckAmount(Card, out decimal Amount) == Results.Succsess) { if (Amount > 0) { MessageBox.Show("На карте есть активный депозит. Выселение не возможно"); return; } } } byte[] cardbuf = new byte[250]; using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { DateTime Now = DateTime.Now; var _C = Db.Cards.Where(x => x.Rooms.Building.Value == current.Building && x.Rooms.Floor.Value == current.Floor && x.Rooms.Room.Value == current.Room && x.Rooms.Room.Value == current.Room && x.Co.Value > Now); int count = _C.Count(); if (count > 0) { foreach (var c in _C) { Form f = new Form() { StartPosition = FormStartPosition.CenterScreen, AutoSize = true, AutoSizeMode = AutoSizeMode.GrowAndShrink, ShowIcon = false, ShowInTaskbar = false, ControlBox = false, Text = $"Положите карту {count--} от номера в авторизатор" }; //f.Controls.Add(new Label //{ // Font = new Font(DefaultFont.FontFamily, 12), // TextAlign = ContentAlignment.MiddleCenter, // Text = $"Положите карту {count--} от номера в авторизатор" //}); f.Controls.Add(new Button { DialogResult = DialogResult.OK, Font = new Font(DefaultFont.FontFamily, 12), AutoSize = true, Text = $"Записать карту от номера" }); Hide(); if (f.ShowDialog() == DialogResult.OK) { if (Program.IshueCard(Now) == 0) //{ } //Стереть_карту f = new Стереть_карту() { StartPosition = FormStartPosition.CenterScreen, Tag = c.Card.Trim() }; //if (f.ShowDialog() == DialogResult.OK) { c.Co = DateTime.Now; f.Close(); //Db.Cards.DeleteOnSubmit(c); } } } } var r = Db.Rooms.Where(x => x.Building == Building && x.Floor == Floor && x.Room == Room && x.Cards.Where(y => y.Co.Value > Now).Count() > 0); if (r.Count() > 0) { Rooms R = r.First(); if (R.Cards.Count(x => x.Co.Value > DateTime.Now) <= 0) { r.First().State = (int)RoomStates.Vacant; } } Db.SubmitChanges(); } Close(); }
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(); }
private void Button1_Click(object sender, EventArgs e) { if (Convert.ToBoolean(Program.Config["Depo"] ?? false)) { if (decimal.TryParse(textBox1.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 { // Счета нет, будем создвать его // 1. записываем карту на номер 999999 if (Program.IshueCard(99, 99, 99, DateTime.Today.AddYears(1)) == 0) { // 2. читаем номер карты byte[] cardbuf = new byte[250]; Card = Program.ReadCard(out cardbuf); } // 3. создаем депозитный счет if (c.CreateAccount(Card, textBox2.Text, Deposite) == Results.Succsess) { //MessageBox.Show("Счет создан успешно"); if (textBox2.Text != string.Empty) { using (LockDbDataContext Db = new LockDbDataContext(Convert.ToString(Program.Config["ConnectionString"]))) { Db.Cards.InsertOnSubmit(new Cards { Card = Card, Holder = textBox2.Text, Ci = DateTime.Now, Co = DateTime.Today.AddYears(1) }); Db.SubmitChanges(); } } } else { MessageBox.Show("Ошибка создания счета"); } //MessageBox.Show($"С картой {Card} не связано ни одного счета"); } } catch (Exception err) { MessageBox.Show($"{err.Message}"); } } } // } //} //else //{ // MessageBox.Show("Нет карты в автризаторе"); //} Close(); }