Пример #1
0
        public void insertNewStopWithDoubleSubmittingTest()
        {
            #region prepare testing data
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            int lineId1 = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            int lineId2 = Convert.ToInt32(_coreDb.ExecuteScalar());
            #endregion

            Thread.Sleep(CONST_SLEEP_TIME);

            BusWeb.Spi.Spi target       = new BusWeb.Spi.Spi();
            int            lineID       = lineId1;
            string         stopName     = "測試路線";
            double         longitude    = 123F;
            double         latitude     = 25F;
            double         curLongitude = 124F;
            double         curLatitude  = 26F;
            string         owner        = "DOWILL";
            string         culture      = "zh-TW";

            target.insertNewStop(lineID, stopName, longitude, latitude, curLongitude, curLatitude, owner, culture);

            Thread.Sleep(CONST_SLEEP_TIME);

            target.insertNewStop(lineID, stopName, longitude, latitude, curLongitude, curLatitude, owner, culture);

            Thread.Sleep(CONST_SLEEP_TIME);

            #region verifying
            DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Lines";
            _coreDb.Fill(dt);
            Assert.AreEqual <int>(2, dt.Count, "Line count should be 2!");

            DsBusWeb.Line2StopDataTable dt2 = new DsBusWeb.Line2StopDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Line2Stop";
            _coreDb.Fill(dt2);
            Assert.AreEqual <int>(1, dt2.Count, "Stops should be only 1 links!");

            DsBusWeb.StopsDataTable dt3 = new DsBusWeb.StopsDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Stops";
            _coreDb.Fill(dt3);
            Assert.AreEqual <int>(1, dt3.Count, "Stops should be 1 stops!");

            var dr = dt3[0];
            Assert.AreEqual <string>(stopName, dr.StopName, "StopName is incorrect!");
            Assert.AreEqual <double>(longitude, dr.Longitude, "Longitude is incorrect!");
            Assert.AreEqual <double>(latitude, dr.Latitude, "Latitude is incorrect!");
            Assert.AreEqual <double>(curLongitude, dr.CreatorLongitude, "CreatorLongitude is incorrect!");
            Assert.AreEqual <double>(curLatitude, dr.CreatorLatitude, "CreatorLatitude is incorrect!");
            Assert.AreEqual <string>(owner, dr.Owner, "Owner is incorrect!");
            Assert.AreEqual(culture, dr["Culture"], "Culture is incorrect!");
            #endregion
        }
Пример #2
0
        private void insertNewStop(int lineID, string stopName, double longitude, double latitude, double curLongitude, double curLatitude, string owner, string culture)
#endif
        {
            _log.Info(MethodInfo.GetCurrentMethod().Name);
            #region issue #38 http://dowill-svr/btnet/edit_bug.aspx?id=38
            string hashData = string.Format("{0}{1}{2}{3}{4}", lineID, stopName, longitude, latitude, owner);
            lock (_preventDupSet)
            {
                if (_preventDupSet.Contains(hashData))
                {
                    _preventDupSet.Clear();
                    return;
                }
                _preventDupSet.Add(hashData);
            }
            #endregion

            var dr = new DsBusWeb.StopsDataTable().NewStopsRow();
            dr.Latitude         = latitude;
            dr.Longitude        = longitude;
            dr.StopName         = stopName;
            dr.CreatorLongitude = curLongitude;
            dr.CreatorLatitude  = curLatitude;
            dr.Culture          = culture;
            dr.Owner            = ((string.IsNullOrEmpty(owner)) ? "SYSTEM" : owner);

            var db = BusWebDataService.GetServiceInstance();
            dr.StopID = db.InsertNewStop(dr);
            var dr2 = new DsBusWeb.Line2StopDataTable().NewLine2StopRow();
            dr2.StopID = dr.StopID;
            dr2.LineID = lineID;
            db.InsertNewLine2StopRelation(dr2);



            #region Do remove bad rating stops and data merging
            lock (typeof(Spi))
            {
                if (null == _mergeDataThread ||
                    _mergeDataThread.ThreadState != ThreadState.Running)
                {
                    _mergeDataThread = new Thread(new ParameterizedThreadStart(removeBadRatingAndMergeLines));
                    _mergeDataThread.Start(db);
                }
            }
            #endregion
        }
