Beispiel #1
0
        public static void CreateGroup(SchemaView view)
        {
            Viewbox Group = new Viewbox();

            Group.SetValue(Viewbox.StretchProperty, Stretch.Fill);
            Canvas workCanvas = (Canvas)view.MainPanel;
            Canvas g          = new Canvas();
            Rect   r          = CalculateBounds(view.SelectionManager.SelectedObjects.Cast <UIElement>().ToList(), workCanvas);

            Canvas.SetLeft(Group, r.X);
            Canvas.SetTop(Group, r.Y);
            Group.Width  = g.Width = r.Width;
            Group.Height = g.Height = r.Height;



            foreach (FrameworkElement ch in view.SelectionManager.SelectedObjects)
            {
                //tool.NotifyObjectDeleted(ch);
                Vector off = VisualTreeHelper.GetOffset(ch);
                Canvas.SetLeft(ch, Canvas.GetLeft(ch) - r.X);
                Canvas.SetTop(ch, Canvas.GetTop(ch) - r.Y);
                workCanvas.Children.Remove(ch);
                g.Children.Add(ch);
            }
            Group.Child = g;
            Canvas.SetTop(g, 0); Canvas.SetLeft(g, 0);
            workCanvas.Children.Add(Group);
            //tool.NotifyObjectCreated(Group);
            view.SelectionManager.SelectObject(null);
            view.MainPanel.InvalidateVisual();
            view.SelectionManager.SelectObject(Group);
        }
Beispiel #2
0
        public void CreateNewSchema()
        {
            string name;
            var    hasTheSameDocument = false;

            name = Env.Current.Project.GenerateUniqueName(ProjectEntityType.Schema, "Untitled_");
            do
            {
                hasTheSameDocument = false;

                foreach (DocumentView doc in documentViews)
                {
                    if (doc is SchemaView && doc.DocumentName == name)
                    {
                        hasTheSameDocument = true;
                        name = Env.Current.Project.GenerateUniqueName(ProjectEntityType.Schema, name);
                        break;
                    }
                }
            }while (hasTheSameDocument);


            var view = new SchemaView(name);

            view.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing);
            documentViews.Add(view);
            view.Show(dockPanel, DockState.Document);
        }
        /// <summary>
        ///		Carga la definición de vistas
        /// </summary>
        private void LoadViews(SQLServerProvider objConnection, Schema objSchema)
        {
            string strSQL;

            // Crea la cadena SQL
            strSQL = @"SELECT Table_Catalog, Table_Schema, Table_Name, View_Definition, Check_Option, Is_Updatable
											 FROM Information_Schema.Views
											 ORDER BY Table_Name"                                            ;
            // Carga las vistas
            using (IDataReader rdoViews = objConnection.ExecuteReader(strSQL, null, CommandType.Text))
            {                                     // Lee los registros
                while (rdoViews.Read())
                {
                    SchemaView objView = new SchemaView(objSchema);

                    // Asigna los datos al objeto
                    objView.Catalog     = (string)rdoViews.IisNull("Table_Catalog");
                    objView.Schema      = (string)rdoViews.IisNull("Table_Schema");
                    objView.Name        = (string)rdoViews.IisNull("Table_Name");
                    objView.Definition  = (string)rdoViews.IisNull("View_Definition");
                    objView.CheckOption = (string)rdoViews.IisNull("Check_Option");
                    objView.IsUpdatable = !(((string)rdoViews.IisNull("Is_Updatable")).Equals("NO", StringComparison.CurrentCultureIgnoreCase));
                    // Añade el objeto a la colección
                    objSchema.Views.Add(objView);
                }
                // Cierra el recordset
                rdoViews.Close();
            }
            // Carga las columnas de la vista
            foreach (SchemaView objView in objSchema.Views)
            {
                LoadColumns(objConnection, objView);
            }
        }
Beispiel #4
0
 public static void ThrowExceptionIfViewIsNull(SchemaView view)
 {
     if (view == null)
     {
         throw new Exception("This view is not accesible");
     }
 }
