private void CbxGates_SelectedIndexChanged(object sender, EventArgs e) { foreach (GATES gate in Enum.GetValues(typeof(GATES))) { if (gate.ToString().Equals(cbxGates.Text)) { selectedGate = gate; break; } } }
//Load data from file public virtual void Load(string GATESFileName) { StreamReader GATESFile = File.OpenText(GATESFileName); var warnings = new List <string>(); int index = GATESFileName.LastIndexOf("\\", StringComparison.Ordinal); string GATESFilePath = GATESFileName.Remove(index); //Read number of gate groups in .GATES file: string nGroups = GATESFile.ReadLine(); int numberOfGroups = Convert.ToInt32(nGroups); AddVariable("NUMBER_OF_GATES", numberOfGroups); //Reset data structs to store .GATES data in local memory: var mainTable = new List <string[]>(); GATESFileContents.Clear(); // //(Code space for individual variables) // for (int i = 0; i < numberOfGroups; ++i) { //Read all rest of data groups from .GATES file.... try { //Gate name: string gateName = GATESFile.ReadLine().Trim(); //Crest elevation, gate height, and Cd. string parameters = GATESFile.ReadLine(); string[] split = parameters.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); string crestElevation = split[0]; string gateHeight = split[1];; string Cd = split[2]; //Secondary table (Gates openings table) file name: string secondaryTableFileName = GATESFile.ReadLine().Trim(); //Read extra lines: int nExtraLines = Convert.ToInt32(GATESFile.ReadLine().Trim()); var lines = new string[nExtraLines]; for (var ii = 0; ii < nExtraLines; ++ii) { lines[ii] = GATESFile.ReadLine(); } //Create this group from data just read: var group = new GATES(); group.GateName = gateName; group.Parameters = parameters; group.SecondaryFileName = secondaryTableFileName; group.nExtraLines = nExtraLines; group.ExtraData = lines; //Store data in memory for this apenings group: GATESFileContents.Add(group); //Store in mainTable a row to be shown in gates table in DIP tab: //(gate name, crest elevation, gate height, Cd, openings table name) var row = new string[5]; row[0] = gateName; row[1] = crestElevation; row[2] = gateHeight; row[3] = Cd; row[4] = secondaryTableFileName; mainTable.Add(row); //Potential new openings group (secundary dependant table). Openings (time, aperture) is // stored in a file whose name could be repeated in the .GATES file for another gate. Only one copy of the file contents is //stored in memory in OpeningsFiles (of GATEOpenings structure). If modified, only that copy is changed. //It will be permanently stored when the user clicks "Save .GATES". Universal.LoadSecondaryTable("GATES", GATESFilePath + "\\" + secondaryTableFileName, ref warnings); } catch (Exception ex) { MessageBox.Show(Universal.Idioma("ERROR 2304171526: error while proccessing ", "ERROR 2304171526: error procesando ") + GATESFileName + ". " + Environment.NewLine + ex.Message, "RiverFlow2D", MessageBoxButtons.OK, MessageBoxIcon.Error); } } GATESFile.Close(); //Save variables associated to control tags: AddVariable("GATES_VALUES", mainTable); // // // Empty lines left intentionally if (warnings.Count > 0) { string warningsList = Universal.Idioma("WARNING 2003171725: The following gates files do not exist: \n\n", "WARNING 2003171725: Los siguientes archivos no existen: \n\n"); for (int i = 0; i < warnings.Count; i++) { warningsList += " ° " + warnings[i] + "\n"; } warningsList += Universal.Idioma("\nDefault files were created.", "\nAchivos por defecto fueron creados."); MessageBox.Show(warningsList, "RiverFlow2D", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }