/// <summary>
        /// Perform undo of this command.
        /// </summary>
        public override void Undo()
        {
            //create a new group
            GroupShape group = new GroupShape(this.Controller.Model);

            //asign the entities to the group
            group.Entities = bundle.Entities;

            foreach (IDiagramEntity entity in group.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = group;
            }
            //add the new group to the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);

            mGroup = group;

            //select the newly created group
            CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>();

            col.Add(mGroup);
            this.Controller.Model.Selection.SelectedItems = col;
            mGroup.Invalidate();
        }
        /// <summary>
        /// Perform redo of this command.
        /// </summary>
        public override void Redo()
        {
            //create a new group; use the standard GroupShape or the CollapsibleGroupShape for a painted group with collapse/expand features.
            //GroupShape group = new GroupShape(this.Controller.Model);
            CollapsibleGroupShape group = new CollapsibleGroupShape(this.controller.Model);
            //asign the entities to the group
            group.Entities.Clear();

            foreach (IDiagramEntity entity in bundle.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = group;
                group.Entities.Add(entity);
            }
            //add the new group to the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);

            mGroup = group;

            //select the newly created group
            CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>();
            col.Add(mGroup);
            Selection.SelectedItems = col;
            mGroup.Invalidate();
        }
        /// <summary>
        /// Perform redo of this command.
        /// </summary>
        public override void Redo()
        {
            //create a new group; use the standard GroupShape or the CollapsibleGroupShape for a painted group with collapse/expand features.
            //GroupShape group = new GroupShape(this.Controller.Model);
            //CollapsibleGroupShape group = new CollapsibleGroupShape(this.controller.Model);
            GroupShape group = new GroupShape(this.controller.Model);

            //asign the entities to the group
            group.Entities.Clear();

            foreach (IDiagramEntity entity in bundle.Entities)
            {
                //this will be recursive if an entity is itself an IGroup
                entity.Group = group;
                group.Entities.Add(entity);
            }
            //add the new group to the layer
            this.Controller.Model.AddEntity(group);

            mGroup = group;

            //select the newly created group
            CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>();

            col.Add(mGroup);
            this.Controller.Model.Selection.SelectedItems = col;
            mGroup.Invalidate();
        }
Beispiel #4
0
        private void ResetItems()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }
            if (ListItems.Count > 0)
            {
                foreach (var item in ListItems)
                {
                    item.IsSelectedChanged -= item_IsSelectedChanged;
                }
                ListItems.Clear();
            }
            if (string.IsNullOrEmpty(SettingType))
            {
                return;
            }
            var setting = UISettings.Current.Items[SettingType];

            if (setting != null && (setting is UISelectSetting))
            {
                var selectSetting = setting as UISelectSetting;

                _CanEdit            = selectSetting.CanUserInput;
                _IsMutiSelect       = selectSetting.CanMutiSelect;
                comboBox.IsEditable = _CanEdit;

                var selects = GetTextItems();
                foreach (var setitem in selectSetting.Items)
                {
                    var item = new UISelectSettingItem
                    {
                        SettingItem = setitem,
                        IsSelected  = selects.FirstOrDefault(s => s.Equals(setitem.Name, StringComparison.OrdinalIgnoreCase)) != null
                    };
                    item.IsSelectedChanged += item_IsSelectedChanged;
                    ListItems.Add(item);
                }
            }
            else
            {
                var selectSetting = new UISelectSetting
                {
                    TargetType    = SettingType,
                    CanMutiSelect = true,
                    CanUserInput  = true,
                    Description   = "自动创建"
                };
                _CanEdit            = selectSetting.CanUserInput;
                _IsMutiSelect       = selectSetting.CanMutiSelect;
                comboBox.IsEditable = _CanEdit;
                UISettings.Current.AddSetting(selectSetting);
            }
        }
