Ejemplo n.º 1
0
    public static List<OrderExtension> Retrieve(string OrderNo)
    {
      DataTable oData = Data.OperationalDB.LoadOrderExtensions(OrderNo);

      List<OrderExtension> oOrderExtensions = new List<OrderExtension>();

      foreach (DataRow oRow in oData.Rows)
      {
        OrderExtension oOrderExtension = new OrderExtension();
        oOrderExtension.OrderNo = oRow["ORDER_NO"].ToString();
        oOrderExtension.LineNo = Convert.ToInt32(oRow["LINE_NO"]);
        oOrderExtension.Key = oRow["KEY"].ToString();
        oOrderExtension.Value = (string)oRow["VALUE"];

        oOrderExtensions.Add(oOrderExtension);
      }

      return oOrderExtensions;
    }
Ejemplo n.º 2
0
    public static List<Order> CreateOrdersFromXML(int iSiteID, string sClientCode, string xml, out Dictionary<string, string> oErrors)
    {
      List<Order> oOrders = new List<Order>();
      oErrors = new Dictionary<string, string>();
      XmlDocument oXmlDoc = new XmlDocument();
      Order oOrder = null;

      
      try
      {
        Event.ValidateXmlSchema.Fire(iSiteID, sClientCode, xml);
      }
      catch (Exception ex)
      {
        throw new Exception("Schema validation failed. " + Helper.FormatExceptionMessage(ex));
      }

      oXmlDoc.LoadXml(xml);

      // In order to validate the xml, we need at least the site and client, so that the correct xml schema can be loaded from the configuration.
      XmlNodeList oNodes = oXmlDoc.SelectNodes("//Orders/DN");
      foreach (XmlElement oXmlElement in oNodes)
      {
        try
        {
          oOrder = new Order();
          oOrder.OrderNo = Event.GenerateOrderNo.Fire(iSiteID, sClientCode);
          oOrder.SiteID = iSiteID;
          oOrder.ClientCode = sClientCode;
          oOrder.DateCreated = DateTime.Now;

          foreach (XmlElement oInnerElement in oXmlElement.ChildNodes)
          {
            if (oInnerElement.Name.ToUpper() == "LINE")
            {
              // We ignore the LINE elements because it will be used later to create order lines.
              continue;
            }

            if (oInnerElement.Name.ToUpper() == "ORDERNO")
            {
              oOrder.ClientOrderNo = oInnerElement.InnerText;
            }
            else
            {
              // Custom elements
              OrderExtension oOrderExtension = new OrderExtension();
              oOrderExtension.OrderNo = oOrder.OrderNo;
              oOrderExtension.LineNo = 0;
              oOrderExtension.Key = oInnerElement.Name;
              oOrderExtension.Value = oInnerElement.InnerText;
              oOrder.OrderExtensions.Add(oOrderExtension);
            }
          }

          foreach (XmlElement oInnerElement in oXmlElement.ChildNodes)
          {
            if (oInnerElement.Name.ToUpper() != "LINE")
            {
              // We ignore the LINE elements because it will be used later to create order lines.
              continue;
            }

            OrderLine oOrderLine = new OrderLine();
            oOrderLine.OrderNo = oOrder.OrderNo;

            foreach (XmlElement oLineElement in oInnerElement.ChildNodes)
            {
              if (oLineElement.Name.ToUpper() == "NO")
              {
                oOrderLine.LineNo = Convert.ToInt32(oLineElement.InnerText);
                break;
              }
            }

            foreach (XmlElement oLineElement in oInnerElement.ChildNodes)
            {
              if (oLineElement.Name.ToUpper() == "NO")
              {
                continue;
              }

              if (oLineElement.Name.ToUpper() == "ITEMCODE")
              {
                oOrderLine.ItemCode = oLineElement.InnerText;
              }
              else if (oLineElement.Name.ToUpper() == "QUANTITY")
              {
                oOrderLine.Quantity = Convert.ToDouble(oLineElement.InnerText);
              }
              else
              {
                // Custom elements
                OrderExtension oOrderExtension = new OrderExtension();
                oOrderExtension.OrderNo = oOrder.OrderNo;
                oOrderExtension.LineNo = oOrderLine.LineNo;
                oOrderExtension.Key = oLineElement.Name;
                oOrderExtension.Value = oLineElement.InnerText;
                oOrder.OrderExtensions.Add(oOrderExtension);
              }
            }

            oOrder.OrderLines.Add(oOrderLine);
          }

          oOrders.Add(oOrder);
        }
        catch (Exception ex)
        {
          oErrors.Add(oOrder.ClientOrderNo == "" ? "NA" : oOrder.ClientOrderNo, "Could not create order from xml. " + Helper.FormatExceptionMessage(ex));
        }
      }

      return oOrders;
    }