Example #1
0
        private static void PrintPlanets(DBStar star, ISheet sheet, int i, IRow row, int j, ICell cell, DBPlanet planet)
        {
            row  = sheet.GetRow(i);
            cell = row.GetCell(j);
            cell.SetCellValue(planet.Name);
            cell = row.GetCell(j + 1) ?? row.CreateCell(j + 1);
            cell.SetCellValue(planet.MiddleDistanceValue +
                              planet.MiddleDistanceUnit.ToString());
            cell = row.GetCell(j + 2) ?? row.CreateCell(j + 2);
            cell.SetCellValue(planet.Radius);
            cell = row.GetCell(j + 3) ?? row.CreateCell(j + 3);
            cell.SetCellValue(planet.Star);
            cell = row.GetCell(j + 4) ?? row.CreateCell(j + 4);
            cell.SetCellValue(planet.Temperature);
            cell = row.GetCell(j + 5) ?? row.CreateCell(j + 5);
            cell.SetCellValue(planet.Type.ToString());
            cell = row.GetCell(j + 6) ?? row.CreateCell(j + 6);
            cell.SetCellValue(planet.InventingDate);
            cell.CellStyle.DataFormat = 14;

            cell = row.GetCell(j + 7) ?? row.CreateCell(j + 7);
            cell.SetCellValue(planet.HasAtmosphere);
            if (planet != star.Planets.Last())
            {
                row = sheet.CopyRow(i, i + 1);
            }
        }
Example #2
0
        public IActionResult AddStar(IFormFile Photo, string Name, string Galaxy, uint Radius, uint Temperature, DateTime Date, uint Dist, string Unit)
        {
            byte[] ph = new byte[0];
            if (Photo != null)
            {
                var str = Photo.OpenReadStream();
                ph = new byte[str.Length];
                str.Read(ph, 0, ph.Length);
                str.Close();
            }
            var dbs     = new DBStar(Date, ph, Name, new Distance(Dist, StringToUnit(Unit)), Radius, Temperature, Galaxy);
            var xml     = new XmlSerializer(typeof(List <DBPlanet>));
            var stream  = new MemoryStream(HttpContext.Session.Get("planets") ?? new byte[0]);
            var planets = xml.Deserialize(stream) as List <DBPlanet>;

            foreach (var planet in planets)
            {
                dbs.Planets.Add(planet);
            }
            db.Stars.Add(dbs);
            db.Planets.AddRange(dbs.Planets);
            db.Moons.AddRange(dbs.Planets.SelectMany(pl => pl.Moons));
            db.SaveChanges();
            HttpContext.Session.Set("img", ph);
            //HttpContext.Session.Set("imgflag", new byte[1]{1});
            return(View("~/Views/Views/StarView.cshtml", dbs));
        }
Example #3
0
        private static void PrintStarProp(DBStar star, ISheet sheet, ref int i, IRow row, int j, ICell cell)
        {
            cell.SetCellValue("Дата открытия");
            cell = row.GetCell(j + 1) ?? row.CreateCell(j + 1);
            cell.SetCellValue(star.InventingDate);
            cell.CellStyle.DataFormat = 14;

            row = sheet.CopyRow(i, i + 1);
            i++;
            cell = row.GetCell(j) ?? row.CreateCell(j);
            cell.SetCellValue("Галактика");
            row.CreateCell(j + 1).SetCellValue(star.Galaxy ?? "");
            row  = sheet.CreateRow(i++);
            cell = row.GetCell(j) ?? row.CreateCell(j);
            cell.SetCellValue("Радиус");
            row.CreateCell(j + 1).SetCellValue(star.Radius);
            row = sheet.CreateRow(i++);

            cell = row.GetCell(j) ?? row.CreateCell(j);
            cell.SetCellValue("Температура");
            row.CreateCell(j + 1).SetCellValue(star.Temperature);
            row = sheet.CreateRow(i++);

            cell = row.GetCell(j) ?? row.CreateCell(j);
            cell.SetCellValue("Среднее расстояние");
            row.CreateCell(j + 1).SetCellValue(star.MiddleDistanceValue);
            row = sheet.CreateRow(i++);
        }
Example #4
0
        public IActionResult StarEditor()
        {
            var l = new List <DBPlanet>();

            SaveToSession(l);
            var star = new DBStar();

            return(View(star));
        }
Example #5
0
        public void EditStar()
        {
            var xml         = new XmlSerializer(typeof(StarPair));
            var requestBody = HttpContext.Request.Body;
            var st          = (StarPair)xml.Deserialize(requestBody /*new StringReader(s)*/);
            //var st = JsonConvert.DeserializeObject<Star>(s);
            var dbs = new DBStar(st.Star);

            dbs.Id = st.Id;
            using (var db = new AstronomicDirectoryDbContext())
            {
                db.Entry(dbs).State = EntityState.Modified;
                db.SaveChanges();
            }
        }
Example #6
0
        private static void PrintStar(DBStar star, ISheet sheet)
        {
            for (var i = sheet.FirstRowNum + 1; i <= sheet.LastRowNum; i++) //Read Excel File
            {
                var row = sheet.GetRow(i);
                if (row == null)
                {
                    continue;
                }
                if (row.Cells.All(d => d.CellType == CellType.Blank))
                {
                    continue;
                }
                var lastCellNum = row.LastCellNum;
                for (int j = row.FirstCellNum; j < lastCellNum; j++)
                {
                    var cell = row.GetCell(j);
                    if (cell != null)
                    {
                        if (cell.StringCellValue == "$PropRow")
                        {
                            PrintStarProp(star, sheet, ref i, row, j, cell);
                            break;
                        }

                        if (cell.StringCellValue == "$Planets")
                        {
                            foreach (var planet in star.Planets)
                            {
                                PrintPlanets(star, sheet, i++, row, j, cell, planet);
                            }
                            break;
                        }

                        if (cell.StringCellValue == "$Moons")
                        {
                            foreach (var moon in star.Planets.SelectMany(p => p.Moons))
                            {
                                PrintMoons(star, sheet, i++, row, j, cell, moon);
                            }
                            break;
                        }
                    }
                }
            }
        }
Example #7
0
        public async Task StarViews(/*string s*/)
        {
            var xml         = new XmlSerializer(typeof(Star));
            var requestBody = HttpContext.Request.Body;
            var st          = (Star)xml.Deserialize(requestBody /*new StringReader(s)*/);
            //var st = JsonConvert.DeserializeObject<Star>(s);
            var dbs = new DBStar(st);

            using (var db = new AstronomicDirectoryDbContext())
            {
                //if (db.Stars.FirstOrDefault(s => s.Name == st.Name) == null)
                await db.Stars.AddAsync(dbs);

                await db.Planets.AddRangeAsync(dbs.Planets);

                await db.Moons.AddRangeAsync(dbs.Planets.SelectMany(pl => pl.Moons));

                //foreach (var pl in dbs.Planets)
                //    if(pl.Moons != null)
                await db.SaveChangesAsync();
            }
        }
Example #8
0
        public IActionResult StarView(IFormFile star)
        {
            var xml = new XmlSerializer(typeof(Star));
            var fs  = star.OpenReadStream();
            var st  = (Star)xml.Deserialize(fs);

            fs.Close();
            var dbs = new DBStar(st);

            //if (db.Stars.FirstOrDefault(s => s.Name == st.Name) == null)
            //{
            db.Stars.Add(dbs);
            db.Planets.AddRange(dbs.Planets);
            db.Moons.AddRange(dbs.Planets.SelectMany(pl => pl.Moons));
            //foreach (var pl in dbs.Planets)
            //    if(pl.Moons != null)

            db.SaveChanges();
            //}

            return(View(dbs));
        }
Example #9
0
        private static void PrintMoons(DBStar star, ISheet sheet, int i, IRow row, int j, ICell cell, DBMoon moon)
        {
            row  = sheet.GetRow(i);
            cell = row.GetCell(j);
            cell.SetCellValue(moon.Name);
            cell = row.GetCell(j + 1) ?? row.CreateCell(j + 1);
            cell.SetCellValue(moon.MiddleDistanceValue +
                              moon.MiddleDistanceUnit.ToString());
            cell = row.GetCell(j + 2) ?? row.CreateCell(j + 2);
            cell.SetCellValue(moon.Radius);
            cell = row.GetCell(j + 3) ?? row.CreateCell(j + 3);
            cell.SetCellValue(moon.PlanetOwner);
            cell = row.GetCell(j + 4) ?? row.CreateCell(j + 4);
            cell.SetCellValue(moon.Temperature);
            cell = row.GetCell(j + 5) ?? row.CreateCell(j + 5);
            cell.SetCellValue(moon.InventingDate);
            cell.CellStyle.DataFormat = 14;

            cell = row.GetCell(j + 6) ?? row.CreateCell(j + 6);
            cell.SetCellValue(moon.HasAtmosphere); /*
                                                    * if (planet != star.Planets.Last())
                                                    * row = sheet.CopyRow(i, i + 1);*/
        }
        /*public Planet(Bitmap photo, string name, Distance middleDistance, uint radius, uint temperature) : base(photo, name, middleDistance, radius, temperature)
         *  {
         *  }*/

        public DBPlanet(DateTime inventingDate, byte[] photo, string name, Distance middleDistance, uint radius, bool hasAtmosphere, PlanetType type, DBStar star, uint temperature = 0, HashSet <Moon> moons = null)
        //base(inventingDate, photo, name, middleDistance, radius, temperature)
        {
            //Database.EnsureCreated();
            HasAtmosphere = hasAtmosphere;
            Type          = type;
            Star          = star.Name;

            Moons = new Collection <DBMoon>();
            if (moons != null)
            {
                foreach (var moon in moons)
                {
                    Moons.Add(new DBMoon(moon, Id));
                }
            }

            Name = name;
            MiddleDistanceValue = middleDistance.Value;
            MiddleDistanceUnit  = middleDistance.Unit;

            Radius      = radius;
            Temperature = temperature;
            //Galaxy = galaxy;
            InventingDate = inventingDate;
        }