Example #1
0
        public void EditRow(View view, Json.View jsonView, string pk, bool ignoreNull, BeforeEditEventHandler beforeEditCallback, BeforeEditInDatabaseEventHandler beforeEditInDatabaseCallback, AfterEditEventHandler afterEditBeforeCommitCallback, AfterEditEventHandler afterEditAfterCommitCallback)
        {
            Dictionary <string, object> values = new Dictionary <string, object>();

            foreach (Json.Field jsonField in jsonView.Fields.Values)
            {
                if (!(ignoreNull && !jsonField.Refresh && (jsonField.Value == null || jsonField.Value.ToString() == string.Empty || jsonField.Value.Equals(false))))
                {
                    object value;
                    if (view.Fields.ContainsKey(jsonField.Name))
                    {
                        if (view.Fields[jsonField.Name].FieldType == FieldType.Column && ((ColumnField)view.Fields[jsonField.Name]).DataColumn.DataType.Equals(typeof(byte[])))
                        {
                            value = ((ColumnField)view.Fields[jsonField.Name]).ConvertFromString(jsonField.Value.ToString());
                        }
                        else
                        {
                            value = LocalizeValue(view, jsonField.Name, jsonField.Value);
                        }
                        values.Add(jsonField.Name, value);
                    }
                    else
                    {
                        values.Add(jsonField.Name, jsonField.Value);
                    }
                }
            }
            view.Edit(values, pk, beforeEditCallback, beforeEditInDatabaseCallback, afterEditBeforeCommitCallback, afterEditAfterCommitCallback);
        }
Example #2
0
        public Json.View GetJsonView(View view, DataAction dataAction, string guid)
        {
            Durados.Web.Mvc.UI.Json.View jsonView = new Json.View();

            foreach (Field field in view.GetVisibleFieldsForRow(dataAction))
            {
                string type = field.GetHtmlControlType().ToString();

                string format = string.Empty;
                if (field.FieldType == FieldType.Column)
                {
                    ColumnFieldType columnFieldType = field.GetColumnFieldType();
                    format = field.Validation.Format;
                }

                string validationType = "Children";
                if (field.FieldType != FieldType.Children)
                {
                    validationType = field.Validation.GetValidationType();
                }

                bool disbled;
                if (dataAction == DataAction.Create)
                {
                    disbled = field.IsDisableForCreate() || field.DisableConfigClonedView(view);
                }
                else
                {
                    disbled = field.IsDisableForEdit(guid) || field.DisableConfigClonedView(view);
                }
                Json.Field jsonField = new Json.Field()
                {
                    Name = field.Name, Type = type, ValidationType = validationType, Format = format, Required = field.Required, Default = field.ConvertDefaultToString(), Searchable = field.IsSearchable(), Disabled = disbled, DisDup = field.DisableInDuplicate, Refresh = field.Refresh, Min = field.Validation.GetMinForJson(), Max = field.Validation.GetMaxForJson(), DependencyData = field.DependencyData
                };
                if (type == HtmlControlType.Autocomplete.ToString() && field.FieldType == FieldType.Parent)
                {
                    jsonField.Value = ((ParentField)field).ConvertDefaultToDisplayValue();
                }
                jsonView.Fields.Add(field.Name, jsonField);
            }

            try
            {
                LoadDerivation(view, jsonView);
            }
            catch { }

            jsonView.InlineAddingCreateUrl  = view.GetInlineAddingCreateUrl();
            jsonView.InlineEditingCreateUrl = view.GetInlineEditingEditUrl();
            jsonView.ViewName = view.Name;

            return(jsonView);
        }
Example #3
0
        public Json.View GetJsonDisplayValue(View view, DataRow dataRow)
        {
            Durados.Web.Mvc.UI.Json.View jsonDisplayValue = new Json.View();

            string pk           = view.GetPkValue(dataRow);
            string displayValue = view.GetDisplayValue(dataRow);

            jsonDisplayValue.Fields.Add("DisplayValue", new Json.Field()
            {
                Value = pk, Default = displayValue
            });

            return(jsonDisplayValue);
        }
Example #4
0
        public DataRow CreateRow(View view, string insertAbovePK, Json.View jsonView, BeforeCreateEventHandler beforeCreateCallback, BeforeCreateInDatabaseEventHandler beforeCreateInDatabaseCallback, AfterCreateEventHandler afterCreateBeforeCommitCallback, AfterCreateEventHandler afterCreateAfterCommitCallback)
        {
            Dictionary <string, object> values = new Dictionary <string, object>();

            foreach (Json.Field jsonField in jsonView.Fields.Values)
            {
                object value;
                if (view.Fields.ContainsKey(jsonField.Name) && view.Fields[jsonField.Name].FieldType == FieldType.Column && ((ColumnField)view.Fields[jsonField.Name]).DataColumn.DataType.Equals(typeof(byte[])))
                {
                    value = ((ColumnField)view.Fields[jsonField.Name]).ConvertFromString(jsonField.Value.ToString());
                }
                else
                {
                    value = LocalizeValue(view, jsonField.Name, jsonField.Value);
                }
                values.Add(jsonField.Name, value);
            }
            DataRow dataRow = view.Create(values, insertAbovePK, beforeCreateCallback, beforeCreateInDatabaseCallback, afterCreateBeforeCommitCallback, afterCreateAfterCommitCallback);

            return(dataRow);
        }
