Ejemplo n.º 1
0
        public int GetPrice(SizeEnum size)
        {
            switch (size)
            {
            case SizeEnum.Small:
                return(_price);

            case SizeEnum.Medium:
                return((int)Math.Ceiling(_price * 1.2));

            case SizeEnum.Large:
                return((int)Math.Ceiling(_price * 1.4));

            default:
                throw new ArgumentException($"We do not have specified price for this size {size.ToString()}");
            }
        }
Ejemplo n.º 2
0
        /**
         * <summary>Gets the page size of the given format and orientation.</summary>
         * <param name="size">Page size.</param>
         * <param name="orientation">Page orientation.</param>
         */
        public static Size GetSize(
            SizeEnum size,
            OrientationEnum orientation
            )
        {
            int width, height = 0;

            // Size.
            {
                string sizeName = size.ToString();
                Match  match    = IsoSeriesSizePattern.Match(sizeName);
                // Is it an ISO standard size?
                if (match.Success)
                {
                    int    baseWidth, baseHeight = 0;
                    string isoSeriesSize = match.Groups[1].Value;
                    if (isoSeriesSize.Equals(IsoSeriesSize_A))
                    {
                        baseWidth = 2384; baseHeight = 3370;
                    }
                    else if (isoSeriesSize.Equals(IsoSeriesSize_B))
                    {
                        baseWidth = 2834; baseHeight = 4008;
                    }
                    else if (isoSeriesSize.Equals(IsoSeriesSize_C))
                    {
                        baseWidth = 2599; baseHeight = 3676;
                    }
                    else
                    {
                        throw new NotImplementedException("Paper format " + size + " not supported yet.");
                    }

                    int    isoSeriesSizeIndex  = Int32.Parse(match.Groups[2].Value);
                    double isoSeriesSizeFactor = 1 / Math.Pow(2, isoSeriesSizeIndex / 2d);

                    width  = (int)Math.Floor(baseWidth * isoSeriesSizeFactor);
                    height = (int)Math.Floor(baseHeight * isoSeriesSizeFactor);
                }
                else // Non-ISO size.
                {
                    switch (size)
                    {
                    case SizeEnum.ArchA: width = 648; height = 864; break;

                    case SizeEnum.ArchB: width = 864; height = 1296; break;

                    case SizeEnum.ArchC: width = 1296; height = 1728; break;

                    case SizeEnum.ArchD: width = 1728; height = 2592; break;

                    case SizeEnum.ArchE: width = 2592; height = 3456; break;

                    case SizeEnum.AnsiA:
                    case SizeEnum.Letter: width = 612; height = 792; break;

                    case SizeEnum.AnsiB:
                    case SizeEnum.Tabloid: width = 792; height = 1224; break;

                    case SizeEnum.AnsiC: width = 1224; height = 1584; break;

                    case SizeEnum.AnsiD: width = 1584; height = 2448; break;

                    case SizeEnum.AnsiE: width = 2448; height = 3168; break;

                    case SizeEnum.Legal: width = 612; height = 1008; break;

                    case SizeEnum.Executive: width = 522; height = 756; break;

                    case SizeEnum.Statement: width = 396; height = 612; break;

                    default: throw new NotImplementedException("Paper format " + size + " not supported yet.");
                    }
                }
            }

            // Orientation.
            switch (orientation)
            {
            case OrientationEnum.Portrait:
                return(new Size(width, height));

            case OrientationEnum.Landscape:
                return(new Size(height, width));

            default:
                throw new NotImplementedException("Orientation " + orientation + " not supported yet.");
            }
        }
