public EventMasterModel GetEventDetails(string EventID)
        {
            try
            {
                EventMasterModel eventMasterModel = new EventMasterModel();

                using (SqlConnection conn = new SqlConnection(ConnString))
                {
                    using (SqlCommand cmd = new SqlCommand("SL_PROC_EVENTMASTER", conn))
                    {

                        conn.Open();
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@EventSPID", SqlDbType.VarChar, 22).Value = EventID;
                        SqlDataReader dr = cmd.ExecuteReader();

                        while (dr.Read())
                        {
                            eventMasterModel.EventTypeID = dr["EventTypeID"].ToString();
                            eventMasterModel.EventType = dr["EventType"].ToString();
                            eventMasterModel.EventSubtypeID = dr["EventSubtypeID"].ToString();
                            eventMasterModel.EventSubTypeDesc = dr["EventSubTypeDesc"].ToString();
                            eventMasterModel.VenueID = dr["VenueID"].ToString();
                            eventMasterModel.VenueName = dr["VenueName"].ToString();
                            eventMasterModel.EventTitle = dr["EventTitle"].ToString();
                            eventMasterModel.EventDesc = dr["EventDesc"].ToString();
                            eventMasterModel.Artists = dr["Artists"].ToString();
                            eventMasterModel.Genre = dr["Genre"].ToString();
                            eventMasterModel.ImagePath = dr["ImagePath"].ToString();
                            eventMasterModel.EventID = dr["EventSPID"].ToString();
                            eventMasterModel.EventDate = dr["EventDate"].ToString();
                            eventMasterModel.EventLayout = dr["EventLayout"].ToString();
                            eventMasterModel.SmallImagePath = dr["SmallImagePath"].ToString();
                        }
                    }
                }

                return eventMasterModel;
            }
            catch
            {
                return null;
            }
        }
        public bool UpdateEventMaster(EventMasterModel eventMasterModel, List<EventTimeDetailsModel> eventTimeDetailsModel)
        {
            try
            {
                string EVENTID = "";

                using (SqlConnection conn = new SqlConnection(ConnString))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            using (SqlCommand cmd = new SqlCommand("SL_PROC_UPDATE_EVENT_NEW", conn, trans))
                            {
                                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                cmd.Parameters.Add("@EventTypeID", SqlDbType.Int).Value = eventMasterModel.EventTypeID;
                                cmd.Parameters.Add("@EventSubtypeID", SqlDbType.Int).Value = eventMasterModel.EventSubtypeID;
                                cmd.Parameters.Add("@VenueID", SqlDbType.Int).Value = eventMasterModel.VenueID;
                                cmd.Parameters.Add("@EventTitle", SqlDbType.VarChar, 200).Value = eventMasterModel.EventTitle;
                                cmd.Parameters.Add("@EventDesc", SqlDbType.VarChar).Value = eventMasterModel.EventDesc;
                                cmd.Parameters.Add("@Artists", SqlDbType.VarChar, 500).Value = eventMasterModel.Artists;
                                cmd.Parameters.Add("@Genre", SqlDbType.VarChar, 500).Value = eventMasterModel.Genre;
                                cmd.Parameters.Add("@EventImg", SqlDbType.VarChar).Value = eventMasterModel.ImagePath;
                                cmd.Parameters.Add("@EventID", SqlDbType.VarChar, 22).Value = eventMasterModel.EventID;
                                cmd.Parameters.Add("@EventDate", SqlDbType.VarChar, 22).Value = eventMasterModel.EventDate;
                                cmd.Parameters.Add("@EvenLayOut", SqlDbType.VarChar).Value = eventMasterModel.EventLayout;
                                cmd.Parameters.Add("@SmallImage", SqlDbType.VarChar).Value = eventMasterModel.SmallImagePath;

                                cmd.ExecuteNonQuery();

                                EVENTID = eventMasterModel.EventID;
                            }

                            for (int i = 0; i < eventTimeDetailsModel.Count; i++)
                            {
                                using (SqlCommand cmd = new SqlCommand("proc_UPDATE_EventTime", conn, trans))
                                {
                                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                    cmd.Parameters.Add("@EventFromTime", SqlDbType.VarChar, 35).Value = eventTimeDetailsModel[i].EventFromTime.ToString();
                                    cmd.Parameters.Add("@EventToTime", SqlDbType.VarChar, 35).Value = eventTimeDetailsModel[i].EventToTime.ToString();
                                    cmd.Parameters.Add("@EventSPID", SqlDbType.VarChar, 22).Value = eventMasterModel.EventID;
                                    cmd.ExecuteNonQuery();
                                }
                            }

                            trans.Commit();
                        }
                        catch (Exception ex)
                        {
                            ErrHandler.WriteError(ex.Message);
                            trans.Rollback();
                            return false;
                        }
                    }
                }

                return true;
            }
            catch (Exception ex1)
            {
                ErrHandler.WriteError(ex1.Message);
                return false;
            }
        }
        private void EditEventDetails(string EventSPID)
        {
            try
            {
                EventsEntryPageViewModel eventsEntryPageViewModel = new EventsEntryPageViewModel();
                EventMasterModel _eventMasterModel = new EventMasterModel();

                _eventMasterModel = eventsEntryPageViewModel.GetEventDetails(EventSPID);

                if (_eventMasterModel != null)
                {
                    txtEventTitle.Value = _eventMasterModel.EventTitle;
                    txtEventDesc.Value = _eventMasterModel.EventDesc;
                    txtArtist.Value = _eventMasterModel.Artists;
                    txtGenre.Value = _eventMasterModel.Genre;
                    txtEventDate.Value = _eventMasterModel.EventDate;
                    ddEventType.SelectedValue = _eventMasterModel.EventTypeID;
                    GetEventSubType(Convert.ToInt32(_eventMasterModel.EventTypeID));

                    img_prev.Src = _eventMasterModel.ImagePath;
                    imgSmallImg.Src = _eventMasterModel.SmallImagePath;
                    ImgTicketImage.Src = _eventMasterModel.EventLayout;

                    ddEvebtSubType.SelectedValue = _eventMasterModel.EventSubtypeID;
                    ddVenueDetails.SelectedValue = _eventMasterModel.VenueID;
                    hdEventID.Value = _eventMasterModel.EventID;

                    hdImagePath.Value = _eventMasterModel.ImagePath;
                    hdEventImagePath.Value = _eventMasterModel.SmallImagePath;
                    hdTicketImagePath.Value = _eventMasterModel.EventLayout;

                    txtEventDate.Value = Convert.ToDateTime(_eventMasterModel.EventDate).ToString("dd/MMM/yyyy");
                }

                EventTimeDetailsModel _eventTimeDetailsModel = new EventTimeDetailsModel();
                _eventTimeDetailsModel = eventsEntryPageViewModel.GetEventTimeDetails(EventSPID);

                if (_eventTimeDetailsModel != null)
                {
                    txtFromTime.Value = _eventTimeDetailsModel.EventFromTime.ToString("HH:mm");
                    txtTotTime.Value = _eventTimeDetailsModel.EventToTime.ToString("HH:mm");
                    EventTimeID.Value = _eventTimeDetailsModel.EventTimeID.ToString();
                }

                List<EventPriceDetailsModel> _eventPriceDetailsModel = new List<EventPriceDetailsModel>();
                _eventPriceDetailsModel = eventsEntryPageViewModel.GetEventPriceDetails(EventSPID);

                int i = 1;

                if (_eventPriceDetailsModel != null)
                {
                    foreach (var item in _eventPriceDetailsModel)
                    {
                        if (i == 1)
                        {
                            EPID1.Value = item.EventPriceID;
                            txtTicketType1.Value = item.EventPriceDetails;
                            txtTotalSeat1.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice1.Value = item.EventPrice;
                        }

                        if (i == 2)
                        {
                            EPID2.Value = item.EventPriceID;
                            txtTicketType2.Value = item.EventPriceDetails;
                            txtTotalSeat2.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice2.Value = item.EventPrice;
                        }

                        if (i == 3)
                        {
                            EPID3.Value = item.EventPriceID;
                            txtTicketType3.Value = item.EventPriceDetails;
                            txtTotalSeat3.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice3.Value = item.EventPrice;
                        }

                        if (i == 4)
                        {
                            EPID4.Value = item.EventPriceID;
                            txtTicketType4.Value = item.EventPriceDetails;
                            txtTotalSeat4.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice4.Value = item.EventPrice;
                        }

                        if (i == 5)
                        {
                            EPID5.Value = item.EventPriceID;
                            txtTicketType5.Value = item.EventPriceDetails;
                            txtTotalSeat5.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice5.Value = item.EventPrice;
                        }

                        if (i == 6)
                        {
                            EPID6.Value = item.EventPriceID;
                            txtTicketType6.Value = item.EventPriceDetails;
                            txtTotalSeat6.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice6.Value = item.EventPrice;
                        }

                        if (i == 7)
                        {
                            EPID7.Value = item.EventPriceID;
                            txtTicketType7.Value = item.EventPriceDetails;
                            txtTotalSeat7.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice7.Value = item.EventPrice;
                        }

                        if (i == 8)
                        {
                            EPID8.Value = item.EventPriceID;
                            txtTicketType8.Value = item.EventPriceDetails;
                            txtTotalSeat8.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice8.Value = item.EventPrice;
                        }

                        if (i == 9)
                        {
                            EPID9.Value = item.EventPriceID;
                            txtTicketType9.Value = item.EventPriceDetails;
                            txtTotalSeat9.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice9.Value = item.EventPrice;
                        }

                        if (i == 10)
                        {
                            EPID10.Value = item.EventPriceID;
                            txtTicketType10.Value = item.EventPriceDetails;
                            txtTotalSeat10.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice10.Value = item.EventPrice;
                        }

                        if (i == 11)
                        {
                            EPID11.Value = item.EventPriceID;
                            txtTicketType11.Value = item.EventPriceDetails;
                            txtTotalSeat11.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice11.Value = item.EventPrice;
                        }

                        if (i == 12)
                        {
                            EPID12.Value = item.EventPriceID;
                            txtTicketType12.Value = item.EventPriceDetails;
                            txtTotalSeat12.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice12.Value = item.EventPrice;
                        }

                        if (i == 13)
                        {
                            EPID13.Value = item.EventPriceID;
                            txtTicketType13.Value = item.EventPriceDetails;
                            txtTotalSeat13.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice13.Value = item.EventPrice;
                        }

                        if (i == 14)
                        {
                            EPID14.Value = item.EventPriceID;
                            txtTicketType14.Value = item.EventPriceDetails;
                            txtTotalSeat14.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice14.Value = item.EventPrice;
                        }

                        if (i == 15)
                        {
                            EPID15.Value = item.EventPriceID;
                            txtTicketType15.Value = item.EventPriceDetails;
                            txtTotalSeat15.Value = item.EventTotalSeat.ToString();
                            txtTicketPrice15.Value = item.EventPrice;
                        }

                        i++;
                    }
                }

                btnSave.Visible = false;
                btnUpdate.Visible = true;
            }
            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 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)
        {
            try
            {
                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.Substring(1, hdEventID.Value.Length - 1);

                    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.Substring(1, hdEventID.Value.Length - 1);

                    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(txtFromTime.Value),
                        EventToTime = Convert.ToDateTime(txtTotTime.Value)
                        //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 (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.UpdateEventMaster(eventMasterModel, eventTimeDetailsModel) == true)
                    {
                        if (fileName != "")
                        {
                            //FileInfo fileInfoPath = new FileInfo(baseImageLocation + ext + "." + file[file.Length - 1].ToString());
                            //if (fileInfoPath.Exists)
                            //{
                            //    fileInfoPath.Delete();
                            //}

                            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", 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);
                    }

                    //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);
                    //}

                }
            }
            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);
            }
        }
        public bool InsertEventMaster(EventMasterModel eventMasterModel, List<EventTimeDetailsModel> eventTimeDetailsModel, List<EventPriceDetailsModel> eventPriceDetailsModel)
        {
            try
            {
                string EVENTID = "";

                using (SqlConnection conn = new SqlConnection(ConnString))
                {
                    conn.Open();
                    using (SqlTransaction trans = conn.BeginTransaction())
                    {
                        try
                        {
                            using (SqlCommand cmd = new SqlCommand("proc_INSERT_EVENT", conn, trans))
                            {
                                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                cmd.Parameters.Add("@EventTypeID", SqlDbType.Int).Value = eventMasterModel.EventTypeID;
                                cmd.Parameters.Add("@EventSubtypeID", SqlDbType.Int).Value = eventMasterModel.EventSubtypeID;
                                cmd.Parameters.Add("@VenueID", SqlDbType.Int).Value = eventMasterModel.VenueID;
                                cmd.Parameters.Add("@EventTitle", SqlDbType.VarChar, 200).Value = eventMasterModel.EventTitle;
                                cmd.Parameters.Add("@EventDesc", SqlDbType.VarChar).Value = eventMasterModel.EventDesc;
                                cmd.Parameters.Add("@Artists", SqlDbType.VarChar, 500).Value = eventMasterModel.Artists;
                                cmd.Parameters.Add("@Genre", SqlDbType.VarChar, 500).Value = eventMasterModel.Genre;
                                cmd.Parameters.Add("@EventImg", SqlDbType.VarChar).Value = eventMasterModel.ImagePath;
                                cmd.Parameters.Add("@EventID", SqlDbType.VarChar, 22).Value = eventMasterModel.EventID;
                                cmd.Parameters.Add("@EventDate", SqlDbType.VarChar, 22).Value = eventMasterModel.EventDate;
                                cmd.Parameters.Add("@EvenLayOut", SqlDbType.VarChar).Value = eventMasterModel.EventLayout;
                                cmd.Parameters.Add("@SmallImage", SqlDbType.VarChar).Value = eventMasterModel.SmallImagePath;

                                cmd.ExecuteNonQuery();

                                EVENTID = eventMasterModel.EventID;
                            }

                            for (int i = 0; i < eventTimeDetailsModel.Count; i++)
                            {
                                using (SqlCommand cmd = new SqlCommand("proc_INSERT_EventTime", conn, trans))
                                {
                                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                    cmd.Parameters.Add("@EventFromTime", SqlDbType.VarChar, 35).Value = eventTimeDetailsModel[i].EventFromTime.ToString();
                                    cmd.Parameters.Add("@EventToTime", SqlDbType.VarChar, 35).Value = eventTimeDetailsModel[i].EventToTime.ToString();
                                    cmd.Parameters.Add("@EventSPID", SqlDbType.VarChar, 22).Value = eventMasterModel.EventID;
                                    cmd.ExecuteNonQuery();
                                }
                            }

                            for (int j = 0; j < eventPriceDetailsModel.Count; j++)
                            {
                                using (SqlCommand cmd = new SqlCommand("proc_insert_eventprice", conn, trans))
                                {
                                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                                    cmd.Parameters.Add("@eventpricedetails", SqlDbType.VarChar, 100).Value = eventPriceDetailsModel[j].EventPriceDetails.ToString();
                                    cmd.Parameters.Add("@eventprice", SqlDbType.VarChar, 6).Value = eventPriceDetailsModel[j].EventPrice.ToString();
                                    cmd.Parameters.Add("@eventtotalseat", SqlDbType.Int).Value = eventPriceDetailsModel[j].EventTotalSeat.ToString();
                                    cmd.Parameters.Add("@eventspid", SqlDbType.VarChar, 22).Value = eventMasterModel.EventID;
                                    cmd.ExecuteNonQuery();
                                }
                            }

                            trans.Commit();

                            GenerateBarCode(EVENTID);
                        }
                        catch (Exception ex)
                        {
                            trans.Rollback();
                        }
                    }
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
        private void EditEventDetails(string EventSPID)
        {
            EventsEntryPageViewModel eventsEntryPageViewModel = new EventsEntryPageViewModel();
            EventMasterModel _eventMasterModel = new EventMasterModel();

            _eventMasterModel = eventsEntryPageViewModel.GetEventDetails(EventSPID);

            if (_eventMasterModel != null)
            {
                txtEventTitle.Value = _eventMasterModel.EventTitle;
                txtEventDesc.Value = _eventMasterModel.EventDesc;
                txtArtist.Value = _eventMasterModel.Artists;
                txtGenre.Value = _eventMasterModel.Genre;
                txtEventDate.Value = _eventMasterModel.EventDate;
                ddEventType.SelectedValue= _eventMasterModel.EventTypeID;
                GetEventSubType(Convert.ToInt32(_eventMasterModel.EventTypeID));

                img_prev.Src = _eventMasterModel.ImagePath;
                imgSmallImg.Src = _eventMasterModel.SmallImagePath;
                ImgTicketImage.Src = _eventMasterModel.EventLayout;

                ddEvebtSubType.SelectedValue = _eventMasterModel.EventSubtypeID;
                ddVenueDetails.SelectedValue = _eventMasterModel.VenueID;
                hdEventID.Value = _eventMasterModel.EventID;

                hdImagePath.Value = _eventMasterModel.ImagePath;
                hdEventImagePath.Value = _eventMasterModel.SmallImagePath;
                hdTicketImagePath.Value = _eventMasterModel.EventLayout;

                txtEventDate.Value = Convert.ToDateTime(_eventMasterModel.EventDate).ToString("dd/MMM/yyyy");
            }

            EventTimeDetailsModel _eventTimeDetailsModel = new EventTimeDetailsModel();
            _eventTimeDetailsModel = eventsEntryPageViewModel.GetEventTimeDetails(EventSPID);

            if (_eventTimeDetailsModel != null)
            {
                txtFromTime.Value = _eventTimeDetailsModel.EventFromTime.ToString("HH:mm");
                txtTotTime.Value = _eventTimeDetailsModel.EventToTime.ToString("HH:mm");
                EventTimeID.Value = _eventTimeDetailsModel.EventTimeID.ToString();
            }

            List<EventPriceDetailsModel> _eventPriceDetailsModel = new List<EventPriceDetailsModel>();
            _eventPriceDetailsModel = eventsEntryPageViewModel.GetEventPriceDetails(EventSPID);

            int i = 1;

            if (_eventPriceDetailsModel != null)
            {
                foreach (var item in _eventPriceDetailsModel)
                {
                    if (i == 1)
                    {
                        EPID1.Value = item.EventPriceID;
                        txtTicketType1.Value = item.EventPriceDetails;
                        txtTotalSeat1.Value = item.EventTotalSeat.ToString();
                        txtTicketPrice1.Value = item.EventPrice;
                    }

                    if (i == 2)
                    {
                        EPID2.Value = item.EventPriceID;
                        txtTicketType2.Value = item.EventPriceDetails;
                        txtTotalSeat2.Value = item.EventTotalSeat.ToString();
                        txtTicketPrice2.Value = item.EventPrice;
                    }

                    if (i == 3)
                    {
                        EPID3.Value = item.EventPriceID;
                        txtTicketType3.Value = item.EventPriceDetails;
                        txtTotalSeat3.Value = item.EventTotalSeat.ToString();
                        txtTicketPrice3.Value = item.EventPrice;
                    }

                    if (i == 4)
                    {
                        EPID4.Value = item.EventPriceID;
                        txtTicketType4.Value = item.EventPriceDetails;
                        txtTotalSeat4.Value = item.EventTotalSeat.ToString();
                        txtTicketPrice4.Value = item.EventPrice;
                    }

                    i++;
                }
            }

            btnSave.Visible = false;
            btnUpdate.Visible = true;
        }