private void btnNewKey_Click(object sender, EventArgs e) { // Imports new (user-defined) land cover key and updates the land cover key table on form if (thisInst.ofdLC_Key.ShowDialog() == DialogResult.OK) { string wholePath = thisInst.ofdLC_Key.FileName; int ind = wholePath.LastIndexOf('\\'); StreamReader sr = new StreamReader(wholePath); string[] fileRow; TopoInfo.LC_SR_DH[] newLC_Key = null; int LC_Count = 0; while (sr.EndOfStream == false) { var dataStr = sr.ReadLine(); fileRow = dataStr.Split(','); if (fileRow.Length == 4) { Array.Resize(ref newLC_Key, LC_Count + 1); newLC_Key[LC_Count] = new TopoInfo.LC_SR_DH(); try { newLC_Key[LC_Count].code = Convert.ToInt16(fileRow[0]); newLC_Key[LC_Count].desc = fileRow[1]; newLC_Key[LC_Count].SR = Convert.ToSingle(fileRow[2]); newLC_Key[LC_Count].DH = Convert.ToSingle(fileRow[3]); } catch { MessageBox.Show("Error reading land cover key. Format of file should be: Code, Description, Surface roughness, Displacement height.", "Continuum 3"); sr.Close(); return; } LC_Count++; } else { MessageBox.Show("Error reading in the land cover key at line: " + LC_Count + "The format should be Code, Description, Surface roughness, Displacement height.", "Continuum 3"); sr.Close(); return; } } sr.Close(); LC_Key_New = newLC_Key; thisInst.Populate_LC_Key_Form(this); } }
private void btnModKey_Click(object sender, EventArgs e) { // Opens the Mod_LC_Key form with the selected land cover code, description, SR, and DH for the user to edit. if (lstLC_SR_DH.SelectedItems.Count == 0) { MessageBox.Show("Select a land cover code to modify.", "Continuum 3"); return; } TopoInfo.LC_SR_DH thisLC = new TopoInfo.LC_SR_DH(); thisLC.code = Convert.ToInt16(lstLC_SR_DH.SelectedItems[0].Text); thisLC.desc = lstLC_SR_DH.SelectedItems[0].SubItems[1].Text; thisLC.SR = Convert.ToSingle(lstLC_SR_DH.SelectedItems[0].SubItems[2].Text); thisLC.DH = Convert.ToSingle(lstLC_SR_DH.SelectedItems[0].SubItems[3].Text); Mod_LC_Key thisMod = new Mod_LC_Key(thisInst, this); thisMod.txtCode.Text = thisLC.code.ToString(); thisMod.txtDesc.Text = thisLC.desc; thisMod.txtSR.Text = Math.Round(thisLC.SR, 3).ToString(); thisMod.txtDH.Text = Math.Round(thisLC.DH, 1).ToString(); if (cboLC_Key.SelectedIndex == 0) { thisInst.topo.SetUS_NLCD_Key(); } else if (cboLC_Key.SelectedIndex == 1) { thisInst.topo.SetNA_LC_Key(); } else if (cboLC_Key.SelectedIndex == 2) { thisInst.topo.SetEU_Corine_LC_Key(); } thisMod.ShowDialog(); LC_Key_New = thisMod.thisLC_Key.LC_Key_New; }