private void btnSave_Click(object sender, System.EventArgs e)
 {
     try
     {
         order = new clsWorkOrders();
         order.cAction = "U";
         if(((DateTime)ViewState["Date"]).CompareTo(adtLastTime.Date) <= 0)
         {
             lblError.Text = "The date cannot more then " + ((DateTime)ViewState["Date"]).ToShortDateString();
         }
         else
         {
             order.iInspectHistoryId = HistoryId;
             order.iOrgId = OrgId;
             order.iInspectSchedDetailId = InspectSchedDetailId;
             order.iId = OrderId;
             order.iEquipId = (Int32)ViewState["EquipId"];
             order.daDateHistory = adtLastTime.Date;
             if(order.InspectHistoryDetail() != -1)
             {
                 // closing the current window and reloading the parent window
                 sOnLoad = "window.close();opener.document.formSelectInspect.submit();";
                 Session["reload"] = true;
             }
         }
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
     }
     finally
     {
         if(order != null)
             order.Dispose();
     }
 }
        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                SourcePageName = "wo_addPMHistoryforPMItem.aspx.cs";

                OrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);

                if(Request.QueryString["id"] == null || Request.QueryString["inspectid"] == null || Request.QueryString["historyid"] == null)
                {
                    btnSave.Enabled = false;
                    return;
                }
                try
                {
                    OrderId = Convert.ToInt32(Request.QueryString["id"]);
                    InspectSchedDetailId = Convert.ToInt32(Request.QueryString["inspectid"]);
                    HistoryId = Convert.ToInt32(Request.QueryString["historyid"]);
                }
                catch(FormatException fex)
                {
                    btnSave.Enabled = false;
                    return;
                }

                if(!IsPostBack)
                {
                    order = new clsWorkOrders();
                    order.cAction = "S";
                    order.iOrgId = OrgId;
                    order.iId = OrderId;
                    order.iInspectSchedDetailId = InspectSchedDetailId;
                    order.iInspectHistoryId = HistoryId;
                    if(order.InspectHistoryDetail() != -1)
                    {
                        ViewState["EquipId"] = order.iEquipId.Value;
                        lblEquipName.Text = order.sEquipId.Value;
                        lblInspectionName.Text = order.sInspectionName.Value;
                        lblInspectSchedule.Text = order.sInspectSchedule.Value;
                        if(HistoryId != 0)
                        {
                            adtLastTime.Date = order.daDateHistory.Value;
                            lblHeader.Text = "Edit Date of Last Inspection";
                        }
                        else
                        {
                            adtLastTime.Date = DateTime.Now;
                            lblHeader.Text = "Add Date of Last Inspection";
                        }
                        ViewState["Date"] = adtLastTime.Date;
                    }
                    else
                    {
                        btnSave.Enabled = false;
                    }
                }
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }