/// <summary> /// Take a dictionary, inspect the inner types of the resultant anonymous object, and make a DataTable object. /// </summary> /// <param name="d">A Dictionary<string, Part> of Part values, with their name as keys.</param> /// <param name="cd">An active CutlistData object.</param> /// <returns>A DataTable object.</returns> private static DataTable DictToPartList(Dictionary <string, Part> d, CutlistData cd) { List <object> lp = new List <object>(); DataTable dt = new DataTable(); foreach (KeyValuePair <string, Part> p in d) { Part i = p.Value; var o = new { Part = i.PartNumber, Description = i.Description, Qty = i.Qty, Material = cd.GetMaterialByID(i.MaterialID.ToString()), L = i.Length, W = i.Width, T = i.Thickness, BlankQty = i.BlankQty, OverL = i.OverL, OverW = i.OverW, CNC1 = i.CNC1, CNC2 = i.CNC2, Op1 = cd.GetOpAbbreviationByID(i.get_OpID(0).ToString()), Op2 = cd.GetOpAbbreviationByID(i.get_OpID(1).ToString()), Op3 = cd.GetOpAbbreviationByID(i.get_OpID(2).ToString()), Op4 = cd.GetOpAbbreviationByID(i.get_OpID(3).ToString()), Op5 = cd.GetOpAbbreviationByID(i.get_OpID(4).ToString()), EdgeFront = cd.GetEdgeByID(i.EdgeFrontID.ToString()), EdgeBack = cd.GetEdgeByID(i.EdgeBackID.ToString()), EdgeLeft = cd.GetEdgeByID(i.EdgeLeftID.ToString()), EdgeRight = cd.GetEdgeByID(i.EdgeRightID.ToString()), Comment = i.Comment, Deptartment = cd.GetDeptByID((int)i.DepartmentID), Update = i.UpdateCNC ? "Yes" : "No" }; lp.Add(o); } // Wow, reflection! Fancy! C++ can't do this (yet). System.Reflection.PropertyInfo[] props = lp[0].GetType().GetProperties(); foreach (var prop in props) { dt.Columns.Add(prop.Name); } foreach (var item in lp) { var values = new object[props.Length]; for (var i = 0; i < props.Length; i++) { values[i] = props[i].GetValue(item, null); } dt.Rows.Add(values); } return(dt); }
/// <summary> /// Take a dictionary, inspect the inner types of the resultant anonymous object, and make a DataTable object. /// </summary> /// <param name="d">A Dictionary<string, Part> of Part values, with their name as keys.</param> /// <param name="cd">An active CutlistData object.</param> /// <returns>A DataTable object.</returns> private static DataTable DictToPartList(Dictionary<string, Part> d, CutlistData cd) { List<object> lp = new List<object>(); DataTable dt = new DataTable(); foreach (KeyValuePair<string, Part> p in d) { Part i = p.Value; var o = new { Part = i.PartNumber, Description = i.Description, Qty = i.Qty, Material = cd.GetMaterialByID(i.MaterialID.ToString()), L = i.Length, W = i.Width, T = i.Thickness, BlankQty = i.BlankQty, OverL = i.OverL, OverW = i.OverW, CNC1 = i.CNC1, CNC2 = i.CNC2, Op1 = cd.GetOpAbbreviationByID(i.get_OpID(0).ToString()), Op2 = cd.GetOpAbbreviationByID(i.get_OpID(1).ToString()), Op3 = cd.GetOpAbbreviationByID(i.get_OpID(2).ToString()), Op4 = cd.GetOpAbbreviationByID(i.get_OpID(3).ToString()), Op5 = cd.GetOpAbbreviationByID(i.get_OpID(4).ToString()), EdgeFront = cd.GetEdgeByID(i.EdgeFrontID.ToString()), EdgeBack = cd.GetEdgeByID(i.EdgeBackID.ToString()), EdgeLeft = cd.GetEdgeByID(i.EdgeLeftID.ToString()), EdgeRight = cd.GetEdgeByID(i.EdgeRightID.ToString()), Comment = i.Comment, Deptartment = cd.GetDeptByID((int)i.DepartmentID), Update = i.UpdateCNC ? "Yes" : "No" }; lp.Add(o); } // Wow, reflection! Fancy! C++ can't do this (yet). System.Reflection.PropertyInfo[] props = lp[0].GetType().GetProperties(); foreach (var prop in props) { dt.Columns.Add(prop.Name); } foreach (var item in lp) { var values = new object[props.Length]; for (var i = 0; i < props.Length; i++) { values[i] = props[i].GetValue(item, null); } dt.Rows.Add(values); } return dt; }