protected override SelectQuery ProcessQuery(SelectQuery selectQuery) { if (selectQuery.IsInsert && selectQuery.Insert.Into.Name == "Parent") { var expr = new QueryVisitor().Find(selectQuery.Insert, e => { if (e.ElementType == QueryElementType.SetExpression) { var se = (SelectQuery.SetExpression)e; return ((SqlField)se.Column).Name == "ParentID"; } return false; }) as SelectQuery.SetExpression; if (expr != null) { var value = ConvertTo<int>.From(((IValueContainer)expr.Expression).Value); if (value == 555) { var tableName = "Parent1"; var dic = new Dictionary<IQueryElement,IQueryElement>(); selectQuery = new QueryVisitor().Convert(selectQuery, e => { if (e.ElementType == QueryElementType.SqlTable) { var oldTable = (SqlTable)e; if (oldTable.Name == "Parent") { var newTable = new SqlTable(oldTable) { Name = tableName, PhysicalName = tableName }; foreach (var field in oldTable.Fields.Values) dic.Add(field, newTable.Fields[field.Name]); return newTable; } } IQueryElement ex; return dic.TryGetValue(e, out ex) ? ex : null; }); } } } return selectQuery; }
private void Clone(Dictionary<MapNode, MapNode> originalToClone) { //Add yourself to lookup MapNode thisClone; if (!originalToClone.TryGetValue(this, out thisClone)) //Determines if this MapNode has been visited yet { thisClone = new MapNode(this.Color); originalToClone.Add(this, thisClone); //Add neighbors to lookup foreach (MapNode neighbor in _neighbors) { neighbor.Clone(originalToClone); //guarentees the neighbor will be in the lookup MapNode neighborClone = originalToClone[neighbor]; if (!thisClone._neighbors.Contains(neighborClone)) thisClone._neighbors.Add(neighborClone); } } }
public void CategoryLoad(DataTable dt) { Dictionary<int, string> dicCategoryMap = new Dictionary<int, string>(); if (File.Exists(_categoryMapFilePath)) { IEnumerable<string> listCategoryMap = File.ReadLines(_categoryMapFilePath); string[] columns; foreach (string categoryMap in listCategoryMap) { columns = categoryMap.Split('|'); dicCategoryMap.Add(int.Parse(columns[0]), columns[1]); } } _indexId = dt.Columns.IndexOf("CID"); _indexName = dt.Columns.IndexOf("CName"); _indexFolderName = dt.Columns.IndexOf("FolderName"); _indexParentId = dt.Columns.IndexOf("FID"); _indexType = dt.Columns.IndexOf("CType"); _indexIsExistVideo = dt.Columns.IndexOf("IsVideo"); _indexIsExistVector = dt.Columns.IndexOf("IsVector"); _indexStoreTableName = dt.Columns.IndexOf("DataTable"); _indexIsDetail = dt.Columns.IndexOf("IsDetail"); Category categoryRoot = new Category(); categoryRoot.Id = 0; categoryRoot.LevelPath = string.Empty; categoryRoot.LevelCategory = string.Empty; categoryRoot.FolderName = string.Empty; string localDirectoryPath; dicCategoryMap.TryGetValue(categoryRoot.Id, out localDirectoryPath); categoryRoot.LocalDirectoryPath = localDirectoryPath; TreeNode nodeRoot = new TreeNode(); nodeRoot.ImageIndex = (int)ImageIndex.Root; nodeRoot.SelectedImageIndex = (int)ImageIndex.Root; nodeRoot.Text = "分类目录"; nodeRoot.Expand(); nodeRoot.Tag = categoryRoot; _treeCategory.Nodes.Clear(); _treeCategory.Nodes.Add(nodeRoot); GreateTree(dt, "0", nodeRoot, ref dicCategoryMap); }
/// <summary> /// Import a CSV file which contains Chapter Names /// </summary> /// <param name="dataChpt"> /// The DataGridView Control /// </param> /// <param name="filename"> /// The filepath and name /// </param> /// <returns>A Populated DataGridView</returns> public static DataGridView ImportChapterNames(DataGridView dataChpt, string filename) { IDictionary<int, string> chapterMap = new Dictionary<int, string>(); try { StreamReader sr = new StreamReader(filename); string csv = sr.ReadLine(); while (csv != null) { if (csv.Trim() != string.Empty) { csv = csv.Replace("\\,", "<!comma!>"); string[] contents = csv.Split(','); int chapter; int.TryParse(contents[0], out chapter); chapterMap.Add(chapter, contents[1].Replace("<!comma!>", ",")); } csv = sr.ReadLine(); } } catch (Exception) { return null; } foreach (DataGridViewRow item in dataChpt.Rows) { string name; chapterMap.TryGetValue((int)item.Cells[0].Value, out name); item.Cells[1].Value = name ?? "Chapter " + item.Cells[0].Value; } return dataChpt; }
private void GreateTree(DataTable dt, string parentId, TreeNode parentNode, ref Dictionary<int, string> dicCategoryMap) { DataView dv = new DataView(dt); dv.RowFilter = "FID = '" + parentId + "'"; foreach (DataRowView drv in dv) { Category category = new Category(); category.Id = Convert.ToInt32(drv[_indexId]); category.Name = drv[_indexName].ToString(); category.FolderName = drv[_indexFolderName].ToString(); category.ParentId = Convert.ToInt32(drv[_indexParentId]); category.Type = (CategoryType)Convert.ToByte(drv[_indexType]); category.IsExistVideo = Convert.ToBoolean(drv[_indexIsExistVideo]); category.IsThumbSquare = Convert.ToBoolean(drv[_indexIsExistVector]); category.StoreTableName = drv[_indexStoreTableName].ToString(); category.IsDetail = Convert.ToBoolean(drv[_indexIsDetail]); category.LevelPath = (parentNode.Tag as Category).LevelPath + "|" + category.FolderName; category.LevelCategory = (parentNode.Tag as Category).LevelCategory + "_" + category.Name; string localDirectoryPath; dicCategoryMap.TryGetValue(category.Id, out localDirectoryPath); category.LocalDirectoryPath = localDirectoryPath; int indexImage = (int)ImageIndex.UnKnowType; if (string.IsNullOrEmpty(category.LocalDirectoryPath) || !Directory.Exists(category.LocalDirectoryPath)) { indexImage = (int)ImageIndex.NoBind; } else if (category.Type == CategoryType.Picture) { indexImage = category.IsDetail ? (int)ImageIndex.PictureDetail : (int)ImageIndex.Picture; } else if (category.Type == CategoryType.Gallery) { indexImage = category.IsDetail ? (int)ImageIndex.GalleryDetail : (int)ImageIndex.Gallery; } TreeNode newTreeNode = new TreeNode(); newTreeNode.ImageIndex = indexImage; newTreeNode.SelectedImageIndex = indexImage; newTreeNode.Text = category.Name; newTreeNode.Tag = category; parentNode.Nodes.Add(newTreeNode); GreateTree(dt, category.Id.ToString(), newTreeNode, ref dicCategoryMap); } }