protected virtual View GetViewByRenderType(EbMobileControl ctrl)
        {
            View view = null;

            if (ctrl is EbMobileButton button)
            {
                if (button.HideInContext && IsHeader)
                {
                    return(null);
                }

                Button btn = (Button)button.Draw(DataRow);
                btn.Clicked += async(sender, args) => await ButtonControlClick(button);

                view = btn;
            }
            else if (ctrl is EbMobileDataColumn dc)
            {
                if (dc.HideInContext && IsHeader)
                {
                    return(null);
                }

                object data = this.DataRow[dc.ColumnName];
                view = ResolveRenderType(dc, data);
            }
            else if (ctrl is EbMobileLabel label)
            {
                EbXLabel lbl = (EbXLabel)label.Draw();
                lbl.SetFont(label.Font, this.IsHeader);
                lbl.SetTextWrap(label.TextWrap);
                view = lbl;
            }
            return(view);
        }
        private bool InitValidators(string controlName, string parent = CTRL_PARENT_FORM)
        {
            EbMobileControl ctrl = GetControl($"{parent}.{controlName}");

            if (ctrl.Validators == null || !ctrl.Validators.Any() || ctrl is INonPersistControl)
            {
                return(true);
            }

            bool flag = true;

            foreach (EbMobileValidator validator in ctrl.Validators)
            {
                if (validator.IsDisabled || validator.IsEmpty())
                {
                    continue;
                }

                flag = EvaluateValidatorExpr(validator, controlName, parent);
                ctrl.SetValidation(flag, validator.FailureMSG);
                if (!flag)
                {
                    break;
                }
            }
            return(flag);
        }
        public static void ExecDGOuterDependency(string dgname)
        {
            if (Instance.dependencyMap.DGDependencyMapColl.TryGetValue(dgname, out ExprDependency exprDep))
            {
                if (exprDep.HasValueDependency)
                {
                    foreach (string name in exprDep.ValueExpr)
                    {
                        EbMobileControl ctrl = Instance.GetControl(name);
                        Instance.EvaluateValueExpr(ctrl, name, CTRL_PARENT_FORM);
                    }
                }

                if (exprDep.HasHideDependency)
                {
                    foreach (string name in exprDep.HideExpr)
                    {
                        EbMobileControl ctrl = Instance.GetControl(name);
                        Instance.EvaluateHideExpr(ctrl, CTRL_PARENT_FORM);
                    }
                }

                if (exprDep.HasDisableDependency)
                {
                    foreach (string name in exprDep.DisableExpr)
                    {
                        EbMobileControl ctrl = Instance.GetControl(name);
                        Instance.EvaluateDisableExpr(ctrl, CTRL_PARENT_FORM);
                    }
                }
            }
        }
        private void SetControlValues(EbDataRow masterRow)
        {
            foreach (var pair in this.Form.ControlDictionary)
            {
                EbMobileControl ctrl = pair.Value;
                object          data = masterRow[ctrl.Name];
                try
                {
                    if (ctrl is IFileUploadControl)
                    {
                        this.SetFileData(ctrl, data);
                    }
                    else if (ctrl is ILinesEnabled line)
                    {
                        EbDataTable lines = this.formData.Tables.Find(table => table.TableName == line.TableName);
                        ctrl.SetValue(lines);
                    }
                    else
                    {
                        ctrl.SetValue(data);
                    }

                    if (this.IsEditButtonVisible)
                    {
                        ctrl.SetAsReadOnly(true);
                    }
                }
                catch (Exception ex)
                {
                    EbLog.Error("Error when setting value to controls on edit");
                    EbLog.Error(ex.Message);
                }
            }
        }
