/* * 初始化文件文件夹树 */ private void StorageImage_InitFolder() { //1.初始化页面树 StorageImageFolder storageImageFolder = storageImageFolderBll.get(1); if (storageImageFolder == null) { return; } TreeViewItem firstItem = new TreeViewItem(); firstItem.IsExpanded = true; firstItem.Header = storageImageFolder.name; firstItem.Tag = storageImageFolder.id; firstItem.Padding = new Thickness(5); StorageImage_GetTreeViewItemChildren(firstItem); //添加单击、右键事件 folderTreeColumn.MouseLeftButtonUp += (object sender, MouseButtonEventArgs e) => StorageImage_TreeView_MouseLeftButtonUp(sender, e); folderTreeColumn.Items.Clear(); folderTreeColumn.Items.Add(firstItem); }
/* * 初始化页面列表 */ private void initCombox() { StorageImageFolder firstFolder = storageImageFolderBll.get(1); if (firstFolder == null) { return; } ComboBoxItem defaultItem = new ComboBoxItem(); defaultItem.Content = "-- 请选择 --"; defaultItem.Tag = 0; defaultItem.IsSelected = true; moveToFolderId.Items.Add(defaultItem); ComboBoxItem firstItem = new ComboBoxItem(); firstItem.Content = firstFolder.name; firstItem.Tag = firstFolder.id; moveToFolderId.Items.Add(firstItem); int level = 0; getTreeViewItemChildren(firstItem, level, 0); }
/* * 获取要删除的图片 */ private void getPageNameForDelete() { StorageImageFolder storageImageFolder = storageImageFolderBll.get(folderId); if (storageImageFolder != null) { pageName.Content = storageImageFolder.name; } }
//页面居中显示到最前面 public StorageImageRenameFolderWindow(TreeView pageTreeColumn, Int32 folderId) { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; this.pageTreeColumn = pageTreeColumn; thatFolderId = folderId; StorageImageFolder thatFolder = storageImageFolderBll.get(thatFolderId); foldername.Text = thatFolder.name; }
/* * 获取最后一个文件夹 */ public StorageImageFolder getLastFolder() { String sql = "select * from storageImageFolder order by id desc limit 0,1"; SQLiteParameter[] parameters = { }; DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters); StorageImageFolder entity = DataToEntity <StorageImageFolder> .FillModel(dt.Rows[0]); return(entity); }
public StorageImageNewFolderWindow(TreeView folderTreeColumn, Int32 parentId) { InitializeComponent(); //this.folderTreeColumn = folderTreeColumn; this.folderTreeColumn = folderTreeColumn; this.parentId = parentId; StorageImageFolder lastFolder = storageImageFolderBll.getLastFolder(); Int32 maxFolderId = lastFolder.id + 1; pagename.Text = "新文件夹" + maxFolderId; WindowStartupLocation = WindowStartupLocation.CenterScreen; }
/* * 获取父栏目中最大的排序号 */ public StorageImageFolder getMaxIdxByParentId(int parentId) { String sql = "select max(idx) as idx from storageImageFolder where parentId=@parentId"; SQLiteParameter[] parameters = { new SQLiteParameter("@parentId", DbType.Int32, 4) }; parameters[0].Value = parentId; DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters); StorageImageFolder entity = DataToEntity <StorageImageFolder> .FillModel(dt.Rows[0]); return(entity); }
/* * 将新添加的页面加入到页面树中 */ private void updateToTree(ItemsControl tree, StorageImageFolder storageVideoFolder) { foreach (TreeViewItem item in tree.Items) { Int32 pageId = (Int32)item.Tag; if (thatFolderId == pageId) { item.Header = storageVideoFolder.name; break; } else { updateToTree(item, storageVideoFolder); } } }
/* * 插入子文件夹 */ public StorageImageFolder insertChild(StorageImageFolder tmp) { //补充idx,createTime两个参数 StorageImageFolder maxFolder = getMaxIdxByParentId(tmp.parentId); if (maxFolder == null) { tmp.idx = 1; } else { tmp.idx = maxFolder.idx + 1; } return(storageImageFolderDal.insert(tmp)); }
/* * 是否存在同名文件夹 */ public int hasSameName(StorageImageFolder entity) { string sql = "select count(*) from storageImageFolder where name=@name and id!=@id"; SQLiteParameter[] parameters = { new SQLiteParameter("@name", DbType.String, 30), new SQLiteParameter("@id", DbType.Int32, 4) }; parameters[0].Value = entity.name; parameters[1].Value = entity.id; object obj = Common.SQLiteHelper.ExecuteScalar(sql, parameters); int result = int.Parse(obj.ToString()); return(result); }
/* * 插入一个文件夹 */ public StorageImageFolder insert(StorageImageFolder entity) { String sql = "insert into storageImageFolder(name,parentId,idx) values(@name,@parentId,@idx);select last_insert_rowid();"; SQLiteParameter[] parameters = { new SQLiteParameter("@name", DbType.String, 100), new SQLiteParameter("@parentId", DbType.Int32, 4), new SQLiteParameter("@idx", DbType.Int32, 4) }; parameters[0].Value = entity.name; parameters[1].Value = entity.parentId; parameters[2].Value = entity.idx; DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters); int id = DataType.ToInt32(dt.Rows[0]["last_insert_rowid()"].ToString()); entity.id = id; return(entity); }
/* * 更新 */ public int update(StorageImageFolder entity) { string sql = "update storageImageFolder set name=@name,parentId=@parentId,idx=@idx" + " where id=@id"; SQLiteParameter[] parameters = { new SQLiteParameter("@name", DbType.String, 100), new SQLiteParameter("@parentId", DbType.Int32, 4), new SQLiteParameter("@idx", DbType.Int32, 4), new SQLiteParameter("@id", DbType.Int32, 4) }; parameters[0].Value = entity.name; parameters[1].Value = entity.parentId; parameters[2].Value = entity.idx; parameters[3].Value = entity.id; int result = Common.SQLiteHelper.ExecuteNonQuery(sql, parameters); return(result); }
/* * 获取文件夹 */ public StorageImageFolder get(int id) { String sql = "select * from storageImageFolder where id=@id"; SQLiteParameter[] parameters = { new SQLiteParameter("@id", DbType.Int32, 4) }; parameters[0].Value = id; DataTable dt = Common.SQLiteHelper.ExecuteQuery(sql, parameters); if (dt == null || dt.Rows.Count == 0) { return(null); } StorageImageFolder storageImageFolder = DataToEntity <StorageImageFolder> .FillModel(dt.Rows[0]); return(storageImageFolder); }
/* * 保存数据 */ private void Button_Click(object sender, RoutedEventArgs e) { StorageImageFolder storageImageFolder = storageImageFolderBll.get(thatFolderId); storageImageFolder.name = foldername.Text; if (string.IsNullOrWhiteSpace(storageImageFolder.name)) { MessageBox.Show("请填写文件夹名称"); return; } //Boolean b = storageImageFolderBll.hasSameName(storageImageFolder); //if (b) //{ // MessageBox.Show("文件夹名称重复,请更换"); // return; //} storageImageFolder = storageImageFolderBll.update(storageImageFolder); updateToTree(pageTreeColumn, storageImageFolder); Close(); }
private void Submit_Button_Click(object sender, RoutedEventArgs e) { StorageImageFolder tmp = new StorageImageFolder(); tmp.name = pagename.Text; tmp.parentId = parentId; if (string.IsNullOrWhiteSpace(tmp.name)) { MessageBox.Show("请填写页面名称"); return; } else if (tmp.parentId == 0) { MessageBox.Show("父页面不存在,请重试"); return; } tmp = storageImageFolderBll.insertChild(tmp); insertToTree(folderTreeColumn, tmp); Close(); }
/* * 将新添加的页面加入到页面树中 */ private void insertToTree(ItemsControl itemsControl, StorageImageFolder folder) { foreach (TreeViewItem item in itemsControl.Items) { Int32 folderId = (Int32)item.Tag; if (parentId == folderId) { TreeViewItem newItem = new TreeViewItem(); newItem.Header = folder.name; newItem.Tag = folder.id; newItem.Padding = new Thickness(5); // newItem.Foreground = Brushes.White; item.Items.Add(newItem); newItem.BringIntoView(); break; } else { insertToTree(item, folder); } } }
/* * 是否存在同名文件夹 */ public bool hasSameName(StorageImageFolder storageImageFolder) { int rows = storageImageFolderDal.hasSameName(storageImageFolder); return(rows > 0 ? true : false); }
/* * 更新 */ public StorageImageFolder update(StorageImageFolder storageImageFolder) { int rows = storageImageFolderDal.update(storageImageFolder); return(storageImageFolder); }