/// <summary>
        /// Procedure close and sign the work order
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSave_FormSubmit(object sender, EventArgs e)
        {
            string sDataGridName;
            DBFieldType FieldType;
            DateTime daCurrentDate;
            try
            {
                daCurrentDate = DateTime.Now;
                order = new clsWorkOrders();
                order.iOrgId = OrgId;
                order.iId = OrderId;
                order.iUserId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                order.sInitials = Signature.sInitials;
                order.sPIN = Signature.sPIN;
                order.sCleanliness = tbCleanliness.Text;
                order.daCurrentDate = _functions.CorrectDate(adtClosed.Date);
                if(order.SigningWorkOrderClose() == -1)
                {
                    Signature.sError = _functions.ErrorMessage(140);
                }
                else
                {
                    order.cAction = "U";
                    order.iNoteId = 0;
                    order.iItemId = OrderId;
                    order.daCreated = daCurrentDate;

                    if(tbTechNote.Text.Length > 0)
                    {
                        order.iNoteTypeId = (int)NoteTypes.TechnicianNote;
                        order.sNote = tbTechNote.Text;
                        order.NoteDetails();
                    }
                    if(tbCheckOutNote.Text.Length > 0)
                    {
                        order.iNoteTypeId = (int)NoteTypes.CheckOutNote;
                        order.sNote = tbCheckOutNote.Text;
                        order.NoteDetails();
                    }

                    #region saving cutom fields
                    if(ViewState["CustomFields"] != null)
                    {
                        order.iId = OrderId;
                        dtCustomFields = (DataTable)ViewState["CustomFields"];

                        sDataGridName = repCustomFields.ClientID;

                        // getting data from Form and changing the dtCustomFields datatable
                        for(int i=0; i<dtCustomFields.Rows.Count; i++)
                        {
                            for(int j=0; j<Request.Form.Count; j++)
                            {
                                if((string)dtCustomFields.Rows[i]["TypeName"] == Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":inputTypeName"])
                                {
                                    FieldType = _functions.TypeNameParser((string)dtCustomFields.Rows[i]["TypeName"]); // nvarchar1...n, ...
                                    switch(FieldType)
                                    {
                                        case DBFieldType._nvarchar:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                        case DBFieldType._int:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                        case DBFieldType._float:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                        case DBFieldType._datetime:
                                            dtCustomFields.Rows[i]["Value_String"] = new SqlDateTime(Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_year"]),
                                                Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_month"]),
                                                Convert.ToInt32(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":adtValue_day"]));
                                            break;
                                        case DBFieldType._bit:
                                            if(Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":chValue"] != null)
                                            {
                                                dtCustomFields.Rows[i]["Value_String"] = "True";
                                            }
                                            else
                                            {
                                                dtCustomFields.Rows[i]["Value_String"] = "False";
                                            }
                                            break;
                                        case DBFieldType._ntext:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                        case DBFieldType._sql_variant:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                        case DBFieldType._lookup:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":ddlValue"];
                                            break;
                                        default:
                                            dtCustomFields.Rows[i]["Value_String"] = Request.Form[sDataGridName + ":_ctl" + j.ToString() + ":tbValue"];
                                            break;
                                    }
                                }
                            }
                        }

                        // saving data to database
                        order.WorkOrderDetail_CustomFields(_functions.SetDataToParameters(dtCustomFields));
                    }
                    #endregion

                    // redirect to the finish screen
                    BackFinishScreen finish = new BackFinishScreen();

                    finish.sMainText = "The Work Order closed successfully!";

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

                    finish.bContinueVisible = true;
                    finish.sContinueText = "[Continue to Check-Out Equipment by Technician]";
                    finish.sContinueURL = "wo_viewCheckOut.aspx?id=" + OrderId.ToString();

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

                    finish.bAdditionalVisible = false;

                    finish.bPrintVisible = true;
                    finish.sPrintText = "[Print the Closed Work Order]";
                    finish.sPrintURL = "ReportViewer.aspx?Report=FleetProReports%2fCompletedOrder&OrderId=" + OrderId.ToString()+ "&OrgId=" + OrgId.ToString();

                    Session["BackFinish"] = finish;

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