/// <summary> /// Gets all of the rows that are within the specified <paramref name="edmTable" /> that satisfies the given /// <paramref name="filter" />. /// </summary> /// <param name="edmTable">The edm table.</param> /// <param name="filter">The filter.</param> /// <returns> /// An array of <see cref="DataRow" /> objects; otherwise <c>null</c>. /// </returns> private IEnumerable <DataRow> GetRows(EdmTable edmTable, string filter) { if (_Dataset == null) { return(null); } if (edmTable == null || !edmTable.Valid) { return(null); } string tableName = _PxApp.GetQualifiedTableName(edmTable.TableName); if (!_Dataset.Tables.Contains(tableName)) { return(null); } // Locate the table within the dataset that matches the given name. DataTable table = _Dataset.Tables[tableName]; if (table == null) { return(null); } // Obtain all of the rows the satisfy the given filter. DataRow[] rows = table.Select(filter, "", DataViewRowState.CurrentRows); return(rows); }
/// <summary> /// This will save the given node and edm struct data into the correct configured edm tables. /// </summary> /// <param name="node">IMMWMSNode which can be the WorkRequest, Design, WorkLocation, or CU.</param> /// <param name="edm">EDM struct containing the data.</param> private void Save(IMMWMSNode node, EDM edm) { string sql = null; EdmTable table = null; IMMWMSWorkRequest workRequest = node as IMMWMSWorkRequest; if (workRequest != null) // WorkRequest { table = _EdmRepository.WorkRequest; sql = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {0} ({1},{2},{3},{4},{5}) VALUES ({6}, {7},'{8}','{9}','{10}')", "{0}", Fields.WorkRequestID, Fields.DesignID, EDM.Fields.Name, EDM.Fields.Value, EDM.Fields.Type, workRequest.ID, _ID, edm.Name, edm.Value, edm.Type); } else { IMMWMSDesign design = node as IMMWMSDesign; if (design != null) // Design { table = _EdmRepository.Design; sql = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {0} ({1},{2},{3},{4}) VALUES ({5}, {6},'{7}','{8}', '{9}')", "{0}", Fields.DesignID, EDM.Fields.Name, EDM.Fields.Value, EDM.Fields.Type, design.ID, _ID, edm.Name, edm.Value, edm.Type); } else { IMMWMSWorklocation workLocation = node as IMMWMSWorklocation; if (workLocation != null) // WorkLocation { table = _EdmRepository.WorkLocation; sql = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {0} ({1},{2},{3},{4},{5}) VALUES ({6}, {7},'{8}','{9}','{10}')", "{0}", Fields.WorkLocationID, Fields.DesignID, EDM.Fields.Name, EDM.Fields.Value, EDM.Fields.Type, workLocation.ID, _ID, edm.Name, edm.Value, edm.Type); } else { IMMWMSCompatibleUnit compatibleUnit = node as IMMWMSCompatibleUnit; if (compatibleUnit != null) // CompatibleUnit { table = _EdmRepository.CompatibleUnit; sql = string.Format(CultureInfo.InvariantCulture, "INSERT INTO {0} ({1},{2},{3},{4},{5}) VALUES ({6}, {7},'{8}','{9}','{10}')", "{0}", Fields.CompatibleUnitID, Fields.DesignID, EDM.Fields.Name, EDM.Fields.Value, EDM.Fields.Type, compatibleUnit.ID, _ID, edm.Name, edm.Value, edm.Type); } } } } // Insert the EDM when the table is valid. if (table != null && table.Valid) { // Check to see that the field is not being excluded. if (table.Fields.Count(o => o.Name.Equals(edm.Name, StringComparison.OrdinalIgnoreCase)) == 0) { // Add the EDM record into the table. _PxApp.ExecuteNonQuery(string.Format(CultureInfo.InvariantCulture, sql, _PxApp.GetQualifiedTableName(table.TableName))); } } }
/// <summary> /// Given the <paramref name="element" /> and the <paramref name="edmTable" /> and /// all of the records that satsify the <paramref name="filter" /> will be added as EDMPROP elements in the document /// from the table. /// </summary> /// <param name="element">IXMLDOMElement of the current xml document.</param> /// <param name="edmTable">The edm table.</param> /// <param name="filter">Filter used to narrow down the table search.</param> private void SetProperty(IXMLDOMElement element, EdmTable edmTable, string filter) { // Obtain all of the rows the satisfy the given filter. IEnumerable <DataRow> rows = this.GetRows(edmTable, filter); if (rows == null) { return; } // Iterate through all of the rows. foreach (DataRow row in rows) { EDM edm = new EDM(row); IXMLDOMElement edmprop = element.ownerDocument.createElement("EDMPROP"); edmprop.setAttribute("Name", edm.Name); edmprop.setAttribute("Type", edm.Type); edmprop.text = edm.Value; element.appendChild(edmprop); } }