/// <summary> /// Gets collection of dynamic custom oreder properties columns /// </summary> /// <returns></returns> private Collection <Column> _GetDynamicCustomOrderColumns(bool isReadOnly) { Collection <Column> dynamicColumns = new Collection <Column>(); OrderCustomPropertiesInfo infos = App.Current.Project.OrderCustomPropertiesInfo; for (int i = 0; i < infos.Count; i++) { OrderCustomProperty info = infos[i]; Column col = new Column(); col.FieldName = OrderCustomProperties.GetCustomPropertyName(i); col.Title = info.Name; if (info.Type == OrderCustomPropertyType.Text) { col.CellEditor = (CellEditor)App.Current.FindResource("CustomOrderPropertyTextEditor"); } else if (info.Type == OrderCustomPropertyType.Numeric) { col.CellEditor = (CellEditor)App.Current.FindResource("CustomOrderPropertyNumericEditor"); col.CellContentTemplate = (DataTemplate)App.Current.FindResource("DefaultStringTemplate"); } else { Debug.Assert(false); // NOTE: not supported } col.ReadOnly = isReadOnly; dynamicColumns.Add(col); } return(dynamicColumns); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Control loaded /// </summary> private void _Loaded(object sender, RoutedEventArgs e) { CellContentPresenter cellContentPresenter = this.VisualParent as CellContentPresenter; if (cellContentPresenter == null) { return; } // initialize control DataCell dataCell = cellContentPresenter.TemplatedParent as DataCell; string columnName = dataCell.ParentColumn.FieldName; ESRI.ArcLogistics.Data.DataObject dataObject = dataCell.ParentRow.DataContext as ESRI.ArcLogistics.Data.DataObject; if (dataObject != null) { int index = OrderCustomProperties.GetCustomPropertyIndex(columnName); if (-1 != index) { OrderCustomProperty info = App.Current.Project.OrderCustomPropertiesInfo[index]; this.MaxLength = info.Length; } else { Debug.Assert(false); // NOTE: not supported } } Keyboard.Focus(this); }
/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Put all properties to string. /// </summary> /// <param name="properties">Order custom properties values</param> internal static string AssemblyDBString(OrderCustomProperties properties, OrderCustomPropertiesInfo info) { Debug.Assert(properties.Count == info.Count); string strSeparator = new string(new char[1] { CommonHelpers.SEPARATOR }); StringBuilder result = new StringBuilder(); for (int index = 0; index < info.Count; ++index) { OrderCustomProperty propertyInfo = info[index]; string value = null; if (OrderCustomPropertyType.Text == propertyInfo.Type) { if (null != properties[index]) { Debug.Assert(properties[index] is string); value = (string)properties[index]; } } else if (OrderCustomPropertyType.Numeric == propertyInfo.Type) { double tmp = 0.0; if (null != properties[index]) { if (properties[index] is double) { tmp = (double)properties[index]; } else if (properties[index] is string) { tmp = double.Parse(properties[index].ToString()); } } value = tmp.ToString(CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE)); } else { Debug.Assert(false); // NOTE: not supported } if (!string.IsNullOrEmpty(value)) { string prop = value.Replace(strSeparator, CommonHelpers.SEPARATOR_ALIAS); result.Append(prop); } if (index < properties.Count - 1) { result.Append(CommonHelpers.SEPARATOR); // NOTE: after last not neded } } return(result.ToString()); }
/// <summary> /// Converts collection of CustomOrderProperty objects to OrderCustomPropertiesInfo. /// </summary> /// <returns>OrderCustomPropertiesInfo object.</returns> public OrderCustomPropertiesInfo GetOrderCustomPropertiesInfo() { OrderCustomPropertiesInfo orderCustomPropertiesInfo = new OrderCustomPropertiesInfo(); foreach (CustomOrderProperty customOrderProperty in _customOrderProperties) { // Create custom order property info using data of item in collection. OrderCustomProperty newOrderCustomProperty = new OrderCustomProperty(customOrderProperty.Name, OrderCustomPropertyType.Text, customOrderProperty.MaximumLength, customOrderProperty.Description, customOrderProperty.OrderPairKey); // Add new custom order property to collection. orderCustomPropertiesInfo.Add(newOrderCustomProperty); } return(orderCustomPropertiesInfo); }
/// <summary> /// Serializes OrderCustomPropertiesInfo object. /// </summary> public static string SerializeOrderCustomPropertiesInfo(OrderCustomPropertiesInfo orderCustomPropertiesInfo) { string xml = null; XmlWriter writer = null; try { StringBuilder sb = new StringBuilder(); writer = XmlWriter.Create(sb); writer.WriteStartElement(NODE_ORDERCUSTOMPROP); writer.WriteAttributeString(ATTR_VERSION, ORDER_CUST_PROP_CURRENT_VERSION.ToString(CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE))); for (int index = 0; index < orderCustomPropertiesInfo.Count; index++) { OrderCustomProperty property = orderCustomPropertiesInfo[index]; writer.WriteStartElement(NODE_PROPERTY); writer.WriteAttributeString(ATTR_NAME, property.Name); writer.WriteAttributeString(ATTR_TYPE, property.Type.ToString()); writer.WriteAttributeString(ATTR_MAXLENGTH, property.Length.ToString()); writer.WriteAttributeString(ATTR_DESCRIPTION, property.Description); writer.WriteAttributeString(ATTR_ORDERPAIRKEY, property.OrderPairKey.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); writer.Flush(); xml = sb.ToString(); } finally { if (writer != null) { writer.Close(); } } return(xml); }
private List <ESRI.ArcLogistics.DomainObjects.Order> processOrders(DataTable table) { List <ESRI.ArcLogistics.DomainObjects.Order> OrderList = new List <Order>(); foreach (DataRow row in table.Rows) { // Create New empty Order CapacitiesInfo capInfo = m_application.Project.CapacitiesInfo; OrderCustomPropertiesInfo propInfo = m_application.Project.OrderCustomPropertiesInfo; ESRI.ArcLogistics.DomainObjects.Order resultOrder = new ESRI.ArcLogistics.DomainObjects.Order(capInfo, propInfo); OrderCustomPropertiesInfo orderPropertiesInfo = resultOrder.CustomPropertiesInfo; OrderCustomProperties orderProperties = resultOrder.CustomProperties; CapacitiesInfo orderCapacitiesInfo = resultOrder.CapacitiesInfo; Capacities orderCapacities = resultOrder.Capacities; bool geocodeProvided = false; bool geocodeCorrect = false; bool geocodedCorrectly = false; double tempD; DateTime TWdateTime; Double tempX = 0.0; Double tempY = 0.0; // Insert Order Information resultOrder.PlannedDate = m_application.CurrentDate; for (int i = 0; i < table.Columns.Count; i++) { try { switch (table.Columns[i].ColumnName) { #region Case Statements case "Name": resultOrder.Name = row["Name"].ToString(); break; case "Address": resultOrder.Address.AddressLine = row["Address"].ToString(); break; case "City": resultOrder.Address.Locality3 = row["City"].ToString(); break; case "State": resultOrder.Address.StateProvince = row["State"].ToString(); break; case "Zip": resultOrder.Address.PostalCode1 = row["Zip"].ToString(); break; case "Zip4": resultOrder.Address.PostalCode2 = row["Zip4"].ToString(); break; case "Country": resultOrder.Address.Country = row["Country"].ToString(); break; case "PlannedDate": DateTime tempDT = new DateTime(); if (System.DateTime.TryParse(row["PlannedDate"].ToString(), out tempDT)) { resultOrder.PlannedDate = tempDT; } break; case "Priority": if (row["Priority"].ToString() == "High") { resultOrder.Priority = OrderPriority.High; } else if (row["Priority"].ToString() == "Normal") { resultOrder.Priority = OrderPriority.Normal; } break; case "OrderType": if (row["OrderType"].ToString() == "Pickup") { resultOrder.Type = OrderType.Pickup; } else if (row["OrderType"].ToString() == "Delivery") { resultOrder.Type = OrderType.Delivery; } break; case "ServiceTime": if (Double.TryParse(row["ServiceTime"].ToString(), out tempD)) { resultOrder.ServiceTime = tempD; } break; case "TimeWindowStart": string tempS = row["TimeWindowStart"].ToString(); if (DateTime.TryParse(tempS, out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { resultOrder.TimeWindow.From = TWdateTime.TimeOfDay; resultOrder.TimeWindow.IsWideOpen = false; } } break; case "TimeWindowFinish": if (DateTime.TryParse(row["TimeWindowFinish"].ToString(), out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { resultOrder.TimeWindow.To = TWdateTime.TimeOfDay; resultOrder.TimeWindow.IsWideOpen = false; } } break; case "TimeWindow2Start": if (DateTime.TryParse(row["TimeWindow2Start"].ToString(), out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { resultOrder.TimeWindow2.From = TWdateTime.TimeOfDay; resultOrder.TimeWindow2.IsWideOpen = false; } } break; case "TimeWindow2Finish": if (DateTime.TryParse(row["TimeWindow2Finish"].ToString(), out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { resultOrder.TimeWindow2.To = TWdateTime.TimeOfDay; resultOrder.TimeWindow2.IsWideOpen = false; } } break; case "MaxViolationTime": if (Double.TryParse(row["MaxViolationTime"].ToString(), out tempD)) { resultOrder.MaxViolationTime = tempD; } break; case "VehicleSpecialties": if (row["VehicleSpecialties"].ToString() != "") { string[] stringSeparators = new string[] { ";", "," }; string[] specialties = row["VehicleSpecialties"].ToString().Split(stringSeparators, StringSplitOptions.None); foreach (string s in specialties) { VehicleSpecialty vs = new VehicleSpecialty(); vs.Name = s; foreach (VehicleSpecialty V in m_application.Project.VehicleSpecialties) { if (String.Compare(V.Name, vs.Name, true) == 0) { V.CopyTo(vs); m_application.Project.VehicleSpecialties.Remove(V); break; } } m_application.Project.VehicleSpecialties.Add(vs); resultOrder.VehicleSpecialties.Add(vs); } } break; case "DriverSpecialties": if (row["DriverSpecialties"].ToString() != "") { string[] stringSeparators2 = new string[] { ";", "," }; string[] specialties2 = row["DriverSpecialties"].ToString().Split(stringSeparators2, StringSplitOptions.None); foreach (string s in specialties2) { DriverSpecialty ds = new DriverSpecialty(); ds.Name = s; foreach (DriverSpecialty D in m_application.Project.DriverSpecialties) { if (String.Compare(D.Name, ds.Name, true) == 0) { D.CopyTo(ds); m_application.Project.DriverSpecialties.Remove(D); break; } } m_application.Project.DriverSpecialties.Add(ds); resultOrder.DriverSpecialties.Add(ds); } } break; case "X": string x = row["X"].ToString(); if (x != "" && x != null) { if (Double.TryParse(row["X"].ToString(), out tempX)) { if (tempX >= -180.0 && tempX <= 180.0 && tempX != 0.0) { geocodeProvided = true; geocodeCorrect = true; } else if (tempX == 0.0) { geocodeCorrect = true; } } } break; case "Y": string y = row["Y"].ToString(); if (y != "" && y != null) { if (Double.TryParse(row["Y"].ToString(), out tempY)) { if (tempY >= -90.0 && tempY <= 90.0 && tempY != 0) { geocodeProvided = true; geocodeCorrect = true; } else if (tempY == 0.0) { geocodeCorrect = true; } } } break; #endregion } if (orderProperties.Count > 0) { OrderCustomProperty orderPropertyInfoItem = null; for (int j = 0; j < orderPropertiesInfo.Count; j++) { orderPropertyInfoItem = orderPropertiesInfo.ElementAt(j) as OrderCustomProperty; string tempName = orderPropertyInfoItem.Name.Replace(" ", ""); if (tempName == table.Columns[i].ColumnName) { orderProperties[j] = (row[table.Columns[i].ToString()].ToString()); break; } } } if (orderCapacities.Count > 0) { CapacityInfo orderCapacityInfoItem = null; for (int k = 0; k < orderCapacitiesInfo.Count; k++) { orderCapacityInfoItem = orderCapacitiesInfo.ElementAt(k); string tempName = orderCapacityInfoItem.Name.Replace(" ", ""); if (tempName == table.Columns[i].ColumnName) { if (Double.TryParse(row[table.Columns[i].ToString()].ToString(), out tempD)) { orderCapacities[k] = tempD; } break; } } } } catch (Exception e) { string statusMessage = " Distribute Orders encountered a problem: " + e.Message; m_application.Messenger.AddError(statusMessage); } } resultOrder.CustomProperties = orderProperties; resultOrder.Capacities = orderCapacities; if (geocodeProvided && geocodeCorrect) { AddressCandidate candidate1 = new AddressCandidate(); ESRI.ArcLogistics.Geometry.Point p = new ESRI.ArcLogistics.Geometry.Point(tempX, tempY); candidate1.GeoLocation = p; candidate1.Score = 100; candidate1.Address = resultOrder.Address; resultOrder.GeoLocation = candidate1.GeoLocation; geocodedCorrectly = true; } else { try { AddressCandidate candidate = new AddressCandidate(); candidate = m_application.Geocoder.Geocode(resultOrder.Address); if (candidate != null) { resultOrder.GeoLocation = candidate.GeoLocation; geocodedCorrectly = true; } else { string statusMessage = "Could not geocode address for: " + resultOrder.Name; m_application.Messenger.AddError(statusMessage); //TODO: Handle orders which were not geocoded!! } } catch (Exception e) { string statusMessage = "Distribute Orders encountered a problem while geocoding addresses: " + e.Message; m_application.Messenger.AddError(statusMessage); } } // Add Order if (geocodedCorrectly) { OrderList.Add(resultOrder); } else { string statusMessage = "Distribute Orders encountered a problem while adding order: " + resultOrder.Name; m_application.Messenger.AddError(statusMessage); } } return(OrderList); }
private ESRI.ArcLogistics.DomainObjects.Order MakeOrderFromInvoice(IInvoiceRet invoiceRet, QBSessionManager session) { ESRI.ArcLogistics.DomainObjects.Order resultOrder = null; ICustomerRet customerRet = QueryCustomer(session, invoiceRet.CustomerRef.FullName.GetValue()); CapacitiesInfo capInfo = m_application.Project.CapacitiesInfo; OrderCustomPropertiesInfo propInfo = m_application.Project.OrderCustomPropertiesInfo; resultOrder = new ESRI.ArcLogistics.DomainObjects.Order(capInfo, propInfo); resultOrder.PlannedDate = m_application.CurrentDate; if (customerRet.ParentRef != null) { resultOrder.Name = customerRet.ParentRef.FullName.GetValue(); } else { resultOrder.Name = customerRet.FullName.GetValue(); } IAddress useAddress = null; if (customerRet.ShipAddress != null) { useAddress = customerRet.ShipAddress; } else if (customerRet.BillAddress != null) { useAddress = customerRet.BillAddress; } else { m_application.Messenger.AddWarning("No address for: " + resultOrder.Name); } if (useAddress != null) { if (useAddress.Addr2 != null) { resultOrder.Address.AddressLine = useAddress.Addr2.GetValue(); } else { resultOrder.Address.AddressLine = useAddress.Addr1.GetValue(); } resultOrder.Address.Locality3 = useAddress.City.GetValue(); resultOrder.Address.StateProvince = useAddress.State.GetValue(); resultOrder.Address.PostalCode1 = useAddress.PostalCode.GetValue(); AddressCandidate candidate = m_application.Geocoder.Geocode(resultOrder.Address); resultOrder.GeoLocation = candidate.GeoLocation; } // Look in the order custom properties for matching invoice detail items (by item description). // Look in the order capacities for matching item type custom fields. OrderCustomPropertiesInfo orderPropertiesInfo = resultOrder.CustomPropertiesInfo; OrderCustomProperties orderProperties = resultOrder.CustomProperties; CapacitiesInfo orderCapacitiesInfo = resultOrder.CapacitiesInfo; Capacities orderCapacities = resultOrder.Capacities; // Retrieve invoice line list // Each line can be either InvoiceLineRet OR InvoiceLineGroupRet IORInvoiceLineRetList orInvoiceLineRetList = invoiceRet.ORInvoiceLineRetList; if (orInvoiceLineRetList != null && (orderProperties.Count > 0 || orderCapacities.Count > 0)) { int lineCount = orInvoiceLineRetList.Count; for (int i = 0; i < lineCount; i++) { IORInvoiceLineRet orInvoiceLineRet = orInvoiceLineRetList.GetAt(i); // Check what to retrieve from the orInvoiceLineRet object // based on the "ortype" property. Skip summary lines. if (orInvoiceLineRet.ortype != ENORInvoiceLineRet.orilrInvoiceLineRet) { continue; } if (orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName != null) { string itemName = orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName.GetValue(); double itemQuantity = 0; if (orInvoiceLineRet.InvoiceLineRet.ItemRef != null) { itemQuantity = System.Convert.ToDouble(orInvoiceLineRet.InvoiceLineRet.Quantity.GetValue()); } // look for matching custom order property OrderCustomProperty orderPropertyInfoItem = null; for (int j = 0; j < orderPropertiesInfo.Count; j++) { orderPropertyInfoItem = orderPropertiesInfo.ElementAt(j) as OrderCustomProperty; if (orderPropertyInfoItem.Name == itemName) { if (orderPropertyInfoItem.Type == OrderCustomPropertyType.Numeric) { orderProperties[j] = itemQuantity; } else { orderProperties[j] = itemQuantity.ToString(); } break; } } // look for matching capacity // need to lookup item record so we get the extra field(s) // TODO: It might be a good idea to cache these locally to avoid // excess QB queries. IORItemRet orItemRet = QueryItem(session, itemName); IDataExtRetList custItemFieldsRetList = null; switch (orItemRet.ortype) { case ENORItemRet.orirItemServiceRet: { // orir prefix comes from OR + Item + Ret IItemServiceRet ItemServiceRet = orItemRet.ItemServiceRet; custItemFieldsRetList = ItemServiceRet.DataExtRetList; } break; case ENORItemRet.orirItemInventoryRet: { IItemInventoryRet ItemInventoryRet = orItemRet.ItemInventoryRet; custItemFieldsRetList = ItemInventoryRet.DataExtRetList; } break; case ENORItemRet.orirItemNonInventoryRet: { IItemNonInventoryRet ItemNonInventoryRet = orItemRet.ItemNonInventoryRet; custItemFieldsRetList = ItemNonInventoryRet.DataExtRetList; } break; } int custItemFieldCount = 0; if (custItemFieldsRetList != null) { custItemFieldCount = custItemFieldsRetList.Count; } for (int j = 0; j < custItemFieldCount; j++) { IDataExtRet custItemField = custItemFieldsRetList.GetAt(j); string custItemFieldName = custItemField.DataExtName.GetValue(); CapacityInfo orderCapacityInfoItem = null; for (int k = 0; k < orderCapacitiesInfo.Count; k++) { orderCapacityInfoItem = orderCapacitiesInfo.ElementAt(k); if (orderCapacityInfoItem.Name == custItemFieldName) { orderCapacities[k] += System.Convert.ToDouble(custItemField.DataExtValue.GetValue()) * itemQuantity; break; } } } } } } resultOrder.CustomProperties = orderProperties; resultOrder.Capacities = orderCapacities; return(resultOrder); }
public static void makeEdit(string field, string value) { field = field.Replace(" ", ""); string message = "Changing " + field + " to " + value + " for all seleced orders."; App.Current.Messenger.AddInfo(message); ISupportSelection selector = (ISupportSelection)App.Current.MainWindow.CurrentPage; for (int i = 0; i < selector.SelectedItems.Count; i++) { // orderRef is a reference to the selected order [i] Order orderRef = (ESRI.ArcLogistics.DomainObjects.Order)selector.SelectedItems[i]; OrderCustomPropertiesInfo orderPropertiesInfo = orderRef.CustomPropertiesInfo; OrderCustomProperties orderProperties = orderRef.CustomProperties; CapacitiesInfo orderCapacitiesInfo = orderRef.CapacitiesInfo; Capacities orderCapacities = orderRef.Capacities; double tempD; DateTime TWdateTime; try { switch (field) { #region Case Statements case "Name": orderRef.Name = value; break; case "Address": orderRef.Address.AddressLine = value; break; case "City": orderRef.Address.Locality3 = value; break; case "State": orderRef.Address.StateProvince = value; break; case "Zip": orderRef.Address.PostalCode1 = value; break; case "Zip4": orderRef.Address.PostalCode2 = value; break; case "Country": orderRef.Address.Country = value; break; case "PlannedDate": DateTime tempDT = new DateTime(); if (System.DateTime.TryParse(value, out tempDT)) { orderRef.PlannedDate = tempDT; } break; case "Priority": if (value == "High") { orderRef.Priority = OrderPriority.High; } else if (value == "Normal") { orderRef.Priority = OrderPriority.Normal; } break; case "OrderType": if (value == "Pickup") { orderRef.Type = OrderType.Pickup; } else if (value == "Delivery") { orderRef.Type = OrderType.Delivery; } break; case "ServiceTime": if (Double.TryParse(value.ToString(), out tempD)) { orderRef.ServiceTime = tempD; } break; case "TimeWindowStart": string tempS = value; if (DateTime.TryParse(tempS, out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { orderRef.TimeWindow.From = TWdateTime.TimeOfDay; orderRef.TimeWindow.IsWideOpen = false; } } break; case "TimeWindowFinish": if (DateTime.TryParse(value, out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { orderRef.TimeWindow.To = TWdateTime.TimeOfDay; orderRef.TimeWindow.IsWideOpen = false; } } break; case "TimeWindow2Start": if (DateTime.TryParse(value, out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { orderRef.TimeWindow2.From = TWdateTime.TimeOfDay; orderRef.TimeWindow2.IsWideOpen = false; } } break; case "TimeWindow2Finish": if (DateTime.TryParse(value, out TWdateTime)) { if (TWdateTime.TimeOfDay != TimeSpan.Zero) { orderRef.TimeWindow2.To = TWdateTime.TimeOfDay; orderRef.TimeWindow2.IsWideOpen = false; } } break; case "MaxViolationTime": if (Double.TryParse(value, out tempD)) { orderRef.MaxViolationTime = tempD; } break; case "VehicleSpecialties": if (value != "") { string[] stringSeparators = new string[] { ";", "," }; string[] specialties = value.Split(stringSeparators, StringSplitOptions.None); foreach (string s in specialties) { VehicleSpecialty vs = new VehicleSpecialty(); vs.Name = s; foreach (VehicleSpecialty V in App.Current.Project.VehicleSpecialties) { if (String.Compare(V.Name, vs.Name, true) == 0) { V.CopyTo(vs); App.Current.Project.VehicleSpecialties.Remove(V); break; } } foreach (VehicleSpecialty V in orderRef.VehicleSpecialties) { if (String.Compare(V.Name, vs.Name, true) == 0) { V.CopyTo(vs); orderRef.VehicleSpecialties.Remove(V); break; } } App.Current.Project.VehicleSpecialties.Add(vs); orderRef.VehicleSpecialties.Add(vs); } } break; case "DriverSpecialties": if (value != "") { string[] stringSeparators2 = new string[] { ";", "," }; string[] specialties2 = value.Split(stringSeparators2, StringSplitOptions.None); foreach (string s in specialties2) { DriverSpecialty ds = new DriverSpecialty(); ds.Name = s; foreach (DriverSpecialty D in App.Current.Project.DriverSpecialties) { if (String.Compare(D.Name, ds.Name, true) == 0) { D.CopyTo(ds); App.Current.Project.DriverSpecialties.Remove(D); break; } } foreach (DriverSpecialty D in orderRef.DriverSpecialties) { if (String.Compare(D.Name, ds.Name, true) == 0) { D.CopyTo(ds); orderRef.DriverSpecialties.Remove(D); break; } } App.Current.Project.DriverSpecialties.Add(ds); orderRef.DriverSpecialties.Add(ds); } } break; //end of case statements #endregion } #region Custom order properties and capacities if (orderProperties.Count > 0) { OrderCustomProperty orderPropertyInfoItem = null; for (int j = 0; j < orderPropertiesInfo.Count; j++) { orderPropertyInfoItem = orderPropertiesInfo.ElementAt(j) as OrderCustomProperty; string tempName = orderPropertyInfoItem.Name.Replace(" ", ""); if (tempName == field) { orderRef.CustomProperties[j] = value; break; } } } if (orderCapacities.Count > 0) { CapacityInfo orderCapacityInfoItem = null; for (int k = 0; k < orderCapacitiesInfo.Count; k++) { orderCapacityInfoItem = orderCapacitiesInfo.ElementAt(k); string tempName = orderCapacityInfoItem.Name.Replace(" ", ""); if (tempName == field) { if (Double.TryParse(value, out tempD)) { orderRef.Capacities[k] = tempD; } break; } } } // End custom order properties and capacities #endregion } catch (Exception e) { message = "Error: " + e.Message; App.Current.Messenger.AddError(message); } } App.Current.Project.Save(); }
/// <summary> /// Converts collection of CustomOrderProperty objects to OrderCustomPropertiesInfo. /// </summary> /// <returns>OrderCustomPropertiesInfo object.</returns> public OrderCustomPropertiesInfo GetOrderCustomPropertiesInfo() { OrderCustomPropertiesInfo orderCustomPropertiesInfo = new OrderCustomPropertiesInfo(); foreach (CustomOrderProperty customOrderProperty in _customOrderProperties) { // Create custom order property info using data of item in collection. OrderCustomProperty newOrderCustomProperty = new OrderCustomProperty(customOrderProperty.Name, OrderCustomPropertyType.Text, customOrderProperty.MaximumLength, customOrderProperty.Description, customOrderProperty.OrderPairKey); // Add new custom order property to collection. orderCustomPropertiesInfo.Add(newOrderCustomProperty); } return orderCustomPropertiesInfo; }
/// <summary> /// Parse string and split it to properties values /// </summary> /// <param name="propertiesValuesString">DB order custom properties string</param> /// <param name="orderCustomPropertiesInfo">Project order custom properties info</param> /// <returns>Parsed order custom properties</returns> internal static OrderCustomProperties CreateFromDBString(string propertiesValuesString, OrderCustomPropertiesInfo orderCustomPropertiesInfo) { Debug.Assert(orderCustomPropertiesInfo != null); // Create order custom properties object using data of orderCustomPropertiesinfo. OrderCustomProperties orderCustomProperties = new OrderCustomProperties(orderCustomPropertiesInfo); if (null == propertiesValuesString) { // special initialization - of numeric values for (int index = 0; index < orderCustomPropertiesInfo.Count; ++index) { if (OrderCustomPropertyType.Numeric == orderCustomPropertiesInfo[index].Type) { orderCustomProperties[index] = 0.0; } } } else { // Values separator. char[] valuesSeparator = new char[1] { CommonHelpers.SEPARATOR }; // Get array of values splitted by separator. string[] propertiesValues = propertiesValuesString.Split(valuesSeparator, StringSplitOptions.None); // This condition is not always true. //Debug.Assert(propertiesValues.Length == orderCustomPropertiesinfo.Count); string strSeparator = new string(valuesSeparator); // Iterate through list of order custom properties. for (int index = 0; index < orderCustomPropertiesInfo.Count; ++index) { // Get current order custom property. OrderCustomProperty orderCustomProperty = orderCustomPropertiesInfo[index]; // If index of item in list of order custom properties info is less than // length of array with values. if (index < propertiesValues.Length) { // Get current value for appropriate custom order property. string currentStrValue = propertiesValues[index]; if (!string.IsNullOrEmpty(currentStrValue)) { currentStrValue = currentStrValue.Replace(CommonHelpers.SEPARATOR_ALIAS, strSeparator); } // Value of current property. object currentPropertyValue = null; // If type of order custom property is Text. if (OrderCustomPropertyType.Text == orderCustomProperty.Type) { // Assign property valus as it is. currentPropertyValue = currentStrValue; } // Type of custom order property is Numeric. else if (OrderCustomPropertyType.Numeric == orderCustomProperty.Type) { // Convert string value to double. double tmp = 0.0; if (!string.IsNullOrEmpty(currentStrValue)) { tmp = double.Parse(currentStrValue, CultureInfo.GetCultureInfo(CommonHelpers.STORAGE_CULTURE)); } currentPropertyValue = tmp; } else { Debug.Assert(false); // NOTE: not supported } // Assign value of current custom order property. orderCustomProperties[index] = currentPropertyValue; } // if (index < values.Length) } // for (int index = 0; index < info.Count; ++index) } // else of if (null == value) return(orderCustomProperties); }