Пример #1
0
        /// <summary>
        /// Hexa 값에 해당하는 Color.Blue, Color.Red 등의 Color structure를 리턴함.
        /// </summary>
        public static Color GetColorByHexa(string Hexa)
        {
            Hexa = NormalizeHexa(Hexa);
            if (string.IsNullOrEmpty(Hexa))
            {
                throw new Exception(Hexa + "는(은) 없는 색입니다.");
            }

            int R = CMath.Dec(Hexa.Substring(0, 2));

            if ((R < 0) || (R > 255))
            {
                throw new Exception(Hexa + "는(은) 없는 색입니다.");
            }

            int G = CMath.Dec(Hexa.Substring(2, 2));

            if ((G < 0) || (G > 255))
            {
                throw new Exception(Hexa + "는(은) 없는 색입니다.");
            }

            int B = CMath.Dec(Hexa.Substring(4, 2));

            if ((G < 0) || (G > 255))
            {
                throw new Exception(Hexa + "는(은) 없는 색입니다.");
            }

            return(Color.FromArgb(R, G, B));
        }
Пример #2
0
        /// <summary>
        /// Hexa 값에 해당하는 VB Color 값을 리턴함.
        /// </summary>
        public static int GetVbColorByHexa(string Hexa)
        {
            Hexa = NormalizeHexa(Hexa);
            if (Hexa == "")
            {
                return(0);
            }

            int R = CMath.Dec(Hexa.Substring(0, 2));

            if ((R < 0) || (R > 255))
            {
                return(0);
            }

            int G = CMath.Dec(Hexa.Substring(2, 2));

            if ((G < 0) || (G > 255))
            {
                return(0);
            }

            int B = CMath.Dec(Hexa.Substring(4, 2));

            if ((G < 0) || (G > 255))
            {
                return(0);
            }

            return(GetVbRGB(R, G, B));
        }
Пример #3
0
        /// <summary>
        /// 통신에서 전송시 깨지지 않도록 61진수 형태로 변환된 Unicode 문자열을 원래의 문자열로 변환함.
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Delim"></param>
        /// <returns></returns>
        public static string DecryptUnicode(string Text)
        {
            const char Delim = '|';

            string All = "";
            string s   = "";

            for (int i = 0, i2 = Text.Length; i < i2; i++)
            {
                char c = Text[i];
                if (c == Delim)
                {
                    if (Text.Substring(i + 1, 1) != Delim.ToString())
                    {
                        string Num61   = Text.Substring(i + 1, 3);
                        int    AscCode = (int)CMath.Get10FromN(Num61, 61);
                        s  = ((char)AscCode).ToString();
                        i += 3;
                    }
                    else
                    {
                        s = c.ToString();
                        i++;
                    }
                }
                else
                {
                    s = c.ToString();
                }

                All += s;
            }

            return(All);
        }
Пример #4
0
        /// <summary>
        /// Unicode 문자열을 통신에서 전송시 깨지지 않도록 61진수 형태로 변환함.
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="Delim"></param>
        /// <returns></returns>
        public static string EncryptUnicode(string Text, bool EncodeUrlParam)
        {
            const char Delim = '|';
            string     All   = "";

            string s = "";

            for (int i = 0, i2 = Text.Length; i < i2; i++)
            {
                char c = Text[i];
                if (CTwoByte.Is2ByteChar(c))
                {
                    int    AscCode = (int)c;
                    string Num61   = CMath.GetNFrom10(AscCode, 61);
                    s = Delim + Num61.PadRight(3);
                }
                else if (c == Delim)
                {
                    s = Delim.ToString() + Delim.ToString();
                }
                else
                {
                    s = EncodeUrlParam ? HttpUtility.UrlEncode(c.ToString()) : c.ToString();
                }

                All += s;
            }

            return(All);
        }
Пример #5
0
        /// <summary>
        /// WebRequest를 이용해 Ftp 기능을 이용할 때 C# 폴더는 C로 읽혀지는 경우 있어 방지하기 위함.
        /// Uri.EscapeDataString 사용하면 /까지 전부 바뀌어 문제가 있는 기호만 변경함.
        /// </summary>
        /// <param name="Url"></param>
        /// <returns></returns>
        public static string EncodeUrlForWebRequest(string Url)
        {
            string Url2 = "";

            string[] aToFind = new string[] {
                "~", "!", "@", "#", "$",
                "%", "^", "&", "(", ")",
                "_", "+", "`", "-", "=",
                "{", "}", "[", "]", ";",
                "'"
            };
            for (int i = 0; i < Url.Length; i++)
            {
                char   c = Url[i];
                string s = c.ToString();
                if (Array.IndexOf(aToFind, s) != -1)
                {
                    s = CMath.Hex(c, true);
                }

                Url2 += s;
            }

            return(Url2);
        }
