Example #1
0
 public FormNewUser(int userId = -1)
 {
     InitializeComponent();
     this.userId = userId;
     this.dbModel = new DatabaseModel();
     this.LoadData();
     if (this.userId != -1) {
         var result = dbModel.user_data.Find(this.userId);
         if (result != null) {
             this.textBoxLogin.Text = result.login;
             this.textBoxPassword.Text = result.password;
             this.textBoxName.Text = result.first_name;
             this.textBoxSurname.Text = result.last_name;
             this.textBoxAddress.Text = result.address;
             this.textBoxTelephoneNum.Text = result.phone;
             this.textBoxEmail.Text = result.email;
             this.comboBoxShowroomAssignment.SelectedIndex = this.comboBoxShowroomAssignment.FindStringExact(result.car_shop.name);
             foreach (var role in result.role) {
                 if (role.name.Equals("administrator"))
                     this.checkBoxAdministrator.Checked = true;
                 else if (role.name.Equals("sprzedawca"))
                     this.checkBoxSeller.Checked = true;
                 else if (role.name.Equals("serwisant"))
                     this.checkBoxTechnician.Checked = true;
                 else if (role.name.Equals("kierownik salonu"))
                     this.checkBoxShowroomManager.Checked = true;
             }
         }
     }
 }
 private void buttonAccept_Click(object sender, EventArgs e)
 {
     int user_id = UserSingleton.Instance.userId;
     var login = textBoxLogin.Text;
     var pass = textBoxPassword.Text;
     var newPass1 = textBoxNewPassword1.Text;
     var newPass2 = textBoxNewPassword2.Text;
     if (newPass1 == newPass2)
     {
         var dbModel = new DatabaseModel();
         var result = dbModel.user_data.Find(user_id);
         if (result != null)
         {
             if (login == result.login && pass == result.password)
             {
                 result.password = newPass1;
                 dbModel.SaveChanges();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Nieprawidłowy login i/lub hasło.\nOsoba zalogowana może zmienić hasło tylko sobie.");
             }
         }
         else
         {
             MessageBox.Show("Sprawdź połaczenie z internetem.");
         }
     }
     else
     {
         MessageBox.Show("Nowe hasło w obu polach musi być jednakowe.");
     }
 }
 private void FormServiceOptions_Load(object sender, EventArgs e)
 {
     var dbModel = new DatabaseModel();
     var services = dbModel.dict_service.SqlQuery("SELECT * FROM dict_service;").ToList();
     foreach (var service in services) {
         this.listBoxAvailableOptions.Items.Add(service.name);
         this.listBoxPriceAvailable.Items.Add(service.cost);
     }
 }
Example #4
0
 private void buttonCancel_Click(object sender, EventArgs e)
 {
     if(row != null){
         var dbModel = new DatabaseModel();
         var reservation = dbModel.reservation.Find((int)row.Cells["idDataGridViewTextBoxColumn"].Value);
         dbModel.reservation.Remove(reservation);
         dbModel.SaveChanges();
         this.buttonFilter_Click(new object(), new EventArgs());
     }
 }
Example #5
0
 private void buttonHire_Click(object sender, EventArgs e)
 {
     if (row != null) {
         var id = row.Cells["idDataGridViewTextBoxColumn"].Value.ToString();
         var dbModel = new DatabaseModel();
         var user = dbModel.user_data.Find(Int32.Parse(id));
         user.is_active = 1;
         dbModel.SaveChanges();
         this.buttonFilter_Click(new object(), new EventArgs());
     }
 }
 public FormClientModify(int id)
 {
     clientId = id;
     InitializeComponent();
     var dbModel = new DatabaseModel();
     var result = dbModel.client.Find(clientId);
     if (result != null)
     {
         this.textBoxName.Text = result.first_name;
         this.textBoxSurname.Text = result.last_name;
         this.textBoxAddress.Text = result.address;
         this.textBoxTelephoneNum.Text = result.phone;
         this.textBoxEmail.Text = result.email;
     }
 }
 private void buttonAccept_Click(object sender, EventArgs e)
 {
     var dbModel = new DatabaseModel();
     var result = dbModel.client.Find(clientId);
     if (result != null)
     {
         result.first_name = this.textBoxName.Text;
         result.last_name = this.textBoxSurname.Text;
         result.address = this.textBoxAddress.Text;
         result.phone = this.textBoxTelephoneNum.Text;
         result.email = this.textBoxEmail.Text;
         dbModel.SaveChanges();
         this.Close();
     }
 }
Example #8
0
 public void loadData()
 {
     DatabaseModel dbModel = new DatabaseModel();
     var salonRanking = dbModel.salon_ranking.SqlQuery("SELECT * FROM salon_ranking;").ToList();
     var ordersInProgres = dbModel.orders_in_progres.SqlQuery("SELECT * FROM orders_in_progres;").ToList();
     var cohCarRes = dbModel.client_order_history_car_res.SqlQuery("SELECT * FROM client_order_history_car_res;").ToList();
     var cohCarSell = dbModel.client_order_history_car_sell.SqlQuery("SELECT * FROM client_order_history_car_sell;").ToList();
     var cohService = dbModel.client_order_history_service.SqlQuery("SELECT * FROM client_order_history_service;").ToList();
     //var listSalonRanking = new List<string[]>();
     //var listOrdersInProgres = new List<string[]>();
     //var listCohCarRes = new List<string[]>();
     //var listCohCarSell = new List<string[]>();
     //var listCohService = new List<string[]>();
     //var listCoh = new List<string[]>();
     listSalonRanking.Add(new string[] { "Nazwa salonu", "Adres salonu", "Telefon", "Strona www", "Ilość sprzedanych samochodów" });
     listOrdersInProgres.Add(new string[] { "Numer porządkowy zamówienia", "Data rezerwacji", "Data wygaśnięcia rezerwacji", "Model samochodu", "Kolor samochodu", "Silnik samochodu",
         "Skrzynia biegów samochodu", "Paliwo samochodu", "Nadwozie samochodu", "Koszt samochodu", "Adres sklepu w którym jest samochód", "Imię klienta", "Nazwisko klienta", "Adres klienta",
         "Telefon klienta", "E-mail klienta", "Imię sprzedawcy", "Nazwisko sprzedawcy", "Telefon sprzedawcy", "E-mail sprzedawcy", "Miejce pracy sprzedawcy", "Czy zatrudniony" });
     listCohCarSell.Add(new string[] { "Numer porządkowy", "Imię", "Nazwisko", "Adres", "Telefon", "E-mail", "Data sprzedania", "Cena", "Model samochodu", "Kolor samochodu" });
     //listCohCarRes.Add(new string[] { item.first_name, item.last_name, item.address, item.phone, item.email, String.Format("{0:dd.MM.yyyy HH:mm}", item.date_reservation), String.Format("{0:dd.MM.yyyy HH:mm}", item.date_reservation_expired), item.car_model, item.car_color });
     //listCohService.Add(new string[] { item.first_name, item.last_name, item.address, item.phone, item.email, String.Format("{0:dd.MM.yyyy HH:mm}", item.date_order), item.cost, item.service, item.comment }); ;
     foreach (salon_ranking item in salonRanking)
     {
         listSalonRanking.Add(new string[] { item.name, item.address, item.phone, item.www, item.cars.ToString() });
     }
     foreach (orders_in_progres item in ordersInProgres)
     {
         listOrdersInProgres.Add(new string[] { item.order_id.ToString(), String.Format("{0:dd.MM.yyyy}", item.date_reservation), String.Format("{0:dd.MM.yyyy}",
             item.date_reservation_expired), item.car_model, item.car_color, item.car_engine, item.car_gearbox, item.car_fuel, item.car_body, item.car_cost, item.shop_address_with_car,
             item.client_first_name, item.client_last_name, item.client_address, item.client_phone, item.client_email, item.user_first_name, item.user_last_name, item.user_phone,
             item.user_email, item.shop_address_with_seller, item.user_is_active.ToString() });
     }
     foreach (client_order_history_car_sell item in cohCarSell)
     {
         listCohCarSell.Add(new string[] { item.id.ToString(), item.first_name, item.last_name, item.address, item.phone, item.email, String.Format("{0:dd.MM.yyyy}",
             item.sell_date), item.cost, item.car_model, item.car_color });
     }
     /*foreach (client_order_history_car_res item in cohCarRes)
     {
         listCohCarRes.Add(new string[] { item.first_name, item.last_name, item.address, item.phone, item.email, String.Format("{0:dd.MM.yyyy}", item.date_reservation),
             String.Format("{0:dd.MM.yyyy}", item.date_reservation_expired), item.car_model, item.car_color });
     }
     foreach (client_order_history_service item in cohService)
     {
         listCohService.Add(new string[] { item.first_name, item.last_name, item.address, item.phone, item.email, String.Format("{0:dd.MM.yyyy}", item.date_order),
             item.cost, item.service, item.comment }); ;
     }*/
 }
 private void buttonAccept_Click(object sender, EventArgs e)
 {
     if (this.client != null && this.car != null) {
         var dbModel = new DatabaseModel();
         var newReservation = new reservation();
         newReservation.date_reservation = this.dateTimePickerPurchaseDate.Value;
         newReservation.date_reservation_expired = this.dateTimePickerPurchaseDate.Value.AddDays(14);
         newReservation.id_user = UserSingleton.Instance.userId;
         newReservation.id_client = (int)this.client.Cells["idDataGridViewTextBoxColumn"].Value;
         newReservation.id_car = (int)this.car.Cells["idDataGridViewTextBoxColumn"].Value;
         dbModel.reservation.Add(newReservation);
         dbModel.SaveChanges();
     } else {
         MessageBox.Show("Musisz najpierw wybrać klienta oraz samochód.");
     }
 }
