/// <summary>
 /// This method will update the job type information
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void ddlJobType_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (ddlJobType.SelectedIndex >= 0)
     {
         var oController = new ScheduledSqlJobsController();
         var oType       = oController.GetJobTypeById(int.Parse(ddlJobType.SelectedValue));
         lblJobDescriptionDisplay.Text = oType.JobDescription;
         lblJobScriptDisplay.Text      = oType.CannedProcedure;
     }
     else
     {
         lblJobDescriptionDisplay.Text = "";
         lblJobScriptDisplay.Text      = "";
     }
 }
 protected void dgrExistingJobs_ItemCommand(object source, DataGridCommandEventArgs e)
 {
     if (e.CommandName.Equals("Edit"))
     {
         var jobTypeId   = int.Parse(e.Item.Cells[0].Text);
         var oController = new ScheduledSqlJobsController();
         var oInfo       = oController.GetJobTypeById(jobTypeId);
         JobId                   = oInfo.JobTypeId;
         txtJobTitle.Text        = oInfo.JobTitle;
         txtJobDescription.Text  = oInfo.JobDescription;
         txtCannedProcedure.Text = oInfo.CannedProcedure;
         btnDelete.Visible       = true;
         pnlView.Visible         = false;
         pnlEdit.Visible         = true;
     }
 }
        /// <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);
            }
        }