public static MDPart CreatePart(ArticleReference articleReference) { // Need to lock project var project = articleReference.Project; project.SmartLock(); if (articleReference.ParentObject != null) { articleReference.ParentObject.SmartLock(); } articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Create new part if (part == null) { articleReference.SmartLock(); // ReSharper disable once RedundantAssignment part = partsDatabase.AddPart(partNr, partVariant); using (new LockingUtility.SeplaLockingVector()) { new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant); } partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part part = partsDatabase.GetPart(partNr, partVariant); } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }
public static MDPart CreatePart(ArticleReference articleReference) { // Need to lock project var project = articleReference.Project; project.SmartLock(); if (articleReference.ParentObject != null) { articleReference.ParentObject.SmartLock(); } articleReference.SmartLock(); // Init var partsDatabase = new MDPartsManagement().OpenDatabase(); //var articleReference = function.ArticleReferences.First(); articleReference.SmartLock(); var partNr = articleReference.PartNr; var partVariant = articleReference.VariantNr; MDPart part = partsDatabase.GetPart(partNr, partVariant); // Create new part if (part == null) { part = partsDatabase.AddPart(partNr, partVariant); // PartSelection to edit data new EplApplication().ShowPartSelectionDialog(ref partNr, ref partVariant); //partsDatabase = new MDPartsManagement().OpenDatabase(); // Second Call needed to get new part //part = partsDatabase.GetPart(partNr, partVariant); } // Load data var article = project.Articles .FirstOrDefault(obj => obj.PartNr.Equals(partNr) && obj.VariantNr.Equals(partVariant) ); if (article != null) { article.SmartLock(); article.LoadFromMasterdata(); } return(part); }