Exemple #1
0
        public bool LoadPedidoToEdit(Pedido pedido)
        {
            bool success = false;

            try
            {
                DBInstance            = UpdateDBObject();
                DBInstance.TempPedido = pedido;
                UIRuntime runtime = new UIRuntime();
                DBInstance.EditOn = true;
                SaveDB(DBInstance);
                foreach (var item in DBInstance.TempPedido.Items)
                {
                    addItemtoPedido(item.id, runtime);
                }
                //Set true the bandera edit on to manage the editions and creation of pedido at same time
                DBInstance.EditOn = true;
                success           = true;
            }
            catch (Exception)
            {
                return(false);
            }

            return(success);
        }
Exemple #2
0
        /*
         * // SUMMARY
         * // Manage the delete of an item on current memory pedido.
         * // Return: Void
         */
        public void removetemfromPedido(int ItemID, UIRuntime runtime)
        {
            Item item = new Item();

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();
            //se busca el producto que se agregara al pedido
            item = SearchItembyID(Convert.ToInt32(ItemID));
            //Restamos el costo total del item del total del pedido
            int indexqty = DBInstance.TempPedido.ItemsQuantity.FindIndex(i => i.Id == item.id);

            DBInstance.TempPedido.Total -= (DBInstance.TempPedido.ItemsQuantity[indexqty].Qty * item.Price);
            //Elimino el item quantity correspondiente
            DBInstance.TempPedido.ItemsQuantity.RemoveAt(indexqty);
            //Se elimina el producto del pedido y tambien su quantity correspondiente
            DBInstance.TempPedido.Items.RemoveAt(DBInstance.TempPedido.Items.FindIndex(x => x.id == item.id));

            runtime.updateTotals(DBInstance.TempPedido.Total);
            if (DBInstance.TempPedido.Items.Count.Equals(0))
            {
                DBInstance.EditOn = false;
            }
            SaveDB(DBInstance);
            DrawPedido(runtime, DBInstance.TempPedido);
        }
Exemple #3
0
        public bool EditPedido(int PedidoID)
        {
            var success = false;

            try
            {
                DBInstance = UpdateDBObject();
                int index = DBInstance.Pedidos.FindIndex(x => x.id.Equals(PedidoID));
                DBInstance.Pedidos[index] = DBInstance.TempPedido;
                DBInstance.TempPedido     = new Pedido();
                DBInstance.EditOn         = false;
                SaveDB(DBInstance);
                var element = (DockPanel) new UIHelper().FindChildByName(Application.Current.MainWindow, "dockpanel", "PanelPedidos");
                element.Children.Clear();
                UIRuntime runtime = new UIRuntime();
                runtime.updateTotals(DBInstance.TempPedido.Total);
                runtime.DrawSelectedPedido(DBInstance.Pedidos[index]);
                success = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error editando pedido.");
            }

            return(success);
        }
Exemple #4
0
        static Task DoSetClipboard(string text, string label)
        {
            var clipboard = UIRuntime.GetService <ClipboardManager>(Context.ClipboardService);

            clipboard.PrimaryClip = ClipData.NewPlainText(label ?? string.Empty, text);

            return(Task.CompletedTask);
        }
Exemple #5
0
        static void RegisterShakeHandler()
        {
            var sensorManager = UIRuntime.GetService <SensorManager>(Context.SensorService);
            var sensor        = sensorManager.GetDefaultSensor(SensorType.Accelerometer);

            ShakeRecognizer = new ShakeRecognizer();
            sensorManager.RegisterListener(ShakeRecognizer, sensor, SensorDelay.Ui);
        }
