示例#1
0
        /*
         * private void Scroll__ScrollChange(object sender, View.ScrollChangeEventArgs e)
         * {
         *  InputMethodManager imm = (InputMethodManager)GetSystemService(Context.InputMethodService);
         *  imm.HideSoftInputFromWindow(layout_.WindowToken, 0);
         * }
         */

        private void AddLuggage_Click(object sender, EventArgs e)
        {
            vSpinner.Clickable = false;
            if (luggage.Checked)
            {
                if (Name.Text.Trim() == String.Empty || LastName.Text.Trim() == String.Empty || Lenght.Text.Trim() == String.Empty || Height.Text.Trim() == String.Empty || Width.Text.Trim() == String.Empty || Weight.Text.Trim() == String.Empty)
                {
                    setAlert("Nie wype³niono wszystkich pól");
                }
                else
                {
                    if (counter == countOfPeople)
                    {
                        Flight f = GlobalMemory.mFlight;
                        f.CountOfClient     += countOfPeople;
                        GlobalMemory.mFlight = f;
                        double cost = Math.Round((f.Price * countOfPeople) + luggagePrice, 2);

                        //MySQLHelper.InsertReservation(GlobalMemory.m_client.ID, f.FlightID, GlobalHelper.ToJSON(clientsShort),cost,countOfPeople, connection);
                        if (MySQLHelper.InsertIntoRes(GlobalMemory.m_client.ID, f.FlightID, cost, GlobalHelper.ToJSON(clientsShort), countOfPeople, connection) == false)
                        {
                            setAlert("Brak miejsc");
                        }

                        // Metoda InsertReservation robi automatycznie update
                        //MySQLHelper.updateCountOfClient(f.FlightID, counter, connection);
                        reservationID = MySQLHelper.getResevationID(GlobalMemory.m_client.ID, f.FlightID, connection);
                        if (reservationID == -1)
                        {
                            setAlert("Error");
                        }
                        foreach (var item in luggages)
                        {
                            MySQLHelper.InsertLuggage(item, reservationID, connection);
                        }
                        this.Finish();
                    }

                    else if (counter == countOfPeople - 1)
                    {
                        counter++;
                        userToken = GlobalHelper.generateIdentify();
                        int len = Convert.ToInt32(Lenght.Text.Trim());
                        int hei = Convert.ToInt32(Height.Text.Trim());
                        int wid = Convert.ToInt32(Width.Text.Trim());
                        luggages.Add(new Luggage(len, hei, wid, Convert.ToInt32(Weight.Text.Trim()), isDanger.Checked, userToken));
                        //+50zl za niebezpieczny bagaz
                        if (isDanger.Checked)
                        {
                            luggagePrice += 50;
                            setAlert("Dodatkowy koszt za niebezpieczny baga¿: 50 z³");
                        }
                        setAlert("Koszt baga¿u: " + getLuggagePrice(len, hei, wid) + " z³");

                        luggagePrice += getLuggagePrice(len, hei, wid);
                        clientsShort.Add(new ClientShort(Name.Text.Trim(), LastName.Text.Trim(), userToken));
                        setAlert("Dodano baga¿ i osobê nr " + counter.ToString() + " Pozosta³o " + (countOfPeople - counter).ToString());
                        setBackground("#C0C0C0", false);
                        Name.SetBackgroundColor(Android.Graphics.Color.ParseColor("#C0C0C0"));
                        Name.Enabled = false;
                        LastName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#C0C0C0"));
                        LastName.Enabled = false;
                        finalPrice.Text  = "Koszt: " + String.Format("{0:N2}", (GlobalMemory.mFlight.Price * (countOfPeople) + luggagePrice)) + " z³";

                        finalPrice.Visibility = ViewStates.Visible;
                        addLuggage.Text       = "Zarezerwuj";
                    }
                    else
                    {
                        userToken = GlobalHelper.generateIdentify();
                        int len = Convert.ToInt32(Lenght.Text.Trim());
                        int hei = Convert.ToInt32(Height.Text.Trim());
                        int wid = Convert.ToInt32(Width.Text.Trim());
                        luggages.Add(new Luggage(len, hei, wid, Convert.ToInt32(Weight.Text.Trim()), isDanger.Checked, userToken));
                        //+50zl za niebezpieczny bagaz
                        if (isDanger.Checked)
                        {
                            luggagePrice += 50;
                            setAlert("Dodatkowy koszt za niebezpieczny baga¿: 50 z³");
                        }
                        setAlert("Koszt baga¿u: " + getLuggagePrice(len, hei, wid) + " z³");
                        luggagePrice += getLuggagePrice(len, hei, wid);

                        clientsShort.Add(new ClientShort(Name.Text.Trim(), LastName.Text.Trim(), userToken));
                        counter++;
                        setAlert("Dodano baga¿ i osobê nr " + counter.ToString() + " Pozosta³o " + (countOfPeople - counter).ToString());
                        txt.Text         = "   Baga¿ nr " + (counter + 1).ToString();
                        txtNames.Text    = "Imie i Nazwisko nr " + (counter + 1).ToString();
                        Name.Text        = "";
                        LastName.Text    = "";
                        Lenght.Text      = "";
                        Height.Text      = "";
                        Width.Text       = "";
                        Weight.Text      = "";
                        isDanger.Checked = false;
                    }
                }
            }
            else
            {
                if (Name.Text.Trim() == String.Empty || LastName.Text.Trim() == String.Empty)
                {
                    setAlert("Nie wypelniono wszystkich pól");
                }
                else
                if (counter == countOfPeople)
                {
                    Flight f = GlobalMemory.mFlight;
                    f.CountOfClient     += countOfPeople;
                    GlobalMemory.mFlight = f;
                    double cost = Math.Round((f.Price * countOfPeople) + luggagePrice, 2);

                    //MySQLHelper.InsertReservation(GlobalMemory.m_client.ID, f.FlightID, GlobalHelper.ToJSON(clientsShort), cost, countOfPeople, connection);
                    if (MySQLHelper.InsertIntoRes(GlobalMemory.m_client.ID, f.FlightID, cost, GlobalHelper.ToJSON(clientsShort), countOfPeople, connection) == false)
                    {
                        setAlert("Brak miejsc");
                    }

                    reservationID = MySQLHelper.getResevationID(GlobalMemory.m_client.ID, f.FlightID, connection);
                    foreach (var item in luggages)
                    {
                        MySQLHelper.InsertLuggage(item, reservationID, connection);
                    }
                    //
                    // Metoda InsertReservation robi automatycznie update
                    //MySQLHelper.updateCountOfClient(f.FlightID, counter, connection);

                    this.Finish();
                }

                else if (counter == countOfPeople - 1)
                {
                    counter++;
                    setBackground("#C0C0C0", false);
                    Name.SetBackgroundColor(Android.Graphics.Color.ParseColor("#C0C0C0"));
                    Name.Enabled = false;
                    LastName.SetBackgroundColor(Android.Graphics.Color.ParseColor("#C0C0C0"));
                    LastName.Enabled = false;

                    clientsShort.Add(new ClientShort(Name.Text.Trim(), LastName.Text.Trim(), "brak"));
                    setAlert("Dodano osobê nr " + counter.ToString() + " Pozosta³o " + (countOfPeople - counter).ToString());

                    finalPrice.Text       = "Koszt: " + String.Format("{0:N2}", (GlobalMemory.mFlight.Price * (countOfPeople)) + luggagePrice) + " z³";
                    finalPrice.Visibility = ViewStates.Visible;
                    addLuggage.Text       = "Zarezerwuj";
                }
                else
                {
                    clientsShort.Add(new ClientShort(Name.Text.Trim(), LastName.Text.Trim(), "brak"));

                    counter++;
                    setAlert("Dodano osobê nr " + counter.ToString() + " Pozosta³o " + (countOfPeople - counter).ToString());
                    txt.Text         = "   Baga¿ nr " + (counter + 1).ToString();
                    txtNames.Text    = "Imie i Nazwisko nr " + (counter + 1).ToString();
                    Name.Text        = "";
                    LastName.Text    = "";
                    Lenght.Text      = "";
                    Height.Text      = "";
                    Width.Text       = "";
                    Weight.Text      = "";
                    isDanger.Checked = false;
                }
            }
        }