Beispiel #5
0
        public Page(string name)
        {
            mLayers = new CollectionBase<ILayer>();

            //the one and only and indestructible layer
            mDefaultLayer = new Layer("Default Layer");
            mDefaultLayer.OnEntityAdded += new EventHandler<EntityEventArgs>(defaultLayer_OnEntityAdded);
            mDefaultLayer.OnEntityRemoved += new EventHandler<EntityEventArgs>(mDefaultLayer_OnEntityRemoved);
            mDefaultLayer.OnClear += new EventHandler(mDefaultLayer_OnClear);
            mLayers.Add(mDefaultLayer);

            mName = name;
        }
Beispiel #6
0
        ///<summary>
        ///Default constructor
        ///</summary>
        public Page(string name, IModel model)
        {
            this.mModel = model;

            mName = name;
            mAmbience = new Ambience(this);

            //the one and only and indestructible layer

            mLayers = new CollectionBase<ILayer>();
            mLayers.Add(new Layer("Default Layer"));

            Init();
        }
Beispiel #7
0
        /// <summary>
        /// Creates a new bundle using a given collection of diagram entities.
        /// </summary>
        /// <param name="collection"></param>
        public Bundle(CollectionBase<IDiagramEntity> collection)
        {
            mEntities = new CollectionBase<IDiagramEntity>();
            //we could assign it directly but let's make sure the collection does not
            //contain unwanted elements
            foreach (IDiagramEntity entity in collection)
            {
                if ((entity is IShape) || (entity is IConnection) || (entity is IGroup))
                    mEntities.Add(entity);
            }

            //the following line would give problem. The event handler attached to the Selection would be triggered when
            //the mEntities collection is changed!
            //mEntities = collection;
        }
Beispiel #8
0
    /// <summary>
    /// Depth-first traversal of an <see cref="IGroup"/>
    /// </summary>
    /// <param name="group"></param>
    /// <param name="collection"></param>
    public static void TraverseCollect(IGroup group, ref CollectionBase<IDiagramEntity> collection) {
      #region Checks
      if (group == null)
        throw new InconsistencyException("Cannot collect entities of a 'null' IGroup");
      if (collection == null)
        throw new InconsistencyException("You need to instantiate a collection before using this method.");
      #endregion

      foreach (IDiagramEntity entity in group.Entities) {
        if (entity is IGroup)
          TraverseCollect(entity as IGroup, ref collection);
        else
          collection.Add(entity);
      }

    }
        /// <summary>
        /// Perform undo of this command.
        /// </summary>
        public override void Undo()
        {
            if (mGroup.CanUnGroup == false)
            {
                return;
            }

            //remove the group from the layer
            this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup);

            // keep track of the entities removed.
            CollectionBase <IDiagramEntity> removedItems =
                new CollectionBase <IDiagramEntity>();

            int numberOfItems = mGroup.Entities.Count;

            //detach the entities from the group
            for (int i = 0; i < numberOfItems; numberOfItems--)
            {
                IDiagramEntity entity = mGroup.Entities[0];
                //this will be recursive if an entity is itself an IGroup
                entity.Group = null;
                mGroup.Entities.Remove(entity);
                Controller.Model.AddEntity(entity);
                entity.Invalidate();
                removedItems.Add(entity);
            }
            //change the visuals such that the entities in the group are selected
            this.Controller.Model.Selection.SelectedItems = removedItems;
            //mGroup.Entities.Clear();

            //mGroup.Invalidate();

            mGroup = null;

            //note that the entities have never been disconnected from the layer
            //so they don't have to be re-attached to the anything.
            //The insertion of the Group simply got pushed in the scene-graph.
        }