Exemple #6
0
        public MainWindow()
        {
            InitializeComponent();
            Global.DatbaseInstance    = new DatabaseModel();
            Global.DBHandler          = new DBHandler();
            Global.UIRuntime          = new UIRuntime();
            Global.DataGridList       = new List <DataGrid>();
            Global.TextBoxList        = new List <TextBox>();
            Global.ValidationsHandler = new Validations();
            Global.Elements           = new List <UIElement>();
            Global.DriveService       = new LDrive();
            //Create an instance of dbhandler

            //Create the mainObject to retrieve de json data
            Global.DatbaseInstance = Global.DBHandler.InitializeDB();
            //Create an instance of UIruntime class
            UIRuntime obj = new UIRuntime();

            //Create a list of border UIComponent dinamically that shows the app to the final user
            //Create 5000 generic products
            //for (int i = 0; i < 5000; i++)
            //{
            //    Global.DatbaseInstance.Items.Add(
            //    new Item
            //    {
            //        id = Global.DBHandler.GenerateID("item", Global.DatbaseInstance),
            //        Name = "Item generado dinamicamente numero: " + i,
            //        Description = "Descripcion del Item generado dinamicamente numero: " + i,
            //        ImagePath = i.ToString()
            //    }
            //    );
            //}

            /*List<Border> */
            borderList = obj.CreatePanels(Global.DatbaseInstance.Items);
            //Set the list on the content viewer
            for (int i = 0; i < borderList.Count; i++)
            {
                MainViewer.Children.Add(borderList[i]);
            }
            //Set the global main object
            //Global.DatbaseInstance = MainObject;
            Global.UIRuntime = obj;
            //Populate datagrid list
            Global.DataGridList.Add(DGEdit);
            Global.DataGridList.Add(DGDelete);
            //Poblate DatagridView with items
            Global.UIRuntime.PopulateAllDataGrids(Global.DataGridList, Global.DatbaseInstance);
            Global.Elements.Add(PanelPedidos);
            //First Validation to the pedidos in progress
            Global.DBHandler.firstValidation(Global.DatbaseInstance.Pedidos);

            DriveExists();
        }
Exemple #7
0
        static async Task OnUnRegistered()
        {
            var successful = await Api.Post("api/v1/authentication/push-notification/unregister",
                                            new
            {
                InstallationToken = UIRuntime.GetInstallationToken()
            });

            if (!successful)
            {
                Log.Error("The server failed to unregister this device from receiving push notifications.");
            }
        }
Exemple #8
0
        static async Task OnRegistered(string token)
        {
            var userId = "???";

            await Api.Post("v1/authentication/push-notification/register",
                           new
            {
                User = userId,
                InstallationToken     = UIRuntime.GetInstallationToken(),
                PushNotificationToken = token,
                DeviceType            = Device.Platform
            });
        }
Exemple #9
0
        /*
         * // SUMMARY
         * // Draw the visual structure of a pedido on it space on screen from a list of pedidos.
         * // Return: Void
         */
        private void DrawPedido(UIRuntime runtime, Pedido MPedido)
        {
            //var el = (Window)Application.Current.MainWindow;
            //var element = (DockPanel)el.FindName("PanelPedidos");
            var element = (DockPanel) new UIHelper().FindChildByName(Application.Current.MainWindow, "dockpanel", "PanelPedidos");

            element.Children.Clear();

            for (int i = 0; i < MPedido.Items.Count; i++)
            {
                var a = MPedido.ItemsQuantity.Where(x => x.Id.Equals(MPedido.Items[i].id)).FirstOrDefault();

                element.Children.Add(runtime.CreatePedidoPanels(MPedido.Items[i], i + 1, MPedido.ItemsQuantity.Where(x => x.Id.Equals(MPedido.Items[i].id)).FirstOrDefault()));
            }
        }
