Ejemplo n.º 1
0
        private void Entrance(string cardId)
        {
            if (allCards.Contains(cardId))
            {
                var db1    = new CarCheckerContext();
                var userId = db1.Cards.FirstOrDefault(c => c.CardId == cardId).UserId;
                var user   = db1.Users.FirstOrDefault(u => u.Id == userId);
                KnownUser(cardId);

                if (!user.InGarage)
                {
                    if (CheckACar.GetCarSratus(cardId) >= 0)
                    {
                        OpenGate.Open(cardId);
                    }
                    else
                    {
                        errorLabel.Text = "Не уплачено!";
                    }
                }
                else
                {
                    errorLabel.Text = "Пользователь не выехал из гаража, но пытается вьехать";
                }
            }
            else
            {
                UnknownPerson();
            }
            RemoveAndFocus();
        }
Ejemplo n.º 2
0
 private void Open(string cardId)
 {
     allCards = db.Cards.Select(c => c.CardId).ToList();
     UnknownPerson();
     if (allCards.Contains(cardId))
     {
         var db1    = new CarCheckerContext();
         var userId = db1.Cards.FirstOrDefault(c => c.CardId == cardId).UserId;
         var user   = db1.Users.FirstOrDefault(u => u.Id == userId);
         KnownUser(cardId);
         if (CheckACar.GetCarSratus(cardId) >= 0)
         {
             OpenGate.Open(cardId);
             UserEntrances.Add(cardId);
         }
         else
         {
             errorLabel.Text = "Не уплачено!";
         }
         //if (user.InGarage)
         //    OpenGate.Open(cardId);
         //else if (CheckACar.GetCarSratus(cardId) >= 0)
         //        OpenGate.Open(cardId);
         //    else
         //        errorLabel.Text = "Не уплачено!";
     }
     RemoveAndFocus();
 }
Ejemplo n.º 3
0
        public static bool ChangeSettings(List <AdminSettings> settings)
        {
            var succsess = false;

            var db = new CarCheckerContext();

            db.AdminSettings.RemoveRange(db.AdminSettings.ToList());
            db.SaveChanges();

            var newSettings = new List <AdminSettings>
            {
                new AdminSettings {
                    Name = AdminSettingsNames.Card1, Value = settings[0].Value
                },
                new AdminSettings {
                    Name = AdminSettingsNames.Card2, Value = settings[1].Value
                },
                new AdminSettings {
                    Name = AdminSettingsNames.Card3, Value = settings[2].Value
                },
                new AdminSettings {
                    Name = AdminSettingsNames.Card4, Value = settings[3].Value
                },
                new AdminSettings {
                    Name = AdminSettingsNames.USBPort, Value = settings[4].Value
                }
            };

            db.AdminSettings.AddRange(newSettings);
            db.SaveChanges();

            succsess = true;
            return(succsess);
        }
