Ejemplo n.º 1
0
        /// <summary>
        /// Procedure is adding a new work order into database and redirecting to finish screen
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btNext_FormSubmit(object sender, EventArgs e)
        {
            string sDataGridName;
            DBFieldType FieldType;
            DateTime daTmpForFixBug, daCurrent;
            try
            {
                daCurrent = DateTime.Now;
                if(adtScheduled.Date < daCurrent)
                {
                    lblErrorScheduled.Text = "The Scheduled date must be in future";
                    return;
                }
                order = new clsWorkOrders();
                order.iOrgId = OrgId;
                order.iEquipId = EquipId;
                if(adtScheduled.Date.Hour == 0 || adtScheduled.Date.Hour == 12)
                {
                    daTmpForFixBug = adtScheduled.Date;
                    if(daTmpForFixBug.Hour == 0)daTmpForFixBug = daTmpForFixBug.AddHours(12);
                    else daTmpForFixBug = daTmpForFixBug.AddHours(-12);
                }
                else
                    daTmpForFixBug = adtScheduled.Date;
                order.daScheduled = daTmpForFixBug;
                order.iInspectSchedDetailId = InspectSchedDetailId;
                order.iUserId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                order.daCurrentDate = daCurrent;
                order.SetInspectWorkOrder();

                if(tbNotes.Text.Length > 0)
                {
                    order.cAction = "U";
                    order.iNoteId = 0;
                    order.iNoteTypeId = (int)NoteTypes.CreationNote;
                    order.iItemId = order.iId;
                    order.daCreated = daCurrent;
                    order.sNote = tbNotes.Text;
                    order.NoteDetails();
                }

                BackFinishScreen finish = new BackFinishScreen();

                finish.sMainText = "The Work Order with Inspection has been created successfully.";

                finish.bMainMenuVisible = true;
                finish.sMainMenuText = "[Return to Main Menu]";
                finish.sMainMenuURL = "main.aspx";

                finish.bContinueVisible = true;
                finish.sContinueText = "[Create a New Future Work Order with Inspection]";
                finish.sContinueURL = "wo_showEquipsForInspect.aspx";

                finish.bViewVisible = true;
                finish.sViewText = "[View a new Work Order with Inspection]";
                finish.sViewURL = "wo_viewWorkOrder.aspx?id=" +  order.iId.Value.ToString();

                finish.bAdditionalVisible = false;

                finish.bPrintVisible = false;

                Session["BackFinish"] = finish;

                Response.Redirect("wo_finish.aspx", false);

            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = "wo_addInspectForecast.aspx?equipid=" + EquipId.ToString() + "&sid=" + InspectSchedDetailId.ToString();
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }
        private void btSave_FormSubmit(object sender, EventArgs e)
        {
            string sDomenName;
            int l_iResult;

            try
            {
                SaveChangedItems();

                order = new clsWorkOrders();
                order.iOrgId = OrgId;
                order.iId = OrderId;
                order.iInspectionId = InspectId;
                order.iUserId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                order.iTechId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                order.sInitials = tbInitial.Text;
                order.sPIN = tbPIN.Text;
                order.daCurrentDate = _functions.CorrectDate(adtInspection.Date);
                switch(order.SigningInspectionList())
                {
                    case 0:
                        if(cbAutoCreateWO.Checked)
                        {
                            order.iInspectSchedDetailId = (int)ViewState["InspectSchedDetailId"];
                            order.iEquipId = (int)ViewState["EquipId"];
                            order.daCurrentDate = _functions.CorrectDate(adtInspection.Date);
                            l_iResult = order.GetDateTimeOfForecastInspection();
                            if(l_iResult == -1)
                            {
                                // error
                                Header.ErrorMessage = _functions.ErrorMessage(order.iErrorCode.Value);
                            }
                            else
                            {
                                if(l_iResult == 2)
                                {
                                    // sent email contain that inspection has been created but The Minimum through Maximum Date range is too small or the Holiday/No Service Date Ranges are too wide and the system is unable to identify any service dates available
                                }
                                order.SetInspectWorkOrder();
                                // redirect to the finish screen
                                BackFinishScreen finish = new BackFinishScreen();
                                if(l_iResult == 1)
                                    finish.sMainText = "The Inspection has been completed successfully. <br>" + _functions.ErrorMessage(order.iErrorCode.Value);
                                else
                                    finish.sMainText = "The Inspection has been completed successfully. <br>Next Inspection has been scheduled by " + order.daScheduled.Value.ToString() + " of work order";

                                finish.bMainMenuVisible = true;
                                finish.sMainMenuText = "[Return to Main Menu]";
                                finish.sMainMenuURL = "main.aspx";

                                if(l_iResult == 1)
                                    finish.bContinueVisible = false;
                                else
                                {
                                    finish.bContinueVisible = true;
                                    finish.sContinueText = "[View the Work Order of Next Inspection]";
                                    finish.sContinueURL = "wo_viewWorkOrder.aspx?id=" +  order.iId.Value.ToString();
                                }

                                finish.bViewVisible = true;
                                finish.sViewText = "[Return to Work Order Detail]";
                                finish.sViewURL = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();

                                finish.bAdditionalVisible = false;

                                finish.bPrintVisible = false;

                                Session["BackFinish"] = finish;

                                Response.Redirect("wo_finish.aspx", false);
                            }
                        }
                        else
                            Response.Redirect("wo_viewWorkOrder.aspx?id=" + OrderId.ToString() + "&#Issues", false);
                        return;
                    case -1:
                        Header.ErrorMessage = _functions.ErrorMessage(140);
                        break;
                    case -2:
                        Header.ErrorMessage = _functions.ErrorMessage(139);
                        break;
                    default:
                        break;
                }
                repInspectItems.DataSource = new DataView(order.GetWorkOrderInspectItems());
                repInspectItems.DataBind();

            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = "wo_viewCompleteInspection.aspx?id=" + OrderId.ToString() + "&inspectid=" + InspectId.ToString();
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }