public void ImportPCI() { m_bError = false; bool bIsMetricData = false; if (m_bIsLinear) { ValidateLinear(); } else { ValidateSection(); } if (m_bError) { return; } string query = "SELECT OPTION_VALUE FROM OPTIONS WHERE OPTION_NAME = 'PCI_UNITS'"; string units = DBMgr.ExecuteQuery(query).Tables[0].Rows[0].ItemArray[0].ToString(); if (units == "METRIC") { bIsMetricData = true; } List <PCIDistressObject> distressRows = new List <PCIDistressObject>(); query = "SELECT DISTRESSNUMBER, DISTRESSNAME, METHOD_, METRIC_CONVERSION FROM PCI_DISTRESS"; DataSet allDistressInfo = DBMgr.ExecuteQuery(query); foreach (DataRow distressInfo in allDistressInfo.Tables[0].Rows) { PCIDistressObject distressProperties = new PCIDistressObject(distressInfo["DISTRESSNAME"].ToString(), int.Parse(distressInfo["DISTRESSNUMBER"].ToString()), (float.Parse(distressInfo["METRIC_CONVERSION"].ToString()))); distressRows.Add(distressProperties); } string strMyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); strMyDocumentsFolder += "\\RoadCare Projects\\Temp"; Directory.CreateDirectory(strMyDocumentsFolder); string strOutFile = strMyDocumentsFolder + "\\pci.txt"; File.Delete(strOutFile); m_twPCI = new StreamWriter(strOutFile); string strOutFileDetails = strMyDocumentsFolder + "\\pciDetails.txt"; File.Delete(strOutFileDetails); m_twPCIDetail = new StreamWriter(strOutFileDetails); if (m_bError) { return; // If there is an error in the BULK PCI load, don't load } List <LRSObjectPCI> listPCI = new List <LRSObjectPCI>(); LRSObjectPCI pciPrevious = null; foreach (DataGridViewRow row in dgvPCIBulkLoad.Rows) { if (!Validation.IsValidRow(row)) { continue; } LRSObjectPCI lrsObjectPCI = new LRSObjectPCI(row.Cells["ROUTES"].Value.ToString(), double.Parse(row.Cells["BEGIN_STATION"].Value.ToString()), double.Parse(row.Cells["END_STATION"].Value.ToString()), row.Cells["DIRECTION"].Value.ToString(), row.Cells["SAMPLE_"].Value.ToString(), DateTime.Parse(row.Cells["DATE_"].Value.ToString()), row.Cells["METHOD_"].Value.ToString(), row.Cells["TYPE_"].Value.ToString(), double.Parse(row.Cells["AREA"].Value.ToString()), row.Cells["DISTRESS"].Value.ToString(), row.Cells["SEVERITY"].Value.ToString(), double.Parse(row.Cells["AMOUNT"].Value.ToString())); if (listPCI.Count > 0) { if (pciPrevious.Route != lrsObjectPCI.Route || pciPrevious.BeginStation != lrsObjectPCI.BeginStation || pciPrevious.EndStation != lrsObjectPCI.EndStation || pciPrevious.Direction != lrsObjectPCI.Direction || pciPrevious.Sample != lrsObjectPCI.Sample || pciPrevious.Area != lrsObjectPCI.Area || pciPrevious.Method != lrsObjectPCI.Method || pciPrevious.Type != lrsObjectPCI.Type || pciPrevious.Date != lrsObjectPCI.Date) { WritePCISample(listPCI, m_nNextPCIID, distressRows, bIsMetricData); listPCI.Clear(); m_nNextPCIID++; } } pciPrevious = lrsObjectPCI; listPCI.Add(lrsObjectPCI); } WritePCISample(listPCI, m_nNextPCIID, distressRows, bIsMetricData); m_twPCI.Close(); m_twPCIDetail.Close(); DBMgr.SQLBulkLoad("PCI", strOutFile, '\t'); DBMgr.SQLBulkLoad("PCI_DETAIL", strOutFileDetails, '\t'); this.Close(); }
public void ValidateLinear() { string strMyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); strMyDocumentsFolder += "\\RoadCare Projects\\Temp"; Directory.CreateDirectory(strMyDocumentsFolder); string strOutFile = strMyDocumentsFolder + "\\PCIValidationErrors.txt"; TextWriter tw = new StreamWriter(strOutFile); FormManager.GetOutputWindow().ClearWindow(); foreach (DataGridViewRow row in dgvPCIBulkLoad.Rows) { string strError = ""; if (!Validation.IsValidRow(row)) { if (row.Index != dgvPCIBulkLoad.Rows.Count - 1) { SetRowColor(row, Color.LightCoral); tw.WriteLine("Entire row must be entered before Bulk Loading. Row:" + row.Index.ToString() + ", " + row.Cells["ROUTES"].Value + ", " + row.Cells["BEGIN_STATION"].Value + ", " + row.Cells["END_STATION"].Value + ", " + row.Cells["SAMPLE_"].Value + ", " + row.Cells["DATE_"].Value); m_bError = true; } continue; } LRSObjectPCI lrsObjectPCI; try { lrsObjectPCI = new LRSObjectPCI(row.Cells["ROUTES"].Value.ToString(), double.Parse(row.Cells["BEGIN_STATION"].Value.ToString()), double.Parse(row.Cells["END_STATION"].Value.ToString()), row.Cells["DIRECTION"].Value.ToString(), row.Cells["SAMPLE_"].Value.ToString(), DateTime.Parse(row.Cells["DATE_"].Value.ToString()), row.Cells["METHOD_"].Value.ToString(), row.Cells["TYPE_"].Value.ToString(), double.Parse(row.Cells["AREA"].Value.ToString()), row.Cells["DISTRESS"].Value.ToString(), row.Cells["SEVERITY"].Value.ToString(), double.Parse(row.Cells["AMOUNT"].Value.ToString())); } catch //(Exception except) { tw.WriteLine("Error validating PCI Object" + row.Index.ToString() + ", " + row.Cells["ROUTES"].Value + ", " + row.Cells["BEGIN_STATION"].Value + ", " + row.Cells["END_STATION"].Value + ", " + row.Cells["SAMPLE_"].Value + ", " + row.Cells["DATE_"].Value); m_bError = true; continue; } if (!Validation.ValidateLinear((LRSObject)lrsObjectPCI, out strError)) { tw.WriteLine(strError + ", " + row.Cells["ROUTES"].Value + ", " + row.Cells["BEGIN_STATION"].Value + ", " + row.Cells["END_STATION"].Value + ", " + row.Cells["SAMPLE_"].Value + ", " + row.Cells["DATE_"].Value); m_bError = true; continue; } if (!Validation.ValidatePCIDetail(lrsObjectPCI, out strError)) { tw.WriteLine(strError + ", " + row.Cells["ROUTES"].Value + ", " + row.Cells["BEGIN_STATION"].Value + ", " + row.Cells["END_STATION"].Value + ", " + row.Cells["SAMPLE_"].Value + ", " + row.Cells["DATE_"].Value); m_bError = true; continue; } } if (m_bError) { Global.WriteOutput("Errors encountered during validation, please check error log file before continuing."); } else { Global.WriteOutput("Validation of PCI Distress complete. No errors or warnings."); } tw.Close(); }