コード例 #1
0
ファイル: DataBackup.cs プロジェクト: InternationalIDEA/ERMT
        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();
                }
            }
        }
コード例 #2
0
ファイル: LoadingForm.cs プロジェクト: InternationalIDEA/ERMT
        public static void ShowLoading(int fadeinTime, string message)
        {
            Showing = true;
            //	Only show if not showing already
            if (Instance == null)
            {
                Instance = new LoadingForm();

                //	Hide initially so as to avoid a nasty pre paint flicker
                Instance.Opacity = 0;
                Instance.Show();

                //	Process the initial paint events
                Application.DoEvents();

                if (Instance != null)
                {
                    Instance.Opacity = 1;
                }
            }
        }
コード例 #3
0
ファイル: EditRegion.cs プロジェクト: InternationalIDEA/ERMT
        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
                {
                }
            }
        }