Exemplo n.º 1
0
        public bool OpenRecord(int number)
        {
            driver = DriverDataMapper.FindByLicenseNumber(number);
            LoadData();

            return(true);
        }
        public IActionResult Login(int login, string password)
        {
            Driver selectedDriver = DriverDataMapper.FindByLicenseNumber(login);

            if (selectedDriver == null)
            {
                Employee employee = EmployeeDataMapper.FindByID(login);
                if (employee == null)
                {
                    ModelState.AddModelError("Login", "User not found in DB");
                }
                else if (employee.Password != password)
                {
                    ModelState.AddModelError("Password", "Wrong password");
                }
                else
                {
                    if (ModelState.IsValid)
                    {
                        HttpContext.Session.SetString("user", employee.ID.ToString());
                        HttpContext.Session.SetString("userType", "employee");
                        return(RedirectToAction("EmployeeInterface", "Home"));
                    }
                }
            }
            else if (selectedDriver.Password != password)
            {
                ModelState.AddModelError("Password", "Wrong password");
            }
            else
            {
                if (ModelState.IsValid)
                {
                    HttpContext.Session.SetString("user", selectedDriver.ID.ToString());
                    HttpContext.Session.SetString("userType", "driver");
                    return(RedirectToAction("DriverInterface", "Home"));
                }
            }

            return(View());
        }
Exemplo n.º 3
0
        private void buttonRecordConfirm_Click(object sender, EventArgs e)
        {
            string category = comboRecordCategory.Text;
            int    expireDays;
            int    ammount;
            int    points;

            try
            {
                expireDays = Convert.ToInt32(boxRecordExpire.Text);
                errorProvider.Clear();
            }
            catch
            {
                errorProvider.SetError(boxRecordExpire, "Field must contains number");
                return;
            }

            try
            {
                ammount = Convert.ToInt32(boxRecordAmmount.Text);
                errorProvider.Clear();
            }
            catch
            {
                errorProvider.SetError(boxRecordAmmount, "Field must contains number");
                return;
            }

            try
            {
                points = Convert.ToInt32(boxRecordPoints.Text);
                errorProvider.Clear();
            }
            catch
            {
                errorProvider.SetError(boxRecordPoints, "Field must contains number");
                return;
            }


            //vytvorit novy zaznam
            Record record = new Record();

            record.Ammount     = ammount;
            record.PointsTaken = points;
            record.DateOfEntry = DateTime.Now;
            record.ExpireDate  = record.DateOfEntry.AddDays(expireDays);

            if (checkBoxPaid.Checked)
            {
                record.PaidDate = DateTime.Now;
            }
            else
            {
                record.PaidDate = null;
            }
            record.driverID   = driverID;
            record.employeeID = manager.login;
            record.fineTypeID = (int)comboRecordCategory.SelectedValue;


            RecordDataMapper.Save(record);


            if (record.PointsTaken > 0)
            {
                //odebrat body ridici
                Driver driver = DriverDataMapper.FindByID(record.driverID);
                driver.SubtractPoints(record.PointsTaken);
                DriverDataMapper.Update(driver);


                if (driver.PointsLessThenZero())
                {
                    string message = "Body ridice <= 0. Odebrat RP";
                    MessageBox.Show(message, "Upozornění", MessageBoxButtons.OK);
                }
            }

            this.Owner.Refresh();
            this.Close();
        }
Exemplo n.º 4
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            int login = -1;

            try
            {
                login = Convert.ToInt32(loginBox.Text);
            }
            catch
            {
                errorProvider.SetError(loginBox, "Wrong credentials");
            }

            string   password = passBox.Text;
            Employee employee = null;
            Driver   driver   = null;

            driver = DriverDataMapper.FindByLicenseNumber(login);
            if (driver == null)
            {
                employee = EmployeeDataMapper.FindByID(login);
            }

            if (driver != null)
            {
                if (driver.Password == password)
                {
                    //prihlasen ridic
                    manager.login    = login;
                    manager.password = password;
                    manager.userType = "driver";

                    DriverProfile form = new DriverProfile();
                    form.Show();
                    this.Hide();
                }
            }
            else if (employee != null)
            {
                if (employee.Password == password)
                {
                    //prihlasen zamestnanec
                    manager.login    = login;
                    manager.password = password;
                    manager.userType = "employee";

                    EmployeeInterfaceForm form = new EmployeeInterfaceForm();
                    form.Show();
                    this.Hide();
                }
            }
            else
            {
                errorProvider.SetError(loginBox, "Wrong credentials");
                errorProvider.SetError(passBox, "Wrong credentials");
                return;
            }


            //EmployeeInterfaceForm form = new EmployeeInterfaceForm();
            //form.Show();
            //this.Hide();
        }
        public IActionResult AutomatickeVytvoreni(string SPZ, int speed, bool isInCity)
        {
            Vehicle vehicle = VehicleDataMapper.FindBySPZ(SPZ);

            if (vehicle == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            Driver driver = DriverDataMapper.FindByID(vehicle.driverID);

            Record record = new Record();

            record.Ammount     = 0;
            record.DateOfEntry = DateTime.Now;
            record.PaidDate    = null;
            record.ExpireDate  = record.DateOfEntry.AddDays(30);
            record.driverID    = driver.ID;
            record.PointsTaken = 0;
            record.employeeID  = 1;
            record.fineTypeID  = 6;


            if (speed < 10 && isInCity == true)
            {
                record.Ammount     = 500;
                record.PointsTaken = 0;
            }
            else if (speed >= 10 && speed < 30 && isInCity == true)
            {
                record.Ammount     = 2000;
                record.PointsTaken = 1;
            }
            else if (speed >= 30 && isInCity == true)
            {
                record.Ammount     = 5000;
                record.PointsTaken = 3;
            }
            else if (speed < 10 && isInCity == false)
            {
                record.Ammount     = 500;
                record.PointsTaken = 0;
            }
            else if (speed >= 10 && speed < 30 && isInCity == false)
            {
                record.Ammount     = 2000;
                record.PointsTaken = 2;
            }
            else if (speed >= 30 && isInCity == false)
            {
                record.Ammount     = 5000;
                record.PointsTaken = 4;
            }


            RecordDataMapper.Save(record);

            driver.RemainingPoints -= record.PointsTaken;
            if (driver.RemainingPoints <= 0)
            {
                driver.State        = false;
                ViewBag.driverState = false;
            }

            DriverDataMapper.Update(driver);

            return(RedirectToAction("Login", "Home"));
        }