Пример #3
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            var gp = parseGMapUrl(txtGMapURL.Text);

            using (var dao = BusWebDataService.GetServiceInstance())
            {
                DsBusWeb ds     = new DsBusWeb();
                int      lineID = 0;
                if (!string.IsNullOrEmpty(txtNewLineName.Text))
                {
                    var dr = ds.Lines.NewLinesRow();
                    dr.LineName = txtNewLineName.Text;
                    lineID      = dao.InsertNewLine(dr);
                }
                else
                {
                    lineID = int.Parse(ddlLine.SelectedValue);
                }

                var dr2 = ds.Stops.NewStopsRow();
                dr2.StopName         = txtNewStopName.Text;
                dr2.Latitude         = gp.latitude;
                dr2.Longitude        = gp.longitude;
                dr2.CreatorLatitude  = 0d;
                dr2.CreatorLongitude = 0d;
                dr2.Owner            = "SYSTEM";

                dr2.StopID = dao.InsertNewStop(dr2);
                var dr3 = new DsBusWeb.Line2StopDataTable().NewLine2StopRow();
                dr3.StopID = dr2.StopID;
                dr3.LineID = lineID;
                dao.InsertNewLine2StopRelation(dr3);
            }
            if (!string.IsNullOrEmpty(txtNewLineName.Text))
            {
                refreshLineList();
            }
            txtNewLineName.Text = string.Empty;
            ClientScript.RegisterClientScriptBlock(typeof(string), "alert", "<script lang=jscript>alert('站點新增成功');</script>");
        }
Пример #4
0
        public void deleteStopTest()
        {
            #region prepare testing data
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            int lineId1 = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Lines(LineName) VALUES('207')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(LineID) FROM Lines";
            int lineId2 = Convert.ToInt32(_coreDb.ExecuteScalar());

            int stopID = 0;

            #region line1
            #region 周美里
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('周美里', 121.583377, 25.057018, 0, 0, 'SYSTEM')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 9, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 後山埤站
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('後山埤站', 121.582911, 25.04487, 0, 0, 'SYSTEM')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 3, 1)", stopID);
            _coreDb.Execute();
            #endregion

            #region 秀朗國小
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('秀朗國小', 121.521262, 24.999231, 121.58084978, 25.05816265, 'SYSTEM')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 3, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 週美里
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('週美里', 121.583377, 25.057018, 121.56014515, 25.03309135, 'SYSTEM')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 松山家商
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('松山家商', 121.580912, 25.035887, 121.5546072, 25.0299129, '*****@*****.**')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 1, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 永和市永元路
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和市永元路', 121.522975, 25.001647, 121.5525412, 25.0270202, '*****@*****.**')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId1, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 2, 0)", stopID);
            _coreDb.Execute();
            #endregion
            #endregion

            #region line2
            #region 永和路
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和路', 120.635709, 24.21521, 121.5614992, 25.0326352, 'SYSTEM')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 永和市永元路
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('永和市永元路', 121.522638, 25.000503, 121.5528976, 25.024357, '*****@*****.**')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 新湖舊宗路口
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('新湖舊宗路口', 121.578653, 25.062323, 121.5777363, 25.0634112, '*****@*****.**')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 0, 0)", stopID);
            _coreDb.Execute();
            #endregion

            #region 新湖一路口
            _coreDb.ExecuteCommand.CommandText = "INSERT INTO Stops(StopName, Longitude, Latitude, CreatorLongitude, CreatorLatitude, Owner) VALUES('新湖一路口', 121.579208, 25.060522, 121.57881499, 25.06057842, '*****@*****.**')";
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = "SELECT MAX(StopID) FROM Stops";
            stopID = Convert.ToInt32(_coreDb.ExecuteScalar());
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO Line2Stop(LineID, StopID) VALUES({0}, {1})", lineId2, stopID);
            _coreDb.Execute();
            _coreDb.ExecuteCommand.CommandText = string.Format("INSERT INTO StopRating(StopID, RatingGood, RatingBad) VALUES({0}, 1, 0)", stopID);
            _coreDb.Execute();
            #endregion
            #endregion
            #endregion

            Thread.Sleep(CONST_SLEEP_TIME);

            BusWeb.Spi.Spi target   = new BusWeb.Spi.Spi();
            string         owner    = "*****@*****.**";
            bool           expected = true;
            bool           actual   = target.deleteStop(stopID, owner);

            Thread.Sleep(CONST_SLEEP_TIME);

            #region verifying
            Assert.AreEqual <bool>(expected, actual, "We shall got return value TRUE as success result.");
            DsBusWeb.LinesDataTable dt = new DsBusWeb.LinesDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Lines";
            _coreDb.Fill(dt);

            Assert.AreEqual <int>(2, dt.Count, "Line count should be only 2 left!");
            DsBusWeb.Line2StopDataTable dt2 = new DsBusWeb.Line2StopDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Line2Stop";
            _coreDb.Fill(dt2);
            Assert.AreEqual <int>(9, dt2.Count, "Stops should be only 9 links left!");
            foreach (var dr in dt2)
            {
                Assert.AreNotEqual <int>(stopID, dr.StopID, "There should not be any stopID in link existing as the deleted one!");
            }

            DsBusWeb.StopsDataTable dt3 = new DsBusWeb.StopsDataTable();
            _coreDb.SelectCommand.CommandText = "SELECT * FROM Stops";
            _coreDb.Fill(dt3);
            Assert.AreEqual <int>(9, dt3.Count, "Stops should be 9 stops left!");
            foreach (var dr in dt3)
            {
                Assert.AreNotEqual <int>(stopID, dr.StopID, "There should not be any stopID in stop info existing as the deleted one!");
            }
            #endregion
        }