Пример #6
0
        /// <summary>
        /// R, G, B 값에 해당하는 Hexa 값을 리턴함.
        /// </summary>
        /// <param name="Red">Red</param>
        /// <param name="Green">Green</param>
        /// <param name="Blue">Blue</param>
        /// <returns>Hexa 값</returns>
        public static string GetHexaByRGB(int Red, int Green, int Blue)
        {
            string r = "", g = "", b = "";

            r = CMath.Hex(Red, false);
            g = CMath.Hex(Green, false);
            b = CMath.Hex(Blue, false);
            return(r.PadLeft(2, '0') + g.PadLeft(2, '0') + b.PadLeft(2, '0'));
        }
Пример #7
0
        public static SizeF GetPaperSize(PaperKind Kind, ScaleModeConstants Mode)
        {
            #region GetValues
            if (_dicPaperSize.Count == 0)
            {
                //기본 프린터가 Microsoft XPS Document Writer인 상태에서 다음 코드로 생성함.
                //기본 프린터가 다른 경우엔 종류가 적어지고 값이 최대 10 정도 달라짐.
                //string s = "";
                //PrinterSettings settings = new PrinterSettings();
                //foreach (PaperSize size in settings.PaperSizes)
                //    s += string.Format("_dicPaperSize.Add(PaperKind.{0}, new Size({1}, {2}));\r\n", size.Kind, size.Width, size.Height);

                _dicPaperSize.Add(PaperKind.Letter, new Size(850, 1100));
                _dicPaperSize.Add(PaperKind.LetterSmall, new Size(850, 1100));
                _dicPaperSize.Add(PaperKind.Tabloid, new Size(1100, 1700));
                _dicPaperSize.Add(PaperKind.Ledger, new Size(1700, 1100));
                _dicPaperSize.Add(PaperKind.Legal, new Size(850, 1400));
                _dicPaperSize.Add(PaperKind.Statement, new Size(550, 850));
                _dicPaperSize.Add(PaperKind.Executive, new Size(725, 1050));
                _dicPaperSize.Add(PaperKind.A3, new Size(1169, 1654));
                _dicPaperSize.Add(PaperKind.A4, new Size(827, 1169));
                _dicPaperSize.Add(PaperKind.A4Small, new Size(827, 1169));
                _dicPaperSize.Add(PaperKind.A5, new Size(583, 827));
                _dicPaperSize.Add(PaperKind.B4, new Size(1012, 1433));
                _dicPaperSize.Add(PaperKind.B5, new Size(717, 1012));
                _dicPaperSize.Add(PaperKind.Folio, new Size(850, 1300));
                _dicPaperSize.Add(PaperKind.Quarto, new Size(846, 1083));
                _dicPaperSize.Add(PaperKind.Standard10x14, new Size(1000, 1400));
                _dicPaperSize.Add(PaperKind.Standard11x17, new Size(1100, 1700));
                _dicPaperSize.Add(PaperKind.Note, new Size(850, 1100));
                _dicPaperSize.Add(PaperKind.Number9Envelope, new Size(387, 887));
                _dicPaperSize.Add(PaperKind.Number10Envelope, new Size(412, 950));
                _dicPaperSize.Add(PaperKind.Number11Envelope, new Size(450, 1037));
                _dicPaperSize.Add(PaperKind.Number12Envelope, new Size(475, 1100));
                _dicPaperSize.Add(PaperKind.Number14Envelope, new Size(500, 1150));
                _dicPaperSize.Add(PaperKind.CSheet, new Size(1700, 2200));
                _dicPaperSize.Add(PaperKind.DSheet, new Size(2200, 3400));
                _dicPaperSize.Add(PaperKind.ESheet, new Size(3400, 4400));
                _dicPaperSize.Add(PaperKind.DLEnvelope, new Size(433, 866));
                _dicPaperSize.Add(PaperKind.C5Envelope, new Size(638, 902));
                _dicPaperSize.Add(PaperKind.C3Envelope, new Size(1276, 1803));
                _dicPaperSize.Add(PaperKind.C4Envelope, new Size(902, 1276));
                _dicPaperSize.Add(PaperKind.C6Envelope, new Size(449, 638));
                _dicPaperSize.Add(PaperKind.C65Envelope, new Size(449, 902));
                _dicPaperSize.Add(PaperKind.B4Envelope, new Size(984, 1390));
                _dicPaperSize.Add(PaperKind.B5Envelope, new Size(693, 984));
                _dicPaperSize.Add(PaperKind.B6Envelope, new Size(693, 492));
                _dicPaperSize.Add(PaperKind.ItalyEnvelope, new Size(433, 906));
                _dicPaperSize.Add(PaperKind.MonarchEnvelope, new Size(387, 750));
                _dicPaperSize.Add(PaperKind.PersonalEnvelope, new Size(362, 650));
                _dicPaperSize.Add(PaperKind.USStandardFanfold, new Size(1487, 1100));
                _dicPaperSize.Add(PaperKind.GermanStandardFanfold, new Size(850, 1200));
                _dicPaperSize.Add(PaperKind.GermanLegalFanfold, new Size(850, 1300));
                _dicPaperSize.Add(PaperKind.IsoB4, new Size(984, 1390));
                _dicPaperSize.Add(PaperKind.JapanesePostcard, new Size(394, 583));
                _dicPaperSize.Add(PaperKind.Standard9x11, new Size(900, 1100));
                _dicPaperSize.Add(PaperKind.Standard10x11, new Size(1000, 1100));
                _dicPaperSize.Add(PaperKind.Standard15x11, new Size(1500, 1100));
                _dicPaperSize.Add(PaperKind.InviteEnvelope, new Size(866, 866));
                _dicPaperSize.Add(PaperKind.LetterExtra, new Size(950, 1200));
                _dicPaperSize.Add(PaperKind.LegalExtra, new Size(950, 1500));
                _dicPaperSize.Add(PaperKind.A4Extra, new Size(927, 1269));
                _dicPaperSize.Add(PaperKind.LetterTransverse, new Size(850, 1100));
                _dicPaperSize.Add(PaperKind.A4Transverse, new Size(827, 1169));
                _dicPaperSize.Add(PaperKind.LetterExtraTransverse, new Size(950, 1200));
                _dicPaperSize.Add(PaperKind.APlus, new Size(894, 1402));
                _dicPaperSize.Add(PaperKind.BPlus, new Size(1201, 1917));
                _dicPaperSize.Add(PaperKind.LetterPlus, new Size(850, 1269));
                _dicPaperSize.Add(PaperKind.A4Plus, new Size(827, 1299));
                _dicPaperSize.Add(PaperKind.A5Transverse, new Size(583, 827));
                _dicPaperSize.Add(PaperKind.B5Transverse, new Size(717, 1012));
                _dicPaperSize.Add(PaperKind.A3Extra, new Size(1268, 1752));
                _dicPaperSize.Add(PaperKind.A5Extra, new Size(685, 925));
                _dicPaperSize.Add(PaperKind.B5Extra, new Size(791, 1087));
                _dicPaperSize.Add(PaperKind.A2, new Size(1654, 2339));
                _dicPaperSize.Add(PaperKind.A3Transverse, new Size(1169, 1654));
                _dicPaperSize.Add(PaperKind.A3ExtraTransverse, new Size(1268, 1752));
                _dicPaperSize.Add(PaperKind.JapaneseDoublePostcard, new Size(787, 583));
                _dicPaperSize.Add(PaperKind.A6, new Size(413, 583));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeKakuNumber2, new Size(945, 1307));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeKakuNumber3, new Size(850, 1091));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeChouNumber3, new Size(472, 925));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeChouNumber4, new Size(354, 807));
                _dicPaperSize.Add(PaperKind.LetterRotated, new Size(1100, 850));
                _dicPaperSize.Add(PaperKind.A3Rotated, new Size(1654, 1169));
                _dicPaperSize.Add(PaperKind.A4Rotated, new Size(1169, 827));
                _dicPaperSize.Add(PaperKind.A5Rotated, new Size(827, 583));
                _dicPaperSize.Add(PaperKind.B4JisRotated, new Size(1433, 1012));
                _dicPaperSize.Add(PaperKind.B5JisRotated, new Size(1012, 717));
                _dicPaperSize.Add(PaperKind.JapanesePostcardRotated, new Size(583, 394));
                _dicPaperSize.Add(PaperKind.JapaneseDoublePostcardRotated, new Size(583, 787));
                _dicPaperSize.Add(PaperKind.A6Rotated, new Size(583, 413));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeKakuNumber2Rotated, new Size(1307, 945));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeKakuNumber3Rotated, new Size(1091, 850));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeChouNumber3Rotated, new Size(925, 472));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeChouNumber4Rotated, new Size(807, 354));
                _dicPaperSize.Add(PaperKind.B6Jis, new Size(504, 717));
                _dicPaperSize.Add(PaperKind.B6JisRotated, new Size(717, 504));
                _dicPaperSize.Add(PaperKind.Standard12x11, new Size(1200, 1100));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeYouNumber4, new Size(413, 925));
                _dicPaperSize.Add(PaperKind.JapaneseEnvelopeYouNumber4Rotated, new Size(925, 413));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber1, new Size(402, 650));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber3, new Size(492, 693));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber4, new Size(433, 819));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber5, new Size(433, 866));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber6, new Size(472, 906));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber7, new Size(630, 906));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber8, new Size(472, 1217));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber9, new Size(902, 1276));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber10, new Size(1276, 1803));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber1Rotated, new Size(650, 402));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber3Rotated, new Size(693, 492));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber4Rotated, new Size(819, 433));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber5Rotated, new Size(866, 433));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber6Rotated, new Size(906, 472));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber7Rotated, new Size(906, 630));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber8Rotated, new Size(1217, 472));
                _dicPaperSize.Add(PaperKind.PrcEnvelopeNumber9Rotated, new Size(1276, 902));
            }
            #endregion GetValues

            Size  szInches100 = _dicPaperSize[Kind];
            SizeF szNew       = new SizeF(
                CMath.ConvertUnit(ScaleModeConstants.Inches, szInches100.Width / 100f, Mode),
                CMath.ConvertUnit(ScaleModeConstants.Inches, szInches100.Height / 100f, Mode));

            return(szNew);
        }
