Example #1
0
        protected void btnSaveEvent_Click(object sender, System.EventArgs e)
        {
            try
            {
                //this.cvCurrentPoints.Validate();
                this.cvCurrentDate.Validate();


                int EventID;

                int EventPeriodID;
                try
                {
                    EventID = int.Parse(Session["EventID"].ToString());
                }
                catch
                {
                    EventID = -1;
                }
                try
                {
                    EventPeriodID = int.Parse(Session["EventPeriodID"].ToString());
                }
                catch
                {
                    EventPeriodID = -1;
                }
                if (Session["Action"].ToString() == "Add")
                {
                    EventID       = -1;
                    EventPeriodID = -1;
                }
                if (!this.IsValid && (EventID < 0))
                {
                    return;
                }
                else if (!this.IsValid)
                {
                    return;
                }

                this.lblNoPeriod.Text = String.Empty;
                BusinessServices.Event objEvent = new BusinessServices.Event();
                objEvent = GetEventValues();

                int    OrganisationID = UserContext.UserData.OrgID;
                string ProfileName    = this.txtEventName.Text;

                DataTable dtEventName = objEvent.CheckUserEventName(objEvent.EventName, OrganisationID, int.Parse(ddlCPDProfile.SelectedValue), EventPeriodID, UserContext.UserID);
                //if (dtProfileName.Rows.Count > 0 && (ProfileNameCheck != ProfileName))
                if (dtEventName.Rows.Count > 0)
                {
                    this.lblMessage.Text    += ResourceManager.GetString("EventExists");
                    this.lblMessage.CssClass = "WarningMessage";
                    return;
                }

                int  CheckRowCount     = 0;
                bool flagCanUpload     = true;
                HttpFileCollection hfc = Request.Files;



                //for (int i = 0; i < hfc.Count; i++)
                //{
                //    HttpPostedFile hpf = hfc[i];
                //    if (hpf.FileName != "")
                //    {
                //        System.IO.FileInfo file = new System.IO.FileInfo(hpf.FileName);
                //        string fname = file.Name.Remove((file.Name.Length - file.Extension.Length));
                //        fname = fname + "_" + DateTime.Now.ToString("dd-MM-yyyy-hh:mm:ss") + file.Extension;


                //        if (hpf.ContentLength > 0)
                //        {
                //            DataTable dt = objEvent.CheckFileName(OrganisationID, fname);
                //            CheckRowCount = dt.Rows.Count;
                //            if (CheckRowCount != 0)
                //            {
                //                // File with this name already exists for this organisation
                //                flagCanUpload = false;

                //                lblMessage.Text = ResourceManager.GetString("FileExists");
                //                lblMessage.CssClass = "WarningMessage";
                //                return;
                //            }
                //        }
                //    }
                //}

                if (EventID > 0) //Existing Event - update
                {
                    if (flagCanUpload)
                    {
                        objEvent.UpdateUserEvent(objEvent);
                        // EventPeriodID = objProfile.GetEventPeriodID(EventID);
                        Session["EventPeriodID"] = EventPeriodID;
                        UploadEventFile(EventPeriodID, true);
                        // objEvent.UpdateEventPeriodAccess(OrganisationID, EventPeriodID, objEvent.EventID);
                        panPeriod.Visible = true;
                        InitialisePage(EventID, EventPeriodID);
                        LoadEvent(EventID, EventPeriodID);
                        this.lblMessage.Text    += ResourceManager.GetString("SaveSuccess");
                        this.lblMessage.CssClass = "SuccessMessage";
                    }
                }
                else // New Event - Add
                {
                    if (flagCanUpload)
                    {
                        EventID       = objEvent.AddEvent(objEvent);
                        EventPeriodID = objEvent.EventPeriodID;

                        UploadEventFile(EventPeriodID, true);

                        // Assign the new values to session variables
                        Session["EventPeriodID"] = EventPeriodID;
                        Session["EventID"]       = EventID;

                        // Initialize all units and users granted access to 0
                        //objEvent.InitialiseEventPeriodAccess(OrganisationID, objEvent.EventID, EventPeriodID);

                        panPeriod.Visible = true;
                        InitialisePage(EventID, EventPeriodID);
                        LoadEvent(EventID, EventPeriodID);

                        this.lblMessage.Text    += ResourceManager.GetString("SaveSuccess");
                        this.lblMessage.CssClass = "SuccessMessage";
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "Usercpdevent.aspx.cs", "btnSaveEvent_Click", ex.Message);
            }
        }