private void btnAddSchedule_Click(object sender, System.EventArgs e)
 {
     try
     {
         inspect = new clsInspections();
         inspect.cAction = "U";
         inspect.iOrgId = OrgId;
         inspect.iInspectScheduleId = 0;
         inspect.sInspectScheduleName= tbScheduleName.Text;
         tbScheduleName.Text = "";
         inspect.InspectScheduleDetails();
         ShowInspectSchedules();
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = "admin_inspectschedules.aspx";
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(inspect != null)
             inspect.Dispose();
     }
 }
 private void dgInspectSchedules_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
     try
     {
         inspect = new clsInspections();
         inspect.iOrgId = OrgId;
         inspect.iInspectScheduleId = Convert.ToInt32(e.Item.Cells[0].Text);
         switch(e.CommandName)
         {
             case "Delete":
                 inspect.cAction = "D";
                 switch(inspect.InspectScheduleDetails())
                 {
                     case -1:
                         Session["lastpage"] = "admin_inspectschedules.aspx";
                         Session["error"] = _functions.ErrorMessage(159);
                         Response.Redirect("error.aspx", false);
                         return;
                     case -2:
                         Header.ErrorMessage = _functions.ErrorMessage(160);
                         break;
                     case -3:
                         Header.ErrorMessage = _functions.ErrorMessage(161);
                         break;
                     case 0:
                         dgInspectSchedules.EditItemIndex = -1;
                         ShowInspectSchedules();
                         break;
                     default:
                         break;
                 }
                 break;
             case "Cancel":
                 dgInspectSchedules.EditItemIndex = -1;
                 ShowInspectSchedules();
                 break;
             case "Edit":
                 dgInspectSchedules.EditItemIndex = e.Item.ItemIndex;
                 ShowInspectSchedules();
                 break;
             case "Update":
                 inspect.cAction = "U";
                 inspect.sInspectScheduleName = ((TextBox)e.Item.FindControl("tbNameEdit")).Text;
                 if(inspect.InspectScheduleDetails() == -1)
                 {
                     Session["lastpage"] = "admin_inspectschedules.aspx";
                     Session["error"] = _functions.ErrorMessage(159);
                     Response.Redirect("error.aspx", false);
                     return;
                 }
                 dgInspectSchedules.EditItemIndex = -1;
                 ShowInspectSchedules();
                 break;
             default:
                 break;
         }
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = "admin_inspectschedules.aspx";
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(inspect != null)
             inspect.Dispose();
     }
 }