Example #5
0
        //private void LoadDerivation(View view, Json.View jsonView)
        //{
        //    if (view.Derivation != null)
        //    {
        //        jsonView.Derivation = new Durados.Web.Mvc.UI.Json.Derivation();
        //        jsonView.Derivation.DerivationField = view.Derivation.DerivationField;
        //        foreach (string derived in view.Derivation.Deriveds.Split('|'))
        //        {
        //            Durados.Web.Mvc.UI.Json.Derived jsonDerived = new Durados.Web.Mvc.UI.Json.Derived();
        //            string[] s = derived.Split(';');
        //            jsonDerived.Value = s[0].Trim('\n');
        //            foreach (string field in s[1].Split(','))
        //            {
        //                string fieldName = field.Trim('\n');
        //                if (view.Fields.ContainsKey(fieldName))
        //                {
        //                    jsonDerived.Fields.Add(fieldName, view.Fields[fieldName].Required);
        //                }
        //            }
        //            jsonView.Derivation.Deriveds.Add(jsonDerived);
        //        }
        //    }

        //}

        private void LoadDerivation(View view, Json.View jsonView)
        {
            if (view.Derivation != null)
            {
                jsonView.Derivation = new Durados.Web.Mvc.UI.Json.Derivation();
                jsonView.Derivation.DerivationField = view.Derivation.DerivationField;
                Dictionary <string, Dictionary <string, Field> > deriveds = view.Derivation.GetDeriveds(view);

                foreach (string value in deriveds.Keys)
                {
                    Durados.Web.Mvc.UI.Json.Derived jsonDerived = new Durados.Web.Mvc.UI.Json.Derived();
                    jsonDerived.Value = value;
                    foreach (string fieldName in deriveds[value].Keys)
                    {
                        jsonDerived.Fields.Add(fieldName, deriveds[value][fieldName].Required);
                    }
                    jsonView.Derivation.Deriveds.Add(jsonDerived);
                }

                //foreach (string derived in view.Derivation.Deriveds.Split('|'))
                //{
                //    Durados.Web.Mvc.UI.Json.Derived jsonDerived = new Durados.Web.Mvc.UI.Json.Derived();
                //    string[] s = derived.Split(';');
                //    jsonDerived.Value = s[0].Trim('\n');
                //    foreach (string field in s[1].Split(','))
                //    {
                //        string fieldName = field.Trim('\n');
                //        if (view.Fields.ContainsKey(fieldName))
                //        {
                //            jsonDerived.Fields.Add(fieldName, view.Fields[fieldName].Required);
                //        }
                //    }
                //    jsonView.Derivation.Deriveds.Add(jsonDerived);
                //}
            }
        }