Exemple #10
0
        static Sensors()
        {
            App.CameToForeground += () =>
            {
                if (Accelerometer.ShouldDetectShaking)
                {
                    Thread.Pool.RunActionOnNewThread(RegisterShakeHandler);
                }
            };

            App.WentIntoBackground += () =>
            {
                if (Accelerometer.ShouldDetectShaking)
                {
                    UIRuntime.GetService <SensorManager>(Context.SensorService).UnregisterListener(ShakeRecognizer);
                }
            };
        }
        public static async Task <bool> Logout()
        {
            var successful = await Post <bool>("api/v1/auth/logout", new
            {
                SessionToken      = BaseApi.GetSessionToken(),
                InstallationToken = UIRuntime.GetInstallationToken() // To disable sending push notifications to this device.
            });

            if (successful)
            {
                IO.File("SessionToken.txt").Delete();
                User.Current = null;

                Nav.DisposeCache();
                await Api.DisposeCache();
            }

            return(successful);
        }
Exemple #12
0
        /*
         * // SUMMARY
         * // Insert data of a new item on JSON FILE writing the current data and updates the DBInstance with the new data
         * // Return: bool (True/False)
         */
        public bool CreateItem(Item Newitem, List <DataGrid> dgList, UIRuntime runtime)
        {
            bool success = false;

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();

            try
            {
                DBInstance.Items.Add(Newitem);
                success = SaveDB(DBInstance);
                runtime.PopulateAllDataGrids(dgList, DBInstance);
                return(success);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
                return(success);
            }
        }
Exemple #13
0
        /*
         * // SUMMARY
         * // Decrement the qty of 1 item on the pedido item list.
         * // Return: Void
         */
        private void decrementItemQty(Pedido pedido, Item itemTarget, UIRuntime runtime)
        {
            var index = pedido.Items.FindIndex(x => x.id == itemTarget.id);

            if (!index.Equals(null) && pedido.ItemsQuantity[index].Id.Equals(itemTarget.id))
            {
                if (pedido.ItemsQuantity[index].Qty <= 1)
                {
                    //delete pedido
                    removetemfromPedido(itemTarget.id, runtime);
                }
                else
                {
                    pedido.ItemsQuantity[index].Qty--;
                    pedido.Total -= itemTarget.Price;
                }
                SaveDB(DBInstance);
                runtime.updateTotals(DBInstance.TempPedido.Total);
            }
        }
Exemple #14
0
        /// <param name="registerationToken">The registration token provided by Apple, Google or Microsoft.</param>
        static async Task OnRegistered(string registerationToken)
        {
            if (User.Current == null)
            {
                throw new Exception("A non-logged in user was registered for push notification!");
            }

            var successful = await Api.Post("api/v1/authentication/push-notification/register",
                                            new
            {
                User = User.Current.Id,
                InstallationToken     = UIRuntime.GetInstallationToken(),
                PushNotificationToken = registerationToken,
                DeviceType            = OS.Platform
            });

            if (!successful)
            {
                throw new Exception("The server failed to register the push notification token.");
            }
        }
