Ejemplo n.º 1
0
        private void Ctrl_ElementNew_Click(object sender, EventArgs e)
        {
            using (var transaction = Cl_App.m_DataContext.Database.BeginTransaction())
            {
                try
                {
                    Cl_EntityLog eLog       = new Cl_EntityLog();
                    Cl_Element   newElement = (Cl_Element)Activator.CreateInstance(typeof(Cl_Element));
                    eLog.f_SetEntity(newElement);
                    Cl_Group group = null;
                    if (p_SelectedGroup != null && p_SelectedGroup.p_Group != null)
                    {
                        group = p_SelectedGroup.p_Group;
                    }
                    Dlg_EditorElement dlg = new Dlg_EditorElement();
                    dlg.Text = "Новый элемент";
                    if (group != null)
                    {
                        newElement.p_ParentGroup  = p_SelectedGroup.p_Group;
                        dlg.ctrl_LGroupValue.Text = p_SelectedGroup.p_Group.p_Name;
                    }
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    newElement.p_Name        = dlg.ctrl_TBName.Text;
                    newElement.p_Comment     = dlg.ctrl_TBDecs.Text;
                    newElement.p_ElementType = (Cl_Element.E_ElementsTypes)dlg.ctrl_CB_ControlType.f_GetSelectedItem();
                    newElement.p_IsPartPre   = true;
                    if (dlg.ctrl_TBName.Text.Length > 0)
                    {
                        newElement.p_PartPre = dlg.ctrl_TBName.Text[0].ToString().ToUpper();
                        if (dlg.ctrl_TBName.Text.Length > 1)
                        {
                            newElement.p_PartPre += dlg.ctrl_TBName.Text.Substring(1, dlg.ctrl_TBName.Text.Length - 1);
                        }
                    }
                    newElement.p_SymmetryParamLeft  = "Слева";
                    newElement.p_SymmetryParamRight = "Справа";
                    Cl_App.m_DataContext.p_Elements.Add(newElement);

                    Cl_App.m_DataContext.SaveChanges();
                    newElement.p_ElementID = newElement.p_ID;
                    Cl_App.m_DataContext.SaveChanges();
                    eLog.f_SaveEntity(newElement);
                    transaction.Commit();

                    Ctrl_TreeNodeElement newNode = new Ctrl_TreeNodeElement(group, newElement);
                    SelectedNode.Nodes.Add(newNode);
                    SelectedNode = newNode;
                    e_AfterCreateElement?.Invoke(this, new TreeViewEventArgs(newNode));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    MonitoringStub.Error("Error_Tree", "При создании нового элемента произошла ошибка", ex, null, null);
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        private void Ctrl_ImageNew_Click(object sender, EventArgs e)
        {
            using (var transaction = Cl_App.m_DataContext.Database.BeginTransaction())
            {
                try
                {
                    Cl_EntityLog eLog = new Cl_EntityLog();

                    Cl_Element newElement = (Cl_Element)Activator.CreateInstance(typeof(Cl_Element));
                    eLog.f_SetEntity(newElement);
                    Cl_Group group = null;
                    if (p_SelectedGroup != null && p_SelectedGroup.p_Group != null)
                    {
                        group = p_SelectedGroup.p_Group;
                    }
                    Dlg_EditorImage dlg = new Dlg_EditorImage();
                    dlg.Text = "Новый рисунок";
                    if (group != null)
                    {
                        newElement.p_ParentGroup  = p_SelectedGroup.p_Group;
                        dlg.ctrl_LGroupValue.Text = p_SelectedGroup.p_Group.p_Name;
                    }
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }
                    newElement.p_Name        = dlg.ctrl_TBName.Text;
                    newElement.p_Comment     = dlg.ctrl_TBDecs.Text;
                    newElement.p_ElementType = Cl_Element.E_ElementsTypes.Image;
                    Cl_App.m_DataContext.p_Elements.Add(newElement);
                    Cl_App.m_DataContext.SaveChanges();
                    newElement.p_ElementID = newElement.p_ID;
                    Cl_App.m_DataContext.SaveChanges();
                    eLog.f_SaveEntity(newElement);
                    transaction.Commit();

                    Ctrl_TreeNodeElement newNode = new Ctrl_TreeNodeElement(group, newElement);
                    SelectedNode.Nodes.Add(newNode);
                    SelectedNode = newNode;
                    e_AfterCreateElement?.Invoke(this, new TreeViewEventArgs(newNode));
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    MonitoringStub.Error("Error_Tree", "При создании нового элемента произошла ошибка", ex, null, null);
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        protected override void f_TreeView_DragDrop(object sender, DragEventArgs e, Ctrl_TreeNodeGroup a_TargetNodeGroup)
        {
            if (a_TargetNodeGroup != null)
            {
                using (var transaction = Cl_App.m_DataContext.Database.BeginTransaction())
                {
                    try
                    {
                        Ctrl_TreeNodeElement draggedNodeElement = (Ctrl_TreeNodeElement)e.Data.GetData(typeof(Ctrl_TreeNodeElement));
                        if (e.Effect == DragDropEffects.Move)
                        {
                            Cl_EntityLog eLog = new Cl_EntityLog();
                            eLog.f_SetEntity(draggedNodeElement.p_Element);

                            var elsDraggeds = Cl_App.m_DataContext.p_Elements.Where(el => el.p_ElementID == draggedNodeElement.p_Element.p_ElementID);
                            if (elsDraggeds != null)
                            {
                                bool isChange = false;
                                foreach (Cl_Element el in elsDraggeds)
                                {
                                    //el.p_ParentGroupID = a_TargetNodeGroup.p_Group.p_ID;
                                    el.p_ParentGroup = a_TargetNodeGroup.p_Group;
                                    isChange         = true;
                                }
                                if (isChange)
                                {
                                    Cl_App.m_DataContext.SaveChanges();
                                    eLog.f_SaveEntity(draggedNodeElement.p_Element);
                                    transaction.Commit();
                                    draggedNodeElement.Remove();
                                    a_TargetNodeGroup.Nodes.Insert(f_GetFirstGroupInNode(a_TargetNodeGroup.Nodes), draggedNodeElement);
                                }
                            }
                            else
                            {
                                MonitoringStub.Error("Error_Tree", "Не найдена элемент для шаблонов", new Exception("EX ERROR"), "elsDraggeds = null", null);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        MonitoringStub.Error("Error_Tree", "При перемещении элемента произошла ошибка", ex, null, null);
                        return;
                    }
                }
            }
        }
        private void f_DragNewElement(Ctrl_TreeNodeElement a_NodeElement, int a_PosX, int a_PosY)
        {
            if (a_NodeElement == null)
            {
                return;
            }
            if (a_NodeElement.p_Element == null)
            {
                return;
            }

            Ctrl_Element ctrlEl = new Ctrl_Element();

            ctrlEl.p_Element    = a_NodeElement.p_Element;
            ctrlEl.Name         = f_CreateName(ctrlEl.p_Name);
            this.InsertionIndex = Items.Count - 1;
            Items.Add(ctrlEl);
            this.Invalidate(this.InsertionIndex);
            this.InsertionIndex = InvalidIndex;
            ctrlMenuDel.Visible = Items.Count > 0;
        }
        protected override void OnDragDrop(DragEventArgs drgevent)
        {
            string[] formats = drgevent.Data.GetFormats();
            foreach (string format in formats)
            {
                var item = drgevent.Data.GetData(format);
                if (item is Ctrl_TreeNodeElement || item is Ctrl_TreeNodeTemplate)
                {
                    if (item is Ctrl_TreeNodeElement)
                    {
                        Ctrl_TreeNodeElement nodeEl = (Ctrl_TreeNodeElement)item;
                        if (f_HasElement(nodeEl.p_Element) || nodeEl.p_Element.p_Version == 0)
                        {
                            MonitoringStub.Warning("Элемент уже в шаблоне");
                            return;
                        }
                    }
                    else if (item is Ctrl_TreeNodeTemplate)
                    {
                        Ctrl_TreeNodeTemplate nodeTemp = (Ctrl_TreeNodeTemplate)item;
                        if (f_HasElement(nodeTemp.p_Template) || nodeTemp.p_Template.p_Version == 0)
                        {
                            MonitoringStub.Warning("Элемент уже в шаблоне");
                            return;
                        }
                    }
                }
            }

            if (this.IsDragging)
            {
                try
                {
                    if (this.InsertionIndex != InvalidIndex)
                    {
                        int dragIndex;
                        int dropIndex;

                        dragIndex = (int)drgevent.Data.GetData(typeof(int));
                        dropIndex = this.InsertionIndex;

                        if (dragIndex < dropIndex)
                        {
                            dropIndex--;
                        }
                        if (this.InsertionMode == I_InsertionMode.After && dragIndex < this.Items.Count - 1)
                        {
                            dropIndex++;
                        }

                        if (dropIndex != dragIndex)
                        {
                            //Point clientPoint = this.PointToClient(new Point(drgevent.X, drgevent.Y));
                            //args = new ListBoxItemDragEventArgs(dragIndex, dropIndex, this.InsertionMode, clientPoint.X, clientPoint.Y);
                            //this.OnItemDrag(args);
                            //if (!args.Cancel)
                            {
                                object dragItem;
                                dragItem = this.Items[dragIndex];
                                this.Items.Remove(dragIndex);
                                this.Items.Insert(dropIndex, dragItem);
                                this.SelectedItem = dragItem;
                            }
                        }
                    }
                }
                finally
                {
                    this.Invalidate(this.InsertionIndex);
                    this.InsertionIndex = InvalidIndex;
                    this.InsertionMode  = I_InsertionMode.None;
                    this.IsDragging     = false;
                }
            }
            else
            {
                if (drgevent.Data.GetData(drgevent.Data.GetFormats()[0]) is Ctrl_TreeNodeElement)
                {
                    f_DragNewElement(drgevent.Data.GetData(drgevent.Data.GetFormats()[0]) as Ctrl_TreeNodeElement, drgevent.X, drgevent.Y);
                }
                else if (drgevent.Data.GetData(drgevent.Data.GetFormats()[0]) is Ctrl_TreeNodeTemplate)
                {
                    f_DragNewTemplate(drgevent.Data.GetData(drgevent.Data.GetFormats()[0]) as Ctrl_TreeNodeTemplate, drgevent.X, drgevent.Y);
                }
            }

            base.OnDragDrop(drgevent);
        }