//data save section private void btnsave_Click(object sender, EventArgs e) { DboTrainsEntities1 entit = new DboTrainsEntities1(); int station1 = (int)cmbs1.SelectedValue; int station2 = (int)cmbs2.SelectedValue; //query for check data avalibility var remove = (from aremove in entit.Tbdistances where aremove.station1Id == station1 && aremove.station2id == station2 select aremove).FirstOrDefault(); //check data avalible or not if (remove != null) { MessageBox.Show("Existing Data"); } else { //get station1 data to variable string station1String = station1.ToString(); //get station2 data to variable string station2String = station2.ToString(); //get distance data to variable string distances = txtdistance.Text.ToString(); //create array string[,] stationDistances = new string[1, 3]; //add data to array stationDistances[0, 0] = station1String; stationDistances[0, 1] = station2String; stationDistances[0, 2] = distances; //start stop watch Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Thread.Sleep(5000); //retrive data from array and insert data to database for (int J = 0; J < stationDistances.GetLength(0); J++) { Tbdistance PTE = new Tbdistance(); PTE.station1Id = Convert.ToInt32(stationDistances[J, 0]); PTE.station2id = Convert.ToInt32(stationDistances[J, 1]); PTE.distance = Convert.ToInt32(stationDistances[J, 2]); entit.Tbdistances.Add(PTE); entit.SaveChanges(); Tbdistance PTE2 = new Tbdistance(); PTE2.station1Id = Convert.ToInt32(stationDistances[J, 1]); PTE2.station2id = Convert.ToInt32(stationDistances[J, 0]); PTE2.distance = Convert.ToInt32(stationDistances[J, 2]); entit.Tbdistances.Add(PTE2); entit.SaveChanges(); } //end stop watch stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; //show spending times lblInsert.Text = " Data Insert Time: " + stopwatch.ElapsedMilliseconds + " Ms"; } }
//open minimum connecters algorithm app private void btnmincon_Click(object sender, EventArgs e) { DboTrainsEntities1 entit = new DboTrainsEntities1(); var cc = (from p in entit.TbStations select new { id = p.id, name = p.Name }); var vv = cc.ToList(); List <TbStation> v = new List <TbStation>(); foreach (var val in vv) { TbStation s = new TbStation(); s.id = val.id; s.Name = val.name; v.Add(s); } var cc2 = (from p in entit.Tbdistances select new { id = p.id, station1 = p.station1Id, station2 = p.station2id, distance = p.distance }); var vv2 = cc2.ToList(); List <Tbdistance> v1 = new List <Tbdistance>(); foreach (var val in vv2) { Tbdistance s1 = new Tbdistance(); s1.id = val.id; s1.station1Id = val.station1; s1.station2id = val.station2; s1.distance = val.distance; v1.Add(s1); } Form1 f = new Form1(v1, v); f.Show(); }