Example #1
0
        public void ShowMessage(String stationName, String stationEnName, double stationLng, double stationLat, int stopTime, String lastStation)
        {                                                        //插入站点
            // Console.WriteLine(stationName + stationEnName + stationLng + stationLat + stopTime + lastStation);
            SelectStation   sel         = new SelectStation();   //实例化查询对象
            UpdateStation   updateSta   = new UpdateStation();   //实例化更新对象
            Common          commStaName = new Common();          //实例化实体类对象
            IncreaseStation increaseSta = new IncreaseStation(); //实例化插入对象
            Calculate       cal         = new Calculate();       //实例化计算距离对象
            Common          com         = sel.SelectFirstStation(lastStation);

            //Console.WriteLine(com.StationName);
            try
            {
                if (lastStation == "首站")//在运行线路开始插入一站(首站)
                {
                    List <Common> listSub1 = sel.SelectSubStation(0);
                    if (listSub1.Count > 0)
                    {//数据库中还有站点
                        for (int i = 0; i < listSub1.Count; i++)
                        {
                            String StaName    = listSub1[i].StationName;
                            int    StaSubject = listSub1[i].SubjectStation + 1;
                            updateSta.UpdateSubject(StaName, StaSubject);
                        }
                        String firstStationName = null;
                        if (com.StationName == null)
                        {
                            firstStationName = sel.SelectFirstStation("首站").StationName;
                        }
                        else
                        {
                            firstStationName = com.StationName;
                        }
                        Console.WriteLine(firstStationName);
                        double lng      = sel.SelectLngLat(firstStationName).lng;
                        double lat      = sel.SelectLngLat(firstStationName).lat;
                        double distance = cal.Distance(stationLng, stationLat, lng, lat); //计算相邻两站之间的距离
                        updateSta.UpdateDistance(firstStationName, distance);             //修改当前首站的距离
                        updateSta.UpdateLastStation(stationName, firstStationName);       //修改当前的首站的上一站名称为要插入的站的站名
                        increaseSta.insertStation(stationName, stationEnName, stationLng, stationLat, stopTime, 0, lastStation, 1);
                    }
                    else
                    {//刚开始插入,数据库中还没有插入站点(首站)
                        increaseSta.insertStation(stationName, stationEnName, stationLng, stationLat, stopTime, 0, lastStation, 1);
                    }
                }
                else
                {
                    int sub = sel.SelectBelong(lastStation);
                    //Console.WriteLine(sub);
                    List <Common> listSub2 = sel.SelectSubStation(sub);
                    if (listSub2.Count > 0)
                    {//在运行线路中间插入一站
                        for (int i = 0; i < listSub2.Count; i++)
                        {
                            String StaName    = listSub2[i].StationName;
                            int    StaSubject = listSub2[i].SubjectStation + 1;
                            updateSta.UpdateSubject(StaName, StaSubject);
                        }
                        String staname = null;
                        if (com.StationName == null)
                        {
                            staname = sel.SelectFirstStation("首站").StationName;
                        }
                        else
                        {
                            staname = com.StationName;
                        }
                        Console.WriteLine(staname);
                        double lng       = sel.SelectLngLat(staname).lng;
                        double lat       = sel.SelectLngLat(staname).lat;
                        double lngL      = sel.SelectLngLat(lastStation).lng;
                        double latL      = sel.SelectLngLat(lastStation).lat;
                        double distanceL = cal.Distance(stationLng, stationLat, lngL, latL); //计算插入站与前一站两站之间的距离
                        double distance  = cal.Distance(lng, lat, stationLng, stationLat);   //计算插入站与后一站两站之间的距离
                        updateSta.UpdateDistance(staname, distance);                         //修改插入站点与后一站的的距离
                        updateSta.UpdateLastStation(stationName, staname);                   //修改后一站的上一站名称为要插入的站的站名
                        increaseSta.insertStation(stationName, stationEnName, stationLng, stationLat, stopTime, distanceL, lastStation, sub + 1);
                    }
                    else
                    {//在运行线路的末尾插入一站
                        double lng      = sel.SelectLngLat(lastStation).lng;
                        double lat      = sel.SelectLngLat(lastStation).lat;
                        double distance = cal.Distance(lng, lat, stationLng, stationLat);//计算插入站与后一站两站之间的距离
                        increaseSta.insertStation(stationName, stationEnName, stationLng, stationLat, stopTime, distance, lastStation, sub + 1);
                    }
                }
                MessageBox.Show("添加成功!");
            }
            catch {
                MessageBox.Show("添加失败,请检查网络连接!");
            }
        }
Example #2
0
 /// <summary>
 /// 删除停靠点
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void button6_Click(object sender, EventArgs e)
 {
     if (colIndex == null)
     {//未选中
         MessageBox.Show("请选择您要删除的站点!");
     }
     else
     {
         DialogResult r = MessageBox.Show("确定要删除该停靠站点?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
         if (r != DialogResult.OK)
         {
             // Cancel = true;
             dataGridView1.Rows[Index].Selected = false;
         }
         else
         {
             try
             {
                 string        commLastStaName = null;
                 string        commStaName     = null;
                 UpdateStation ups             = new UpdateStation();
                 DeleteStation delSta          = new DeleteStation();
                 SelectStation sel             = new SelectStation();
                 Calculate     cal             = new Calculate();
                 int           sub             = sel.SelectBelong(colIndex);
                 List <Common> list            = new List <Common>();
                 list = sel.SelectSubStation(sub);
                 for (int i = 0; i < list.Count; i++)
                 {
                     ups.UpdateSubject(list[i].StationName, list[i].SubjectStation - 1);
                 }
                 //Console.WriteLine(colIndex);
                 commLastStaName = sel.SelectBeforeStation(colIndex).LastStationName; //查询删除站点的上一站
                 if (commLastStaName == "首站")
                 {                                                                    //只有首站
                     if (sel.SelectFirstStation(colIndex) == null)
                     {
                         delSta.deleteSta(colIndex);
                     }
                     else
                     {
                         ups.UpdateLastStation(commStaName, "首站");
                         delSta.deleteSta(colIndex);
                     }
                 }
                 else
                 {
                     if (sel.SelectFirstStation(colIndex) == null)
                     {//删除末站
                         delSta.deleteSta(colIndex);
                     }
                     else
                     {                                                               //删除中间某一站
                         commStaName = sel.SelectFirstStation(colIndex).StationName; //查询以删除站点为上一站的站点
                         double lastLng  = sel.SelectLngLat(commLastStaName).lng;
                         double lastLat  = sel.SelectLngLat(commLastStaName).lat;
                         double afterLng = sel.SelectLngLat(commStaName).lng;
                         double afterLat = sel.SelectLngLat(commStaName).lat;
                         ups.UpdateDistance(commStaName, cal.Distance(afterLng, afterLat, lastLng, lastLat));
                         ups.UpdateLastStation(commStaName, commLastStaName);
                         delSta.deleteSta(colIndex);
                     }
                 }
                 DateViewDetails(); //加载运行线路信息
                 showStation();     //首末站数据加载
                 ComboBoxDetails(); //掉电恢复区comboBox数据加载
                 showStation();     //显示首末站
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 return;
             }
         }
     }
 }