Beispiel #10
0
        public Model()
        {
            mAmbience = new Ambience(this);
            //listen to events
            AttachToAmbience(mAmbience);

            //here I'll have to work on the scene graph
            this.mShapes = new ShapeCollection();

            //the page collection
            mPages = new CollectionBase<IPage>();

            //the default page
            mDefaultPage = new Page("Default Page");
            mDefaultPage.OnEntityAdded += new EventHandler<EntityEventArgs>(mDefaultPage_OnEntityAdded);
            mDefaultPage.OnEntityRemoved += new EventHandler<EntityEventArgs>(mDefaultPage_OnEntityRemoved);
            mDefaultPage.OnClear += new EventHandler(mDefaultPage_OnClear);
            mPages.Add(mDefaultPage);
            //initially the current page is the one and only default page
            mCurrentPage = mDefaultPage;

            //the paintables
            mPaintables = new CollectionBase<IDiagramEntity>();
        }
        private CollectionBase<INode> sortedChildren(INode n)
        {
            double basevalue = 0;
            // update basevalue angle for node ordering
            INode p = n.ParentNode;
            if (p != null)
            {
                basevalue = normalize(Math.Atan2(p.Y - n.Y, p.X - n.X));
            }
            int cc = n.ChildCount;
            if (cc == 0) return null;

            INode c = (INode)n.FirstChild;

            // TODO: this is hacky and will break when filtering
            // how to know that a branch is newly expanded?
            // is there an alternative property we should check?
            //if ( !c.isStartVisible() )
            //{
            //    // use natural ordering for previously invisible nodes
            //    return n.Children;
            //}

            double[] angle = new double[cc];
            int[] idx = new int[cc];
            for (int i = 0; i < cc; ++i, c = c.NextSibling)
            {
                idx[i] = i;
                angle[i] = normalize(-basevalue + Math.Atan2(c.Y - n.Y, c.X - n.X));
            }

            Array.Sort(angle, idx);//or is it the other way around
            CollectionBase<INode> col = new CollectionBase<INode>();
            CollectionBase<INode> children = n.Children;
            for (int i = 0; i < cc; ++i)
            {
                col.Add(children[idx[i]]);
            }
            return col;

            // return iterator over sorted children
            //return new Iterator() {
            //    int cur = 0;
            //    public Object next() {
            //        return n.getChild(idx[cur++]);
            //    }
            //    public bool hasNext() {
            //        return cur < idx.Length;
            //    }
            //    public void remove() {
            //        throw new UnsupportedOperationException();
            //    }
            //};
        }
Beispiel #12
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Sets the current page.
    /// </summary>
    /// <param name="page">The page.</param>
    // ------------------------------------------------------------------
    public void SetCurrentPage(IPage page) {
      mCurrentPage = page;
      RaiseOnAmbienceChanged(new AmbienceEventArgs(page.Ambience));
      RaiseOnCurrentPageChanged(new PageEventArgs(page));

      //change the paintables as well            
      //Paintables = new CollectionBase<IDiagramEntity>();

      #region Reload of the z-order, usually only necessary after deserialization

      CollectionBase<IDiagramEntity> collected = new CollectionBase<IDiagramEntity>();
      //pick up the non-group entities
      foreach (IDiagramEntity entity in Paintables)
        if (!typeof(IGroup).IsInstanceOfType(entity))
          collected.Add(entity);

      if (collected.Count > 0) {
        Algorithms.SortInPlace<IDiagramEntity>(collected, new SceneIndexComparer<IDiagramEntity>());
        //Paintables.AddRange(collected);
      }
      #endregion

    }
Beispiel #13
0
    // ------------------------------------------------------------------
    /// <summary>
    /// Default constructor
    /// </summary>
    // ------------------------------------------------------------------
    public Model() {
      //here I'll have to work on the scene graph
      //this.mShapes = new CollectionBase<IShape>();
      //the default page

      //the page collection
      mPages = new CollectionBase<IPage>();
      Page p = new Page("Default Page", this);
      p.Ambience.PageColor = ArtPalette.DefaultPageColor;
      mPages.Add(p);

      Init();
    }
Beispiel #14
0
    /// <summary>
    /// Perform undo of this command.
    /// </summary>
    public override void Undo() {
      if (mGroup.CanUnGroup == false) {
        return;
      }

      //remove the group from the layer
      this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup);

      // keep track of the entities removed.
      CollectionBase<IDiagramEntity> removedItems =
          new CollectionBase<IDiagramEntity>();

      int numberOfItems = mGroup.Entities.Count;
      //detach the entities from the group
      for (int i = 0; i < numberOfItems; numberOfItems--) {
        IDiagramEntity entity = mGroup.Entities[0];
        //this will be recursive if an entity is itself an IGroup
        entity.Group = null;
        mGroup.Entities.Remove(entity);
        Controller.Model.AddEntity(entity);
        entity.Invalidate();
        removedItems.Add(entity);
      }
      //change the visuals such that the entities in the group are selected
      this.Controller.Model.Selection.SelectedItems = removedItems;
      //mGroup.Entities.Clear();

      //mGroup.Invalidate();

      mGroup = null;

      //note that the entities have never been disconnected from the layer
      //so they don't have to be re-attached to the anything.
      //The insertion of the Group simply got pushed in the scene-graph.


    }
