private void Yes_Click(object sender, RoutedEventArgs e)
        {
            TagBean bean = DataContext as TagBean;

            bean.Name  = bean.Name.Trim();
            bean.Color = bean.Color.Trim();
            if (bean.Name == string.Empty)
            {
                MessageBox.Show("名称不得为空", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            else if (bean.Name.Length > 30)
            {
                MessageBox.Show("名称过长", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            if (bean.Color == string.Empty)
            {
                bean.Color = "#FFFFFF";
            }
            bool isColorTrue = bean.Color.Length == 7;

            isColorTrue = isColorTrue && bean.Color[0] == '#';
            if (isColorTrue)
            {
                try
                {
                    ColorUtil.GetRGB(bean.Color);
                    DialogResult = true;
                    Close(); return;
                }
                catch { }
            }
            MessageBox.Show("颜色代码格式错误", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
        }
        /// <summary>
        /// 修改或新添标签标注
        /// </summary>
        /// <param name="path">标注路径</param>
        /// <param name="isNew">是否是新建</param>
        public static void AllOrEditTag(string path, bool isNew)
        {
            SelectTagWindow window       = new SelectTagWindow();
            bool?           dialogResult = window.ShowDialog();

            if (dialogResult == true)
            {
                TagBean tagBean = window.tagBean;
                if (tagBean.Id == 0)
                {
                    DirTagMapper.DeleteOneByPath(path);
                }
                if (isNew)
                {
                    DirTagMapper.AddOne(new DirTagBean()
                    {
                        Path  = path,
                        TagId = tagBean.Id,
                    });
                }
                else
                {
                    DirTagMapper.EditOneByPath(path, tagBean.Id);
                }
                //刷新标签缓存
                TagSupport.SetTagSort();
            }
        }
Beispiel #3
0
        //修改标签
        private void EditTag_Click(object sender, RoutedEventArgs e)
        {
            MainWindow  main = Application.Current.MainWindow as MainWindow;
            ListBoxItem item = GetSender(sender) as ListBoxItem;
            //获取bean
            TagBean bean = item.Content as TagBean;

            main.tagPage.EditTag_Click(bean);
        }
Beispiel #4
0
        //修改标签
        public void EditTag_Click(TagBean bean)
        {
            TagWindow window = new TagWindow("修改标签", bean);
            bool?     result = window.ShowDialog();

            if (result == true)
            {
                TagMapper.UpdataOne(bean);
                RefreshAll();
            }
        }
Beispiel #5
0
 /// <summary>
 /// 添加一行数据
 /// </summary>
 /// <param name="bean">对应的数据实体</param>
 public static void AddOne(TagBean bean)
 {
     using (SQLiteCommand cmd = new SQLiteCommand())
     {
         cmd.CommandText = "INSERT INTO [tag] ([parent_id], [name], [color]) VALUES (@parent_id, @name, @color);";
         cmd.Parameters.Add("parent_id", DbType.UInt32).Value = bean.ParentId;
         cmd.Parameters.Add("name", DbType.String).Value      = bean.Name;
         cmd.Parameters.Add("color", DbType.String).Value     = bean.Color;
         SQLiteClient.Write(cmd);
     }
 }
Beispiel #6
0
 /// <summary>
 /// 更新已有标签
 /// </summary>
 /// <param name="bean">对应的数据实体</param>
 public static void UpdataOne(TagBean bean)
 {
     using (SQLiteCommand cmd = new SQLiteCommand())
     {
         cmd.CommandText = "UPDATE [tag] SET [name]=@name, [color]=@color WHERE [id]=@id;";
         cmd.Parameters.Add("id", DbType.UInt32).Value    = bean.Id;
         cmd.Parameters.Add("name", DbType.String).Value  = bean.Name;
         cmd.Parameters.Add("color", DbType.String).Value = bean.Color;
         SQLiteClient.Write(cmd);
     }
 }
Beispiel #7
0
        //删除标签
        private void DeleteTag_Click(object sender, RoutedEventArgs e)
        {
            MainWindow  main = Application.Current.MainWindow as MainWindow;
            ListBoxItem item = GetSender(sender) as ListBoxItem;
            TagBean     bean = item.Content as TagBean;
            //通过ListBoxItem获取ListBox
            DependencyObject parent = VisualTreeHelper.GetParent(item);

            while (!(parent is ListBox))
            {
                parent = VisualTreeHelper.GetParent(parent);
            }
            main.tagPage.DeleteTag_Click(bean.Id, parent as ListBox);
        }
Beispiel #8
0
 //将表格转换为bean
 private static TagBean[] GetBeanListByTable(DataTable table)
 {
     TagBean[] list = new TagBean[table.Rows.Count];
     for (int i = 0; i < table.Rows.Count; i++)
     {
         uint    parentId = table.Rows[i]["parent_id"] is DBNull ? 0 : Convert.ToUInt32(table.Rows[i]["parent_id"]);
         TagBean bean     = new TagBean()
         {
             Id       = Convert.ToUInt32(table.Rows[i]["id"]),
             ParentId = parentId,
             Name     = table.Rows[i]["name"] as string,
             Color    = table.Rows[i]["color"] as string,
         };
         list[i] = bean;
     }
     return(list);
 }
Beispiel #9
0
        //标签的点击事件
        private void Tag_Selected(object sender, SelectionChangedEventArgs e)
        {
            ListBox node = sender as ListBox;

            if (node.SelectedItem == null)
            {
                return;
            }
            //获取bean
            TagBean bean = node.SelectedItem as TagBean;

            //刷新标签栏
            selectedTagId = bean.Id;
            int plies = GetPliesByName(node.Name);

            switch (plies)
            {
            case 0:
                if (nodeParentId[1] == selectedTagId)
                {
                    return;
                }
                nodeParentId[1] = selectedTagId;
                nodeParentId[2] = -1;
                RefreshAll();
                break;

            case 1:
                if (nodeParentId[2] == selectedTagId)
                {
                    return;
                }
                nodeParentId[2] = selectedTagId;
                RefreshAll();
                break;

            case 2:
                nodeParentId[3] = selectedTagId;
                break;

            default: break;
            }
            //刷新地址栏
            tagName.Text         = string.Concat('[', bean.Name, "]所标注的地址:");
            pathList.ItemsSource = TagService.GetPathItemSource(selectedTagId);
        }
 public TagWindow(string title, TagBean bean = null)
 {
     InitializeComponent();
     Title = title;
     WindowStartupLocation = WindowStartupLocation.CenterScreen;
     if (bean == null)
     {
         DataContext = new TagBean()
         {
             Name = string.Empty, Color = string.Empty
         }
     }
     ;
     else
     {
         DataContext = bean;
     }
 }
        public static void RefreshNode(ref DirNode dirNode)
        {
            //刷新标签
            TagBean tagBean = TagSupport.GetTagByPath(dirNode.Path, out bool isThis);

            if (tagBean == null)
            {
                dirNode.Tag = new TagBean()
                {
                    Color = "#FFFFFF"
                }
            }
            ;
            dirNode.IsRootTag = isThis;
            dirNode.Tag       = tagBean;
            //刷新子节点
            BuildNodeTree.BuildChildrenNodes(dirNode);
        }
Beispiel #12
0
    public static TagBean Get(string id)
    {
        if (string.IsNullOrEmpty(id))
        {
            return(null);
        }

        TagBean tag = null;

        if (_tags.ContainsKey(id))
        {
            tag = _tags[id];
        }
        else
        {
            tag = Create(id, "");
        }

        return(tag);
    }
Beispiel #13
0
        //新建标签
        public void NewTag_Click(ListBox sender)
        {
            int plies = GetPliesByName(sender.Name);

            if (nodeParentId[plies] == -1)
            {
                MessageBox.Show("未选择父级标签", "提示", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                return;
            }
            uint      patentId = Convert.ToUInt32(nodeParentId[plies]);
            TagWindow window   = new TagWindow("新建标签");
            bool?     result   = window.ShowDialog();

            if (result == true)
            {
                TagBean bean = window.DataContext as TagBean;
                bean.ParentId = patentId;
                TagMapper.AddOne(bean);
                RefreshAll();
            }
        }
Beispiel #14
0
    public static TagBean Create(string id, string name = "")
    {
        if (string.IsNullOrEmpty(id))
        {
            return(null);
        }

        TagBean tag = null;

        if (_tags.ContainsKey(id))
        {
            tag       = _tags[id];
            tag._id   = id;
            tag._name = name;
        }
        else
        {
            _tags.Add(id, new TagBean(id, name));
        }

        return(tag);
    }
 //确定
 private void Yes_Click(object sender, RoutedEventArgs e)
 {
     tagBean      = (tagTree.SelectedItem as TagNode)?.Tag;
     DialogResult = true;
     Close();
 }
Beispiel #16
0
        /// <summary>
        /// 建立该节点的子节点
        /// </summary>
        /// <param name="node">文件夹节点</param>
        public static void BuildChildrenNodes(DirNode node)
        {
            //获取对应节点下的文件夹列表
            RecordBean[] oldBeans;
            if (node.OldIncidentId == 0)
            {
                oldBeans = new RecordBean[0];
            }
            else
            {
                oldBeans = RecordMapper.GetBeansByPid(node.OldId, node.OldIncidentId);
            }
            RecordBean[] newBeans;
            if (node.NewIncidentId == 0)
            {
                newBeans = new RecordBean[0];
            }
            else
            {
                newBeans = RecordMapper.GetBeansByPid(node.NewId, node.NewIncidentId);
            }
            List <DirNode> dirNodes = new List <DirNode>();

            //遍历两个文件夹列表
            foreach (RecordBean oldBean in oldBeans)
            {
                RecordBean newBean = null;
                //去除重复项
                for (int i = 0; i < newBeans.Length; i++)
                {
                    if (newBeans[i] == null)
                    {
                        continue;
                    }
                    if (oldBean.Path == newBeans[i].Path)
                    {
                        newBean     = newBeans[i];
                        newBeans[i] = null;
                    }
                }
                //建立node
                DirNode dirNode = new DirNode()
                {
                    Name = oldBean.Name,
                    Path = oldBean.Path,
                    // 放入一个空数组,告知页面该节点可以展开
                    Children = oldBean.DirCount > 0 ? new DirNode[1] : null,
                };
                SetOldId(ref dirNode, oldBean, node.OldIncidentId);
                //设置类型
                if (newBean != null)
                {
                    SetNewId(ref dirNode, newBean, node.NewIncidentId);
                    if (oldBean.Equals(newBean))
                    {
                        dirNode.Type = DirNodeType.Unchanged;
                    }
                    else
                    {
                        dirNode.Type = DirNodeType.Changed;
                    }
                }
                else
                {
                    dirNode.Type = DirNodeType.Deleted;
                }
                dirNodes.Add(dirNode);
            }
            //新纪录中新增的部分
            foreach (RecordBean newBean in newBeans)
            {
                if (newBean == null)
                {
                    continue;
                }
                DirNode dirNode = new DirNode()
                {
                    Name     = newBean.Name,
                    Path     = newBean.Path,
                    Children = newBean.DirCount > 0 ? new DirNode[1] : null,
                    //新增的节点
                    Type = DirNodeType.Added,
                };
                SetNewId(ref dirNode, newBean, node.NewIncidentId);
                dirNodes.Add(dirNode);
            }
            //添加标签
            TagBean nullTag = new TagBean()
            {
                Color = "#FFFFFF"
            };

            foreach (DirNode dirNode in dirNodes)
            {
                TagBean tagBean = TagSupport.GetTagByPath(dirNode.Path, out bool isThis);
                if (tagBean == null)
                {
                    dirNode.Tag = nullTag;
                    continue;
                }
                dirNode.IsRootTag = isThis;
                dirNode.Tag       = tagBean;
            }
            node.Children = dirNodes.ToArray();
        }
 //删除标签
 private void Null_Click(object sender, RoutedEventArgs e)
 {
     tagBean      = new TagBean();
     DialogResult = true;
 }