Просмотр исходного кода

excel操作如果不存在cell,需要create

tanghai 12 лет назад
Родитель
Сommit
086e73e545

+ 11 - 5
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -6,6 +6,7 @@ using System.IO;
 using System.Windows;
 using Infrastructure;
 using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
 
 namespace Robot
 {
@@ -138,8 +139,9 @@ namespace Robot
 				{ "套装", 26 },
 			};
 
-			HSSFWorkbook hssfWorkbook = null;
-			using (var file = new FileStream("F:\\MallItemProto.xls", FileMode.Open, FileAccess.Read))
+			HSSFWorkbook hssfWorkbook;
+			const string path = @"F:\MallItemProto.xls";
+			using (var file = new FileStream(path, FileMode.Open, FileAccess.Read))
 			{
 				hssfWorkbook = new HSSFWorkbook(file);
 			}
@@ -159,13 +161,17 @@ namespace Robot
 					continue;
 				}
 				var name = row.GetCell(nameIndex).ToString();
-				if (dict.ContainsKey(name))
+
+				if (!dict.ContainsKey(name))
 				{
-					row.GetCell(nameIndex - 1).SetCellValue(dict[name].ToString());
+					continue;
 				}
+
+				ICell cell = row.GetCell(nameIndex - 1) ?? row.CreateCell(nameIndex - 1);
+				cell.SetCellValue(dict[name].ToString());
 			}
 
-			using (var file = new FileStream("F:\\MallItemProto.xls", FileMode.Open, FileAccess.Write))
+			using (var file = new FileStream(path, FileMode.Open, FileAccess.Write))
 			{
 				hssfWorkbook.Write(file);
 			}

+ 1 - 1
CSharp/App/Modules/Tree/BehaviorTreeView.xaml.cs

@@ -38,7 +38,7 @@ namespace Tree
 		private void MenuNewNode_Executed(object sender, ExecutedRoutedEventArgs e)
 		{
 			Point point = Mouse.GetPosition(this.listBox);
-			var treeNode = new TreeNode(point.X, point.Y);
+			var treeNode = new TreeNode{ X = point.X, Y = point.Y};
 
 			// one root node
 			if (this.ViewModel.TreeNodes.Count == 0)

+ 16 - 6
CSharp/App/Modules/Tree/TreeNode.cs

@@ -1,17 +1,27 @@
-namespace Tree
+using System.Collections.Generic;
+
+namespace Tree
 {
 	public class TreeNode
 	{
-		public TreeNode(double x, double y)
-		{
-			this.X = x;
-			this.Y = y;
-		}
+		private readonly List<int> childIds = new List<int>();
 
 		public double X { get; set; }
 
 		public double Y { get; set; }
 
 		public int Type { get; set; }
+
+		public int Id { get; set; }
+
+		public int ParentId { get; set; }
+
+		public List<int> ChildIds
+		{
+			get
+			{
+				return this.childIds;
+			}
+		}
 	}
 }

+ 16 - 6
CSharp/App/Modules/Tree/TreeNodeViewModel.cs

@@ -1,4 +1,6 @@
-using System.Collections.ObjectModel;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using Microsoft.Practices.Prism.ViewModel;
 
 namespace Tree
@@ -7,8 +9,8 @@ namespace Tree
 	{
 		private static int globalNum;
 		private readonly int num;
-		private const double width = 80;
-		private const double height = 50;
+		private static double width = 80;
+		private static double height = 50;
 		private readonly TreeNode treeNode;
 		private double connectorX2;
 		private double connectorY2;
@@ -51,6 +53,10 @@ namespace Tree
 			{
 				return width;
 			}
+			set
+			{
+				width = value;
+			}
 		}
 
 		public static double Height
@@ -59,6 +65,10 @@ namespace Tree
 			{
 				return height;
 			}
+			set
+			{
+				height = value;
+			}
 		}
 
 		public bool IsRoot
@@ -101,7 +111,7 @@ namespace Tree
 			}
 			set
 			{
-				if (this.treeNode.X == value)
+				if (Math.Abs(this.treeNode.X - value) < 0.1)
 				{
 					return;
 				}
@@ -125,7 +135,7 @@ namespace Tree
 			}
 			set
 			{
-				if (this.treeNode.Y == value)
+				if (Math.Abs(this.treeNode.Y - value) < 0.1)
 				{
 					return;
 				}
@@ -161,7 +171,7 @@ namespace Tree
 		{
 			get
 			{
-				return this.IsRoot? width / 2 : this.connectorX2;
+				return this.IsRoot? Width / 2 : this.connectorX2;
 			}
 			set
 			{