Пример #1
0
        public iImage NewImage(iTable header, string imagePath)
        {
            iImage column = new iImage();

            column.SetImage(imagePath);
            header.Columns.Add(column);
            return(column);
        }
Пример #2
0
        public bool RemoveImage(iTable header, iImage col)
        {
            var colCount = header.Columns.Count;

            header.Columns.Remove(col);
            if (header.Columns.Count == colCount - 1)
            {
                return(true);
            }
            return(false);
        }
Пример #3
0
        void menuItem_Click(object sender, EventArgs e)

        {
            try
            {
                TreeNode      selectedNod = treeView1.SelectedNode;
                var           tag         = selectedNod.Tag;
                ToolStripItem menuItem    = (ToolStripItem)sender;

                if (menuItem.Name == "AddTable")

                {
                    if (tag != null)
                    {
                        if (tag.GetType().Equals(typeof(ArrayList)))
                        {
                            var parent   = (ArrayList)tag;
                            var newtable = inv.NewTable(parent);
                            var newnod   = selectedNod.Nodes.Add("Table");
                            newnod.Tag             = newtable;
                            treeView1.SelectedNode = newnod;
                            newnod.EnsureVisible();
                            treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                            return;
                        }
                        if (tag.GetType().Equals(typeof(iTable)))
                        {
                            var parent   = (iTable)tag;
                            var newtable = inv.NewTable(parent.Columns);
                            var newnod   = selectedNod.Nodes.Add("Table");
                            newnod.Tag             = newtable;
                            treeView1.SelectedNode = newnod;
                            newnod.EnsureVisible();
                            treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                            return;
                        }
                    }
                }
                if (menuItem.Name == "AddCellColumn")
                {
                    iTable header = treeView1.SelectedNode.Tag as iTable;
                    if (header != null)
                    {
                        var col    = inv.NewColumn(header);
                        var newnod = selectedNod.Nodes.Add(col.Text);
                        newnod.Tag             = col;
                        treeView1.SelectedNode = newnod;
                        newnod.EnsureVisible();
                        treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                        //LoadTree();
                    }
                }
                if (menuItem.Name == "AddCellImage")
                {
                    iTable header = treeView1.SelectedNode.Tag as iTable;
                    if (header != null)
                    {
                        string filename = GetImageFile();
                        if (filename == "")
                        {
                            return;
                        }
                        var col    = inv.NewImage(header, filename);
                        var newnod = selectedNod.Nodes.Add("Image");
                        newnod.Tag             = col;
                        treeView1.SelectedNode = newnod;
                        newnod.EnsureVisible();
                        treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                        //LoadTree();
                    }
                }
                if (menuItem.Name == "RemoveTable")
                {
                    var    currenNod = treeView1.SelectedNode;
                    iTable header    = currenNod.Tag as iTable;
                    var    parentNod = currenNod.Parent;
                    var    parent    = parentNod.Tag;
                    if (header != null)
                    {
                        if (parent.GetType().Equals(typeof(iTable)))
                        {
                            if (inv.RemoveTable(header, ((iTable)parent).Columns) == true)
                            {
                                currenNod.Remove();
                            }
                        }
                        else
                        {
                            if (inv.RemoveTable(header, parent) == true)
                            {
                                currenNod.Remove();
                            }
                        }

                        //LoadTree();
                    }
                }
                if (menuItem.Name == "RemoveCellColumn")
                {
                    var     currenNod    = treeView1.SelectedNode;
                    iColumn headerColumn = currenNod.Tag as iColumn;
                    iTable  header       = currenNod.Parent.Tag as iTable;
                    if (header != null)
                    {
                        if (headerColumn != null)
                        {
                            if (inv.RemoveColumn(header, headerColumn) == true)
                            {
                                currenNod.Remove();
                                var newnod = treeView1.SelectedNode;
                                treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                                //LoadTree();
                            }
                        }
                    }
                }

                if (menuItem.Name == "RemoveCellImage")
                {
                    var    currenNod    = treeView1.SelectedNode;
                    iImage headerColumn = currenNod.Tag as iImage;
                    iTable header       = currenNod.Parent.Tag as iTable;
                    if (header != null)
                    {
                        if (headerColumn != null)
                        {
                            if (inv.RemoveImage(header, headerColumn) == true)
                            {
                                currenNod.Remove();
                                var newnod = treeView1.SelectedNode;
                                treeView1_NodeMouseClick(treeView1, new TreeNodeMouseClickEventArgs(newnod, MouseButtons.Left, 1, 0, 0));
                                //LoadTree();
                            }
                        }
                    }
                }

                if (menuItem.Name == "Cut")
                {
                    var currenNod = treeView1.SelectedNode;
                    if (currenNod.Tag == null)
                    {
                        CutItem = null; return;
                    }
                    ;

                    var    parrentNod  = currenNod.Parent;
                    iTable parentTable = parrentNod.Tag as iTable;
                    if (parentTable == null)
                    {
                        return;
                    }
                    var ind = parentTable.Columns.IndexOf(currenNod.Tag);

                    CutItem = new CutObject()
                    {
                        CutNode = currenNod, CutObjIndex = ind, CutParentobj = parentTable
                    };
                }

                if (menuItem.Name == "Paste")
                {
                    var currenNod = treeView1.SelectedNode;
                    if (currenNod.Tag == null)
                    {
                        throw new Exception("selected item is null");
                    }
                    if (CutItem == null)
                    {
                        throw new Exception("Cut item not found");
                    }
                    var parentNod  = treeView1.SelectedNode.Parent;
                    var parentItem = parentNod.Tag;
                    if (parentItem == null)
                    {
                        throw new Exception("Parent is not found");
                    }
                    //if (parentNod.Text == "Data") throw new Exception("Data section cannot be pasted");
                    //if (!CutItem.CutObj.GetType().Equals(currenNod.Tag.GetType())) throw new Exception("Cut item and paste item do not match");
                    var CutObj = CutItem.CutParentobj.Columns[CutItem.CutObjIndex];
                    if (CutObj.GetType().Equals(typeof(iColumn)) || CutObj.GetType().Equals(typeof(iTable)))
                    {
                        if (CutObj.GetType().Equals(typeof(iTable)) && (parentNod.Text == "Detail Header" || parentNod.Text == "Detail Footer" || parentNod.Text == "Data"))
                        {
                            throw new Exception("Table cannot be paste here");
                        }
                        //{
                        var parenttbl = parentItem as iTable;
                        if (parenttbl == null)
                        {
                            throw new Exception("Parent is not a table");
                        }

                        CutItem.CutParentobj.Columns.RemoveAt(CutItem.CutObjIndex);
                        var arrayIndex = parenttbl.Columns.IndexOf(currenNod.Tag);
                        parenttbl.Columns.Insert(arrayIndex, CutObj);
                        var    nodIndex    = selectedNod.Index;
                        string text        = CutObj.GetType().Equals(typeof(iColumn)) ? ((iColumn)CutObj).Text : "Table";
                        var    insertedNod = parentNod.Nodes.Insert(nodIndex, text);
                        insertedNod.Tag = CutObj;
                        CutItem.CutNode.Parent.Nodes.Remove(CutItem.CutNode);
                        CutItem = null;

                        //}
                    }

                    //if (currenNod.Tag.GetType().Equals(typeof(iTable)))
                    //{
                    //    CutObject = currenNod.Tag as iTable;
                    //}
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }