Beispiel #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.txtName.Text))
            {
                MessageBox.Show("Please enter the Occasion or Event description.",
                                "Add Occasion or Event", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.txtName.Focus();
                return;
            }

            if (this.UserOccasion == null)
            {
                this.UserOccasion = new UserOccasion();
            }

            this.UserOccasion.Name  = this.txtName.Text;
            this.UserOccasion.Notes = this.txtNotes.Text;
            this.UserOccasion.Color = this._selectedForeColor;

            if (rbOneTime.Checked)
            {
                this.UserOccasion.JewishDate       = this.JewishDate;
                this.UserOccasion.UserOccasionType = UserOccasionTypes.OneTime;
            }
            else if (this.rbJewishYearly.Checked)
            {
                this.UserOccasion.JewishDate       = this.JewishDate;
                this.UserOccasion.UserOccasionType = UserOccasionTypes.HebrewDateRecurringYearly;
            }
            else if (this.rbJewishMonthly.Checked)
            {
                this.UserOccasion.JewishDate       = this.JewishDate;
                this.UserOccasion.UserOccasionType = UserOccasionTypes.HebrewDateRecurringMonthly;
            }
            else if (this.rbSecularYearly.Checked)
            {
                this.UserOccasion.SecularDate      = this.SecularDate;
                this.UserOccasion.UserOccasionType = UserOccasionTypes.SecularDateRecurringYearly;
            }
            else if (this.rbSecularMonthly.Checked)
            {
                this.UserOccasion.SecularDate      = this.SecularDate;
                this.UserOccasion.UserOccasionType = UserOccasionTypes.SecularDateRecurringMonthly;
            }

            if (!Properties.Settings.Default.UserOccasions.Contains(this.UserOccasion))
            {
                Properties.Settings.Default.UserOccasions.Add(this.UserOccasion);
            }

            //Set the back-color for all occasions on that same day (Jewish/Secular according to occasion type)
            UserOccasionColection.FromSettings(this.JewishDate).ForEach(uo =>
                                                                        uo.BackColor = this._selectedBackColor);

            Properties.Settings.Default.Save();

            OccasionWasChanged?.Invoke(this, this.UserOccasion);

            this.Close();
        }
Beispiel #2
0
        private void frmAddOccasionEng_Load(object sender, EventArgs e)
        {
            if (this.UserOccasion != null)
            {
                this.txtName.Text     = this.UserOccasion.Name;
                this.txtNotes.Text    = this.UserOccasion.Notes;
                this.txtName.TabIndex = 1000;

                switch (this.UserOccasion.UserOccasionType)
                {
                case UserOccasionTypes.OneTime:
                    this.JewishDate        = this.UserOccasion.JewishDate;
                    this.rbOneTime.Checked = true;
                    break;

                case UserOccasionTypes.HebrewDateRecurringYearly:
                    this.JewishDate             = this.UserOccasion.JewishDate;
                    this.rbJewishYearly.Checked = true;
                    break;

                case UserOccasionTypes.HebrewDateRecurringMonthly:
                    this.JewishDate = this.UserOccasion.JewishDate;
                    this.rbJewishMonthly.Checked = true;
                    break;

                case UserOccasionTypes.SecularDateRecurringYearly:
                    this.SecularDate             = this.UserOccasion.SecularDate;
                    this.rbSecularYearly.Checked = true;
                    break;

                case UserOccasionTypes.SecularDateRecurringMonthly:
                    this.SecularDate = this.UserOccasion.SecularDate;
                    this.rbSecularMonthly.Checked = true;
                    break;
                }
                this.btnAdd.Text        = "Update";
                this.btnDelete.Visible  = true;
                this._selectedForeColor = this.UserOccasion.Color;
            }
            else
            {
                this.btnDelete.Visible  = false;
                this.btnCancel.Location = this.btnDelete.Location;
            }

            this.txtName.ForeColor = this.btnColor.BackColor = this._selectedForeColor;

            //As each day can only have a single background color,
            //we get this occasions back color from any occasion in the list for the day.
            //What exactly is this "Day" is determined by the occasion type.
            this._selectedBackColor = (from o in UserOccasionColection.FromSettings(this.JewishDate)
                                       where o.BackColor != Color.Empty
                                       select o.BackColor).FirstOrDefault();
            this.btnBGColor.BackColor     = this.txtName.BackColor = this._selectedBackColor;
            this.llClearBackColor.Visible = (this._selectedBackColor != Color.Empty);
            this.SetLabels();
            //Repaint the background
            this.Invalidate();
        }
        public frmDailyInfoEng(JewishDate jd, Location location)
        {
            this._displayingJewishDate = jd;
            this._dailyZmanim          = new DailyZmanim(jd.GregorianDate, location);
            this._holidays             = Zmanim.GetHolidays(jd, location.IsInIsrael).Cast <SpecialDay>();
            this._occasions            = UserOccasionColection.FromSettings(jd);

            InitializeComponent();

            this._lblOccasionFont = new Font(this.Font, FontStyle.Bold);
            this.webBrowser1.ObjectForScripting = new ScriptingObject();
        }
        public frmDailyInfoHeb(JewishDate jd, Location location)
        {
            this._displayingJewishDate = jd;
            this.SetSecularDate();
            this._dailyZmanim = new DailyZmanim(this._secularDateAtMidnight, location);
            this._holidays    = Zmanim.GetHolidays(jd, location.IsInIsrael).Cast <SpecialDay>();
            this._occasions   = UserOccasionColection.FromSettings(jd);

            InitializeComponent();

            this._lblOccasionFont = new Font(this.tableLayoutPanel1.Font, FontStyle.Bold);
            this.webBrowser1.ObjectForScripting = new ScriptingObject();
        }
