コード例 #1
0
        public ActionResult ExportAll ()
        {
            var model = new XML { XMLFamilyGroup = new List<XMLSystemFamily>() };
            foreach(var fam in db.LsystemFamily.Where(x=>x.LsystemFamilyID!=62).ToList())
            {
                var systemfamily = new XMLSystemFamily();
                systemfamily.FamilyName = fam.FamilyName;
                systemfamily.SystemCount = fam.Lsystems.Count();
                systemfamily.Systems = new List<XMLSystems>();
                systemfamily.DescriptionDE = fam.DescriptionDE;
                systemfamily.DescriptionEN = fam.DescriptionEN;
                systemfamily.ModifiedOn = fam.ModifiedOn;
                foreach(var sys in fam.Lsystems)
                {
                    var system = new XMLSystems();
                    system.SystemName = sys.LsystemName;
                    system.MaterialNumber = sys.MaterialNumber;
                    system.ModifiedOn = sys.ModifiedOn;
                    system.DescriptionEN = sys.DescriptionEN;
                    system.DescriptionDE = sys.DescriptionDE;
                    system.Options = new List<XMLOptions>();
                    foreach(var op in sys.Options)
                    {
                        var opt = new XMLOptions();
                        opt.Option = op.OptionName;
                        opt.TechnicalCharacteristic = op.TechnicalCharacteristic.TCName;
                        opt.ModifiedOn = op.ModifiedOn;
                        opt.DescriptionDE = op.DescriptionDE;
                        opt.DescriptionEN = op.DescriptionEN;
                        opt.OptionValues = new List<XMLOptionValues>();
                        foreach(var ov in op.OptionValues)
                        {
                            var opv = new XMLOptionValues();
                            opv.OptionValue = ov.OptionVal;
                            opv.DescriptionDE= ov.DescriptionDE;
                            opv.DescriptionEN = ov.DescriptionEN;
                            opv.ModifiedOn = ov.ModifiedOn;
                            opv.SetValues = new List<XMLSetValues>();
                            foreach(var sv in ov.SetValue)
                            {
                                var set = new XMLSetValues();
                                set.Property = sv.TcSet.SetName;
                                set.Status = sv.TcSet.DataStatus.ToString();
                                set.Unit = sv.TcSet.PhysicalUnit;
                                set.ModifiedOn = sv.ModifiedOn;
                                set.Value = sv.Value;
                                opv.SetValues.Add(set);
                            }
                            opt.OptionValues.Add(opv);
                        }
                        system.Options.Add(opt);
                    }
                    systemfamily.Systems.Add(system);
                }
                model.XMLFamilyGroup.Add(systemfamily);
            }
            var serializer = new XmlSerializer(typeof(XML));
            var path = String.Format("{0}xmlfiles", AppDomain.CurrentDomain.BaseDirectory);
            FileStream fs = new FileStream("\\\\FE0VMC0643\\TeDaLS\\xmlfiles\\sample.xml", FileMode.OpenOrCreate);
            fs.Close();
            StreamWriter writer = new StreamWriter(fs.Name);
            serializer.Serialize(writer.BaseStream, model);

            writer.Close();
            //System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
            //response.StatusCode = 200;

            //response.AddHeader("content-disposition", "attachment; filename=" + fs.Name);
            //response.AddHeader("Content-Transfer-Encoding", "binary");
            //response.AddHeader("Content-Length", _Buffer.Length.ToString());

            // response.ContentType = "application-download";
            //response.TransmitFile(fs.Name);
            string filename = "ExportAll _ " + DateTime.Now + ".xml";
            return File(fs.Name, "text/xml", filename);
            
        }
コード例 #2
0
        //public ActionResult XmlExport()
        //{
        //    var model = db.LsystemFamily.ToList();
        //    return View(model);
        //}

        //Export a particular system family
        public ActionResult XmlExport(int id)
        {

            // var model = new LsystemFamily();
            // model = db.LsystemFamily.FirstOrDefault(x => x.LsystemCount == 0);
            //// model.Lsystems = db.Lsystem.Where(x => x.LsystemFamilyID == model.LsystemFamilyID);
            // var serializer = new XmlSerializer(typeof(export_test));
            // //XmlSerializer serializer = new XmlSerializer(p.GetType());
            // StreamWriter writer = new StreamWriter(@"C:\Users\vav9sw\Documents\Visual Studio 2013\Projects\TEDALS-Ver01.4\xml\newxml.xml");
            // serializer.Serialize(writer.BaseStream, model);

            if (db.UserRight.FirstOrDefault(x => x.UserCode == User.Identity.Name).IsExporter || db.UserRight.FirstOrDefault(x => x.UserCode == User.Identity.Name).IsAdmin)
            {
                try
                {
                    //if (id == null)
                    //{
                    //    ViewBag.Error = "A null parameter was passed to the function";
                    //    return View("Error");
                    //}



                var model = new XMLSystemFamily();
                var lsystemfamily = db.LsystemFamily.FirstOrDefault(x => x.LsystemFamilyID == id);
                model.FamilyName = lsystemfamily.FamilyName;
                model.SystemCount = lsystemfamily.Lsystems.Count();
                model.DescriptionDE = lsystemfamily.DescriptionDE;
                model.DescriptionEN = lsystemfamily.DescriptionEN;

                model.ModifiedOn = lsystemfamily.ModifiedOn;
                model.Systems = new List<XMLSystems>();
                foreach (var item in lsystemfamily.Lsystems)
                {
                    XMLSystems sys = new XMLSystems
                    {
                        SystemName = item.LsystemName,
                        MaterialNumber = item.MaterialNumber,
                        DescriptionDE = item.DescriptionDE,
                        DescriptionEN = item.DescriptionEN,

                        ModifiedOn = item.ModifiedOn,
                        Options = new List<XMLOptions>()
                    };
                    foreach (var op in item.Options)
                    {
                        XMLOptions option = new XMLOptions
                        {
                            Option = op.OptionName,
                            TechnicalCharacteristic = op.TechnicalCharacteristic.TCName,

                            ModifiedOn = op.ModifiedOn,
                            DescriptionDE = op.DescriptionDE,
                            DescriptionEN = op.DescriptionEN,
                            OptionValues = new List<XMLOptionValues>()
                        };
                        foreach (var ov in op.OptionValues)
                        {
                            XMLOptionValues optionvalues = new XMLOptionValues
                            {
                                OptionValue = ov.OptionVal,

                                ModifiedOn = ov.ModifiedOn,
                                DescriptionDE = ov.DescriptionDE,
                                DescriptionEN = ov.DescriptionEN,
                                SetValues = new List<XMLSetValues>()
                            };
                            foreach (var setvalue in ov.SetValue)
                            {
                                XMLSetValues setvalues = new XMLSetValues
                                {

                                    ModifiedOn = setvalue.ModifiedOn,
                                    Property = setvalue.TcSet.SetName,
                                    Value = setvalue.Value,
                                    Unit = setvalue.TcSet.PhysicalUnit,
                                    Status = setvalue.TcSet.DataStatus.ToString()
                                };
                                optionvalues.SetValues.Add(setvalues);
                            }
                            option.OptionValues.Add(optionvalues);
                        }
                        sys.Options.Add(option);
                    }
                    model.Systems.Add(sys);
                }

                var serializer = new XmlSerializer(typeof(XMLSystemFamily));
                var path = String.Format("{0}xmlfiles", AppDomain.CurrentDomain.BaseDirectory);
                FileStream fs = new FileStream("\\\\FE0VMC0643\\TeDaLS\\xmlfiles\\sample.xml", FileMode.OpenOrCreate);
                fs.Close();
                StreamWriter writer = new StreamWriter(fs.Name);
                serializer.Serialize(writer.BaseStream, model);

                writer.Close();
                //System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
                //response.StatusCode = 200;

                //response.AddHeader("content-disposition", "attachment; filename=" + fs.Name);
                //response.AddHeader("Content-Transfer-Encoding", "binary");
                //response.AddHeader("Content-Length", _Buffer.Length.ToString());

                // response.ContentType = "application-download";
                //response.TransmitFile(fs.Name);
                string filename = model.FamilyName + "_" + DateTime.Now + ".xml";
                return File(fs.Name, "text/xml", filename);
                }
                catch(Exception e)
                {
                    ViewBag.Error = e.Message;
                    return View("Error");
                }
            }
            else
                return View("AuthorizationError");
        }