protected void btnIns_Click(object sender, EventArgs e) { PanelInsDettRic.Visible = true; AccessoView.ChangeMode(FormViewMode.Insert); AccessoView.Visible = true; if (descrizioneback.Text.Length == 0) { griBackend.Visible = false; pnlGrid.Visible = false; } else { BackEndDictionaryService bes = new BackEndDictionaryService(); listadescr = bes.GetByDescr(descrizioneback.Text); if (listadescr == null) { pnlGrid.Visible = false; } } }
//funzione per visualizzare i dati dell'ente ricercato private void GetGridResult() { BackEndDictionaryService s = new BackEndDictionaryService(); if ((codiceback.Text.Length == 0) && (descrizioneback.Text.Length == 0)) { this.info.AddMessage("Attenzione: Immettere Codice Backend o la Descrizione", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); griBackend.Visible = false; AccessoView.Visible = false; pnlGrid.Visible = false; PanelInsDettRic.Visible = false; //PanelRicerca.Visible = false; return; } if ((codiceback.Text.Length > 0) && (descrizioneback.Text.Length > 0)) { griBackend.Visible = false; AccessoView.Visible = false; pnlGrid.Visible = false; PanelInsDettRic.Visible = false; // PanelRicerca.Visible = false; this.info.AddMessage("Attenzione: Immettere Codice Backend o la Descrizione", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } if (codiceback.Text.Length > 0) { AccessoView.Visible = false; // Session["Accessopag"] = null; codeBk = new List <BackEndRefCode>(); appoggio = s.GetByCode(codiceback.Text); if (appoggio == null) { this.info.AddMessage("Attenzione: Codice non presente", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); griBackend.Visible = false; pnlGrid.Visible = false; AccessoView.Visible = false; return; } codeBk.Add(appoggio); griBackend.Visible = true; griBackend.DataSource = codeBk; Session["Accesso"] = codeBk; griBackend.DataBind(); griBackend.Visible = true; } else { codeBk = null; } if (descrizioneback.Text.Length > 0) { AccessoView.Visible = false; listadescr = s.GetByDescr(descrizioneback.Text); if (listadescr == null) { this.info.AddMessage("Attenzione: Descrizione non presente", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); griBackend.Visible = false; pnlGrid.Visible = false; AccessoView.Visible = false; return; } griBackend.DataSource = listadescr; Session["Accesso"] = listadescr; griBackend.DataBind(); griBackend.Visible = true; OnAccessoPagerIndexChanged("", 0); if (listadescr.Count <= PagerSize) { griBackend.BottomPagerRow.Visible = false; } // Session["Accessopag"] = null; } else if (codiceback.Text.Length == 0) { listadescr = null; } }
protected void AccessoView_ItemCommand(object sender, FormViewCommandEventArgs e) { if (e.CommandName.Equals("Insert")) { BackEndRefCode entity = new BackEndRefCode(); BackEndDictionaryService s = new BackEndDictionaryService(); try { if ((((TextBox)AccessoView.FindControl("TextCode")).Text != null) && (((TextBox)AccessoView.FindControl("TextCode")).Text != "")) { codInser = s.GetByCode(((TextBox)AccessoView.FindControl("TextCode")).Text); if (codInser != null) { this.info.AddMessage("Attenzione: codice backend e' legato ad un altro accesso", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } entity.Codice = ((TextBox)AccessoView.FindControl("TextCode")).Text; } else { this.info.AddMessage("Attenzione: codice backend e' obbligatorio", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } entity.Descrizione = ((TextBox)AccessoView.FindControl("TextDescrizione")).Text; entity.Categoria = ((TextBox)AccessoView.FindControl("TextCategoria")).Text; entity.DescrizionePlus = ((TextBox)AccessoView.FindControl("TextDescrizionePlus")).Text; } catch { this.info.AddMessage("Attenzione: si è verificato un errore", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } if (entity.Descrizione == "") { entity.Descrizione = null; } if (entity.Categoria == "") { entity.Categoria = null; } if (entity.DescrizionePlus == "") { entity.DescrizionePlus = null; } try { s.Insert(entity); if (descrizioneback.Text.Length > 0) { listadescr = s.GetByDescr(descrizioneback.Text); if (listadescr != null) { Session["Accesso"] = listadescr; if (listadescr.Count > 0) { int index = listadescr.IndexOf(listadescr.First(x => x.Codice == entity.Codice)); OnAccessoPagerIndexChanged("", index / PagerSize); // OnAccessoPagerIndexChanged("", 0); if (listadescr.Count <= PagerSize) { griBackend.BottomPagerRow.Visible = false; } } } } else { griBackend.Visible = false; pnlGrid.Visible = false; } } catch (Exception ex) { this.info.AddMessage("Inserimento non riuscito: Errore in banca dati dettagli " + ex.Message, Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } this.info.AddMessage("Accesso inserito", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO); // griBackend.Visible = false; // AccessoView.Visible = false; this.AccessoView.DataSource = null; this.AccessoView.DataBind(); } else { // BackEndRefCode entity = (BackEndRefCode)Session["AccessoId"]; entity = (BackEndRefCode)Session["AccessoId"]; int idCnt = Int32.Parse(((HiddenField)AccessoView.FindControl("hfIdAccesso")).Value); if (entity == null) { return; } if (entity.Id == idCnt) { if (e.CommandName.Equals("Update")) { try { AccessoView.ChangeMode(FormViewMode.Edit); //((TextBox)AccessoView.FindControl("TextCode")); if ((((TextBox)AccessoView.FindControl("TextCode")).Text != null) && (((TextBox)AccessoView.FindControl("TextCode")).Text != "")) { codInser = s.GetByCode(((TextBox)AccessoView.FindControl("TextCode")).Text); if ((codInser != null) && (entity.Id != codInser.Id)) { this.info.AddMessage("Attenzione: codice backend e' legato ad un altro accesso", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } entity.Codice = ((TextBox)AccessoView.FindControl("TextCode")).Text; } else { this.info.AddMessage("Attenzione: codice backend e' obbligatorio", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } entity.Descrizione = ((TextBox)AccessoView.FindControl("TextDescrizione")).Text; entity.Categoria = ((TextBox)AccessoView.FindControl("TextCategoria")).Text; entity.DescrizionePlus = ((TextBox)AccessoView.FindControl("TextDescrizionePlus")).Text; List <BackEndRefCode> bkEnt = (List <BackEndRefCode>)Session["Accesso"]; int index = bkEnt.IndexOf(bkEnt.First(x => x.Id == idCnt)); OnAccessoPagerIndexChanged("", index / PagerSize); if (bkEnt.Count <= PagerSize) { griBackend.BottomPagerRow.Visible = false; } } catch { this.info.AddMessage("Attenzione: si è verificato un errore", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } } if (e.CommandName.Equals("Delete")) { try { //metodo per l'update s.Delete(idCnt); if (descrizioneback.Text.Length > 0) { listadescr = s.GetByDescr(descrizioneback.Text); if (listadescr != null) { Session["Accesso"] = listadescr; OnAccessoPagerIndexChanged("", 0); if (listadescr.Count <= PagerSize) { griBackend.BottomPagerRow.Visible = false; } } } else { griBackend.Visible = false; pnlGrid.Visible = false; } } catch (Exception) { this.info.AddMessage("Cancellazione non riuscita: Errore in banca dati", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } this.info.AddMessage("Accesso cancellato", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO); PanelInsDettRic.Visible = false; // griBackend.Visible = false; AccessoView.Visible = false; } } if (e.CommandName.Equals("Update")) { if (entity.Descrizione == "") { entity.Descrizione = null; } if (entity.Categoria == "") { entity.Categoria = null; } if (entity.DescrizionePlus == "") { entity.DescrizionePlus = null; } try { //metodo per l'update s.Update(entity); } catch (Exception) { this.info.AddMessage("Aggiornamento non riuscito: Errore in banca dati", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.ERROR); return; } this.info.AddMessage("Accesso modificato", Com.Delta.Messaging.MapperMessages.LivelloMessaggio.INFO); // griBackend.Visible = true; // griBackend.DataSource = listadescrupd; // griBackend.DataBind(); PanelInsDettRic.Visible = false; AccessoView.Visible = false; } } }