Beispiel #5
0
        public static ObjectId FindExisting(DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, IDynamicService <DynamicRecord> dynamicService, out bool isValidInput)
        {
            isValidInput = true;
            //check if the current record exists... only check for quick create ones
            if ((record._id == null || record._id == ObjectId.Empty) && view != null && view.Schema.UniqueIndex != null)
            {
                var filter = view.Schema.UniqueIndex.ToDictionary(v => v, v =>
                                                                  v.Contains("$") ?
                                                                  //v.Split('$')[0] = View  (View$Name)
                                                                  //v.Split('$')[1] = Name
                                                                  (record[v.Split('$')[0]] as IDictionary <string, object>)[v.Split('$')[1]].ToString() :
                                                                  record[v]?.ToString()
                                                                  );

                // If all filters are empty that's because we're receiving an object without a unique index,
                // which can't be compared
                if (filter.All(x => string.IsNullOrEmpty(x.Value)))
                {
                    // We received something without a valid uniqueIndex
                    isValidInput = false;
                }
                else
                {
                    var existingRecords = dynamicService.GetAll(view, tenantId, loggedUser, RecordLevelSecurityEnum.NoRestriction).ToList();
                    var existingRecord  = existingRecords.Where(e => e.Contains(filter)).ToList();

                    if (existingRecord != null && existingRecord.Count() > 0)
                    {
                        return(existingRecord.First()._id);
                    }
                }
            }
            return(ObjectId.Empty);
        }
Beispiel #6
0
        public static ObjectId FindExisting(DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, IDynamicRepository dynamicRepository, out bool isValidInput)
        {
            isValidInput = true;
            //check if the current record exists... only check for quick create ones
            if ((record._id == null || record._id == ObjectId.Empty) && view.Schema.UniqueIndex != null)
            {
                var filter = view.Schema.UniqueIndex.ToDictionary(v => v, v => record[v]?.ToString());

                // If all filters are empty that's because we're receiving an object without a unique index,
                // which can't be compared
                if (filter.All(x => string.IsNullOrEmpty(x.Value)))
                {
                    // We received something without a valid uniqueIndex
                    isValidInput = false;
                }
                else
                {
                    var existingRecords = dynamicRepository.GetAll <DynamicRecord>(view.Schema.Name, tenantId, null);
                    var existingRecord  = existingRecords.Where(e => e.Contains(filter)).ToList();

                    if (existingRecord != null && existingRecord.Count() > 0)
                    {
                        return(existingRecord.First()._id);
                    }
                }
            }
            return(ObjectId.Empty);
        }
Beispiel #7
0
        public override void Execute()
        {
            SchemaView view = (SchemaView)ControlledObject;

            view.ZoomGesture.Zoom = level;
            view.Focus();
        }
        /// <summary>
        ///		Carga las columnas de la vista
        /// </summary>
        private void LoadColumns(SQLServerProvider objConnection, SchemaView objView)
        {
            ParametersDBCollection objColParameters = new ParametersDBCollection();
            string strSQL;

            // Asigna lo parámetros
            objColParameters.Add("@View_Catalog", objView.Catalog);
            objColParameters.Add("@View_Schema", objView.Schema);
            objColParameters.Add("@View_Name", objView.Name);
            // Crea la cadena SQL
            strSQL = @"SELECT Table_Catalog, Table_Schema, Table_Name, Column_Name
											 FROM Information_Schema.View_Column_Usage
											 WHERE View_Catalog = @View_Catalog
												 AND View_Schema = @View_Schema
												 AND View_Name = @View_Name"                                                ;
            // Carga las columnas
            using (IDataReader rdoColumns = objConnection.ExecuteReader(strSQL, objColParameters, CommandType.Text))
            {                                     // Lee los registros
                while (rdoColumns.Read())
                {
                    SchemaColumn objColumn = new SchemaColumn(objView.Parent);

                    // Carga los datos de la columna
                    objColumn.Catalog = (string)rdoColumns.IisNull("Table_Catalog");
                    objColumn.Schema  = (string)rdoColumns.IisNull("Table_Schema");
                    objColumn.Table   = (string)rdoColumns.IisNull("Table_Name");
                    objColumn.Name    = (string)rdoColumns.IisNull("Column_Name");
                    // Añade la columna a la colección
                    objView.Columns.Add(objColumn);
                }
                // Cierra el recordset
                rdoColumns.Close();
            }
        }