Example #10
0
 private void buttonRealize_Click(object sender, EventArgs e)
 {
     if(row != null){
         var dbModel = new DatabaseModel();
         var reservation = dbModel.reservation.Find((int)row.Cells["idDataGridViewTextBoxColumn"].Value);
         var carSell = new car_sell();
         carSell.id_car = reservation.id_car;
         carSell.id_client = reservation.id_client;
         carSell.id_user = UserSingleton.Instance.userId;
         carSell.sell_date = DateTime.Now;
         carSell.cost = Decimal.Parse(dbModel.car.Find(carSell.id_car).cost);
         dbModel.car_sell.Add(carSell);
         dbModel.reservation.Remove(reservation);
         dbModel.SaveChanges();
         this.buttonFilter_Click(new object(), new EventArgs());
     }
 }
Example #11
0
 public void loadData()
 {
     DatabaseModel dbModel = new DatabaseModel();
     var dictBody = dbModel.dict_body.SqlQuery("SELECT * FROM dict_body;").ToList();
     var dictColor = dbModel.dict_color.SqlQuery("SELECT * FROM dict_color;").ToList();
     var dictEngine = dbModel.dict_engine.SqlQuery("SELECT * FROM dict_engine;").ToList();
     var dictFuel = dbModel.dict_fuel.SqlQuery("SELECT * FROM dict_fuel;").ToList();
     var dictGearbox = dbModel.dict_gearbox.SqlQuery("SELECT * FROM dict_gearbox;").ToList();
     var dictSeries = dbModel.dict_series.SqlQuery("SELECT * FROM dict_series;").ToList();
     var dictModel = dbModel.model.SqlQuery("SELECT * FROM model;").ToList();
     var dictShop = dbModel.car_shop.SqlQuery("SELECT * FROM car_shop;").ToList();
     var listBody = new List<string>();
     var listColor = new List<string>();
     var listEngine = new List<string>();
     var listFuel = new List<string>();
     var listGearbox = new List<string>();
     var listSeries = new List<string>();
     var listModel = new List<string>();
     var listShop = new List<string>();
     listBody.Add("");
     listColor.Add("");
     listEngine.Add("");
     listFuel.Add("");
     listGearbox.Add("");
     listSeries.Add("");
     listModel.Add("");
     listShop.Add("");
     foreach (dict_body item in dictBody) { listBody.Add(item.body); }
     foreach (dict_color item in dictColor) { listColor.Add(item.color); }
     foreach (dict_engine item in dictEngine) { listEngine.Add(item.engine); }
     foreach (dict_fuel item in dictFuel) { listFuel.Add(item.fuel); }
     foreach (dict_gearbox item in dictGearbox) { listGearbox.Add(item.gearbox); }
     foreach (dict_series item in dictSeries) { listSeries.Add(item.series); }
     foreach (model item in dictModel) { listModel.Add(item.name); }
     foreach (car_shop item in dictShop) { listShop.Add(item.name); }
     this.comboBoxCarBody.DataSource = listBody;
     this.comboBoxColor.DataSource = listColor;
     this.comboBoxEngine.DataSource = listEngine;
     this.comboBoxFuel.DataSource = listFuel;
     this.comboBoxGearbox.DataSource = listGearbox;
     this.comboBoxSeries.DataSource = listSeries;
     this.comboBoxModel.DataSource = listModel;
     this.comboBoxShop.DataSource = listShop;
 }
