Example #1
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";
            }
        }
Example #2
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");
            }
        }
Example #3
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  = "";
        }
Example #4
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 = "";
        }
Example #5
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 = "";
            }
        }
Example #6
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 = "";
            }
        }