Beispiel #5
0
        /// <summary>
        /// Gets all occasions and events for the given Jewish Date
        /// </summary>
        /// <param name="currDate"></param>
        /// <returns></returns>
        public static UserOccasionColection FromSettings(JewishDate currDate)
        {
            var col = new UserOccasionColection();

            col.AddRange(from uo in Properties.Settings.Default.UserOccasions
                         where (uo.UserOccasionType == UserOccasionTypes.OneTime &&
                                (uo.JewishDate == currDate || uo.SecularDate.Date == currDate.GregorianDate.Date)) ||
                         ((uo.JewishDate == null || uo.JewishDate <= currDate) && (
                              (uo.UserOccasionType == UserOccasionTypes.HebrewDateRecurringYearly && (uo.JewishDate.Day == currDate.Day && IsJewishMonthMatch(uo.JewishDate, currDate))) ||
                              (uo.UserOccasionType == UserOccasionTypes.HebrewDateRecurringMonthly && (uo.JewishDate.Day == currDate.Day)) ||
                              (uo.UserOccasionType == UserOccasionTypes.SecularDateRecurringYearly && (uo.SecularDate.Day == currDate.GregorianDate.Day && uo.SecularDate.Month == currDate.GregorianDate.Month)) ||
                              (uo.UserOccasionType == UserOccasionTypes.SecularDateRecurringMonthly && (uo.SecularDate.Day == currDate.GregorianDate.Day))))
                         select uo);
            return(col);
        }
 public void AddNewOccasion(Point?parentPoint)
 {
     if (this._frmAddOccasionHeb != null)
     {
         this._frmAddOccasionHeb.CloseStyle = frmAddOccasionHeb.CloseStyles.None;
         this._frmAddOccasionHeb.Close();
     }
     this._frmAddOccasionHeb = new frmAddOccasionHeb {
         JewishDate = this._displayingJewishDate
     };
     this.PositionAddOccasion(parentPoint);
     this._frmAddOccasionHeb.OccasionWasChanged += delegate(object sndr, UserOccasion uo)
     {
         if (UserOccasionColection.FromSettings(this.JewishDate).Contains(uo))
         {
             this.AddOccasion(uo);
             this.tableLayoutPanel1.BackColor = (uo.BackColor != Color.Empty ? uo.BackColor.Color : Color.GhostWhite);
         }
         OccasionWasChanged?.Invoke(this, (uo != null ? uo.JewishDate : this._displayingJewishDate));
     };
 }
        public void EditOccasion(UserOccasion occ, Point?parentPoint)
        {
            if (this._frmAddOccasionEng != null)
            {
                this._frmAddOccasionEng.CloseStyle = frmAddOccasionEng.CloseStyles.None;
                this._frmAddOccasionEng.Close();
            }
            this._frmAddOccasionEng = new frmAddOccasionEng(occ);

            LinkLabel lnkLbl = this.tableLayoutPanel1.Controls.OfType <LinkLabel>().First(ll => ll.Tag == occ);
            Label     lbl    = (Label)this.tableLayoutPanel1.Controls[this.tableLayoutPanel1.Controls.IndexOf(lnkLbl) + 1];

            this._frmAddOccasionEng.OccasionWasChanged += delegate(object sndr, UserOccasion uo)
            {
                OccasionWasChanged?.Invoke(this, (uo != null ? uo.JewishDate : this._displayingJewishDate));

                if (this._frmAddOccasionEng.UserOccasion == null ||
                    (!UserOccasionColection.FromSettings(this._displayingJewishDate).Contains(this._frmAddOccasionEng.UserOccasion)))
                {
                    this.tableLayoutPanel1.Controls.Remove(lbl);
                    this.tableLayoutPanel1.Controls.Remove(lnkLbl);
                    if (this.tableLayoutPanel1.RowCount > 0)
                    {
                        this.tableLayoutPanel1.RowCount -= 1;
                    }
                }
                else
                {
                    lnkLbl.Text      = this._frmAddOccasionEng.UserOccasion.Name;
                    lnkLbl.LinkColor = this._frmAddOccasionEng.UserOccasion.Color;
                    var dateDiff = this._frmAddOccasionEng.UserOccasion.GetAnniversaryString(this.JewishDate, false);
                    lbl.Text = ((!string.IsNullOrWhiteSpace(dateDiff)) ? "(" + dateDiff + ") " : "") +
                               (this._frmAddOccasionEng.UserOccasion.Notes ?? "");
                    this.tableLayoutPanel1.BackColor = (uo.BackColor != Color.Empty ? uo.BackColor.Color : Color.GhostWhite);
                }
            };
            this.PositionAddOccasion(parentPoint);
        }
 public frmImportOccasionsHeb(UserOccasionColection uoc)
 {
     InitializeComponent();
     this.OcassionList = uoc;
 }
        private void llImport_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            using (var sfd = new OpenFileDialog()
            {
                DefaultExt = "xml",
                Filter = "קובצי XML (*.xml)|*.xml|כל סוגי הקבצים (*.*)|*.*",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                RestoreDirectory = false,
                FileName = "לוח_ייצוא_אירועים_" + (Environment.UserName ?? "") + ".xml"
            })
            {
                if (sfd.ShowDialog(this) == DialogResult.OK && (!string.IsNullOrWhiteSpace(sfd.FileName)) && File.Exists(sfd.FileName))
                {
                    UserOccasionColection uoc = null;
                    var formatter             = new System.Xml.Serialization.XmlSerializer(Properties.Settings.Default.UserOccasions.GetType());
                    using (var stream = new FileStream(sfd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        try
                        {
                            uoc = (UserOccasionColection)formatter.Deserialize(stream);
                        }
                        catch
                        {
                            MessageBox.Show("ייבוא אירועים מקובץ " + sfd.FileName +
                                            "נכשלה.\nאנא וודאו שהקובץ הוא רשימת אירועים שייוצאו מתוכנת לוח ושלא נעשו בו שינויים לא נכונים",
                                            "לוח - ייבוא אירועים", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            //Let the user try again...
                            llImport_LinkClicked(sender, e);
                            return;
                        }
                    }

                    if (uoc != null && uoc.Count > 0)
                    {
                        using (var fi = new frmImportOccasionsHeb(uoc))
                        {
                            if (fi.ShowDialog() == DialogResult.OK)
                            {
                                Properties.Settings.Default.UserOccasions.AddRange(fi.OcassionList);
                                Properties.Settings.Default.Save();
                                ((dynamic)this.Owner).Reload();
                                this.LoadList();
                                MessageBox.Show(fi.OcassionList.Count.ToString() + " אירועים הובאו בהצלחה מקובץ " + sfd.FileName,
                                                "לוח - ייבוא אירועים");
                            }
                            else
                            {
                                MessageBox.Show("לא הובאו שום אירועים מקובץ " + sfd.FileName,
                                                "לוח - ייבוא אירועים",
                                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        return;
                    }
                    else
                    {
                        MessageBox.Show("לא הצלחנו להביא שום אירועים מקובץ " + sfd.FileName,
                                        "לוח - ייבוא אירועים", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
        }
 public void UpdateOccasions()
 {
     this.UserOccasions = UserOccasionColection.FromSettings(this.JewishDate);
 }
Beispiel #11
0
        private void llImportList_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            using (var sfd = new OpenFileDialog()
            {
                DefaultExt = "xml",
                Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*",
                InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                RestoreDirectory = false,
                FileName = "Luach Project Occasions" + (Environment.UserName ?? "") + ".xml"
            })
            {
                if (sfd.ShowDialog(this) == DialogResult.OK && (!string.IsNullOrWhiteSpace(sfd.FileName)) && File.Exists(sfd.FileName))
                {
                    UserOccasionColection uoc = null;
                    var formatter             = new System.Xml.Serialization.XmlSerializer(Properties.Settings.Default.UserOccasions.GetType());
                    using (var stream = new FileStream(sfd.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        try
                        {
                            uoc = (UserOccasionColection)formatter.Deserialize(stream);
                        }
                        catch
                        {
                            MessageBox.Show("We were not able to import any Occasions from " + sfd.FileName +
                                            ".\nPlease assure that the selected file is a valid Occasion file, and that it was not edited incorrectly.",
                                            "Luach Project - Import Occasions", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            //Let the user try again...
                            llImportList_LinkClicked(sender, e);
                            return;
                        }
                    }

                    if (uoc != null && uoc.Count > 0)
                    {
                        using (var fi = new frmImportOccasionsEng(uoc))
                        {
                            if (fi.ShowDialog() == DialogResult.OK)
                            {
                                Properties.Settings.Default.UserOccasions.AddRange(fi.OcassionList);
                                Properties.Settings.Default.Save();
                                ((dynamic)this.Owner).Reload();
                                this.LoadList();
                                MessageBox.Show(fi.OcassionList.Count.ToString() + " Occasions have been successfully imported from " + sfd.FileName,
                                                "Luach Project - Import Occasions");
                            }
                            else
                            {
                                MessageBox.Show("No occasions were imported from " + sfd.FileName,
                                                "Luach Project - Import Occasions", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }

                        return;
                    }
                    else
                    {
                        MessageBox.Show("There weren't any occasions that we were able to import from " + sfd.FileName,
                                        "Luach Project - Import Occasions", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
        }