private void LoadWorkData(int workId, int assetId)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            if (workId != 0)
            {
                ManholeRehabilitationWorkDetailsGateway manholeRehabilitationWorkDetailsGateway = new ManholeRehabilitationWorkDetailsGateway(manholeRehabilitationTDS);
                if (manholeRehabilitationWorkDetailsGateway.Table.Rows.Count > 0)
                {
                    if (manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId).HasValue)
                    {
                        DateTime preppedDate = (DateTime)manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                        tkrdpRehabilitationPreppedDate.SelectedDate = DateTime.Parse(preppedDate.Month.ToString() + "/" + preppedDate.Day.ToString() + "/" + preppedDate.Year.ToString());
                    }

                    if (manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId).HasValue)
                    {
                        DateTime sprayedDate = (DateTime)manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);
                        tkrdpRehabilitationSprayedDate.SelectedDate = DateTime.Parse(sprayedDate.Month.ToString() + "/" + sprayedDate.Day.ToString() + "/" + sprayedDate.Year.ToString());
                    }

                    if (manholeRehabilitationWorkDetailsGateway.GetDate(workId).HasValue)
                    {
                        //Load saved batch
                        int batchId = (manholeRehabilitationWorkDetailsGateway.GetBatchID(workId));
                        ddlRehabilitationBatchDate.SelectedValue = batchId.ToString();
                        hdfExistBatchId.Value = "True";
                        hdfBatchId.Value = batchId.ToString();
                    }
                    else
                    {
                        ddlRehabilitationBatchDate.SelectedValue = "0";
                        hdfExistBatchId.Value = "False";
                    }

                    // Show Comments
                    tbxCommentsDataComments.Text = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                    // ... ... Store datasets
                    Session["manholeRehabilitationTDS"] = manholeRehabilitationTDS;
                }
            }

            // Load last batch
            MrBatchVerificationGateway mrBatchVerificationGateway = new MrBatchVerificationGateway();
            mrBatchVerificationGateway.LoadAll(companyId);
            if (mrBatchVerificationGateway.Table.Rows.Count > 0)
            {
                WorkManholeRehabilitationBatchGateway workManholeRehabilitationBatchGateway = new WorkManholeRehabilitationBatchGateway();
                hdfBatchId.Value = workManholeRehabilitationBatchGateway.GetLastId(companyId).ToString();
                int batchId = Int32.Parse(hdfBatchId.Value);

                mrBatchVerificationGateway.LoadByBatchId(batchId, companyId);
                DateTime batchDate = mrBatchVerificationGateway.GetDate(batchId);
                tbxLastRehabilitationBatchDate.Text = batchDate.Month.ToString() + "/" + batchDate.Day.ToString() + "/" + batchDate.Year.ToString();
                lblBatchDateRequired.Visible = false;

                // ... ... Store datasets
                Session["manholeRehabilitationTDS"] = manholeRehabilitationTDS;
            }
            else
            {
                lblBatchDateRequired.Visible = true;
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="inProject">inProject</param>
        /// <returns>WorkID</returns>
        public int Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int assetId, int companyId, bool inProject)
        {
            ManholeRehabilitationTDS manholeRehabilitationChanges = (ManholeRehabilitationTDS)Data.GetChanges();
            int workId = 0;

            if (manholeRehabilitationChanges.WorkDetails.Rows.Count > 0)
            {
                ManholeRehabilitationWorkDetailsGateway manholeRehabilitationWorkDetailsGateway = new ManholeRehabilitationWorkDetailsGateway(manholeRehabilitationChanges);

                // Update manhole rehabilitation
                foreach (ManholeRehabilitationTDS.WorkDetailsRow row in (ManholeRehabilitationTDS.WorkDetailsDataTable)manholeRehabilitationChanges.WorkDetails)
                {
                    // Unchanged values
                    workId = row.WorkID;

                    WorkManholeRehabilitationGateway workManholeRehabilitationGateway = new WorkManholeRehabilitationGateway();
                    workManholeRehabilitationGateway.LoadByWorkId(workId, companyId);

                    if (workManholeRehabilitationGateway.Table.Rows.Count > 0)
                    {
                        // Update Information
                        // Original values
                        // ... work values
                        DateTime? originalPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDateOriginal(workId);
                        DateTime? originalSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDateOriginal(workId);

                        // ... Comments
                        string originalComments = manholeRehabilitationWorkDetailsGateway.GetCommentsOriginal(workId);

                        // New variables
                        DateTime? newPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                        DateTime? newSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);

                        // comments
                        string newComments = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                        // Update work
                        UpdateWork(countryId, provinceId, countyId, cityId, projectId, assetId, originalPreppedDate, originalSprayedDate, row.BatchID, originalComments, false, companyId, newPreppedDate, newSprayedDate, row.BatchID, newComments, false);
                    }
                    else
                    {
                        // Loading workId
                        WorkGateway workGateway = new WorkGateway();
                        workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Manhole Rehabilitation", companyId);

                        if (workGateway.Table.Rows.Count == 0)
                        {
                            // New variables
                            DateTime? newPreppedDate = manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                            DateTime? newSprayedDate = manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);
                            int? newBatchId = manholeRehabilitationWorkDetailsGateway.GetBatchID(workId);
                            string newComments = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                            // InsertWork
                            Work work = new Work();

                            int? libraryCategories = null;
                            string history = "";

                            int newWorkId = work.InsertDirect(projectId, assetId, "Manhole Rehabilitation", libraryCategories, false, companyId, newComments, history);

                            // ... Insert manhole rehabilitation work
                            WorkManholeRehabilitation workManholeRehabilitation = new WorkManholeRehabilitation();
                            workManholeRehabilitation.InsertDirect(newWorkId, newPreppedDate, newSprayedDate, newBatchId, false, companyId);

                            workId = newWorkId;
                        }
                    }
                }
            }

            return workId;
        }
        private void LoadWorkData(int workId, int assetId)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            if (workId != 0)
            {
                ManholeRehabilitationWorkDetailsGateway manholeRehabilitationWorkDetailsGateway = new ManholeRehabilitationWorkDetailsGateway(manholeRehabilitationTDS);
                if (manholeRehabilitationWorkDetailsGateway.Table.Rows.Count > 0)
                {
                    tbxRehabilitationPreppedDate.Text = "";
                    if (manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId).HasValue)
                    {
                        DateTime preppedDate = (DateTime)manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId);
                        tbxRehabilitationPreppedDate.Text = preppedDate.Month.ToString() + "/" + preppedDate.Day.ToString() + "/" + preppedDate.Year.ToString();
                    }

                    tbxRehabilitationSprayedDate.Text = "";
                    if (manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId).HasValue)
                    {
                        DateTime sprayedDate = (DateTime)manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId);
                        tbxRehabilitationSprayedDate.Text = sprayedDate.Month.ToString() + "/" + sprayedDate.Day.ToString() + "/" + sprayedDate.Year.ToString();
                    }

                    tbxRehabilitationBatchDate.Text = "";
                    if (manholeRehabilitationWorkDetailsGateway.GetDate(workId).HasValue)
                    {
                        try
                        {
                            DateTime batchDate = (DateTime)manholeRehabilitationWorkDetailsGateway.GetDate(workId);
                            tbxRehabilitationBatchDate.Text = batchDate.Month.ToString() + "/" + batchDate.Day.ToString() + "/" + batchDate.Year.ToString();
                            hdfBatchId.Value = manholeRehabilitationWorkDetailsGateway.GetBatchID(workId).ToString();
                        }
                        catch
                        {
                        }
                    }

                    // Show Comments
                    tbxCommentsDataComments.Text = manholeRehabilitationWorkDetailsGateway.GetComments(workId);

                    // ... ... Store datasets
                    Session["manholeRehabilitationTDS"] = manholeRehabilitationTDS;
                }
            }
            else
            {
                // Load last batch
                MrBatchVerificationGateway mrBatchVerificationGateway = new MrBatchVerificationGateway();
                mrBatchVerificationGateway.LoadAll(companyId);
                if (mrBatchVerificationGateway.Table.Rows.Count > 0)
                {
                    WorkManholeRehabilitationBatchGateway workManholeRehabilitationBatchGateway = new WorkManholeRehabilitationBatchGateway();
                    hdfBatchId.Value = workManholeRehabilitationBatchGateway.GetLastId(companyId).ToString();
                    int batchId = Int32.Parse(hdfBatchId.Value);

                    mrBatchVerificationGateway.LoadByBatchId(batchId, companyId);
                    DateTime batchDate = mrBatchVerificationGateway.GetDate(batchId);
                    tbxRehabilitationBatchDate.Text = batchDate.Month.ToString() + "/" + batchDate.Day.ToString() + "/" + batchDate.Year.ToString();

                    // ... ... Store datasets
                    Session["manholeRehabilitationTDS"] = manholeRehabilitationTDS;
                }
            }
        }