public static string RenderSection(PartPackage partPack, SectionPackage[] sectionPacks) { ItemPackage inner_pack = MakeInner(partPack, sectionPacks); partPack["ItemTemplate"] = Properties.Resources.SingleContents; partPack["PartTemplate"] = Properties.Resources.StandardPart; return RenderPart(partPack, new ItemPackage[] { inner_pack }); }
public static string RenderSection(SectionPackage[] items, int depth) { string sectionName = DepthToSectionName(depth); PartPackage pack = new PartPackage(sectionName); pack["PartTemplate"] = Properties.Resources.SectionPart; pack["ItemTemplate"] = Properties.Resources.SectionItem; pack["Depth"] = depth.ToString(); pack["Indent"] = AddIndent(depth); return StandardPart.RenderPart(pack, items); }
public static string RenderTest(PartPackage partPack, PackageBase[] itemPacks, string renderType) { partPack["PartTemplate"] = Properties.Resources.StandardPart; switch (renderType) { case "StandardItem": partPack["ItemTemplate"] = Properties.Resources.StandardItem; break; case "DerivateItem": partPack["ItemTemplate"] = Properties.Resources.DerivateItem; break; case "Caption": partPack["ItemTemplate"] = Properties.Resources.Caption; break; } return RenderPart(partPack, itemPacks); }
public string SavePackage(int packageID = 0, int partID = 0, double weight = 0, double height = 0, double width = 0, double length = 0, int qty = 1, int weightUnit = 0, int heightUnit = 0, int widthUnit = 0, int lengthUnit = 0, int qtyUnit = 0, int type = 1) { try { PartPackage package = new PartPackage(); package = ProductModels.SavePackage(packageID, partID, weight, height, width, length, qty, weightUnit, heightUnit, qtyUnit, type); JsonSerializerSettings settings = new JsonSerializerSettings(); settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; Newtonsoft.Json.Formatting format = Newtonsoft.Json.Formatting.None; return JsonConvert.SerializeObject(package, format, settings); } catch (Exception e) { return "{\"error\":\"" + e.Message + "\"}"; } }
public static PartPackage GetPackage(int packageID) { PartPackage package = new PartPackage(); try { CurtDevDataContext db = new CurtDevDataContext(); package = (from pp in db.PartPackages where pp.ID.Equals(packageID) select pp).FirstOrDefault<PartPackage>(); } catch (Exception e) { } return package; }
public static string DeletePackage(int packageID) { CurtDevDataContext db = new CurtDevDataContext(); PartPackage package = new PartPackage(); try { package = (from p in db.PartPackages where p.ID.Equals(packageID) select p).First<PartPackage>(); UpdatePart(package.partID); db.PartPackages.DeleteOnSubmit(package); db.SubmitChanges(); } catch { } return ""; }
public static PartPackage SavePackage(int packageID = 0, int partID = 0, double weight = 0, double height = 0, double width = 0, double length = 0, int qty = 1, int weightUnit = 0, int dimensionUnit = 0, int qtyUnit = 0, int type = 1) { CurtDevDataContext db = new CurtDevDataContext(); PartPackage package = new PartPackage(); // Validate the price information if (partID == 0) throw new Exception("Part ID is invalid."); if (weight == 0) throw new Exception("Weight is required."); if (qty <= 0) throw new Exception("Quantity is required."); if (weightUnit == 0) throw new Exception("Weight Unit is required."); if (dimensionUnit == 0) throw new Exception("Dimensional Unit is required."); if (qtyUnit == 0) throw new Exception("Package Unit is required."); if (type <= 0) throw new Exception("Package Type is required."); if (packageID == 0) { // Create new price object package = new PartPackage { partID = partID, weight = weight, width = (width > 0) ? width : (double?)null, height = (height > 0) ? height : (double?)null, length = (length > 0) ? length : (double?)null, quantity = qty, weightUOM = weightUnit, dimensionUOM = dimensionUnit, packageUOM = qtyUnit, typeID = type }; db.PartPackages.InsertOnSubmit(package); db.SubmitChanges(); } else { // Get the price record that we will update package = (from p in db.PartPackages where p.ID.Equals(packageID) select p).FirstOrDefault<PartPackage>(); // Make sure we found the price if (package.partID > 0) { package.weight = weight; package.width = (width > 0) ? width : (double?)null; package.height = (height > 0) ? height : (double?)null; package.length = (length > 0) ? length : (double?)null; package.quantity = qty; package.weightUOM = weightUnit; package.dimensionUOM = dimensionUnit; package.packageUOM = qtyUnit; package.typeID = type; db.SubmitChanges(); } else { throw new Exception("Failed to update package."); } } UpdatePart(partID); return package; }
private static ItemPackage MakeInner(PartPackage partPack, SectionPackage[] sectionPacks) { int depth = 0; if (partPack.ContainsKey("Depth")) { depth = int.Parse(partPack["Depth"]) + 1; } ItemPackage inner_pack = new ItemPackage(partPack["ClassIdentifier"]); inner_pack["Contents"] = SectionPart.RenderSection(sectionPacks, depth); return inner_pack; }
private static string RenderItemAsIfSectionPack(PackageBase itemPack, PartPackage partPack) { SectionPackage section = itemPack as SectionPackage; if (section != null) { // sectionのHタグのために設定 int depth = int.Parse(partPack["Depth"]); itemPack["Depth"] = (depth + 3).ToString(); itemPack["Indent"] = AddIndent(depth); } return TemplateBase.Render(itemPack, partPack["ItemTemplate"]) + "\n"; }
private static string RenderItemAsIfRenderSection(PackageBase itemPack, PartPackage partPack) { string result = RenderItemAsIfSectionPack(itemPack, partPack); SectionPackage section_pack = itemPack as SectionPackage; if (section_pack != null) { var childs = section_pack.Childs.ToArray(); if (childs.Length > 0) { int depth = int.Parse(partPack["Depth"]) + 1; result += SectionPart.RenderSection(childs, depth); } } return result; }
private static string RenderingItems(PartPackage partPack, PackageBase[] itemPacks) { string result = ""; if (itemPacks.Length > 0) { result += RenderItemAsIfRenderSection(itemPacks[0], partPack); for (int i = 1; i < itemPacks.Length; i++) { string indent = ""; if (partPack.ContainsKey("Depth")) { int depth = int.Parse(partPack["Depth"]); indent = AddIndent(depth); indent += " "; } result += "\n" + indent + Properties.Resources.Separate; result += RenderItemAsIfRenderSection(itemPacks[i], partPack); } } return result; }
// AddIndentとは互換性のない処理なので$Indent$を挿入してもうまくいかないので注意 private static string DepthForIndent(PartPackage partPack) { // subsection以降のインデントを整える if (partPack.ContainsKey("Depth")) { int depth = int.Parse(partPack["Depth"]); switch (depth) { case 1: return " "; case 2: return " "; } } return ""; }
public static string RenderTest(PartPackage partPackage) { return Render(partPackage, Properties.Resources.NavigationPart); }
public static string RenderPart(PartPackage partPack, PackageBase[] itemPacks) { partPack["Contents"] = RenderingItems(partPack, itemPacks); return DepthForIndent(partPack) + TemplateBase.Render(partPack, partPack["PartTemplate"]); }