/// <summary>
        /// Save a section
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <returns>section_assetId</returns>
        private int SaveSection(DataMigrationTDS.JlDataMigrationRow row, int projectId, Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId)
        {
            string street = ""; if (!row.IsStreetNull()) street = row.Street;
            string subArea = ""; if (!row.IsSubAreaNull()) subArea = row.SubArea;
            string usmh = ""; if (!row.IsUSMHNull()) usmh = row.USMH;
            string dsmh = ""; if (!row.IsDSMHNull()) dsmh = row.DSMH;
            string usmhAddress = ""; if (!row.IsUSMHMNNull()) usmhAddress = row.USMHMN;
            string dsmhAddress = ""; if (!row.IsDSMHMNNull()) dsmhAddress = row.DSMHMN;
            string mapLength = ""; if (!row.IsScaledLengthNull()) mapLength = row.ScaledLength;
            string actualLength = ""; if (!row.IsActualLengthNull()) actualLength = row.ActualLength;
            string mapSize = ""; if (!row.IsSize_Null()) mapSize = row.Size_;
            string confirmedSize = ""; if (!row.IsConfirmedSizeNull()) confirmedSize = row.ConfirmedSize;
            string usmhDepth = ""; if (!row.IsUSMHDepthNull()) usmhDepth = row.USMHDepth;
            string dsmhDepth = ""; if (!row.IsDSMHDepthNull()) dsmhDepth = row.DSMHDepth;
            string steelTapeThruPipe = ""; if (!row.IsSteelTapeThruPipeNull()) steelTapeThruPipe = row.SteelTapeThruPipe;
            string usmhMouth12 = ""; if (!row.IsUSMHAtMouth1200Null()) usmhMouth12 = row.USMHAtMouth1200;
            string usmhMouth1 = ""; if (!row.IsUSMHAtMouth100Null()) usmhMouth12 = row.USMHAtMouth100;
            string usmhMouth2 = ""; if (!row.IsUSMHAtMouth200Null()) usmhMouth12 = row.USMHAtMouth200;
            string usmhMouth3 = ""; if (!row.IsUSMHAtMouth300Null()) usmhMouth12 = row.USMHAtMouth300;
            string usmhMouth4 = ""; if (!row.IsUSMHAtMouth400Null()) usmhMouth12 = row.USMHAtMouth400;
            string usmhMouth5 = ""; if (!row.IsUSMHAtMouth500Null()) usmhMouth12 = row.USMHAtMouth500;
            string dsmhMouth12 = ""; if (!row.IsDSMHAtMouth1200Null()) dsmhMouth12 = row.DSMHAtMouth1200;
            string dsmhMouth1 = ""; if (!row.IsDSMHAtMouth100Null()) dsmhMouth12 = row.DSMHAtMouth100;
            string dsmhMouth2 = ""; if (!row.IsDSMHAtMouth200Null()) dsmhMouth12 = row.DSMHAtMouth200;
            string dsmhMouth3 = ""; if (!row.IsDSMHAtMouth300Null()) dsmhMouth12 = row.DSMHAtMouth300;
            string dsmhMouth4 = ""; if (!row.IsDSMHAtMouth400Null()) dsmhMouth12 = row.DSMHAtMouth400;
            string dsmhMouth5 = ""; if (!row.IsDSMHAtMouth500Null()) dsmhMouth12 = row.DSMHAtMouth500;
            string thickness = ""; if (!row.IsThicknessNull()) thickness = row.Thickness;

            // insert usmh (if not exists)
            int? usmh_assetId = null;
            if (usmh != "")
            {
                LfsAssetSewerMH lfsAssetSewerUsmh = new LfsAssetSewerMH(null);
                usmh_assetId = lfsAssetSewerUsmh.InsertDirect(countryId, provinceId, countyId, cityId, usmh, "", "", usmhAddress, false, companyId, "", "", null, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", null, "", "", null);
            }

            // insert dsmh (if not exists)
            int? dsmh_assetId = null;
            if (dsmh != "")
            {
                LfsAssetSewerMH lfsAssetSewerDsmh = new LfsAssetSewerMH(null);
                dsmh_assetId = lfsAssetSewerDsmh.InsertDirect(countryId, provinceId, countyId, cityId, dsmh, "", "", dsmhAddress, false, companyId, "", "", null, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", null, "", "", null);
            }

            // insert section
            LfsAssetSewerSection lfsAssetSewerSection = new LfsAssetSewerSection(null);
            int section_assetId = lfsAssetSewerSection.InsertDirect(countryId, provinceId, countyId, cityId, row.OriginalSectionID, street, usmh_assetId, dsmh_assetId, mapSize, confirmedSize, mapLength, actualLength, null, null, "", usmhDepth, dsmhDepth, usmhAddress, dsmhAddress, steelTapeThruPipe, usmhMouth12, usmhMouth1, usmhMouth2, usmhMouth3, usmhMouth4, usmhMouth5, dsmhMouth12, dsmhMouth1, dsmhMouth2, dsmhMouth3, dsmhMouth4, dsmhMouth5, false, companyId, subArea, thickness, -1, "", DateTime.Now);

            return section_assetId;
        }
 /// <summary>
 /// InitData. 
 /// </summary>
 protected override void InitData()
 {
     _data = new DataMigrationTDS();
 }
        private bool StepSectionsNext()
        {
            string fName = null;
            HttpPostedFile postedFile = htmlInputFileSections.PostedFile;

            if ((postedFile != null) && (postedFile.ContentLength > 0))
            {
                //--- Post file
                byte[] buffer = new byte[postedFile.ContentLength];
                postedFile.InputStream.Read(buffer, 0, postedFile.ContentLength);

                //--- Save posted file
                string physicalApplicationPath = Request.PhysicalApplicationPath;
                if (Request.PhysicalApplicationPath.Substring(Request.PhysicalApplicationPath.Length - 1, 1) != "\\")
                {
                    physicalApplicationPath += "\\";
                }
                fName = physicalApplicationPath + "export\\" + Path.GetFileName(postedFile.FileName);
                postedFile.SaveAs(fName);

                //--- Process bulk upload
                string bulkUploadResultMessage;

                if (!ProcessBulkUpload(fName, out bulkUploadResultMessage))
                {
                    lblResultsSections.Text = bulkUploadResultMessage;
                    File.Delete(fName);
                    return false;
                }
                else
                {
                    File.Delete(fName);

                    // create dataset
                    DataMigrationTDS dataSet = new DataMigrationTDS();
                    dataSet.JlDataMigration.Merge(dataMigration, true);

                    Session["dataMigration"] = dataMigration;

                    return true;
                }
            }
            else
            {
                lblResultsSections.Text = "Please select a file";
                return false;
            }
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP2 - SUMMARY
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP2 - SUMMARY - AUXILIAR METHODS
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP2 - SUMMARY - METHODS
        //
        private void StepSummaryIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Summary";

            // Initialize summary
            DataMigrationTDS dataSet = new DataMigrationTDS();
            dataSet.JlDataMigration.Merge(dataMigration, true);
            JlDataMigration model = new JlDataMigration(dataSet);

            tbxSummary.Text = model.GetSectionsSummary("");
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP1 - PROJECTS
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP1 - PROJECTS - METHODS
        //
        private void StepProjectsIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please select a Microsoft Excel file of migration project";

            //--- Initialize
            DataMigrationTDS dataSet = new DataMigrationTDS();
            dataSet.DataMigrationProject.Merge(dataMigrationProject, true);
            DataMigrationProject model = new DataMigrationProject(dataSet);
            model.Table.Rows.Clear();
            dataMigrationProject = dataSet.DataMigrationProject;
            Session["dataMigrationProject"] = dataSet.DataMigrationProject;
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP1 - SECTIONS
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP1 - SECTIONS - METHODS
        //
        private void StepSectionsIn()
        {
            // Set instruction
            Label instruction = (Label)this.Master.FindControl("lblInstruction");
            instruction.Text = "Please select a Microsoft Excel file of migration section";

            //--- Initialize
            DataMigrationTDS dataSet = new DataMigrationTDS();
            dataSet.JlDataMigration.Merge(dataMigration, true);
            JlDataMigration model = new JlDataMigration(dataSet);
            model.Table.Rows.Clear();
            dataMigration = dataSet.JlDataMigration;
            Session["dataMigration"] = dataSet.JlDataMigration;
        }
        private bool ProcessBulkUpload(string fName, out string bulkUploadResultMessage)
        {
            bool bulkUploadProccessed = true;
            bulkUploadResultMessage = "";

            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();

            AppSettingsReader appSettingReader = new AppSettingsReader();
            string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES;IMEX=1';Data Source=" + fName + ";";

            OleDbConnection connection = new OleDbConnection(excelConnectionString);
            OleDbCommand command = null;
            OleDbDataReader dataReader = null;

            try
            {
                try
                {
                    connection.Open();
                    command = new OleDbCommand("select * from [sections]", connection);
                    dataReader = command.ExecuteReader();
                    dataReader.Close();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    bulkUploadResultMessage = "You did not define the 'sections' data range.  Bulk upload ABORTED.  Original message: " + ex.Message;
                    bulkUploadProccessed = false;

                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }

                //--- Process bulk upload
                if (bulkUploadProccessed)
                {
                    connection.Open();
                    command = new OleDbCommand("select * from [sections]", connection);
                    dataReader = command.ExecuteReader();

                    int id = 0;

                    while (dataReader.Read())
                    {
                        if (!IsEmptyRow(dataReader))
                        {
                            bool deleted = false;
                            int companiesId = 0;
                            string client = "";
                            string subArea = "";
                            string street = "";
                            string usmh = "";
                            string dsmh = "";
                            string mapSize = ""; //Size_
                            string mapLength = ""; //ScaledLength
                            string actualLength = ""; //
                            string confirmedSize = "";
                            bool jlWork = false; // JL work
                            string usmhMn = "";
                            string dsmhMn = "";
                            string usmhDepth = "";
                            string dsmhDepth = "";
                            string steelTapeThruPipe = "";
                            string usmhAtMouth1200 = "";
                            string usmhAtMouth100 = "";
                            string usmhAtMouth200 = "";
                            string usmhAtMouth300 = "";
                            string usmhAtMouth400 = "";
                            string usmhAtMouth500 = "";
                            string dsmhAtMouth1200 = "";
                            string dsmhAtMouth100 = "";
                            string dsmhAtMouth200 = "";
                            string dsmhAtMouth300 = "";
                            string dsmhAtMouth400 = "";
                            string dsmhAtMouth500 = "";

                            string dataCell = null;
                            string dataCellToUpper = null;

                            //--- ... fill section row
                            string originalSectionId = dataReader.GetValue(dataReader.GetOrdinal("ID")).ToString().Trim();

                            for (int i = 0; i < dataReader.FieldCount; i++)
                            {
                                dataCell = dataReader.GetValue(i).ToString().Trim();
                                dataCellToUpper = dataReader.GetValue(i).ToString().Trim().ToUpper();

                                switch (dataReader.GetName(i).Trim())
                                {
                                    case "ID":
                                        originalSectionId = dataCell;
                                        break;

                                    case "COMPANIES_ID":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            companiesId = int.Parse(dataCell);
                                        }
                                        else
                                        {
                                            bulkUploadResultMessage = "Invalid value in 'COMPANIES_ID' column (" + originalSectionId + ").  Bulk upload ABORTED.";
                                        }

                                        break;

                                    case "SubArea":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            subArea = dataCell;
                                        }
                                        break;

                                    case "Street":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            street = dataCell;
                                        }
                                        break;

                                    case "USMH":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmh = dataCell;
                                        }
                                        break;

                                    case "DSMH":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmh = dataCell;
                                        }
                                        break;

                                    case "Size_":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                mapSize = dataCell;
                                            }
                                            else
                                            {
                                                bulkUploadResultMessage = "Invalid value in 'Size_' column (" + originalSectionId + ").  Bulk upload ABORTED.";
                                                bulkUploadProccessed = false;
                                            }
                                        }
                                        break;

                                    case "ScaledLength":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                mapLength = dataCell;
                                            }
                                            else
                                            {
                                                bulkUploadResultMessage = "Invalid value in 'ScaledLength' column (" + originalSectionId + ").  Bulk upload ABORTED.";
                                                bulkUploadProccessed = false;
                                            }
                                        }
                                        break;

                                    case "ActualLength":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                actualLength = dataCell;
                                            }
                                            else
                                            {
                                                bulkUploadResultMessage = "Invalid value in 'ActualLength' column (" + originalSectionId + " " + dataCell + ").  Bulk upload ABORTED.";
                                                bulkUploadProccessed = false;
                                            }
                                        }
                                        break;

                                    case "ConfirmedSize":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                confirmedSize = dataCell;
                                            }
                                            else
                                            {
                                                bulkUploadResultMessage = "Invalid value in 'ConfirmedSize' column (" + originalSectionId + ").  Bulk upload ABORTED.";
                                                bulkUploadProccessed = false;
                                            }
                                        }
                                        break;

                                    case "JLiner":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            jlWork = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "USMHMN":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhMn = dataCell;
                                        }
                                        break;

                                    case "DSMHMN":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhMn = dataCell;
                                        }
                                        break;

                                    case "USMHDepth":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhDepth = dataCell;
                                        }
                                        break;

                                    case "DSMHDepth":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhDepth = dataCell;
                                        }
                                        break;

                                    case "SteelTapeThruPipe":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            steelTapeThruPipe = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth1200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth1200 = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth100":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth100 = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth200 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth300":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth300 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth400":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth400 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth500":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth500 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth1200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth1200 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth100":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth100 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth200 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth300":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth300 = dataCell;
                                        }
                                        break;
                                    case "DSMHAtMouth400":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth400 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth500":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth500 = dataCell;
                                        }
                                        break;

                                    case "Deleted":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            deleted = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    default:
                                        bulkUploadResultMessage = "Invalid column name '" + dataReader.GetName(i) + "' in section data range.";
                                        bulkUploadProccessed = false;
                                        break;
                                }

                                if (!bulkUploadProccessed)
                                {
                                    break;
                                }
                            }

                            if (bulkUploadProccessed && jlWork && !deleted)
                            {
                                DataMigrationGateway dataMigrationGateway = new DataMigrationGateway(null);
                                Guid originalId = dataMigrationGateway.GetOriginalIdByCompanyIdCompaniesIdRecordIdStreet(int.Parse(hdfCompanyId.Value), companiesId, originalSectionId, street);

                                id = id + 1;

                                if (!dataMigrationGateway.IsMigratedSection(originalId, originalSectionId))
                                {
                                    //--- Initialize
                                    int companyId = Int32.Parse(hdfCompanyId.Value);
                                    DataMigrationTDS dataSet = new DataMigrationTDS();
                                    dataSet.JlDataMigration.Merge(dataMigration, true);
                                    JlDataMigration model = new JlDataMigration(dataSet);
                                    CompaniesGateway companiesGateway = new CompaniesGateway();
                                    companiesGateway.LoadByCompaniesId(companiesId, companyId);
                                    client = companiesGateway.GetName(companiesId);

                                    model.Insert(originalId, originalSectionId, companiesId, client, subArea, street, usmh, dsmh, mapSize, mapLength, actualLength, confirmedSize, jlWork, usmhMn, dsmhMn, usmhDepth, dsmhDepth, steelTapeThruPipe, usmhAtMouth1200, usmhAtMouth100, usmhAtMouth200, usmhAtMouth300, usmhAtMouth400, usmhAtMouth500, dsmhAtMouth1200, dsmhAtMouth100, dsmhAtMouth200, dsmhAtMouth300, dsmhAtMouth400, dsmhAtMouth500, 0, 0, false, "No", 0, 0);

                                    dataMigration = dataSet.JlDataMigration;
                                    Session["dataMigration"] = dataSet.JlDataMigration;
                                }
                            }
                        }
                    }

                    dataReader.Close();
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }

                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }

                throw ex;
            }

            return (bulkUploadProccessed) ? true : false;
        }
        // ////////////////////////////////////////////////////////////////////////
        // METHODS
        //
        private void Save()
        {
            // process sections
            DataMigrationTDS dataSet = new DataMigrationTDS();
            dataSet.JlDataMigration.Merge(dataMigration, true);
            dataSet.DataMigrationProject.Merge(dataMigrationProject, true);
            JlDataMigration model = new JlDataMigration(dataSet);
            DataMigrationProject modelProject = new DataMigrationProject(dataSet);

            int loginId = Convert.ToInt32(Session["loginID"]);

            // save to database
            DB.Open();
            DB.BeginTransaction();
            try
            {
                modelProject.Save(int.Parse(hdfCompanyId.Value), loginId);
                model.Save(int.Parse(hdfCompanyId.Value), loginId);

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

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private bool ProcessBulkProjectsUpload(string fName, out string bulkUploadProjectsResultMessage)
        {
            bool bulkUploadProccessed = true;
            bulkUploadProjectsResultMessage = "";

            AppSettingsReader appSettingReader = new AppSettingsReader();
            string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES;IMEX=1';Data Source=" + fName + ";";
            OleDbConnection connection = new OleDbConnection(excelConnectionString);
            OleDbCommand command = null;
            OleDbDataReader dataReader = null;

            try
            {
                try
                {
                    //--- Process bulk upload
                    if (bulkUploadProccessed)
                    {
                        connection.Open();
                        command = new OleDbCommand("select * from [projects]", connection);
                        dataReader = command.ExecuteReader();

                        while (dataReader.Read())
                        {
                            if (!IsEmptyRow(dataReader))
                            {
                                int companiesId = 0;
                                Int64 countryId = 0;
                                Int64? provinceId = null;
                                Int64? countyId = null;
                                Int64? cityId = null;
                                int officeId = 0;
                                int? projectLeadId = null;
                                int salesmanId = 0;
                                string project = "";

                                string dataCell = null;
                                string dataCellToUpper = null;

                                //--- ... fill section row
                                for (int i = 0; i < dataReader.FieldCount; i++)
                                {
                                    dataCell = dataReader.GetValue(i).ToString().Trim();
                                    dataCellToUpper = dataReader.GetValue(i).ToString().Trim().ToUpper();

                                    switch (dataReader.GetName(i).Trim())
                                    {
                                        case "COMPANIES_ID":
                                            companiesId = int.Parse(dataCell);
                                            break;

                                        case "Country":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                countryId = Int64.Parse(dataCell);
                                            }
                                            break;

                                        case "Province":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                provinceId = Int64.Parse(dataCell);
                                            }
                                            break;

                                        case "County":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                countyId = Int64.Parse(dataCell);
                                            }
                                            break;

                                        case "City":
                                            if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                            {
                                                cityId = Int64.Parse(dataCell);
                                            }
                                            break;

                                        case "Office":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                officeId = int.Parse(dataCell);
                                            }
                                            break;

                                        case "Project Lead (optional)":
                                            if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                            {
                                                projectLeadId = int.Parse(dataCell);
                                            }
                                            break;

                                        case "Salesman":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                salesmanId = int.Parse(dataCell);
                                            }
                                            break;

                                        case "Project":
                                            if (dataCellToUpper != "NULL")
                                            {
                                                project = dataCell;
                                            }
                                            else
                                            {
                                                bulkUploadProjectsResultMessage = "Invalid value in 'Project' column.  Bulk upload ABORTED.";
                                                bulkUploadProccessed = false;
                                            }
                                            break;
                                    }

                                    if (!bulkUploadProccessed)
                                    {
                                        break;
                                    }
                                }

                                if (bulkUploadProccessed)
                                {
                                    //--- Initialize
                                    DataMigrationTDS dataSet = new DataMigrationTDS();
                                    dataSet.DataMigrationProject.Merge(dataMigrationProject, true);
                                    DataMigrationProject model = new DataMigrationProject(dataSet);
                                    model.Insert(companiesId, countryId, provinceId, countyId, cityId, officeId, projectLeadId, salesmanId, project);
                                    dataMigrationProject = dataSet.DataMigrationProject;
                                    Session["dataMigrationProject"] = dataSet.DataMigrationProject;
                                }
                            }
                        }

                        dataReader.Close();
                        connection.Close();
                    }
                }
                catch (Exception ex)
                {
                    bulkUploadProjectsResultMessage = "You did not define the 'projects' data range.  Bulk upload ABORTED.  Original message: " + ex.Message;
                    bulkUploadProccessed = false;

                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }

                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }

                throw ex;
            }

            return (bulkUploadProccessed) ? true : false;
        }
        private bool ProcessBulkUpload(string fName, out string bulkUploadResultMessage)
        {
            bool bulkUploadProccessed = true;
            bulkUploadResultMessage = "";

            AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();

            AppSettingsReader appSettingReader = new AppSettingsReader();

            string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES;IMEX=1';Data Source=" + fName + ";";

            OleDbConnection connection = new OleDbConnection(excelConnectionString);
            OleDbCommand command = null;
            OleDbDataReader dataReader = null;

            try
            {
                try
                {
                    connection.Open();
                    command = new OleDbCommand("select * from [sections]", connection);
                    dataReader = command.ExecuteReader();
                    dataReader.Close();
                    connection.Close();
                }
                catch (Exception ex)
                {
                    bulkUploadResultMessage = "You did not define the 'sections' data range.  Bulk upload ABORTED.  Original message: " + ex.Message;
                    bulkUploadProccessed = false;

                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }

                //--- Process bulk upload
                if (bulkUploadProccessed)
                {
                    connection.Open();
                    command = new OleDbCommand("select * from [sections]", connection);
                    dataReader = command.ExecuteReader();

                    int id = 0;

                    while (dataReader.Read())
                    {
                        if (!IsEmptyRow(dataReader))
                        {
                            string clientId = "";
                            int companiesId = 0;
                            string client = "";
                            string subArea = "";
                            string street = "";
                            string usmh = "";
                            string dsmh = "";
                            string mapSize = ""; //Size_
                            string mapLength = ""; //ScaledLength
                            DateTime? p1Date = null;
                            string actualLength = ""; //
                            string cxisRemoved = "";
                            DateTime? m1Date = null;
                            DateTime? m2Date = null;
                            DateTime? installDate = null;
                            DateTime? finalVideo = null;
                            bool issueIdentified = false;
                            bool issueResolved = false;
                            bool fllWork = false; // FLL Work
                            bool issueGivenToBayCity = false;
                            string confirmedSize = "";
                            DateTime? deadLineDate = null;
                            DateTime? proposedLiningDate = null;
                            bool salesIssue = false;
                            bool lfsIssue = false;
                            bool clientIssue = false;
                            bool investigationIssue = false;
                            bool jlWork = false; // JL work
                            bool raWork = false; // RA Work
                            DateTime? preFlushDate = null;
                            DateTime? preVideoDate = null;
                            string usmhMn = "";
                            string dsmhMn = "";
                            string usmhDepth = "";
                            string dsmhDepth = "";
                            string measurementsTakenBy = "";
                            string steelTapeThruPipe = "";
                            string usmhAtMouth1200 = "";
                            string usmhAtMouth100 = "";
                            string usmhAtMouth200 = "";
                            string usmhAtMouth300 = "";
                            string usmhAtMouth400 = "";
                            string usmhAtMouth500 = "";
                            string dsmhAtMouth1200 = "";
                            string dsmhAtMouth100 = "";
                            string dsmhAtMouth200 = "";
                            string dsmhAtMouth300 = "";
                            string dsmhAtMouth400 = "";
                            string dsmhAtMouth500 = "";
                            string hydrantAdrress = "";
                            string distanceToInversionMh = "";
                            bool rampsRequired = false;
                            string degreeOfTrafficControl = "";
                            bool standarBypass = false;
                            string hydroWireDetails = "";
                            string pipeMaterialType = "";
                            int? capedLaterals = null;
                            bool roboticPrepRequired = false;
                            bool pipeSizeChange = false;
                            string videoDoneFrom = "";
                            string ToManhole = "";
                            string cutterDescriptionDuringMeasuring = "";
                            string lineWidthId = "";
                            bool schoolZone = false;
                            bool restaurantArea = false;
                            bool carswashLaundromat = false;
                            bool hydroPulley = false;
                            bool fridgeCart = false;
                            bool twoInchPump = false;
                            bool sixInchBypass = false;
                            bool scaffolding = false;
                            bool winchExtension = false;
                            bool extraGenerator = false;
                            bool greyCableExtension = false;
                            bool easementMats = false;
                            string measurementType = "";
                            bool dropPipe = false;
                            string dropPipeInvertDepth = "";
                            string measurementFromManhole = "";

                            string dataCell = null;
                            string dataCellToUpper = null;

                            //--- ... fill section row
                            string originalSectionId = dataReader.GetValue(dataReader.GetOrdinal("ID")).ToString().Trim();

                            for (int i = 0; i < dataReader.FieldCount; i++)
                            {
                                dataCell = dataReader.GetValue(i).ToString().Trim();
                                dataCellToUpper = dataReader.GetValue(i).ToString().Trim().ToUpper();

                                switch (dataReader.GetName(i).Trim())
                                {
                                    case "ID":
                                        originalSectionId = dataCell;
                                        break;

                                    case "ClientID":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            clientId = dataCell;
                                        }
                                        break;

                                    case "COMPANIES_ID":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            companiesId = int.Parse(dataCell);
                                        }
                                        else
                                        {
                                            string aux = dataReader.GetFieldType(2).ToString();
                                            string aux2 = dataReader.GetDouble(dataReader.GetOrdinal("COMPANIES_ID")).ToString();
                                            string aux3 = dataReader.GetString(dataReader.GetOrdinal("COMPANIES_ID")).ToString();
                                        }
                                        break;

                                    case "Client":
                                        if (dataCellToUpper != "NULL")
                                        {
                                            client = dataCell;
                                        }
                                        break;

                                    case "SubArea":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            subArea = dataCell;
                                        }
                                        break;

                                    case "Street":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            street = dataCell;
                                        }
                                        break;

                                    case "USMH":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmh = dataCell;
                                        }
                                        break;

                                    case "DSMH":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmh = dataCell;
                                        }
                                        break;

                                    case "Size_":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                mapSize = dataCell;
                                            }
                                        }
                                        break;

                                    case "ScaledLength":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                mapLength = dataCell;
                                            }
                                        }
                                        break;

                                    case "P1Date":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            p1Date = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "ActualLength":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                actualLength = dataCell;
                                            }
                                        }
                                        break;

                                    case "CXIsRemoved":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            cxisRemoved = dataCell;
                                        }
                                        break;

                                    case "M1Date":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            m1Date = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "M2Date":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            m2Date = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "InstallDate":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            installDate = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "FinalVideo":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            finalVideo = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "IssueIdentified":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            issueIdentified = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "IssueResolved":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            issueResolved = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "FullLengthLining":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            fllWork = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "IssueGivenToBayCity":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            issueGivenToBayCity = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "ConfirmedSize":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            if (Distance.IsValidDistance(dataCell))
                                            {
                                                confirmedSize = dataCell;
                                            }
                                        }
                                        break;

                                    case "DeadlineDate":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            deadLineDate = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "ProposedLiningDate":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            proposedLiningDate = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "SalesIssue":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            salesIssue = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "LFSIssue":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            lfsIssue = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "ClientIssue":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            clientIssue = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "InvestigationIssue":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            investigationIssue = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "JLiner":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            jlWork = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "RehabAssessment":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            raWork = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "PreFlushDate":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            preFlushDate = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "PreVideoDate":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            preVideoDate = Convert.ToDateTime(dataCell);
                                        }
                                        break;

                                    case "USMHMN":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhMn = dataCell;
                                        }
                                        break;

                                    case "DSMHMN":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhMn = dataCell;
                                        }
                                        break;

                                    case "USMHDepth":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhDepth = dataCell;
                                        }
                                        break;

                                    case "DSMHDepth":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhDepth = dataCell;
                                        }
                                        break;

                                    case "MeasurementsTakenBy":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            measurementsTakenBy = dataCell;
                                        }
                                        break;

                                    case "SteelTapeThruPipe":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            steelTapeThruPipe = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth1200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth1200 = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth100":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth100 = dataCell;
                                        }
                                        break;

                                    case "USMHAtMouth200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth200 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth300":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth300 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth400":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth400 = dataCell;
                                        }
                                        break;
                                    case "USMHAtMouth500":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            usmhAtMouth500 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth1200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth1200 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth100":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth100 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth200":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth200 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth300":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth300 = dataCell;
                                        }
                                        break;
                                    case "DSMHAtMouth400":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth400 = dataCell;
                                        }
                                        break;

                                    case "DSMHAtMouth500":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dsmhAtMouth500 = dataCell;
                                        }
                                        break;

                                    case "HydrantAddress":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            hydrantAdrress = dataCell;
                                        }
                                        break;

                                    case "DistanceToInversionMH":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            distanceToInversionMh = dataCell;
                                        }
                                        break;

                                    case "RampsRequired":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            rampsRequired = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "DegreeOfTrafficControl":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            degreeOfTrafficControl = dataCell;
                                        }
                                        break;

                                    case "StandarBypass":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            standarBypass = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "HydroWireDetails":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            hydroWireDetails = dataCell;
                                        }
                                        break;

                                    case "PipeMaterialType":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            pipeMaterialType = dataCell;
                                        }
                                        break;

                                    case "CappedLaterals":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            capedLaterals = int.Parse(dataCell);
                                        }
                                        break;

                                    case "RoboticPrepRequired":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            roboticPrepRequired = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "PipeSizeChange":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            pipeSizeChange = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "VideoDoneFrom":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            videoDoneFrom = dataCell;
                                        }
                                        break;

                                    case "ToManhole":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            ToManhole = dataCell;
                                        }
                                        break;

                                    case "CutterDescriptionDuringMeasuring":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            cutterDescriptionDuringMeasuring = dataCell;
                                        }
                                        break;

                                    case "LineWithID":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            lineWidthId = dataCell;
                                        }
                                        break;

                                    case "SchoolZone":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            schoolZone = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "RestaurantArea":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            restaurantArea = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "CarwashLaundromat":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            carswashLaundromat = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "HydroPulley":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            hydroPulley = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "FridgeCart":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            fridgeCart = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "TwoInchPump":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            twoInchPump = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "SixInchBypass":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            sixInchBypass = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "Scaffolding":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            scaffolding = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "WinchExtension":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            winchExtension = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "ExtraGenerator":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            extraGenerator = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "GreyCableExtension":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            greyCableExtension = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "EasementMats":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            easementMats = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "MeasurementType":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            measurementType = dataCell;
                                        }
                                        break;

                                    case "DropPipe":
                                        if ((dataCellToUpper == "YES") || (dataCellToUpper == "NO"))
                                        {
                                            dropPipe = (dataCellToUpper == "YES") ? true : false;
                                        }
                                        break;

                                    case "DropPipeInvertDepth":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            dropPipeInvertDepth = dataCell;
                                        }
                                        break;

                                    case "MeasuredFromManhole":
                                        if (dataCellToUpper != "NULL" && dataCellToUpper != "")
                                        {
                                            measurementFromManhole = dataCell;
                                        }
                                        break;

                                    default:
                                        bulkUploadResultMessage = "Invalid column name '" + dataReader.GetName(i) + "' in section data range.";
                                        bulkUploadProccessed = false;
                                        break;
                                }

                                if (!bulkUploadProccessed)
                                {
                                    break;
                                }
                            }

                            if (bulkUploadProccessed)
                            {
                                DataMigrationGateway dataMigrationGateway = new DataMigrationGateway(null);
                                Guid originalId = dataMigrationGateway.GetOriginalIdByCompanyIdCompaniesIdRecordIdStreet(int.Parse(hdfCompanyId.Value), companiesId, originalSectionId, street);

                                id = id + 1;

                                if (!dataMigrationGateway.IsMigratedSection(originalId, originalSectionId))
                                {
                                    //--- Initialize
                                    DataMigrationTDS dataSet = new DataMigrationTDS();
                                    dataSet.DataMigration.Merge(dataMigration, true);
                                    DataMigration model = new DataMigration(dataSet);

                                    model.Insert(originalId, originalSectionId, clientId, companiesId, client, subArea, street, usmh, dsmh, mapSize, mapLength, p1Date, actualLength, cxisRemoved, m1Date, m2Date, installDate, finalVideo, issueIdentified, issueResolved, fllWork, issueGivenToBayCity, confirmedSize, deadLineDate, proposedLiningDate, salesIssue, lfsIssue, clientIssue, investigationIssue, jlWork, raWork, preFlushDate, preVideoDate, usmhMn, dsmhMn, usmhDepth, dsmhDepth, measurementsTakenBy, steelTapeThruPipe, usmhAtMouth1200, usmhAtMouth100, usmhAtMouth200, usmhAtMouth300, usmhAtMouth400, usmhAtMouth500, dsmhAtMouth1200, dsmhAtMouth100, dsmhAtMouth200, dsmhAtMouth300, dsmhAtMouth400, dsmhAtMouth500, hydrantAdrress, distanceToInversionMh, rampsRequired, degreeOfTrafficControl, standarBypass, hydroWireDetails, pipeMaterialType, capedLaterals, roboticPrepRequired, pipeSizeChange, videoDoneFrom, ToManhole, cutterDescriptionDuringMeasuring, lineWidthId, schoolZone, restaurantArea, carswashLaundromat, hydroPulley, fridgeCart, twoInchPump, sixInchBypass, scaffolding, winchExtension, extraGenerator, greyCableExtension, easementMats, measurementType, dropPipe, dropPipeInvertDepth, measurementFromManhole);

                                    dataMigration = dataSet.DataMigration;
                                    Session["dataMigration"] = dataSet.DataMigration;
                                }
                            }
                        }
                    }

                    dataReader.Close();
                    connection.Close();
                }
            }
            catch (Exception ex)
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                }

                if (connection.State == ConnectionState.Open)
                {
                    connection.Close();
                }

                throw ex;
            }

            return (bulkUploadProccessed) ? true : false;
        }
        /// <summary>
        /// GetProjectNumber
        /// </summary>
        /// <param name="row">row</param>
        /// <param name="companyId">companyId</param>
        /// <returns></returns>
        private string GetProjectNumber(DataMigrationTDS.DataMigrationProjectRow row, int companyId)
        {
            DateTime date = DateTime.Now;

            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(row.CountryID);
            string pnCountryId = countryGateway.GetIdForProjects(row.CountryID);

            OfficeGateway officeGateway = new OfficeGateway(new DataSet());
            officeGateway.LoadByOfficeId(row.OfficeID);
            string pnOfficeId = officeGateway.GetIdForProjects(row.OfficeID);

            SalesmanGateway salesmanGateway = new SalesmanGateway(new DataSet());
            salesmanGateway.LoadBySalesmanId(row.SalesmanID);
            string pnSalesmanId = salesmanGateway.GetIdForProjects(row.SalesmanID);

            ProjectNumberGateway projectNumberGateway = new ProjectNumberGateway();
            projectNumberGateway.Load();
            ProjectNumber projectNumber = new ProjectNumber(projectNumberGateway.Data);
            string pnYearCode = projectNumber.GetYearCode(date.Year);
            string pnProjectIncrement = projectNumber.GetProjectIncrement(date.Year, companyId);

            string newProjectNumber = pnCountryId + pnOfficeId + pnSalesmanId + pnYearCode + pnProjectIncrement;

            return newProjectNumber;
        }
        /// <summary>
        /// SaveRAWork
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="section_assetId">section_assetId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="subArea">subArea</param>
        /// <param name="comments">comments</param>
        /// <param name="loginId">loginId</param>
        private void SaveRAWork(DataMigrationTDS.DataMigrationRow row, int projectId, int section_assetId, int companyId, string comments, int loginId)
        {
            DateTime dateTime_ = DateTime.Now;
            string commentsToWork = "";
            DateTime? preFlushDate = null; if (!row.IsPreFlushDateNull()) preFlushDate = row.PreFlushDate;
            DateTime? preVideoDate = null; if (!row.IsPreVideoDateNull()) preVideoDate = row.PreVideoDate;

            if (comments != "")
            {
                // ... Get user name
                LoginGateway loginGateway = new LoginGateway();
                loginGateway.LoadByLoginId(loginId, companyId);
                string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);

                // ... Form the comment string
                commentsToWork = commentsToWork + dateTime_ + "\n" + "(" + user.Trim() + ") \n Subject: Bulk Upload Comments \n Comment: " + comments;
            }

            WorkRehabAssessment workRehabAssessment = new WorkRehabAssessment(null);
            int workId = workRehabAssessment.InsertDirect(projectId, section_assetId, null, preFlushDate, preVideoDate, false, companyId, commentsToWork, "");

            if (comments != "")
            {
                WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                workCommentsGateway.LoadByWorkIdWorkType(workId, companyId, "Rehab Assessment");
                WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                workComments.Insert(workId, 0, "Rehab Assessment", "Bulk Upload Comments", loginId, DateTime.Now, comments, null, false, companyId, false, "Rehab Assessment");

                // UpdateComments
                workCommentsGateway.Update();
            }
        }
        /// <summary>
        /// SaveFLLWork
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="section_assetId"></param>
        /// <param name="companyId"></param>
        /// <param name="comments"></param>
        /// <param name="loginId"></param>
        private void SaveFLLWork(DataMigrationTDS.DataMigrationRow row, int projectId, int section_assetId, int companyId, string comments, int loginId)
        {
            DateTime dateTime_ = DateTime.Now;
            string commentsToWork = "";
            string clientId = ""; if (!row.IsClientIDNull()) clientId = row.ClientID;
            DateTime? proposedLiningDate = null; if (!row.IsProposedLiningDateNull()) proposedLiningDate = row.ProposedLiningDate;
            DateTime? deadLineLiningDate = null; if (!row.IsDeadlineDateNull()) deadLineLiningDate = row.DeadlineDate;
            DateTime? p1Date = null; if (!row.IsP1DateNull()) p1Date = row.P1Date;
            DateTime? m1Date = null; if (!row.IsM1DateNull()) m1Date = row.M1Date;
            DateTime? m2Date = null; if (!row.IsM2DateNull()) m2Date = row.M2Date;
            DateTime? installDate = null; if (!row.IsInstallDateNull()) installDate = row.InstallDate;
            DateTime? finalVideoDate = null; if (!row.IsFinalVideoNull()) finalVideoDate = row.FinalVideo;
            bool issueIdentified = row.IssueIdentified;
            bool issueLFS = row.LFSIssue;
            bool issueClient = row.ClientIssue;
            bool issueSales = row.SalesIssue;
            bool issueGivenToClient = row.IssueGivenToBayCity;
            bool issueResolved = row.IssueResolved;
            bool issueInvestigation = row.InvestigationIssue;
            int? cxisRemoved = null; if (!row.IsCXIsRemovedNull()) cxisRemoved = int.Parse(row.CXIsRemoved);
            string lineWidthId = ""; if (!row.IsLineWithIDNull()) lineWidthId = row.LineWithID;
            string measurementsTakenBy = ""; if (!row.IsMeasurementsTakenByNull()) measurementsTakenBy = row.MeasurementsTakenBy;
            string hydrantAddress = ""; if (!row.IsHydrantAddressNull()) hydrantAddress = row.HydrantAddress;
            string distanceToInversionMh = ""; if (!row.IsDistanceToInversionMHNull()) distanceToInversionMh = row.DistanceToInversionMH;
            string trafficControl = ""; if (!row.IsDegreeOfTrafficControlNull()) trafficControl = row.DegreeOfTrafficControl;
            string hydroWireDetails = ""; if (!row.IsHydroWireDetailsNull()) hydroWireDetails = row.HydroWireDetails;
            bool rampsRequired = row.RampsRequired;
            bool pipeSizeChanges = row.PipeSizeChange;
            bool standarBypass = row.StandarBypass;
            bool roboticPrepRequired = row.RoboticPrepRequired;
            bool schoolZone = row.SchoolZone;
            bool restaurantArea = row.RestaurantArea;
            bool carswashLaundromat = row.CarwashLaundromat;
            bool hydroPulley = row.HydroPulley;
            bool fridgeCart = row.FridgeCart;
            bool twoPump = row.TwoInchPump;
            bool sixBypass = row.SixInchBypass;
            bool scaffolding = row.Scaffolding;
            bool winchExtension = row.WinchExtension;
            bool extraGenerator = row.ExtraGenerator;
            bool greyCableExtension = row.GreyCableExtension;
            bool easementMats = row.EasementMats;
            string measurementType = ""; if (!row.IsMeasurementTypeNull()) measurementType = row.MeasurementType;
            string measurementFromMh = ""; if (!row.IsMeasuredFromManholeNull()) measurementFromMh = row.MeasuredFromManhole;
            string videoDoneFromMh = ""; if (!row.IsVideoDoneFromNull()) videoDoneFromMh = row.VideoDoneFrom;
            string videoDoneToMh = ""; if (!row.IsToManholeNull()) videoDoneToMh = row.ToManhole;
            string videoDistance = ""; if (!row.IsCutterDescriptionDuringMeasuringNull()) videoDistance = row.CutterDescriptionDuringMeasuring;
            bool dropPipe = row.DropPipe;
            string dropPipeInvertDepth = ""; if (!row.IsDropPipeInvertDepthNull()) dropPipeInvertDepth = row.DropPipeInvertDepth;
            int? cappedLaterals = null; if (!row.IsCappedLateralsNull()) cappedLaterals = row.CappedLaterals;
            string materialType = ""; if (!row.IsPipeMaterialTypeNull()) materialType = row.PipeMaterialType;
            string usmh = ""; if (!row.IsUSMHNull()) usmh = row.USMH;
            string dsmh = ""; if (!row.IsDSMHNull()) dsmh = row.DSMH;

            if (comments != "")
            {
                // ... Get user name
                LoginGateway loginGateway = new LoginGateway();
                loginGateway.LoadByLoginId(loginId, companyId);
                string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);

                // ... Form the comment string
                commentsToWork = commentsToWork + dateTime_ + "\n" + "(" + user.Trim() + ") \n Subject: Bulk Upload Comments \n Comment: " + comments;
            }

            if (measurementFromMh != "")
            {
                if (measurementFromMh.ToUpper() == "USMH" || usmh.Contains(measurementFromMh))
                {
                    measurementFromMh = "USMH";
                }

                if (measurementFromMh.ToUpper() == "DSMH" || dsmh.Contains(measurementFromMh))
                {
                    measurementFromMh = "DSMH";
                }

                if (measurementFromMh != "USMH" && measurementFromMh != "DSMH")
                {
                    measurementFromMh = "";
                }
            }

            if (videoDoneFromMh != "")
            {
                if (videoDoneFromMh.ToUpper() == "USMH" || usmh.Contains(videoDoneFromMh))
                {
                    videoDoneFromMh = "USMH";
                }

                if (videoDoneFromMh.ToUpper() == "DSMH" || dsmh.Contains(videoDoneFromMh))
                {
                    videoDoneFromMh = "DSMH";
                }

                if (videoDoneFromMh != "USMH" && videoDoneFromMh != "DSMH")
                {
                    videoDoneFromMh = "";
                }
            }

            if (videoDoneToMh != "")
            {
                if (videoDoneToMh.ToUpper() == "USMH" || usmh.Contains(videoDoneToMh))
                {
                    videoDoneToMh = "USMH";
                }

                if (videoDoneToMh.ToUpper() == "DSMH" || dsmh.Contains(videoDoneToMh))
                {
                    videoDoneToMh = "DSMH";
                }

                if (videoDoneToMh != "USMH" && videoDoneToMh != "DSMH")
                {
                    videoDoneToMh = "";
                }
            }

            WorkFullLengthLining workFullLengthLining = new WorkFullLengthLining(null);
            int workId = workFullLengthLining.InsertDirectEmptyWorks(projectId, section_assetId, null, clientId, proposedLiningDate, deadLineLiningDate, p1Date, m1Date, m2Date, installDate, finalVideoDate, issueIdentified, issueLFS, issueClient, issueSales, issueGivenToClient, issueResolved, false, companyId, issueInvestigation, commentsToWork, "");

            if (comments != "")
            {
                WorkCommentsGateway workCommentsGateway = new WorkCommentsGateway();
                workCommentsGateway.LoadByWorkIdWorkType(workId, companyId, "Full Length Lining");
                WorkComments workComments = new WorkComments(workCommentsGateway.Data);
                workComments.Insert(workId, 0, "Other", "Bulk Upload Comments", loginId, dateTime_, comments, null, false, companyId, false, "Full Length Lining");

                // UpdateComments
                workCommentsGateway.Update();
            }

            if (materialType != "")
            {
                DataMigrationGateway dataMigrationGateway = new DataMigrationGateway(null);
                dataMigrationGateway.InsertMaterial(section_assetId, 1, materialType, dateTime_, false, companyId);
            }
        }