public Material AddMaterial(ElsevierMaterials.Models.Domain.Export.Exporter exporter, Material material, int materialId, int sourceMaterialId, int sourceId, int subgroupId, IMaterialsContextUow materialContextUow)
        {
            if (material == null)
            {
                ElsevierMaterials.Models.Domain.Material.MaterialBasicInfo materialBasicInfo = _materialBinder.GetMaterialInfo(materialId, sourceMaterialId, sourceId, subgroupId, materialContextUow);

                material = new Material();
                material.MaterialInfo.MaterialId       = materialId;
                material.MaterialInfo.SourceMaterialId = sourceMaterialId;
                material.MaterialInfo.SourceId         = sourceId;
                material.MaterialInfo.SubgroupId       = subgroupId;
                material.MaterialInfo.Name             = materialBasicInfo.Name;
                material.MaterialInfo.SubgroupName     = materialBasicInfo.SubgroupName;
                if (exporter.Materials.Count > 0)
                {
                    material.MaterialInfo.RowId = exporter.Materials.Max(m => m.MaterialInfo.RowId) + 1;
                }
                else
                {
                    material.MaterialInfo.RowId = 1;
                }


                material.MaterialInfo.TypeId   = materialBasicInfo.TypeId;
                material.MaterialInfo.TypeName = materialBasicInfo.TypeName;
                material.MaterialInfo.Standard = materialBasicInfo.Standard;
                exporter.Materials.Add(material);
            }
            return(material);
        }
        public int RemovePropertyFromMaterial(int materialId, int sourceMaterialId, int sourceId, int subgroupId, int propertyId, int sourcePropertyId, int rowId)
        {
            ElsevierMaterials.Models.Domain.Export.Exporter exporter = GetExporter();

            ElsevierMaterials.Models.Domain.Export.Material material = exporter.Materials.Where(m => m.MaterialInfo.MaterialId == materialId && m.MaterialInfo.SourceMaterialId == sourceMaterialId && m.MaterialInfo.SourceId == sourceId && m.MaterialInfo.SubgroupId == subgroupId).FirstOrDefault();

            material.Properties.Remove(material.Properties.Where(m => m.ElsBasicInfo.TypeId == propertyId && m.ElsBasicInfo.SourceTypeId == sourcePropertyId && m.ElsBasicInfo.RowId == rowId).FirstOrDefault());

            Material materialForDelete = null;

            foreach (var materialobj in exporter.Materials)
            {
                if (materialobj.Properties.Count == 0)
                {
                    materialForDelete = materialobj;
                    break;
                }
            }

            int materialRowId = -1;

            if (materialForDelete != null)
            {
                materialRowId = materialForDelete.MaterialInfo.RowId;
                exporter.Materials.Remove(materialForDelete);
            }

            System.Web.HttpContext.Current.Session["Exporter"] = exporter;
            return(materialRowId);
        }
Exemplo n.º 3
0
 public ActionResult ChangeMaterial(int rowId)
 {
     //TODO:-Progress indicator ChangeMaterial
     ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();
     ElsevierMaterials.Models.Domain.Export.Material material = exporter.Materials.Where(m => m.MaterialInfo.RowId == rowId).FirstOrDefault();
     return(Json(ResponseStatus.Success, RenderPartialViewToString("MaterialProperties", material), JsonRequestBehavior.AllowGet));
 }
 public bool RemoveMaterials(int[] materials)
 {
     ElsevierMaterials.Models.Domain.Export.Exporter exporter = GetExporter();
     foreach (var rowId in materials)
     {
         exporter.Materials.Remove(exporter.Materials.Where(m => m.MaterialInfo.RowId == rowId).FirstOrDefault());
     }
     System.Web.HttpContext.Current.Session["Exporter"] = exporter;
     return(true);
 }
Exemplo n.º 5
0
 public ActionResult Materials()
 {
     BreadcrumbNavigationGetSet();
     ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();
     foreach (var material in exporter.Materials)
     {
         material.Properties = material.Properties.OrderBy(m => m.ElsBasicInfo.Name).ToList();
     }
     return(View("Exporter", exporter));
 }
Exemplo n.º 6
0
        public ActionResult RemoveMaterials(string materials)
        {
            var jsSer = new JavaScriptSerializer();

            int[] materialsInt = jsSer.Deserialize <int[]>(materials);
            bool  hasMaterials = _binder.RemoveMaterials(materialsInt);

            ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();

            return(View("Exporter", exporter));
        }