Ejemplo n.º 4
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
                var db           = new CarCheckerContext();
                int garageNumber = Convert.ToInt32(garageComboBox.SelectedItem);
                var user         = db.Users.FirstOrDefault(u => u.GarageNumber == garageNumber);

                user.Name     = nameTextBox.Text;
                user.Surname  = surnameTextBox.Text;
                user.Phone    = phoneTextBox.Text;
                user.Birthday = (DateTime) new DateTimeConverter().ConvertFromString(birthdayTextBox.Text);
                db.SaveChanges();

                DialogResult result = MessageBox.Show("Успех!", "Успех!", MessageBoxButtons.OK);
                if (result == DialogResult.OK)
                {
                    Close();
                }
            }
            catch (Exception)
            {
                DialogResult result = MessageBox.Show("Ошибка!", "Ошибка!", MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 5
0
 public static double GetCarStatus(int garageNumber)
 {
     using (var db = new CarCheckerContext())
     {
         var user = db.Users.FirstOrDefault(u => u.GarageNumber == garageNumber);
         return(user.Balance);
     }
 }
Ejemplo n.º 6
0
        public static void AddNewUser(User user, string cardNumber)
        {
            var db = new CarCheckerContext();

            db.Users.Add(user);
            db.SaveChanges();

            AddCardToUser(user, cardNumber);
        }
Ejemplo n.º 7
0
 private static void AddOneOpenCount()
 {
     using (var db = new CarCheckerContext())
     {
         var currentOpensCount = db.AdminSettings.FirstOrDefault(s => s.Name == "openCount").Value;
         db.AdminSettings.FirstOrDefault(s => s.Name == "openCount").Value =
             (Convert.ToInt32(currentOpensCount) + 1).ToString();
         db.SaveChanges();
     }
 }
Ejemplo n.º 8
0
        public static double GetCarSratus(string cardNumber)
        {
            using (var db = new CarCheckerContext())
            {
                var card = db.Cards.FirstOrDefault(c => c.CardId == cardNumber);
                var user = db.Users.FirstOrDefault(u => u.Id == card.UserId);

                return(GetCarStatus(user.GarageNumber));
            }
        }
Ejemplo n.º 9
0
        private static void SendCommandToArduino()
        {
            const int  isReady = 4, end = 5;
            var        db          = new CarCheckerContext();
            SerialPort serialPort1 = new SerialPort()
            {
                PortName = db.AdminSettings.FirstOrDefault(a => a.Name == "arduinoPort").Value,
                BaudRate = 9600
            };

            if (!serialPort1.IsOpen)
            {
                serialPort1.Open();
            }

            if (serialPort1.IsOpen)
            {
                serialPort1.Write("5");
            }

            serialPort1.DiscardInBuffer();
            if (firstOpen)
            {
                firstOpen = false;
                serialPort1.Close();
                return;
            }

            bool getAnswer    = true;
            var  answer       = serialPort1.ReadChar();
            var  answersCount = 0;


            for (int i = 0; i < 15; i++)
            {
                answer = serialPort1.ReadChar();
                if (answer == end)
                {
                    serialPort1.Close();
                    break;
                }
                else if (answer == isReady)
                {
                    serialPort1.Close();
                    SendCommandToArduino();
                    break;
                }
                if (i == 14)
                {
                    serialPort1.Close();
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        public static void AddCardToUser(User user, string cardNumber)
        {
            var db = new CarCheckerContext();

            db.Cards.Add(new RFIDCard
            {
                CardId = cardNumber,
                UserId = user.Id
            });
            db.SaveChanges();
        }
Ejemplo n.º 11
0
        private void ChangeAdminSettings()
        {
            var    db        = new CarCheckerContext();
            string openCount = "0";

            if (db.AdminSettings.ToList().Count == 11)
            {
                openCount = db.AdminSettings.ToList().FirstOrDefault(s => s.Name == "openCount").Value;
            }

            db.AdminSettings.RemoveRange(db.AdminSettings.ToList());
            db.SaveChanges();

            var newSettings = new List <AdminSettings>
            {
                new AdminSettings {
                    Name = "adminDeviceName", Value = adminTextBox.Text
                },
                new AdminSettings {
                    Name = "entranceDeviceName", Value = entranceTextBox.Text
                },
                new AdminSettings {
                    Name = "exitDeviceName", Value = exitTextBox.Text
                },
                new AdminSettings {
                    Name = "card1", Value = card1TextBox.Text
                },
                new AdminSettings {
                    Name = "card2", Value = card2TextBox.Text
                },
                new AdminSettings {
                    Name = "card3", Value = card3TextBox.Text
                },
                new AdminSettings {
                    Name = "card4", Value = card4TextBox.Text
                },
                new AdminSettings {
                    Name = "arduinoPort", Value = arduinoTextBox.Text
                },
                new AdminSettings {
                    Name = "admin1", Value = admin1TextBox.Text
                },
                new AdminSettings {
                    Name = "admin2", Value = admin2TextBox.Text
                },
                new AdminSettings {
                    Name = "openCount", Value = openCount
                }
            };

            db.AdminSettings.AddRange(newSettings);
            db.SaveChanges();
        }
Ejemplo n.º 12
0
        public static bool Add(User user, string cardNumber)
        {
            var succsess = false;
            var db       = new CarCheckerContext();

            db.Users.Add(user);
            db.SaveChanges();

            AddCardToUser(user, cardNumber);
            succsess = true;
            return(succsess);
        }
Ejemplo n.º 13
0
 public static void Add(string card)
 {
     using (var db = new CarCheckerContext())
     {
         db.Entrances.Add(new Entrance
         {
             EntranceDate = DateTime.Now.Date,
             UserId       = Users.GetUser(card).User.Id
         });
         db.SaveChanges();
     }
 }
Ejemplo n.º 14
0
        private static void ChangeStatusInGarage(string cardId)
        {
            using (var db = new CarCheckerContext())
            {
                var userId       = db.Cards.FirstOrDefault(c => c.CardId == cardId).UserId;
                var userInGarage = db.Users.FirstOrDefault(u => u.Id == userId);

                userInGarage.InGarage        = !userInGarage.InGarage;
                db.Entry(userInGarage).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }
        }
Ejemplo n.º 15
0
        public static User GetSelectedUser(string selectedGarage)
        {
            var db     = new CarCheckerContext();
            var garage = Convert.ToInt32(selectedGarage);
            var user   = db.Users
                         .Include(u => u.Payments)
                         .Include(u => u.Cards)
                         .Include(u => u.Entrances)
                         .FirstOrDefault(u => u.GarageNumber == garage);

            return(user);
        }
Ejemplo n.º 16
0
        public static string[] GarageNumbers()
        {
            var db              = new CarCheckerContext();
            var garages         = db.Users.Select(u => u.GarageNumber).OrderBy(k => k).ToArray();
            var garagesInString = new List <string>();

            foreach (var garage in garages)
            {
                garagesInString.Add(garage.ToString());
            }
            return(garagesInString.ToArray());
        }
Ejemplo n.º 17
0
 public static bool AddEntrance(string card)
 {
     using (var db = new CarCheckerContext())
     {
         db.Entrances.Add(new Entrance
         {
             EntranceDate = DateTime.Now.Date,
             UserId       = GetUser(card).User.Id
         });
         db.SaveChanges();
         return(true);
     }
 }
Ejemplo n.º 18
0
 public static void Add(string card)
 {
     using (var db = new CarCheckerContext())
     {
         var newEntrance = new Entrance
         {
             EntranceDate = DateTime.Now.Date,
             UserId       = Show.GetUserByCard(card).Id
         };
         db.Entrances.Add(newEntrance);
         db.SaveChanges();
     }
 }
Ejemplo n.º 19
0
        public static AllUserData ShowUserByCardId(string card)
        {
            var db    = new CarCheckerContext();
            var users = db.Cards.Include(c => c.User).ToList();

            var user = new AllUserData
            {
                User = GetUserByCard(card),
                Card = db.Cards.FirstOrDefault(c => c.CardId == card)
            };

            return(user);
        }
Ejemplo n.º 20
0
        public static void Pay(User user, double price)
        {
            var db = new CarCheckerContext();

            db.Payments.Add(new Models.Payment
            {
                PayUserId = user.Id,
                Sum       = price,
                DateTime  = DateTime.Now
            });
            db.SaveChanges();
            db.Users.FirstOrDefault(u => u.Id == user.Id).Balance += price;
            db.SaveChanges();
        }
Ejemplo n.º 21
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            var        db          = new CarCheckerContext();
            SerialPort serialPort1 = new SerialPort()
            {
                PortName = db.AdminSettings.FirstOrDefault(a => a.Name == "arduinoPort").Value,
                BaudRate = 9600
            };

            if (serialPort1.IsOpen)
            {
                serialPort1.Close();
            }
        }
Ejemplo n.º 22
0
        public static void WriteOff(double price)
        {
            var db = new CarCheckerContext();

            foreach (var user in db.Users)
            {
                user.Balance -= price;
            }
            db.SaveChanges();
            db.WriteOff.Add(
                new WriteOff
            {
                Sum      = price,
                DateTime = DateTime.Now
            });
            db.SaveChanges();
        }
Ejemplo n.º 23
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 10)
            {
                var cardId = textBox1.Text;
                errorLabel.Text = "";
                textBox1.Text   = "";

                if (cardId == password)
                {
                    ReactionOnCard.SuperAdmin();
                    RemoveAndFocus();
                    return;
                }

                if (adminSettings["admin1"] == cardId || adminSettings["admin2"] == cardId)
                {
                    ReactionOnCard.Admin();
                    RemoveAndFocus();
                    return;
                }

                if (adminSettings["adminDeviceName"] == inputDeviceName || adminSettings.ContainsValue(cardId))
                {
                    ReactionOnCard.SuperAdmin();
                    RemoveAndFocus();
                    return;
                }

                Open(cardId);
                var        db          = new CarCheckerContext();
                SerialPort serialPort1 = new SerialPort()
                {
                    PortName = db.AdminSettings.FirstOrDefault(a => a.Name == "arduinoPort").Value,
                    BaudRate = 9600
                };
                if (serialPort1.IsOpen)
                {
                    serialPort1.Close();
                }

                RemoveAndFocus();
            }
        }
Ejemplo n.º 24
0
        public static bool Pay(User user, int price)
        {
            var succsess = false;
            var db       = new CarCheckerContext();

            db.Payments.Add(
                new Models.Payment
            {
                PayUserId = user.Id,
                Sum       = price,
                DateTime  = DateTime.Now
            }
                );
            db.SaveChanges();
            db.Users.Find(user.Id).Balance += price;
            db.SaveChanges();
            succsess = true;
            return(succsess);
        }
Ejemplo n.º 25
0
        public static bool WriteOff(int price)
        {
            var succsess = false;
            var db       = new CarCheckerContext();

            foreach (var user in db.Users)
            {
                user.Balance -= price;
            }

            db.SaveChanges();

            db.WriteOff.Add(new WriteOff {
                DateTime = DateTime.Now, Sum = price
            });
            db.SaveChanges();

            return(succsess);
        }
Ejemplo n.º 26
0
 private void Exit(string cardId)
 {
     if (allCards.Contains(cardId))
     {
         var db1    = new CarCheckerContext();
         var userId = db1.Cards.FirstOrDefault(c => c.CardId == cardId).UserId;
         var user   = db1.Users.FirstOrDefault(u => u.Id == userId);
         KnownUser(cardId);
         if (user.InGarage)
         {
             OpenGate.Open(cardId);
         }
         else
         {
             errorLabel.Text = "Пользователь не вьехал в гараж, но пытается выехать";
         }
     }
     else
     {
         UnknownPerson();
     }
     RemoveAndFocus();
 }
Ejemplo n.º 27
0
        public static List <User> GetAllUsers()
        {
            var db = new CarCheckerContext();

            return(db.Users.ToList());
        }
Ejemplo n.º 28
0
        public static List <WriteOff> GetAllWriteOff()
        {
            var db = new CarCheckerContext();

            return(db.WriteOff.ToList());
        }