Ejemplo n.º 3
0
        /**
          <summary>Gets the page size of the given format and orientation.</summary>
          <param name="size">Page size.</param>
          <param name="orientation">Page orientation.</param>
        */
        public static Size GetSize(
            SizeEnum size,
            OrientationEnum orientation
            )
        {
            int width, height = 0;

              // Size.
              {
            string sizeName = size.ToString();
            Match match = IsoSeriesSizePattern.Match(sizeName);
            // Is it an ISO standard size?
            if(match.Success)
            {
              int baseWidth, baseHeight = 0;
              string isoSeriesSize = match.Groups[1].Value;
              if(isoSeriesSize.Equals(IsoSeriesSize_A))
              {baseWidth = 2384; baseHeight = 3370;}
              else if(isoSeriesSize.Equals(IsoSeriesSize_B))
              {baseWidth = 2834; baseHeight = 4008;}
              else if(isoSeriesSize.Equals(IsoSeriesSize_C))
              {baseWidth = 2599; baseHeight = 3676;}
              else
              {throw new NotImplementedException("Paper format " + size + " not supported yet.");}

              int isoSeriesSizeIndex = Int32.Parse(match.Groups[2].Value);
              double isoSeriesSizeFactor = 1 / Math.Pow(2,isoSeriesSizeIndex/2d);

              width = (int)Math.Floor(baseWidth * isoSeriesSizeFactor);
              height = (int)Math.Floor(baseHeight * isoSeriesSizeFactor);
            }
            else // Non-ISO size.
            {
              switch(size)
              {
            case SizeEnum.ArchA: width = 648; height = 864; break;
            case SizeEnum.ArchB: width = 864; height = 1296; break;
            case SizeEnum.ArchC: width = 1296; height = 1728; break;
            case SizeEnum.ArchD: width = 1728; height = 2592; break;
            case SizeEnum.ArchE: width = 2592; height = 3456; break;
            case SizeEnum.AnsiA: case SizeEnum.Letter: width = 612; height = 792; break;
            case SizeEnum.AnsiB: case SizeEnum.Tabloid: width = 792; height = 1224; break;
            case SizeEnum.AnsiC: width = 1224; height = 1584; break;
            case SizeEnum.AnsiD: width = 1584; height = 2448; break;
            case SizeEnum.AnsiE: width = 2448; height = 3168; break;
            case SizeEnum.Legal: width = 612; height = 1008; break;
            case SizeEnum.Executive: width = 522; height = 756; break;
            case SizeEnum.Statement: width = 396; height = 612; break;
            default: throw new NotImplementedException("Paper format " + size + " not supported yet.");
              }
            }
              }

              // Orientation.
              switch(orientation)
              {
            case OrientationEnum.Portrait:
              return new Size(width,height);
            case OrientationEnum.Landscape:
              return new Size(height,width);
            default:
              throw new NotImplementedException("Orientation " + orientation + " not supported yet.");
              }
        }
Ejemplo n.º 4
0
        public User Insert(User user)
        {
            using (var connection = new MySqlConnection(_connectionString))
            {
                connection.Open();
                MySqlCommand cmd = connection.CreateCommand();

                /* Get User table query */
                cmd.CommandText =
                    @"INSERT INTO User (Email, Password, IsBeginner)
                      VALUES (@Email, @Password, @IsBeginner);";
                cmd.Parameters.AddWithValue("@Email", user.Email);
                cmd.Parameters.AddWithValue("@Password", user.Password);
                cmd.Parameters.AddWithValue("@IsBeginner", user.Preference.IsBeginner);

                cmd.ExecuteNonQuery();

                cmd.CommandText = @"SELECT UserId FROM User
                    WHERE Email = @Email";

                int userId = (int)cmd.ExecuteScalar();

                foreach (string language in user.Preference.Languages)
                {
                    /* Language table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"SELECT LanguageId FROM Language
                            WHERE LanguageName = @LanguageName;";
                    cmd.Parameters.AddWithValue("@LanguageName", language);
                    int languageId = (int)cmd.ExecuteScalar();

                    /* UserLanguage table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"INSERT INTO UserLanguage (UserId, LanguageId)
                          VALUES (@UserId, @LanguageId);";
                    cmd.Parameters.AddWithValue("@UserId", userId);
                    cmd.Parameters.AddWithValue("@LanguageId", languageId);
                    cmd.ExecuteNonQuery();
                }

                foreach (string topic in user.Preference.Topics)
                {
                    /* Topic table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"SELECT TopicId FROM Topic
                          WHERE TopicName = @TopicName;";
                    cmd.Parameters.AddWithValue("@TopicName", topic);
                    int topicId = (int)cmd.ExecuteScalar();

                    /* UserTopic table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"INSERT INTO UserTopic (UserId, TopicId)
                          VALUES (@UserId, @TopicId);";
                    cmd.Parameters.AddWithValue("@UserId", userId);
                    cmd.Parameters.AddWithValue("@TopicId", topicId);
                    cmd.ExecuteNonQuery();
                }

                foreach (SizeEnum.Size size in user.Preference.Sizes)
                {
                    /* Size table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"SELECT SizeId FROM Size WHERE SizeName = @SizeName;";
                    cmd.Parameters.AddWithValue("@SizeName", SizeEnum.ToString(size));
                    int sizeId = (int)cmd.ExecuteScalar();

                    /* UserSize table query */
                    cmd.Parameters.Clear();
                    cmd.CommandText =
                        @"INSERT INTO UserSize (UserId, SizeId)
                          VALUES (@UserId, @SizeId);";
                    cmd.Parameters.AddWithValue("@UserId", userId);
                    cmd.Parameters.AddWithValue("@SizeId", sizeId);
                    cmd.ExecuteNonQuery();
                }
            }
            return(user);
        }