Example #5
0
 private void InitializeDependency(EbMobileControl control, string parent)
 {
     foreach (int value in Enum.GetValues(typeof(ExpressionType)))
     {
         if (control.HasExpression((ExpressionType)value, out string script))
         {
             foreach (string dependent in GetDependentNames(script))
             {
                 string dparent = dependent.Split(CharConstants.DOT)[0];
                 if (dparent != CTRL_PARENT_FORM && parent == CTRL_PARENT_FORM)// grid to form dependency
                 {
                     if (!DGDependencyMapColl.ContainsKey(dparent))
                     {
                         DGDependencyMapColl[dparent] = new ExprDependency();
                     }
                     DGDependencyMapColl[dparent].Add((ExpressionType)value, $"{parent}.{control.Name}");
                 }
                 else if (parent == dparent)// avoid form to grid dependency
                 {
                     if (!DependencyMapCollection.ContainsKey(dependent))
                     {
                         DependencyMapCollection[dependent] = new ExprDependency();
                     }
                     DependencyMapCollection[dependent].Add((ExpressionType)value, $"{parent}.{control.Name}");
                 }
             }
         }
     }
 }
 private void InitValueExpr(ExprDependency exprDep, string trigger_control, string parent = CTRL_PARENT_FORM)
 {
     if (exprDep.HasValueDependency)
     {
         foreach (string name in exprDep.ValueExpr)
         {
             EbMobileControl ctrl = GetControl(name);
             EvaluateValueExpr(ctrl, trigger_control, parent);
         }
     }
 }
 private void InitDisableExpr(ExprDependency exprDep, EbMobileControl currentControl = null, string parent = CTRL_PARENT_FORM)
 {
     if (exprDep.HasDisableDependency)
     {
         foreach (var name in exprDep.DisableExpr)
         {
             EbMobileControl ctrl = GetControl(name);
             this.EvaluateDisableExpr(ctrl, parent);
         }
     }
     else if (currentControl != null && currentControl.DisableExpr?.IsEmpty() == false)
     {
         this.EvaluateDisableExpr(currentControl, parent);
     }
 }
 private void EvaluateExpression(EbMobileControl ctrl, View view)
 {
     if (ctrl.HasExpression(ExpressionType.HideExpression))
     {
         string script = ctrl.HiddenExpr.GetCode();
         EbListHelper.SetDataRow(DataRow);
         view.IsVisible = !EbListHelper.EvaluateHideExpr(script);
     }
     else if (ctrl.HasExpression(ExpressionType.ValueExpression))
     {
         string script = ctrl.ValueExpr.GetCode();
         EbListHelper.SetDataRow(DataRow);
         EbListHelper.EvaluateValueExpr(view, script);
     }
 }
        private void EvaluateDefaultValueExpr(EbMobileControl ctrl, string parent)
        {
            string expr = ctrl.DefaultValueExpression.GetCode();

            string computed = GetComputedExpression(expr, ctrl.Name, parent);

            try
            {
                object value = evaluator.Execute(computed);
                ctrl.SetValue(value);
                ctrl.DefaultExprEvaluated = true;
            }
            catch (Exception ex)
            {
                EbLog.Info($"Default script evaluation error in control '{ctrl.Name}'");
                EbLog.Error(ex.Message);
            }
        }
        private void EvaluateValueExpr(EbMobileControl ctrl, string trigger_control, string parent)
        {
            string expr = ctrl.ValueExpr.GetCode();

            string computed = GetComputedExpression(expr, ctrl.Name, parent);

            try
            {
                object value = evaluator.Execute(computed);
                ctrl.SetValue(value);
                ctrl.ValueChanged(trigger_control);
            }
            catch (Exception ex)
            {
                EbLog.Info($"Value script evaluation error in control '{ctrl.Name}'");
                EbLog.Error(ex.Message);
            }
        }
        private void SetFileData(EbMobileControl ctrl, object data)
        {
            FUPSetValueMeta fup = new FUPSetValueMeta
            {
                TableName  = this.Form.TableName,
                RowId      = this.RowId,
                FileRefIds = data?.ToString()
            };

            if (ctrl is EbMobileFileUpload)
            {
                if (this.filesData != null && this.filesData.ContainsKey(ctrl.Name))
                {
                    fup.Files.AddRange(this.filesData[ctrl.Name]);
                }
            }
            ctrl.SetValue(fup);
        }
