Пример #1
0
 private void btnSalva_Click(object sender, EventArgs e)
 {
     if (validateForm())
     {
         using (databaseContext = CreateDatabaseContext())
         {
             PersonaggiManagerNew manager = new PersonaggiManagerNew(databaseContext);
             bool   res    = false;
             string nome   = txtNome.Text.Trim();
             long   specie = 0;
             if (cmbSpecie.SelectedValue != null)
             {
                 specie = (long)cmbSpecie.SelectedValue;
             }
             long     tipo          = long.Parse(cmbTipo.SelectedValue.ToString());
             long     punti         = long.Parse(mstxPunti.Text.Trim());
             string   sesso         = cmbSesso.SelectedItem.ToString();
             long     LatoOscuro    = long.Parse(mstxLatoOscuro.Text.Trim());
             DateTime dataCreazione = dtCreazione.Value.Date;
             long     vivo          = chkVivo.Checked ? 1 : 0;
             DateTime?dataMorte     = null;
             string   password      = txtPassword.Text.Trim();
             long     fazione       = (long)cmbFazione.SelectedValue;
             string   titolo        = txtTitolo.Text.Trim();
             if (!chkVivo.Checked)
             {
                 dataMorte = dtMorte.Value.Date;
             }
             if (numeroPg.HasValue)
             {
                 res = manager.SaveCharacter(numeroPg.Value, nome, specie, tipo, punti, sesso, LatoOscuro, dataCreazione, vivo, dataMorte, password, fazione, titolo, attitudes);
             }
             else
             {
                 long?newNumPg = null;
                 if (!string.IsNullOrWhiteSpace(mstxNumeroPg.Text.Trim()))
                 {
                     newNumPg = long.Parse(mstxNumeroPg.Text.Trim());
                 }
                 res = manager.CreateNewCharacter(newNumPg, numeroSW.Value, nome, specie, tipo, punti, sesso, LatoOscuro, dataCreazione, vivo, dataMorte, password, fazione, titolo, attitudes);
             }
             if (res)
             {
                 databaseContext.SaveChanges();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Errore durante il salvataggio, ricontrollare i dati inseriti");
             }
         }
     }
 }