private void LoadDetailaDataCompleteWork(int serviceId, ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway)
        {
            // Load for CompleteWork Tab
            // ... pnlCompleteWork
            tbxCompleteWorkDataCompleteWorkDateTime.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId).ToString();

            if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId).HasValue)
            {
                DateTime backInServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
                tkrdpCompleteWorkDataUnitBackInServiceDate.SelectedDate = DateTime.Parse(backInServiceDate.Month.ToString() + "/" + backInServiceDate.Day.ToString() + "/" + backInServiceDate.Year.ToString());
            }

            tbxCompleteWorkDataCompleteMileage.Text = serviceInformationBasicInformationGateway.GetCompleteWorkMileage(serviceId);
            lblCompleteWorkDataMileageUnitOfMeasurement.Text = serviceInformationBasicInformationGateway.GetMileageUnitOfMeasurement(serviceId);
            lblCompleteWorkDataMileageUnitOfMeasurementReadOnly.Text = serviceInformationBasicInformationGateway.GetMileageUnitOfMeasurement(serviceId);

            // ... For team member
            tbxCompleteWorkDataDescription.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
            ckbxCompleteWorkDataPreventable.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
            tbxCompleteWorkDataLabourHours.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId).ToString();

            // ... For third party vendor
            tbxCompleteWorkDataDescriptionThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
            ckbxCompleteWorkDataPreventableThirdPartyVendor.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
            tbxCompleteWorkDataInvoiceNumberThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumber(serviceId);
            tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId).ToString();

            // ... PnlCompleteWorkReadOnly
            tbxCompleteWorkDataCompleteWorkDateTimeReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId).ToString();

            tbxCompleteWorkDataUnitBackInServiceDateReadOnly.Text = "";
            if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId).HasValue)
            {
                DateTime backInServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
                tbxCompleteWorkDataUnitBackInServiceDateReadOnly.Text = backInServiceDate.Month.ToString() + "/" + backInServiceDate.Day.ToString() + "/" + backInServiceDate.Year.ToString();
            }

            tbxCompleteWorkDataCompleteMileageReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkMileage(serviceId);

            // ... For team member
            tbxCompleteWorkDataDescriptionReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
            ckbxCompleteWorkDataPreventableReadOnly.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
            tbxCompleteWorkDataLabourHoursReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId).ToString();

            // ... For third party vendor
            tbxCompleteWorkDataDescriptionThirdPartyVendorReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
            ckbxCompleteWorkDataPreventableThirdPartyVendorReadOnly.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
            tbxCompleteWorkDataInvoiceNumberThirdPartyVendorReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumber(serviceId);
            tbxCompleteWorkDataInvoiceAmountThirdPartyVendorReadOnly.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId).ToString();
        }
        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);
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ServiceInformationTDS servicesInformationChanges = (ServiceInformationTDS)Data.GetChanges();

            if (servicesInformationChanges.BasicInformation.Rows.Count > 0)
            {
                ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(servicesInformationChanges);

                // Update services
                foreach (ServiceInformationTDS.BasicInformationRow basicInformationRow in (ServiceInformationTDS.BasicInformationDataTable)servicesInformationChanges.BasicInformation)
                {
                    // Unchanged values
                    int serviceId = basicInformationRow.ServiceID;
                    string number = serviceInformationBasicInformationGateway.GetServiceNumber(serviceId);
                    DateTime dateTime_ = serviceInformationBasicInformationGateway.GetDateTime_(serviceId);
                    int? unitId = null; if (serviceInformationBasicInformationGateway.GetUnitID(serviceId).HasValue) unitId = serviceInformationBasicInformationGateway.GetUnitID(serviceId);
                    string type = serviceInformationBasicInformationGateway.GetType(serviceId);
                    int ownerId = serviceInformationBasicInformationGateway.GetOwnerID(serviceId);

                    // Original values
                    bool originalMtoDto = serviceInformationBasicInformationGateway.GetMtoDtoOriginal(serviceId);
                    string originalDescription = serviceInformationBasicInformationGateway.GetServiceDescriptionOriginal(serviceId);
                    string originalState = serviceInformationBasicInformationGateway.GetServiceStateOriginal(serviceId);
                    DateTime? originalAssignDateTime = null; if (serviceInformationBasicInformationGateway.GetAssignmentDateTimeOriginal(serviceId).HasValue) originalAssignDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAssignmentDateTimeOriginal(serviceId);
                    DateTime? originalAssignDeadlineDate = null; if (serviceInformationBasicInformationGateway.GetAssignedDeadlineDateOriginal(serviceId).HasValue) originalAssignDeadlineDate = (DateTime)serviceInformationBasicInformationGateway.GetAssignedDeadlineDateOriginal(serviceId);
                    bool originalAssignTeamMember = serviceInformationBasicInformationGateway.GetToTeamMemberOriginal(serviceId);
                    int? originalAssignTeamMemberID = null; if (serviceInformationBasicInformationGateway.GetAssignTeamMemberIdOriginal(serviceId).HasValue) originalAssignTeamMemberID = (int)serviceInformationBasicInformationGateway.GetAssignTeamMemberIdOriginal(serviceId);
                    string originalAssignThirdPartyVendor = serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendorOriginal(serviceId);
                    DateTime? originalAcceptDateTime = null; if (serviceInformationBasicInformationGateway.GetAcceptedDateTimeOriginal(serviceId).HasValue) originalAcceptDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAcceptedDateTimeOriginal(serviceId);
                    DateTime? originalRejectDateTime = null; if (serviceInformationBasicInformationGateway.GetRejectedDateTimeOriginal(serviceId).HasValue) originalRejectDateTime = (DateTime)serviceInformationBasicInformationGateway.GetRejectedDateTimeOriginal(serviceId);
                    string originalRejectReason = serviceInformationBasicInformationGateway.GetRejectedReasonOriginal(serviceId);
                    DateTime? originalStartWorkDateTime = null; if (serviceInformationBasicInformationGateway.GetStartWorkDateTimeOriginal(serviceId).HasValue) originalStartWorkDateTime = (DateTime)serviceInformationBasicInformationGateway.GetStartWorkDateTimeOriginal(serviceId);
                    DateTime? originalStartWorkOutOfServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitOutOfServiceDateOriginal(serviceId).HasValue) originalStartWorkOutOfServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitOutOfServiceDateOriginal(serviceId);
                    string originalStartWorkOutOfServiceTime = serviceInformationBasicInformationGateway.GetUnitOutOfServiceTimeOriginal(serviceId);
                    DateTime? originalCompleteWorkDateTime = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDateTimeOriginal(serviceId).HasValue) originalCompleteWorkDateTime = (DateTime)serviceInformationBasicInformationGateway.GetCompleteWorkDateTimeOriginal(serviceId);
                    DateTime? originalCompleteWorkBackToServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDateOriginal(serviceId).HasValue) originalCompleteWorkBackToServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDateOriginal(serviceId);
                    string originalCompleteWorkBackToServiceTime = serviceInformationBasicInformationGateway.GetUnitBackInServiceTimeOriginal(serviceId);
                    string originalCompleteWorkDetailDescription = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescriptionOriginal(serviceId);
                    bool originalCompleteWorkDetailPreventable = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventableOriginal(serviceId);
                    decimal? originalCompleteWorkDetailTMLabourHours = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHoursOriginal(serviceId).HasValue) originalCompleteWorkDetailTMLabourHours = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHoursOriginal(serviceId);
                    decimal? originalCompleteWorkDetailTMCost = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMCostOriginal(serviceId).HasValue) originalCompleteWorkDetailTMCost = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMCostOriginal(serviceId);
                    string originalCompleteWorkDetailTPVInvoiceNumber = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumberOriginal(serviceId);
                    decimal? originalCompleteWorkDetailTPVInvoiceAmout = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmoutOriginal(serviceId).HasValue) originalCompleteWorkDetailTPVInvoiceAmout = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmoutOriginal(serviceId);
                    string originalNotes = serviceInformationBasicInformationGateway.GetNotesOriginal(serviceId);
                    int? originalRuleId = null; if (serviceInformationBasicInformationGateway.GetRuleIdOriginal(serviceId).HasValue) originalRuleId = (int)serviceInformationBasicInformationGateway.GetRuleIdOriginal(serviceId);
                    string originalMileage = serviceInformationBasicInformationGateway.GetMileageOriginal(serviceId);
                    string originalStartWorkMileage = serviceInformationBasicInformationGateway.GetStartWorkMileageOriginal(serviceId);
                    string originalCompleteWorkMileage = serviceInformationBasicInformationGateway.GetCompleteWorkMileageOriginal(serviceId);
                    bool originalDeleted = serviceInformationBasicInformationGateway.GetDeletedOriginal(serviceId);
                    int? originalLibraryCategoriesId = null; if (serviceInformationBasicInformationGateway.GetLibraryCategoriesIdOriginal(serviceId).HasValue) originalLibraryCategoriesId = serviceInformationBasicInformationGateway.GetLibraryCategoriesIdOriginal(serviceId).Value;

                    // New variables
                    bool newMtoDto = serviceInformationBasicInformationGateway.GetMtoDto(serviceId);
                    string newDescription = serviceInformationBasicInformationGateway.GetServiceDescription(serviceId);
                    string newState = serviceInformationBasicInformationGateway.GetServiceState(serviceId);
                    DateTime? newAssignDateTime = null; if(serviceInformationBasicInformationGateway.GetAssignmentDateTime(serviceId).HasValue) newAssignDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAssignmentDateTime(serviceId);
                    DateTime? newAssignDeadlineDate = null; if (serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId).HasValue) newAssignDeadlineDate = (DateTime)serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId);
                    bool newAssignTeamMember = serviceInformationBasicInformationGateway.GetToTeamMember(serviceId);
                    int? newAssignTeamMemberId = null; if (serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId).HasValue) newAssignTeamMemberId = (int)serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId);
                    string newAssignThirdPartyVendor = serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId);
                    DateTime? newAcceptDateTime = null; if(serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId).HasValue) newAcceptDateTime = (DateTime)serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId);
                    DateTime? newRejectDateTime = null; if(serviceInformationBasicInformationGateway.GetRejectedDateTime(serviceId).HasValue) newRejectDateTime = (DateTime)serviceInformationBasicInformationGateway.GetRejectedDateTime(serviceId);
                    string newRejectReason = serviceInformationBasicInformationGateway.GetRejectedReason(serviceId);
                    DateTime? newStartWorkDateTime = null;  if( serviceInformationBasicInformationGateway.GetStartWorkDateTime(serviceId).HasValue) newStartWorkDateTime = (DateTime) serviceInformationBasicInformationGateway.GetStartWorkDateTime(serviceId);
                    DateTime? newStartWorkOutOfServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId).HasValue) newStartWorkOutOfServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId);
                    string newStartWorkOutOfServiceTime = serviceInformationBasicInformationGateway.GetUnitOutOfServiceTime(serviceId);
                    DateTime? newCompleteWorkDateTime = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId).HasValue) newCompleteWorkDateTime = (DateTime)serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId);
                    DateTime? newCompleteWorkBackToServiceDate = null; if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId).HasValue) newCompleteWorkBackToServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
                    string newCompleteWorkBackToServiceTime = serviceInformationBasicInformationGateway.GetUnitBackInServiceTime(serviceId);
                    string newCompleteWorkDetailDescription = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
                    bool newCompleteWorkDetailPreventable = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
                    decimal? newCompleteWorkDetailTMLabourHours = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId).HasValue) newCompleteWorkDetailTMLabourHours = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId);
                    decimal? newCompleteWorkDetailTMCost = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMCost(serviceId).HasValue) newCompleteWorkDetailTMCost = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMCost(serviceId);
                    string newCompleteWorkDetailTPVInvoiceNumber = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumber(serviceId);
                    decimal? newCompleteWorkDetailTPVInvoiceAmout = null; if (serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId).HasValue) newCompleteWorkDetailTPVInvoiceAmout = (decimal)serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId);
                    string newNotes = serviceInformationBasicInformationGateway.GetNotes(serviceId);
                    int? newRuleId = null; if (serviceInformationBasicInformationGateway.GetRuleId(serviceId).HasValue) newRuleId = (int)serviceInformationBasicInformationGateway.GetRuleId(serviceId);
                    string newMileage = serviceInformationBasicInformationGateway.GetMileage(serviceId);
                    string newStartWorkMileage = serviceInformationBasicInformationGateway.GetStartWorkMileage(serviceId);
                    string newCompleteWorkMileage = serviceInformationBasicInformationGateway.GetCompleteWorkMileage(serviceId);
                    int? newLibraryCategoriesId = null; if (serviceInformationBasicInformationGateway.GetLibraryCategoriesId(serviceId).HasValue) newLibraryCategoriesId = serviceInformationBasicInformationGateway.GetLibraryCategoriesId(serviceId).Value;
                    bool newDeleted = serviceInformationBasicInformationGateway.GetDeleted(serviceId);

                    // ... Update
                    UpdateService(serviceId, number, dateTime_, originalMtoDto, originalDescription, unitId, type, originalState, ownerId, originalAssignDateTime, originalAssignDeadlineDate, originalAssignTeamMember, originalAssignTeamMemberID, originalAssignThirdPartyVendor, originalAcceptDateTime, originalRejectDateTime, originalRejectReason, originalStartWorkDateTime, originalStartWorkOutOfServiceDate, originalStartWorkOutOfServiceTime, originalCompleteWorkDateTime, originalCompleteWorkBackToServiceDate, originalCompleteWorkBackToServiceTime, originalCompleteWorkDetailDescription, originalCompleteWorkDetailPreventable, originalCompleteWorkDetailTMLabourHours, originalCompleteWorkDetailTMCost, originalCompleteWorkDetailTPVInvoiceNumber, originalCompleteWorkDetailTPVInvoiceAmout, originalDeleted, companyId, originalNotes, originalRuleId, originalMileage, originalStartWorkMileage, originalCompleteWorkMileage, originalLibraryCategoriesId, number, dateTime_, newMtoDto, newDescription, unitId, type, newState, ownerId, newAssignDateTime, newAssignDeadlineDate, newAssignTeamMember, newAssignTeamMemberId, newAssignThirdPartyVendor, newAcceptDateTime, newRejectDateTime, newRejectReason, newStartWorkDateTime, newStartWorkOutOfServiceDate, newStartWorkOutOfServiceTime, newCompleteWorkDateTime, newCompleteWorkBackToServiceDate, newCompleteWorkBackToServiceTime, newCompleteWorkDetailDescription, newCompleteWorkDetailPreventable, newCompleteWorkDetailTMLabourHours, newCompleteWorkDetailTMCost, newCompleteWorkDetailTPVInvoiceNumber, newCompleteWorkDetailTPVInvoiceAmout, newDeleted, companyId, newNotes, newRuleId, newMileage, newStartWorkMileage, newCompleteWorkMileage, newLibraryCategoriesId);

                    // Update checklist
                    if (type == "Checklist")
                    {
                        // ... Original values
                        DateTime? originalAssociatedChecklistLastService = serviceInformationBasicInformationGateway.GetAssociatedChecklistLastServiceOriginal(serviceId);
                        DateTime? originalAssociatedChecklistNextDue = serviceInformationBasicInformationGateway.GetAssociatedChecklistNextDueOriginal(serviceId);
                        bool originalAssociatedChecklistDone = serviceInformationBasicInformationGateway.GetAssociatedChecklistDoneOriginal(serviceId);
                        bool originalAssociatedChecklistDeleted = serviceInformationBasicInformationGateway.GetAssociatedChecklistDeletedOriginal(serviceId);
                        int originalAssociatedChecklistCompanyId = serviceInformationBasicInformationGateway.GetAssociatedChecklistCompanyIdOriginal(serviceId);
                        string originalAssociatedChecklistRuleState = serviceInformationBasicInformationGateway.GetAssociatedChecklistRuleStateOriginal(serviceId);

                        // ... New values
                        DateTime? newAssociatedChecklistLastService = serviceInformationBasicInformationGateway.GetAssociatedChecklistLastService(serviceId);
                        DateTime? newAssociatedChecklistNextDue = serviceInformationBasicInformationGateway.GetAssociatedChecklistNextDue(serviceId);
                        bool newAssociatedChecklistDone = serviceInformationBasicInformationGateway.GetAssociatedChecklistDone(serviceId);
                        bool newAssociatedChecklistDeleted = serviceInformationBasicInformationGateway.GetAssociatedChecklistDeleted(serviceId);
                        int newAssociatedChecklistCompanyId = serviceInformationBasicInformationGateway.GetAssociatedChecklistCompanyId(serviceId);
                        string newAssociatedChecklistRuleState = serviceInformationBasicInformationGateway.GetAssociatedChecklistRuleState(serviceId);

                        // ... Update
                        Checklist checklist = new Checklist();
                        checklist.UpdateDirect((int)unitId, (int)originalRuleId, originalAssociatedChecklistLastService, originalAssociatedChecklistNextDue, originalAssociatedChecklistDone, originalAssociatedChecklistRuleState, originalAssociatedChecklistDeleted, originalAssociatedChecklistCompanyId, (int)unitId, (int)originalRuleId, newAssociatedChecklistLastService, newAssociatedChecklistNextDue, newAssociatedChecklistDone, newAssociatedChecklistRuleState, originalAssociatedChecklistDeleted, originalAssociatedChecklistCompanyId);
                    }
                }
            }
        }
        private void LoadDetailedData(int serviceId)
        {
            ServiceInformationBasicInformationGateway serviceInformationBasicInformationGateway = new ServiceInformationBasicInformationGateway(serviceInformationTDS);
            if (serviceInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load for General Tab
                tbxGeneralCreatedBy.Text = serviceInformationBasicInformationGateway.GetCreatedBy(serviceId);
                tbxGeneralMileage.Text = serviceInformationBasicInformationGateway.GetMileage(serviceId);
                lblGeneralMileageUnitOfMeasurement.Text = serviceInformationBasicInformationGateway.GetMileageUnitOfMeasurement(serviceId);

                // Load for Assginment Tab
                tbxAssignmentDataAssignmentDateTime.Text = serviceInformationBasicInformationGateway.GetAssignmentDateTime(serviceId).ToString();

                tbxAssignmentDataAssignedDeadlineDate.Text = "";
                if (serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId).HasValue)
                {
                    DateTime deadlineDate = (DateTime)serviceInformationBasicInformationGateway.GetAssignedDeadlineDate(serviceId);
                    tbxAssignmentDataAssignedDeadlineDate.Text = deadlineDate.Month.ToString() + "/" + deadlineDate.Day.ToString() + "/" + deadlineDate.Year.ToString();
                }

                if ((serviceInformationBasicInformationGateway.GetToTeamMember(serviceId)) && (serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId)) == "")
                {
                    // ... For team member
                    rbtnAssignmentDataToTeamMember.Checked = true;
                    if (serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId).HasValue)
                    {
                        int teamMemberId = (int)serviceInformationBasicInformationGateway.GetAssignTeamMemberId(serviceId);
                        EmployeeGateway employeeGateway = new EmployeeGateway();
                        employeeGateway.LoadByEmployeeId(teamMemberId);

                        tbxAssigmentDataToTeamMemberName.Text = employeeGateway.GetLastName(teamMemberId) + " " + employeeGateway.GetFirstName(teamMemberId);
                    }

                    // ... For third party vendor
                    rbtnAssignmentDataToThirdPartyVendor.Checked = false;
                }
                else
                {
                    if ((!serviceInformationBasicInformationGateway.GetToTeamMember(serviceId)) && (serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId)) != "")
                    {
                        // ... For team member
                        rbtnAssignmentDataToTeamMember.Checked = false;

                        // ... For third party vendor
                        rbtnAssignmentDataToThirdPartyVendor.Checked = true;
                        tbxAssignmentDataAssignToThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetAssignedThirdPartyVendor(serviceId);
                    }
                    else
                    {
                        rbtnAssignmentDataToTeamMember.Checked = false;
                        rbtnAssignmentDataToThirdPartyVendor.Checked = false;
                    }
                }

                tbxAssignmentDataAcceptedDateTime.Text = serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId).ToString();

                DateTime? acceptedDateTime = serviceInformationBasicInformationGateway.GetAcceptedDateTime(serviceId);
                if (acceptedDateTime.HasValue) tbxAssignmentDataAcceptedDateTime.Text = acceptedDateTime.ToString();

                DateTime? rejectedDateTime = serviceInformationBasicInformationGateway.GetRejectedDateTime(serviceId);
                if (rejectedDateTime.HasValue) tbxAssignmentDataRejectedDateTime.Text = rejectedDateTime.ToString();
                tbxAssignmentDataRejectedReason.Text = serviceInformationBasicInformationGateway.GetRejectedReason(serviceId);

                // Load for StartWork Tab
                tbxStartWorkDataWorkStartDateTime.Text = serviceInformationBasicInformationGateway.GetStartWorkDateTime(serviceId).ToString();

                tbxStartWorkDataUnitOutOfServiceDate.Text = "";
                if (serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId).HasValue)
                {
                    DateTime outOfServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitOutOfServiceDate(serviceId);
                    tbxStartWorkDataUnitOutOfServiceDate.Text = outOfServiceDate.Month.ToString() + "/" + outOfServiceDate.Day.ToString() + "/" + outOfServiceDate.Year.ToString();
                }

                tbxStartWorkDataStartMileage.Text = serviceInformationBasicInformationGateway.GetStartWorkMileage(serviceId);
                lblStartWorkDataMileageUnitOfMeasurement.Text = serviceInformationBasicInformationGateway.GetMileageUnitOfMeasurement(serviceId);

                // Load for Complete Work Tab
                tbxCompleteWorkDataCompleteWorkDateTime.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDateTime(serviceId).ToString();

                tbxCompleteWorkDataUnitBackInServiceDate.Text = "";
                if (serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId).HasValue)
                {
                    DateTime backInServiceDate = (DateTime)serviceInformationBasicInformationGateway.GetUnitBackInServiceDate(serviceId);
                    tbxCompleteWorkDataUnitBackInServiceDate.Text = backInServiceDate.Month.ToString() + "/" + backInServiceDate.Day.ToString() + "/" + backInServiceDate.Year.ToString();
                }

                tbxCompleteWorkDataCompleteMileage.Text = serviceInformationBasicInformationGateway.GetCompleteWorkMileage(serviceId);
                lblCompleteWorkDataMileageUnitOfMeasurement.Text = serviceInformationBasicInformationGateway.GetMileageUnitOfMeasurement(serviceId);

                // ... For team member
                tbxCompleteWorkDataDescription.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
                ckbxCompleteWorkDataPreventable.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
                tbxCompleteWorkDataLabourHours.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTMLabourHours(serviceId).ToString();

                // ... For third party vendor
                tbxCompleteWorkDataDescriptionThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailDescription(serviceId);
                ckbxCompleteWorkDataPreventableThirdPartyVendor.Checked = serviceInformationBasicInformationGateway.GetCompleteWorkDetailPreventable(serviceId);
                tbxCompleteWorkDataInvoiceNumberThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceNumber(serviceId);
                tbxCompleteWorkDataInvoiceAmountThirdPartyVendor.Text = serviceInformationBasicInformationGateway.GetCompleteWorkDetailTPVInvoiceAmout(serviceId).ToString();
            }
        }