Example #12
0
        private void Initialize(EbMobileControl control)
        {
            recognizer         = new TapGestureRecognizer();
            recognizer.Tapped += ThumbNail_Tapped;

            if (control is EbMobileDisplayPicture dp)
            {
                controlType            = FupControlType.DP;
                CameraButton.IsVisible = dp.EnableCameraSelect;
                FilesButton.IsVisible  = dp.EnableFileSelect;
            }
            else if (control is EbMobileFileUpload fup)
            {
                controlType            = FupControlType.CONTEXT;
                CameraButton.IsVisible = fup.EnableCameraSelect;
                FilesButton.IsVisible  = fup.EnableFileSelect;
            }
        }
        private void EvaluateDisableExpr(EbMobileControl ctrl, string parent)
        {
            string expr = ctrl.DisableExpr.GetCode();

            string computed = GetComputedExpression(expr, ctrl.Name, parent);

            try
            {
                bool value = evaluator.Execute <bool>(computed);
                ctrl.SetAsReadOnly(value);
            }
            catch (Exception ex)
            {
                EbLog.Info($"Disable script evaluation error in control '{ctrl.Name}', considering as false");
                EbLog.Error(ex.Message);

                ctrl.SetAsReadOnly(false);
            }
        }
        private void EvaluateHideExpr(EbMobileControl ctrl, string parent)
        {
            string expr = ctrl.HiddenExpr.GetCode();

            string computed = GetComputedExpression(expr, ctrl.Name, parent);

            try
            {
                bool value = evaluator.Execute <bool>(computed);
                ctrl.SetVisibilty(!value);
            }
            catch (Exception ex)
            {
                EbLog.Info($"hide script evaluation error in control '{ctrl.Name}', considering as false");
                EbLog.Error(ex.Message);

                ctrl.SetVisibilty(true);
            }
        }
        public static void EvaluateExprOnLoad(EbMobileControl ctrl, FormMode mode)
        {
            string parent = ctrl.Parent;

            if (Instance.dependencyMap.HasDependency($"{parent}.{ctrl.Name}"))
            {
                ExprDependency exprDep = Instance.dependencyMap.GetDependency($"{parent}.{ctrl.Name}");

                if (mode == FormMode.NEW || mode == FormMode.EDIT || mode == FormMode.PREFILL)
                {
                    if (mode == FormMode.NEW || mode == FormMode.PREFILL)
                    {
                        Instance.InitHideExpr(exprDep, ctrl, parent);
                        Instance.InitDisableExpr(exprDep, ctrl, parent);
                    }
                    else if (mode == FormMode.EDIT)
                    {
                        if (ctrl.DoNotPersist)
                        {
                            Instance.InitValueExpr(exprDep, ctrl.Name, parent);
                        }

                        Instance.InitHideExpr(exprDep, ctrl, parent);
                    }
                }
            }
            else
            {
                if (mode == FormMode.NEW || mode == FormMode.EDIT || mode == FormMode.PREFILL)
                {
                    if (ctrl.HasExpression(ExpressionType.HideExpression))
                    {
                        Instance.EvaluateHideExpr(ctrl, parent);
                    }
                    if ((mode == FormMode.NEW || mode == FormMode.PREFILL) && ctrl.HasExpression(ExpressionType.DisableExpression))
                    {
                        Instance.EvaluateDisableExpr(ctrl, parent);
                    }
                }
            }
        }
        private void SetDefaultValueInternal(string controlName, string parent = CTRL_PARENT_FORM)
        {
            if (this.dependencyMap.HasDependency($"{parent}.{controlName}"))
            {
                ExprDependency exprDep = this.dependencyMap.GetDependency($"{parent}.{controlName}");

                if (exprDep.HasDefaultDependency)
                {
                    foreach (string name in exprDep.DefaultValueExpr)
                    {
                        this.SetDefaultValueInternal(name, parent);
                    }
                }
            }

            EbMobileControl ctrl = GetControl($"{parent}.{controlName}");

            if (ctrl.DefaultValueExpression != null && !ctrl.DefaultValueExpression.IsEmpty())
            {
                this.EvaluateDefaultValueExpr(ctrl, parent);
            }
        }
        private static string Validate_inner(EbMobileControl ctrl)
        {
            string msg = null;

            if (!ctrl.Validate())
            {
                msg = string.IsNullOrEmpty(ctrl.Label) ? ctrl.Name : ctrl.Label;
                msg = string.IsNullOrEmpty(msg) ? "Fields required" : (msg + " is required");
                if (ctrl.Hidden)
                {
                    msg += " (Hidden)";
                }
            }

            bool valid = Instance.InitValidators(ctrl.Name, ctrl.Parent);

            if (!valid)
            {
                msg = ctrl.GetValidatorFailureMsg();
                msg = string.IsNullOrEmpty(msg) ? ("Validation failed: " + ctrl.Label ?? ctrl.Name) : msg;
            }
            return(msg);
        }
        protected override View GetViewByRenderType(EbMobileControl ctrl)
        {
            View view = null;

            if (ctrl is EbMobileLabel label)
            {
                EbXLabel xlabel = (EbXLabel)label.Draw();

                if (label.RenderAsIcon)
                {
                    string icon = (label.BindingParam == null ? label.Icon : GetStaticData(label)) ?? "f128";
                    xlabel.Text = icon.ToFontIcon();
                }
                else
                {
                    xlabel.Text = GetStaticData(label);
                }
                xlabel.SetFont(label.Font);
                xlabel.SetTextWrap(label.TextWrap);
                view = xlabel;
            }

            return(view);
        }
Example #19
0
 public FileUploader(EbMobileControl control)
 {
     InitializeComponent();
     Initialize(control);
 }