Example #1
0
 void dataBackup1_OnBackupCompleted(object sender, System.EventArgs e)
 {
     LoadingForm.Fadeout();
     if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("BackupSaved")) ==
         CustomMessageBoxReturnValue.Ok)
     {
         Close();
     }
 }
Example #2
0
        private void tsmiEditRegionDeleteAllChildRegions_Click(object sender, EventArgs e)
        {
            Region region = (Region)_selectedNode.Tag;

            if (region.RegionLevel < 1)
            {
                CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("WorldContinentNotDelete"));
                return;
            }

            List <Region> childRegions = RegionHelper.GetAllChilds(region.IDRegion);

            if (childRegions.Any(r => r.IDRegion == region.IDRegion))
            {
                Region regionRemove = childRegions.First(r => r.IDRegion == region.IDRegion);
                childRegions.Remove(regionRemove);
            }

            if (childRegions == null || childRegions.Count == 0)
            {
                CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionHasNoChilds"));
                return;
            }

            List <Model> childRegionModels = ModelHelper.GetByRegions(childRegions);

            if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionChildsDeleteConfirm"), CustomMessageBoxMessageType.Warning,
                                             CustomMessageBoxButtonType.YesNo, new[] { region.RegionName }) == CustomMessageBoxReturnValue.Ok)
            {
                if (childRegionModels.Count > 0)
                {
                    if (
                        CustomMessageBox.ShowMessage(
                            ResourceHelper.GetResourceText("RegionChildsWithModelsDeleteConfirm"),
                            CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo) !=
                        CustomMessageBoxReturnValue.Ok)
                    {
                        return;
                    }
                    LoadingForm.ShowLoading();
                    foreach (Model model in childRegionModels)
                    {
                        ModelHelper.Delete(model);
                    }
                    ViewManager.LoadModelsMenu();
                }
                LoadingForm.ShowLoading();
                foreach (Region childRegion in childRegions)
                {
                    RegionHelper.Delete(childRegion);
                }
                LoadRegions();
                CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionChildsDeleted"));
                LoadingForm.Fadeout();
            }
        }
Example #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            bool backupDatabase   = chkBackupDataBase.Checked;
            bool backupFiles      = chkBackupFiles.Checked;
            bool backupShapefiles = chkBackupShapefiles.Checked;

            if (backupDatabase == false && backupFiles == false && backupShapefiles == false)
            {
                CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("MustSelectAtLeastOneOption"));
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog {
                Filter = "Gzipped backup files(*gz)|*.gz", Title = "Save backup files"
            };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                btnOK.Enabled = false;

                try
                {
                    LoadingForm.ShowLoading();
                    string filename = sfd.FileName;
                    string content  = DocumentHelper.Backup(backupDatabase, backupFiles, backupShapefiles);
                    File.WriteAllBytes(filename, Convert.FromBase64String(content));
                    //SetBackupVersion(filename);


                    if (OnBackupCompleted != null)
                    {
                        OnBackupCompleted(new object(), new EventArgs());
                    }
                }
                catch (Exception ex)
                {
                    CustomMessageBox.ShowMessage(ex.Message, CustomMessageBoxMessageType.Error, CustomMessageBoxButtonType.OKOnly);
                    LoadingForm.Fadeout();
                }
            }
        }
