Пример #1
0
 public bool AddFileAirport(File_Airport model)
 {
     return(airportdal.Add(model) > 0);
 }
Пример #2
0
        /// <summary>
        /// 添加机场、航线、作业区
        /// </summary>
        /// <param name="airportidList"></param>
        /// <param name="airlineText"></param>
        /// <param name="repetPlanID"></param>
        public void AddRepetitivePlanOther(List <string> airportidList, string airlineText, string cworkText, string pworkText, string hworkText, string repetPlanID, string keyValue, ref string airlineworkText)
        {
            var           context = new ZHCC_GAPlanEntities();
            StringBuilder sb      = new StringBuilder("");

            //   using (TransactionScope scope = new TransactionScope())
            //  using (var scope = context.Database.BeginTransaction())
            //  {

            //try
            //{
            if (!string.IsNullOrEmpty(keyValue))
            {
                var airlist = context.File_Airport.Where(u => u.RepetPlanID.Equals(repetPlanID));
                foreach (var item in airlist)
                {
                    context.File_Airport.Remove(item);
                }
                var masterlist = context.File_Master.Where(u => u.RepetPlanID.Equals(repetPlanID));
                foreach (var item in masterlist)
                {
                    context.File_Master.Remove(item);
                }
                var detaillist = context.File_Detail.Where(u => u.RepetPlanID.Equals(repetPlanID));
                foreach (var item in detaillist)
                {
                    context.File_Detail.Remove(item);
                }
                context.SaveChanges();
            }
            #region 机场
            var i = 1;
            foreach (var item in airportidList)
            {
                File_Airport airport = new File_Airport()
                {
                    RepetPlanID = repetPlanID,
                    AirportID   = item,
                    Sort        = i
                };
                i++;
                context.File_Airport.Add(airport);
            }
            var a = context.SaveChanges();
            #endregion
            #region 航线
            if (!string.IsNullOrEmpty(airlineText))
            {
                var airlineList = (AirlineFillTotal)JsonConvert.DeserializeObject(airlineText, typeof(AirlineFillTotal));
                var sblinedesc  = new StringBuilder("");
                foreach (var item in airlineList.airlineArray)
                {
                    if (item.airlinePointList.Count() > 0)
                    {
                        sblinedesc.Clear();
                        File_Master master = new File_Master()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            RepetPlanID = repetPlanID,
                            WorkType    = "airline",
                            FlyHeight   = item.FlyHeight,
                        };
                        var index = 1;
                        foreach (var pointItem in item.airlinePointList)
                        {
                            if (string.IsNullOrEmpty(pointItem.PointName))
                            {
                                continue;
                            }
                            sblinedesc.Append(pointItem.PointName);
                            File_Detail point = new File_Detail()
                            {
                                ID          = Guid.NewGuid().ToString(),
                                MasterID    = master.ID,
                                RepetPlanID = repetPlanID,
                                PointName   = pointItem.PointName,
                                Sort        = index
                            };

                            var splitmodel = SpecialFunctions.latLongSplit(pointItem.LatLong);
                            point.Longitude = splitmodel.Longitude;
                            point.Latitude  = splitmodel.Latitude;
                            context.File_Detail.Add(point);
                            context.SaveChanges();
                            sblinedesc.Append("(");
                            sblinedesc.Append(pointItem.LatLong);
                            sblinedesc.Append(")");
                            sblinedesc.Append("-");
                            index++;
                        }
                        if (sblinedesc.Length > 0)
                        {
                            sblinedesc.Remove(sblinedesc.Length - 1, 1);
                        }
                        if (!string.IsNullOrEmpty(master.FlyHeight))
                        {
                            sblinedesc.Append(",高度");
                            sblinedesc.Append(master.FlyHeight);
                            sblinedesc.Append("米(含)以下");
                        }
                        master.LineDescript = sblinedesc.ToString();
                        context.File_Master.Add(master);
                        context.SaveChanges();
                        sb.AppendLine(master.LineDescript + ";");
                    }
                }
            }
            #endregion
            #region 作业区(圆)
            if (!string.IsNullOrEmpty(cworkText))
            {
                var workList   = (AirlineFillTotal)JsonConvert.DeserializeObject(cworkText, typeof(AirlineFillTotal));
                var sblinedesc = new StringBuilder("");
                foreach (var item in workList.airlineArray)
                {
                    if (item.airlinePointList.Count() > 0 && !string.IsNullOrEmpty(item.Radius))
                    {
                        sblinedesc.Clear();
                        File_Master master = new File_Master()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            RepetPlanID = repetPlanID,
                            FlyHeight   = item.FlyHeight,
                            WorkType    = "circle"
                        };
                        var customAreaStr = new StringBuilder("");
                        var index         = 1;
                        foreach (var pointItem in item.airlinePointList)
                        {
                            if (string.IsNullOrEmpty(pointItem.PointName))
                            {
                                continue;
                            }
                            sblinedesc.Append(pointItem.PointName);
                            File_Detail point = new File_Detail()
                            {
                                ID          = Guid.NewGuid().ToString(),
                                MasterID    = master.ID,
                                RepetPlanID = repetPlanID,
                                PointName   = pointItem.PointName,
                                Sort        = index
                            };
                            var splitmodel = SpecialFunctions.latLongSplit(pointItem.LatLong);
                            point.Longitude = splitmodel.Longitude;
                            point.Latitude  = splitmodel.Latitude;
                            context.File_Detail.Add(point);
                            var b = context.SaveChanges();
                            sblinedesc.Append("(");
                            sblinedesc.Append(pointItem.LatLong);
                            sblinedesc.Append(")");
                            if (!string.IsNullOrEmpty(point.Latitude) && !string.IsNullOrEmpty(point.Longitude))
                            {
                                customAreaStr.Append("N");
                                customAreaStr.Append(point.Latitude);
                                customAreaStr.Append("E");
                                customAreaStr.Append(point.Longitude);
                                customAreaStr.Append(",");
                            }
                            index++;
                        }
                        DbGeography geoArea = null;
                        try
                        {
                            geoArea = context.f_GetGEOAreaByPointString(customAreaStr.ToString(), 4).First();
                        }
                        catch
                        {
                        }
                        //计算管制区
                        var customAreaList = context.CustomControlArea.Where(m => m.ControlAreaBoundary.Intersects(geoArea)).Select(m => m.ControlAreaName);
                        master.CustomArea = string.Join(",", customAreaList.ToArray());

                        Int16 _radius = 0;
                        if (!string.IsNullOrWhiteSpace(item.Radius) && Int16.TryParse(item.Radius, out _radius))
                        {
                            master.RaidusMile = _radius;
                            var tempraidus = "为圆心半径" + item.Radius + "公里范围内";
                            sblinedesc.Append(tempraidus);
                        }
                        if (!string.IsNullOrEmpty(master.FlyHeight))
                        {
                            sblinedesc.Append(",高度");
                            sblinedesc.Append(master.FlyHeight);
                            sblinedesc.Append("米(含)以下");
                        }
                        master.LineDescript = sblinedesc.ToString();
                        context.File_Master.Add(master);
                        var s = context.SaveChanges();
                        sb.AppendLine(master.LineDescript + ";");
                    }
                }
            }
            #endregion
            #region 作业区(点)
            if (!string.IsNullOrEmpty(pworkText))
            {
                var workList   = (AirlineFillTotal)JsonConvert.DeserializeObject(pworkText, typeof(AirlineFillTotal));
                var sblinedesc = new StringBuilder("");
                foreach (var item in workList.airlineArray)
                {
                    if (item.airlinePointList.Count() > 0)
                    {
                        sblinedesc.Clear();
                        File_Master master = new File_Master()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            RepetPlanID = repetPlanID,
                            FlyHeight   = item.FlyHeight,
                            WorkType    = "area"
                        };
                        var customAreaStr = new StringBuilder("");
                        var index         = 1;
                        foreach (var pointItem in item.airlinePointList)
                        {
                            if (string.IsNullOrEmpty(pointItem.PointName))
                            {
                                continue;
                            }
                            sblinedesc.Append(pointItem.PointName);
                            File_Detail point = new File_Detail()
                            {
                                ID          = Guid.NewGuid().ToString(),
                                MasterID    = master.ID,
                                RepetPlanID = repetPlanID,
                                PointName   = pointItem.PointName,
                                Sort        = index
                            };
                            var splitmodel = SpecialFunctions.latLongSplit(pointItem.LatLong);
                            point.Longitude = splitmodel.Longitude;
                            point.Latitude  = splitmodel.Latitude;
                            context.File_Detail.Add(point);
                            context.SaveChanges();
                            sblinedesc.Append("(");
                            sblinedesc.Append(pointItem.LatLong);
                            sblinedesc.Append(")");
                            sblinedesc.Append("-");
                            if (!string.IsNullOrEmpty(point.Latitude) && !string.IsNullOrEmpty(point.Longitude))
                            {
                                customAreaStr.Append("N");
                                customAreaStr.Append(point.Latitude);
                                customAreaStr.Append("E");
                                customAreaStr.Append(point.Longitude);
                                customAreaStr.Append(",");
                            }
                            index++;
                        }
                        if (customAreaStr.Length > 0)
                        {
                            customAreaStr.Remove(customAreaStr.Length - 1, 1);
                        }
                        if (sblinedesc.Length > 0)
                        {
                            sblinedesc.Remove(sblinedesc.Length - 1, 1);
                        }
                        DbGeography geoArea = null;
                        try
                        {
                            geoArea = context.f_GetGEOAreaByPointString(customAreaStr.ToString(), 3).First();
                        }
                        catch
                        {
                        }
                        //计算管制区
                        var customAreaList = context.CustomControlArea.Where(m => m.ControlAreaBoundary.Intersects(geoArea)).Select(m => m.ControlAreaName);
                        master.CustomArea = string.Join(",", customAreaList.ToArray());
                        var tempraidus = item.airlinePointList.Count() + "点连线范围内";
                        sblinedesc.Append(tempraidus);
                        if (!string.IsNullOrEmpty(master.FlyHeight))
                        {
                            sblinedesc.Append(",高度");
                            sblinedesc.Append(master.FlyHeight);
                            sblinedesc.Append("米(含)以下");
                        }
                        master.LineDescript = sblinedesc.ToString();
                        context.File_Master.Add(master);
                        context.SaveChanges();
                        sb.AppendLine(master.LineDescript + ";");
                    }
                }
            }
            #endregion
            #region 作业区(线)
            if (!string.IsNullOrEmpty(hworkText))
            {
                var workList   = (AirlineFillTotal)JsonConvert.DeserializeObject(hworkText, typeof(AirlineFillTotal));
                var sblinedesc = new StringBuilder("");
                foreach (var item in workList.airlineArray)
                {
                    if (item.airlinePointList.Count() > 0)
                    {
                        sblinedesc.Clear();
                        File_Master master = new File_Master()
                        {
                            ID          = Guid.NewGuid().ToString(),
                            RepetPlanID = repetPlanID,
                            FlyHeight   = item.FlyHeight,
                            WorkType    = "airlinelr"
                        };
                        var customAreaStr = new StringBuilder("");
                        var index         = 1;
                        foreach (var pointItem in item.airlinePointList)
                        {
                            if (string.IsNullOrEmpty(pointItem.PointName))
                            {
                                continue;
                            }
                            sblinedesc.Append(pointItem.PointName);
                            File_Detail point = new File_Detail()
                            {
                                ID          = Guid.NewGuid().ToString(),
                                MasterID    = master.ID,
                                RepetPlanID = repetPlanID,
                                PointName   = pointItem.PointName,
                                Sort        = index
                            };
                            var splitmodel = SpecialFunctions.latLongSplit(pointItem.LatLong);
                            point.Longitude = splitmodel.Longitude;
                            point.Latitude  = splitmodel.Latitude;
                            context.File_Detail.Add(point);
                            context.SaveChanges();
                            sblinedesc.Append("(");
                            sblinedesc.Append(pointItem.LatLong);
                            sblinedesc.Append(")");
                            sblinedesc.Append("-");
                            if (!string.IsNullOrEmpty(point.Latitude) && !string.IsNullOrEmpty(point.Longitude))
                            {
                                customAreaStr.Append("N");
                                customAreaStr.Append(point.Latitude);
                                customAreaStr.Append("E");
                                customAreaStr.Append(point.Longitude);
                                customAreaStr.Append(",");
                            }
                            index++;
                        }
                        if (customAreaStr.Length > 0)
                        {
                            customAreaStr.Remove(customAreaStr.Length - 1, 1);
                        }
                        if (sblinedesc.Length > 0)
                        {
                            sblinedesc.Remove(sblinedesc.Length - 1, 1);
                        }
                        Int16 _radius = 0;
                        if (!string.IsNullOrWhiteSpace(item.Radius) && Int16.TryParse(item.Radius, out _radius))
                        {
                            master.RaidusMile = _radius;
                            var tempraidus = "航线左右" + item.Radius + "公里范围内";
                            sblinedesc.Append(tempraidus);
                        }
                        if (!string.IsNullOrEmpty(master.FlyHeight))
                        {
                            sblinedesc.Append(",高度");
                            sblinedesc.Append(master.FlyHeight);
                            sblinedesc.Append("米(含)以下");
                        }
                        DbGeography geoArea = null;
                        try
                        {
                            geoArea = context.f_GetGEOAreaByPointString(customAreaStr.ToString(), 2).First();
                        }
                        catch
                        {
                        }
                        //计算管制区
                        var customAreaList = context.CustomControlArea.Where(m => m.ControlAreaBoundary.Intersects(geoArea)).Select(m => m.ControlAreaName);
                        master.CustomArea   = string.Join(",", customAreaList.ToArray());
                        master.LineDescript = sblinedesc.ToString();
                        context.File_Master.Add(master);
                        context.SaveChanges();
                        sb.AppendLine(master.LineDescript + ";");
                    }
                }
            }
            #endregion
            airlineworkText = sb.ToString();
            //      scope.Complete();
            //}
            //catch (Exception ex)
            //{

            //    //var ss = ex.Message + ex.InnerException + ex.StackTrace;
            //    //dbContextTransaction.();
            //    throw ex;
            //}
            // }
        }