Example #12
0
 private void buttonFilter_Click(object sender, EventArgs e)
 {
     var name = this.textBoxName.Text;
     var surname = this.textBoxSurname.Text;
     var dbModel = new DatabaseModel();
     string wherePart = " WHERE";
     if (!String.IsNullOrWhiteSpace(name))
         wherePart += " first_name like '" + name + "%'";
     if (!String.IsNullOrWhiteSpace(name) && !String.IsNullOrWhiteSpace(surname))
         wherePart += " AND";
     if (!String.IsNullOrWhiteSpace(surname))
         wherePart += " last_name like '" + surname + "%'";
     if (wherePart.Equals(" WHERE"))
         wherePart = "";
     var db = dbModel.user_data.SqlQuery("SELECT * FROM user_data" + wherePart +";").ToList();
     var source = new BindingSource();
     source.DataSource = db;
     this.dataGridViewUsers.DataSource = source;
 }
 private void buttonAccept_Click(object sender, EventArgs e)
 {
     var dbModel = new DatabaseModel();
     foreach (var service in this.selectedServices) {
         var order = new client_order();
         var serv = dbModel.dict_service.SqlQuery("SELECT * FROM dict_service WHERE name like '" + service.ToString() + "';").ToList();
         order.date_order = this.dateTimePickerPurchaseDate.Value;
         order.date_done = this.dateTimePickerPurchaseDate.Value;
         order.id_client = (int)this.client.Cells["idDataGridViewTextBoxColumn"].Value;
         order.id_service = (int)serv[0].id;
         order.id_user = UserSingleton.Instance.userId;
         order.cost = Decimal.Parse(serv[0].cost);
         order.comment = this.textBoxComment.Text;
         order.id_car_shop = dbModel.user_data.Find(UserSingleton.Instance.userId).id_car_shop;
         order.is_done = 1;
         dbModel.client_order.Add(order);
         dbModel.SaveChanges();
     }
     this.Close();
 }
        public FormAccountManagement()
        {
            InitializeComponent();
            this.panel2BackgroundLogin.Visible = false;

            int user_id = UserSingleton.Instance.userId;
            var dbModel = new DatabaseModel();
            var user = dbModel.user_data.Find(user_id);
            var shop = dbModel.car_shop.Find(user.id_car_shop);

            this.textBoxName.Text = user.first_name;
            this.textBoxSurname.Text = user.last_name;
            this.textBoxAddress.Text = user.address;
            this.textBoxTelephoneNum.Text = user.phone;
            this.textBoxEmail.Text = user.email;
            this.textBoxShop.Text = shop.name + ", " + shop.address;

            this.labelRole.Visible = false;
            this.textBoxRole.Visible = false;
        }
Example #15
0
 private void buttonLogin_Click(object sender, EventArgs e)
 {
     var dbModel = new DatabaseModel();
     var db = dbModel.user_data.SqlQuery("SELECT * FROM user_data;").ToList();
     var login = textBoxLogin.Text;
     var pass = textBoxPass.Text;
     var resultLogin = db.Find(item => item.login == login);
     var resultPass = db.Find(item => item.password == pass);
     if (resultLogin != null && resultPass != null && resultLogin.id == resultPass.id)
     {
         if (resultLogin.is_active == 1)
         {
             UserSingleton.Instance.userId = resultLogin.id;
             //var userRoles = dbModel.user_data.Find(resultLogin.id).role;
             //foreach (var userRole in userRoles) {
             //    if (userRole.name.Equals("administrator")) {
             //        UserSingleton.Instance.userRole = userRole.id;
             //        break;
             //    } else if (userRole.name.Equals("kierownik salonu") && UserSingleton.Instance.userRole != 4) {
             //        UserSingleton.Instance.userRole = userRole.id;
             //    } else if (UserSingleton.Instance.userRole != 1 && UserSingleton.Instance.userRole != 4) {
             //        UserSingleton.Instance.userRole = userRole.id;
             //    }
             //}
             FormMainView fmv = new FormMainView();
             this.Hide();
             fmv.ShowDialog();
             fmv.Activate();
             this.Close();
         }
         else
         {
             MessageBox.Show("Jesteś nieaktywnym użytkownikiem.\nSkontaktuj się z administratorem systemu.");
         }
     } else
     {
         MessageBox.Show("Błędny login lub hasło.");
     }
 }
        private void listBoxCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.labelDictionaryNewWord.Visible = true;
            this.textBoxNewDictionaryData.Visible = true;
            this.buttonAdd.Visible = true;
            this.buttonSaveAndQuit.Visible = true;
            string[] tables = {"dict_body", "dict_color", "dict_engine", "dict_fuel", "dict_gearbox", "dict_series", "dict_service", "model"};
            var selectedTable = tables[this.listBoxCategories.SelectedIndex];
            List<string> list = new List<string>();
            List<string> cost = new List<string>();
            var dbModel = new DatabaseModel();
            switch (selectedTable)
            {
                case "dict_body":
                    dictionarySettings(false, list, cost);
                    var allBody = dbModel.dict_body.SqlQuery("SELECT * FROM dict_body;").ToList();
                    foreach(dict_body item in allBody)
                    {
                        list.Add(item.body);
                    }
                    break;
                case "dict_color":
                    dictionarySettings(false, list, cost);
                    var allColor = dbModel.dict_color.SqlQuery("SELECT * FROM dict_color;").ToList();
                    foreach(dict_color item in allColor)
                    {
                        list.Add(item.color);
                    }
                    break;
                case "dict_engine":
                    dictionarySettings(false, list, cost);
                    var allEngine = dbModel.dict_engine.SqlQuery("SELECT * FROM dict_engine;").ToList();
                    foreach(dict_engine item in allEngine)
                    {
                        list.Add(item.engine);
                    }
                    break;
                case "dict_fuel":
                    dictionarySettings(false, list, cost);
                    var allFuel = dbModel.dict_fuel.SqlQuery("SELECT * FROM dict_fuel;").ToList();
                    foreach(dict_fuel item in allFuel)
                    {
                        list.Add(item.fuel);
                    }
                    break;
                case "dict_gearbox":
                    dictionarySettings(false, list, cost);
                    var allGearbox = dbModel.dict_gearbox.SqlQuery("SELECT * FROM dict_gearbox;").ToList();
                    foreach(dict_gearbox item in allGearbox)
                    {
                        list.Add(item.gearbox);
                    }
                    break;
                case "dict_series":
                    dictionarySettings(false, list, cost);
                    var allSeries = dbModel.dict_series.SqlQuery("SELECT * FROM dict_series;").ToList();
                    foreach(dict_series item in allSeries)
                    {
                        list.Add(item.series);
                    }
                    break;
                case "dict_service":
                    dictionarySettings(true, list, cost);
                    var allService = dbModel.dict_service.SqlQuery("SELECT * FROM dict_service;").ToList();
                    foreach(dict_service item in allService)
                    {
                        list.Add(item.name);
                        cost.Add(item.cost);
                    }
                    break;
                case "model":
                    dictionarySettings(false, list, cost);
                    var allModel = dbModel.model.SqlQuery("SELECT * FROM model;").ToList();
                    foreach (model item in allModel)
                    {
                        list.Add(item.name);
                    }
                    break;
                default:
                    list.Clear();
                    cost.Clear();
                    break;
            }

            this.listBoxDictionaryData.DataSource = list;
            this.listBoxCost.DataSource = cost;
        }