Beispiel #9
0
        public override void Execute()
        {
            SchemaView view = (SchemaView)ControlledObject;

            view.ZoomGesture.Zoom /= 1.05;
            //view.ZoomOut();
        }
        public void OnOpenProjectEntity(ProjectEntityType type, string name)
        {
            // Open your schema and other document types here by entity name
            DocumentView view = null;

            switch (type)
            {
            case ProjectEntityType.Schema:
                foreach (DocumentView doc in documentViews)
                {
                    if (doc is SchemaView)
                    {
                        if (doc.DocumentName == name)
                        {
                            doc.Activate();
                            return;
                        }
                    }
                }
                view = new SchemaView();
                if ((view == null) || (view as SchemaView).LoadDocument(name) == false)
                {
                    System.Windows.MessageBox.Show(DialogMessages.CannotLoadSchema,
                                                   DialogMessages.ErrorCaption,
                                                   System.Windows.MessageBoxButton.OK,
                                                   System.Windows.MessageBoxImage.Error);
                    return;
                }
                break;

            case ProjectEntityType.VariableList:
                foreach (DocumentView doc in documentViews)
                {
                    if (doc is VariablesView)
                    {
                        doc.Activate();
                        return;
                    }
                }
                view = new VariablesView();
                if ((view == null))
                {
                    System.Windows.MessageBox.Show(DialogMessages.CannotLoadVariables,
                                                   DialogMessages.ErrorCaption,
                                                   System.Windows.MessageBoxButton.OK,
                                                   System.Windows.MessageBoxImage.Error);
                    return;
                }
                break;
            }
            documentViews.Add(view);
            view.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing);
            view.Show(dockPanel, DockState.Document);
            currentDocument = (DocumentView)dockPanel.ActiveDocument;
        }
Beispiel #11
0
        public static byte[] GetFileBytes(string schemaName, SchemaView view)
        {
            using (ExcelPackage pck = new ExcelPackage())
            {
                //Create the worksheet
                ExcelWorksheet ws = pck.Workbook.Worksheets.Add(schemaName);

                IEnumerable <dynamic> headers = view.Attributes.Where(a => a.Value.IsVisible == true).Select((a, i) => new { Index = i + 1, ColumnName = a.Value.Title, AttributeName = a.Key, Format = "string" });
                headers.ToList().ForEach(h => ws.Cells[1, h.Index].Value = h.ColumnName);

                //format columns  (TODO: analudg. when format exists at the Column Schema level)
                headers.Where(h => h.Format == "Numeric").ToList().ForEach(h =>
                {
                    ws.Cells[2, h.Index].Style.Numberformat.Format = "#,##0.00";
                    ws.Cells[2, h.Index].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;
                });
                return(pck.GetAsByteArray());
            }
        }
Beispiel #12
0
 public static RecordLevelSecurityEnum GetAccessType(string roleCode, SchemaView view, List <DynamicRecord> permissions)
 {
     try
     {
         var viewAccessCode = permissions.Where(p => p.ContainsKey(roleCode) && (bool)p[roleCode] && p["View"]?.ToString() == view.ViewFullName)
                              .Select(p => (string)p[string.Format("{0}_AccessType", roleCode)]?.ToString()) //TA_AccessType / SP_AccessType
                              .FirstOrDefault();
         if (viewAccessCode != null)
         {
             return((RecordLevelSecurityEnum)Enum.Parse(typeof(RecordLevelSecurityEnum), viewAccessCode));
         }
         else
         {
             return(GetAccessType(roleCode));
         }
     }
     catch
     {
         return(GetAccessType(roleCode));
     }
 }
