Example #1
0
        public static List <Luggage> get_LuggageForReservation(int ReservationID, MySqlConnection conn)
        {
            List <Luggage> retuned   = new List <Luggage>();
            string         cmdString = "SELECT * FROM Luggage WHERE ReservationID = @thisReservationID";

            conn.Open();
            MySqlCommand cmd = new MySqlCommand(cmdString, conn);

            cmd.Parameters.AddWithValue("@thisReservationID", ReservationID);
            var result = cmd.ExecuteReader();

            while (result.Read())
            {
                Luggage luggage = new Luggage();
                luggage.LuggageID     = result.GetInt16("LuggageID");
                luggage.ReservationID = result.GetInt16("ReservationID");
                luggage.Lenght        = result.GetInt16("Length");
                luggage.Height        = result.GetInt16("Height");
                luggage.Width         = result.GetInt16("Width");
                luggage.Weight        = result.GetInt16("Weight");
                luggage.IsDangerous   = result.GetBoolean("isDangerous");
                luggage.UserToken     = result.GetString("userToken");

                retuned.Add(luggage);
            }
            conn.Close();
            return(retuned);
        }
        private bool Valid_luggage_field_if_change(View row, Helper.Luggage luggage)
        {
            bool result = false;

            if (row.FindViewById <EditText>(Resource.Id.b_dlugosc).Text != luggage.Lenght.ToString())
            {
                return(true);
            }
            if (row.FindViewById <EditText>(Resource.Id.b_wysokosc).Text != luggage.Height.ToString())
            {
                return(true);
            }
            if (row.FindViewById <EditText>(Resource.Id.b_szerokosc).Text != luggage.Width.ToString())
            {
                return(true);
            }
            if (row.FindViewById <EditText>(Resource.Id.b_waga).Text != luggage.Weight.ToString())
            {
                return(true);
            }
            if (row.FindViewById <CheckBox>(Resource.Id.is_dangerous).Checked != luggage.IsDangerous)
            {
                return(true);
            }
            return(result);
        }
 private Helper.Luggage Get_New_luggage(View row, Helper.Luggage old)
 {
     return(new Helper.Luggage()
     {
         LuggageID = old.LuggageID,
         Lenght = int.Parse(row.FindViewById <EditText>(Resource.Id.b_dlugosc).Text),
         Height = int.Parse(row.FindViewById <EditText>(Resource.Id.b_wysokosc).Text),
         Width = int.Parse(row.FindViewById <EditText>(Resource.Id.b_szerokosc).Text),
         Weight = int.Parse(row.FindViewById <EditText>(Resource.Id.b_waga).Text),
         IsDangerous = row.FindViewById <CheckBox>(Resource.Id.is_dangerous).Checked
     });
 }
        private void Set_luggage(View row, Helper.Luggage luggage)
        {
            row.FindViewById <CheckBox>(Resource.Id.isBagaz).Checked = true;

            row.FindViewById <EditText>(Resource.Id.b_dlugosc).Enabled    = true;
            row.FindViewById <EditText>(Resource.Id.b_dlugosc).Text       = luggage.Lenght.ToString();
            row.FindViewById <EditText>(Resource.Id.b_wysokosc).Enabled   = true;
            row.FindViewById <EditText>(Resource.Id.b_wysokosc).Text      = luggage.Height.ToString();
            row.FindViewById <EditText>(Resource.Id.b_szerokosc).Enabled  = true;
            row.FindViewById <EditText>(Resource.Id.b_szerokosc).Text     = luggage.Width.ToString();
            row.FindViewById <EditText>(Resource.Id.b_waga).Enabled       = true;
            row.FindViewById <EditText>(Resource.Id.b_waga).Text          = luggage.Weight.ToString();
            row.FindViewById <CheckBox>(Resource.Id.is_dangerous).Enabled = true;
            row.FindViewById <CheckBox>(Resource.Id.is_dangerous).Checked = luggage.IsDangerous;
        }
        int ChangePriceLuggage(Helper.Luggage oldLuggage, Helper.Luggage newLuggage)
        {
            int change = 0;

            int priceOld = ReserveTickets_2.getLuggagePrice(oldLuggage.Lenght, oldLuggage.Height, oldLuggage.Width);
            int priceNew = ReserveTickets_2.getLuggagePrice(newLuggage.Lenght, newLuggage.Height, newLuggage.Width);

            if (oldLuggage.IsDangerous && !newLuggage.IsDangerous)
            {
                change -= 50;
            }

            if (!oldLuggage.IsDangerous && newLuggage.IsDangerous)
            {
                change += 50;
            }

            return(change - (priceOld - priceNew));
        }
Example #6
0
        public static bool UpdateLuggage(Luggage lugagge, MySqlConnection conn)
        {
            bool returned = true;

            try
            {
                conn.Open();
                string insertLuggage = "UPDATE Luggage SET  " +
                                       "Length=@length, Height=@height, Width=@width, Weight=@weight, isDangerous=@isDanger " +
                                       "WHERE LuggageID = @this_LuggageID";

                MySqlCommand cmdLuggage = new MySqlCommand(insertLuggage, conn);


                cmdLuggage.Parameters.AddWithValue("@length", lugagge.Lenght);
                cmdLuggage.Parameters.AddWithValue("@height", lugagge.Height);
                cmdLuggage.Parameters.AddWithValue("@width", lugagge.Width);
                cmdLuggage.Parameters.AddWithValue("@weight", lugagge.Weight);
                if (lugagge.IsDangerous)
                {
                    cmdLuggage.Parameters.AddWithValue("@isDanger", 1);
                }
                else
                {
                    cmdLuggage.Parameters.AddWithValue("@isDanger", 0);
                }
                cmdLuggage.Parameters.AddWithValue("@this_LuggageID", lugagge.LuggageID);
                cmdLuggage.ExecuteNonQuery();
            }
            catch (Exception)
            {
                returned = false;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(returned);
        }
Example #7
0
        public static bool InsertLuggage(Luggage lugagge, int reservationID, MySqlConnection conn)
        {
            bool returned = true;

            try
            {
                conn.Open();
                string insertLuggage = "INSERT INTO `Luggage` (`ReservationID`,`Length`, `Height`, `Width`, `Weight`, `isDangerous`, `userToken`) VALUES (@reservationID, @length,@height,@width, @weight, @isDanger,@uToken)";

                MySqlCommand cmdLuggage = new MySqlCommand(insertLuggage, conn);

                cmdLuggage.Parameters.AddWithValue("@reservationID", reservationID);
                cmdLuggage.Parameters.AddWithValue("@length", lugagge.Lenght);
                cmdLuggage.Parameters.AddWithValue("@height", lugagge.Height);
                cmdLuggage.Parameters.AddWithValue("@width", lugagge.Width);
                cmdLuggage.Parameters.AddWithValue("@weight", lugagge.Weight);
                if (lugagge.IsDangerous)
                {
                    cmdLuggage.Parameters.AddWithValue("@isDanger", 1);
                }
                else
                {
                    cmdLuggage.Parameters.AddWithValue("@isDanger", 0);
                }
                cmdLuggage.Parameters.AddWithValue("@uToken", lugagge.UserToken);

                var r = cmdLuggage.ExecuteNonQuery();
            }
            catch (Exception)
            {
                returned = false;
            }
            finally
            {
                if (conn != null)
                {
                    conn.Close();
                }
            }
            return(returned);
        }
        private void Valid_and_update(View row, int groudPosition)
        {
            if (_actualClick == groudPosition && !_hasClicked)
            {
                _hasClicked = true;
                var result = _DataList.luggages.Find(s => s.UserToken == _DataList.details.client[groudPosition].UserToken);
                if (result != null)
                {
                    if (Valid_luggage_field(row))
                    {
                        if (!Valid_luggage_field_if_change(row, result))
                        {
                            GlobalMemory._menuPage.setAlert("Brak zmian. ");
                        }
                        else
                        {
                            var newLuggage = Get_New_luggage(row, result);
                            // Zmieniono parametry bagazu
                            Helper.MySQLHelper.UpdateLuggage(newLuggage, _obj.connection);
                            Helper.MySQLHelper.UpdatePrice((_DataList.KosztRezerwacji + ChangePriceLuggage(result, newLuggage)).ToString(), _DataList.ReservationID.ToString(), _obj.connection);


                            GlobalMemory._menuPage.setAlert("Zmieniono parametry baga¿u pomyœlnie. ");
                            _obj.Finish();
                        }
                    }
                    else
                    {
                        // usunieto bagaz
                        float newPrice = _DataList.KosztRezerwacji;
                        if (result.IsDangerous)
                        {
                            newPrice -= 50;
                        }
                        newPrice -= ReserveTickets_2.getLuggagePrice(result.Lenght, result.Height, result.Width);
                        _DataList.details.client[groudPosition].UserToken = "brak";
                        string newJSON = JsonConvert.SerializeObject(new ClientShortJSON()
                        {
                            users = _DataList.details.client.ToArray()
                        });

                        Helper.MySQLHelper.DeleteLuggageAndChangePrice(result.LuggageID.ToString(), newJSON, newPrice.ToString(), _DataList.ReservationID.ToString(), _obj.connection);
                        GlobalMemory._menuPage.setAlert("Baga¿ zosta³ usuniêty dla klienta " + _DataList.details.client[groudPosition].ToStringWithoutToken() + ".");
                        _obj.Finish();
                    }
                }
                else
                {
                    // dodano bagaz
                    if (Valid_luggage_field(row))
                    {
                        string Token = Helper.GlobalHelper.generateIdentify();
                        _DataList.details.client[groudPosition].UserToken = Token;
                        string newJSON = JsonConvert.SerializeObject(new ClientShortJSON()
                        {
                            users = _DataList.details.client.ToArray()
                        });
                        Helper.Luggage newLuggage = Create_Luggage(row, Token);
                        Helper.MySQLHelper.InsertLuggage(newLuggage, newLuggage.ReservationID, _obj.connection);
                        float newPrice = _DataList.KosztRezerwacji + ReserveTickets_2.getLuggagePrice(newLuggage.Lenght, newLuggage.Height, newLuggage.Width);
                        if (newLuggage.IsDangerous)
                        {
                            newPrice += 50;
                        }
                        Helper.MySQLHelper.UpdateJSONAndPrice(newJSON, newPrice.ToString(), _DataList.ReservationID.ToString(), _obj.connection);
                        GlobalMemory._menuPage.setAlert("Baga¿ zosta³ dodany dla klienta " + _DataList.details.client[groudPosition].ToStringWithoutToken() + ".");
                        _obj.Finish();
                    }
                    else
                    {
                        GlobalMemory._menuPage.setAlert("Brak zmian. ");
                        _obj.Finish();
                    }
                }
            }
        }