public void SetComponentProperties(int MachineComponentId) { try { using (DataContext = new DataContext(StatisModels.ProjectProps.FakeServer)) { var component = DataContext.MachineComponent .Include("ComponentImages") .Include("ComponentStocks") .Where(i => i.Id == MachineComponentId) .First(); DS_Component.DataSource = CurrentComponent = component; if (component.ComponentStocks.Count > 0) { DS_ComponentStock.DataSource = CurrentStock = component.ComponentStocks[0]; } if (component.ComponentImages.Count > 0) { DS_ComponentImage.DataSource = CurrentImage = component.ComponentImages[0]; ComponentPicture.Image = component.ComponentImages[0].Image; } } } catch (Exception ex) { MessageBox.Show("Error while getting data from database"); } }
private void ImageParseClickCallback(object sender, EventArgs e) { // parse the picture from clipboard if (!Clipboard.ContainsImage()) { return; } ComponentPicture.Image = Clipboard.GetImage(); if (CurrentImage == null) { CurrentImage = new ComponentImage(); } CurrentImage.SetImage(ComponentPicture.Image); }
public void SetComponentProperties(MachineComponent component) { CurrentComponent = component; if (CurrentComponent.ComponentStocks.Count > 0) { CurrentStock = CurrentComponent.ComponentStocks[0]; } DS_Component.DataSource = CurrentComponent; DS_ComponentStock.DataSource = CurrentStock; if (component.ComponentImages.Count > 0) { CurrentImage = component.ComponentImages[0]; ComponentPicture.Image = component.ComponentImages[0].Image; } }
public void UpdateComponent() { try { string oldComponent = CurrentComponent.ComponentCode; using (DataContext = new DataContext(StatisModels.ProjectProps.FakeServer)) { ComponentImage currentImage = new ComponentImage(); currentImage.ImageString = CurrentImage.ImageString; currentImage.ImageName = CurrentImage.ImageName; if (CurrentComponent.ComponentImages == null || CurrentComponent.ComponentImages.Count == 0) { CurrentComponent.ComponentImages = new List <ComponentImage>(new ComponentImage[] { currentImage }); } else if (CurrentComponent.ComponentImages.Count > 0) { CurrentComponent.ComponentImages[0].ImageString = currentImage.ImageString; CurrentComponent.ComponentImages[0].ImageName = currentImage.ImageName; } if (DataContext.Entry(CurrentComponent.ComponentImages[0]).State != System.Data.Entity.EntityState.Modified) { DataContext.Entry(CurrentComponent.ComponentImages[0]).State = System.Data.Entity.EntityState.Modified; } DataContext.SaveChanges(); if (DataContext.Entry(CurrentStock).State != System.Data.Entity.EntityState.Modified) { DataContext.Entry(CurrentStock).State = System.Data.Entity.EntityState.Modified; } DataContext.SaveChanges(); if (DataContext.Entry(CurrentComponent).State != System.Data.Entity.EntityState.Modified) { DataContext.Entry(CurrentComponent).State = System.Data.Entity.EntityState.Modified; } DataContext.SaveChanges(); } MessageBox.Show($"Update {oldComponent} successfully"); } catch (Exception ex) { MessageBox.Show("Update information failed"); } }
private Component GetComponentsFromFile(string componentFile) { XDocument document = null; try { document = XDocumentUtils.Load(componentFile); } catch (XmlException exception) { Log.LogError(nameof(FileBasedComponentProvider), $"Error in reading component file: {exception}"); return(null); } var xElement = document.Descendants().FirstOrDefault(); if (xElement != null) { #warning making id based on file location, check again once function based provider come alive var xmlBytes = new UnicodeEncoding().GetBytes(componentFile); var hashedXmlBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(xmlBytes); var id = new Guid(hashedXmlBytes); var title = xElement.GetAttributeValue(Namespaces.Components + Title) ?? Path.GetFileNameWithoutExtension(componentFile); var description = xElement.GetAttributeValue(Namespaces.Components + Description) ?? ""; var groupingTagsRaw = xElement.GetAttributeValue(Namespaces.Components + Tags) ?? GuessGroupingTagsBasedOnPath(componentFile); List <string> groupingTags = new List <string>(); if (!groupingTagsRaw.IsNullOrEmpty()) { var tagManager = ServiceLocator.GetRequiredService <TagManager>(); groupingTags.AddRange( groupingTagsRaw.ToLower() .Split(',') .Select(f => f.Trim()) .Select(tagManager.GetTagTitle) .ToList()); } var containerClasses = ContainerClassManager.ParseToList(xElement.GetAttributeValue(Namespaces.Components + ContainerClasses)); var antiTags = ContainerClassManager.ParseToList(xElement.GetAttributeValue(Namespaces.Components + AntiTags)); var componentImage = new ComponentImage() { CustomImageUri = xElement.GetAttributeValue(Namespaces.Components + Image), IconName = xElement.GetAttributeValue(Namespaces.Components + Icon) }; xElement.Attributes().Where(f => f.Name.Namespace == Namespaces.Components).Remove(); return(new Component { Id = id, Title = title, Description = description, GroupingTags = groupingTags, ContainerClasses = containerClasses, AntiTags = antiTags, ComponentImage = componentImage, ComponentDefinition = xElement.Document.GetDocumentAsString() }); } return(null); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var regex = new RegularExpressionAttribute(@"^(.*?(\.(png|jpg|gif|jpeg)\b)[^$]*)$"); if (Used > InStock) { yield return(new ValidationResult( "Components used cannot be higher then Components owned", new[] { "InStock", "Used" })); } if (DatasheetFile != null && DataSheet != DatasheetFile.FileName) { yield return(new ValidationResult( "Text input is not the same as the file upload.</br>Did you wanted to change it to something else?", new[] { "DataSheet" })); } if (ComponentImageFile != null && ComponentImage != ComponentImageFile.FileName) { yield return(new ValidationResult( "Text input is not the same as the file upload.</br>Did you wanted to change it to something else?", new[] { "ComponentImage" })); } if (ComponentPinoutImageFile != null && ComponentPinoutImage != ComponentPinoutImageFile.FileName) { yield return(new ValidationResult( "Text input is not the same as the file upload.</br>Did you wanted to change it to something else?", new[] { "ComponentPinoutImage" })); } if (DataSheet != null) { if (DataSheet.Contains("www.google.")) { var datasheetLink = DataSheet.GetQueryParam("url"); if (datasheetLink.Contains(".pdf")) { DataSheet = datasheetLink; } else { yield return(new ValidationResult( "The Google link that was parsed does not contain a valid pdf file", new[] { "DataSheet" })); } } else if (!DataSheet.EndsWith(".pdf")) { yield return(new ValidationResult("Please upload a PDF file.", new[] { "DataSheet" })); } } if (ComponentPinoutImage != null) { if (ComponentPinoutImage.Contains("www.google.")) { var imagelink = ComponentPinoutImage.GetQueryParam("url"); if (regex.IsValid(imagelink)) { ComponentPinoutImage = imagelink; } else { yield return(new ValidationResult( "The Google link that was parsed does not contain a valid image link", new[] { "ComponentPinoutImage" })); } } else if (!regex.IsValid(ComponentPinoutImage)) { yield return(new ValidationResult("The file is not a valid image file", new [] { "ComponentPinoutImage" })); } } if (ComponentImage != null) { if (ComponentImage.Contains("www.google.")) { var imagelink = ComponentImage.GetQueryParam("url"); if (regex.IsValid(imagelink)) { ComponentImage = imagelink; } else { yield return(new ValidationResult( "The Google link that was parsed does not contain a valid image link", new[] { "ComponentImage" })); } } else if (!regex.IsValid(ComponentImage)) { yield return(new ValidationResult("The file is not a valid image file", new[] { "ComponentImage" })); } } }