private void buttonAdd_Click(object sender, EventArgs e)
        {
            string markė          = textMarkė.Text;
            string price          = textPrice.Text;
            string type           = textType.Text;
            string yearMade       = textYearMade.Text;
            string yearCar        = textYearCar.Text;
            string trademark      = textBoxTrademark.Text;
            string storehouseName = textStorehouseName.Text;

            int counter = 0;

            List <string>   outputUsers       = new List <string>();
            MySqlDataReader outputStreamUsers = Database.Select($"SELECT * FROM dalysadmin.sandėliai WHERE pavadinimas ='{storehouseName}';");

            while (outputStreamUsers.Read())
            {
                counter++;
            }
            Database.Close();
            if (counter == 0)
            {
                popup newForm = new popup("Sandėlys su tokiu pavadinimu neužregistruotas, įrašykite sandėlį kuris jau yra užregistruotas");
                newForm.ShowDialog();
            }
            else
            {
                Database.Insert($"INSERT INTO dalysadmin.dalys( markė, kaina, mašinų_dalies_tipas, gamybos_metai, mašinos_metai, prekinis_ženklas, pavadinimas) VALUES('{markė}','{price}','{type}','{yearMade}','{yearCar}','{trademark}','{storehouseName}'); ");
                Database.Close();
                popup newForm = new popup("Dalį pavyko įdėti!");
                newForm.ShowDialog();
                counter = 0;
            }
        }
        private void buttonRegistr_Click(object sender, EventArgs e)
        {
            string storeHouseID        = textBoxStorehouseId.Text;
            string storehouseName      = textBoxStorehouseName.Text;
            string storehouseStock     = textBoxStock.Text;
            string storehouseStockFree = textBoxStockFree.Text;

            int counter = 0;

            List <string>   outputUsers       = new List <string>();
            MySqlDataReader outputStreamUsers = Database.Select($"SELECT * FROM dalysadmin.sandeliai WHERE pavadinimas ='{storehouseName}';");

            while (outputStreamUsers.Read())
            {
                counter++;
            }
            Database.Close();
            if (counter != 0)
            {
                popup newForm = new popup("Sandėlys su tokiu pavadinimu jau užregistruotas");
                newForm.ShowDialog();
            }
            else
            {
                Database.Insert($"INSERT INTO dalysadmin.sandeliai(ID, pavadinimas, laisvas_plotas, uzimtumas) VALUES('{storeHouseID}','{storehouseName}','{storehouseStockFree}','{storehouseStock}'); ");
                Database.Close();
                popup newForm = new popup("Sandėlį pavyko užregistruoti!");
                newForm.ShowDialog();
            }
        }
        private void buttonModify_Click(object sender, EventArgs e)
        {
            string          newName   = textBoxStorehouseName.Text;
            int             freeSpace = (int)numericUpDownSpace.Value;
            int             counter   = 0;
            MySqlDataReader outputStreamWarehouses = Database.Select($"SELECT * FROM dalysadmin.sandelys WHERE vidKo ='{Code}';");

            while (outputStreamWarehouses.Read())
            {
                counter++;
            }
            if (counter != 1)
            {
                popup newForm = new popup("Sandelys nerastas.");
                newForm.ShowDialog();
            }
            else
            {
                Database.Update($"UPDATE dalysadmin.sandeliai SET pavadinimas ='{newName}', laisvas_plotas ='{freeSpace}' WHERE vidKo ='{Code}';");
                Database.Close();
                popup newForm = new popup("Dalis rasta ir koreguota.");
                newForm.ShowDialog();
            }
            Database.Close();
        }
        private void buttonRegistr_Click(object sender, EventArgs e)
        {
            string companyName  = textBoxCompName.Text;
            string companyCode  = textBoxCompID.Text;
            string storeHouseID = textBoxStorehouseId.Text;

            int counter = 0;

            List <string>   outputUsers       = new List <string>();
            MySqlDataReader outputStreamUsers = Database.Select($"SELECT * FROM dalysadmin.imones WHERE pavadinimas ='{companyName}';");

            while (outputStreamUsers.Read())
            {
                counter++;
            }
            Database.Close();
            if (counter != 0)
            {
                popup newForm = new popup("Nurodyta įmonė jau užregistruota");
                newForm.ShowDialog();
            }
            else
            {
                Database.Insert($"INSERT INTO dalysadmin.imones(pavadinimas, san_ID, vidKo) VALUES('{companyName}','{storeHouseID}','{companyCode}'); ");
                Database.Close();
                popup newForm = new popup("Pavyko registruoti!");
                newForm.ShowDialog();
            }
        }
        private void Modify_Button_Click(object sender, EventArgs e)
        {
            string mark    = textBoxMark.Text;
            string type    = textBoxType.Text;
            int    year    = Int32.Parse(textBoxYear.Text);
            string maker   = textBoxMaker.Text;
            int    price   = Int32.Parse(textBoxPrice.Text);
            int    amount  = Int32.Parse(textBoxAmount.Text);
            string code    = textBoxCode.Text;
            int    counter = 0;

            MySqlDataReader outputStreamParts = Database.Select($"SELECT * FROM dalysadmin.dalys WHERE vidKo ='{code}';");

            while (outputStreamParts.Read())
            {
                counter++;
                Console.WriteLine(outputStreamParts["id"] + " " + outputStreamParts["marke"] + " " + outputStreamParts["vidKo"]);
            }
            if (counter != 1)
            {
                popup newForm = new popup("Dalis nerasta.");
                newForm.ShowDialog();
            }
            else
            {
                Database.Update($"UPDATE dalysadmin.dalys SET marke ='{mark}', tipas ='******', gamybos_metai ='{year}', gamintojas ='{maker}', kaina ='{price}' WHERE vidKo ='{code}';");
                Database.Close();
                popup newForm = new popup("Dalis rasta ir koreguota.");
                newForm.ShowDialog();
            }
            Database.Close();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            string newPass     = textBoxNewPass.Text;
            string newPassConf = textBoxNewPassConfirm.Text;
            string oldpass     = textBoxOldPass.Text;

            StreamReader input            = new StreamReader("logins.txt");
            string       usernameInternal = input.ReadLine();

            input.Close();

            if (newPass == newPassConf)
            {
                Database.Update($"UPDATE dalysadmin.vartotojai SET slaptazodis = '{Database.Encrypt(newPass)}' WHERE vardas='{usernameInternal}' AND slaptazodis = '{Database.Encrypt(oldpass)}';");

                StreamWriter clear = new StreamWriter("logins.txt");
                clear.Close();

                this.Hide();
                Login newForm = new Login();
                newForm.ShowDialog();
                this.Close();
            }
            else
            {
                popup newForm = new popup("Nauji slaptažodžiai nesutampa.");
                newForm.ShowDialog();
            }
        }
