PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/Bin/etc/scripts/OrderConfirmation.cs

https://bitbucket.org/williamybs/uidipythontool
C# | 78 lines | 61 code | 1 blank | 16 comment | 3 complexity | 460129ed00e9fc3fbfd83066838c65b2 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.IO;
  7. using DICK;
  8. using DICK.Core;
  9. using Antlr.StringTemplate;
  10. namespace DICK.Scripts
  11. {
  12. /*
  13. * ORDERCONFIRMATION SAMPLE PROJECT
  14. * Author: Henry Nordstrom
  15. * Date: February 11, 2011
  16. *
  17. * This sample demonstrates the following features of DICK:
  18. * - Using the StringTemplate as template engine (DICK supports both StringTemplate and NVelocity)
  19. * - Possibility to do select queries directly to the database
  20. * - Using the QueryToolsADO library to retrieve datatables based on a query
  21. * - Using the FileNameBody context variable to specify the body of the filename for the file to be written
  22. *
  23. * The template file used together with this script is named "OrderConfirmation.cs"
  24. *
  25. */
  26. public class OrderConfirmation:IDataObject
  27. {
  28. public override DICKContext GetContext(string key)
  29. {
  30. //Initialize context
  31. DICKContext ctx=new DICKContext();
  32. DataTable header=QueryToolsADO.QueryToDataTable("select DocNum, isnull(NumAtCard,'-'), DocDate, DocTotal, '-' from ordr where docentry="+key);
  33. DataTable rows=QueryToolsADO.QueryToDataTable("select ItemCode, Dscription, Quantity, Price, LineTotal, LineNum from RDR1 where docentry = "+key);
  34. DataRow hdr=header.Rows[0];
  35. ctx.SetAttribute("DOCNUM",hdr[0].ToString());
  36. ctx.SetAttribute("NUMATCARD",hdr[1].ToString());
  37. ctx.SetAttribute("DOCDATE",((DateTime)hdr[2]).ToString("dd.MM.yyyy"));
  38. ctx.SetAttribute("DOCTOTAL",((Decimal)hdr[3]).ToString("F2"));
  39. ctx.SetAttribute("SIGN",hdr[4].ToString());
  40. int rowcounter=0;
  41. foreach (DataRow row in rows.Rows)
  42. {
  43. SortedDictionary<string, object> record = new SortedDictionary<string, object>();
  44. record.Add("ItemCode", (row[0].ToString().Trim()).PadRight(16,' '));
  45. record.Add("ItemName", row[1].ToString());
  46. record.Add("Quantity", ((Decimal)row[2]).ToString("F2").Trim().PadLeft(21,' '));
  47. record.Add("Price", ((Decimal)row[3]).ToString("F2").Trim().PadLeft(24,' '));
  48. record.Add("LineTotal", ((Decimal)row[4]).ToString("F2").Trim().PadLeft(24,' '));
  49. DataTable textrows=QueryToolsADO.QueryToDataTable("select linetext from rdr10 where docentry="+key+" and aftlinenum="+row[5].ToString());
  50. if(textrows!=null && textrows.Rows.Count>0)
  51. {
  52. List<string> textlines=new List<string>();
  53. foreach(DataRow textrow in textrows.Rows)
  54. {
  55. textlines.Add(textrow[0].ToString());
  56. record.Add("TextLines",textlines);
  57. }
  58. }
  59. ctx.SetAttribute("RECORDS",record);
  60. rowcounter++;
  61. }
  62. //If there is only one record, we need to add another, empty one. Otherwise StringTemplate doesn't find the rows as specified in the template.
  63. if(rowcounter<2)
  64. {
  65. SortedDictionary<string, object> record = new SortedDictionary<string, object>();
  66. record.Add("ItemCode", "".PadRight(16,' '));
  67. record.Add("ItemName", "");
  68. record.Add("Quantity", "".PadLeft(21,' '));
  69. record.Add("Price", "".PadLeft(24,' '));
  70. record.Add("LineTotal", "".PadLeft(24,' '));
  71. ctx.SetAttribute("RECORDS",record);
  72. }
  73. ctx.FileNameBody=key;
  74. return ctx;
  75. }
  76. }
  77. }