Exemplo n.º 7
0
        public ActionResult RemovePropertyFromMaterial(int materialId, int sourceMaterialId, int sourceId, int subgroupId, int propertyId, int sourcePropertyId, int rowId)
        {
            //TODO:-na Layout home napravi partial views za popupove koje pozivas

            int materialRowIdForDeleting = _binder.RemovePropertyFromMaterial(materialId, sourceMaterialId, sourceId, subgroupId, propertyId, sourcePropertyId, rowId);

            ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();

            ElsevierMaterials.Models.Domain.Export.Material material = exporter.Materials.Where(m => m.MaterialInfo.MaterialId == materialId && m.MaterialInfo.SourceMaterialId == sourceMaterialId && m.MaterialInfo.SourceId == sourceId && m.MaterialInfo.SubgroupId == subgroupId).FirstOrDefault();

            return(Json(ResponseStatus.Success, new { hasMaterialsAdded = exporter.Materials.Count > 0 ? true: false, materialRowIdForDeleting = materialRowIdForDeleting, data = RenderPartialViewToString("MaterialProperties", material) }, JsonRequestBehavior.AllowGet));
        }
 public ElsevierMaterials.Models.Domain.Export.Exporter GetExporter()
 {
     //TODO: Ogar predlaze dase cuva u bazi. mozda
     ElsevierMaterials.Models.Domain.Export.Exporter exporter = System.Web.HttpContext.Current.Session["Exporter"] as ElsevierMaterials.Models.Domain.Export.Exporter;
     if (exporter != null)
     {
         return(exporter);
     }
     else
     {
         exporter = new ElsevierMaterials.Models.Domain.Export.Exporter();
         System.Web.HttpContext.Current.Session["Exporter"] = exporter;
         return(exporter);
     }
 }
Exemplo n.º 9
0
        public ActionResult ExportData(string types, string materials)
        {
            var jsSer = new JavaScriptSerializer();

            string[] typesString  = jsSer.Deserialize <string[]>(types);
            int[]    materialsInt = jsSer.Deserialize <int[]>(materials);

            if (typesString.Length == 0)
            {
                return(Json(IniCore.Web.Mvc.ResponseStatus.Error, new { message = "Please select at least one export type." }));
            }
            ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();
            MemoryStream zipStream = _formaterBinder.ExportData(typesString, materialsInt, exporter);

            return(File(zipStream.ToArray(), "application/octet-stream", "Export " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss",
                                                                                                           CultureInfo.InvariantCulture) + ".zip"));
        }
