Пример #1
0
        //data insert section
        private void btntsave_Click(object sender, EventArgs e)
        {
            DboTrainsEntities1 entit       = new DboTrainsEntities1();
            string             stationName = textBox1.Text.ToString();

            //array created
            string[]  InsertArray = new string[1];
            Stopwatch stopwatch   = new Stopwatch();

            stopwatch.Start();

            //set value to array
            InsertArray[0] = stationName;

            //retrive data from array and insert to database
            for (int J = 0; J < InsertArray.Length; J++)
            {
                TbStation PTE = new TbStation();
                PTE.Name = InsertArray[J];
                entit.TbStations.Add(PTE);
                entit.SaveChanges();
            }
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            //show spending times
            Lblinsert.Text = " Data Insert Time: " + stopwatch.ElapsedMilliseconds + " Ms";
            textBox1.Text  = "";
        }
Пример #2
0
        //print the shortest paths
        void printPath(int currentVertex,
                       int[] parents)
        {
            String StationName = "";

            if (currentVertex == NO_PARENT)
            {
                return;
            }

            DboTrainsEntities1 entit = new DboTrainsEntities1();
            var StationStart         = (from p in entit.TbStations
                                        where p.id == currentVertex + 1
                                        select new
            {
                name = p.Name,
            });

            var vv2 = StationStart.ToList();

            foreach (var val2 in vv2)
            {
                StationName = val2.name;
            }


            printPath(parents[currentVertex], parents);
            showLbl.Text += StationName + "-->";
        }
Пример #3
0
        //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";
            }
        }
Пример #4
0
        //show station distances
        public void showstation()
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            //get data from database
            var cc = (from p in entit.Tbdistances
                      join e in entit.TbStations on p.station1Id equals e.id
                      join y in entit.TbStations on p.station2id equals y.id
                      select new
            {
                id = p.id,
                station1name = e.Name,
                station2name = y.Name,
                distances = p.distance
            });
            //convert to list
            var vv = cc.ToList();

            dgvdistances.DataSource = vv;
            //var rowcount = cc.Count();
            //create array
            // string[,] arr = new string[rowcount, 4];
            //int index = 0;
            ////add database data to array
            //foreach (var val in vv)
            //{
            //arr[index, 0] = val.id.ToString();
            // arr[index, 1] = val.station1name;
            // arr[index, 2] = val.station2name;
            // arr[index, 3] = val.distances.ToString();
            //index++;
            //}

            //Stopwatch stopwatch = new Stopwatch();

            //stopwatch.Start();
            //Thread.Sleep(5000);
            //retrive data from array
            //for (int i = 0; i < arr.GetLength(0); i++)
            //{


            // string[] row = new string[arr.GetLength(1)];

            // for (int J = 0; J < arr.GetLength(1); J++)
            // {
            //row[J] = arr[i, J];
            //}

            //dgvdistances.Rows.Add(row);
            // }

            // stopwatch.Stop();
            //TimeSpan ts = stopwatch.Elapsed;
            //show spending time
            //lblLoadEx.Text = " Data Load Time: " + stopwatch.ElapsedMilliseconds + " Ms";
        }
Пример #5
0
        //update section
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            int    station1          = (int)cmbs1.SelectedValue;
            int    station2          = (int)cmbs2.SelectedValue;
            string station1String    = station1.ToString();
            string station2String    = station2.ToString();
            string distances         = txtdistance.Text.ToString();

            //query for data avalibility
            var remove = (from aremove in entit.Tbdistances
                          where aremove.station1Id == station1 && aremove.station2id == station2
                          select aremove).FirstOrDefault();

            //create array
            string[,] stationDistances = new string[1, 3];
            //set data to array
            stationDistances[0, 0] = station1String;
            stationDistances[0, 1] = station2String;
            stationDistances[0, 2] = distances;
            //check data avalible or not
            if (remove != null)
            {
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();
                Thread.Sleep(5000);
                //retrive data from array and update data
                for (int J = 0; J < stationDistances.GetLength(0); J++)
                {
                    int station1Id = Convert.ToInt32(stationDistances[J, 0]);
                    int station2Id = Convert.ToInt32(stationDistances[J, 1]);
                    int distances2 = Convert.ToInt32(stationDistances[J, 2]);

                    //a to b = 10KM
                    var UpdateDeTable = (from id1 in entit.Tbdistances where id1.station1Id == station1Id && id1.station2id == station2Id select id1).FirstOrDefault();
                    UpdateDeTable.distance = distances2;
                    entit.SaveChanges();
                    //b to a = 10KM
                    var UpdateDeTable2 = (from id11 in entit.Tbdistances where id11.station1Id == station2Id && id11.station2id == station1Id select id11).FirstOrDefault();
                    UpdateDeTable2.distance = distances2;
                    entit.SaveChanges();
                }

                stopwatch.Stop();
                TimeSpan ts = stopwatch.Elapsed;
                //display spending time to update
                lblUp.Text = " Data Update Time: " + stopwatch.ElapsedMilliseconds + " Ms";
            }
            else
            {
                MessageBox.Show("Not Avalible Data");
            }
        }
