using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; // Local namespaces using uk.eurologic.lib.core; using uk.eurologic.lib.acme; public partial class CMS_EditDiaryEvent : System.Web.UI.Page { protected CAcmeUser m_User; protected int m_EventId = 0, m_Year = 0, m_Month = 0, m_Day = 0; protected string m_DiaryId = ""; protected void Page_Load(object sender, EventArgs e) { m_User = new CAcmeUser(Request.Cookies); Label lbl = (Label)Master.FindControl("lblDialogTitle"); if (lbl != null) lbl.Text = "Edit diary event"; GetArgs(); if (!IsPostBack) { popEvent(); } else { updateEvent(); //Response.Write(""); Response.Write(""); Response.End(); } } protected void GetArgs() { m_EventId = 0; if (Request.QueryString["id"] != null) Int32.TryParse(Request.QueryString["id"].ToString(), out m_EventId); m_DiaryId = Request.QueryString["diary"] != null ? Request.QueryString["diary"].ToString() : ""; if (m_EventId == 0) { if (Request.QueryString["y"] != null) Int32.TryParse(Request.QueryString["y"].ToString(), out m_Year); if (Request.QueryString["m"] != null) Int32.TryParse(Request.QueryString["m"].ToString(), out m_Month); if (Request.QueryString["d"] != null) Int32.TryParse(Request.QueryString["d"].ToString(), out m_Day); } } protected void popEvent() { if (m_EventId > 0) { CDiaryEvent ev = new CDiaryEvent(m_EventId); ev.DbInit(); lblDiaryName.Text = ev.DiaryName; edtStartDate.Text = ev.StartDate != DateTime.MinValue ? ev.StartDate.ToString("dd/MM/yyyy") : ""; edtEndDate.Text = ev.EndDate != DateTime.MinValue ? ev.EndDate.ToString("dd/MM/yyyy") : ""; edtTitle.Text = ev.Title.ToString(); edtLocation.Text = ev.Location.ToString(); edtTxt.Text = ev.Txt.ToString(); edtStartTime.Text = ev.StartTime; edtEndTime.Text = ev.EndTime; lblUpdatedBy.Text = "Last updated " + ev.DateUpdated.ToString("d-MMM-yy hh.mm") + " by " + ev.UpdatedByName; } else { DateTime dt = DateTime.Parse(m_Year.ToString() + "/" + m_Month.ToString() + "/" + m_Day.ToString()); edtStartDate.Text = dt.ToString("dd/MM/yyyy"); edtEndDate.Text = ""; edtTitle.Text = ""; edtLocation.Text = ""; edtTxt.Text = ""; edtStartTime.Text = ""; edtEndTime.Text = ""; } } protected void updateEvent() { string sStartDate = edtStartDate.Text.Trim(); if (edtStartTime.Text.Trim() != "") sStartDate += " " + edtStartTime.Text.Trim(); string sEndDate = edtEndDate.Text.Trim() != "" ? edtEndDate.Text.Trim() : edtStartDate.Text.Trim(); if (edtEndTime.Text.Trim() != "") sEndDate += " " + edtEndTime.Text.Trim(); if (m_EventId > 0) { CDiaryEvent ev = new CDiaryEvent(m_EventId); if (chkDelete.Checked) ev.DbDelete(); else ev.DbUpdate(sStartDate, sEndDate, edtTitle.Text, edtLocation.Text, edtTxt.Text, m_User.Id); } else { CDiaryEvent ev = new CDiaryEvent(); ev.DbCreate(m_DiaryId, sStartDate, sEndDate, edtTitle.Text, edtLocation.Text, edtTxt.Text, m_User.Id); } } }