Beispiel #13
0
        public void OnOpenProjectEntity(ProjectEntityType type, string name)
        {
            // Open your schema and other document types here by entity name
            DocumentView view = null;

            switch (type)
            {
            case ProjectEntityType.Schema:
                foreach (DocumentView doc in documentViews)
                {
                    if (doc is SchemaView)
                    {
                        if (doc.DocumentName == name)
                        {
                            doc.Activate();
                            return;
                        }
                    }
                }
                view = new SchemaView(name);

                view.FormClosing += new FormClosingEventHandler(OnDocumentWindowClosing);
                documentViews.Add(view);
                view.Show(dockPanel, DockState.Document);
                break;

            case ProjectEntityType.Archiver:
                ShowArchiverSettings();
                break;

            case ProjectEntityType.Script:
                OnOpenScript(this, name);
                break;

            // etc....
            default:
                break;
            }
        }
Beispiel #14
0
        public static ObjectId DeepCreate(DynamicRecord parentRecord, DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, string roleCode, IDynamicService <DynamicRecord> dynamicService, ISchemaService schemaService, bool allowUpdate = false)
        {
            var complexRecords = record.Values().Where(v => view.Schema.Attributes.ContainsKey(v.Key) && (view.Schema.Attributes[v.Key].IsComplex || view.Schema.Attributes[v.Key].IsSubCatalog));

            complexRecords.ToList().ForEach(r =>
            {
                var subcatalogView = schemaService.GetView(view.Schema.Attributes[r.Key].DataType, ViewCategory.Create, tenantId, roleCode);  //this should go to cache all of the time, it would be expensive not to.

                // When manually creating an invoice, we need to check if Count > 0, otherwise FindExisting throws an exception
                if (r.Value is Dictionary <string, object> && ((Dictionary <string, object>)r.Value).Count > 0)
                {
                    var subRecord     = new DynamicRecord().Initialize <DynamicRecord>((Dictionary <string, object>)r.Value, null, ViewCategory.Create);
                    bool isValidInput = true;
                    subRecord._id     = FindExisting(subRecord, subcatalogView, tenantId, loggedUser, dynamicService, out isValidInput);
                    if (subcatalogView != null && subcatalogView.Schema.AllowQuickCreate && subRecord._id == ObjectId.Empty && isValidInput)
                    {
                        var fieldId     = DeepCreate(parentRecord ?? record, subRecord, subcatalogView, tenantId, loggedUser, roleCode, dynamicService, schemaService);
                        var field       = ((Dictionary <string, object>)r.Value);
                        var arrayOfKeys = field.Keys.ToArray();
                        foreach (var k in arrayOfKeys)
                        {
                            if (subRecord.ContainsKey(k))
                            {
                                field[k] = subRecord[k];
                            }
                        }
                    }
                    else if (subRecord._id != ObjectId.Empty)
                    {
                        ((Dictionary <string, object>)r.Value)["_id"] = subRecord._id;
                    }
                }
                else if (subcatalogView?.Schema != null && subcatalogView.Schema.AllowQuickCreate && r.Value is List <Dictionary <string, object> > && ((List <Dictionary <string, object> >)r.Value).Count > 0)
                {
                    ((List <Dictionary <string, object> >)r.Value).ForEach(v =>
                    {
                        var subRecord   = new DynamicRecord().Initialize <DynamicRecord>(v, subcatalogView, ViewCategory.Create);
                        var fieldId     = DeepCreate(parentRecord ?? record, subRecord, subcatalogView, tenantId, loggedUser, roleCode, dynamicService, schemaService, true);
                        var field       = v;
                        var arrayOfKeys = field.Keys.ToArray();
                        foreach (var k in arrayOfKeys)
                        {
                            if (subRecord.ContainsKey(k))
                            {
                                field[k] = subRecord[k];
                            }
                        }
                    });
                }
            });

            if (record._id != ObjectId.Empty && allowUpdate)
            {
                record.ParentRecord = parentRecord;
                dynamicService.Update(record, view.Schema.CollectionName, view.Schema.Name, tenantId, loggedUser, roleCode);
                return(record._id);
            }
            else
            {
                var isValidInput = false;
                record._id = FindExisting(record, view, tenantId, loggedUser, dynamicService, out isValidInput);
                if (record._id == ObjectId.Empty)
                {
                    record.ParentRecord = parentRecord;
                    return(dynamicService.Add(record, view.Schema.Name, tenantId, loggedUser, roleCode));
                }
                else if (allowUpdate)
                {
                    record.ParentRecord = parentRecord;
                    dynamicService.Update(record, view.Schema.CollectionName, view.Schema.Name, tenantId, loggedUser, roleCode);
                    return(record._id);
                }
                else
                {
                    return(ObjectId.Empty);
                }
            }
        }
Beispiel #15
0
 public static ObjectId DeepCreate(DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, string roleCode, IDynamicService <DynamicRecord> dynamicService, ISchemaService schemaService, bool allowUpdate = false)
 {
     return(DeepCreate(null, record, view, tenantId, loggedUser, roleCode, dynamicService, schemaService, allowUpdate));
 }
Beispiel #16
0
        public static ObjectId DeepCreate(DynamicRecord parentRecord, DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, IDynamicRepository dynamicRepository, Dictionary <string, SchemaView> views, bool allowUpdate = false)
        {
            var complexRecords = record.Values().Where(v => view.Schema.Attributes.ContainsKey(v.Key) && (view.Schema.Attributes[v.Key].IsComplex || view.Schema.Attributes[v.Key].IsSubCatalog));

            complexRecords.ToList().ForEach(r =>
            {
                var subcatalogView = views.FirstOrDefault(x => x.Key == string.Format("{0}.{1}.{2}", view.Schema.Attributes[r.Key].DataType, ViewCategory.Create.ToString(), "Default")).Value;  //this should go to cache all of the time, it would be expensive not to.

                // When manually creating an invoice, we need to check if Count > 0, otherwise FindExisting throws an exception
                if (r.Value is Dictionary <string, object> && ((Dictionary <string, object>)r.Value).Count > 0)
                {
                    var subRecord     = new DynamicRecord().Initialize <DynamicRecord>((Dictionary <string, object>)r.Value, null, ViewCategory.Create);
                    bool isValidInput = true;
                    subRecord._id     = FindExisting(subRecord, subcatalogView, tenantId, loggedUser, dynamicRepository, out isValidInput);
                    if (subcatalogView.Schema.AllowQuickCreate && subRecord._id == ObjectId.Empty && isValidInput)
                    {
                        ((Dictionary <string, object>)r.Value)["_id"] = DeepCreate(parentRecord ?? record, subRecord, subcatalogView, tenantId, loggedUser, dynamicRepository, views);
                    }
                    else if (subRecord._id != ObjectId.Empty)
                    {
                        ((Dictionary <string, object>)r.Value)["_id"] = subRecord._id;
                    }
                }
                else if (r.Value is List <Dictionary <string, object> > && ((List <Dictionary <string, object> >)r.Value).Count > 0)
                {
                    ((List <Dictionary <string, object> >)r.Value).ForEach(v =>
                    {
                        var newId = DeepCreate(parentRecord ?? record, new DynamicRecord().Initialize <DynamicRecord>(v, subcatalogView, ViewCategory.Create), subcatalogView, tenantId, loggedUser, dynamicRepository, views, true);
                        v["_id"]  = newId;
                    });
                }
            });

            if (record._id != ObjectId.Empty && allowUpdate)
            {
                record.ParentRecord = parentRecord;
                dynamicRepository.Edit(record, view.Schema.Name, tenantId, loggedUser, views);
                return(record._id);
            }
            else
            {
                var isValidInput = false;
                record._id = FindExisting(record, view, tenantId, loggedUser, dynamicRepository, out isValidInput);
                if (record._id == ObjectId.Empty)
                {
                    record.ParentRecord = parentRecord;
                    var returnId = dynamicRepository.AddReturnId(record, view.Schema.Name, tenantId, loggedUser, views);
                    return(new ObjectId(returnId));
                }
                else if (allowUpdate)
                {
                    record.ParentRecord = parentRecord;
                    dynamicRepository.Edit(record, view.Schema.Name, tenantId, loggedUser, views);
                    return(record._id);
                }
                else
                {
                    return(ObjectId.Empty);
                }
            }
        }