Пример #6
0
        //data load section
        public void showstation()
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            //get data from database
            var cc = (from p in entit.TbStations
                      select new
            {
                id = p.id,
                name = p.Name
            });

            var vv = cc.ToList();

            dgvstation.DataSource = vv;
            //var rowcount = cc.Count();
            //created array
            //string[,] arr = new string[rowcount, 2];
            //int index = 0;
            //load data to array from database when start the application
            //foreach (var val in vv)
            //{
            //arr[index, 0] = val.id.ToString();
            // arr[index, 1] = val.name;
            //index++;
            //}

            //Stopwatch stopwatch = new Stopwatch();

            //stopwatch.Start();
            //
            //display data in gridView from array
            //for (int i = 0; i<arr.GetLength(0);i++)
            //{


            // string [] row = new string [arr.GetLength(1)];

            //for (int J = 0; J < arr.GetLength(1); J++)
            //{
            //row[J] = arr[i, J];
            //}

            //dgvstation.Rows.Add(row);
            //}

            //stopwatch.Stop();
            //TimeSpan ts = stopwatch.Elapsed;
            // show data retrive time from array
            //lblshowtime.Text = " Data Load Time: "+ stopwatch.ElapsedMilliseconds+" Ms";

            //dgvstation.Rows.Add(vv);
            //vstation.DataBind();
        }
Пример #7
0
        //function to print shortest path distance,path
        void printSolution(int startVertex,
                           int[] distances,
                           int[] parents)
        {
            int nVertices = distances.Length;

            showLbl.Text = "";
            for (int vertexIndex = 0;
                 vertexIndex < nVertices;
                 vertexIndex++)
            {
                if (vertexIndex != startVertex)
                {
                    String             StationName    = "";
                    String             StationEndName = "";
                    DboTrainsEntities1 entit          = new DboTrainsEntities1();
                    //identify start station name according to selected vertex
                    var StationStart = (from p in entit.TbStations
                                        where p.id == startVertex + 1
                                        select new
                    {
                        name = p.Name,
                    });

                    var vv2 = StationStart.ToList();

                    foreach (var val2 in vv2)
                    {
                        StationName = val2.name;
                    }
                    //identify end station name according to selected vertex
                    var EndStation = (from p in entit.TbStations
                                      where p.id == vertexIndex + 1
                                      select new
                    {
                        name = p.Name,
                    });

                    var vv22 = EndStation.ToList();

                    foreach (var val21 in vv22)
                    {
                        StationEndName = val21.name;
                    }
                    //set user input data to display
                    showLbl.Text += "\n\n" + StationName + " to " + StationEndName + "               " + distances[vertexIndex] + "                  ";


                    printPath(vertexIndex, parents);
                }
            }
        }
Пример #8
0
        //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();
        }
Пример #9
0
        //load stations to combo box
        void loadData()
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            var StationStart         = (from p in entit.TbStations

                                        select new
            {
                name = p.Name,
                id = p.id
            });

            var vv2 = StationStart.ToList();


            cmbValues.DataSource    = vv2;
            cmbValues.DisplayMember = "name";
            cmbValues.ValueMember   = "id";
        }
Пример #10
0
        //data delete section
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();

            //create array
            int[] DeleteArray = new int[1];
            //set data to array
            DeleteArray[0] = Convert.ToInt32(txtdeleteid.Text);

            Stopwatch stopwatch = new Stopwatch();

            //start stop watch
            stopwatch.Start();
            Thread.Sleep(5000);
            //retrive data from array and delete data
            for (int J = 0; J < DeleteArray.Length; J++)
            {
                int idx    = DeleteArray[J];
                var remove = (from aremove in entit.Tbdistances
                              where aremove.id == idx
                              select aremove).FirstOrDefault();
                //check data avalibility
                if (remove != null)
                {
                    int stationid1 = Convert.ToInt32(remove.station1Id);
                    int stationid2 = Convert.ToInt32(remove.station2id);


                    entit.Tbdistances.Remove(remove);
                    entit.SaveChanges();
                }
                else
                {
                    MessageBox.Show("Not Avalible Data");
                }
            }
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            //display spending times to delete
            lbldeleteex.Text = " Data Delete Time: " + stopwatch.ElapsedMilliseconds + " Ms";

            txtdeleteid.Text = "";
        }