Exemple #15
0
        /*
         * // SUMMARY
         * // Manage the addition of an item to a current on memory pedido.
         * // Return: Void
         */
        public void addItemtoPedido(int ItemID, UIRuntime runtime)
        {
            Item item = new Item();

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();
            //se busca el producto que se agregara al pedido
            item = SearchItembyID(Convert.ToInt32(ItemID));
            //Hay datos en el objeto en memoria??? Si no existen datos se inicializa el nuevo pedido...
            if (DBInstance.TempPedido.id.Equals(0))
            {
                GeneratePedidoOnMemory(item, DBInstance, "");
                SaveDB(DBInstance);
            }
            else // Si existe un pedido en memoria comenzamos las validaciones del producto en la lista
            {
                //Si existe en la lista cargada en memoria entonces se actualiza, si no existe se agrega a la lista en memoria
                if (DBInstance.TempPedido.Items.Find(x => x.id == item.id) != null) //Ya existe el producto
                {
                    incrementItemQty(DBInstance.TempPedido, DBInstance.TempPedido.Items[DBInstance.TempPedido.Items.FindIndex(x => x.id == item.id)]);
                    DBInstance.TempPedido.Total += item.Price;
                }
                else // No existe el producto en la lista lo agregamos
                {
                    DBInstance.TempPedido.Items.Add(item);
                    DBInstance.TempPedido.ItemsQuantity.Add(new ItemQty
                    {
                        Id    = item.id,
                        Price = item.Price,
                        Qty   = 0
                    });
                    incrementItemQty(DBInstance.TempPedido, DBInstance.TempPedido.Items[DBInstance.TempPedido.Items.FindIndex(x => x.id == item.id)]);
                    DBInstance.TempPedido.Total += item.Price;
                }
                SaveDB(DBInstance);
            }
            runtime.updateTotals(DBInstance.TempPedido.Total);
            DrawPedido(runtime, DBInstance.TempPedido);
        }
        public static async Task <bool> Login(string email, string password)
        {
            var sessionToken = await Post <string>("api/v1/auth/login", new
            {
                Email             = email,
                Password          = password,
                installationToken = UIRuntime.GetInstallationToken()
            });

            if (sessionToken.LacksValue())
            {
                return(false);
            }

            IO.File("SessionToken.txt").WriteAllText(sessionToken);
            if (!await User.LoadFromSessionToken())
            {
                return(false);
            }
            await UI.Services.PushNotificationListener.Register();

            return(true);
        }
Exemple #17
0
 /*
  * // SUMMARY
  * // Call private function decrementItemQty.
  * // Return: Void
  */
 public void decrementQty(int id, UIRuntime runtime)
 {
     DBInstance = UpdateDBObject();
     decrementItemQty(DBInstance.TempPedido, DBInstance.Items.Find(x => x.id.Equals(id)), runtime);
 }
Exemple #18
0
 static Vibrator CreateVibrator() => UIRuntime.GetService <Vibrator>(Context.VibratorService);
Exemple #19
0
 static async Task OnUnRegistered()
 {
     await Api.Post("v1/authentication/push-notification/unregister",
                    new { InstallationToken = UIRuntime.GetInstallationToken() });
 }
 public override void OnCreate()
 {
     base.OnCreate();
     UIRuntime.Initialize <MainApplication>("MyProjectName");
     RegisterActivityLifecycleCallbacks(this);
 }
Exemple #21
0
        /*
         * // SUMMARY
         * // Edit or Delete Data from JSON FILE and updates the DBInstance and JSON File with the new data
         * // Return: bool (True/False)
         */
        public bool edit_delete_item(Item item, string action, List <DataGrid> dgList, UIRuntime runtime)
        {
            bool success = false;

            //UpdateDBObject the databaseobject to get the most recent data
            DBInstance = UpdateDBObject();

            try
            {
                var pastItem = DBInstance.Items.FindIndex(x => x.id == item.id);

                if (action == "edit")
                {
                    DBInstance.Items[pastItem] = item;
                    success = SaveDB(DBInstance);
                }
                else if (action == "delete")
                {
                    DBInstance.Items.RemoveAt(pastItem);
                    success = SaveDB(DBInstance);
                }
                runtime.PopulateAllDataGrids(dgList, DBInstance);
                return(success);
            }
            catch (Exception es)
            {
                MessageBox.Show("Error mientras se editaba el item. Error: " + es.Message);
                return(success);
            }
        }
Exemple #22
0
 /*
  * // SUMMARY
  * // Call private function incrementItemQty.
  * // Return: Void
  */
 public void CallDrawPedido(UIRuntime runtime)
 {
     DBInstance = UpdateDBObject();
     DrawPedido(runtime, DBInstance.TempPedido);
 }
Exemple #23
0
 internal static void Init()
 {
     Manager   = UIRuntime.GetService <LocationManager>(Context.LocationService);
     Providers = Manager.GetProviders(enabledOnly: false).Where(s => s != LocationManager.PassiveProvider).ToArray();
 }