private int XmlSKUIDUpdateCommand(WMSContext dc, XElement update) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var sk in update.Elements(ns + "SKUID")) { string key = sk.Element(ns + "ID").Value; SKU_ID skuid = dc.SKU_IDs.Find(key); if (skuid == null) { skuid = new SKU_ID { ID = key }; dc.SKU_IDs.Add(skuid); } skuid.Description = sk.Element(ns + "Description").Value; skuid.DefaultQty = double.Parse(sk.Element(ns + "Quantity").Value, System.Globalization.NumberStyles.Any); skuid.Unit = sk.Element(ns + "Unit").Value; skuid.Weight = double.Parse(sk.Element(ns + "Weight").Value, System.Globalization.NumberStyles.Any); skuid.Layout = int.Parse(sk.Element(ns + "Size").Element("Layout").Value); skuid.Capacity = int.Parse(sk.Element(ns + "Size").Element("Capacity").Value); skuid.Height = int.Parse(sk.Element(ns + "Size").Element("Height").Value); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private async Task FillParameters() { try { using (var dc = new WMSContext()) { await dc.Database.ExecuteSqlCommandAsync($"DELETE FROM dbo.Parameters"); IEnumerable <Parameter> list = new List <Parameter> { new Parameter { Name = "InputCommand.Place", Value = "T014" }, new Parameter { Name = "OutOfWarehouse.Place", Value = "W:out" } }; dc.Parameters.AddRange(list); await dc.SaveChangesAsync(); } } catch (Exception ex) { SimpleLog.AddException(ex, nameof(ModelInitialization)); Debug.WriteLine(ex.Message); throw; } }
private int XmlMaterialUpdate(WMSContext dc, XElement update) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var sk in update.Elements(ns + "Material")) { string key = sk.Element(ns + "ID").Value; Box_ID boxid = dc.Box_IDs.Find(key); if (boxid == null) { boxid = new Box_ID { ID = key }; dc.Box_IDs.Add(boxid); } boxid.SKU_ID = sk.Element(ns + "SKUID").Value; boxid.Batch = sk.Element(ns + "Batch").Value; } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private int XmlCancelCommand(WMSContext dc, XElement cancel) { try { XNamespace ns = XDocument.Root.Name.Namespace; int cancelKey = XmlConvert.ToInt32(cancel.Element(ns + "CommandID").Value); var cmd = dc.CommandERP.FirstOrDefault(p => p.ERP_ID == cancelKey); if (cmd != null && cmd.Status < CommandERP.CommandERPStatus.Active) { Model.Singleton().UpdateERPCommandStatus(cmd.ID, CommandERP.CommandERPStatus.Canceled); cmd.Status = CommandERP.CommandERPStatus.Canceled; } else if (cmd == null) { throw new XMLParsingException($"CommandID:NOCOMMANDID ({cancelKey})"); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private int XmlDeleteSKUCommand(WMSContext dc, XElement deleteSku) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var tuid in deleteSku.Elements(ns + "TU")) { int tuidkey = XmlConvert.ToInt32(tuid.Element(ns + "TUID").Value); if (dc.TUs.FirstOrDefault(p => p.TU_ID == tuidkey) == null) { throw new XMLParsingException($"TUID:NOTUID ({tuidkey:d9})"); } IEnumerable <TU> tu = dc.TUs.Where(prop => prop.TU_ID == tuidkey); dc.TUs.RemoveRange(tu); } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private int XmlCreateTUCommand(WMSContext dc, XElement createTU) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var tu in createTU.Elements(ns + "TU")) { int key = XmlConvert.ToInt32(tu.Element(ns + "TUID").Value); string loc = tu.Element(ns + "Location").Value; TU_ID tuid = dc.TU_IDs.Find(key); if (tuid == null) { tuid = new TU_ID { ID = key }; dc.TU_IDs.Add(tuid); } else { throw new XMLParsingException($"TUID:TUIDEXISTS ({key:d9})"); } if (dc.PlaceIds.Find(loc) == null) { throw new XMLParsingException($"Location:NOLOCATION ({loc})"); } if (dc.Places.FirstOrDefault(prop => prop.PlaceID == loc && prop.FK_PlaceID.DimensionClass >= 0 && prop.FK_PlaceID.DimensionClass < 999) != null) { throw new XMLParsingException($"Location:LOCATIONFULL ({loc})"); } try { tuid.Blocked = XmlConvert.ToInt32(tu.Element(ns + "Blocked").Value); } catch { tuid.Blocked = 0; } tuid.DimensionClass = 0; Place p = dc.Places.FirstOrDefault(prop => prop.TU_ID == key); if (p == null) { p = new Place { TU_ID = key }; dc.Places.Add(p); } p.PlaceID = loc; } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
protected void LoadXml(string xml) { LoadSchema(); XDocument = XDocument.Parse(xml); XDocument.Validate(_schema, (o, e) => { Debug.WriteLine($"{e.Message}"); Exception ex = new Exception(e.Message); SimpleLog.AddException(ex, nameof(XmlBasic)); throw ex; }); }
void IWMSToMFCS.PlaceChanged(string placeID, int TU_ID, int dim, string changeType) { try { Model.Singleton().UpdatePlace(placeID, TU_ID, dim, changeType); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
void IWMSToMFCS.DestinationEmptied(string place) { try { Model.Singleton().ReleaseRamp(place); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
public void UpdateRackFrequencyClass(double[] abcPortions) { try { Task.WaitAll(UpdateRackFrequencyClassAsync(abcPortions)); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(ModelInitialization)); Debug.WriteLine(ex.Message); throw; } }
public void FillPlaceIDAndParams() { try { Task.WaitAll(FillPlaceIDs(), FillParameters()); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(ModelInitialization)); Debug.WriteLine(ex.Message); throw; } }
bool IWMSToMFCS.OrderForRampActive(string ramp) { try { return(Model.Singleton().OrderForRampActive(ramp)); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
private async Task UpdateRackFrequencyClassAsync(double[] abc) { try { using (var dc = new WMSContext()) { var query = dc.PlaceIds.Where(p => p.PositionTravel > 0 && p.PositionHoist > 0).OrderBy(pp => pp.PositionHoist * pp.PositionHoist + pp.PositionTravel * pp.PositionTravel); int m = query.Count(); int count = 0; int idx = 0; int idxmax = 0; double range = 0; if (abc == null || abc.Length == 0) { idxmax = 0; range = 1.0; } else { idxmax = abc.Length; range = abc[0]; } foreach (var slot in query) { count++; if (count / (double)m > range) { idx++; if (idx < idxmax) { range += abc[idx]; } else { range = 1.0; } } slot.FrequencyClass = idx + 1; } await dc.SaveChangesAsync(); } } catch (Exception ex) { SimpleLog.AddException(ex, nameof(ModelInitialization)); Debug.WriteLine(ex.Message); throw; } }
public override string ProcessXml(string xml) { try { lock (Model.Singleton()) return(XmlProces(xml)); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
/* ERPSubmitStatus IWMSToERP.ErpCommandsS(ERPCommand erpCommands) * { * try * { * XmlReadERPCommand cmd = new XmlReadERPCommand(); * cmd.ProcessXml(erpCommands); * return null; * } * catch (Exception ex) * { * SimpleLog.AddException(ex, nameof(WMSToMFCS)); * Debug.WriteLine(ex.Message); * throw new FaultException(ex.Message); * } * } */ string IWMSToERP.ErpCommands(string xml) { try { XmlReadERPCommand cmd = new XmlReadERPCommand(); return(cmd.ProcessXml(xml)); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
ERPSubmitStatus IWMSToERP.ErpCommandsS(ERPCommand erpCommands) { try { XmlReadERPCommand cmd = new XmlReadERPCommand(); cmd.ProcessXml(erpCommands); return(null); } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
void IWMSToMFCS.CommandStatusChanged(int cmdId, int status) { try { if (cmdId >= 0) { Model.Singleton().UpdateCommand(cmdId, status); } } catch (Exception ex) { SimpleLog.AddException(ex, nameof(WMSToMFCS)); Debug.WriteLine(ex.Message); throw new FaultException(ex.Message); } }
private int XmlDeleteTUCommand(WMSContext dc, XElement deleteTU, string exitPlace) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var tuid in deleteTU.Elements(ns + "TU")) { int tuidkey = XmlConvert.ToInt32(tuid.Element(ns + "TUID").Value); string loc = tuid.Element(ns + "Location").Value; IEnumerable <TU> tu = dc.TUs.Where(prop => prop.TU_ID == tuidkey); Place place = dc.Places.Where(prop => prop.TU_ID == tuidkey).FirstOrDefault(); if (place == null) { throw new XMLParsingException("TUID:NOTUID"); } if (place.PlaceID == loc) { dc.Places.Remove(place); string entry = dc.Parameters.Find("InputCommand.Place").Value; Place p = new Place { TU_ID = place.TU_ID, PlaceID = exitPlace }; dc.Places.Add(p); dc.SaveChanges(); // dc.TUs.RemoveRange(tu); } else { throw new XMLParsingException($"Location:NOTUIDONLOCATION ({tuidkey:d9}, {loc})"); } } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
// todo make reply private int XmlStatusCommand(WMSContext dc, XElement status) { try { XNamespace ns = XDocument.Root.Name.Namespace; int statusKey = XmlConvert.ToInt32(status.Element(ns + "CommandID").Value); var cmd = dc.CommandERP.FirstOrDefault(p => p.ERP_ID == statusKey); if (cmd == null) { throw new XMLParsingException($"CommandID:NOCOMMANDID ({statusKey})"); } return(100 + (int)cmd.Status); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private int XmlCreateSKUCommand(WMSContext dc, XElement createSku) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var tu in createSku.Elements(ns + "TU")) { int tukey = XmlConvert.ToInt32(tu.Element(ns + "TUID").Value); if (dc.TU_IDs.Find(tukey) == null) { throw new XMLParsingException($"TUID:NOTUID ({tukey:d9})"); } foreach (var sku in tu.Element(ns + "SKUs").Elements(ns + "SKU")) { string skukey = sku.Element(ns + "SKUID").Value; if (dc.SKU_IDs.Find(skukey) == null) { throw new XMLParsingException($"SKUID:NOSKUID ({skukey})"); } dc.TUs.Add(new TU { TU_ID = XmlConvert.ToInt32(tu.Element(ns + "TUID").Value), // SKU_ID = skukey, Qty = double.Parse(sku.Element(ns + "Quantity").Value, System.Globalization.NumberStyles.Any), // Batch = sku.Element(ns + "Batch").Value, ProdDate = XmlConvert.ToDateTime(sku.Element(ns + "ProdDate").Value, XmlDateTimeSerializationMode.Local), ExpDate = XmlConvert.ToDateTime(sku.Element(ns + "ExpDate").Value, XmlDateTimeSerializationMode.Local) }); } } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
// Test xml->database form->xml // read xml->table form private int XmlMoveCommand(WMSContext dc, XElement move, int id) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var order in move.Elements(ns + "Order")) { string loc = order.Element(ns + "Location").Value; if (dc.PlaceIds.Find(loc) == null) { throw new XMLParsingException($"Destination:NOLOCATION ({loc})"); } foreach (var suborder in order.Element(ns + "Suborders").Elements(ns + "Suborder")) { foreach (var sku in suborder.Element(ns + "Materials").Elements(ns + "Material")) { string boxid = sku.Value; if (dc.Box_IDs.Find(boxid) == null) { throw new XMLParsingException($"MATERIAL:NOMATERIALID ({boxid})"); } if (dc.TUs.FirstOrDefault(p => p.Box_ID == boxid) == null) { throw new XMLParsingException($"MATERIAL:NOMATERIALINWAREHOUSE ({boxid})"); } } } } var orders = (from order in move.Elements(ns + "Order") from suborder in order.Element(ns + "Suborders").Elements(ns + "Suborder") from boxid in suborder.Element(ns + "Materials").Elements(ns + "Material") select new Order { ERP_ID = id, OrderID = XmlConvert.ToInt32(order.Element(ns + "OrderID").Value), ReleaseTime = XmlConvert.ToDateTime(order.Element(ns + "ReleaseTime").Value, XmlDateTimeSerializationMode.Local), Destination = order.Element(ns + "Location").Value, SubOrderID = XmlConvert.ToInt32(suborder.Element(ns + "SuborderID").Value), SubOrderERPID = XmlConvert.ToInt32(suborder.Element(ns + "SuborderERPID").Value), SubOrderName = suborder.Element(ns + "Name").Value, Box_ID = boxid.Value, Operation = XmlConvert.ToInt32(suborder.Element(ns + "PickAction").Value) == 0 ? Order.OrderOperation.BringBox : Order.OrderOperation.PickBox, Status = 0 }).ToList(); foreach (var o in orders) { o.TU_ID = dc.TUs.FirstOrDefault(p => p.Box_ID == o.Box_ID).TU_ID; o.SKU_ID = dc.Box_IDs.Find(o.Box_ID).SKU_ID; o.SKU_Batch = dc.Box_IDs.Find(o.Box_ID).Batch; o.SKU_Qty = 1; } dc.Orders.AddRange(orders); return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private string XmlProces(string xml) { XElement el0 = null; bool fault = false; XDocument XOutDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), el0 = new XElement("ERPsubmitStatus")); XNamespace nsOut = XOutDocument.Root.Name.Namespace; try { using (var dc = new WMSContext()) { el0.Add(new XElement("xmlcommandstring")); el0.Add(new XElement("Commands")); LoadXml(xml); XNamespace ns = XDocument.Root.Name.Namespace; foreach (var cmd in XDocument.Root.Elements()) { XElement elC = null; XDocument XOutDocumentC = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"), elC = new XElement("Command")); XNamespace nsOutC = XOutDocumentC.Root.Name.Namespace; var cmdERP = new CommandERP { Command = cmd.ToString(), ERP_ID = Convert.ToInt32(cmd.Element(ns + "ERPID").Value), Reference = Reference() + $"(ERP_ID = {cmd.Element(ns + "ERPID").Value}, Action = {cmd.Name.LocalName})", Status = cmd.Name.LocalName == "MaterialMove" ? CommandERP.CommandERPStatus.NotActive : CommandERP.CommandERPStatus.Finished, LastChange = DateTime.Now }; try { if (dc.CommandERP.FirstOrDefault(p => p.ERP_ID == cmdERP.ERP_ID) != null) { throw new XMLParsingException($"ERPID:ERPIDEXISTS ({cmdERP.ERP_ID})"); } dc.CommandERP.Add(cmdERP); dc.SaveChanges(); int status = 0; switch (cmd.Name.LocalName) { case "SKUIDUpdate": status = XmlSKUIDUpdateCommand(dc, cmd); break; case "TUCreate": status = XmlCreateTUCommand(dc, cmd); break; case "TUDelete": status = XmlDeleteTUCommand(dc, cmd, dc.Parameters.Find("Place.OutOfWarehouse").Value); break; case "TUChange": status = XmlChangeTUCommand(dc, cmd); break; case "TUCreateSKU": status = XmlCreateSKUCommand(dc, cmd); break; case "TUDeleteSKU": status = XmlDeleteSKUCommand(dc, cmd); break; case "MaterialMove": status = XmlMoveCommand(dc, cmd, cmdERP.ID); break; case "MaterialUpdate": status = XmlMaterialUpdate(dc, cmd); break; case "Cancel": status = XmlCancelCommand(dc, cmd); break; case "Status": status = XmlStatusCommand(dc, cmd); break; default: throw new Exception(); } dc.SaveChanges(); el0.Element(nsOut + "Commands").Add(new XElement("Command")); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("ERPID", cmdERP.ERP_ID)); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Status", 0)); elC.Add(new XElement("ERPID", cmdERP.ERP_ID)); elC.Add(new XElement("Status", 0)); if (status >= 100) // to immediatelly return status of command in question { string st; switch (status % 100) { case 1: st = "ACTIVE"; break; case 2: st = "CANCELED"; break; case 3: st = "FINISHED"; break; default: st = "WAITING"; break; } (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Details", st)); elC.Add(new XElement("Details", st)); } else { (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Details", "")); } (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("ExtraInfo", "")); } catch (Exception ex) { fault = true; el0.Element(nsOut + "Commands").Add(new XElement("Command")); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("ERPID", cmdERP.ERP_ID)); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Status", 1)); if (ex is XMLParsingException) { string[] s = ex.Message.Split(':'); if (s.Length > 1) { (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Details", s[0])); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("ExtraInfo", s[1])); elC.Add(new XElement("Details", s[0])); elC.Add(new XElement("ExtraInfot", s[1])); } } else { (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("Details", "OTHER")); (el0.Element(nsOut + "Commands").LastNode as XElement).Add(new XElement("ExtraInfo", ex.Message)); elC.Add(new XElement("Details", "OTHER")); elC.Add(new XElement("ExtraInfot", ex.Message)); } Log.AddException(ex); Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); } try { using (var dcc = new WMSContext()) { var c = dcc.CommandERP.Find(cmdERP.ID); if (c != null) { c.Command = $"{c.Command}\n\n<!-- reply\n{elC}\n-->"; dcc.SaveChanges(); } } } catch (Exception) {; } } } el0.Element(nsOut + "xmlcommandstring").Add(new XElement("Status", fault ? 1 : 0)); el0.Element(nsOut + "xmlcommandstring").Add(new XElement("ExtraInfo", "")); return(XOutDocument.ToString()); } catch (Exception ex) { el0.Element(nsOut + "xmlcommandstring").Add(new XElement("Status", 1)); el0.Element(nsOut + "xmlcommandstring").Add(new XElement("ExtraInfo", ex.Message)); Log.AddException(ex); Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); return(XOutDocument.ToString()); } }
// Test xml->database form->xml // read xml->table form private int XmlMoveCommand(WMSContext dc, XElement move, int id) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var order in move.Elements(ns + "Order")) { string loc = order.Element(ns + "Location").Value; if (dc.PlaceIds.Find(loc) == null) { throw new XMLParsingException($"Destination:NOLOCATION ({loc})"); } foreach (var suborder in order.Element(ns + "Suborders").Elements(ns + "Suborder")) { string name3 = suborder.Element(ns + "Name").Value; string[] name = name3.Split('#'); if (name.Length != 5) { throw new XMLParsingException($"Suborder:NAMEFORMAT ({name3})"); } foreach (var sku in suborder.Element(ns + "SKUs").Elements(ns + "SKU")) { string skuid = sku.Element(ns + "SKUID").Value; string so = suborder.Element(ns + "SuborderID").Value; if (dc.SKU_IDs.Find(skuid) == null) { throw new XMLParsingException($"SKUID:NOSKUID ({so}, {skuid})"); } if (sku.Element(ns + "Batch").Value == null || sku.Element(ns + "Batch").Value.Length == 0) { throw new XMLParsingException($"SKUID:NOBATCH ({so}, {skuid})"); } } } } IEnumerable <Order> orders = from order in move.Elements(ns + "Order") from suborder in order.Element(ns + "Suborders").Elements(ns + "Suborder") from sku in suborder.Element(ns + "SKUs").Elements(ns + "SKU") select new Order { ERP_ID = id, OrderID = XmlConvert.ToInt32(order.Element(ns + "OrderID").Value), ReleaseTime = XmlConvert.ToDateTime(order.Element(ns + "ReleaseTime").Value, XmlDateTimeSerializationMode.Local), Destination = order.Element(ns + "Location").Value, SubOrderID = XmlConvert.ToInt32(suborder.Element(ns + "SuborderID").Value), SubOrderERPID = XmlConvert.ToInt32(suborder.Element(ns + "SuborderERPID").Value), SubOrderName = suborder.Element(ns + "Name").Value, SKU_ID = sku.Element(ns + "SKUID").Value, SKU_Qty = double.Parse(sku.Element(ns + "Quantity").Value, System.Globalization.NumberStyles.Any), SKU_Batch = sku.Element(ns + "Batch").Value, Status = 0 }; dc.Orders.AddRange(orders); return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }
private async Task FillPlaceIDs() { try { using (var dc = new WMSContext()) { await dc.Database.ExecuteSqlCommandAsync($"DELETE FROM dbo.PlaceIDs"); var linq1 = from rack in new List <int> { 11, 12, 21, 22 } from travel in Enumerable.Range(1, 126) from hoist in Enumerable.Range(1, 9) from depth in Enumerable.Range(1, 2) select new PlaceID { ID = $"W:{rack:d2}:{travel:d3}:{hoist:d1}:{depth:d1}", PositionHoist = hoist, PositionTravel = travel }; var linq2 = from str in ConveyorNames() select new PlaceID { ID = str }; var linq3 = (from truck in Enumerable.Range(1, 5) from row in Enumerable.Range(1, 4) select new PlaceID { ID = $"W:32:0{truck:d1}{row:d1}:1:1" }); var linq4 = new List <PlaceID> { new PlaceID { ID = "W:32:01", DimensionClass = -1 }, new PlaceID { ID = "W:32:02", DimensionClass = -1 }, new PlaceID { ID = "W:32:03", DimensionClass = -1 }, new PlaceID { ID = "W:32:04", DimensionClass = -1 }, new PlaceID { ID = "W:32:05", DimensionClass = -1 }, new PlaceID { ID = "T04" } }; dc.PlaceIds.AddRange(linq2.Union(linq1).Union(linq3).Union(linq4)); await dc.SaveChangesAsync(); } } catch (Exception ex) { SimpleLog.AddException(ex, nameof(ModelInitialization)); Debug.WriteLine(ex.Message); throw; } }
private int XmlChangeTUCommand(WMSContext dc, XElement change) { try { XNamespace ns = XDocument.Root.Name.Namespace; foreach (var tu in change.Elements(ns + "TU")) { int tuidkey = XmlConvert.ToInt32(tu.Element(ns + "TUID").Value); string loc = null; try { loc = tu.Element(ns + "Location").Value; } catch { } if (loc != null) { var p = dc.Places.FirstOrDefault(prop => prop.TU_ID == tuidkey); if (p != null) { dc.Places.Remove(p); } else { throw new XMLParsingException($"TUID:NOTUID ({tuidkey:d9})"); } if (dc.PlaceIds.Find(loc) == null) { throw new XMLParsingException($"Location:NOLOCATION ({loc})"); } if (dc.Places.FirstOrDefault(prop => prop.PlaceID == loc && prop.FK_PlaceID.DimensionClass >= 0 && prop.FK_PlaceID.DimensionClass < 999) != null) { throw new XMLParsingException($"Location:LOCATIONFULL ({loc})"); } dc.Places.Add(new Place { PlaceID = tu.Element(ns + "Location").Value, TU_ID = tuidkey, }); } try { var tuid = dc.TU_IDs.Find(tuidkey); if (XmlConvert.ToInt32(tu.Element(ns + "Blocked").Value) == 1) { tuid.Blocked |= 4; // quality block } else { int mask = int.MaxValue ^ 4; tuid.Blocked &= mask; // quality block } } catch { } } return(0); } catch (Exception ex) { Debug.WriteLine(ex.Message); SimpleLog.AddException(ex, nameof(XmlReadERPCommand)); throw; } }