private void FormPCIBulkLoad_Load(object sender, EventArgs e) { if (dataAdapter != null) { dataAdapter.Dispose(); // Free up the resources } if (binding != null) { binding.Dispose(); } if (table != null) { table.Dispose(); } try { string strQuery; if (m_bIsLinear) { strQuery = "SELECT * FROM PCI_VALIDATION_LINEAR ORDER BY ROUTES, DIRECTION, BEGIN_STATION, END_STATION, DATE_"; } else { strQuery = "SELECT * FROM PCI_VALIDATION ORDER BY FACILITY, SECTION, DATE_, SAMPLE_"; } dataAdapter = new DataAdapter(strQuery); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); binding = new BindingSource(); binding.DataSource = table; dgvPCIBulkLoad.DataSource = binding; bindingNavigatorPCIValidation.BindingSource = binding; dgvPCIBulkLoad.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; if (m_bIsLinear) { Validation.LoadLRS(); } else { Validation.LoadSRS(); } } catch (Exception exception) { Global.WriteOutput("Error: Building current attribute view. SQL message is " + exception.Message); } foreach (DataGridViewColumn column in dgvPCIBulkLoad.Columns) { column.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } }
private void LoadDistressMapping() { string query = "SELECT * FROM PCI_DISTRESS"; if (pciDistressMapAdapter != null) { pciDistressMapAdapter.Dispose(); // Free up the resources } if (binding != null) { binding.Dispose(); } if (table != null) { table.Dispose(); } pciDistressMapAdapter = new DataAdapter(query); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; pciDistressMapAdapter.Fill(table); binding = new BindingSource(); binding.DataSource = table; dgvDistressMapping.DataSource = binding; }
private void UpdateAssetGrid() { if (dataAdapter != null) { dataAdapter.Dispose(); // Free up the resources } if (binding != null) { binding.Dispose(); } if (table != null) { table.Dispose(); } try { String strQuery = "Select * From " + m_strAsset; if (tbAdvancedSearch.Text != "") { strQuery += " WHERE " + tbAdvancedSearch.Text; } binding = new BindingSource(); dataAdapter = new DataAdapter(strQuery, m_assetCP); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); binding.DataSource = table; dgvAssets.DataSource = binding; bindingNavigatorAsset.BindingSource = binding; dgvAssets.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; dgvAssets.Columns["GEOMETRY"].Visible = false; dgvAssets.Columns["EnvelopeMinX"].Visible = false; dgvAssets.Columns["EnvelopeMaxX"].Visible = false; dgvAssets.Columns["EnvelopeMinY"].Visible = false; dgvAssets.Columns["EnvelopeMaxY"].Visible = false; } catch (Exception exception) { Global.WriteOutput("Error: Building current attribute view. SQL message is " + exception.Message); } }
private void frmEditLookupTable_Load(object sender, EventArgs e) { this.Text += ". Tabella: " + table; DataSet ds = null; DataAdapter da = null; db.GetLookupTable(table, ref ds, ref da); dgwTable.DataSource = ds.Tables[0]; da.Dispose(); }
private void UpdateSectionGrid() { bool IsLinear = false; if (checkMilepost.Checked) { IsLinear = true; } string strSelect = DBOp.GetAdvancedFilterSelectStatement(IsLinear, m_strNetworkID, comboBoxRouteFacilty.Text, textBoxAdvanceSearch.Text, comboBoxFilterAttribute.Text, comboBoxAttributeValue.Text); if (dataAdapter != null) { dataAdapter.Dispose(); // Free up the resources } if (binding != null) { binding.Dispose(); } if (table != null) { table.Dispose(); } try { binding = new BindingSource(); dataAdapter = new DataAdapter(strSelect); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); binding.DataSource = table; dgvSection.DataSource = binding; bindingNavigatorSectionView.BindingSource = binding; dgvSection.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; for (int i = 0; i < dgvSection.ColumnCount; i++) { dgvSection.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } dgvSection.Columns["SECTIONID"].Visible = false; } catch (Exception exc) { Global.WriteOutput("Error: Filling Section View. Check advanced search. " + exc.Message); } }
private void DataAdapter_onCompleted(object sender, DataAdapterCompleteEvent e) { DataAdapter cAdapter = sender as DataAdapter; cAdapter.Dispose(); int iTimeFrame = e.TotalSeconds; string sSymbolId = e.SymbolId.ToLower(); if (iTimeFrame < Resolution.MAX_BASE_TOTALSECONDS) { lock (__cMinBases) { if (__cMinBases.ContainsKey(sSymbolId)) { __cMinBases.Remove(sSymbolId); } } } else { lock (__cDayBases) { if (__cDayBases.ContainsKey(sSymbolId)) { __cDayBases.Remove(sSymbolId); } } } }
private SeriesSymbolDataRand InternalGetSeries(InstrumentDataRequest dataRequest, bool useCache) { SeriesStorage cStorage = null; string sLSymbolId = dataRequest.Symbol.ToLower(); lock (__cStorages) { if (!__cStorages.TryGetValue(sLSymbolId, out cStorage)) { cStorage = new SeriesStorage(16); __cStorages.Add(sLSymbolId, cStorage); } } SeriesSymbolDataRand cSeriesRand = null; int iTotalSeconds = dataRequest.Resolution.TotalSeconds; if (useCache) { //是否使用快取 lock (cStorage) { //需要 lock 這個區塊(避免非同步讀取資料時發生問題) int iBaseSeconds = (iTotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? Resolution.MIN_BASE_TOTALSECONDS : Resolution.MAX_BASE_TOTALSECONDS; SeriesSymbolData cSeries = cStorage.GetSeries(iTotalSeconds); if (cSeries == null) { cSeries = cStorage.GetSeries(iBaseSeconds); if (cSeries == null) { DataAdapter cAdapter = LoadAdapter(ref dataRequest); cSeries = cAdapter.Series; cStorage.Add(cSeries); } } if (iBaseSeconds == iTotalSeconds) { dataRequest = cSeries.DataRequest; goto exit; } else { cSeries = cSeries.CreateSeries(dataRequest); //利用基礎周期建立其他的資料周期 cStorage.Add(cSeries); //加入至 SeriesStorage } dataRequest.Resolution = cSeries.DataRequest.Resolution; //將目標的週期結構更新至傳入的 InstrumentDataRequest 週期結構 DataRequestEvent cRequestEvent = new DataRequestEvent(dataRequest); cSeries.OnRequest(cRequestEvent); //如果已經存在則請求使用者需要的歷史資料區間(請求方法會檢查目前已下載的歷史資料區間是否足夠, 如果使用者需要的歷史資料區間比較大會向伺服器請求) dataRequest.Range.Count = cRequestEvent.Count; //將請求後的正確數量傳入至結構內 exit: cSeriesRand = new SeriesSymbolDataRand(cSeries, dataRequest); } } else { DataAdapter cAdapter = LoadAdapter(ref dataRequest, false); //重新建立新的基礎週期序列資料(不使用快取, 不保存至快取內, 使用完畢之後立即 Dispose) SeriesSymbolData cSeries = cAdapter.Series; //取得新的基礎周期序列資料 int iBaseSeconds = (iTotalSeconds < Resolution.MAX_BASE_TOTALSECONDS) ? Resolution.MIN_BASE_TOTALSECONDS : Resolution.MAX_BASE_TOTALSECONDS; if (iBaseSeconds == iTotalSeconds) { dataRequest = cSeries.DataRequest; } else { SeriesSymbolData cTargetSeries = cSeries.CreateSeries(dataRequest); //使用 InstrumentDataRequest 建立新的其他週期序列資料 cSeries.Merge(cTargetSeries); //將基礎周期序列資料合併至新的其他週期序列資料 cSeries.Dispose(); //釋放基礎周期序列資料 cSeries = cTargetSeries; } cSeriesRand = new SeriesSymbolDataRand(cSeries, dataRequest); cStorage.Add(cSeries, true); //保存序列資料(存放在 SeriesStorage 內的序列資料才會自動合併最新的即時資訊報價) cAdapter.Dispose(); //釋放資料配置者類別 } return cSeriesRand; }
public bool UpdateAttributeView(List <String> listNew, bool bReadCurrentColumns) { if (bReadCurrentColumns) { m_listColumns.Clear(); foreach (DataGridViewColumn col in dgvAttributeView.Columns) { if (col.HeaderText != "FACILITY" && col.HeaderText != "SECTION" && col.HeaderText != "BEGIN_STATION" && col.HeaderText != "END_STATION" && col.HeaderText != "DIRECTION") { m_listColumns.Add(col.HeaderText); } } } //dsmelser 2008.08.01 //Clear icons SetAllAttributeIconsInactive(); treeNodeTags.Clear(); foreach (String str in listNew) { if (!m_listColumns.Contains(str)) { m_listColumns.Add(str); } } foreach (String str in m_listColumns) { //dsmelser 2008.08.01 //Store the appropriate Tags to change the correct icons int divideIndex = str.LastIndexOf('_'); int throwaway; if (divideIndex >= 0) { string yearName = str.Substring(divideIndex + 1); if (Int32.TryParse(yearName, out throwaway)) { string attributeName = str.Substring(0, str.Length - yearName.Length - 1); treeNodeTags.Add(m_strNetworkID + " " + attributeName + " " + yearName); } else { treeNodeTags.Add(m_strNetworkID + " " + str + " " + str); } } else { treeNodeTags.Add(m_strNetworkID + " " + str + " " + str); } } SetAllAttributeIconsActive(); String strSelect; if (checkMilepost.Checked) { strSelect = "SELECT FACILITY,SECTION,BEGIN_STATION,END_STATION,DIRECTION"; } else { strSelect = "SELECT FACILITY,SECTION"; } String strSimulation = toolStripComboBoxSimulation.Text; String strSimulationID = ""; if (strSimulation != "") { strSimulationID = m_hashSimulationID[strSimulation].ToString(); } List <string> listColumns = new List <string>(); string simulationTable = "SIMULATION_" + m_strNetworkID.ToString() + "_" + strSimulationID.ToString(); if (!string.IsNullOrWhiteSpace(strSimulationID)) { listColumns = DBMgr.GetTableColumns(simulationTable); } ////Then each of the input columns foreach (String str in m_listColumns) { strSelect += ","; if (listColumns.Contains(str)) { strSelect += simulationTable + "."; } strSelect += str; } String strFrom = DBOp.BuildFromStatement(m_strNetworkID, strSimulationID, true); strSelect += strFrom; String strWhere = ""; String strSearch = textBoxAdvanceSearch.Text; strSearch = strSearch.Trim(); if (comboBoxRouteFacilty.Text != "All") { strWhere = " WHERE FACILITY='" + comboBoxRouteFacilty.Text + "'"; strSelect += strWhere; } if (strSearch != "") { strSelect += " AND "; strSelect += "(" + strSearch + ")"; } if (checkBoxCustomFilter.Checked) { if (comboBoxFilterAttribute.Text.Trim() != "") { if (comboBoxAttributeValue.Text.Trim() != "All") { strSelect += " AND "; strSelect += "(" + comboBoxFilterAttribute.Text.Trim() + " = '" + comboBoxAttributeValue.Text.Trim() + "')"; } } } // SELECT field1, field2, field3 // FROM first_table // INNER JOIN second_table // ON first_table.keyfield = second_table.foreign_keyfield if (dataAdapter != null) { dataAdapter.Dispose(); // Free up the resources } if (binding != null) { binding.Dispose(); } if (table != null) { table.Dispose(); } try { binding = new BindingSource(); dataAdapter = new DataAdapter(strSelect); // Populate a new data table and bind it to the BindingSource. table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); binding.DataSource = table; dgvAttributeView.DataSource = binding; bindingNavigatorAttributeView.BindingSource = binding; dgvAttributeView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText; for (int i = 0; i < m_listColumns.Count; i++) { String strCol = m_listColumns[i].ToString(); if (checkMilepost.Checked) { dgvAttributeView.Columns[strCol].DisplayIndex = i + 5; } else { dgvAttributeView.Columns[strCol].DisplayIndex = i + 2; } dgvAttributeView.Columns[strCol].DefaultCellStyle.Format = GetAttributeFormat(strCol); } if (dgvAttributeView.Columns["BEGIN_STATION"] != null) { dgvAttributeView.Columns["BEGIN_STATION"].DefaultCellStyle.Format = "f2"; } if (dgvAttributeView.Columns["END_STATION"] != null) { dgvAttributeView.Columns["END_STATION"].DefaultCellStyle.Format = "f2"; } if (checkMilepost.Checked) { dgvAttributeView.Columns["FACILITY"].DisplayIndex = 0; dgvAttributeView.Columns["SECTION"].DisplayIndex = 1; dgvAttributeView.Columns["BEGIN_STATION"].DisplayIndex = 2; dgvAttributeView.Columns["END_STATION"].DisplayIndex = 3; dgvAttributeView.Columns["DIRECTION"].DisplayIndex = 4; } else { dgvAttributeView.Columns["FACILITY"].DisplayIndex = 0; dgvAttributeView.Columns["SECTION"].DisplayIndex = 1; } //update with validation stuff UpdateValidation(); } catch (Exception exception) { Global.WriteOutput("Error: Building current attribute view, try re-rolling up the network. " + exception.Message); return(false); } return(true); }
private void PasteRows() { bool error = false; Global.ClearOutputWindow(); if (!checkAllowEdit.Checked) { Global.WriteOutput("Note: External data cannot be pasted into a Raw Attribute if Allow Attribute Edit is not checked."); return; } try { dataAdapter.Update(( DataTable )binding.DataSource); } catch (Exception ex) { Global.WriteOutput("ERROR: Could not update table prior to pasting data: " + ex.Message); error = true; } finally { dataAdapter.Dispose(); } if (!error) { String strMyDocumentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); strMyDocumentsFolder += "\\RoadCare Projects\\Temp"; Directory.CreateDirectory(strMyDocumentsFolder); String strOutFile = strMyDocumentsFolder + "\\paste.txt"; TextWriter tw = new StreamWriter(strOutFile); // List of errors during import to print out after PasteRows completes. List <String> listErrors = new List <String>(); bool bLinear = rbLinearRef.Checked; string s = Clipboard.GetText(); s = s.Replace("\r\n", "\n"); string[] lines = s.Split('\n'); try { foreach (string line in lines) { if (line.Length > 0) { //Split on either commas or tabs string[] cells = line.Split(new string[] { "\t" }, StringSplitOptions.None); //INSERT INTO table_name (column1, column2,...)VALUES (value1, value2,....) if (bLinear) { if (cells.Length != 6) { listErrors.Add(line + ": Paste aborted because more/less than 6 columns detected"); return; } //Trim white space. for (int i = 0; i < cells.Length; i++) { cells[i] = cells[i].Trim(); } if (!m_listFacility.Contains(cells[0])) { listErrors.Add(line + "\t not imported because it does not exist in Facility/Route list"); continue; } float fBegin; float fEnd; try { fBegin = float.Parse(cells[1]); fEnd = float.Parse(cells[2]); } catch { listErrors.Add(line + "\t not imported because BEGIN_STATION and END_STATION must be positive numbers"); continue; } if (fBegin > fEnd) { listErrors.Add(line + "\t not imported because BEGIN_STATION must be less or equal to END_STATION"); continue; } if (fBegin < 0 || fEnd < 0) { listErrors.Add(line + "\t not imported because BEGIN_STATION and END_STATION must be positive numbers"); continue; } if (cells[3] == "") { listErrors.Add(line + "\t not imported because DIRECTION must be included."); continue; } DateTime date; try { date = DateTime.Parse(cells[4]); } catch { listErrors.Add(line + "\t not imported because DATE format is incorrect."); continue; } float fNumber; if (!m_bString) { try { fNumber = float.Parse(cells[5]); } catch { listErrors.Add(line + "\t not imported because number expected for data column."); continue; } } String strOut = ""; for (int i = 0; i < cells.Length; i++) { switch (m_cp.Provider) { case "MSSQL": strOut += "\t"; if (i == 4) { strOut += "\t\t\t"; } strOut += cells[i]; break; case "ORACLE": if (i > 0) { strOut += "\t"; } if (i == 4) { strOut += "\t\t\t"; DateTime rowDate = DateTime.Parse(cells[i]); strOut += rowDate.ToString("dd/MMM/yyyy"); } else { strOut += cells[i]; } break; default: throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); } } tw.WriteLine(strOut); } else //SRS { if (cells.Length != 5) { listErrors.Add(line + "Paste aborted because more/less than 5 columns detected"); return; } //Trim white space. for (int i = 0; i < cells.Length; i++) { cells[i] = cells[i].Trim(); } if (!m_listFacility.Contains(cells[0])) { if (!m_listFacilityUpper.Contains(cells[0].ToUpper())) { listErrors.Add(line + "\t not imported because it does not exist in Facility/Route list"); continue; } else { cells[0] = m_listFacility[m_listFacilityUpper.IndexOf(cells[0].ToUpper())]; } } if (cells[1] == "") { listErrors.Add(line + "\t not imported because SECTION must not be blank."); continue; } DateTime date; try { date = DateTime.Parse(cells[3]); } catch { listErrors.Add(line + "\t not imported because DATE format is incorrect."); continue; } float fNumber; if (!m_bString) { try { if (cells[4].ToString() != "") { fNumber = float.Parse(cells[4]); } else { fNumber = float.NaN; } } catch { listErrors.Add(line + "\t not imported because number expected for data column."); continue; } } String strOut = ""; for (int i = 0; i < cells.Length; i++) { switch (m_cp.Provider) { case "MSSQL": strOut += "\t"; break; case "ORACLE": if (i > 0) { strOut += "\t"; } break; default: throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); } if (i == 0) { strOut += "\t\t\t\t"; } strOut += cells[i]; } tw.WriteLine(strOut); } } else { continue; } } } catch (Exception exc) { Global.WriteOutput("Error pasting in data rows. " + exc.Message); } finally { tw.Close(); } switch (DBMgr.NativeConnectionParameters.Provider) { case "MSSQL": DBMgr.SQLBulkLoad(m_strAttribute, strOutFile, '\t'); break; case "ORACLE": List <string> columnNames = new List <string>(); columnNames.Add("ROUTES"); columnNames.Add("BEGIN_STATION"); columnNames.Add("END_STATION"); columnNames.Add("DIRECTION"); columnNames.Add("FACILITY"); columnNames.Add("SECTION"); columnNames.Add("SAMPLE_"); columnNames.Add("DATE_"); columnNames.Add("DATA_"); try { DBMgr.OracleBulkLoad(DBMgr.NativeConnectionParameters, m_strAttribute, strOutFile, columnNames, "\\t"); } catch (Exception ex) { Global.WriteOutput("Oracle bulk load failed: " + ex.Message); } break; default: throw new NotImplementedException("TODO: Create ANSI implementation for XXXXXXXXXXXX"); } CreateDataGridView(); // Create error output in Output window. String strError = ""; Global.ClearOutputWindow(); foreach (String str in listErrors) { strError += str + "\r\n"; } if (strError != "") { Global.WriteOutput(strError); } } }