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(); }
private void btnDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("Delete the occasion/event \"" + this.UserOccasion.Name + "\"?", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { Properties.Settings.Default.UserOccasions.Remove(this.UserOccasion); Properties.Settings.Default.Save(); this.UserOccasion = null; OccasionWasChanged?.Invoke(this, this.UserOccasion); this.Close(); } }
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); }