private void DisplayHolidays(StringBuilder html)
        {
            var shkia = this._dailyZmanim.ShkiaAtElevation;

            if (this._holidays.Count() > 0)
            {
                foreach (var h in this._holidays)
                {
                    html.AppendFormat("<div class=\"padWidth\">{0}", h.NameEnglish);
                    if (h.NameEnglish == "Shabbos Mevarchim")
                    {
                        var nextMonth = this._displayingJewishDate + 12;
                        html.AppendFormat(" - Chodesh {0}", nextMonth.MonthName);

                        var molad = Molad.GetMolad(nextMonth.Month, nextMonth.Year);
                        var dim   = JewishDateCalculations.DaysInJewishMonth(this._displayingJewishDate.Year, this._displayingJewishDate.Month);
                        var dow   = dim - this._displayingJewishDate.Day;
                        if (dim == 30)
                        {
                            dow--;
                        }
                        html.AppendFormat("<div>Molad: {0}</div>", molad.ToString(this._dailyZmanim.ShkiaAtElevation));
                        html.AppendFormat("<div>Rosh Chodesh: {0}{1}</div>",
                                          Utils.DaysOfWeek[dow], (dim == 30 ? ", " + Utils.DaysOfWeek[(dow + 1) % 7] : ""));
                    }
                    html.Append("</div>");

                    if (h.NameEnglish.Contains("Sefiras Ha'omer"))
                    {
                        var dayOfOmer = this._displayingJewishDate.GetDayOfOmer();
                        html.AppendFormat("<div><a onclick=\"javacript:window.external.showSefirah({0}, false);return false;\" class=\"tahoma nine steelBlue pointer\">{1}</a></div>",
                                          dayOfOmer, Utils.GetOmerNusach(dayOfOmer, Properties.Settings.Default.Nusach));
                    }

                    if (h.DayType.IsSpecialDayType(SpecialDayTypes.EruvTavshilin))
                    {
                        html.Append("<div class=\"padWidth eight bold crimson\">Eiruv Tavshilin</div>");
                    }
                }
            }
            html.Append("<table>");
            if (shkia != TimeOfDay.NoValue &&
                this._holidays.Any(h => h.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting)))
            {
                this.AddLine(html, "Candle Lighting", (shkia - this._dailyZmanim.Location.CandleLighting).ToString(), wideDescription: false);
                html.Append("<tr><td class=\"nobg\" colspan=\"3\">&nbsp;</td></tr>");
            }
        }
