private void Save()
        {
            // Validate data
            bool validData = true;

            validData = ValidatePage();

            // For valid data
            if (validData)
            {
                // Costs Gridview, if the gridview is edition mode
                if (grdCosts.EditIndex >= 0)
                {
                    grdCosts.UpdateRow(grdCosts.EditIndex, true);
                }

                // Notes Gridview, if the gridview is edition mode
                if (grdNotes.EditIndex >= 0)
                {
                    grdNotes.UpdateRow(grdNotes.EditIndex, true);
                }

                // Save cost and notes data
                GrdCostsAdd();
                GrdNotesAdd();

                // Save data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int serviceId = Int32.Parse(hdfServiceId.Value);

                // Unmodified data
                ServiceInformationBasicInformationGateway serviceInformationBasicInformationGatewayForEdit = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
                string serviceState = serviceInformationBasicInformationGatewayForEdit.GetServiceState(serviceId);
                string associatedChecklistRuleState = serviceInformationBasicInformationGatewayForEdit.GetAssociatedChecklistRuleState(serviceId);

                // ... Get basic service data
                bool newMtoDto = ckbxMtoDto.Checked;
                string newServiceDescription = tbxServiceDescription.Text.Trim();

                // ... Get general service data
                string newMileage = tbxGeneralMileage.Text.Trim();

                // ... Get assigned data
                DateTime? newAssignmentDateTime = null;
                DateTime? newAssignmentDeadlineDate = null;
                bool newToTeamMember = false;
                int? newAssignTeamMemberID = null;
                string newThirdPartyVendor = "";
                DateTime? assignmentAcceptedDateTime = null;
                string newAssignmentRejectedReason = "";
                DateTime? assignmentRejectedDateTime = null;

                if (pnlAssignmentData.Visible)
                {
                    if (pnlAssignedToReadOnly.Visible)
                    {
                        if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                        if (serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId).HasValue) newAssignmentDeadlineDate = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId);
                        newToTeamMember = serviceInformationBasicInformationGatewayForEdit.GetToTeamMember(serviceId);
                        if (newToTeamMember) newAssignTeamMemberID = (int)serviceInformationBasicInformationGatewayForEdit.GetAssignTeamMemberId(serviceId);
                        newThirdPartyVendor = serviceInformationBasicInformationGatewayForEdit.GetAssignedThirdPartyVendor(serviceId);
                    }

                    if (pnlAssignedTo.Visible)
                    {
                        if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                        if (tkrdpAssignmentDataAssignedDeadlineDate.SelectedDate.HasValue) newAssignmentDeadlineDate = tkrdpAssignmentDataAssignedDeadlineDate.SelectedDate.Value;
                        newToTeamMember = rbtnAssignmentDataToTeamMember.Checked;
                        if (newToTeamMember) newAssignTeamMemberID = Int32.Parse(ddlAssignmentDataAssignToTeamMember.SelectedValue);
                        newThirdPartyVendor = tbxAssignmentDataAssignToThirdPartyVendor.Text.Trim();
                    }

                    if (serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId).HasValue) assignmentAcceptedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId);
                    if (serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId).HasValue) assignmentRejectedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId);
                    newAssignmentRejectedReason = tbxAssignmentDataRejectedReason.Text.Trim();
                }
                else
                {
                    if (pnlAssignmentDataReadOnly.Visible)
                    {
                        if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                        if (serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId).HasValue) newAssignmentDeadlineDate = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId);
                        newToTeamMember = serviceInformationBasicInformationGatewayForEdit.GetToTeamMember(serviceId);
                        if (newToTeamMember) newAssignTeamMemberID = (int)serviceInformationBasicInformationGatewayForEdit.GetAssignTeamMemberId(serviceId);
                        newThirdPartyVendor = serviceInformationBasicInformationGatewayForEdit.GetAssignedThirdPartyVendor(serviceId);
                        if (serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId).HasValue) assignmentAcceptedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId);
                        if (serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId).HasValue) assignmentRejectedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId);
                        newAssignmentRejectedReason = tbxAssignmentDataRejectedReasonReadOnly.Text.Trim();
                    }
                }

                // ... Get start work data
                DateTime? startWorkDateTime = null; if (serviceInformationBasicInformationGatewayForEdit.GetStartWorkDateTime(serviceId).HasValue) startWorkDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetStartWorkDateTime(serviceId);
                DateTime? newUnitOutOfServiceDate = null;
                string newUnitOutOfServiceTime = "";
                string newStartWorkMileage = "";

                if (pnlStartWorkData.Visible)
                {
                    if (tkrdpStartWorkDataUnitOutOfServiceDate.SelectedDate.HasValue) newUnitOutOfServiceDate = tkrdpStartWorkDataUnitOutOfServiceDate.SelectedDate.Value;
                    newUnitOutOfServiceTime = "8:00 AM";
                    newStartWorkMileage = tbxStartWorkDataStartMileage.Text.Trim();
                }
                else
                {
                    if (pnlStartWorkDataReadOnly.Visible)
                    {
                        if (tbxStartWorkDataUnitOutOfServiceDateReadOnly.Text.Trim() != "") newUnitOutOfServiceDate = DateTime.Parse(tbxStartWorkDataUnitOutOfServiceDateReadOnly.Text.Trim());
                        newUnitOutOfServiceTime = "8:00 AM";
                        newStartWorkMileage = tbxStartWorkDataStartMileageReadOnly.Text.Trim();
                    }
                }

                // ... Get complete work data
                DateTime? completeWorkDateTime = null; if (serviceInformationBasicInformationGatewayForEdit.GetCompleteWorkDateTime(serviceId).HasValue) completeWorkDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetCompleteWorkDateTime(serviceId);
                DateTime? newUnitBackInServiceDate = null;
                string newUnitBackInServiceTime = "";
                string newCompleteWorkMileage = "";
                string newCompleteWorkDetailDescription = "";
                bool newCompleteWorkDetailPreventable = false;
                decimal? newCompleteWorkDetailTMLabourHours = 0.0M;
                string newCompleteWorkDetailTPVInvoiceNumber = "";
                decimal? newCompleteWorkDetailTPVInvoiceAmout = 0.0M;

                if (pnlCompleteWorkData.Visible)
                {
                    if (tkrdpCompleteWorkDataUnitBackInServiceDate.SelectedDate.HasValue) newUnitBackInServiceDate = tkrdpCompleteWorkDataUnitBackInServiceDate.SelectedDate.Value;
                    newUnitBackInServiceTime = "8:00 AM";
                    newCompleteWorkMileage = tbxCompleteWorkDataCompleteMileage.Text.Trim();

                    // ... ... From team member
                    if (pnlTeamMemberAssigned.Visible)
                    {
                        if (tbxCompleteWorkDataDescription.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescription.Text.Trim();
                        newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventable.Checked;
                    }
                    newCompleteWorkDetailTMLabourHours = null; if (tbxCompleteWorkDataLabourHours.Text.Trim() != "") newCompleteWorkDetailTMLabourHours = decimal.Parse(tbxCompleteWorkDataLabourHours.Text.Trim());

                    // ... ... From Third party vendor
                    if (pnlThirdPartyVendorAssigned.Visible)
                    {
                        if (tbxCompleteWorkDataDescriptionThirdPartyVendor.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescriptionThirdPartyVendor.Text.Trim();
                        newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventableThirdPartyVendor.Checked;
                    }
                    newCompleteWorkDetailTPVInvoiceNumber = tbxCompleteWorkDataInvoiceNumberThirdPartyVendor.Text.Trim();
                    newCompleteWorkDetailTPVInvoiceAmout = null; if (tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text.Trim() != "") newCompleteWorkDetailTPVInvoiceAmout = decimal.Parse(tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text.Trim());
                }
                else
                {
                    if (pnlCompleteWorkDataReadOnly.Visible)
                    {
                        if (tbxCompleteWorkDataUnitBackInServiceDateReadOnly.Text.Trim() != "") newUnitBackInServiceDate = DateTime.Parse(tbxCompleteWorkDataUnitBackInServiceDateReadOnly.Text.Trim());
                        newUnitBackInServiceTime = "8:00 AM";
                        newCompleteWorkMileage = tbxCompleteWorkDataCompleteMileageReadOnly.Text.Trim();

                        // ... ... From team member
                        if (pnlTeamMemberAssignedReadOnly.Visible)
                        {
                            if (tbxCompleteWorkDataDescriptionReadOnly.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescriptionReadOnly.Text.Trim();
                            newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventableReadOnly.Checked;
                        }
                        newCompleteWorkDetailTMLabourHours = null; if (tbxCompleteWorkDataLabourHoursReadOnly.Text.Trim() != "") newCompleteWorkDetailTMLabourHours = decimal.Parse(tbxCompleteWorkDataLabourHoursReadOnly.Text.Trim());

                        // ... ... From Third party vendor
                        if (pnlThirdPartyVendorAssignedReadOnly.Visible)
                        {
                            if (tbxCompleteWorkDataDescriptionThirdPartyVendorReadOnly.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescriptionThirdPartyVendorReadOnly.Text.Trim();
                            newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventableThirdPartyVendorReadOnly.Checked;
                        }
                        newCompleteWorkDetailTPVInvoiceNumber = tbxCompleteWorkDataInvoiceNumberThirdPartyVendorReadOnly.Text.Trim();
                        newCompleteWorkDetailTPVInvoiceAmout = null; if (tbxCompleteWorkDataInvoiceAmountThirdPartyVendorReadOnly.Text.Trim() != "") newCompleteWorkDetailTPVInvoiceAmout = decimal.Parse(tbxCompleteWorkDataInvoiceAmountThirdPartyVendorReadOnly.Text.Trim());
                    }
                }

                // Update service data
                ServiceInformationBasicInformation serviceInformationBasicInformation = new ServiceInformationBasicInformation(serviceInformationTDS);
                int? libraryCategoriesId = null; if (serviceInformationBasicInformationGatewayForEdit.GetLibraryCategoriesId(int.Parse(hdfServiceId.Value)).HasValue) libraryCategoriesId = (int)serviceInformationBasicInformationGatewayForEdit.GetLibraryCategoriesId(int.Parse(hdfServiceId.Value));
                serviceInformationBasicInformation.Update(serviceId, serviceState, newMtoDto, newServiceDescription, newMileage, newAssignmentDateTime, newAssignmentDeadlineDate, newToTeamMember, newAssignTeamMemberID, newThirdPartyVendor, assignmentAcceptedDateTime, assignmentRejectedDateTime, newAssignmentRejectedReason, startWorkDateTime, newUnitOutOfServiceDate, newUnitOutOfServiceTime, newStartWorkMileage, completeWorkDateTime, newUnitBackInServiceDate, newUnitBackInServiceTime, newCompleteWorkMileage, newCompleteWorkDetailDescription, newCompleteWorkDetailPreventable, newCompleteWorkDetailTMLabourHours, newCompleteWorkDetailTPVInvoiceNumber, newCompleteWorkDetailTPVInvoiceAmout, associatedChecklistRuleState, libraryCategoriesId);

                // Store datasets
                Session["serviceInformationTDS"] = serviceInformationTDS;

                Session.Remove("libraryTDSForServices");

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";

                // Redirect
                string url = "";
                if (Request.QueryString["source_page"] == "services_navigator2.aspx" || Request.QueryString["source_page"] == "services_add_request.aspx")
                {
                    url = "./services_navigator2.aspx?source_page=services_edit.aspx&service_id=" + hdfServiceId.Value + GetNavigatorState() + "&update=yes";
                }

                if (Request.QueryString["source_page"] == "services_summary.aspx")
                {
                    string activeTab = hdfActiveTab.Value;
                    url = "./services_summary.aspx?source_page=services_edit.aspx&dashboard=" + hdfDashboard.Value + "&service_id=" + hdfServiceId.Value + "&active_tab=" + activeTab + GetNavigatorState() + "&update=yes";
                }

                Response.Redirect(url);
            }
        }
        private void Save2()
        {
            // Costs Gridview, if the gridview is edition mode
            if (grdCosts.EditIndex >= 0)
            {
                grdCosts.UpdateRow(grdCosts.EditIndex, true);
            }

            // Notes Gridview, if the gridview is edition mode
            if (grdNotes.EditIndex >= 0)
            {
                grdNotes.UpdateRow(grdNotes.EditIndex, true);
            }

            // Save cost and notes data
            GrdCostsAdd();
            GrdNotesAdd();

            // Save data
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int serviceId = Int32.Parse(hdfServiceId.Value);

            // Unmodified data
            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGatewayForEdit = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
            string serviceState = serviceInformationBasicInformationGatewayForEdit.GetServiceState(serviceId);
            string associatedChecklistRuleState = serviceInformationBasicInformationGatewayForEdit.GetAssociatedChecklistRuleState(serviceId);

            // ... Get basic service data
            bool newMtoDto = ckbxMtoDto.Checked;
            string newServiceDescription = tbxServiceDescription.Text.Trim();

            // ... Get general service data
            string newMileage = tbxGeneralMileage.Text.Trim();

            // ... Get assigned data
            DateTime? newAssignmentDateTime = null;
            DateTime? newAssignmentDeadlineDate = null;
            bool newToTeamMember = false;
            int? newAssignTeamMemberID = null;
            string newThirdPartyVendor = "";
            DateTime? assignmentAcceptedDateTime = null;
            string newAssignmentRejectedReason = "";
            DateTime? assignmentRejectedDateTime = null;

            if (pnlAssignmentData.Visible)
            {
                if (pnlAssignedToReadOnly.Visible)
                {
                    if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                    if (serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId).HasValue) newAssignmentDeadlineDate = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId);
                    newToTeamMember = serviceInformationBasicInformationGatewayForEdit.GetToTeamMember(serviceId);
                    if (newToTeamMember) newAssignTeamMemberID = (int)serviceInformationBasicInformationGatewayForEdit.GetAssignTeamMemberId(serviceId);
                    newThirdPartyVendor = serviceInformationBasicInformationGatewayForEdit.GetAssignedThirdPartyVendor(serviceId);
                }

                if (pnlAssignedTo.Visible)
                {
                    if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                    if (tkrdpAssignmentDataAssignedDeadlineDate.SelectedDate.HasValue) newAssignmentDeadlineDate = tkrdpAssignmentDataAssignedDeadlineDate.SelectedDate.Value;
                    newToTeamMember = rbtnAssignmentDataToTeamMember.Checked;
                    if (newToTeamMember) newAssignTeamMemberID = Int32.Parse(ddlAssignmentDataAssignToTeamMember.SelectedValue);
                    newThirdPartyVendor = tbxAssignmentDataAssignToThirdPartyVendor.Text.Trim();
                }

                if (serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId).HasValue) assignmentAcceptedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId);
                if (serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId).HasValue) assignmentRejectedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId);
                newAssignmentRejectedReason = tbxAssignmentDataRejectedReason.Text.Trim();
            }
            else
            {
                if (pnlAssignmentDataReadOnly.Visible)
                {
                    if (serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignmentDateTimeOriginal(serviceId);
                    if (serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId).HasValue) newAssignmentDeadlineDate = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAssignedDeadlineDate(serviceId);
                    newToTeamMember = serviceInformationBasicInformationGatewayForEdit.GetToTeamMember(serviceId);
                    if (newToTeamMember) newAssignTeamMemberID = (int)serviceInformationBasicInformationGatewayForEdit.GetAssignTeamMemberId(serviceId);
                    newThirdPartyVendor = serviceInformationBasicInformationGatewayForEdit.GetAssignedThirdPartyVendor(serviceId);
                    if (serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId).HasValue) assignmentAcceptedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetAcceptedDateTime(serviceId);
                    if (serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId).HasValue) assignmentRejectedDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetRejectedDateTime(serviceId);
                    newAssignmentRejectedReason = tbxAssignmentDataRejectedReasonReadOnly.Text.Trim();
                }
            }

            // ... Get start work data
            DateTime? startWorkDateTime = null; if (serviceInformationBasicInformationGatewayForEdit.GetStartWorkDateTime(serviceId).HasValue) startWorkDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetStartWorkDateTime(serviceId);
            DateTime? newUnitOutOfServiceDate = null;
            string newUnitOutOfServiceTime = "";
            string newStartWorkMileage = "";

            if (pnlStartWorkData.Visible)
            {
                if (tkrdpStartWorkDataUnitOutOfServiceDate.SelectedDate.HasValue) newUnitOutOfServiceDate = tkrdpStartWorkDataUnitOutOfServiceDate.SelectedDate.Value;
                newUnitOutOfServiceTime = "8:00 AM";
                newStartWorkMileage = tbxStartWorkDataStartMileage.Text.Trim();
            }
            else
            {
                if (pnlStartWorkDataReadOnly.Visible)
                {
                    newUnitOutOfServiceDate = serviceInformationBasicInformationGatewayForEdit.GetUnitOutOfServiceDate(serviceId);
                    newUnitOutOfServiceTime = serviceInformationBasicInformationGatewayForEdit.GetUnitOutOfServiceTime(serviceId);
                    newStartWorkMileage = serviceInformationBasicInformationGatewayForEdit.GetMileage(serviceId);
                }
            }

            // ... Get complete work data
            DateTime? completeWorkDateTime = null; if (serviceInformationBasicInformationGatewayForEdit.GetCompleteWorkDateTime(serviceId).HasValue) completeWorkDateTime = (DateTime)serviceInformationBasicInformationGatewayForEdit.GetCompleteWorkDateTime(serviceId);
            DateTime? newUnitBackInServiceDate = null; if (tkrdpCompleteWorkDataUnitBackInServiceDate.SelectedDate.HasValue) newUnitBackInServiceDate = tkrdpCompleteWorkDataUnitBackInServiceDate.SelectedDate.Value;
            string newUnitBackInServiceTime = "8:00 AM";
            string newCompleteWorkMileage = tbxCompleteWorkDataCompleteMileage.Text.Trim();
            string newCompleteWorkDetailDescription = "";
            bool newCompleteWorkDetailPreventable = false;

            // ... ... From team member
            if (pnlTeamMemberAssigned.Visible)
            {
                if (tbxCompleteWorkDataDescription.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescription.Text.Trim();
                newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventable.Checked;
            }
            decimal? newCompleteWorkDetailTMLabourHours = null; if (tbxCompleteWorkDataLabourHours.Text.Trim() != "") newCompleteWorkDetailTMLabourHours = decimal.Parse(tbxCompleteWorkDataLabourHours.Text.Trim());

            // ... ... From Third party vendor
            if (pnlThirdPartyVendorAssigned.Visible)
            {
                if (tbxCompleteWorkDataDescriptionThirdPartyVendor.Text.Trim() != "") newCompleteWorkDetailDescription = tbxCompleteWorkDataDescriptionThirdPartyVendor.Text.Trim();
                newCompleteWorkDetailPreventable = ckbxCompleteWorkDataPreventableThirdPartyVendor.Checked;
            }
            string newCompleteWorkDetailTPVInvoiceNumber = tbxCompleteWorkDataInvoiceNumberThirdPartyVendor.Text.Trim();
            decimal? newCompleteWorkDetailTPVInvoiceAmout = null; if (tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text.Trim() != "") newCompleteWorkDetailTPVInvoiceAmout = decimal.Parse(tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text.Trim());

            // Update service data
            ServiceInformationBasicInformation serviceInformationBasicInformation = new ServiceInformationBasicInformation(serviceInformationTDS);
            int? libraryCategoriesId = null; if (serviceInformationBasicInformationGatewayForEdit.GetLibraryCategoriesId(int.Parse(hdfServiceId.Value)).HasValue) libraryCategoriesId = (int)serviceInformationBasicInformationGatewayForEdit.GetLibraryCategoriesId(int.Parse(hdfServiceId.Value));
            serviceInformationBasicInformation.Update(serviceId, serviceState, newMtoDto, newServiceDescription, newMileage, newAssignmentDateTime, newAssignmentDeadlineDate, newToTeamMember, newAssignTeamMemberID, newThirdPartyVendor, assignmentAcceptedDateTime, assignmentRejectedDateTime, newAssignmentRejectedReason, startWorkDateTime, newUnitOutOfServiceDate, newUnitOutOfServiceTime, newStartWorkMileage, completeWorkDateTime, newUnitBackInServiceDate, newUnitBackInServiceTime, newCompleteWorkMileage, newCompleteWorkDetailDescription, newCompleteWorkDetailPreventable, newCompleteWorkDetailTMLabourHours, newCompleteWorkDetailTPVInvoiceNumber, newCompleteWorkDetailTPVInvoiceAmout, associatedChecklistRuleState, libraryCategoriesId);

            // Store datasets
            Session["serviceInformationTDS"] = serviceInformationTDS;

            ViewState["update"] = "no";
        }
        private void UpdateState()
        {
            int serviceId = Int32.Parse(hdfServiceId.Value);
            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);

            // General Data
            bool mtoDto = serviceInformationBasicInformationGateway.GetMtoDto(serviceId);
            string serviceDescription = serviceInformationBasicInformationGateway.GetServiceDescription(serviceId);
            string mileage = serviceInformationBasicInformationGateway.GetMileage(serviceId);
            int? libraryCategoriesId = null; if (serviceInformationBasicInformationGateway.GetLibraryCategoriesId(serviceId).HasValue) libraryCategoriesId = serviceInformationBasicInformationGateway.GetLibraryCategoriesId(serviceId).Value;

            // Initialize Data
            // ... Initialize Assigned Data with existent data
            DateTime? newAssignmentDateTime = null; if (serviceInformationBasicInformationGateway.GetAssignmentDateTime(serviceId).HasValue) newAssignmentDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAssignmentDateTime(serviceId);
            DateTime? newDeadlineDate = null; if (serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId).HasValue) newDeadlineDate = (DateTime)serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId);
            bool newToTeamMember = serviceInformationBasicInformationGateway.GetToTeamMember(serviceId);
            int? newAssignTeamMemberID = null; if(serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId).HasValue) newAssignTeamMemberID = (int)serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId);
            string newThirdPartyVendor = serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId);

            // ... Initialize Assigned Accepted Data with existent data
            DateTime? newAssignmentAcceptedDateTime = null; if (serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId).HasValue) newAssignmentAcceptedDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId);

            // ... Initialize Assigned Rejected Data with existent data
            DateTime? newAssignmentRejectedDateTime = null; if (serviceInformationBasicInformationGateway.GetRejectedDateTime(serviceId).HasValue) newAssignmentRejectedDateTime = (DateTime)serviceInformationBasicInformationGateway.GetRejectedDateTime(serviceId);
            string newAssignmnetRejectedReason = serviceInformationBasicInformationGateway.GetRejectedReason(serviceId);

            // ... Initialize Start Work Data with existent data
            DateTime? newStartWorkDateTime = null; if (serviceInformationBasicInformationGateway.GetStartWorkDateTime(serviceId).HasValue) newStartWorkDateTime = (DateTime)serviceInformationBasicInformationGateway.GetStartWorkDateTime(serviceId);
            DateTime? newUnitOutOfServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId).HasValue) newUnitOutOfServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId);
            string newUnitOutOfServiceTime = serviceInformationBasicInformationGateway.GetUnitOutOfServiceTime(serviceId);
            string newStartWorkMileage = serviceInformationBasicInformationGateway.GetStartWorkMileage(serviceId);

            // ... Initialize Complete Work Data with existent data
            DateTime? newCompleteWorkDateTime = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId).HasValue) newCompleteWorkDateTime = (DateTime)serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId);
            DateTime? newUnitBackInServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId).HasValue) newUnitBackInServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
            string newUnitBackInServiceTime = serviceInformationBasicInformationGateway.GetUnitBackInServiceTime(serviceId);
            string newCompleteWorkMileage = serviceInformationBasicInformationGateway.GetCompleteWorkMileage(serviceId);
            string newAssociatedChecklistRuleState = serviceInformationBasicInformationGateway.GetAssociatedChecklistRuleState(serviceId);

            // ... Get new values
            string serviceState = null;
            switch ((string)Request.QueryString["state"])
            {
                case "Assigned":
                    serviceState = "Assigned";
                    newAssignmentDateTime = DateTime.Now;
                    if (tkrdpPnlAssignDeadlineDate.SelectedDate.HasValue) newDeadlineDate = tkrdpPnlAssignDeadlineDate.SelectedDate.Value;
                    newToTeamMember = rbtnPnlAssignToTeamMember.Checked;
                    newAssignTeamMemberID = null; if (newToTeamMember) newAssignTeamMemberID = Int32.Parse(ddlPnlAssignAssignToTeamMember.SelectedValue);
                    newThirdPartyVendor = tbxPnlAssignAssignToThirdPartyVendor.Text.Trim();
                    break;

                case "Accepted":
                    serviceState = "Accepted";
                    newAssignmentAcceptedDateTime = DateTime.Now;
                    break;

                case "Rejected":
                    serviceState = "Rejected";
                    newAssignmentRejectedDateTime = DateTime.Now;
                    newAssignmnetRejectedReason = tbxPnlAssignmentRejectDataRejectedReason.Text.Trim();
                    break;

                case "StartWork":
                    serviceState = "In Progress";
                    newStartWorkDateTime = DateTime.Now;
                    newUnitOutOfServiceDate = null; if (tkrdpPnlStartWorkUnitOutOfServiceDate.SelectedDate.HasValue) newUnitOutOfServiceDate = tkrdpPnlStartWorkUnitOutOfServiceDate.SelectedDate.Value;
                    newUnitOutOfServiceTime = DateTime.Now.ToShortTimeString();
                    newStartWorkMileage = tbxPnlStartWorkStartMileage.Text.Trim();
                    break;

                case "CompleteWork":
                    serviceState = "Completed";
                    newCompleteWorkDateTime = DateTime.Now;
                    newUnitBackInServiceDate = null; if (tkrdpPnlCompleteWorkUnitBackInServiceDate.SelectedDate.HasValue) newUnitBackInServiceDate = tkrdpPnlCompleteWorkUnitBackInServiceDate.SelectedDate.Value;
                    newUnitBackInServiceTime = DateTime.Now.ToShortTimeString();
                    newCompleteWorkMileage = tbxPnlCompleteWorkCompleteMileage.Text.Trim();
                    newAssociatedChecklistRuleState = "Healthy";
                    break;
            }

            // Update service data
            ServiceInformationBasicInformation serviceInformationBasicInformation = new ServiceInformationBasicInformation(serviceInformationTDS);
            serviceInformationBasicInformation.Update(serviceId, serviceState, mtoDto, serviceDescription, mileage, newAssignmentDateTime, newDeadlineDate, newToTeamMember, newAssignTeamMemberID, newThirdPartyVendor, newAssignmentAcceptedDateTime, newAssignmentRejectedDateTime, newAssignmnetRejectedReason, newStartWorkDateTime, newUnitOutOfServiceDate, newUnitOutOfServiceTime, newStartWorkMileage, newCompleteWorkDateTime, newUnitBackInServiceDate, newUnitBackInServiceTime, newCompleteWorkMileage, "", false, null, "", null, newAssociatedChecklistRuleState, libraryCategoriesId);
        }