Beispiel #17
0
 public static ObjectId DeepCreate(DynamicRecord record, SchemaView view, ObjectId tenantId, ObjectId loggedUser, IDynamicRepository dynamicRepository, Dictionary <string, SchemaView> views, bool allowUpdate = false)
 {
     return(DeepCreate(null, record, view, tenantId, loggedUser, dynamicRepository, views, allowUpdate));
 }
 public XamlViewCommand(SchemaView sv)
     : base(sv)
 {
     _scView = sv;
 }
Beispiel #19
0
        public static void BreakGroup(SchemaView view)
        {
            Canvas  parent = (Canvas)view.MainPanel;
            Viewbox g      = view.SelectionManager.SelectedObjects[0] as Viewbox;

            try
            {
                Canvas gc = (Canvas)g.Child;

                while (gc.Children.Count > 0)
                {
                    System.Windows.FrameworkElement child = gc.Children[0] as System.Windows.FrameworkElement;

                    //this code need for ungrouping not stretched shapes
                    child.SetValue(System.Windows.Controls.Panel.MarginProperty, System.Windows.DependencyProperty.UnsetValue);
                    //Rect b=VisualTreeHelper.GetContentBounds(child);
                    Rect   b    = VisualTreeHelper.GetDescendantBounds(child);
                    double left = Canvas.GetLeft(child);
                    double top  = Canvas.GetTop(child);

                    left = double.IsNaN(left) ? 0 : left;
                    top  = double.IsNaN(top) ? 0 : top;


                    if ((child is Shape) && child.ReadLocalValue(System.Windows.Shapes.Shape.StretchProperty).Equals(System.Windows.DependencyProperty.UnsetValue))
                    {
                        child.Width  = b.Width;
                        child.Height = b.Height;
                        Canvas.SetLeft(child, left + b.X);
                        Canvas.SetTop(child, top + b.Y);


                        child.SetValue(System.Windows.Shapes.Shape.StretchProperty, System.Windows.Media.Stretch.Fill);
                        gc.UpdateLayout();
                    }
                    // excluding rotate from common matrix
                    // need to separate scale*skew matrix on scale and transform transformations

                    Matrix matrGtr = ((Transform)child.TransformToVisual(parent)).Value;


                    double x = matrGtr.OffsetX;
                    double y = matrGtr.OffsetY;

                    double angleY = Math.Atan(matrGtr.M12 / matrGtr.M11) * 180 / Math.PI;
                    matrGtr.OffsetY = 0; matrGtr.OffsetX = 0;

                    RotateTransform rt = new RotateTransform(angleY);
                    matrGtr.Rotate(-angleY);
                    TransformGroup gtr = new TransformGroup();
                    gtr.Children.Add(new MatrixTransform(matrGtr));
                    gtr.Children.Add(rt);
                    child.RenderTransform = gtr;

                    child.RenderTransformOrigin = new Point(0.5, 0.5);

                    Point pO = new Point(child.Width * child.RenderTransformOrigin.X, child.Height * child.RenderTransformOrigin.Y);
                    Point p  = gtr.Transform(pO);
                    Canvas.SetLeft(child, x - (pO - p).X);
                    Canvas.SetTop(child, y - (pO - p).Y);

                    gc.Children.Remove(child);
                    parent.Children.Add(child);
                    //tool.NotifyObjectCreated(child);
                }
                g.Child = null;
                //tool.NotifyObjectDeleted(g);
                parent.Children.Remove(g);
                view.SelectionManager.SelectObject(null);
            }
            catch (Exception)
            {
            }
        }