Example #17
0
 private void buttonFilter_Click(object sender, EventArgs e)
 {
     var dbModel = new DatabaseModel();
     var model = this.comboBoxModel.Text;
     var series = this.comboBoxSeries.Text;
     var color = this.comboBoxColor.Text;
     var engine = this.comboBoxEngine.Text;
     var gearbox = this.comboBoxGearbox.Text;
     var fuel = this.comboBoxFuel.Text;
     var body = this.comboBoxCarBody.Text;
     var priceF = this.maskedTextBoxPriceFrom.Text;
     var priceT = this.maskedTextBoxPriceTo.Text;
     var priceFrom = 0;
     Int32.TryParse(priceF, out priceFrom);
     var priceTo = 0;
     Int32.TryParse(priceT, out priceTo);
     var shop = this.comboBoxShop.Text;
     var next = false;
     string wherePart = " WHERE";
     if (!String.IsNullOrWhiteSpace(model))
     {
         wherePart += " model like '" + model + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(series))
     {
         if (next) wherePart += " AND";
         wherePart += " series like '" + series + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(color))
     {
         if (next) wherePart += " AND";
         wherePart += " color like '" + color + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(engine))
     {
         if (next) wherePart += " AND";
         wherePart += " engine like '" + engine + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(gearbox))
     {
         if (next) wherePart += " AND";
         wherePart += " gearbox like '" + gearbox + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(fuel))
     {
         if (next) wherePart += " AND";
         wherePart += " fuel like '" + fuel + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(body))
     {
         if (next) wherePart += " AND";
         wherePart += " body like '" + body + "'";
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(priceF))
     {
         if (next) wherePart += " AND";
         wherePart += " cost > " + priceFrom;
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(priceT))
     {
         if (next) wherePart += " AND";
         wherePart += " cost > " + priceTo;
         next = true;
     }
     if (!String.IsNullOrWhiteSpace(shop))
     {
         if (next) wherePart += " AND";
         wherePart += " name like '" + shop + "'";
         next = true;
     }
     if (wherePart.Equals(" WHERE"))
         wherePart = "";
     var db = dbModel.full_car.SqlQuery("SELECT * FROM full_car" + wherePart + ";").ToList();
     var source = new BindingSource();
     source.DataSource = db;
     this.dataGridViewCar.DataSource = source;
 }