protected void btnSave_ServerClick(object sender, EventArgs e)
        {
            try
            {
                if (ValidatePage() == true)
                {
                    //BIG IMAGE

                    string s = filenm.Value;
                    string[] file = s.Split('.');
                    string t = file[file.Length - 1].ToString();
                    string ext = "";

                    var r = new Random();
                    string d = DateTime.Now.ToString("ddMMyyhhmmss") + r.Next(100);
                    ext = "E" + d;

                    string baseImageLocation = Server.MapPath("~\\ShowlineImages\\");
                    HttpFileCollection files = Request.Files;
                    HttpPostedFile httpPostedFile = files["filenm"];
                    string fileExt = Path.GetExtension(httpPostedFile.FileName).ToLower();
                    string fileName = Path.GetFileName(httpPostedFile.FileName);

                    //SMALL IMAGE

                    string sm = filesmallimage.Value;
                    string[] filesm = sm.Split('.');
                    string tsm = filesm[filesm.Length - 1].ToString();
                    string extSM = "";

                    string dsm = DateTime.Now.ToString("ddMMyyhhmmss") + r.Next(100);
                    extSM = "S" + dsm;

                    string baseImageLocationsm = Server.MapPath("~\\ShowlineImages\\");
                    HttpFileCollection filessm = Request.Files;
                    HttpPostedFile httpPostedFilesm = filessm["filesmallimage"];
                    string fileExtsm = Path.GetExtension(httpPostedFilesm.FileName).ToLower();
                    string fileNamesm = Path.GetFileName(httpPostedFilesm.FileName);

                    // TICKET IMAGE

                    string sTm = filebackgroundimage.Value;
                    string[] filesTm = sTm.Split('.');
                    string tsTm = filesTm[filesTm.Length - 1].ToString();
                    string extSTM = "";

                    string dsTm = DateTime.Now.ToString("ddMMyyhhmmss") + r.Next(100);
                    extSTM = "T" + dsTm;

                    string baseImageLocationsTm = Server.MapPath("~\\ShowlineImages\\");
                    HttpFileCollection filessTm = Request.Files;
                    HttpPostedFile httpPostedFilesTm = filessTm["filebackgroundimage"];
                    string fileExtsTm = Path.GetExtension(httpPostedFilesTm.FileName).ToLower();
                    string fileNamesTm = Path.GetFileName(httpPostedFilesTm.FileName);
                    //

                    EventsEntryPageViewModel _eventMasterDAL = new EventsEntryPageViewModel();
                    EventMasterModel eventMasterModel = new EventMasterModel();
                    List<EventTimeDetailsModel> eventTimeDetailsModel = new List<EventTimeDetailsModel>();

                    List<EventPriceDetailsModel> eventPriceDetailsModel = new List<EventPriceDetailsModel>();

                    eventMasterModel.EventTypeID = ddEventType.SelectedItem.Value;
                    eventMasterModel.EventSubtypeID = ddEvebtSubType.SelectedItem.Value.ToString();
                    eventMasterModel.VenueID = ddVenueDetails.SelectedItem.Value;
                    eventMasterModel.EventTitle = txtEventTitle.Value.Trim();
                    eventMasterModel.EventDesc = txtEventDesc.Value.Trim();
                    eventMasterModel.Artists = txtArtist.Value.Trim();
                    eventMasterModel.Genre = txtGenre.Value.Trim();
                    eventMasterModel.ImagePath = "/ShowlineImages/" + ext + "." + file[file.Length - 1].ToString();
                    eventMasterModel.SmallImagePath = "/ShowlineImages/" + extSM + "." + filesm[filesm.Length - 1].ToString();
                    eventMasterModel.EventLayout = "/ShowlineImages/" + extSTM + "." + filesTm[filesTm.Length - 1].ToString();
                    eventMasterModel.EventID = ext;
                    eventMasterModel.EventDate = txtEventDate.Value;

                    eventTimeDetailsModel.Add(new EventTimeDetailsModel
                        {
                            EventFromTime = Convert.ToDateTime(txtFromTime.Value),
                            EventToTime = Convert.ToDateTime(txtTotTime.Value)
                        });

                    if (txtTicketType1.Value.Trim() != "" || txtTotalSeat1.Value.Trim() != "" || txtTicketPrice1.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType1.Value.Trim(), EventPrice = txtTicketPrice1.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat1.Value.Trim()) });
                    }

                    if (txtTicketType2.Value.Trim() != "" || txtTotalSeat2.Value.Trim() != "" || txtTicketPrice2.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType2.Value.Trim(), EventPrice = txtTicketPrice2.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat2.Value.Trim()) });
                    }

                    if (txtTicketType3.Value.Trim() != "" || txtTotalSeat3.Value.Trim() != "" || txtTicketPrice3.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType3.Value.Trim(), EventPrice = txtTicketPrice3.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat3.Value.Trim()) });
                    }

                    if (txtTicketType4.Value.Trim() != "" || txtTotalSeat4.Value.Trim() != "" || txtTicketPrice4.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType4.Value.Trim(), EventPrice = txtTicketPrice4.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat4.Value.Trim()) });
                    }

                    if (txtTicketType5.Value.Trim() != "" || txtTotalSeat5.Value.Trim() != "" || txtTicketPrice5.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType5.Value.Trim(), EventPrice = txtTicketPrice5.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat5.Value.Trim()) });
                    }

                    if (txtTicketType6.Value.Trim() != "" || txtTotalSeat6.Value.Trim() != "" || txtTicketPrice6.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType6.Value.Trim(), EventPrice = txtTicketPrice6.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat6.Value.Trim()) });
                    }

                    if (txtTicketType7.Value.Trim() != "" || txtTotalSeat7.Value.Trim() != "" || txtTicketPrice7.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType7.Value.Trim(), EventPrice = txtTicketPrice7.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat7.Value.Trim()) });
                    }

                    if (txtTicketType8.Value.Trim() != "" || txtTotalSeat8.Value.Trim() != "" || txtTicketPrice8.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType8.Value.Trim(), EventPrice = txtTicketPrice8.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat8.Value.Trim()) });
                    }

                    if (txtTicketType9.Value.Trim() != "" || txtTotalSeat9.Value.Trim() != "" || txtTicketPrice9.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType9.Value.Trim(), EventPrice = txtTicketPrice9.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat9.Value.Trim()) });
                    }

                    if (txtTicketType10.Value.Trim() != "" || txtTotalSeat10.Value.Trim() != "" || txtTicketPrice10.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType10.Value.Trim(), EventPrice = txtTicketPrice10.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat10.Value.Trim()) });
                    }

                    if (txtTicketType11.Value.Trim() != "" || txtTotalSeat11.Value.Trim() != "" || txtTicketPrice11.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType11.Value.Trim(), EventPrice = txtTicketPrice11.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat11.Value.Trim()) });
                    }

                    if (txtTicketType12.Value.Trim() != "" || txtTotalSeat12.Value.Trim() != "" || txtTicketPrice12.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType12.Value.Trim(), EventPrice = txtTicketPrice12.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat12.Value.Trim()) });
                    }

                    if (txtTicketType13.Value.Trim() != "" || txtTotalSeat13.Value.Trim() != "" || txtTicketPrice13.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType13.Value.Trim(), EventPrice = txtTicketPrice13.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat13.Value.Trim()) });
                    }

                    if (txtTicketType14.Value.Trim() != "" || txtTotalSeat14.Value.Trim() != "" || txtTicketPrice14.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType14.Value.Trim(), EventPrice = txtTicketPrice14.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat14.Value.Trim()) });
                    }

                    if (txtTicketType15.Value.Trim() != "" || txtTotalSeat15.Value.Trim() != "" || txtTicketPrice15.Value.Trim() != "")
                    {
                        eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType15.Value.Trim(), EventPrice = txtTicketPrice15.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat15.Value.Trim()) });
                    }

                    if (_eventMasterDAL.InsertEventMaster(eventMasterModel, eventTimeDetailsModel, eventPriceDetailsModel) == true)
                    {
                        if (fileName != "")
                        {
                            httpPostedFile.SaveAs(baseImageLocation + ext + "." + file[file.Length - 1].ToString());
                        }

                        if (fileNamesm != "")
                        {
                            httpPostedFilesm.SaveAs(baseImageLocationsm + extSM + "." + filesm[filesm.Length - 1].ToString());
                        }

                        if (fileExtsTm != "")
                        {
                            httpPostedFilesTm.SaveAs(baseImageLocationsTm + extSTM + "." + filesTm[filesTm.Length - 1].ToString());
                        }

                        ClearAllControl();
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Add Event Details", "<script type='text/javascript'>ConfirmMsg('Event Saved Sucessfully.','Add Event Details');</script>", false);
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Add Event Details", "<script type='text/javascript'>ErrorMsg('Unexpected error occured.Plese refresh the page and try again!','Add Event Details');</script>", false);
                    }

                }
            }
            catch (Exception ex)
            {
                ErrHandler.WriteError(ex.Message);
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                sb.Append(@"<script language='javascript'>");
                sb.Append(@"alert('Error : " + ex.Message + "')");
                sb.Append(@"</script>");
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Error", sb.ToString(), false);
            }
        }
        protected void btnUpdate_ServerClick(object sender, EventArgs e)
        {
            if (ValidatePage() == true)
            {
                string s = filenm.Value;
                string[] file;
                string ext = "";

                if (s == "")
                {
                    file = hdImagePath.Value.Split('.');
                }
                else
                {
                    file = s.Split('.');

                }

                string t = file[file.Length - 1].ToString();
                var r = new Random();
                string d = hdEventID.Value;
                ext = d;
                string baseImageLocation = Server.MapPath("~\\ShowlineImages\\");
                HttpFileCollection files = Request.Files;
                HttpPostedFile httpPostedFile = files["filenm"];
                string fileExt = Path.GetExtension(httpPostedFile.FileName).ToLower();
                string fileName = Path.GetFileName(httpPostedFile.FileName);

                #region SmallImagePath

                string sm = filesmallimage.Value;
                string[] filesm;
                string extsm = "";
                string dsm = "S" + hdEventID.Value;

                if (sm == "")
                {
                    filesm = hdEventImagePath.Value.Split('.');
                }
                else
                {
                    filesm = sm.Split('.');
                }

                string tsm = filesm[filesm.Length - 1].ToString();
                r = new Random();

                extsm = dsm;
                string baseImageLocationsm = Server.MapPath("~\\ShowlineImages\\");
                HttpFileCollection filessm = Request.Files;
                HttpPostedFile httpPostedFilesm = filessm["filesmallimage"];
                string fileExtsm = Path.GetExtension(httpPostedFilesm.FileName).ToLower();
                string fileNamesm = Path.GetFileName(httpPostedFilesm.FileName);

                #endregion

                #region TicketImage

                string sTm = filebackgroundimage.Value;
                string[] filesTm;
                string extsTm = "";
                string dsTm = "T" + hdEventID.Value;

                if (sTm == "")
                {
                    filesTm = hdTicketImagePath.Value.Split('.');
                }
                else
                {
                    filesTm = sTm.Split('.');
                }

                string tTm = filesTm[filesTm.Length - 1].ToString();
                r = new Random();

                extsTm = dsTm;
                string baseImageLocationsTm = Server.MapPath("~\\ShowlineImages\\");
                HttpFileCollection filessTm = Request.Files;
                HttpPostedFile httpPostedFilesTm = filessTm["filebackgroundimage"];
                string fileExtsTm = Path.GetExtension(httpPostedFilesTm.FileName).ToLower();
                string fileNamesTm = Path.GetFileName(httpPostedFilesTm.FileName);

                #endregion

                EventsEntryPageViewModel _eventMasterDAL = new EventsEntryPageViewModel();
                EventMasterModel eventMasterModel = new EventMasterModel();
                List<EventTimeDetailsModel> eventTimeDetailsModel = new List<EventTimeDetailsModel>();

                List<EventPriceDetailsModel> eventPriceDetailsModel = new List<EventPriceDetailsModel>();

                eventMasterModel.EventTypeID = ddEventType.SelectedItem.Value;
                eventMasterModel.EventSubtypeID = ddEvebtSubType.SelectedItem.Value.ToString();
                eventMasterModel.VenueID = ddVenueDetails.SelectedItem.Value;
                eventMasterModel.EventTitle = txtEventTitle.Value.Trim();
                eventMasterModel.EventDesc = txtEventDesc.Value.Trim();
                eventMasterModel.Artists = txtArtist.Value.Trim();
                eventMasterModel.Genre = txtGenre.Value.Trim();
                eventMasterModel.ImagePath = "/ShowlineImages/" + ext + "." + file[file.Length - 1].ToString();
                eventMasterModel.SmallImagePath = "/ShowlineImages/" + extsm + "." + filesm[filesm.Length - 1].ToString();
                eventMasterModel.EventLayout = "/ShowlineImages/" + extsTm + "." + filesTm[filesTm.Length - 1].ToString();
                eventMasterModel.EventID = ext;
                eventMasterModel.EventDate = txtEventDate.Value;

                eventTimeDetailsModel.Add(new EventTimeDetailsModel
                {
                    EventFromTime = Convert.ToDateTime(txtEventDate.Value + " " + txtFromTime.Value),
                    EventToTime = Convert.ToDateTime(txtEventDate.Value + " " + txtTotTime.Value)
                });

                if (txtTicketType1.Value.Trim() != "" || txtTotalSeat1.Value.Trim() != "" || txtTicketPrice1.Value.Trim() != "")
                {
                    eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType1.Value.Trim(), EventPrice = txtTicketPrice1.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat1.Value.Trim()) });
                }

                if (txtTicketType2.Value.Trim() != "" || txtTotalSeat2.Value.Trim() != "" || txtTicketPrice2.Value.Trim() != "")
                {
                    eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType2.Value.Trim(), EventPrice = txtTicketPrice2.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat2.Value.Trim()) });
                }

                if (txtTicketType3.Value.Trim() != "" || txtTotalSeat3.Value.Trim() != "" || txtTicketPrice3.Value.Trim() != "")
                {
                    eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType3.Value.Trim(), EventPrice = txtTicketPrice3.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat3.Value.Trim()) });
                }

                if (txtTicketType4.Value.Trim() != "" || txtTotalSeat4.Value.Trim() != "" || txtTicketPrice4.Value.Trim() != "")
                {
                    eventPriceDetailsModel.Add(new EventPriceDetailsModel { EventPriceDetails = txtTicketType4.Value.Trim(), EventPrice = txtTicketPrice4.Value.Trim(), EventTotalSeat = Convert.ToInt32(txtTotalSeat4.Value.Trim()) });
                }

                if (_eventMasterDAL.DeleteEventDetails(hdEventID.Value) == true)
                {

                    if (_eventMasterDAL.InsertEventMaster(eventMasterModel, eventTimeDetailsModel, eventPriceDetailsModel) == true)
                    {
                        if (fileName != "")
                        {
                            httpPostedFile.SaveAs(baseImageLocation + ext + "." + file[file.Length - 1].ToString());
                        }

                        if (fileNamesm != "")
                        {
                            httpPostedFilesm.SaveAs(baseImageLocation + extsm + "." + filesm[filesm.Length - 1].ToString());
                        }

                        if (fileNamesTm != "")
                        {
                            httpPostedFilesTm.SaveAs(baseImageLocation + extsTm + "." + filesTm[filesTm.Length - 1].ToString());
                        }

                        ClearAllControl();

                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Add Event Details", "<script type='text/javascript'>ConfirmMsg('Event Saved Sucessfully.','Add Event Details');</script>", false);
                        //Response.Redirect("~/viewevent.aspx");//-kk redirect
                            Response.Redirect("~/viewevent.aspx", false);
                            Context.ApplicationInstance.CompleteRequest();

                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Add Event Details", "<script type='text/javascript'>ErrorMsg('Unexpected error occured.Plese refresh the page and try again!','Add Event Details');</script>", false);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "Add Event Details", "<script type='text/javascript'>ErrorMsg('Unexpected error occured.Plese refresh the page and try again!','Add Event Details');</script>", false);
                }

            }
        }