Ejemplo n.º 1
0
        public static int InsertUser(string firstname, string lastname, string birthday,
                                     string phonenumber, string email, string gender, string city,
                                     string street, string login, string type)
        {
            db = new Database();
            db.Connect();

            Address a = new Address(city, street);

            AddressTable.Insert(a);
            a.Id = AddressTable.SelectMaxId(db);

            Person p = new Person(firstname, lastname, birthday, phonenumber, email, gender, a, a.Id);

            PersonTable.Insert(p);
            p.Id = PersonTable.SelectMaxId(db);

            User u = new User(login, type, p, p.Id);

            u.Id = UserTable.SelectMaxId(db);

            int uAdded = UserTable.Insert(u, db);

            db.Close();

            return(uAdded);
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Do you really want to add this player?", "", MessageBoxButtons.YesNo))
            {
                Person p   = new Person();
                var    tmp = PersonTable.Select();
                try
                {
                    p.Id         = tmp.Count + 1;
                    p.First_Name = textBox1.Text;
                    p.Last_Name  = textBox5.Text;
                    p.Birth_Date = Int32.Parse(textBox4.Text);
                    if (comboBoxRole.SelectedIndex == -1)
                    {
                        MessageBox.Show("ROLE MUST BE CHOSEN!\nClick on the role to chose it\nThe role name must be in blue in order to be chosen sucessfully\n", "", MessageBoxButtons.OK);
                        return;
                    }
                    p.Role = comboBoxRole.Items[comboBoxRole.SelectedIndex].ToString();


                    if (p.First_Name.Length > 30 || p.Last_Name.Length > 30 || p.Birth_Date > 2300 || p.Birth_Date < 1800)
                    {
                        throw new Exception();
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("WRONG FORMAT OF INPUT!\nBoth name and last name can be max 30 chars long\nBirth year must be realistic\n", "", MessageBoxButtons.OK);
                    return;
                }



                if (comboBoxTeam.SelectedIndex == -1)
                {
                    MessageBox.Show("TEAM NOT CHOSEN!\nClick on the team name to chose it\n", "", MessageBoxButtons.OK);
                    return;
                }
                Team t = new Team();
                t.Id      = comboBoxTeam.SelectedIndex + 1;
                p.Team_Id = t;



                if (comboBoxGame.SelectedIndex == -1)
                {
                    MessageBox.Show("GAME NOT CHOSEN!\nClick on the game name to chose it\n", "", MessageBoxButtons.OK);
                    return;
                }
                Game g = new Game();
                g.Id      = comboBoxGame.SelectedIndex + 1;
                p.Game_Id = g;

                PersonTable.Insert(p);
                this.Close();
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Database db = new Database();

            db.Connect();


            Address a1 = new Address("Žilina", "Fatranská 6");
            Address a2 = new Address("Martin", "Martinská 6");
            //AddressTable.Insert(a1, db);
            //AddressTable.Insert(a2, db);

            Person p1 = new Person(generateString(8), generateString(8), null, "+421" + generateString(9),
                                   generateString(4) + "@email.com", "Muz", a1, a1.Id);

            PersonTable.Insert(p1);

            //Person p1 = new Person("Lukáš","Paučin","1996-06-19", "+)

            /*
             * Person p1 = new Person();
             * p1.Id = 1;
             * p1.FirstName = "Lukáš";
             * p1.LastName = "Paučin";
             * p1.BirthDay = null;
             * p1.PhoneNumber = "+421521645";
             * p1.Email = "*****@*****.**";
             * p1.Gender = "Muz";
             * p1.Address = a1;
             * p1.AddressId = a1.Id;
             *
             * PersonTable.Insert(p1, db);
             */

            db.Close();
        }
Ejemplo n.º 4
0
        private void Button_insert_Click(object sender, EventArgs e)
        {
            if (TextBox_name.Text == "" || textBox_Birth_city.Text == "" || textBoxTIN.Text == "" || textBoxSSN.Text == "" || textBoxAddress.Text == "" || textBoxROOM.Text == "")
            {
                MessageBox.Show("Az össszes mező kitöltése kötelező!");
            }
            else
            {
                string[] BirthDate = Convert.ToString(dateTime_BirthDate.Value).Split('.');
                string[] check_in  = Convert.ToString(dateTime_check_in.Value).Split('.');
                string[] check_out = Convert.ToString(dateTime_check_out.Value).Split('.');


                Person person = new Person(TextBox_name.Text, textBoxTIN.Text, textBoxSSN.Text, textBoxAddress.Text, BirthDate[0] + "-" + BirthDate[1] + "-" + BirthDate[2], textBox_Birth_city.Text, "F", check_out[0] + "-" + check_out[1] + "-" + check_out[2], check_in[0] + "-" + check_in[1] + "-" + check_in[2], int.Parse(textBoxROOM.Text));
                manager_studentsTable.Insert(person);
                Button_view_Click(sender, e);
                TextBox_name.Clear();
                textBox_Birth_city.Clear();
                textBoxTIN.Clear();
                textBoxSSN.Clear();
                textBoxAddress.Clear();
                textBoxROOM.Clear();
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            Database db = new Database();

            db.Connect();


            /***1.1 Vloženie užívateľa***/
            Address a1 = new Address("Bratislava", "Lomnická 9");

            AddressTable.Insert(a1);
            a1.Id = AddressTable.SelectMaxId(db);

            Person p1 = new Person("Lukáš", "Náhodný", "1996-10-12", "+421" + RandomString("number", 9),
                                   RandomString("word", 5) + "@email.com", "muz", a1, a1.Id);

            PersonTable.Insert(p1);
            p1.Id = PersonTable.SelectMaxId(db);


            User u1 = new User((p1.LastName.Substring(0, 3) + RandomString("number", 4)).ToLower(),
                               "courier", p1, p1.Id);

            UserTable.Insert(u1);
            u1.Id = UserTable.SelectMaxId(db);



            /***1.2 Aktualizácia užívateľa***/
            p1.LastName = "Aktualizovaný";
            PersonTable.Update(p1);
            u1.Login = (p1.LastName.Substring(0, 3) + RandomString("number", 4)).ToLower();
            UserTable.Update(u1);


            /***1.3 Zrušenie užívateľa**/
            //int UserToDelete = 15;
            //UserTable.Delete(UserToDelete);
            //PersonTable.Delete(UserToDelete);
            //Console.WriteLine("User with ID " + UserToDelete + " has been deleted." );
            //Console.WriteLine(" ");

            List <Shipment> Shipments2 = ShipmentTable.SelectAllShipments(db);

            foreach (var shipment in Shipments2)
            {
                Console.WriteLine(shipment.Id);
            }

            /*List<Shipment> ShipmentsD = ShipmentTable.SelectShipmentDetail(21,db);
             *
             * foreach (var shipment in ShipmentsD)
             * {
             *  Console.WriteLine(shipment.Id.ToString() +  shipment.Type + " " + shipment.Price + " " + shipment.DeliveryPrice + " " +
             *      shipment.Weight + " " + shipment.OrderTime + " " + shipment.DeliveryTime);
             * }*/


            /**1.4 Zoznam užívateľov**/
            List <User> Users = UserTable.SelectUsers(db);

            Console.WriteLine("(1.4)User list");

            foreach (var user in Users)
            {
                Console.WriteLine("  " + user.Id + "  " + user.Person.FullName + " " + user.Login + "   " +
                                  user.Type + " " + user.Person.Email + " " + user.Person.Address.City + "...");
            }
            Console.WriteLine(" ");


            /***1.5 Detail užívateľa***/
            User UserDetail = UserTable.SelectUser(p1.Id, db);

            Console.WriteLine("(1.5)User detail with ID: " + p1.Id + " " + UserDetail.Person.FullName + " " +
                              UserDetail.Login + " " + UserDetail.Type + " " + UserDetail.Person.Address.City + "....");
            Console.WriteLine(" ");


            /***2.1 Zoznam neskoro doručených zásielok (podľa id kuriéra)***/
            int             CourierToCheckId = 3;
            List <Shipment> LateShipments    = ShipmentTable.SelectLateShipmentsByCourierId(CourierToCheckId, db);

            Console.WriteLine("(2.1)Late shipments by courier id");

            foreach (var shipment in LateShipments)
            {
                Console.WriteLine(" " + shipment.Id.ToString() + " with " + shipment.Delay.ToString() + " day(s) delay. " + "Delivered " +
                                  shipment.Delivered + " instead of " + shipment.DeliveryTime);
            }
            Console.WriteLine(" ");


            /***2.2 Ukončené zásielky***/
            string StateToCheck = "zrusena zakaznikom"; /*vyzdvihnuta, nevyzdvihnuta*/

            ;           List <Shipment> DoneShipments = ShipmentTable.SelectDoneShipmentsByState(StateToCheck, db);
            Console.WriteLine("(2.2)Done shipments by state");

            foreach (var shipment in DoneShipments)
            {
                Console.WriteLine(" " + shipment.Id + " done at " + shipment.DoneAt);
            }
            Console.WriteLine(" ");


            /***2.3 Nedoručené zásielky***/
            int             IdOfCourierChecking = 5;
            List <Shipment> NotDoneShipments    = ShipmentTable.SelectNotDoneShipmentsByCourierId(IdOfCourierChecking, db);

            Console.WriteLine("(2.3)My shipments to deliver");

            foreach (var shipment in NotDoneShipments)
            {
                Console.WriteLine(" " + shipment.Id + " should be delivered at " + shipment.DeliveryTime +
                                  " to " + shipment.Person.FullName);
            }
            Console.WriteLine(" ");


            /***2.4 Počet jednotlivých zásielok pre ich stavy (u každého kuriéra)***/
            List <User> ShipmentsByState = ShipmentTable.SelectShipmentsByState(db);

            Console.WriteLine("(2.4)Shipment count by its state with courierID");
            Console.WriteLine(" " + "Courier ID" + "   Picked   Not Picked   Canceled   On way");

            foreach (var user in ShipmentsByState)
            {
                Console.WriteLine("      " + user.Id + "         " + user.CourPicked + "         " + user.CourNotPicked
                                  + "            " + user.CourCanceled + "         " + user.CourOnWay);
            }
            Console.WriteLine(" ");


            /***2.5 Aktuálne meškajúce zásielky (kuriéra)***/
            List <Shipment> CurrLateShipments = ShipmentTable.SelectCurrLateShipmentsByCourierId(7, db);

            Console.WriteLine("(2.5)My currently late shipments");

            foreach (var shipment in CurrLateShipments)
            {
                Console.WriteLine(" " + shipment.Id + " should be delivered " + shipment.Delay + " day(s) ago.");
            }
            Console.WriteLine(" ");

            /***3.3 Vloženie novej zásielky a automatická aktualizácia cien a váhy***/
            Console.WriteLine("(3.3)Adding new shipment...");
            Person p2 = new Person("Neregistrovaný", "Užívateľ", "1996-10-12", "+421" + RandomString("number", 9),
                                   RandomString("word", 5) + "@email.com", "muz", a1, a1.Id);

            PersonTable.Insert(p2);
            p2.Id = PersonTable.SelectMaxId(db);

            string productIds            = "4,5,6"; /* ID produtkov, ktoré si užívateľ vyberie v rozhraní*/;
            String CreateAndUpdateResult = ShipmentTable.CreateAndUpdateShipment("Test funkcie 3.3.", p2.Id, 1, 4, 2, productIds, db);

            Console.WriteLine(CreateAndUpdateResult);
            Console.WriteLine(" ");

            /***3.4 Automatická aktualizácia ceny doručenia pri oneskorenom doručení a upozornenie zákazníka o tejto udalosti***/
            Console.WriteLine("(3.4)Updating shipment delivery prices and sending notifications...");
            Console.WriteLine(ShipmentTable.LateShipNotificationAndUpdate("Ospravedlňujeme sa za meškanie vašej zásielky.", db));
            Console.WriteLine(" ");

            /***3.5 História a pohyb zásielky***/
            String Updated = ShipmentTable.HistoryAndMovement(11122, "zrusena zakaznikom", 4, db);

            Console.WriteLine("(3.5) " + Updated);

            Console.ReadLine();


            db.Close();
        }