protected void btnDelete_Click(object sender, EventArgs e)
        {
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
            string workType = hdfWorkType.Value.Trim();

            PostPageChanges();

            ArrayList assetIdArrayList = GetAssetIdArrayList();

            if (assetIdArrayList.Count > 0)
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl();
                flatSectionJl.LoadByAssetIdArrayList(assetIdArrayList, 1, currentProjectId, workType, companyId);

                if (flatSectionJl.Table.Rows.Count > 0)
                {
                    // Delete store dataset
                    Session.Remove("flatSectionJlTDS");

                    // Store datasets
                    Session["jlNavigatorTDS"] = jlNavigatorTDS;
                    Session["flatSectionJlTDS"] = flatSectionJl.Data;

                    // Redirect
                    string url = "./jl_delete.aspx?source_page=jl_navigator2.aspx&client_id=" + hdfCurrentClientId.Value + "&project_id=" + hdfCurrentProjectId.Value + "&work_type=" + hdfWorkType.Value + GetNavigatorState();
                    Response.Redirect(url);
                }
            }
            else
            {
                RestoreNavigatorState();
                cvSelection.IsValid = false;
            }
        }
        private void FLLateralsSave(string lateralId, bool requiresRoboticPrep, DateTime? equiresRoboticPrepIssueCompleted, bool holdClientIssue, bool holdLFSIssue, bool dyeTestReq, DateTime? dyeTestComplete)
        {
            int workIdJl = Int32.Parse(hdfWorkIdJl.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);
            flatSectionJlTDSForFLL = new FlatSectionJlTDS();

            FlatSectionJlGateway flatSectionJlGateway = new FlatSectionJlGateway(flatSectionJlTDSForFLL);
            flatSectionJlGateway.LoadAllByWorkId(workIdJl, companyId);

            string latId = lateralId.Substring(3, lateralId.Length - 3);

            if (flatSectionJlGateway.Table.Rows.Count > 0)
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDSForFLL);

                flatSectionJl.UpdateAllLateralsFromFLL(latId, requiresRoboticPrep, equiresRoboticPrepIssueCompleted, holdClientIssue, holdLFSIssue, dyeTestReq, dyeTestComplete);
            }

            Session["flatSectionJlTDSForFLL"] = flatSectionJlTDSForFLL;
            flatSectionJlTDSForFLL.AcceptChanges();
        }
        private void UpdateDatabase()
        {
            DB.Open();
            DB.BeginTransaction();
            try
            {
                int companyId = Int32.Parse(hdfCompanyId.Value);

                // Update Comments and History
                FlatSectionJlCommentDetails flatSectionJlCommentDetails = new FlatSectionJlCommentDetails(flatSectionJlTDS);
                flatSectionJlCommentDetails.Save(companyId);

                FlatSectionJlHistoryDetails flatSectionJlHistoryDetails = new FlatSectionJlHistoryDetails(flatSectionJlTDS);
                flatSectionJlHistoryDetails.Save(companyId);

                // Update FlatSectionJl for new Comments
                int workId = Int32.Parse(hdfWorkId.Value.Trim());
                string workType = "Junction Lining Lateral";

                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
                flatSectionJl.UpdateCommentsHistoryForSummaryEdit(workId, workType, companyId);

                JlNavigator jlNavigator = new JlNavigator(jlNavigatorTDS);
                jlNavigator.UpdateComments(workId, workType, companyId);

                Session["flatSectionJlTDS"] = flatSectionJlTDS;
                Session["jlNavigatorTDS"] = jlNavigatorTDS;

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void WorkUpdate()
        {
            // Get general variables
            int projectId = Int32.Parse(hdfCurrentProject.Value.Trim());
            int companyId = Convert.ToInt32(Session["companyID"]);
            FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
            DataView dataViewFlatSectionJl = new DataView(flatSectionJlTDS.FlatSectionJl);
            dataViewFlatSectionJl.RowFilter = "(Selected = 1) AND (Deleted = 0)";

            foreach (DataRowView row in dataViewFlatSectionJl)
            {
                int workId = Int32.Parse(row["WorkID"].ToString());
                int assetId = Int32.Parse(row["AssetID"].ToString());
                string workType = "Junction Lining Lateral";

                // Get original variables
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(workId, companyId);

                string originalWorkType = workGateway.GetWorkTypeOriginal(workId);
                int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId);
                string originalComment = workGateway.GetCommentsOriginal(workId);
                string originalHistory = workGateway.GetHistoryOriginal(workId);

                // Get new comment
                WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                workCommentsGateway.LoadByWorkIdWorkType(workId, companyId, "Junction Lining Lateral");
                WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                string newComments = workComments.GetAllComments(workId, companyId, workCommentsGateway.Table.Rows.Count, "\n");

                // Get new history
                WorkHistoryGateway workHistoryGateway = new WorkHistoryGateway();
                workHistoryGateway.LoadByWorkIdWorkType(workId, companyId, "Junction Lining Lateral");
                WorkHistory workHistory = new WorkHistory(workHistoryGateway.Data);
                string newHistory = workHistory.GetAllHistory(workId, companyId, workHistoryGateway.Table.Rows.Count, "\n");

                Work work = new Work(null);
                work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComments, newHistory);

                flatSectionJl.UpdateCommentsHistoryForSummaryEdit(workId, workType, companyId);
            }
        }
        private void Save()
        {
            FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);

            DataView dataViewFlatSectionJl = new DataView(flatSectionJlTDS.FlatSectionJl);
            dataViewFlatSectionJl.RowFilter = "(Selected = 1) AND (Deleted = 0)";

            string summary = "";
            bool existsDataModificated = false;
            string fieldToUpdate = ddlFieldToUpdate.SelectedValue;

            foreach (DataRowView row in dataViewFlatSectionJl)
            {
                if (IsValidLateralToUpdate(fieldToUpdate, row))
                {
                    int workId = Int32.Parse(row["WorkID"].ToString());

                    // Date fields
                    if ((fieldToUpdate == "VideoInspection") || (fieldToUpdate == "PipeLocated") || (fieldToUpdate == "ServicesLocated") || (fieldToUpdate == "CoInstalled")
                        || (fieldToUpdate == "BackfilledConcrete") || (fieldToUpdate == "BackfilledSoil") || (fieldToUpdate == "Grouted") || (fieldToUpdate == "Cored")
                        || (fieldToUpdate == "Prepped") || (fieldToUpdate == "PreVideo") || (fieldToUpdate == "Measured") || (fieldToUpdate == "NoticeDelivered")
                        || (fieldToUpdate == "InProcess") || (fieldToUpdate == "InStock") || (fieldToUpdate == "Delivered") || (fieldToUpdate == "LinerInstalled")
                        || (fieldToUpdate == "FinalVideo") || (fieldToUpdate == "CoCutDown") || (fieldToUpdate == "FinalRestoration")
                        || (fieldToUpdate == "DigRequiredPriorToLiningCompleted") || (fieldToUpdate == "DigRequiredAfterLiningCompleted") || (fieldToUpdate == "HoldClientIssueResolved")
                        || (fieldToUpdate == "HoldLFSIssueResolved") || (fieldToUpdate == "LateralRequiresRoboticPrepCompleted")
                       )
                    {
                        // ... Update row
                        flatSectionJl.UpdateDateField(workId, fieldToUpdate, tkrdpValue.SelectedDate);
                        existsDataModificated = true;
                    }
                    else
                    {
                        // String fields
                        if (fieldToUpdate == "CoPitLocation")
                        {
                            // ... Update row
                            flatSectionJl.UpdateStringField(workId, fieldToUpdate, ddlCoPitLocationValue.SelectedValue);
                            existsDataModificated = true;
                        }

                        // String fields
                        if (fieldToUpdate == "PrepType")
                        {
                            // ... Update row
                            flatSectionJl.UpdateStringField(workId, fieldToUpdate, ddlPrepType.SelectedValue);
                            existsDataModificated = true;
                        }

                        // String fields
                        if (fieldToUpdate == "LinerType")
                        {
                            // ... Update row
                            flatSectionJl.UpdateStringField(workId, fieldToUpdate, ddlLinerType.SelectedValue);
                            existsDataModificated = true;
                        }

                        // String fields
                        if (fieldToUpdate == "ContractYear")
                        {
                            // ... Update row
                            flatSectionJl.UpdateStringField(workId, fieldToUpdate, tbxValue.Text);
                            existsDataModificated = true;
                        }

                        // Boolean fields
                        if ((fieldToUpdate == "CoRequired") || (fieldToUpdate == "OutOfScope") || (fieldToUpdate == "DigRequiredPriorToLining") || (fieldToUpdate == "DigRequiredAfterLining")
                            || (fieldToUpdate == "HoldClientIssue") || (fieldToUpdate == "HoldLFSIssue") || (fieldToUpdate == "LateralRequiresRoboticPrep"))
                        {
                            // ... Update row
                            flatSectionJl.UpdateBooleanField(workId, fieldToUpdate, cbxValue.Checked);
                            existsDataModificated = true;
                        }

                        // Special field - Comment
                        if (fieldToUpdate == "Comment")
                        {
                            // ... Update row
                            AddComments(workId, tbxComments.Text);
                            ViewState["UpdateComments"] = true;
                            existsDataModificated = true;
                        }
                    }
                }
                else
                {
                    string[] flowOderId = row["LateralDescription"].ToString().Split('-');

                    if (summary.Trim().Length == 0)
                    {
                        string reason = "";

                        switch (fieldToUpdate)
                        {
                            case "DigRequiredPriorToLining":
                                reason = "Dig Required Prior To Lining Completed has value.";
                                break;

                            case "DigRequiredPriorToLiningCompleted":
                                reason = "Dig Required Prior To Lining is not checked.";
                                break;

                            case "DigRequiredAfterLining":
                                reason = "Dig Required After Lining Completed has value.";
                                break;

                            case "DigRequiredAfterLiningCompleted":
                                reason = "Dig Required After Lining is not checked.";
                                break;

                            case "HoldClientIssue":
                                reason = "Hold - Client Issue Resolved has value.";
                                break;

                            case "HoldClientIssueResolved":
                                reason = "Hold - Client Issue is not checked.";
                                break;

                            case "HoldLFSIssue":
                                reason = "Hold - LFS Issue Resolved has value.";
                                break;

                            case "HoldLFSIssueResolved":
                                reason = "Hold - LFS Issue is not checked.";
                                break;

                            case "LateralRequiresRoboticPrep":
                                reason = "Requires Robotic Prep Completed has value.";
                                break;

                            case "LateralRequiresRoboticPrepCompleted":
                                reason = "Requires Robotic Prep is not checked.";
                                break;
                        }

                        summary = "The following laterals were not updated because " + reason + "\n\n";

                        summary = summary + "\t - " + flowOderId[1] + "-JL-" + flowOderId[2] + "\n";
                    }
                    else
                    {
                        summary = summary + "\t - " + flowOderId[1] + "-JL-" + flowOderId[2] + "\n";
                    }
                }
            }

            if (summary.Trim().Length == 0)
            {
                summary = "All the laterals were updated\n\n";
            }

            tbxSummary.Text = summary;

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

            if (existsDataModificated)
            {
                // Update database
                UpdateDatabase();
            }
        }
        private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProject.Value.Trim());
            int companyId = Int32.Parse(Session["companyID"].ToString());

            // Load project
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // Get location
            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            // Save
            DB.Open();
            DB.BeginTransaction();
            try
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);

                if (Convert.ToBoolean(ViewState["UpdateComments"]))
                {
                    // Update Comments
                    FlatSectionJlCommentDetails flatSectionJlCommentDetails = new FlatSectionJlCommentDetails(flatSectionJlTDS);
                    flatSectionJlCommentDetails.Save(companyId);

                    // Update works
                    WorkUpdate();
                }
                else
                {
                    flatSectionJl.UpdateDirect(countryId, provinceId, countyId, cityId, projectId, companyId);
                }

                DB.CommitTransaction();

                flatSectionJlTDS.AcceptChanges();

                // Store datasets
                Session["flatSectionJlTDS"] = flatSectionJlTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        // STEP1 - BEGIN
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP1 - BEGIN - AUXILIAR EVENTS
        //
        protected void ddlFieldToUpdate_SelectedIndexChanged(object sender, EventArgs e)
        {
            // Date fields
            if ((ddlFieldToUpdate.SelectedValue == "VideoInspection") || (ddlFieldToUpdate.SelectedValue == "PipeLocated") || (ddlFieldToUpdate.SelectedValue == "ServicesLocated") || (ddlFieldToUpdate.SelectedValue == "CoInstalled")
                || (ddlFieldToUpdate.SelectedValue == "BackfilledConcrete") || (ddlFieldToUpdate.SelectedValue == "BackfilledSoil") || (ddlFieldToUpdate.SelectedValue == "Grouted") || (ddlFieldToUpdate.SelectedValue == "Cored")
                || (ddlFieldToUpdate.SelectedValue == "Prepped") || (ddlFieldToUpdate.SelectedValue == "PreVideo") || (ddlFieldToUpdate.SelectedValue == "Measured") || (ddlFieldToUpdate.SelectedValue == "NoticeDelivered")
                || (ddlFieldToUpdate.SelectedValue == "InProcess") || (ddlFieldToUpdate.SelectedValue == "InStock") || (ddlFieldToUpdate.SelectedValue == "Delivered") || (ddlFieldToUpdate.SelectedValue == "LinerInstalled")
                || (ddlFieldToUpdate.SelectedValue == "FinalVideo") || (ddlFieldToUpdate.SelectedValue == "CoCutDown") || (ddlFieldToUpdate.SelectedValue == "FinalRestoration")
                || (ddlFieldToUpdate.SelectedValue == "DigRequiredPriorToLiningCompleted") || (ddlFieldToUpdate.SelectedValue == "DigRequiredAfterLiningCompleted") || (ddlFieldToUpdate.SelectedValue == "HoldClientIssueResolved")
                || (ddlFieldToUpdate.SelectedValue == "HoldLFSIssueResolved") || (ddlFieldToUpdate.SelectedValue == "LateralRequiresRoboticPrepCompleted")
               )
            {
                tkrdpValue.Visible = true;
                cbxValue.Visible = false;
                ddlCoPitLocationValue.Visible = false;
                tbxComments.Visible = false;
                ddlPrepType.Visible = false;
                ddlLinerType.Visible = false;
                tbxValue.Visible = false;
            }
            else
            {
                tbxValue.Visible = false;

                // String fields
                if (ddlFieldToUpdate.SelectedValue == "CoPitLocation")
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = false;
                    ddlCoPitLocationValue.Visible = true;
                    ddlPrepType.Visible = false;
                    ddlLinerType.Visible = false;
                    tbxComments.Visible = false;
                }

                // String fields
                if (ddlFieldToUpdate.SelectedValue == "PrepType")
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = false;
                    ddlCoPitLocationValue.Visible = false;
                    ddlPrepType.Visible = true;
                    ddlLinerType.Visible = false;
                    tbxComments.Visible = false;
                }

                // String fields
                if (ddlFieldToUpdate.SelectedValue == "LinerType")
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = false;
                    ddlCoPitLocationValue.Visible = false;
                    ddlPrepType.Visible = false;
                    ddlLinerType.Visible = true;
                    tbxComments.Visible = false;
                }

                // String fields
                if (ddlFieldToUpdate.SelectedValue == "ContractYear")
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = false;
                    ddlCoPitLocationValue.Visible = false;
                    ddlPrepType.Visible = false;
                    ddlLinerType.Visible = false;
                    tbxComments.Visible = false;
                    tbxValue.Visible = true;
                }

                // Boolean fields
                if ((ddlFieldToUpdate.SelectedValue == "CoRequired") || (ddlFieldToUpdate.SelectedValue == "OutOfScope") || (ddlFieldToUpdate.SelectedValue == "DigRequiredPriorToLining") || (ddlFieldToUpdate.SelectedValue == "DigRequiredAfterLining") || (ddlFieldToUpdate.SelectedValue == "HoldClientIssue")
                    || (ddlFieldToUpdate.SelectedValue == "HoldLFSIssue") || (ddlFieldToUpdate.SelectedValue == "LateralRequiresRoboticPrep"))
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = true;
                    ddlCoPitLocationValue.Visible = false;
                    ddlPrepType.Visible = false;
                    ddlLinerType.Visible = false;
                    tbxComments.Visible = false;
                }

                // Special fields - Comment
                if (ddlFieldToUpdate.SelectedValue == "Comment")
                {
                    tkrdpValue.Visible = false;
                    cbxValue.Visible = false;
                    ddlCoPitLocationValue.Visible = false;
                    ddlPrepType.Visible = false;
                    ddlLinerType.Visible = false;
                    tbxComments.Visible = true;

                    FlatSectionJlCommentDetailsGateway flatSectionJlCommentDetailsGateway = new FlatSectionJlCommentDetailsGateway(flatSectionJlTDS);
                    flatSectionJlCommentDetailsGateway.ClearBeforeFill = false;
                    FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
                    DataView dataViewFlatSectionJl = new DataView(flatSectionJlTDS.FlatSectionJl);
                    dataViewFlatSectionJl.RowFilter = "(Selected = 1) AND (Deleted = 0)";

                    foreach (DataRowView row in dataViewFlatSectionJl)
                    {
                        int workId = Int32.Parse(row["WorkID"].ToString());
                        int companyId = Int32.Parse(Session["companyID"].ToString());

                        // Get comments
                        flatSectionJlCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, "Junction Lining Lateral");
                    }
                }
            }
        }
        private void Save2()
        {
            Page.Validate();

            if (Page.IsValid)
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);

                // Update flatSectionJlTDS
                foreach (GridViewRow row in grdvJl.Rows)
                {
                    // ... Get standard fields
                    int workId = int.Parse(((HiddenField)row.FindControl("hdfWorkID")).Value);
                    int assetId = int.Parse(((HiddenField)row.FindControl("hdfAssetID")).Value);
                    int section_ = int.Parse(((HiddenField)row.FindControl("hdfSection_")).Value);
                    int companyId = int.Parse(hdfCompanyId.Value);
                    string address = ((TextBox)row.FindControl("tbxAddress")).Text.Trim();
                    DateTime? pipeLocated = null; if (((RadDatePicker)row.FindControl("tkrdpPipeLocated")).SelectedDate.HasValue) pipeLocated = ((RadDatePicker)row.FindControl("tkrdpPipeLocated")).SelectedDate.Value;
                    DateTime? servicesLocated = null; if (((RadDatePicker)row.FindControl("tkrdpServicesLocated")).SelectedDate.HasValue) servicesLocated = ((RadDatePicker)row.FindControl("tkrdpServicesLocated")).SelectedDate.Value;
                    DateTime? coInstalled = null; if (((RadDatePicker)row.FindControl("tkrdpCoInstalled")).SelectedDate.HasValue) coInstalled = ((RadDatePicker)row.FindControl("tkrdpCoInstalled")).SelectedDate;
                    DateTime? backfilledConcrete = null; if (((RadDatePicker)row.FindControl("tkrdpBackfilledConcrete")).SelectedDate.HasValue) backfilledConcrete = ((RadDatePicker)row.FindControl("tkrdpBackfilledConcrete")).SelectedDate.Value;
                    DateTime? backfilledSoil = null; if (((RadDatePicker)row.FindControl("tkrdpBackfilledSoil")).SelectedDate.HasValue) backfilledSoil = ((RadDatePicker)row.FindControl("tkrdpBackfilledSoil")).SelectedDate.Value;
                    DateTime? grouted = null; if (((RadDatePicker)row.FindControl("tkrdpGrouted")).SelectedDate.HasValue) grouted = ((RadDatePicker)row.FindControl("tkrdpGrouted")).SelectedDate.Value;
                    DateTime? cored = null; if (((RadDatePicker)row.FindControl("tkrdpCored")).SelectedDate.HasValue) cored = ((RadDatePicker)row.FindControl("tkrdpCored")).SelectedDate.Value;
                    DateTime? prepped = null; if (((RadDatePicker)row.FindControl("tkrdpPrepped")).SelectedDate.HasValue) prepped = ((RadDatePicker)row.FindControl("tkrdpPrepped")).SelectedDate;
                    DateTime? measured = null; if (((RadDatePicker)row.FindControl("tkrdpMeasured")).SelectedDate.HasValue) measured = ((RadDatePicker)row.FindControl("tkrdpMeasured")).SelectedDate;
                    string linerSize = ""; if (((TextBox)row.FindControl("tbxLinerSize")).Text.Trim() != "") linerSize = ((TextBox)row.FindControl("tbxLinerSize")).Text.Trim();
                    DateTime? inProcess = null; if (((RadDatePicker)row.FindControl("tkrdpInProcess")).SelectedDate.HasValue) inProcess = ((RadDatePicker)row.FindControl("tkrdpInProcess")).SelectedDate.Value;
                    DateTime? inStock = null; if (((RadDatePicker)row.FindControl("tkrdpInStock")).SelectedDate.HasValue) inStock = ((RadDatePicker)row.FindControl("tkrdpInStock")).SelectedDate.Value;
                    DateTime? tkrdplivered = null; if (((RadDatePicker)row.FindControl("tkrdpDelivered")).SelectedDate.HasValue) tkrdplivered = ((RadDatePicker)row.FindControl("tkrdpDelivered")).SelectedDate.Value;
                    DateTime? preVideo = null; if (((RadDatePicker)row.FindControl("tkrdpPreVideo")).SelectedDate.HasValue) preVideo = ((RadDatePicker)row.FindControl("tkrdpPreVideo")).SelectedDate;
                    DateTime? linerInstalled = null; if (((RadDatePicker)row.FindControl("tkrdpLinerInstalled")).SelectedDate.HasValue) linerInstalled = ((RadDatePicker)row.FindControl("tkrdpLinerInstalled")).SelectedDate.Value;
                    DateTime? finalVideo = null; if (((RadDatePicker)row.FindControl("tkrdpFinalVideo")).SelectedDate.HasValue) finalVideo = ((RadDatePicker)row.FindControl("tkrdpFinalVideo")).SelectedDate.Value;
                    string distanceFromUSMH = ""; if (((TextBox)row.FindControl("tbxDistanceFromUSMH")).Text.Trim() != "") distanceFromUSMH = ((TextBox)row.FindControl("tbxDistanceFromUSMH")).Text.Trim();
                    string comments = ""; if (((TextBox)row.FindControl("tbxComments")).Text.Trim() != "") comments = ((TextBox)row.FindControl("tbxComments")).Text.Trim();
                    string history = ""; if (((TextBox)row.FindControl("tbxHistory")).Text.Trim() != "") history = ((TextBox)row.FindControl("tbxHistory")).Text.Trim();
                    decimal? cost = null; if (((TextBox)row.FindControl("tbxCost")).Text.Trim() != "") cost = decimal.Parse(((TextBox)row.FindControl("tbxCost")).Text.Trim());
                    bool deleted = false;
                    bool selected = true;
                    DateTime? videoInspection = null; if (((RadDatePicker)row.FindControl("tkrdpVideoInspection")).SelectedDate.HasValue) videoInspection = ((RadDatePicker)row.FindControl("tkrdpVideoInspection")).SelectedDate.Value;
                    string coPitLocation = ""; coPitLocation = ((DropDownList)row.FindControl("ddlCoPitLocation")).SelectedValue;
                    DateTime? coCutDown = null; if (((RadDatePicker)row.FindControl("tkrdpCoCutDown")).SelectedDate.HasValue) coCutDown = ((RadDatePicker)row.FindControl("tkrdpCoCutDown")).SelectedDate.Value;
                    DateTime? finalRestoration = null; if (((RadDatePicker)row.FindControl("tkrdpFinalRestoration")).SelectedDate.HasValue) finalRestoration = ((RadDatePicker)row.FindControl("tkrdpFinalRestoration")).SelectedDate.Value;
                    string clientLateralId = ""; if (((TextBox)row.FindControl("tbxClientLateralId")).Text.Trim() != "") clientLateralId = ((TextBox)row.FindControl("tbxClientLateralId")).Text.Trim();
                    string videoLengthToPropertyLine = ""; if (((TextBox)row.FindControl("tbxVideoLengthToPropertyLine")).Text.Trim() != "") videoLengthToPropertyLine = ((TextBox)row.FindControl("tbxVideoLengthToPropertyLine")).Text.Trim();
                    DateTime? noticeDelivered = null; if (((RadDatePicker)row.FindControl("tkrdpNoticeDelivered")).SelectedDate.HasValue) noticeDelivered = ((RadDatePicker)row.FindControl("tkrdpNoticeDelivered")).SelectedDate.Value;
                    string hamiltonInspectionNumber = ""; if (((TextBox)row.FindControl("tbxHamiltonInspectionNumber")).Text.Trim() != "") hamiltonInspectionNumber = ((TextBox)row.FindControl("tbxHamiltonInspectionNumber")).Text.Trim();
                    string flange = ""; flange = ((DropDownList)row.FindControl("ddlFlange")).SelectedValue;
                    string gasket = ""; gasket = ((DropDownList)row.FindControl("ddlGasket")).SelectedValue;
                    string connectionType = ""; connectionType = ((DropDownList)row.FindControl("ddlConnectionType")).SelectedValue;
                    string distanceFromDSMH = ""; if (((TextBox)row.FindControl("tbxDistanceFromDSMH")).Text.Trim() != "") distanceFromDSMH = ((TextBox)row.FindControl("tbxDistanceFromDSMH")).Text.Trim();
                    string depthOfLocated = ""; if (((TextBox)row.FindControl("tbxDepthOfLocated")).Text.Trim() != "") depthOfLocated = ((TextBox)row.FindControl("tbxDepthOfLocated")).Text.Trim();
                    bool digRequiredPriorToLining = ((CheckBox)row.FindControl("cbxDigRequiredPriorToLining")).Checked;
                    DateTime? digRequiredPriorToLiningCompleted = null; if (((RadDatePicker)row.FindControl("tkrdpDigRequiredPriorToLiningCompleted")).SelectedDate.HasValue) digRequiredPriorToLiningCompleted = ((RadDatePicker)row.FindControl("tkrdpDigRequiredPriorToLiningCompleted")).SelectedDate.Value;
                    bool digRequiredAfterLining = ((CheckBox)row.FindControl("cbxDigRequiredAfterLining")).Checked;
                    DateTime? digRequiredAfterLiningCompleted = null; if (((RadDatePicker)row.FindControl("tkrdpDigRequiredAfterLiningCompleted")).SelectedDate.HasValue) digRequiredAfterLiningCompleted = ((RadDatePicker)row.FindControl("tkrdpDigRequiredAfterLiningCompleted")).SelectedDate.Value;
                    bool outOfScope = ((CheckBox)row.FindControl("cbxOutOfScope")).Checked;
                    bool holdClientIssue = ((CheckBox)row.FindControl("cbxHoldClientIssue")).Checked;
                    DateTime? holdClientIssueResolved = null; if (((RadDatePicker)row.FindControl("tkrdpHoldClientIssueResolved")).SelectedDate.HasValue) holdClientIssueResolved = ((RadDatePicker)row.FindControl("tkrdpHoldClientIssueResolved")).SelectedDate.Value;
                    bool holdLFSIssue = ((CheckBox)row.FindControl("cbxHoldLFSIssue")).Checked;
                    DateTime? holdLFSIssueResolved = null; if (((RadDatePicker)row.FindControl("tkrdpHoldLFSIssueResolved")).SelectedDate.HasValue) holdLFSIssueResolved = ((RadDatePicker)row.FindControl("tkrdpHoldLFSIssueResolved")).SelectedDate.Value;
                    bool requiresRoboticPrep = ((CheckBox)row.FindControl("cbxRequiresRoboticPrep")).Checked;
                    DateTime? requiresRoboticPrepCompleted = null; if (((RadDatePicker)row.FindControl("tkrdpRequiresRoboticPrepCompleted")).SelectedDate.HasValue) requiresRoboticPrepCompleted = ((RadDatePicker)row.FindControl("tkrdpRequiresRoboticPrepCompleted")).SelectedDate.Value;
                    string linerType = ""; linerType = ((DropDownList)row.FindControl("ddlLinerType")).SelectedValue;
                    string prepType = ""; prepType = ((DropDownList)row.FindControl("ddlPrepType")).SelectedValue;
                    bool dyeTestReq = ((CheckBox)row.FindControl("ckbxDyeTestReq")).Checked;
                    DateTime? DyeTestComplete = null; if (((RadDatePicker)row.FindControl("tkrdpDyeTestComplete")).SelectedDate.HasValue) DyeTestComplete = ((RadDatePicker)row.FindControl("tkrdpDyeTestComplete")).SelectedDate.Value;
                    bool coRequired = false; if (prepType == "CO Req") coRequired = true;
                    bool pitRequired = false; if (prepType == "Pit Req") pitRequired = true;
                    bool liningThruCo = true;
                    bool postContractDigRequired = true;
                    string contractYear = ""; if (((TextBox)row.FindControl("tbxContractYear")).Text.Trim() != "") contractYear = ((TextBox)row.FindControl("tbxContractYear")).Text.Trim();

                    // ... Update row
                    flatSectionJl.Update(workId, assetId, section_, companyId, address, pipeLocated, servicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, tkrdplivered, preVideo, linerInstalled, finalVideo, distanceFromUSMH, distanceFromDSMH,  cost, deleted, selected, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, clientLateralId, videoLengthToPropertyLine, liningThruCo, noticeDelivered, hamiltonInspectionNumber, flange, gasket, connectionType, depthOfLocated, digRequiredPriorToLining, digRequiredPriorToLiningCompleted, digRequiredAfterLining, digRequiredAfterLiningCompleted, outOfScope, holdClientIssue, holdClientIssueResolved, holdLFSIssue, holdLFSIssueResolved, requiresRoboticPrep, requiresRoboticPrepCompleted, linerType, prepType, dyeTestReq, DyeTestComplete, contractYear);
                }

                // Store datasets
                Session["flatSectionJlTDS"] = flatSectionJlTDS;
            }
        }
        private void UpdateDatabase()
        {
            // Get ids
            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value);

            // Delete
            DB.Open();
            DB.BeginTransaction();
            try
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
                flatSectionJl.DeleteDirect(companyId);

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void Delete()
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Delete jliners
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);

                // ... Delete in flatSectionJlinerTDS
                foreach (FlatSectionJlTDS.FlatSectionJlRow flatSectionJlRow in (FlatSectionJlTDS.FlatSectionJlDataTable)flatSectionJl.Table)
                {
                    if ((flatSectionJlRow.Selected) && (!flatSectionJlRow.Deleted))
                    {
                        flatSectionJl.Delete(flatSectionJlRow.WorkID);
                    }
                }

                // ... Update assets
                string workType = hdfWorkType.Value.Trim();
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());

                // Update databse
                UpdateDatabase();

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

                // Redirect
                string url = "";
                if (Request.QueryString["source_page"] == "jl_navigator2.aspx")
                {
                    url = "./jl_navigator2.aspx?source_page=jl_delete.aspx&client_id=" + hdfCurrentClientId.Value + "&project_id=" + hdfCurrentProjectId.Value + "&work_type=" + hdfWorkType.Value + GetNavigatorState() + "&update=yes";
                }

                if (Request.QueryString["source_page"] == "flat_section_jl_summary.aspx")
                {
                    url = "./flat_section_jl_summary.aspx?source_page=jl_delete.aspx&client_id=" + hdfCurrentClientId.Value + "&project_id=" + hdfCurrentProjectId.Value + "&work_type=" + hdfWorkType.Value + GetNavigatorState() + "&update=yes";
                }
                Response.Redirect(url);
            }
        }
        private int Update()
        {
            FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);
            int jlSelected = 0;

            // Update flatSectionJlTDS
            foreach (GridViewRow row in grdvJl.Rows)
            {
                int workId = Int32.Parse(((HiddenField)row.FindControl("hdfWorkID")).Value.ToString().Trim());
                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;

                flatSectionJl.UpdateSelected(workId, selected);

                if (selected) jlSelected++;
            }

            // Save jliners selection
            flatSectionJlTDS.AcceptChanges();

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

            return jlSelected;
        }