private string GetPhaseValueText(ModelRiskAlert alert) { StringBuilder returnText = new StringBuilder(); List <ModelRiskAlertPhase> modelRiskAlertPhases = ModelRiskAlertHelper.GetPhases(alert); foreach (var modelRiskAlertPhase in modelRiskAlertPhases) { Phase phase = PhaseHelper.Get(modelRiskAlertPhase.IDPhase); returnText.Append(phase.Title + "<br/>"); } return(returnText.ToString()); }
private void EditRiskAndAction_Load(object sender, EventArgs e) { //TREEVIEW Model model = ERMTSession.Instance.CurrentModel; if (model != null) { tvRegions.Nodes.Clear(); Region current = RegionHelper.Get(model.IDRegion); List <Region> regions = new List <Region>(); regions.Add(RegionHelper.Get(1)); if (current.IDParent.HasValue && current.IDParent != 1) { regions.Add(RegionHelper.Get(current.IDParent.Value)); } regions.Add(current); regions.AddRange(RegionHelper.GetAllChilds(current.IDRegion)); TreeNode node = new TreeNode() { Text = current.RegionName, Name = current.IDRegion.ToString(), Tag = current }; int mainRegionLevel = RegionHelper.GetLevel(current.IDRegion); tvRegions.Nodes.Add(node); AddChildRegions(tvRegions.Nodes[0], regions, mainRegionLevel); tvRegions.SelectedNode = tvRegions.Nodes[0]; tvRegions.ExpandAll(); } //Electoral Phase cbElectoralPhases.Items.Add(new ComboBoxItemFace(null)); cbElectoralPhases.Items.AddRange(PhaseHelper.GetAll().Select(p => new ComboBoxItemFace(p)).ToArray()); cbElectoralPhases.SelectedIndex = 0; // Add data from alert: if (_alert.IDModel != 0) { tbCode.Text = _alert.Code; tbTitle.Text = _alert.Title; dtpDateFrom.Value = _alert.DateFrom; dtpDateTo.Value = _alert.DateTo; tbDescription.Text = _alert.RiskDescription; tbAction.Text = _alert.Action; tbResult.Text = _alert.Result; rbStatusActive.Checked = _alert.Active; rbStatusInactive.Checked = !_alert.Active; // Phases: List <ModelRiskAlertPhase> modelRiskAlertPhaseList = ModelRiskAlertHelper.GetPhases(_alert); foreach (ModelRiskAlertPhase mrap in modelRiskAlertPhaseList) { foreach (var cboPhase in cbElectoralPhases.Items) { if (((ComboBoxItemFace)cboPhase).IFase != null) { if (((ComboBoxItemFace)cboPhase).IFase.IDPhase == mrap.IDPhase) { lbElectoralPhases.Items.Add(cboPhase); } } } } // Regions: List <ModelRiskAlertRegion> modelRiskAlertRegionList = ModelRiskAlertHelper.GetModelRiskAlertRegions(_alert); foreach (ModelRiskAlertRegion region in modelRiskAlertRegionList) { foreach (TreeNode node in tvRegions.Nodes) { CheckRegion(node, region); } } // Add analysis: List <ModelRiskAlertAttachment> modelRiskAlertAttachment = ModelRiskAlertHelper.GetModelRiskAlertAttachments(_alert); foreach (ModelRiskAlertAttachment att in modelRiskAlertAttachment) { addUpdater(att); } // And a last button to add more: addUpdater(); } else { Label newLabel = new Label { Text = ResourceHelper.GetResourceText("RiskAndActionSaveWarning"), ForeColor = Color.Red, Width = 500 }; analysisPanel.Controls.Add(newLabel); } }
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 LoadRisksDataGrid() { if (_enableSearch) { Model model = ERMTSession.Instance.CurrentModel; if (model != null) { // Load List: // Clear and create columns: dgvAlerts.Rows.Clear(); // Create a list of integer: List <int> regionsChecked = new List <int>(); foreach (TreeNode checkedNode in tvRegions.Nodes) { GetCheckedRegions(regionsChecked, checkedNode); } List <ModelRiskAlert> alerts = new List <ModelRiskAlert>(); if (IsMasterRAR) { dgvAlerts.Columns["Model"].Visible = true; alerts = ModelRiskAlertHelper.GetWithFilter(null, regionsChecked, (rbActive.Checked) ? true : (rbInactive.Checked ? (bool?)false : null)); } else { dgvAlerts.Columns["Model"].Visible = false; alerts = ModelRiskAlertHelper.GetWithFilter(model.IDModel, regionsChecked, (rbActive.Checked) ? true : (rbInactive.Checked ? (bool?)false : null)); } if (alerts == null || alerts.Count == 0) { return; } List <ModelRiskAlert> modelRiskAlertDistinctIDsList = new List <ModelRiskAlert>(); foreach (ModelRiskAlert alert in alerts) { if (IsAlertInList(alert, modelRiskAlertDistinctIDsList)) { continue; } List <ModelRiskAlertPhase> modelRiskAlertPhaseList = ModelRiskAlertHelper.GetPhases(alert); int i = 0; StringBuilder electoralPhase = new StringBuilder(""); foreach (ModelRiskAlertPhase mrap in modelRiskAlertPhaseList) { if (i > 0) { electoralPhase.Append(" - "); } electoralPhase.Append(PhaseHelper.Get(mrap.IDPhase).Title); i = i + 1; } Model alertModel = IsMasterRAR ? ModelHelper.GetModel(alert.IDModel) : ERMTSession.Instance.CurrentModel; i = dgvAlerts.Rows.Add(alert.Code, alertModel.Name, alert.Title, electoralPhase.ToString() != "" ? electoralPhase.ToString() : "--", alert.DateCreated, alert.DateModified, (alert.Active) ? "Active" : "Inactive", "+"); DataGridViewRow r = dgvAlerts.Rows[i]; r.Tag = alert; if (electoralPhase.ToString() != "") { r.Cells[2].ToolTipText = electoralPhase.ToString().Replace(",", Environment.NewLine); } if (alert.Active) { r.Cells[5].Style.BackColor = Color.Red; r.Cells[5].Style.ForeColor = Color.Black; } else { r.Cells[5].Style.BackColor = Color.Green; r.Cells[5].Style.ForeColor = Color.White; } } } } }