Exemple #1
0
 public string CheckedText(object input)
 {
     return(TextFunction == null?UniversalEditorSettings.DefaultTextChecker(input) : TextFunction(input));
 }
Exemple #2
0
        public string UniversalTableSaver(object obj, UniversalEditorSettings settings)
        {
            try
            {
                var db = new DB();
                if (obj == null)
                {
                    return("Объект не найден");
                }
                var table = (ITable)db.GetType()
                            .GetProperty(settings.TableName)
                            .GetValue(db, null);

                if ((int)obj.GetPropertyValue(settings.UIDColumnName) == 0)
                {
                    if (settings.OnUniversalSaving != null)
                    {
                        obj = settings.OnUniversalSaving(obj);
                    }
                    table.InsertOnSubmit(obj);
                }
                else
                {
                    try
                    {
                        //obj.Detach();
                        //table.Attach(obj, true);
                        db.Refresh(RefreshMode.KeepChanges, obj);
                    }
                    catch (Exception e)
                    {
                        object entry =
                            Enumerable.Cast <object>(table)
                            .FirstOrDefault(
                                item =>
                                (int)item.GetPropertyValue(settings.UIDColumnName) ==
                                (int)obj.GetPropertyValue(settings.UIDColumnName));
                        if (entry != null)
                        {
                            obj.Detach();
                            entry.LoadPossibleProperties(obj, new string[] { settings.UIDColumnName });
                            db.Refresh(RefreshMode.KeepChanges);
                        }
                    }
                    //catch (Exception e)
                    {
                        /*
                         *                      obj.GetType().GetMethod("Initialize", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, null);
                         *
                         *                      var ndb = new DB();
                         *                      obj.ToString()|
                         */
                    }
                }
                db.SubmitChanges();
                return("");
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }