Beispiel #1
0
        private void SaveToHtml(string html_filename)
        {
            string pic_filename = Path.Combine(Path.GetDirectoryName(html_filename), Path.GetFileNameWithoutExtension(html_filename) + ".jpg");

            if (!Globals.Tournaments.ContainsKey(FCompetition.Info.TournamentId))
            {
                DatabaseManager.CurrentDb.ReadTournamentList(Globals.Tournaments);
            }
            TournamentInfo tInfo  = Globals.Tournaments[FCompetition.Info.TournamentId].Info;
            string         tDate  = tInfo.DateBegin.ToString("dd.MM.yyyy") + " - " + tInfo.DateEnd.ToString("dd.MM.yyyy");
            string         tPlace = tInfo.Place;
            string         tName  = tInfo.Name;
            string         cName  = FCompetition.Info.Name;
            string         cDate  = FCompetition.Info.Date.ToString("dd.MM.yyyy");
            string         title  = String.Format("{0}. {1}. {2} - {3}", tDate, tPlace, tName, cName);

            HtmlGenerator html = new HtmlGenerator();

            html.Title = title;
            StringBuilder body = new StringBuilder();

            body.AppendLine(html.TagString("h1", tDate + " - " + tPlace));
            body.AppendLine(html.TagString("h1", tName));
            body.AppendLine(html.TagString("h2", cName));

            // Список участников
            body.AppendLine(html.TagString("h3", Localizator.Dictionary.GetString("PLAYER_IN_COMPETITION", ":")));
            body.AppendLine(html.TagString("p", lvCompetitionPlayers.ToHtmlTableString()));

            // Сетка турнира
            if (FCompetition.Info.Status != CompetitionInfo.CompetitionState.RegistrationAndSeeding)
            {
                Bitmap bmp = pnlCompetition.GetPicture(new SolidBrush(Color.White));
                PictureSaver.SavePicture(bmp, pic_filename, ImageFormat.Png);
                string fn  = Path.GetFileName(pic_filename);
                string img = String.Format("<img src='{0}' alt=''/>", fn);
                body.AppendLine(html.TagString("h3", Localizator.Dictionary.GetString("COMPETITION_MATCHES", " :")));
                body.AppendLine(html.TagString("p", img));
            }

            // Результаты
            if (FCompetition.Info.Status == CompetitionInfo.CompetitionState.Finished)
            {
                body.AppendLine(html.TagString("h3", Localizator.Dictionary.GetString("COMPETITION_RESULTS", " :")));
                body.AppendLine(html.TagString("p", lvPlayerPlace.ToHtmlTableString()));
            }

            // Изменение рейтинга
#if FEDITION
            if (FCompetition.Info.Status == CompetitionInfo.CompetitionState.Finished && FCompetition.Info.ChangesRating)
            {
                body.AppendLine(html.TagString("h3", Localizator.Dictionary.GetString("RATING_CHANGES", " :")));
                body.AppendLine(html.TagString("p", lvRatingAfter.ToHtmlTableString()));
            }
#endif
            html.Body = body.ToString();
            html.SaveTo(html_filename);
        }
Beispiel #2
0
        public ActionResult AddPicture(AddPictureModel model, HttpPostedFileBase file)
        {
            var user = db.User.FirstOrDefault(x => x.login == User.Identity.Name);

            if (user == null || !IsItMineGallery(model.galleryId))
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ViewBag.galleryId = new SelectList(user.Gallery, "id", "name");
            if (file == null)
            {
                ModelState.AddModelError(string.Empty, "You must select an image.");
                return(View(model));
            }

            if (file.ContentLength > 750 * 1000)
            {
                ModelState.AddModelError(string.Empty, "File size must be less than 750 kilobytes.");
            }

            string file_extention = Path.GetExtension(file.FileName).ToLower();

            if (file_extention != ".mpo" && file_extention != ".jpg")
            {
                ModelState.AddModelError(string.Empty, "File extention must be '.mpo' or '.jpg'.");
            }

            if (model.isAdvanced && model.isTo2d && model.leftOrRight < 0 && model.leftOrRight > 1)
            {
                ModelState.AddModelError(string.Empty, "You must choose which of the images (left or right) should be saved in 2D.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Picture picture = new Picture
            {
                description  = model.description,
                galleryId    = model.galleryId,
                CreationDate = DateTime.Now
            };

            db.Picture.Add(picture);
            db.SaveChanges();

            picture = new PictureSaver(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Picture")).AnalyzeAndSave(picture, model, file);

            picture.Gallery.LastPicture = picture;
            db.Entry(picture).State     = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Details", "Gallery", new { id = picture.galleryId }));
        }
Beispiel #3
0
 private void btnSavePicture_Click(object sender, EventArgs e)
 {
     if (pnlCompetition == null)
     {
         return;
     }
     saveDialog.DefaultExt = "";
     saveDialog.FileName   = "";
     saveDialog.Title      = Localizator.Dictionary.GetString("SAVE_MATCHES");
     saveDialog.Filter     = PictureSaver.Filter;
     if (saveDialog.ShowDialog() == DialogResult.OK)
     {
         Bitmap bmp = pnlCompetition.GetPicture(new SolidBrush(Color.White));
         PictureSaver.SavePicture(bmp, saveDialog.FileName, Utils.PictureSaver.Formats[saveDialog.FilterIndex - 1]);
     }
     pnlCompetition.Refresh();
 }