Exemplo n.º 10
0
        public ActionResult AddPropertiesForMaterial(int materialId, int sourceMaterialId, int sourceId, int subgroupId, List <PropertyFilter> properties)
        {
            ElsevierMaterials.Models.Domain.Export.Exporter exporter = _binder.GetExporter();

            List <PropertyFilter> propertiesForExport;
            string message = _formaterBinder.GetPropertiesForExport(sourceMaterialId, sourceId, subgroupId, properties, exporter, out propertiesForExport, materialContextUow);

            if (propertiesForExport.Count > 0)
            {
                Material material = exporter.Materials.Where(m => m.MaterialInfo.MaterialId == materialId && m.MaterialInfo.SourceMaterialId == sourceMaterialId && m.MaterialInfo.SourceId == sourceId && m.MaterialInfo.SubgroupId == subgroupId).FirstOrDefault();
                material = _binder.AddMaterial(exporter, material, materialId, sourceMaterialId, sourceId, subgroupId, materialContextUow);


                _binder.AddPropertiesForMaterial(sourceMaterialId, sourceId, subgroupId, propertiesForExport, material, materialContextUow);
            }

            return(Json(ResponseStatus.Success, new { success = true, message = message }, JsonRequestBehavior.AllowGet));
        }
        public MemoryStream ExportData(string[] types, int[] materials, ElsevierMaterials.Models.Domain.Export.Exporter exporter)
        {
            MemoryStream zipStream = new MemoryStream();

            zipStream.Seek(0, SeekOrigin.Begin);


            using (ZipFile zip = new ZipFile())
            {
                bool atLeastOneMaterialHasProperties = false;
                foreach (var rowId in materials)
                {
                    ElsevierMaterials.Models.Domain.Export.Material material = exporter.Materials.Where(m => m.MaterialInfo.RowId == rowId).FirstOrDefault();

                    bool materialContainsPropertiesForExport = false;
                    foreach (var prop in material.Properties)
                    {
                        int notMappedPropertyId       = prop.ElsBasicInfo.SourceTypeId != 0 ? prop.ElsBasicInfo.SourceTypeId : prop.ElsBasicInfo.TypeId;
                        TMPropertyTypeEnum propertyId = MapElsPropertyId(notMappedPropertyId, (SourceTypeEnum)material.MaterialInfo.SourceId);

                        if (exporter.Properties.Contains(propertyId))
                        {
                            materialContainsPropertiesForExport = true;
                            atLeastOneMaterialHasProperties     = true;

                            break;
                        }
                    }

                    if (materialContainsPropertiesForExport)
                    {
                        MemoryStream mz = AddMaterialToZip(types, material, exporter);
                        mz.Seek(0, SeekOrigin.Begin);
                        zip.AddEntry(material.MaterialInfo.Name.Replace("/", "") + "_" + material.MaterialInfo.RowId + ".zip", mz);
                    }
                }
                if (atLeastOneMaterialHasProperties)
                {
                    zip.Save(zipStream);
                }
            }
            return(zipStream);
        }
        public string GetPropertiesForExport(int sourceMaterialId, int sourceId, int subgroupId, List <PropertyFilter> properties, ElsevierMaterials.Models.Domain.Export.Exporter exporter, out List <PropertyFilter> propertiesForExport, IMaterialsContextUow materialContextUow)
        {
            propertiesForExport = new List <PropertyFilter>();
            PropertyBinder  propertyBinder  = new PropertyBinder();
            ConditionBinder conditionBinder = new ConditionBinder();
            string          message         = "";
            string          propertes1      = "";
            string          propertes2      = "";
            string          ulOpen          = "<ul>";
            string          ulClose         = "</ul>";
            string          title1          = "The following properties are added to export: ";
            string          title2          = "The following properties cannot be exported: ";



            foreach (var addedProperty in properties)
            {
                ElsevierMaterials.Models.Condition condition = conditionBinder.FillCondition(sourceMaterialId, sourceId, subgroupId, materialContextUow, addedProperty);

                int notMappedPropertyId       = addedProperty.SourceTypeId != 0 ? addedProperty.SourceTypeId : addedProperty.TypeId;
                TMPropertyTypeEnum propertyId = MapElsPropertyId(notMappedPropertyId, (SourceTypeEnum)sourceId);

                if (!exporter.Properties.Contains(propertyId))
                {
                    if (propertes2 == "")
                    {
                        propertes2 = propertes2 + ulOpen;
                    }
                    propertes2 = propertes2 + "<li>" + propertyBinder.FillPropertyName(sourceMaterialId, sourceId, subgroupId, materialContextUow, addedProperty, condition) + "</li>";
                }
                else
                {
                    propertiesForExport.Add(addedProperty);
                    if (propertes1 == "")
                    {
                        propertes1 = propertes1 + ulOpen;
                    }

                    propertes1 = propertes1 + "<li>" + propertyBinder.FillPropertyName(sourceMaterialId, sourceId, subgroupId, materialContextUow, addedProperty, condition) + "</li>";
                }
            }

            if (propertes1 != "" && propertes2 != "")
            {
                message = title1 + propertes1 + ulClose + "<br/>" + title2 + propertes2 + ulClose;
            }
            else if (propertes1 != "")
            {
                message = title1 + propertes1 + ulClose;
            }
            else if (propertes2 != "")
            {
                message = title2 + propertes2 + ulClose;
            }


            return(message);
        }
        private MemoryStream AddMaterialToZip(string[] typesString, ElsevierMaterials.Models.Domain.Export.Material material, ElsevierMaterials.Models.Domain.Export.Exporter exporter)
        {
            MemoryStream msMaterial = new MemoryStream();

            msMaterial.Seek(0, SeekOrigin.Begin);

            using (ZipFile zip = new ZipFile())
            {
                foreach (var item in typesString)
                {
                    IList <ElsevierMaterials.Models.Domain.Export.Property> properties = material.Properties;

                    ExportTypeEnum             exportType = (ExportTypeEnum)int.Parse(item);
                    bool                       hasAtLeatsOnePropertyForExport = false;
                    ExportType                 ep = exporter.ExportTypes.Where(m => m.ExportTypeId == exportType).FirstOrDefault();
                    IList <TMPropertyTypeEnum> propertiesForSelectedExport = ep.Properties;
                    foreach (var prop in material.Properties)
                    {
                        int notMappedPropertyId       = prop.ElsBasicInfo.SourceTypeId != 0 ? prop.ElsBasicInfo.SourceTypeId : prop.ElsBasicInfo.TypeId;
                        TMPropertyTypeEnum propertyId = MapElsPropertyId(notMappedPropertyId, (SourceTypeEnum)material.MaterialInfo.SourceId);

                        if (propertiesForSelectedExport.Contains(propertyId))
                        {
                            hasAtLeatsOnePropertyForExport = true;
                            break;
                        }
                    }
                    if (hasAtLeatsOnePropertyForExport)
                    {
                        MemoryStream mz = getZipStream(int.Parse(item), properties, material);
                        mz.Seek(0, SeekOrigin.Begin);

                        if (exportType == ExportTypeEnum.Esi)
                        {
                            zip.AddEntry("ESI ProCAST.zip", mz);
                        }
                        else if (exportType == ExportTypeEnum.Siemens)
                        {
                            zip.AddEntry("Siemens NX.zip", mz);
                        }
                        else
                        {
                            zip.AddEntry(exportType + ".zip", mz);
                        }
                    }
                }
                zip.Save(msMaterial);
            }

            return(msMaterial);
        }