private void btnSave_Click(object sender, EventArgs e) { if (!ValidateScreen()) { return; } try { User user = userCRUD.User; UserHelper.Validate(user); if ((from u in UserHelper.GetAll() where (user.Username.ToLower() == u.Username.ToLower() && user.IDUser != u.IDUser) select u).Any()) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("UserNameAlreadyExists"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.OKOnly); return; } UserHelper.Save(user); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("UserSavedOk"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.OKOnly); Clear(); LoadUserCombo(); } catch (Exception ex) { CustomMessageBox.ShowError(ex.Message); } }
private void btnRemove_Click(object sender, EventArgs e) { TreeNode n = tvMarkerType.SelectedNode; if (n != null) { if ( CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ConfirmDeleteMarkerType"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Ok) { bool deleteImage = CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ConfirmDeleteMarkerTypeImage"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Ok; //delete the marker type and the server image MarkerTypeHelper.Delete((MarkerType)(n.Tag), deleteImage); //delete the image from the client. if (deleteImage) { pbSymbol.Image = null; DeleteMarkerTypeImageFromClient((MarkerType)(n.Tag)); } CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("MarkerTypeDeleted")); LoadData(); Clear(); } } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("SelectMarkerType")); } }
private void btnSave_Click(object sender, EventArgs e) { if (MarkerType.Name != string.Empty && (cbSymbol.SelectedIndex != 0 || (cbSymbol.SelectedIndex == 0 && _fileName != string.Empty))) { MarkerTypeHelper.Save(MarkerType); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("MarkerTypeSaved")); Clear(); if (_fileName != string.Empty) { Document doc = new Document { DocumentType = ERMTDocumentType.Icon, Content = Convert.ToBase64String(File.ReadAllBytes(_fileName)), Filename = Path.GetFileName(_fileName) }; DocumentHelper.Save(doc); DocumentHelper.DownloadFiles(); } LoadData(); Clear(); btnRemove.Enabled = false; } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("Allfieldsrequired")); } }
private void btnSave_Click(object sender, EventArgs e) { if (txtPassword.Text != string.Empty && txtConfirm.Text != string.Empty) { if (txtPassword.Text == txtConfirm.Text) { User user = ERMTSession.Instance.CurrentUser; //Update password user.Password = txtPassword.Text; UserHelper.Save(user); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("PasswordChanged")); Close(); } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("PasswordNoMatch"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); } } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("PasswordEmpty"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); } }
private void btnAddDocument_Click(object sender, EventArgs e) { string fileName = GetDocumentToLoad(); if (!string.IsNullOrEmpty(fileName)) { string newFileName = DirectoryAndFileHelper.ClientDocumentsFolder + fileName.Split('\\')[fileName.Split('\\').Length - 1]; if (File.Exists(newFileName)) { if (CustomMessageBoxReturnValue.Ok != CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DocumentExistsAlready"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo)) { return; } File.Delete(newFileName); } File.Copy(fileName, newFileName); byte[] fileContent = File.ReadAllBytes(newFileName); Document document = new Document { Content = Convert.ToBase64String(fileContent), Filename = newFileName, DocumentType = ERMTDocumentType.Document }; DocumentHelper.Save(document); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DocumentAddedOk")); } }
private void btnDelete_Click(object sender, EventArgs e) { if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("PhaseBulletDelete"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Ok) { // Mark as deleted in the // Get the ID: int bulletId = ((PhaseBullet)bulletsListBox.SelectedItem).IDPhaseBullet; // Remove the item from the list bulletsListBox.BeginUpdate(); bulletsListBox.Items.RemoveAt(bulletsListBox.SelectedIndex); bulletsListBox.EndUpdate(); if (bulletId > 0) { //PhaseBulletHelper.Delete(bulletId); PhaseBulletsIDsToDelete.Add(bulletId); _bullets.RemoveAll(s => s.IDPhaseBullet == bulletId); } else { // It is negative, so it is a new one, we must actually remove it from the list. _bullets.RemoveAll(s => s.IDPhaseBullet == bulletId); } } }
private void btnSave_Click(object sender, EventArgs e) { Model model = modelCRUD1.Model; try { if (!ModelHelper.Validate(model)) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("RequiredName")); return; } List <ModelFactor> factors = modelCRUD1.ModelFactors; if (factors.Count == 0) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("AtLeastOneFactor")); return; } model = ModelHelper.Save(model); foreach (ModelFactor mf in factors) { mf.IDModel = model.IDModel; ModelFactorHelper.Save(mf); } CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ModelSavedOk")); ViewManager.ShowStart(); ViewManager.LoadModelsMenu(); } catch (Exception exception) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("ModelSavingError") + exception.Message); } }
void dataBackup1_OnBackupCompleted(object sender, System.EventArgs e) { LoadingForm.Fadeout(); if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("BackupSaved")) == CustomMessageBoxReturnValue.Ok) { Close(); } }
private void btnSave_Click(object sender, EventArgs e) { //Save settings; ConfigurationSettingsHelper.SaveEndpointAddress(txtEndPointAddress.Text); DialogResult = DialogResult.OK; CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("IPChanged")); Close(); }
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(); } }
private bool isValid() { if (dtpDateFrom.Text == string.Empty) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAndActionDateFrom"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); dtpDateFrom.Focus(); return(false); } if (dtpDateTo.Text == string.Empty) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAndActionDateTo"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); dtpDateTo.Focus(); return(false); } // Check that it has at least one Phase if (lbElectoralPhases.Items.Count == 0) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAndActionPhase"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); cbElectoralPhases.Focus(); return(false); } bool retValue = false; // Check that it has at least one region (ignore the ones marked as deleted) foreach (TreeNode node in tvRegions.Nodes) { if (checkChecked(node)) { retValue = true; break; } } if (!retValue) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAndActionRegion"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.OKOnly); return(false); } return(true); }
private void btnDeleteDocument_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog { InitialDirectory = DirectoryAndFileHelper.ClientDocumentsFolder, CheckPathExists = true, Multiselect = false, Title = ResourceHelper.GetResourceText("DeleteDocumentDialogTitle"), }; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } DirectoryInfo diSelectedFile = new DirectoryInfo(openFileDialog.FileName); DirectoryInfo diInitialDirectory = new DirectoryInfo(openFileDialog.InitialDirectory); if (Path.GetDirectoryName(diSelectedFile.FullName) != Path.GetDirectoryName(diInitialDirectory.FullName)) { //means they have changed the base directory. We can't allow that. CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DeleteDocumentUseDefaultDirectory")); return; } if (File.Exists(openFileDialog.FileName)) { if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DeleteDocumentWarning"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Ok) { //delete the local copy of the file File.Delete(openFileDialog.FileName); } } Document documentToDelete = new Document { Content = string.Empty, Filename = openFileDialog.FileName, DocumentType = ERMTDocumentType.Document }; DocumentHelper.Delete(documentToDelete); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DocumentSuccessfullyDeleted")); }
private void btnSave_Click(object sender, EventArgs e) { try { foreach (ModelFactor f in OrderedModelFactors) { ModelFactorHelper.Save(f); } CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ModelSavedOk")); ViewManager.CloseView(); } catch (Exception exception) { CustomMessageBox.ShowError(exception.Message); } }
public void FactorSaved(object sender, Factor factor) { try { FactorHelper.Validate(factor); FactorHelper.Save(factor); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("FactorSavedOk"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.OKOnly); ViewManager.ShowStart(); } catch (Exception exception) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText(exception.Message), CustomMessageBoxMessageType.Error, CustomMessageBoxButtonType.OKOnly); } }
private void btnSave_Click(object sender, EventArgs e) { if (Title == string.Empty || Latitude.ToString() == string.Empty || Longitude.ToString() == string.Empty || MarkerType.IDMarkerType == 0) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("MarkerValidation")); return; } if (_validFormData) { ((Form)Parent).DialogResult = DialogResult.OK; } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("LatitudeLongitudeFormatError")); } }
public void FactorDeleted(object sender, Factor factor) { try { if ( CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("AssociatedDataWillBeLost"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Ok) { FactorHelper.Delete(factor); } LoadCombo(); } catch (Exception ex) { CustomMessageBox.ShowMessage(ex.Message); } }
private bool ValidateScreen() { string message = string.Empty; if (string.IsNullOrEmpty(userCRUD.User.Name)) { message += ResourceHelper.GetResourceText("UserValidateFirstName") + "\r\n"; } if (string.IsNullOrEmpty(userCRUD.User.Lastname)) { message += ResourceHelper.GetResourceText("UserValidateLastName") + "\r\n"; } if (string.IsNullOrEmpty(userCRUD.User.Password)) { message += ResourceHelper.GetResourceText("UserValidatePass") + "\r\n"; } if (string.IsNullOrEmpty(userCRUD.User.Username)) { message += ResourceHelper.GetResourceText("UserValidateUsername") + "\r\n"; } if (string.IsNullOrEmpty(userCRUD.User.Email)) { message += ResourceHelper.GetResourceText("UserValidateEmail") + "\r\n"; } if (userCRUD.User.IDRole == 0) { message += ResourceHelper.GetResourceText("UserValidateRole") + "\r\n"; } if (!userCRUD.PasswordsMatch) { message += ResourceHelper.GetResourceText("UserValidatePassMatch") + "\r\n"; } bool valid = (message.Length == 0); if (!valid) { CustomMessageBox.ShowMessage(message); } return(valid); }
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(); } } }
private void btnDelete_Click(object sender, EventArgs e) { try { if ( CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ConfirmDeleteUser"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Cancel) { return; } UserHelper.Delete((User)cbUsers.SelectedItem); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("UserDeletedOk")); ViewManager.ShowStart(); } catch (Exception ex) { CustomMessageBox.ShowError(ex.Message); } }
public void SaveFactors(List <Factor> factors) { try { foreach (Factor f in factors) { FactorHelper.Save(f); } if (factors[0].InternalFactor) { return; } CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ReorderFactorsSavedOk"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.OKOnly); ViewManager.ShowStart(); } catch (Exception exception) { CustomMessageBox.ShowMessage(exception.Message, CustomMessageBoxMessageType.Error, CustomMessageBoxButtonType.OKOnly); } }
private void LoginUser() { User user; UserHelper.Login(txtUserName.Text, txtPassword.Text, out user); if (user != null) { ERMTSession.Instance.LoginUser(user); ViewManager.LoadApplicationInitialState(); ViewManager.ShowStart(); if (chkStaySignedIn.Checked) { CacheCurrentUser(); } } else { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("LoginFailed"), CustomMessageBoxMessageType.Error, CustomMessageBoxButtonType.OKOnly); } }
private void btnSave_Click(object sender, EventArgs e) { if (modelCRUD1.FactorsChanged() && CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("FactorsChangedMessage"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo) == CustomMessageBoxReturnValue.Cancel) { return; } try { Model model = modelCRUD1.Model; if (!ModelHelper.Validate(model)) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("RequiredName")); return; } List <ModelFactor> factors = modelCRUD1.ModelFactors; if (!factors.Any()) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("AtLeastOneFactor")); return; } model = ModelHelper.Save(model); foreach (ModelFactor mf in factors) { mf.IDModel = model.IDModel; ModelFactorHelper.Save(mf); } CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("ModelSavedOk")); ViewManager.LoadModelsMenu(); ViewManager.ShowStart(); EventManager.RaiseModelUpdated(); } catch (Exception exception) { CustomMessageBox.ShowError(exception.Message); } }
private void btnSave_Click(object sender, EventArgs e) { if (ValidateScreen()) { User user = userCRUD.User; try { UserHelper.Validate(user); if ((from u in UserHelper.GetAll() where user.Username == u.Username select u).Any()) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("UserNameAlreadyExists")); return; } UserHelper.Save(user); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("UserSavedOk")); ViewManager.ShowStart(); } catch (Exception ex) { CustomMessageBox.ShowError(ex.Message); } } }
private void tsmiEditRegionDeleteRegion_Click(object sender, EventArgs e) { Region region = (Region)_selectedNode.Tag; List <Region> childRegions = RegionHelper.GetAllRelated(region.IDRegion); List <Model> modelsUsingSelectedRegionOrChilds = ModelHelper.GetByRegions(childRegions); modelsUsingSelectedRegionOrChilds.AddRange(ModelHelper.GetByRegion(region.IDRegion)); if (modelsUsingSelectedRegionOrChilds.Count > 0) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionWithModels")); return; } if (CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionDeleteConfirm"), CustomMessageBoxMessageType.Warning, CustomMessageBoxButtonType.YesNo, new[] { region.RegionName }) == CustomMessageBoxReturnValue.Ok) { RegionHelper.Delete(region); LoadRegions(); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RegionDeleted")); } }
private void btnSave_Click(object sender, EventArgs e) { _phase.Title = txtPhaseName.Text; _phase.Column1Text = col1HtmlEditorControl.InnerHtml; _phase.Column2Text = col2HtmlEditorControl.InnerHtml; _phase.Column3Text = col3HtmlEditorControl.InnerHtml; _phase.PractitionersTips = practitionersTipsHtmlEditorControl.InnerHtml; // Reorder bullets (they were ordereded in the control, but need to reorder the underlying list: column1BulletList.SortList(); column2BulletList.SortList(); column3BulletList.SortList(); //delete phase bullets removed by the user. foreach (int idPhaseBullet in column1BulletList.PhaseBulletsIDsToDelete) { PhaseBulletHelper.Delete(idPhaseBullet); } foreach (int idPhaseBullet in column2BulletList.PhaseBulletsIDsToDelete) { PhaseBulletHelper.Delete(idPhaseBullet); } foreach (int idPhaseBullet in column3BulletList.PhaseBulletsIDsToDelete) { PhaseBulletHelper.Delete(idPhaseBullet); } foreach (PhaseBullet phaseBullet in column1BulletList.Bullets) { phaseBullet.ColumnNumber = 1; phaseBullet.IDPhase = _phase.IDPhase; } foreach (PhaseBullet phaseBullet in column2BulletList.Bullets) { phaseBullet.ColumnNumber = 2; phaseBullet.IDPhase = _phase.IDPhase; } foreach (PhaseBullet phaseBullet in column3BulletList.Bullets) { phaseBullet.ColumnNumber = 3; phaseBullet.IDPhase = _phase.IDPhase; } try { PhaseHelper.Validate(_phase); PhaseHelper.Save(_phase); PhaseBulletHelper.SaveColumnBullets(column1BulletList.Bullets); PhaseBulletHelper.SaveColumnBullets(column2BulletList.Bullets); PhaseBulletHelper.SaveColumnBullets(column3BulletList.Bullets); PhaseHelper.GenerateAllFiles(_phase); DocumentHelper.DownloadFilesAsync(); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("PhaseSavedOk")); LoadCombo(); } catch (Exception exception) { CustomMessageBox.ShowError(exception.Message); } }
private void btnOK_Click(object sender, EventArgs e) { bool restoreDataBase = chkRestoreDataBase.Checked; bool restoreFiles = chkRestoreFiles.Checked; bool restoreShapefiles = chkRestoreShapefiles.Checked; if (restoreDataBase == false && restoreFiles == false && restoreShapefiles == false) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("MustSelectAtLeastOneOption")); return; } if (Environment.OSVersion.Version.Major == 6) { if (!IsAdministrator()) { CustomMessageBoxReturnValue customMessageBoxReturnValue1 = CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RestoreAsAdministratorWarning"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo); if (customMessageBoxReturnValue1 == CustomMessageBoxReturnValue.Ok) { // it's windows Vista / 7. UAC requires the user to run as an ADMINISTRATOR to restart the Windows Service. ProcessStartInfo info = new ProcessStartInfo(); info.FileName = Assembly.GetEntryAssembly().Location; info.UseShellExecute = true; info.Verb = "runas"; // Provides Run as Administrator if (Process.Start(info) != null) { // The user accepted the UAC prompt. Application.Exit(); } } else { return; } } } CustomMessageBoxReturnValue customMessageBoxReturnValue2 = CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RestoreTimeWarning"), CustomMessageBoxMessageType.Information, CustomMessageBoxButtonType.YesNo); if (customMessageBoxReturnValue2 == CustomMessageBoxReturnValue.Cancel) { return; } OpenFileDialog ofd = new OpenFileDialog() { Filter = "Gzipped restore files(*.gz)|*.gz", Title = "Restore backup from..." }; if (ofd.ShowDialog() == DialogResult.OK) { Boolean backupFailed = false; try { string noCorrespondingRestorations = DocumentHelper.Restore(Convert.ToBase64String(File.ReadAllBytes(ofd.FileName)), restoreDataBase, restoreFiles, restoreShapefiles); RestartService("IDEA Geo Host Service"); if (noCorrespondingRestorations != string.Empty) { if (noCorrespondingRestorations.Contains("invaliddbversion")) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("DataRestoreInvalidDBVersion")); backupFailed = true; } if (noCorrespondingRestorations.Contains("errorrestoringdb")) { CustomMessageBox.ShowError(ResourceHelper.GetResourceText("DataRestoreError")); backupFailed = true; } noCorrespondingRestorations = noCorrespondingRestorations.Substring(0, noCorrespondingRestorations.Length - 3); noCorrespondingRestorations = " " + ResourceHelper.GetResourceText("SelectedRestoreOptionsWereNotBackupFile") + ": " + noCorrespondingRestorations + "."; } if (!backupFailed) { CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("DataRestored") + noCorrespondingRestorations); Application.Exit(); } } catch (Exception ex) { CustomMessageBox.ShowMessage(ex.Message, CustomMessageBoxMessageType.Error, CustomMessageBoxButtonType.OKOnly); } } }
private void tsmiEditRegionAddRoadsAndPOI_Click(object sender, EventArgs e) { ShapeFileERMTType shapeFileERMTType = ((ToolStripMenuItem)sender).Name == "tsmiEditRegionAddRoads" ? ShapeFileERMTType.Path : ShapeFileERMTType.POI; OpenFileDialog openFileDialog = new OpenFileDialog { Filter = "Shape Files (*.shp)|*.shp" }; DialogResult result = openFileDialog.ShowDialog(); if (result == DialogResult.OK) { FileInfo shapeFileInfo = new FileInfo(openFileDialog.FileName); try { 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")); return; } else { Region selectedRegion = (Region)_selectedNode.Tag; if (selectedRegion != null) { String newRegionFileName = SaveShapefiles(shapeFileInfo, selectedRegion, shapeFileERMTType); switch (shapeFileERMTType) { case ShapeFileERMTType.Path: { selectedRegion.PathFileName = newRegionFileName; break; } case ShapeFileERMTType.POI: { selectedRegion.POIFileName = newRegionFileName; break; } } RegionHelper.Save(selectedRegion); CustomMessageBox.ShowMessage(shapeFileERMTType == ShapeFileERMTType.Path ? ResourceHelper.GetResourceText("PathSuccessfullySaved") : ResourceHelper.GetResourceText("POISuccessfullySaved")); } } } catch (Exception ex) { //Shape was not valid } finally { } } }
private void btnSaveRiskAndAction_Click(object sender, EventArgs e) { if (isValid()) { // Save data: Model model = ERMTSession.Instance.CurrentModel; _alert.IDModel = model.IDModel; _alert.Code = tbCode.Text; _alert.Title = tbTitle.Text; _alert.DateFrom = Convert.ToDateTime(dtpDateFrom.Value); _alert.DateTo = Convert.ToDateTime(dtpDateTo.Value); _alert.RiskDescription = tbDescription.Text; _alert.Action = tbAction.Text; _alert.Result = tbResult.Text; _alert.Active = rbStatusActive.Checked; List <ModelRiskAlertPhase> modelRiskAlertPhaseListToSave = new List <ModelRiskAlertPhase>(); ModelRiskAlertPhase modelRiskAlertPhase = null; List <ModelRiskAlertPhase> modelRiskAlertPhaseList = ModelRiskAlertHelper.GetPhases(_alert); foreach (var lbPhase in lbElectoralPhases.Items) { bool found = false; foreach (ModelRiskAlertPhase oPhase in modelRiskAlertPhaseList) { if (((ComboBoxItemFace)lbPhase).IFase.IDPhase == oPhase.IDPhase) { found = true; break; } } if (!found) { modelRiskAlertPhase = new ModelRiskAlertPhase(); modelRiskAlertPhase.IDPhase = ((ComboBoxItemFace)lbPhase).IFase.IDPhase; modelRiskAlertPhaseListToSave.Add(modelRiskAlertPhase); } } List <ModelRiskAlertRegion> modelRiskAlertRegionList = ModelRiskAlertHelper.GetModelRiskAlertRegions(_alert); List <ModelRiskAlertRegion> modelRiskAlertRegionsToDelete = GetModelRiskAlertRegionsToDelete(modelRiskAlertRegionList); List <int> regionIDsToAdd = GetRegionIDsToAdd(modelRiskAlertRegionList); // Add new attachments: foreach (Control control in analysisPanel.Controls) { if (control is Updater) { if (((Updater)control).HasFile && ((Updater)control).Id == 0) { ModelRiskAlertAttachment att = new ModelRiskAlertAttachment(); att.IDModelRiskAlert = _alert.IDModelRiskAlert; att.AttachmentFile = ((Updater)control).FileName; // Nombre del archivo, sin el ID adelante. att.Content = Convert.ToBase64String(((Updater)control).Content); ModelRiskAlertHelper.SaveAttachment(att); } } } // Save the Alert: _alert = ModelRiskAlertHelper.Save(_alert); if (modelRiskAlertPhaseListToSave.Count > 0) { foreach (ModelRiskAlertPhase mrap in modelRiskAlertPhaseListToSave) { mrap.IDModelRiskAlert = _alert.IDModelRiskAlert; ModelRiskAlertHelper.SavePhase(mrap); } } if (regionIDsToAdd.Count > 0) { foreach (int regionID in regionIDsToAdd) { ModelRiskAlertRegion mrar = new ModelRiskAlertRegion(); mrar.IDModelRiskAlert = _alert.IDModelRiskAlert; mrar.IDRegion = regionID; ModelRiskAlertHelper.SaveRegion(mrar); } } if (modelRiskAlertRegionsToDelete.Count > 0) { foreach (ModelRiskAlertRegion mrar in modelRiskAlertRegionsToDelete) { ModelRiskAlertHelper.DeleteRegion(mrar); } } this.Close(); CustomMessageBox.ShowMessage(ResourceHelper.GetResourceText("RiskAlertSaved")); } }
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 { } } }