Пример #8
0
        /// <summary>
        /// HTML 스타일의 BORDER-TOP을 그림.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="c"></param>
        /// <param name="Width"></param>
        /// <param name="BorderWidth"></param>
        /// <param name="startX">
        /// direct의 위치에 따라 다음과 같이 시작 위치가 정해짐.(시계 방향)
        /// Top: 왼쪽에서 시작, Right: 위쪽에서 시작, Bottom : 오른쪽에서 시작, Left: 아래쪽에서 시작
        /// </param>
        /// <param name="startY">
        /// direct의 위치에 따라 다음과 같이 시작 위치가 정해짐.(시계 방향)
        /// Top: 왼쪽에서 시작, Right: 위쪽에서 시작, Bottom : 오른쪽에서 시작, Left: 아래쪽에서 시작
        /// </param>
        /// <param name="direct"></param>
        /// <example>
        /// private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        /// {
        ///     Graphics g = e.Graphics;
        ///
        ///     Color c = Color.Transparent;
        ///     BorderDirection direct = BorderDirection.Top;
        ///     int BorderWidth = 10;
        ///     int Width = 100;
        ///     float startX = 0, startY = 0;
        ///
        ///     for (int i = 0; i &lt; 4; i++)
        ///     {
        ///         switch (i)
        ///         {
        ///             case 0:
        ///                 c = Color.Red;
        ///                 startX = 0; startY = 0;
        ///                 direct = BorderDirection.Top;
        ///                 break;
        ///             case 1:
        ///                 c = Color.Green;
        ///                 startX = 100; startY = 0;
        ///                 direct = BorderDirection.Right;
        ///                 break;
        ///             case 2:
        ///                 c = Color.Blue;
        ///                 startX = 100; startY = 100;
        ///                 direct = BorderDirection.Bottom;
        ///                 break;
        ///             case 3:
        ///                 c = Color.Black;
        ///                 startX = 0; startY = 100;
        ///                 direct = BorderDirection.Left;
        ///                 break;
        ///         }
        ///
        ///         DrawBorder(g, c, Width, BorderWidth,
        ///             startX, startY, direct);
        ///     }
        /// }
        /// </example>
        private void DrawBorder(Graphics g, Color c,
                                float startX, float startY, int Width, int BorderWidth, BorderDirection direct, HtmlBorderStyle BStyle)
        {
            RectangleF RectF = new RectangleF(0f, 0f, 0f, 0f);

            switch (BStyle)
            {
            case HtmlBorderStyle.solid:
                switch (direct)
                {
                case BorderDirection.Top:
                    RectF.X      = startX;
                    RectF.Y      = startY;
                    RectF.Width  = Width;
                    RectF.Height = BorderWidth;
                    break;

                case BorderDirection.Right:
                    RectF.X      = startX - BorderWidth;
                    RectF.Y      = startY;
                    RectF.Width  = BorderWidth;
                    RectF.Height = Width;
                    break;

                case BorderDirection.Bottom:
                    RectF.X      = startX;
                    RectF.Y      = startY - BorderWidth;
                    RectF.Width  = Width;
                    RectF.Height = BorderWidth;
                    break;

                case BorderDirection.Left:
                    RectF.X      = startX;
                    RectF.Y      = startY;
                    RectF.Width  = BorderWidth;
                    RectF.Height = Width;
                    break;
                }

                g.FillRectangle(new SolidBrush(c), RectF);
                break;

            case HtmlBorderStyle.double_:
                RectangleF RectF2 = new RectangleF(0f, 0f, 0f, 0f);
                //두개의 채워진 도형과 하나의 빈 도형을 그림.
                //가장 많은 너비를 갖는 우선순위는 첫번째 채워진 도형, 두번째 채워진 도형, 빈 도형임.
                int b2 = (int)CMath.RoundDown(BorderWidth / 3M);
                int b3 = (int)CMath.RoundDown((BorderWidth - b2) / 2M);
                int b1 = BorderWidth - b3 - b2;

                switch (direct)
                {
                case BorderDirection.Top:
                    RectF.X      = startX;
                    RectF.Y      = startY;
                    RectF.Width  = Width;
                    RectF.Height = b1;

                    RectF2.X      = startX;
                    RectF2.Y      = startY + b1 + b2;
                    RectF2.Width  = Width;
                    RectF2.Height = b3;

                    break;

                case BorderDirection.Right:
                    RectF.X      = startX - BorderWidth;
                    RectF.Y      = startY;
                    RectF.Width  = b1;
                    RectF.Height = Width;

                    RectF2.X      = startX - b3;
                    RectF2.Y      = startY;
                    RectF2.Width  = b3;
                    RectF2.Height = Width;

                    break;

                case BorderDirection.Bottom:
                    RectF.X      = startX;
                    RectF.Y      = startY - BorderWidth;
                    RectF.Width  = Width;
                    RectF.Height = b1;

                    RectF2.X      = startX;
                    RectF2.Y      = startY - b3;
                    RectF2.Width  = Width;
                    RectF2.Height = b3;

                    break;

                case BorderDirection.Left:
                    RectF.X      = startX;
                    RectF.Y      = startY;
                    RectF.Width  = BorderWidth;
                    RectF.Height = Width;

                    RectF2.X      = startX + b1 + b2;
                    RectF2.Y      = startY;
                    RectF2.Width  = b3;
                    RectF2.Height = Width;

                    break;
                }

                g.FillRectangles(new SolidBrush(c), new RectangleF[2] {
                    RectF, RectF2
                });
                break;
            }
        }