Exemple #2
0
        private void DrawSingleDay(Graphics g, JewishDate currDate, float width, float height, float currX, float currY)
        {
            var    zmanim     = new Zmanim(currDate, this._currentLocation);
            var    rect       = new RectangleF(currX, currY, width, height);
            var    text       = currDate.Day.ToNumberHeb();
            var    holidays   = Zmanim.GetHolidays(currDate, this._currentLocation.IsInIsrael);
            string textZmanim = "";

            if (currDate.DayOfWeek == DayOfWeek.Saturday)
            {
                foreach (SpecialDay sd in holidays)
                {
                    if (sd.DayType == SpecialDayTypes.Shabbos)
                    {
                        holidays.Remove(sd);
                        break;
                    }
                }

                foreach (SpecialDay sd in holidays)
                {
                    if (sd.NameEnglish == "Shabbos Mevarchim")
                    {
                        var nextMonth = currDate + 12;
                        var molad     = Molad.GetMolad(nextMonth.Month, nextMonth.Year);
                        sd.NameHebrew += "\nמולד: " + molad.ToStringHeb(zmanim.GetShkia());
                        break;
                    }
                }

                textZmanim = string.Join(" - ", Sedra.GetSedra(currDate, false).Select(i => i.nameHebrew)) +
                             "\n" + Zmanim.GetHolidaysText(holidays, "\n", true);

                g.FillRectangle(Program.ShabbosBrush, rect);
            }
            else
            {
                if (currDate.DayOfWeek == DayOfWeek.Sunday)
                {
                    width      = (this.pnlMain.Width - currX) - 1f;
                    rect.Width = width;
                }
                if (holidays.Count > 0)
                {
                    var hlist = holidays.Cast <SpecialDay>();
                    if (hlist.Any(h => h.DayType.HasFlag(SpecialDayTypes.HasCandleLighting)))
                    {
                        textZmanim += "הדלק\"נ: " +
                                      (zmanim.GetShkia() - this._currentLocation.CandleLighting).ToString24H() + "\n";
                    }
                    if (hlist.Any(h =>
                                  (h.DayType & SpecialDayTypes.MajorYomTov) == SpecialDayTypes.MajorYomTov ||
                                  (h.DayType & SpecialDayTypes.MinorYomtov) == SpecialDayTypes.MinorYomtov))
                    {
                        g.FillRectangle(Program.YomtovBrush, rect);
                    }

                    textZmanim += Zmanim.GetHolidaysText(holidays, "\n", true);
                }
            }
            this._dateList.Add(Tuple.Create(currDate, textZmanim, rect));

            if (this._selectedDay != null && currDate == this._selectedDay)
            {
                g.FillRectangle(Program.SelectedDayBackgroundBrush, rect);
            }

            g.DrawRectangle(Program.DayCellBorderPen, rect.X, rect.Y, rect.Width, rect.Height);

            if (currDate == this._todayJewishDate)
            {
                var eh = rect.Height / 3.3f;
                var ew = rect.Width / 3.3f;
                g.FillClosedCurve(Program.DayHeadersBGBrush, new PointF[]
                {
                    new PointF(rect.X + ew, rect.Y + eh),
                    new PointF(rect.X + (rect.Width - ew), rect.Y + eh),
                    new PointF(rect.X + (rect.Width - ew), rect.Y + (rect.Height - eh)),
                    new PointF(rect.X + ew, rect.Y + (rect.Height - eh))
                }, System.Drawing.Drawing2D.FillMode.Alternate, 3f);
            }

            rect.Height /= 2f;
            rect.X       = currX + (width / 2);
            rect.Width   = (width / 2);
            g.DrawString(text, this._dayFont, Program.DayTextBrush, rect, Program.StringFormat);
            rect.X = currX;
            g.DrawString(currDate.GregorianDate.Day.ToString(), this._secularDayFont, Program.SecularDayBrush, rect, Program.StringFormat);
            rect.Width = width;

            if (!string.IsNullOrWhiteSpace(textZmanim))
            {
                rect.Y     += rect.Height;
                rect.Height = height - rect.Height;
                g.DrawString(textZmanim, this._zmanimFont, Program.ZmanimBrush, rect, Program.StringFormat);
            }
        }
        internal void ShowDateData()
        {
            this.Cursor = Cursors.WaitCursor;
            var showSeconds     = Properties.Settings.Default.ShowSeconds;
            var dy              = DafYomi.GetDafYomi(this._displayingJewishDate);
            var netzshkia       = this._dailyZmanim.NetzShkiaAtElevation;
            var netzshkiaMishor = this._dailyZmanim.NetzShkiaMishor;
            var netz            = this._dailyZmanim.NetzAtElevation;
            var shkia           = this._dailyZmanim.ShkiaAtElevation;
            var netzMishor      = this._dailyZmanim.NetzMishor;
            var shkiaMishor     = this._dailyZmanim.ShkiaMishor;
            var chatzos         = this._dailyZmanim.Chatzos;
            var shaaZmanis      = this._dailyZmanim.ShaaZmanis;
            var shaaZmanis90    = this._dailyZmanim.ShaaZmanisMga;
            var html            = new StringBuilder();

            html.AppendFormat("<div class=\"padWidth royalBlue bold\">{0}</div>",
                              this._displayingJewishDate.ToLongDateStringHeb());
            html.AppendFormat("<div class=\"padWidth lightSteelBlue\">{0}</div>",
                              this._displayingSecularDate.ToString("D", Program.HebrewCultureInfo));

            //If the secular day is a day behind as day being displayed is todays date and it is after sunset,
            //the user may get confused as the secular date for today and tomorrow will be the same.
            //So we esplain'in it to them...
            if (this._secularDateAtMidnight.Date != this._displayingSecularDate.Date)
            {
                html.Append("<div class=\"padWidth rosyBrown seven italic\">שים לב: תאריך הלועזי מתחיל בשעה 0:00</div>");
            }

            this.DisplayDateDiff(html);

            html.Append("<br />");
            if (this._holidays.Count() > 0)
            {
                foreach (var h in this._holidays)
                {
                    html.AppendFormat("<div class=\"padWidth\">{0}", h.NameHebrew);
                    if (h.NameEnglish == "Shabbos Mevarchim")
                    {
                        var nextMonth = this._displayingJewishDate + 12;
                        html.AppendFormat(" - חודש {0}", Utils.GetProperMonthNameHeb(nextMonth.Year, nextMonth.Month));

                        var molad = Molad.GetMolad(nextMonth.Month, nextMonth.Year);
                        var dim   = JewishDateCalculations.DaysInJewishMonth(this._displayingJewishDate.Year, this._displayingJewishDate.Month);
                        var dow   = dim - this._displayingJewishDate.Day;
                        if (dim == 30)
                        {
                            dow--;
                        }
                        html.AppendFormat("<div>המולד: {0}</div>", molad.ToStringHeb(this._dailyZmanim.ShkiaAtElevation));
                        html.AppendFormat("<div>ראש חודש: {0}{1}</div>",
                                          Utils.JewishDOWNames[dow], (dim == 30 ? ", " + Utils.JewishDOWNames[(dow + 1) % 7] : ""));
                    }
                    html.Append("</div>");
                    if (h.NameEnglish.Contains("Sefiras Ha'omer"))
                    {
                        var dayOfOmer = this._displayingJewishDate.GetDayOfOmer();
                        html.AppendFormat("<div><a onclick=\"javacript:window.external.showSefirah({0}, true);return false;\" class=\"nine bluoid pointer\">{1}</a></div>",
                                          dayOfOmer, Utils.GetOmerNusach(dayOfOmer, Properties.Settings.Default.Nusach));
                    }

                    if (h.DayType.IsSpecialDayType(SpecialDayTypes.EruvTavshilin))
                    {
                        html.Append("<div class=\"padWidth crimson bold\">עירוב תבשילין</div>");
                    }
                }
            }

            html.Append("<table>");

            if (shkia != TimeOfDay.NoValue &&
                this._holidays.Any(h => h.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting)))
            {
                this.AddLine(html, "הדלקת נרות", (shkia - this._dailyZmanim.Location.CandleLighting).ToString24H(showSeconds),
                             wideDescription: false);
                html.Append("<tr><td class=\"nobg\" colspan=\"3\">&nbsp;</td></tr>");
            }

            this.AddLine(html, "פרשת השבוע",
                         string.Join(" ", Sedra.GetSedra(this._displayingJewishDate, this._dailyZmanim.Location.IsInIsrael).Select(i => i.nameHebrew)),
                         wideDescription: false);
            if (dy != null)
            {
                this.AddLine(html, "דף יומי", dy.ToStringHeb(), wideDescription: false);
            }

            html.Append("</table><br />");
            html.AppendFormat("<div class=\"padBoth lightSteelBlueBG ghostWhite nine bold clear\">זמני היום ב{0}</div>",
                              this._dailyZmanim.Location.NameHebrew);
            html.Append("<table>");

            if (netz == TimeOfDay.NoValue)
            {
                this.AddLine(html, "הנץ החמה", "השמש אינו עולה", bold: true, emphasizeValue: true);
            }
            else
            {
                if (this._displayingJewishDate.Month == 1 && this._displayingJewishDate.Day == 14)
                {
                    this.AddLine(html, "סו\"ז אכילת חמץ", ((netz - 90) + (int)Math.Floor(shaaZmanis90 * 4D)).ToString24H(showSeconds),
                                 bold: true);
                    this.AddLine(html, "סו\"ז שריפת חמץ", ((netz - 90) + (int)Math.Floor(shaaZmanis90 * 5D)).ToString24H(showSeconds),
                                 bold: true);
                    html.Append("<br />");
                }

                this.AddLine(html, "עלות השחר - 90", (netzMishor - 90).ToString24H(showSeconds));
                this.AddLine(html, "עלות השחר - 72", (netzMishor - 72).ToString24H(showSeconds));

                if (netz == netzMishor)
                {
                    this.AddLine(html, "הנץ החמה", netz.ToString24H(showSeconds), bold: true, emphasizeValue: true);
                }
                else
                {
                    this.AddLine(html, "הנה\"ח <span class=\"reg lightSteelBlue\">...מ " + this._dailyZmanim.Location.Elevation.ToString() + " מטר</span>",
                                 netz.ToString24H(showSeconds));
                    this.AddLine(html, "הנה\"ח <span class=\"reg lightSteelBlue\">...גובה פני הים</span>",
                                 netzMishor.ToString24H(showSeconds), bold: true, emphasizeValue: true);
                }
                this.AddLine(html, "סוזק\"ש - מג\"א", this._dailyZmanim.GetZman(ZmanType.KShmMga).ToString24H(showSeconds));
                this.AddLine(html, "סוזק\"ש - הגר\"א", this._dailyZmanim.GetZman(ZmanType.KshmGra).ToString24H(showSeconds));
                this.AddLine(html, "סוז\"ת - מג\"א", this._dailyZmanim.GetZman(ZmanType.TflMga).ToString24H(showSeconds));
                this.AddLine(html, "סוז\"ת - הגר\"א", this._dailyZmanim.GetZman(ZmanType.TflGra).ToString24H(showSeconds));
            }
            if (netz != TimeOfDay.NoValue && shkia != TimeOfDay.NoValue)
            {
                this.AddLine(html, "חצות היום והלילה", chatzos.ToString24H(showSeconds));
                this.AddLine(html, "מנחה גדולה", this._dailyZmanim.GetZman(ZmanType.MinchaG).ToString24H(showSeconds));
                this.AddLine(html, "מנחה קטנה", this._dailyZmanim.GetZman(ZmanType.MinchaK).ToString24H(showSeconds));
                this.AddLine(html, "פלג המנחה", this._dailyZmanim.GetZman(ZmanType.MinchaPlg).ToString24H(showSeconds));
            }
            if (shkia == TimeOfDay.NoValue)
            {
                this.AddLine(html, "שקיעת החמה", "השמש אינו שוקע", bold: true, emphasizeValue: true);
            }
            else
            {
                if (shkia == shkiaMishor)
                {
                    this.AddLine(html, "שקיעת החמה", shkia.ToString24H(showSeconds), bold: true, emphasizeValue: true);
                }
                else
                {
                    this.AddLine(html, "שקה\"ח <span class=\"reg lightSteelBlue\">...גובה פני הים</span>", shkiaMishor.ToString24H(showSeconds));
                    this.AddLine(html, "שקה\"ח <span class=\"reg lightSteelBlue\">...מ " + this._dailyZmanim.Location.Elevation.ToString() + " מטר</span>",
                                 shkia.ToString24H(showSeconds), bold: true, emphasizeValue: true);
                }

                this.AddLine(html, "צאת הכוכבים 45", (shkia + 45).ToString24H(showSeconds));
                this.AddLine(html, "רבינו תם", (shkia + 72).ToString24H(showSeconds));
                this.AddLine(html, "72 דקות זמניות", (shkia + (int)(shaaZmanis * 1.2)).ToString24H(showSeconds));
                this.AddLine(html, "72 דקות זמניות לחומרה", (shkia + (int)(shaaZmanis90 * 1.2)).ToString24H(showSeconds));
            }
            html.Append("</table>");
            this.webBrowser1.DocumentText = Properties.Resources.InfoHTMLHeb
                                            .Replace("{{BODY}}", html.ToString());

            this.tableLayoutPanel1.Controls.Clear();
            foreach (UserOccasion occ in this._occasions)
            {
                this.AddOccasion(occ);
            }

            var bg = (from o in this._occasions
                      where o.BackColor != Color.Empty
                      select o.BackColor).FirstOrDefault();

            this.tableLayoutPanel1.BackColor = (bg != Color.Empty ? bg.Color : Color.GhostWhite);

            this.Cursor = Cursors.Default;
        }
