/// <summary>
        /// Responds to the users request to Save
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var             oController = new ScheduledSqlJobsController();
            JobScheduleInfo oInfo;

            if (hfJobId.Value.Equals("-1"))
            {
                oInfo = new JobScheduleInfo();
                oInfo.JobScheduleId = -1;
                oInfo.NextJobRun    = System.DateTime.Now.AddMinutes(2);
                oInfo.LastJobRun    = System.DateTime.Now;
            }
            else
            {
                //Load the values
                oInfo = oController.GetJobScheduleItemById(int.Parse(hfJobId.Value));
            }

            //Load the rest
            oInfo.JobFrequencyType  = ddlJobFrequency.SelectedValue;
            oInfo.JobFrequencyValue = int.Parse(txtJobFrequency.Text);
            oInfo.JobScript         = lblJobScriptDisplay.Text;
            oInfo.JobTitle          = ddlJobType.Text;
            oInfo.JobTypeId         = int.Parse(ddlJobType.SelectedValue);

            //Save it
            oController.SaveJobScheduleItem(oInfo);

            //Update
            BindJobsGrid();

            //Cancel
            btnCancel_Click(sender, e);
        }
        /// <summary>
        /// This method handles edit and delete
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void dgrJobs_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            var oController = new ScheduledSqlJobsController();
            var jobId       = int.Parse(e.Item.Cells[0].Text);

            //Take action
            if (e.CommandName.Equals("Edit"))
            {
                //Set id
                hfJobId.Value = jobId.ToString();

                //Get items to load
                var oInfo = oController.GetJobScheduleItemById(jobId);
                ddlJobType.SelectedValue = oInfo.JobTypeId.ToString();
                ddlJobType_SelectedIndexChanged(this, EventArgs.Empty);
                txtJobFrequency.Text          = oInfo.JobFrequencyValue.ToString();
                ddlJobFrequency.SelectedValue = oInfo.JobFrequencyType;

                //Swap views
                pnlViewJobs.Visible    = false;
                pnlAddEditJobs.Visible = true;
            }
            else if (e.CommandName.Equals("Delete"))
            {
                //Delete
                oController.DeleteJobScheduleItem(jobId);

                //Rebind
                BindJobsGrid();
            }
            else if (e.CommandName.Equals("History"))
            {
                var oHistory = oController.GetJobScheduleHistory(jobId);
                if (oHistory == null)
                {
                    oHistory = new List <JobScheduleHistoryInfo>();
                }
                dgrHistory.DataSource = oHistory;
                dgrHistory.DataBind();

                pnlViewJobs.Visible   = false;
                pnlJobHistory.Visible = true;
            }
            else if (e.CommandName.Equals("Run"))
            {
                //Manually run job
                var oJob      = oController.GetJobScheduleItemById(jobId);
                var oJobInfo  = oController.GetJobTypeById(oJob.JobTypeId);
                var result    = "";
                var isSuccess = true;
                try
                {
                    int rows = oController.ExecuteJob(oJob.JobScript, oJobInfo.IsCannedJob);
                    result = "Success<br />" + rows.ToString() + " rows afected";
                }
                catch (Exception ex)
                {
                    isSuccess = false;
                    result    = "Error: " + ex.Message;
                }

                //Update the entry and insert history
                oController.InsertJobScheduleHistory(oJob.JobScheduleId, DateTime.Now, isSuccess, result);

                DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, Localization.GetString("RunSuccess", this.LocalResourceFile), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.GreenSuccess);
            }
        }