Beispiel #15
0
        public static ExcelImportResult OnExecute(string fileName)
        {
            var importResult = new ExcelImportResult();
            var items        = new List <object>();
            //手动加个数据测试
            ExcelToSql  excelConfig = new ExcelToSql();
            ExcelSource source      = new ExcelSource();

            source.SheetName   = "用户清单";
            excelConfig.Source = source;
            SqlTarget target    = new SqlTarget();
            SqlConfig sqlConfig = new SqlConfig();

            sqlConfig.CommandName = "ImportRecord";
            sqlConfig.GroupName   = "系统安全";
            sqlConfig.TableName   = "[dbo].[sys_User]";
            //SqlItem sqlItem1 = new SqlItem();
            sqlConfig.Parameters = null;
            target.SqlRowImport  = sqlConfig;
            excelConfig.Target   = target;

            ImportSource importSource = new ImportSource();

            importSource.RowFrom  = 2;
            importSource.TitleRow = 1;
            CollectionBase <ImportField> fieldList = new CollectionBase <ImportField>();
            ImportField field1 = new ImportField();

            field1.Name = "UserID"; field1.IsRequired = true; field1.Title = "用户ID"; field1.AllowEmpty = false;
            //importField.Converter = string.Empty; importField.ConverterParameter = string.Empty;暂时不考虑转换
            ImportField field2 = new ImportField();

            field2.Name = "UserName"; field2.IsRequired = true; field2.Title = "登录名"; field2.AllowEmpty = false;
            ImportField field3 = new ImportField();

            field3.Name = "FullName"; field3.IsRequired = true; field3.Title = "用户名"; field3.AllowEmpty = false;
            ImportField field4 = new ImportField();

            field4.Name = "Email"; field4.IsRequired = true; field4.Title = "邮箱"; field4.AllowEmpty = false;
            ImportField field5 = new ImportField();

            field5.Name = "IsValid"; field5.IsRequired = true; field5.Title = "是否有效"; field5.AllowEmpty = false;
            fieldList.Add(field1); fieldList.Add(field2); fieldList.Add(field3); fieldList.Add(field4); fieldList.Add(field5);
            importSource.Fields = fieldList;


            Dictionary <string, ExcelToSql> directory = new Dictionary <string, ExcelToSql>();//根据sheetName判断调用哪个配置参数,系统初始读取不同配置加载到内存,静态全局
            Dictionary <string, string>     parameter = new Dictionary <string, string>();

            directory.Add(source.SheetName, excelConfig);
            //检查配置是否完整

            //读文件
            string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=NO;IMEX=0'";

            using (OleDbConnection myConn = new OleDbConnection(strCon))
            {
                DataTable dtTable = new DataTable();
                try
                {
                    myConn.Open();
                    System.Data.DataTable dt = myConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                    foreach (DataRow row in dt.Rows)                     //多少个sheets
                    {
                        string sheetName = row["TABLE_NAME"].ToString(); //sheetName
                        string name      = sheetName.TrimEnd(new char[] { '$' });
                        if (!directory.ContainsKey(name))
                        {
                            throw new Exception("上传文件工作表名和配置项不对应");
                        }
                        ExcelToSql config = directory[name];

                        var sqlItem = config.Target.SqlRowImport.SqlItem;
                        if (sqlItem == null)
                        {
                            throw new Exception("SQL配置不存在");
                        }
                        var conn = SqlData.Current.Connections[sqlItem.ConnectionName];
                        if (conn == null)
                        {
                            throw new Exception("数据连接不存在");
                        }
                        string           commandText = "select * from [" + sheetName + "]";//SQL语句
                        OleDbDataAdapter odp         = new OleDbDataAdapter(commandText, myConn);
                        odp.Fill(dtTable);
                        var           rows             = dtTable.Rows;
                        var           columns          = dtTable.Columns;
                        int           fromIndex        = config.Source.RowFrom;                                  //table内容行
                        int           titleRowNumber   = config.Source.TitleRow;                                 //table标题行
                        var           requiredFields   = config.Source.Fields.Where(x => x.IsRequired);
                        var           allowEmptyFields = config.Source.Fields.Where(x => x.AllowEmpty == false); //允许为空应该是判断不允许为空字段值
                        List <string> titles           = new List <string>();
                        for (int i = 0; i < columns.Count; i++)
                        {
                            string titleName = rows[titleRowNumber][i].ToString();//读取标题行
                            titles.Add(titleName);
                        }

                        foreach (var importField in requiredFields)//标题Title限制条件,不符合直接取消导入
                        {
                            if (!titles.Contains(importField.Title))
                            {
                                throw new Exception("上传文件工作表字段格式错误");
                            }
                        }

                        for (int i = fromIndex; i < rows.Count; i++)//内容是否允许不为空判断,逻辑todo
                        {
                            for (int j = 0; j < columns.Count; j++)
                            {
                                string value = rows[i][j].ToString();
                                foreach (var importField in allowEmptyFields)//判断每个Name限制条件,不符合直接取消导入
                                {
                                    if (!importField.AllowEmpty && value.IsNullOrEmpty())
                                    {
                                    }
                                }
                                parameter.Add(columns[j].ToString(), value);
                                items.Add(parameter);//添加sql参数
                            }
                        }

                        //开始导入:导入需要一个较长的时间
                        using (var db = conn.Open())
                        {
                            using (var trans = db.BeginTransaction())
                            {
                                try
                                {
                                    foreach (var item in items)
                                    {
                                        var count = (int)db.ExecuteScalar(sqlItem, items.ToArray());
                                        //0、不更新;1、新增成功;2、更新成功;
                                        switch (count)
                                        {
                                        case 0:
                                            importResult.CancelCount += 1;
                                            break;

                                        case 1:
                                            importResult.InsertCount += 1;
                                            break;

                                        case 2:
                                            importResult.UpdateCount += 1;
                                            break;
                                        }
                                    }
                                    trans.Commit();
                                }
                                catch
                                {
                                    trans.Rollback();
                                    throw;
                                }
                            }
                        }//结束导入
                    }
                }
                catch (Exception ex)
                {
                    dtTable = new DataTable();
                }
            }
            return(importResult);
        }