Example #6
0
        public Json.View GetJsonView(View view, DataAction dataAction, string pk, DataRow dataRow, string guid, BeforeSelectEventHandler beforeSelectCallback, AfterSelectEventHandler afterSelectCallback)
        {
            //DataRow dataRow = view.GetDataRow(pk, null, beforeSelectCallback, afterSelectCallback);

            if (dataRow == null)
            {
                return(null);
            }

            Json.View jsonView = new Json.View();

            foreach (Field field in view.GetVisibleFieldsForRow(dataAction))
            {
                if (field.FieldType == FieldType.Column)
                {
                    string type = field.GetHtmlControlType().ToString();

                    string format = string.Empty;
                    if (field.FieldType == FieldType.Column)
                    {
                        ColumnFieldType columnFieldType = field.GetColumnFieldType();

                        format = field.Validation.Format;
                    }

                    string validationType = "Children";
                    if (field.FieldType != FieldType.Children)
                    {
                        validationType = field.GetValidationType();
                    }
                    ColumnField columnField = (ColumnField)field;
                    //string value= columnField.ConvertToString(dataRow);
                    //if (columnField.DataColumn.DataType == typeof(bool) && string.IsNullOrEmpty(value))
                    //    value = false.ToString();
                    object value = dataRow[columnField.DataColumn.ColumnName];


                    if (view is Durados.Config.IConfigView && field.Name == "Formula")
                    {
                        string parentViewname = dataRow.GetParentRow("Fields")["Name"].ToString();

                        Map map = Maps.Instance.GetMap();

                        View currentView = (View)map.Database.Views[parentViewname];

                        value = DataAccessHelper.ReplaceFieldDisplayNames(value.ToString(), false, currentView);
                    }

                    if (value is DBNull || value.Equals("null"))
                    {
                        value = string.Empty;
                    }
                    else if (columnField.DataColumn.DataType == typeof(DateTime) || columnField.DataColumn.DataType == typeof(byte[]))
                    {
                        value = columnField.ConvertToString(dataRow);
                    }

                    bool disbled;
                    if (dataAction == DataAction.Create)
                    {
                        disbled = field.IsDisableForCreate() || field.DisableConfigClonedField(dataRow);
                    }
                    else
                    {
                        disbled = field.IsDisableForEdit(guid) || field.DisableConfigClonedField(dataRow);
                    }

                    if (dataAction == DataAction.Create)
                    {
                        if (!field.IncludeInDuplicate)
                        {
                            if (field.DefaultValue != null)
                            {
                                value = field.DefaultValue.ToString();
                            }
                            else
                            {
                                value = string.Empty;
                            }
                        }
                    }

                    if (columnField.Encrypted && columnField.SpecialColumn == SpecialColumn.Password)
                    {
                        value = columnField.View.Database.EncryptedPlaceHolder;
                    }

                    jsonView.Fields.Add(field.Name, new Json.Field()
                    {
                        Name = field.Name, Value = value, Type = field.GetHtmlControlType().ToString(), ValidationType = validationType, Format = format, Required = field.Required, Searchable = field.IsSearchable(), Disabled = disbled, DisDup = field.DisableInDuplicate, Refresh = field.Refresh, Min = field.Validation.GetMinForJson(), Max = field.Validation.GetMaxForJson(), DependencyData = field.DependencyData
                    });
                }
                else if (field.FieldType == FieldType.Parent)
                {
                    //, DependencyChildren = parentField.GetDependencyChildrenNames()
                    ParentField parentField = (ParentField)field;

                    string  fk        = string.Empty;
                    DataRow parentRow = null;
                    try
                    {
                        parentRow = dataRow.GetParentRow(parentField.DataRelation.RelationName);
                        fk        = parentField.ParentView.GetPkValue(parentRow);
                    }
                    catch (Exception)
                    {
                        DataColumn[] columns = parentField.GetDataColumns();
                        if (columns.Length == 1)
                        {
                            fk = dataRow[columns[0].ColumnName].ToString();
                        }
                        else
                        {
                            foreach (DataColumn column in columns)
                            {
                                fk += dataRow[column.ColumnName].ToString() + ',';
                            }
                            fk.TrimEnd(',');
                        }
                    }

                    DataRow dependencyRow = parentRow;

                    if (parentField.GetHtmlControlType() == HtmlControlType.OutsideDependency)
                    {
                        List <string> dependencyFks = new List <string>();

                        List <Durados.ParentField>   dependencyDynasty = parentField.GetDependencyDynasty();
                        Durados.DataAccess.SqlAccess sqlAccess         = new SqlAccess();

                        foreach (ParentField dependencyField in dependencyDynasty)
                        {
                            DataRow row = dependencyRow.GetParentRow(dependencyField.DataRelation.RelationName);
                            if (row == null)
                            {
                                string key = dependencyField.View.GetFkValue(dependencyRow, dependencyField.DataRelation.RelationName);
                                row = sqlAccess.GetDataRow(dependencyField.ParentView, key, dependencyRow.Table.DataSet);
                            }
                            dependencyRow = row;
                            string dependencyFk = dependencyField.ParentView.GetPkValue(dependencyRow);
                            dependencyFks.Add(dependencyFk);
                        }

                        dependencyFks.Reverse();
                        dependencyDynasty.Reverse();

                        int i = 0;
                        foreach (ParentField dependencyField in dependencyDynasty)
                        {
                            Json.Field jsonDependencyField = GetParentJsonField(dependencyField, dependencyFks[i], dataAction, guid);

                            jsonView.Fields.Add(jsonDependencyField.Name, jsonDependencyField);

                            i++;
                        }
                    }

                    Json.Field jsonField = GetParentJsonField(parentField, fk, dataAction, guid);

                    if (parentField.DisableConfigClonedField(dataRow))
                    {
                        jsonField.Disabled = true;
                    }

                    jsonView.Fields.Add(field.Name, jsonField);
                }

                else if (field.FieldType == FieldType.Children)
                {
                    if (((ChildrenField)field).ChildrenHtmlControlType == ChildrenHtmlControlType.CheckList)
                    {
                        string value = string.Empty;
                        if (dataAction == DataAction.Create)
                        {
                            if (field.IncludeInDuplicate)
                            {
                                value = ((ChildrenField)field).GetSelectedChildrenPKDelimited(pk);
                            }
                            else
                            {
                                if (field.DefaultValue != null)
                                {
                                    value = field.DefaultValue.ToString();
                                }
                            }
                        }
                        else
                        {
                            value = ((ChildrenField)field).GetSelectedChildrenPKDelimited(pk);
                        }

                        Json.Field jsonField = GetChildrenJsonField(((ChildrenField)field), value);

                        jsonView.Fields.Add(field.Name, jsonField);
                    }
                    else
                    {
                        Json.Field jsonField = GetChildrenJsonField(((ChildrenField)field), null);
                        jsonView.Fields.Add(field.Name, jsonField);
                    }
                }
            }

            try
            {
                LoadDerivation(view, jsonView);
            }
            catch { }

            jsonView.InlineAddingCreateUrl = view.GetInlineAddingCreateUrl();
            jsonView.ViewName = view.Name;

            return(jsonView);
        }