protected void llenarTabla() { string table = string.Empty; var datostablaFrase = new FrasesData().ObtenerFrases(); if (datostablaFrase.Code == 0) { foreach (var a in datostablaFrase.Result) { table += @" <tr>" + "<td>" + a.Id + "</td>" + "<td>" + a.enun1 + "</td>" + "<td>" + a.enun2 + "</td>" + "<td>" + a.correcta + "</td>" + "<td>" + a.opcion1 + "</td>" + "<td>" + a.opcion2 + "</td>" + "<td>" + a.opcion3 + "</td>" + "<td>" + "<button type='button' id='btnEditarFrase' class='btn btn-success csBtnEditarFrase' data-toggle='modal' data-target='#addFrase' data-id='" + a.Id + "' data-enun1='" + a.enun1 + "' data-enun2='" + a.enun2 + "' data-correcta='" + a.correcta + "' data-opcion1='" + a.opcion1 + "' data-opcion2='" + a.opcion2 + "' data-opcion3='" + a.opcion3 + "'><i class='fa fa-pencil'></i></button>" + "<button type='button' id='btnBorrarFrase' class='btn btn-danger csBtnBorrarFrase' data-toggle='modal' data-target='#borrarFrase' data-id='" + a.Id + "' data-tipo='1' ><i class='fa fa-trash-o'></i></button>" + "</td>" + " </tr>"; } ltlTableFrases.Text = table; } }
protected void GuardarFrase_Click(object sender, EventArgs e) { var frase = new fraseDTO { Id = int.Parse(IdFrase.Value), enun1 = enun1.Text, enun2 = enun2.Text, correcta = short.Parse(correcta.Text), opcion1 = opcion1.Text, opcion2 = opcion2.Text, opcion3 = opcion3.Text }; var objfrase = new FrasesData().GuardarFrase(frase); if (objfrase.Code != 0) { ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", objfrase.Message, true); } else { llenarTabla(); BorrarFormulario(); } }
private void GuardarDatosExcel(string path) { var cont = 1; //Leemos el archivo de excel try { var fracesLts = new List <fraseDTO>(); using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read)) { hssfworkbook = new XSSFWorkbook(file); xlsxToDT(); var table = dataSet1.Tables[0]; foreach (DataRow row in table.Rows) { var objFrase = new fraseDTO(); objFrase.Id = int.Parse(row[0].ToString()); objFrase.enun1 = row[1].ToString(); objFrase.enun2 = row[2].ToString(); objFrase.correcta = short.Parse(row[3].ToString()); objFrase.opcion1 = row[4].ToString(); objFrase.opcion2 = row[5].ToString(); objFrase.opcion3 = row[6].ToString(); objFrase.nivel = int.Parse(row[7].ToString()); fracesLts.Add(objFrase); cont++; } } File.Delete(path); var gFrases = new FrasesData().GuardarFrases(fracesLts); if (gFrases.Code != 0) { MensajeError("Al guardar frases, Detalle: " + gFrases.Message); } else { lblError.Text = "Archivo cargado con éxito."; } } catch (Exception ex) { //Se borra el archivo //app.Workbooks.Close(); System.IO.File.Delete(path); MensajeError("Al leer archivo en la linea: " + cont + " Detalle: " + ex.Message + " " + (ex.InnerException == null ? "" : ex.InnerException.Message)); } }
private void GuardarDatosExcelSilabitos(string path) { //Leemos el archivo de excel Excel.Application app = new Excel.Application(); Excel.Workbook workBook = app.Workbooks.Open(path); Excel.Worksheet workSheet = workBook.ActiveSheet; Excel.Range range = workSheet.UsedRange; var fracesLts = new List <fraseSilabitosDTO>(); var cont = 1; try { for (int i = 2; i <= range.Rows.Count; i++) { var objFrase = new fraseSilabitosDTO(); objFrase.Id = int.Parse(((Excel.Range)range.Cells[i, 1]).Text); objFrase.c1 = ((Excel.Range)range.Cells[i, 2]).Text; objFrase.c2 = ((Excel.Range)range.Cells[i, 3]).Text; objFrase.c3 = ((Excel.Range)range.Cells[i, 4]).Text; objFrase.p1 = ((Excel.Range)range.Cells[i, 5]).Text; objFrase.p1 = ((Excel.Range)range.Cells[i, 6]).Text; objFrase.orden = ((Excel.Range)range.Cells[i, 7]).Text; objFrase.acomodo = short.Parse(((Excel.Range)range.Cells[i, 8]).Text); objFrase.nivel = int.Parse(((Excel.Range)range.Cells[i, 9]).Text); fracesLts.Add(objFrase); cont++; } //Se borra el archivo app.Workbooks.Close(); System.IO.File.Delete(path); var gFrases = new FrasesData().GuardarFrasesSilabitos(fracesLts); if (gFrases.Code != 0) { MensajeError("Al guardar frases de Silabitos, Detalle: " + gFrases.Message); } else { lblError.Text = "Archivo cargado con éxito."; } } catch (Exception ex) { //Se borra el archivo app.Workbooks.Close(); System.IO.File.Delete(path); MensajeError("Al leer archivo en la linea: " + cont + " Detalle: " + ex.Message + " " + (ex.InnerException == null ? "" : ex.InnerException.Message)); } }
protected void BorrarFrase_Click(object sender, EventArgs e) { var objfrase = new FrasesData().BorrarFrase(int.Parse(IdFraseBorrar.Value), int.Parse(TipoFraseBorrar.Value)); if (objfrase.Code != 0) { ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", objfrase.Message, true); } else { llenarTabla(); } }