Пример #11
0
        //station combo box
        private void cmb2Load()
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            var StationStart         = (from p in entit.TbStations

                                        select new
            {
                name = p.Name,
                id = p.id
            });

            var vv2 = StationStart.ToList();



            //set station data to combo box
            cmbs2.DataSource    = vv2;
            cmbs2.DisplayMember = "name";
            cmbs2.ValueMember   = "id";
        }
Пример #12
0
        //delete section
        private void btntdelete_Click(object sender, EventArgs e)
        {
            string id = txtid.Text.ToString();

            if (id == "")
            {
                MessageBox.Show("Please Select cell from grid before Delete", "warning");
            }
            else
            {
                DboTrainsEntities1 entit = new DboTrainsEntities1();
                //create array
                int[] DeleteArray = new int[1];
                //add array data
                DeleteArray[0] = Convert.ToInt32(id);

                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();

                //retrive data from array and delete data
                for (int J = 0; J < DeleteArray.Length; J++)
                {
                    int idx    = DeleteArray[J];
                    var remove = (from aremove in entit.TbStations
                                  where aremove.id == idx
                                  select aremove).FirstOrDefault();
                    if (remove != null)
                    {
                        entit.TbStations.Remove(remove);
                        entit.SaveChanges();
                    }
                }
                stopwatch.Stop();
                TimeSpan ts = stopwatch.Elapsed;
                //display spending time for delete task
                lbldeex.Text = " Data Delete Time: " + stopwatch.ElapsedMilliseconds + " Ms";

                textBox1.Text = "";
            }
        }
Пример #13
0
        //load data section
        private void Distances_Load(object sender, EventArgs e)
        {
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            var StationStart         = (from p in entit.TbStations

                                        select new
            {
                name = p.Name,
                id = p.id
            });

            var vv2 = StationStart.ToList();


            cmbs1.DataSource    = vv2;
            cmbs1.DisplayMember = "name";
            cmbs1.ValueMember   = "id";



            showstation();
            cmb2Load();
        }
Пример #14
0
        //update section
        private void btntupdate_Click(object sender, EventArgs e)
        {
            string stationName = textBox1.Text.ToString();
            string id          = txtid.Text.ToString();

            if (id == "")
            {
                MessageBox.Show("Please Select cell from grid before update", "warning");
            }
            else
            {
                DboTrainsEntities1 entit = new DboTrainsEntities1();
                //create array for update
                string[,] station = new string[1, 2];
                //set  value to array
                station[0, 0] = id;
                station[0, 1] = stationName;
                Stopwatch stopwatch = new Stopwatch();

                stopwatch.Start();

                //get data from array and update data
                for (int J = 0; J < station.GetLength(0); J++)
                {
                    int sId           = Convert.ToInt32(station[J, 0]);
                    var UpdateDeTable = (from id1 in entit.TbStations where id1.id == sId select id1).FirstOrDefault();
                    UpdateDeTable.Name = station[J, 1];
                    entit.SaveChanges();
                }

                stopwatch.Stop();
                TimeSpan ts = stopwatch.Elapsed;
                // display spending time for update task
                lblupex.Text  = " Data Update Time: " + stopwatch.ElapsedMilliseconds + " Ms";
                textBox1.Text = "";
            }
        }
Пример #15
0
        void startAlgorithm()
        {
            //int selectedValue = Convert.ToInt32(cmbValues.ValueMember);

            //get the selected station from the combobox
            int selectedValueRetrive = (int)cmbValues.SelectedValue;
            int selectedValue        = selectedValueRetrive - 1;
            DboTrainsEntities1 entit = new DboTrainsEntities1();
            //get station Id's from database
            var cc = (from p in entit.TbStations
                      select new
            {
                id = p.id,
            });
            //convert station id to list
            var vv = cc.ToList();
            //get station count
            var rowcount = cc.Count();

            //initialize the 2d array
            int[,] arr = new int[rowcount, rowcount];

            int row    = 0;
            int column = 0;

            //arrary row data
            foreach (var val in vv)
            {
                column = 0;
                int id = val.id;
                //array column data
                for (int i = 1; i <= rowcount; i++)
                {
                    //get distances from database
                    var Distance = (from p in entit.Tbdistances
                                    where p.station1Id == id && p.station2id == i
                                    select new
                    {
                        distances = p.distance,
                    });
                    //convert to list
                    var vv2 = Distance.ToList();
                    //check distances value
                    foreach (var val2 in vv2)
                    {
                        if (val2.distances == null)
                        {
                            arr[row, column] = 0;
                        }
                        else
                        {
                            //set station details to array
                            arr[row, column] = Convert.ToInt32(val2.distances);
                        }
                    }

                    column++;
                }
                row++;
            }



            int[,] adjacencyMatrix = { { 0, 4 },
                                       { 5, 0 }, };
            //send the 2d array and startvertex to the algorithm function
            dijkstra(arr, selectedValue);
        }