Пример #7
0
        private void Delete_Button_Click(object sender, EventArgs e)
        {
            string code    = textBoxCode.Text;
            int    counter = 0;

            MySqlDataReader outputStreamParts = Database.Select($"SELECT * FROM dalysadmin.dalys WHERE vidKo ='{code}';");

            while (outputStreamParts.Read())
            {
                counter++;
            }
            if (counter < 1)
            {
                popup newForm = new popup("Tokia dalis neegzistuoja. \n" + "Patikrinkite vidinį kodą");
                newForm.ShowDialog();
            }
            else if ((int)outputStreamParts["kiekis"] > 0)
            {
                popup newForm = new popup("Dalies negalima pašalinti, kadangi jos kiekis nėra lygus 0. \n" + "Koreguokite dalies kiekį skiltyje Koreguoti dalį");
                newForm.ShowDialog();
            }
            else
            {
                outputStreamParts = Database.Select($"DELETE * FROM dalysadmin.dalys WHERE vidKo ='{code}';");
                popup newForm = new popup("Dalis buvo sėkmingai pašalinta.");
                newForm.ShowDialog();
            }
        }
        private void buttonRegistr_Click(object sender, EventArgs e)
        {
            string username = textBoxUserName.Text;
            string email    = textBoxEmail.Text;
            string phone    = textBoxPhoneNumber.Text;
            string company  = textBoxCompanyName.Text;
            string oldpass  = textBoxOldPass.Text;

            StreamReader input            = new StreamReader("logins.txt");
            string       usernameInternal = input.ReadLine();

            input.Close();
            Console.WriteLine(usernameInternal);
            if (oldpass != null && oldpass != "")
            {
                Database.Update($"UPDATE dalysadmin.vartotojai SET vardas='{username}', elPastas='{email}', telNr = '{phone}', imonesPavad = '{company}' WHERE vardas='{usernameInternal}' AND slaptazodis = '{Database.Encrypt(oldpass)}';");
                Database.Close();

                StreamWriter clear = new StreamWriter("logins.txt");
                clear.Close();

                this.Hide();
                Login newForm = new Login();
                newForm.ShowDialog();
                this.Close();
            }
            else
            {
                popup newForm = new popup("Įveskite savo slaptažodį.");
                newForm.ShowDialog();
            }
        }
        private void Add_Button_Click(object sender, EventArgs e)
        {
            string                      code              = textBoxCode.Text;
            int                         counter           = 0;
            MySqlDataReader             outputStreamParts = Database.Select($"SELECT * FROM dalysadmin.dalys WHERE vidKo ='{code}'");
            Dictionary <string, string> outputParts       = new Dictionary <string, string>();

            while (outputStreamParts.Read())
            {
                counter++;
                Console.WriteLine(outputStreamParts["id"] + " " + outputStreamParts["marke"] + " " + outputStreamParts["vidKo"]);
                outputParts.Add(outputStreamParts["id"].ToString(), outputStreamParts["vidKo"].ToString());
            }

            if (counter == 0)
            {
                popup newForm = new popup("Dalis nerasta.");
                newForm.ShowDialog();
            }
            else
            {
                Database.Delete($"DELETE FROM dalysadmin.dalys WHERE vidKo = '{code}';");
                Database.Close();
                popup newForm = new popup("Dalis pašalinta.");
                newForm.ShowDialog();
            }
        }
Пример #10
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            string userName = textBoxUserName.Text;
            string password = textBoxPassword.Text;
            int    counter  = 0;
            List <Tuple <string, string, string> > output = new List <Tuple <string, string, string> >();
            MySqlDataReader outputStream = Database.Select($"SELECT * FROM dalysadmin.vartotojai WHERE vardas ='{userName}' AND slaptazodis ='{Database.Encrypt(password)}';");

            while (outputStream.Read())
            {
                counter++;
                //Console.WriteLine(outputStream["id"] + " " + outputStream["vardas"] + " " + outputStream["slaptazodis"]);
                output.Add(new Tuple <string, string, string>(outputStream["vardas"].ToString(), outputStream["slaptazodis"].ToString(), outputStream["id"].ToString()));
            }
            Database.Close();
            if (counter == 1)
            {
                if (output[0].Item1 == userName && output[0].Item2 == Database.Encrypt(password))
                {
                    //StreamWriter activate = new StreamWriter("logins.txt");
                    Database.Activate(userName, output[0].Item3);
                    //activate.WriteLine(userName);
                    //activate.WriteLine(output[0].Item3);
                    //activate.Close();

                    //Console.WriteLine("pavyko");
                    this.Hide();
                    Main newForm = new Main();
                    newForm.ShowDialog();
                    this.Close();
                }
                else
                {
                    popup newForm = new popup("Neteisingas slaptažodis arba prisijungimo vardas.");
                    newForm.ShowDialog();
                    //Console.WriteLine("nepavyko");
                }
            }
            else if (counter == 0)
            {
                popup newForm = new popup("Prašau įveskite tinkamą vartotojo vardą ir slaptažodį.");
                newForm.ShowDialog();
                Console.WriteLine($"counter = {counter}");
            }
            else
            {
                popup newForm = new popup("Duplikuotos paskyros. Prašau susisiekite su administratoriumi.");
                newForm.ShowDialog();
                Console.WriteLine($"counter = {counter}");
            }
            Database.Close();
        }
        private void buttonDelete_Click(object sender, EventArgs e)
        {
            int    storeHouseID                   = int.Parse(textBoxStorehouseId.Text);
            string storehouseName                 = textBoxStorehouseName.Text;
            int    counter                        = 0;
            Dictionary <int, string> output       = new Dictionary <int, string>();
            MySqlDataReader          outputStream = Database.Select($"SELECT * FROM dalysadmin.sandeliai WHERE ID ='{storeHouseID}' AND pavadinimas ='{storehouseName}';");

            while (outputStream.Read())
            {
                counter++;
                Console.WriteLine((int)outputStream["ID"] + " " + outputStream["pavadinimas"]);
                output.Add((int)outputStream["ID"], outputStream["pavadinimas"].ToString());

                /*                counter++;
                 * Console.WriteLine((int)outputStream["ID"] + " " + outputStream["pavadinimas"]);
                 * output.Add((int)outputStream["ID"], outputStream["pavadinimas"].ToString());*/
            }
            //     outputStream = Database.Select($"DELETE * FROM dalysadmin.sandeliai WHERE ID ='{storeHouseID}' AND pavadinimas ='{storehouseName}';");
            Database.Close();
            if (counter > 0)
            {
                if (checkBoxDeleteParts.Checked && output.ElementAt(0).Value == storehouseName)
                {
                    outputStream = Database.Select($"DELETE FROM dalysadmin.sandeliai WHERE ID ='{storeHouseID}' AND pavadinimas ='{storehouseName}';");
                    outputStream = Database.Select($"DELETE FROM dalysadmin.dalys WHERE vidKo ='{storeHouseID}';");

                    popup newForm = new popup("Sandėlys ir jame buvusios dalys buvo sėkmingai pašalinti iš duomenų bazės.");
                    newForm.ShowDialog();
                }
                //output.ElementAt(0).Key == storeHouseID )
                else if (output.ElementAt(0).Value == storehouseName)
                {
                    outputStream = Database.Select($"DELETE FROM dalysadmin.sandeliai WHERE ID ='{storeHouseID}' AND pavadinimas ='{storehouseName}';");
                    popup newForm = new popup("Sandėlys buvo sėkmingai pašalintas iš duomenų bazės.");

                    /*//Console.WriteLine("pavyko");
                     * this.Hide();
                     * Main newForm = new Main();
                     * newForm.ShowDialog();
                     * this.Close();*/
                }
            }
            else if (counter == 0)
            {
                popup newForm = new popup("Prašau įveskite tinkamą sandėlio pavadinimą arba ID.");
                newForm.ShowDialog();
                Console.WriteLine($"counter = {counter}");
            }
        }
        private void buttonRegistr_Click(object sender, EventArgs e)
        {
            //string storeHouseID = textBoxStorehouseId.Text;
            string storehouseName = textBoxStorehouseName.Text;
            //string storehouseStock = textBoxStock.Text;
            string storehouseStockFree = textBoxStockFree.Text;
            string internalCode        = textBoxCode.Text;

            int counter = 0;

            //List<string> outputUsers = new List<string>();
            MySqlDataReader outputStreamWarehouses1 = Database.Select($"SELECT * FROM dalysadmin.sandeliai WHERE pavadinimas ='{storehouseName}';");

            while (outputStreamWarehouses1.Read())
            {
                counter++;
            }
            Database.Close();
            if (counter != 0)
            {
                popup newForm = new popup("Sandėlys su tokiu pavadinimu jau užregistruotas");
                newForm.ShowDialog();
            }
            else
            {
                Console.WriteLine("E");
                counter = 0;
                MySqlDataReader outputStreamWarehouses2 = Database.Select($"SELECT * FROM dalysadmin.sandeliai WHERE vidKo ='{internalCode}';");

                while (outputStreamWarehouses2.Read())
                {
                    counter++;
                }
                Database.Close();

                if (counter != 0)
                {
                    popup newForm = new popup("Sandėlys su tokiu vidiniu kodu jau užregistruotas");
                    newForm.ShowDialog();
                }
                else
                {
                    Database.Insert($"INSERT INTO dalysadmin.sandeliai(prekes, pavadinimas, laisvas_plotas, uzimtumas, vidKo, vartotojoID) " +
                                    $"VALUES('', '{storehouseName}','{storehouseStockFree}', 0, '{internalCode}', '{Database.GetUserID()}'); ");
                    Database.Close();
                    popup newForm = new popup("Sandėlį pavyko užregistruoti!");
                    newForm.ShowDialog();
                }
            }
        }
        private void Add_Button_Click(object sender, EventArgs e)
        {
            if (textBoxCode.Text == "")
            {
                popup newForm = new popup("Prašau sugeneruokite kodą.");
                newForm.ShowDialog();
            }
            else
            {
                string mark    = textBoxMark.Text;
                string type    = textBoxType.Text;
                int    year    = Int32.Parse(textBoxYear.Text);
                string maker   = textBoxMaker.Text;
                int    price   = Int32.Parse(textBoxPrice.Text);
                int    amount  = Int32.Parse(textBoxAmount.Text);
                string code    = textBoxCode.Text;
                int    counter = 0;

                MySqlDataReader             outputStreamParts = Database.Select($"SELECT * FROM dalysadmin.dalys WHERE vidKo ='{code}'");
                Dictionary <string, string> outputParts       = new Dictionary <string, string>();
                while (outputStreamParts.Read())
                {
                    counter++;
                    Console.WriteLine(outputStreamParts["id"] + " " + outputStreamParts["marke"] + " " + outputStreamParts["vidKo"]);
                    outputParts.Add(outputStreamParts["id"].ToString(), outputStreamParts["vidKo"].ToString());
                }
                Database.Close();
                if (counter != 0)
                {
                    popup newForm = new popup("Ši dalis jau egzistuoja.");
                    newForm.ShowDialog();
                }
                else
                {
                    Database.Insert($"INSERT INTO dalysadmin.dalys(marke, tipas, gamybos_metai, gamintojas, kaina, vidKo) VALUES('{mark}','{type}','{year}','{maker}','{price}','{code}'); ");
                    popup newForm = new popup("Dalis pridėta.");
                    newForm.ShowDialog();
                }
            }
        }
        private void buttonRegistr_Click(object sender, EventArgs e)
        {
            string companyName = textBoxCompName.Text;
            string companyCode = textBoxCompID.Text;
            string email       = textBoxEmail.Text;
            string username    = textBoxUsrName.Text;
            string password    = Database.Encrypt(textBoxPsw.Text);
            string confirm     = Database.Encrypt(textBoxCnfPsw.Text);
            string phone       = textBoxTel.Text;
            int    counter     = 0;
            Dictionary <string, string> outputCompanies = new Dictionary <string, string>();

            if (password == confirm)
            {
                MySqlDataReader outputStreamCompany = Database.Select($"SELECT * FROM dalysadmin.imones WHERE pavadinimas ='{companyName}' AND vidKo = '{companyCode}';");
                while (outputStreamCompany.Read())
                {
                    counter++;
                    Console.WriteLine(outputStreamCompany["id"] + " " + outputStreamCompany["pavadinimas"] + " " + outputStreamCompany["vidKo"]);
                    outputCompanies.Add(outputStreamCompany["pavadinimas"].ToString(), outputStreamCompany["vidKo"].ToString());
                }
                Database.Close();
                if (counter == 0)
                {
                    if (MessageBox.Show("Jūsų nurodyta įmonė nerasta. Ar norite pridėti naują įmonę su įvestais duomenimis?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        Database.Insert($"INSERT INTO dalysadmin.imones(pavadinimas, san_ID, vidKo) VALUES('{companyName}','UNUSED','{companyCode}');");
                        popup newForm = new popup("Įmonė įregistruota. Galite testi vartotojo paskyros registraciją.");
                        newForm.ShowDialog();
                    }
                }
                else if (counter == 1)
                {
                    //Console.WriteLine("imone rasta");
                    counter = 0;
                    List <string>   outputUsers       = new List <string>();
                    MySqlDataReader outputStreamUsers = Database.Select($"SELECT * FROM dalysadmin.vartotojai WHERE vardas ='{username}';");
                    while (outputStreamUsers.Read())
                    {
                        counter++;
                        //outputUsers.Add(outputStreamCompany["vardas"].ToString());
                    }
                    Database.Close();
                    if (counter != 0)
                    {
                        popup newForm = new popup("Nurodytas vartotojas jau egzistuoja.");
                        newForm.ShowDialog();
                        //Console.WriteLine("toks vartotojas jau egzistuoja");
                    }
                    else
                    {
                        Database.Insert($"INSERT INTO dalysadmin.vartotojai(vardas, slaptazodis, telNr, elPastas, imonesPavad) VALUES('{username}','{password}','{phone}','{email}','{companyName}'); ");

                        //Console.WriteLine("pavyko registruoti");
                        Database.Close();
                        popup newForm = new popup("Pavyko registruoti!");
                        newForm.ShowDialog();
                    }
                }
                else
                {
                    popup newForm = new popup("imoniu per daug! susisiekite su administratoriumi.");
                    newForm.ShowDialog();
                    //Console.WriteLine("imoniu per daug! susisiekite su administratoriumi");
                }
            }
            else
            {
                popup newForm = new popup("Slaptažodžiai nesutampa.");
                newForm.ShowDialog();
            }
        }