コード例 #1
0
        private IEnumerable <XElement> Group(IEnumerable <XElement> rows)
        {
            IEnumerable <string> storerkeys = rows.Select(x => x.Element("STORERKEY").Value).Distinct();

            foreach (string key in storerkeys)
            {
                string   duns        = getStorerDuns(key);
                XElement storerGroup = new XElement("VendorShipmentPODReport");
                storerGroup.Add(new XAttribute("VendorCode", key));
                storerGroup.Add(new XAttribute("VendorDuns", duns));
                //string cmcode = rows.Where(x => x.Element("STORERKEY").Value == key).Select(x => x.Element("CONSIGNEEKEY").Value).First();
                //string cmduns = rows.Where(x => x.Element("STORERKEY").Value == key).Select(x => x.Element("CMDUNS").Value).First();
                //storerGroup.Add(new XAttribute("CMCode", cmcode));
                //storerGroup.Add(new XAttribute("CMDuns", cmduns));


                XElement fromrole     = ConfigHelper.GetRoleElement(_configpath, _fromRole, "fromRole");
                XElement tostxrole    = ConfigHelper.GetRoleElement(_configpath, _toSTXRole, "toRole");
                XElement toe2openrole = ConfigHelper.GetRoleElement(_configpath, _toe2openRole, "toRole");
                //XElement hub = ConfigHelper.GetRoleElement(_warehous, "hub");
                XElement config = new XElement("config");
                config.Add(new XElement("fromRole", fromrole.Elements()));
                config.Add(new XElement("tostxRole", tostxrole.Elements()));
                config.Add(new XElement("toe2openRole", toe2openrole.Elements()));
                //config.Add(new XElement("hub", hub.Elements()));
                storerGroup.Add(config);
                //添加所有物流/分ASIC/NOASIC
                IEnumerable <XElement> vendorreport = rows.Where(x => x.Element("STORERKEY").Value == key).ToArray();
                XElement noasic = new XElement("NOASIC");
                IEnumerable <OrderHead> orderheads = rows.Where(x => x.Element("STORERKEY").Value == key).Select(x => new OrderHead()
                {
                    OrderKey       = x.Element("ORDERKEY").Value,
                    CMCode         = x.Element("CONSIGNEEKEY").Value,
                    DeliveryOrder  = x.Element("LOTTABLE02").Value,
                    ExternOrderKey = x.Element("EXTERNORDERKEY").Value
                }).Distinct();
                foreach (OrderHead orderhead in orderheads)
                {
                    //表头/表体分组
                    XElement orderel = new XElement("ORDER");
                    orderel.Add(new XElement("ORDERKEY", orderhead.OrderKey));
                    //string externorderkey = rows.Where(x => x.Element("STORERKEY").Value == key && x.Element("ORDERKEY").Value == orderkey).Select(x => x.Element("EXTERNORDERKEY").Value).First();
                    orderel.Add(new XElement("EXTERNORDERKEY", orderhead.ExternOrderKey));
                    orderel.Add(new XElement("DELIVERYORDER", orderhead.DeliveryOrder));
                    orderel.Add(new XElement("CMCODE", orderhead.CMCode));
                    //string comcode = rows.Where(x => x.Element("STORERKEY").Value == key && x.Element("ORDERKEY").Value == orderkey).Select(x => x.Element("COMCODE").Value).First();
                    //orderel.Add(new XElement("COMCODE", comcode));
                    //XElement orderdetail = new XElement("ORDERDETAIL");
                    IEnumerable <XElement> detail = rows.Where(x => x.Element("STORERKEY").Value == key &&
                                                               x.Element("ORDERKEY").Value == orderhead.OrderKey &&
                                                               x.Element("CONSIGNEEKEY").Value == orderhead.CMCode &&
                                                               x.Element("LOTTABLE02").Value == orderhead.DeliveryOrder).ToArray();
                    //orderdetail.Add(detail);
                    orderel.Add(detail);
                    noasic.Add(orderel);
                }



                storerGroup.Add(noasic);



                yield return(storerGroup);
            }
        }