Beispiel #16
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public Model()
        {
            //here I'll have to work on the scene graph
            //this.mShapes = new CollectionBase<IShape>();
            //the default page
            
            //the page collection
            mPages = new CollectionBase<IPage>();
            mPages.Add(new Page("Default Page", this));

            Init();
        }
    /// <summary>
    /// Perform undo of this command.
    /// </summary>
    public override void Undo() {

      //create a new group
      GroupShape group = new GroupShape(this.Controller.Model);
      //asign the entities to the group
      group.Entities = bundle.Entities;

      foreach (IDiagramEntity entity in group.Entities) {
        //this will be recursive if an entity is itself an IGroup
        entity.Group = group;
      }
      //add the new group to the layer
      this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group);

      mGroup = group;

      //select the newly created group
      CollectionBase<IDiagramEntity> col = new CollectionBase<IDiagramEntity>();
      col.Add(mGroup);
      this.Controller.Model.Selection.SelectedItems = col;
      mGroup.Invalidate();


    }
Beispiel #18
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public Model()
        {
            //here I'll have to work on the scene graph
            //this.mShapes = new CollectionBase<IShape>();
            //the default page
            
            //the page collection
            mPages = new CollectionBase<IPage>();
            mPages.Add(new Page("Default Page", this));

            mConnectorHolders = new Dictionary<IConnector, IDiagramEntity>();

            Init();
        }