Exemple #4
0
        private SingleDateInfo DrawSingleDay(Graphics g, JewishDate currDate, float width, float height, float currX, float currY)
        {
            var zmanim   = new Zmanim(currDate, this._currentLocation);
            var rect     = new RectangleF(currX, currY, width, height);
            var text     = currDate.Day.ToNumberHeb().Replace("'", "");
            var holidays = Zmanim.GetHolidays(currDate, this._currentLocation.IsInIsrael);

            SingleDateInfo sdi = new SingleDateInfo(currDate, new RectangleF(rect.Location, rect.Size));

            this._singleDateInfoList.Add(sdi);

            if (this._isFirstOpen)
            {
                //We will be repainting anyway...
                return(sdi);
            }

            string textZmanim = "";

            if (currDate.DayOfWeek == DayOfWeek.Saturday)
            {
                bool noSedra = false;

                width      = (this.pnlMain.Width - currX) - 1f;
                rect.Width = width;

                foreach (SpecialDay sd in holidays)
                {
                    if (sd.DayType == SpecialDayTypes.Shabbos)
                    {
                        holidays.Remove(sd);
                        break;
                    }
                }

                foreach (SpecialDay sd in holidays)
                {
                    if (sd.DayType.IsSpecialDayType(SpecialDayTypes.MajorYomTov) || sd.DayType.IsSpecialDayType(SpecialDayTypes.CholHamoed))
                    {
                        noSedra = true;
                    }
                    if (sd.NameEnglish == "Shabbos Mevarchim")
                    {
                        var nextMonth = currDate + 12;
                        var molad     = Molad.GetMolad(nextMonth.Month, nextMonth.Year);
                        sd.NameEnglish += "\nMolad: " + molad.ToString(zmanim.GetShkia());
                        break;
                    }
                }

                if (noSedra)
                {
                    textZmanim = Zmanim.GetHolidaysText(holidays, "\n", false);
                }
                else
                {
                    textZmanim = string.Join(" - ", Sedra.GetSedra(currDate, this._currentLocation.IsInIsrael).Select(i => i.nameEng)) +
                                 "\n" + Zmanim.GetHolidaysText(holidays, "\n", false);
                }

                g.FillRectangle(Program.ShabbosBrush, rect);
            }
            else if (holidays.Count > 0)
            {
                var hlist = holidays.Cast <SpecialDay>();
                if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting))))
                {
                    textZmanim += "Candles: " +

                                  (zmanim.GetShkia() - this._currentLocation.CandleLighting).ToString() + "\n";
                }
                if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.MajorYomTov))))
                {
                    g.FillRectangle(Program.MajorYomtovBrush, rect);
                }
                else if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.MinorYomtov))))
                {
                    g.FillRectangle(Program.MinorYomtovBrush, rect);
                }
                textZmanim += Zmanim.GetHolidaysText(holidays, "\n", false);
            }

            if (sdi.UserOccasions.Any(bc => bc.BackColor != Color.Empty))
            {
                g.FillRectangle(new SolidBrush(sdi.UserOccasions.First(bc => bc.BackColor.Color != Color.Empty).BackColor), rect);
            }
            if (this._selectedDay != null && currDate == this._selectedDay)
            {
                g.FillRectangle(Program.SelectedDayBackgroundBrush, rect);
            }

            g.DrawRectangle(Program.DayCellBorderPen, rect.X, rect.Y, rect.Width, rect.Height);

            if (currDate == this._todayJewishDate)
            {
                var eh = rect.Height / 3.3f;
                var ew = rect.Width / 3.3f;
                g.FillClosedCurve(Program.DayHeadersBGBrush, new PointF[]
                {
                    new PointF(rect.X + ew, rect.Y + eh),
                    new PointF(rect.X + (rect.Width - ew), rect.Y + eh),
                    new PointF(rect.X + (rect.Width - ew), rect.Y + (rect.Height - eh)),
                    new PointF(rect.X + ew, rect.Y + (rect.Height - eh))
                }, System.Drawing.Drawing2D.FillMode.Alternate, 3f);
            }
            //accumulative height of all text rectangles - keeps track of current Y position in box.
            float offsetTop = 0f;

            //Padding top - varies according to what needs to be displayed beneath it
            rect.Y = currY + (rect.Height / (sdi.UserOccasions.Count + holidays.Count > 1 ? 20 : 10));

            //Hebrew day will be on the left, so we cut the rectangle in half.
            rect.Width /= 2;
            rect.Height = TextRenderer.MeasureText(g, text, this._dayFont, rect.Size.ToSize(), Program.TextFormatFlags).Height;
            offsetTop  += rect.Height;

            TextRenderer.DrawText(
                g,
                text,
                this._dayFont,
                Rectangle.Truncate(rect),
                Program.DayTextColor,
                Program.TextFormatFlags);

            //Secular day will be on the right, so we move the rectangle over to the right of the box.
            //No need to resize the width.
            rect.X += rect.Width;

            TextRenderer.DrawText(
                g,
                currDate.GregorianDate.Day.ToString(),
                this._secularDayFont,
                Rectangle.Truncate(rect),
                Program.SecularDayColor,
                Program.TextFormatFlags);

            //Move rectangle back over to the left of the box
            rect.X = currX;
            //resize rectangle to fix whole box
            rect.Width = width;

            offsetTop += rect.Height / (holidays.Count > 1 ? 5 : 3);

            foreach (var o in sdi.UserOccasions)
            {
                //Get the text size for this occasions label.
                var textSize = TextRenderer.MeasureText(g, o.Name, this._userOccasionFont, rect.Size.ToSize(), Program.TextFormatFlags);

                //Move the Y position down to empty space.
                rect.Y      = currY + offsetTop;
                rect.Height = textSize.Height;
                //Save the exact position of the occasion label so when the user clicks on it afterwards, we can open the occasion for editing.
                //Note: the occasion labels are centered in the days box, so we can't use the X position of rect (which is always 0).
                o.Rectangle = new RectangleF(rect.X + ((rect.Width / 2) - (textSize.Width / 2)),
                                             rect.Y, textSize.Width, textSize.Height);

                TextRenderer.DrawText(
                    g,
                    o.Name,
                    this._userOccasionFont,
                    Rectangle.Truncate(rect),
                    o.Color,
                    Program.TextFormatFlags);

                offsetTop += rect.Height;
            }

            if (!string.IsNullOrWhiteSpace(textZmanim))
            {
                rect.Y = currY + offsetTop;

                rect.Height = height - offsetTop;

                TextRenderer.DrawText(
                    g,
                    textZmanim,
                    this._zmanimFont,
                    Rectangle.Truncate(rect),
                    Program.ZmanimColor,
                    Program.TextFormatFlags);
            }

            return(sdi);
        }