private void cableAddButton_Click(object sender, EventArgs e) { //the function first checks the correctness of the entered data, and then the "CableAdd" function is called double prestressForce; double friction; bool prestressForceisDouble = Double.TryParse(prestressForceTextbox.Text, out prestressForce); bool frictionForceisDouble = Double.TryParse(frictionTextBox.Text, out friction); if (systemNameTextbox.Text == "" || nrCableTypbox.Text == "" || quantitiyCableTextbox.Text == "" || frictionTextBox.Text == "") { MessageBox.Show("Wypełnij wszystkie pola!", "Błąd"); } else if (!prestressForceisDouble) { MessageBox.Show("Siła sprężająca w złym formacie"); } else if (!frictionForceisDouble) { MessageBox.Show("Tarcie w złym formacie"); } else if (dataGridView2.Rows.Count < 3) { MessageBox.Show("Rzędne kabla zostały nieprawidłowo wprowadzone."); } else if (!cableBeginActive.Checked && !cableEndActive.Checked) { MessageBox.Show("Zakotwienie czynne musi być chociaż z jednej strony"); } else if (System.Text.RegularExpressions.Regex.IsMatch(quantitiyCableTextbox.Text, "[^0-9]")) { MessageBox.Show("Prosze wpisać ilość kabli w odpowiednim formacie", "błąd"); quantitiyCableTextbox.Clear(); } else { CableDrawing(); Ordinates(); Cable cable = new Cable(systemNameTextbox.Text, Int32.Parse(nrCableTypbox.Text), Int32.Parse(quantitiyCableTextbox.Text), Double.Parse(prestressForceTextbox.Text), Double.Parse(frictionTextBox.Text), cableBeginActive.Checked, cableEndActive.Checked); cable.cableOrdinates = Ordinates(); CableAdd(Int32.Parse(nrCableTypbox.Text), cable); } }
public ReviewForces(Cable k) { InitializeComponent(); systemNameLabel.Text = k.systemName; nrCableLabel.Text = k.nrCable.ToString(); quantityCableLabel.Text = k.quantityCable.ToString(); prestressForceLabel.Text = k.prestressForce.ToString(); for (int i = 0; i < k.Forces().Count(); i++) { silyDataGridView.Rows.Add((i + 1).ToString(), k.Forces()[i].X.ToString("N2"), k.Forces()[i].Y.ToString("N2")); } }
public void CableAdd(int nrCable, Cable k) // adds a cable to the list "cables" { if (cables.ContainsKey(nrCable) == false) { cables[nrCable] = k; } else { DialogResult dialogResult = MessageBox.Show("Dany nr kabla już istnieje. Czy chcesz go nadpisać?", "Nadpisanie kabla", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { cables.Remove(nrCable); cables[nrCable] = k; } } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) // open file dialog and clears everything { OpenFileDialog openFileDialog1 = new OpenFileDialog(); TextClear(); cables.Clear(); try { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open); StreamReader sr = new StreamReader(fs); string line; string[] ordinatesTemp; List <string> text = new List <string>(); while ((line = sr.ReadLine()) != null) { text.Add(line); } for (int i = 0; i < text.Count(); i++) { if (text[i].Contains("Cable nr: ")) { Cable k = new Cable(); k.nrCable = Int32.Parse(text[i].Remove(0, 9)); k.systemName = text[i + 1].Remove(0, 15); k.prestressForce = Double.Parse(text[i + 2].Remove(0, 22)); k.friction = Double.Parse(text[i + 3].Remove(0, 21)); k.quantityCable = Int32.Parse(text[i + 4].Remove(0, 13)); k.cableBeginActive = bool.Parse(text[i + 5].Remove(0, 35)); k.cableEndActive = bool.Parse(text[i + 6].Remove(0, 33)); //----------------------------------write ordinates to datagridview-------------------------------------------- int n = 0; for (int j = i + 10; text[j] != ""; j++) { n++; } n = 0; for (int j = i + 10; text[j] != ""; j++) { ordinatesTemp = (Regex.Split(text[j], "\t")); ordinates.Add(new Point() { X = Double.Parse(ordinatesTemp[1]), Y = Double.Parse(ordinatesTemp[2]) }); n++; } k.cableOrdinates = ordinates; cables[k.nrCable] = k; } } systemNameTextbox.Text = cables[1].systemName; prestressForceTextbox.Text = cables[1].prestressForce.ToString(); quantitiyCableTextbox.Text = cables[1].quantityCable.ToString(); frictionTextBox.Text = cables[1].friction.ToString(); cableBeginActive.Checked = cables[1].cableBeginActive; cableEndActive.Checked = cables[1].cableEndActive; for (int i = 0; i < cables[1].cableOrdinates.Count(); i++) { dataGridView2.Rows.Add(cables[1].cableOrdinates.ElementAt(i).X, cables[1].cableOrdinates.ElementAt(i).Y); } CableDrawing(); nrCableTypbox.Text = "1"; sr.Close(); } else { MessageBox.Show("Plik nie istnieje!", "Błąd"); } } catch (Exception exc) { MessageBox.Show("Plik uszkodzony: " + exc.Message); } }