private void dataGridView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete) { if (MessageBox.Show("¿Esta Seguro que desea eliminar el juego seleccionado?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { games = stdClassCSharp.readJsonFile("games.json"); if (games["UpdateIndex", TiposDevolver.Boleano]) { stdClassCSharp updates = stdClassCSharp.readJsonFile("updates.json"); updates.Remove(games["UpdateIndex", TiposDevolver.Entero]); updates.writeJsonFile("updates.json"); } if (games["DlcIndex", TiposDevolver.Boleano]) { stdClassCSharp dlcs = stdClassCSharp.readJsonFile("dlcs.json"); dlcs.Remove(games["DlcIndex", TiposDevolver.Entero]); dlcs.writeJsonFile("dlcs.json"); } games.Remove(Convert.ToInt32(dataGridView1.CurrentRow.Cells["colIndex"].Value)); games.writeJsonFile("games.json"); if (txtFiltro.Text == "") { llenarGrid(); } else { txtFiltro.Text = ""; } } } }
private void guardarJuego() { stdClassCSharp gamesStd = stdClassCSharp.readJsonFile("games.json"); stdClassCSharp updatesStd = stdClassCSharp.readJsonFile("updates.json"); stdClassCSharp dlcStd = stdClassCSharp.readJsonFile("dlcs.json"); game["Titulo"] = txtTitulo.Text.Trim(); if (!string.IsNullOrWhiteSpace(txtDescripcion.Text)) { game["Descripcion"] = txtDescripcion.Text; } else if (game["Descripcion", TiposDevolver.Boleano]) { game.Remove("Descripcion"); } if (!string.IsNullOrWhiteSpace(txtPeso.Text)) { game["Peso"] = txtPeso.Text; } else if (game["Peso", TiposDevolver.Boleano]) { game.Remove("Peso"); } if (!string.IsNullOrWhiteSpace(txtFormato.Text)) { game["Formato"] = txtFormato.Text; } else if (game["Formato", TiposDevolver.Boleano]) { game.Remove("Formato"); } if (!string.IsNullOrWhiteSpace(txtPassword.Text)) { game["Password"] = txtPassword.Text; } else if (game["Password", TiposDevolver.Boleano]) { game.Remove("Password"); } if (!string.IsNullOrWhiteSpace(txtUploadBy.Text)) { game["UploadBy"] = txtUploadBy.Text; } else if (game["UploadBy", TiposDevolver.Boleano]) { game.Remove("UploadBy"); } if (!string.IsNullOrWhiteSpace(txtUrlAvatar.Text)) { game["ImagenDiscord"] = txtUrlAvatar.Text; } else if (game["ImagenDiscord", TiposDevolver.Boleano]) { game.Remove("ImagenDiscord"); } if (!string.IsNullOrWhiteSpace(txtPortada.Text)) { game["ImagenJuego"] = txtPortada.Text; } else if (game["ImagenJuego", TiposDevolver.Boleano]) { game.Remove("ImagenJuego"); } game["Links"] = new stdClassCSharp(true); foreach (string link in txtGameLinks.Text.Trim().Split(new String[] { Environment.NewLine }, StringSplitOptions.None)) { game["Links"].Add(link); } if (!string.IsNullOrWhiteSpace(txtVersion.Text) && !string.IsNullOrWhiteSpace(txtLinksUpdate.Text)) { update["Titulo"] = txtTitulo.Text.Trim(); update["Version"] = txtVersion.Text.Trim(); if (!string.IsNullOrWhiteSpace(txtPesoUpdate.Text)) { update["Peso"] = txtPesoUpdate.Text; } else if (update["Peso", TiposDevolver.Boleano]) { update.Remove("Peso"); } if (!string.IsNullOrWhiteSpace(txtFormatoUpdate.Text)) { update["Formato"] = txtFormatoUpdate.Text; } else if (update["Formato", TiposDevolver.Boleano]) { update.Remove("Formato"); } if (!string.IsNullOrWhiteSpace(txtPasswordUpdate.Text)) { update["Password"] = txtPasswordUpdate.Text; } else if (update["Password", TiposDevolver.Boleano]) { update.Remove("Password"); } if (!string.IsNullOrWhiteSpace(txtUploadBy.Text)) { update["UploadBy"] = txtUploadBy.Text; } else if (update["UploadBy", TiposDevolver.Boleano]) { update.Remove("UploadBy"); } if (!string.IsNullOrWhiteSpace(txtUrlAvatar.Text)) { update["ImagenDiscord"] = txtUrlAvatar.Text; } else if (update["ImagenDiscord", TiposDevolver.Boleano]) { update.Remove("ImagenDiscord"); } if (!string.IsNullOrWhiteSpace(txtPortada.Text)) { update["ImagenJuego"] = txtPortada.Text; } else if (update["ImagenJuego", TiposDevolver.Boleano]) { update.Remove("ImagenJuego"); } update["Links"] = new stdClassCSharp(true); foreach (string link in txtLinksUpdate.Text.Trim().Split(new String[] { Environment.NewLine }, StringSplitOptions.None)) { update["Links"].Add(link); } } if (!string.IsNullOrWhiteSpace(txtLinksDlc.Text)) { dlc["Titulo"] = txtTitulo.Text.Trim(); if (!string.IsNullOrWhiteSpace(txtPesoDlc.Text)) { dlc["Peso"] = txtPesoDlc.Text; } else if (dlc["Peso", TiposDevolver.Boleano]) { dlc.Remove("Peso"); } if (!string.IsNullOrWhiteSpace(txtformatoDlc.Text)) { dlc["Formato"] = txtformatoDlc.Text; } else if (dlc["Formato", TiposDevolver.Boleano]) { dlc.Remove("Formato"); } if (!string.IsNullOrWhiteSpace(txtPasswordDlc.Text)) { dlc["Password"] = txtPasswordDlc.Text; } else if (dlc["Password", TiposDevolver.Boleano]) { dlc.Remove("Password"); } if (!string.IsNullOrWhiteSpace(txtUploadBy.Text)) { dlc["UploadBy"] = txtUploadBy.Text; } else if (dlc["UploadBy", TiposDevolver.Boleano]) { dlc.Remove("UploadBy"); } if (!string.IsNullOrWhiteSpace(txtUrlAvatar.Text)) { dlc["ImagenDiscord"] = txtUrlAvatar.Text; } else if (dlc["ImagenDiscord", TiposDevolver.Boleano]) { dlc.Remove("ImagenDiscord"); } if (!string.IsNullOrWhiteSpace(txtPortada.Text)) { dlc["ImagenJuego"] = txtPortada.Text; } else if (dlc["ImagenJuego", TiposDevolver.Boleano]) { dlc.Remove("ImagenJuego"); } dlc["Links"] = new stdClassCSharp(true); foreach (string link in txtLinksDlc.Text.Trim().Split(new String[] { Environment.NewLine }, StringSplitOptions.None)) { dlc["Links"].Add(link); } } if (game["UpdateIndex", TiposDevolver.Boleano]) { if (update.toArray().Length == 0) { updatesStd.Remove(game["UpdateIndex", TiposDevolver.Entero]); game.Remove("UpdateIndex"); } else { updatesStd[game["UpdateIndex", TiposDevolver.Entero]] = update; } } else if (update.toArray().Length > 0) { updatesStd.Add(update); game["UpdateIndex"] = updatesStd.toArray().Length - 1; } if (game["DlcIndex", TiposDevolver.Boleano]) { if (dlc.toArray().Length == 0) { dlcStd.Remove(game["DlcIndex", TiposDevolver.Entero]); game.Remove("DlcIndex"); } else { dlcStd[game["DlcIndex", TiposDevolver.Entero]] = dlc; } } else if (dlc.toArray().Length > 0) { dlcStd.Add(dlc); game["DlcIndex"] = dlcStd.toArray().Length - 1; } if (indexGame == -1) { gamesStd.Add(game); } else { gamesStd[indexGame] = game; } gamesStd.writeJsonFile("games.json"); updatesStd.writeJsonFile("updates.json"); dlcStd.writeJsonFile("dlcs.json"); }