示例#1
0
        public static async Task <bool> isMonthlyIncomingExceded()
        {
            bool response = false;

            try
            {
                List <CloureParam> cparams = new List <CloureParam>();
                cparams.Add(new CloureParam("module", "finances"));
                cparams.Add(new CloureParam("topic", "is_monthly_incoming_exceeded"));
                string res = await CloureManager.ExecuteAsync(cparams);

                JsonObject api_result = JsonObject.Parse(res);
                string     error      = api_result.GetNamedString("Error");
                if (error == "")
                {
                    response = CloureManager.ParseBoolObject(api_result.GetNamedValue("Response"));
                }
                else
                {
                    throw new Exception(error);
                }
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(ex.Message);
                await dialog.ShowAsync();
            }

            return(response);
        }
        public static async Task <UserGroup> Get(string id)
        {
            UserGroup item = new UserGroup();

            try
            {
                List <CloureParam> cparams = new List <CloureParam>();
                cparams.Add(new CloureParam("module", "users_groups"));
                cparams.Add(new CloureParam("topic", "obtener"));
                cparams.Add(new CloureParam("id", id));
                string res = await CloureManager.ExecuteAsync(cparams);

                JsonObject api_result = JsonObject.Parse(res);
                string     error      = api_result.GetNamedString("Error");
                if (error == "")
                {
                    JsonObject item_obj = api_result.GetNamedObject("Response");
                    item.Name    = item_obj.GetNamedString("Id");
                    item.IsStaff = CloureManager.ParseBoolObject(item_obj.GetNamedValue("PerteneceAEmpresa"));
                }
                else
                {
                    throw new Exception(error);
                }
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(ex.Message);
                await dialog.ShowAsync();
            }

            return(item);
        }
        public async static Task <List <UserGroup> > GetList()
        {
            List <UserGroup> items = new List <UserGroup>();

            try
            {
                List <CloureParam> cparams = new List <CloureParam>();
                cparams.Add(new CloureParam("module", "users_groups"));
                cparams.Add(new CloureParam("topic", "get_list"));
                string res = await CloureManager.ExecuteAsync(cparams);

                JsonObject api_result = JsonObject.Parse(res);
                string     error      = api_result.GetNamedString("Error");
                if (error == "")
                {
                    JsonObject api_response = api_result.GetNamedObject("Response");
                    JsonArray  registers    = api_response.GetNamedArray("Registros");

                    foreach (JsonValue jsonValue in registers)
                    {
                        JsonObject register = jsonValue.GetObject();
                        UserGroup  item     = new UserGroup();
                        item.Id      = register.GetNamedString("Id");
                        item.Name    = register.GetNamedString("Nombre");
                        item.Type    = register.GetNamedString("TipoGrupoId");
                        item.IsStaff = CloureManager.ParseBoolObject(register.GetNamedValue("PerteneceAEmpresa"));

                        JsonArray available_commands_arr = register.GetNamedArray("AvailableCommands");
                        item.AvailableCommands = new List <AvailableCommand>();
                        foreach (JsonValue available_cmd_obj in available_commands_arr)
                        {
                            JsonObject       available_cmd_item  = available_cmd_obj.GetObject();
                            int              available_cmd_id    = (int)available_cmd_item.GetNamedNumber("Id");
                            string           available_cmd_name  = available_cmd_item.GetNamedString("Name");
                            string           available_cmd_title = available_cmd_item.GetNamedString("Title");
                            AvailableCommand availableCommand    = new AvailableCommand(available_cmd_id, available_cmd_name, available_cmd_title);
                            item.AvailableCommands.Add(availableCommand);
                        }

                        items.Add(item);
                    }
                }
                else
                {
                    throw new Exception(error);
                }
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog(ex.Message);
                await dialog.ShowAsync();
            }

            return(items);
        }
        private async void LoadSettings()
        {
            stackModulesOptions.Children.Clear();
            moduleSettings = await Settings.GetList();

            foreach (ModuleSettings module in moduleSettings)
            {
                TextBlock txtModuleTitle = new TextBlock();
                txtModuleTitle.HorizontalAlignment     = HorizontalAlignment.Stretch;
                txtModuleTitle.HorizontalTextAlignment = TextAlignment.Center;
                txtModuleTitle.Text = module.ModuleTitle;

                if (module.CloureSettings != null)
                {
                    StackPanel stackPrivileges = new StackPanel();

                    if (module.CloureSettings.Count > 0)
                    {
                        foreach (CloureSetting setting in module.CloureSettings)
                        {
                            Grid             grid = new Grid();
                            TextBlock        txtPrivilegeTitle = new TextBlock();
                            ColumnDefinition colTitle          = new ColumnDefinition();
                            ColumnDefinition colControl        = new ColumnDefinition();
                            colTitle.Width   = new GridLength(1, GridUnitType.Star);
                            colControl.Width = new GridLength(200, GridUnitType.Pixel);
                            grid.ColumnDefinitions.Add(colTitle);
                            grid.ColumnDefinitions.Add(colControl);

                            txtPrivilegeTitle.Text = setting.Title;
                            Grid.SetColumn(txtPrivilegeTitle, 0);

                            grid.Children.Add(txtPrivilegeTitle);

                            if (setting.Type == "bool")
                            {
                                ToggleSwitch toggleSwitch = new ToggleSwitch();
                                toggleSwitch.Tag      = setting;
                                toggleSwitch.IsOn     = CloureManager.ParseBoolObject(setting.Value);
                                toggleSwitch.Toggled += ToggleSwitch_Toggled;
                                Grid.SetColumn(toggleSwitch, 1);
                                grid.Children.Add(toggleSwitch);
                            }

                            stackPrivileges.Children.Add(grid);
                        }
                        stackModulesOptions.Children.Add(txtModuleTitle);
                        stackModulesOptions.Children.Add(stackPrivileges);
                    }
                }
            }
        }