private void Listview1_removebtn_Click(object sender, RoutedEventArgs e) { while (listView1.SelectedItems.Count > 0) { //Update listView1 VariationDataSource.Variation v = listView1.SelectedItems[0] as VariationDataSource.Variation; //Variations Vs = listView1.ItemsSource as Variations; Variations.Remove(v); //Update Par_ListBox Parameters Ps = new Parameters(Variations); Par_ListBox.ItemsSource = Ps; //Update T-way ComboBox updateComboBox(); //Update constrain tab this.listBox3.Items.Clear(); this.Iftextbox.Clear(); this.Thentextbox.Clear(); } this.button6.IsEnabled = false; }
private void Addbtn_Click(object sender, RoutedEventArgs e) { foreach (VariationDataSource.Variation v in Variations) { if (v.Parameter == this.textBox1.Text.Trim()) { MessageBox.Show("The " + "\"" + v.Parameter + "\"" + " Parameter has been existed in the table"); this.textBox1.Clear(); this.textBox2.Clear(); return; } } string value = this.textBox2.Text.Trim().Replace(",", ",").TrimEnd(','); VariationDataSource.Variation V = new VariationDataSource.Variation() { Parameter = this.textBox1.Text.Trim(), Value = value }; Variations.Add(V); this.textBox1.Clear(); this.textBox2.Clear(); this.textBox1.Focus(); //Update T-way comboBox updateComboBox(); //Update Par_ListBox Parameters Ps = new Parameters(Variations); Par_ListBox.ItemsSource = Ps; //Update constrain tab this.listBox3.Items.Clear(); this.Iftextbox.Clear(); this.Thentextbox.Clear(); }
private void Loaddata(string filename) { string extension = System.IO.Path.GetExtension(filename); if (extension == ".txt") { //######################################################### //Read from Text file //######################################################### StreamReader streamReader = new StreamReader(filename); string line; while ((line = streamReader.ReadLine()) != null) { string par = line.Replace(";", ";").Substring(0, line.IndexOf(":")).Trim(); string val = line.Replace(",", ",").Substring(line.IndexOf(':') + 1).Trim().TrimEnd(",".ToCharArray()); var v = new VariationDataSource.Variation() { Parameter = par, Value = val }; Variations.Add(v); } } if (extension == ".xls") { //######################################################### //Read from Excel 2003 //######################################################### FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read); //Reading from a binary Excel file ('97-2003 format; *.xls) IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream); DataTable result = excelReader.AsDataSet().Tables[0]; int Rows_Count = result.Rows.Count; for (int i = 0; i < Rows_Count; i++) { var v = new VariationDataSource.Variation() { Parameter = result.Rows[i][0].ToString().Replace(";", ";").Trim(), Value = result.Rows[i][1].ToString().Replace(",", ",").Trim().TrimEnd(",".ToCharArray()) }; Variations.Add(v); } //Free resources (IExcelDataReader is IDisposable) excelReader.Close(); } if (extension == ".xlsx") { //######################################################### //Read from Excel 2007 //######################################################### FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read); //Reading from a OpenXml Excel file (2007 format; *.xlsx) IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); DataTable result = excelReader.AsDataSet().Tables[0]; int Rows_Count = result.Rows.Count; for (int i = 0; i < Rows_Count; i++) { var v = new VariationDataSource.Variation() { Parameter = result.Rows[i][0].ToString().Replace(";", ";").Trim(), Value = result.Rows[i][1].ToString().Replace(",", ",").Trim().TrimEnd(",".ToCharArray()) }; Variations.Add(v); } //Free resources (IExcelDataReader is IDisposable) excelReader.Close(); } //Update ComboBox updateComboBox(); //Update Par_ListBox Parameters Ps = new Parameters(Variations); Par_ListBox.ItemsSource = Ps; //Update constrain tab this.listBox3.Items.Clear(); this.Iftextbox.Clear(); this.Thentextbox.Clear(); }
private void Addbtn_Click(object sender, RoutedEventArgs e) { foreach(VariationDataSource.Variation v in Variations) { if (v.Parameter == this.textBox1.Text.Trim()) { MessageBox.Show("The " + "\"" + v.Parameter + "\"" + " Parameter has been existed in the table"); this.textBox1.Clear(); this.textBox2.Clear(); return; } } string value = this.textBox2.Text.Trim().Replace(",", ",").TrimEnd(','); VariationDataSource.Variation V = new VariationDataSource.Variation() { Parameter = this.textBox1.Text.Trim(), Value = value }; Variations.Add(V); this.textBox1.Clear(); this.textBox2.Clear(); this.textBox1.Focus(); //Update T-way comboBox updateComboBox(); //Update Par_ListBox Parameters Ps = new Parameters(Variations); Par_ListBox.ItemsSource = Ps; //Update constrain tab this.listBox3.Items.Clear(); this.Iftextbox.Clear(); this.Thentextbox.Clear(); }