protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (EventID != 0)
{
lblCrateEvent.Text = "Modify an Event";
var events = DBGolfVolunteer.SpLoadEventByID(EventID);
foreach (var item in events)
{
txtEvenName.Text = item.fld_event_name;
txtStartDate.Text = Convert.ToDateTime(item.fld_startdate).ToShortDateString().ToString();
txtEndDate.Text = Convert.ToDateTime(item.fld_enddate).ToShortDateString().ToString();
txtTotalRound.Text = item.fld_roundcount.ToString();
txtMainName.Text = item.fld_contact_primary_name;
txtMainEmail.Text = item.fld_contact_primary_email;
txtMainPhone.Text = item.fld_contact_primary_telephone;
txtSecondName.Text = item.fld_second_contact_name;
txtSecondEmail.Text = item.fld_second_contact_email;
txtSecondPhone.Text = item.fld_second_contact_telephone;
txtThirdName.Text = item.fld_third_contact_name;
txtThirdEmail.Text = item.fld_third_contact_email;
txtThirdPhone.Text = item.fld_third_contact_telephone;
txtSummary.Text = item.fld_summary;
txtStartDate1.Text = Convert.ToDateTime(item.fld_display_startdate).ToShortDateString().ToString();
txtEndDate1.Text = Convert.ToDateTime(item.fld_display_enddate).ToShortDateString().ToString();
txtDescription.Text = item.fld_message;
}
btnSave.Text = "Accept Changes";
}
else
{
lblCrateEvent.Text = "Create an Event";
}
}
}
//Event Insert
protected void btnSave_Click(object sender, EventArgs e)
{
if (EventID == 0)
{
//lblCrateEvent.Text = "Create an Event";
tbl_event objtbl_event = new tbl_event();
objtbl_event.fld_event_name = txtEvenName.Text;
objtbl_event.fld_startdate = Convert.ToDateTime(txtStartDate.Text);
objtbl_event.fld_enddate = Convert.ToDateTime(txtEndDate.Text);
objtbl_event.fld_roundcount = int.Parse(txtTotalRound.Text);
objtbl_event.fld_contact_primary_name = txtMainName.Text;
objtbl_event.fld_contact_primary_email = txtMainEmail.Text;
objtbl_event.fld_contact_primary_telephone = txtMainPhone.Text;
objtbl_event.fld_second_contact_name = txtSecondName.Text;
objtbl_event.fld_second_contact_email = txtSecondEmail.Text;
objtbl_event.fld_second_contact_telephone = txtSecondPhone.Text;
objtbl_event.fld_third_contact_name = txtThirdName.Text;
objtbl_event.fld_third_contact_email = txtThirdEmail.Text;
objtbl_event.fld_third_contact_telephone = txtThirdPhone.Text;
objtbl_event.fld_status = 1;
objtbl_event.fld_homepage = 0;
objtbl_event.fld_displaynames = 0;
objtbl_event.fld_summary = txtSummary.Text;
objtbl_event.fld_message = txtDescription.Text;
objtbl_event.fld_display_startdate = Convert.ToDateTime(txtStartDate1.Text);
objtbl_event.fld_display_enddate = Convert.ToDateTime(txtEndDate1.Text);
DBGolfVolunteer.tbl_events.InsertOnSubmit(objtbl_event);
try
{
DBGolfVolunteer.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
finally
{
divMessage.Visible = true;
divMessage.InnerHtml = "Event Inserted Successfully";
}
}
//Evetn update
else
{
tbl_event events = DBGolfVolunteer.tbl_events.Single(ev => ev.fld_id == Convert.ToInt32(EventID));
events.fld_event_name = txtEvenName.Text;
events.fld_startdate = Convert.ToDateTime(txtStartDate.Text);
events.fld_enddate = Convert.ToDateTime(txtEndDate.Text);
events.fld_roundcount = Convert.ToInt32(txtTotalRound.Text);
events.fld_contact_primary_name = txtMainName.Text;
events.fld_contact_primary_email = txtMainEmail.Text;
events.fld_contact_primary_telephone = txtMainPhone.Text;
events.fld_second_contact_name = txtSecondName.Text;
events.fld_second_contact_email = txtSecondEmail.Text;
events.fld_second_contact_telephone = txtSecondPhone.Text;
events.fld_third_contact_name = txtThirdName.Text;
events.fld_third_contact_email = txtThirdEmail.Text;
events.fld_third_contact_telephone = txtThirdPhone.Text;
events.fld_summary = txtSummary.Text;
events.fld_display_startdate = Convert.ToDateTime(txtStartDate1.Text);
events.fld_display_enddate = Convert.ToDateTime(txtEndDate1.Text);
events.fld_message = txtDescription.Text;
try
{
DBGolfVolunteer.SubmitChanges();
}
catch (Exception ex)
{
throw ex;
}
finally
{
divMessage.Visible = true;
divMessage.InnerHtml = "Event Updated Successfully";
}
}
clear();
}
No comments:
Post a Comment