Example #4
0
        private void tsmiEditRegionAddChildRegion_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog {
                Filter = "Shape Files (*.shp)|*.shp"
            };
            DialogResult result = openFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                FileInfo shapeFileInfo = new FileInfo(openFileDialog.FileName);
                try
                {
                    int count = (LayerOverlay)winformsMap1.Overlays[0] != null ? ((LayerOverlay)winformsMap1.Overlays[0]).Layers.Count : 0;
                    if (!File.Exists(shapeFileInfo.ToString().Replace(".shp", ".dbf")) || !File.Exists(shapeFileInfo.ToString().Replace(".shp", ".shx")))
                    {
                        //if there's no DBF / SHX file, can't use this .shp.
                        //http://thinkgeo.com/forums/MapSuite/tabid/143/aft/2947/Default.aspx
                        //1) In real life, how those files (.shp .shx .dbf) are generated ?
                        //1. These files are automatically created upon creation of a shapefile, using the CreateShapeFile method of Map Suite or another shapefile creation application. These three files are required for a shapefile to function as dictated by ESRI shapefile standard.
                        CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("EditRegionShapeFileMissingFiles"));
                    }
                    else
                    {
                        ShapeFileFeatureLayer newRegion = MapHelper.GetRegionFeatureLayer(shapeFileInfo);
                        DataTable             table     = GetDataTable(newRegion);


                        PickColumnForm pck = new PickColumnForm(table);
                        if (pck.ShowDialog() == DialogResult.OK)
                        {
                            LoadingForm.ShowLoading();
                            _columnName = pck.SelectedColumn;
                            string parentColumnName = pck.SelectedParentColumn;
                            try
                            {
                                int           regionCount       = 0;
                                List <Region> siblingRegions    = null;
                                String        newRegionFileName = string.Empty;
                                Region        parent            = null;
                                foreach (DataRow row in table.Rows)
                                {
                                    Boolean saveRegion = false;
                                    Region  region     = NewRegionData;
                                    region.RegionName = row[_columnName].ToString();
                                    if (parentColumnName != "No parent column")
                                    //If la segunda columna esta seleccionada parentNameColumnIndex!=-1
                                    {
                                        //Quien es el pais?
                                        int idCountry = GetCountry(RegionHelper.Get(region.IDParent.Value));
                                        if (region.IDParent != null)
                                        {
                                            Region parentRegion = RegionHelper.Get(region.IDParent.Value);
                                            if (parentRegion.IDParent != null)
                                            {
                                                if (idCountry == _regionData.IDRegion)
                                                {
                                                    region.IDParent = _regionData.IDRegion;
                                                    saveRegion      = true;
                                                }
                                                else
                                                {
                                                    if (siblingRegions == null)
                                                    {
                                                        siblingRegions = RegionHelper.GetChildsAtLevel(idCountry,
                                                                                                       _regionData.RegionLevel);
                                                    }

                                                    foreach (Region r in siblingRegions) //Hermanos
                                                    {
                                                        if (r.RegionName != (string)row[parentColumnName])
                                                        {
                                                            continue;
                                                        }
                                                        region.IDParent = r.IDRegion;
                                                        saveRegion      = true;
                                                        break;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                region.IDParent = parentRegion.IDRegion;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        saveRegion = true;
                                    }

                                    parent = RegionHelper.Get(region.IDParent.Value);
                                    if (saveRegion)
                                    {
                                        region.RegionLevel = parent.RegionLevel + 1;
                                        if (newRegionFileName == string.Empty)
                                        {
                                            newRegionFileName = SaveShapefiles(shapeFileInfo, region);
                                        }
                                        region.ShapeFileName = newRegionFileName;
                                        if (table.Rows.Count == 1)
                                        {
                                            //it's the only region in the shapefile. So, no need to specify an index
                                            region.ShapeFileIndex = null;
                                        }
                                        else
                                        {
                                            //it's a shapefile that contains more than 1 regions. Index is needed.
                                            region.ShapeFileIndex = regionCount;
                                        }

                                        RegionHelper.Save(region);
                                        regionCount++;
                                    }
                                }
                                //Reload  map and tree
                                LoadRegions();
                                if (parent != null)
                                {
                                    ShowShapeChilds(parent);
                                }
                                LoadingForm.Fadeout();
                                CustomMessageBox.ShowMessage(regionCount + " " + ResourceHelper.GetResourceText("NewRegionsHaveBeenImported"));
                            }
                            catch (Exception ex)
                            {
                                LogHelper.LogError(ex);
                                throw;
                            }
                            finally
                            {
                                LoadingForm.Fadeout();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    //Shape was not valid
                }
                finally
                {
                }
            }
        }