Пример #9
0
        public static int DateDiff(DateInterval interval, DateTime dt1, DateTime dt2, DayOfWeek eFirstDayOfWeek)
        {
            if (interval == DateInterval.Year)
            {
                return(dt2.Year - dt1.Year);
            }
            else if (interval == DateInterval.Month)
            {
                return((dt2.Month - dt1.Month) + (12 * (dt2.Year - dt1.Year)));
            }


            TimeSpan ts = dt2 - dt1;

            switch (interval)
            {
            case DateInterval.Day:
            case DateInterval.DayOfYear:
                return(CMath.RoundDownIgnoreSign(ts.TotalDays));

            case DateInterval.Hour:
                return(CMath.RoundDownIgnoreSign(ts.TotalHours));

            case DateInterval.Minute:
                return(CMath.RoundDownIgnoreSign(ts.TotalMinutes));

            case DateInterval.Second:
                return(CMath.RoundDownIgnoreSign(ts.TotalSeconds));

            case DateInterval.Millisecond:
                return(CMath.RoundDownIgnoreSign(ts.TotalMilliseconds));

            case DateInterval.Weekday:
                return(CMath.RoundDownIgnoreSign(ts.TotalDays / 7.0));

            case DateInterval.WeekOfYear:
                while (dt2.DayOfWeek != eFirstDayOfWeek)
                {
                    dt2 = dt2.AddDays(-1);
                }
                while (dt1.DayOfWeek != eFirstDayOfWeek)
                {
                    dt1 = dt1.AddDays(-1);
                }
                ts = dt2 - dt1;
                return(CMath.RoundDownIgnoreSign(ts.TotalDays / 7.0));

            case DateInterval.Month:
                throw new Exception("절대 이 줄 실행 안됨.");

            case DateInterval.Quarter:
                double d1Quarter = GetQuarter(dt1.Month);
                double d2Quarter = GetQuarter(dt2.Month);
                double d1        = d2Quarter - d1Quarter;
                double d2        = (4 * (dt2.Year - dt1.Year));
                return(CMath.RoundDownIgnoreSign(d1 + d2));

            case DateInterval.Year:
                throw new Exception("절대 이 줄 실행 안됨.");
            }

            return(0);
        }