private void Votacion_Load(object sender, EventArgs e) { //this.TopMost = true; //this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; ConexionPostgres conn = new ConexionPostgres(); string cadenaSql = "SELECT id_pregunta FROM modelo.pregunta_actual WHERE nit = '" + this.valor + "' AND fecha = '" + this.fecha + "';"; var resultado = conn.consultar(cadenaSql); this.id_pregunta_actual = resultado[0]["id_pregunta"]; string cadenaSql1 = "SELECT pregunta FROM modelo.pregunta WHERE id_pregunta='" + id_pregunta_actual + "';"; var resultado1 = conn.consultar(cadenaSql1); string pregunta_actual = resultado1[0]["pregunta"]; pregunta.Text = pregunta_actual; string cadenaSql2 = "SELECT id_opcion, opcion FROM modelo.opcion_pregunta WHERE id_pregunta='" + id_pregunta_actual + "' ORDER BY id_opcion;"; var resultado2 = conn.consultar(cadenaSql2); string opcion = resultado2[0]["opcion"]; Label[] labels = new Label[10]; labels[0] = label1; labels[1] = label2; labels[2] = label3; labels[3] = label4; labels[4] = label5; labels[5] = label6; labels[6] = label7; labels[7] = label8; labels[8] = label9; labels[9] = label10; foreach (Dictionary<string, string> fila in resultado2) { int indice = Int32.Parse(fila["id_opcion"]); indice = indice - 1; labels[indice].Text = fila["id_opcion"] + "-" + fila["opcion"]; } }
private void IniciarAsamblea_Load(object sender, EventArgs e) { //this.TopMost = true; //this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; ConexionPostgres conn = new ConexionPostgres(); var resultado = conn.consultar("SELECT * FROM modelo.tipo_asamblea; "); List<Select> sl = new List<Select>(); foreach (Dictionary<string, string> fila in resultado) { int numVal = Int32.Parse(fila["id_tipo_asamblea"]); // tipoasambleabix.Items.Add(new ListItem ( fila["nombre"], numVal)); sl.Add(new Select() { Text = fila["tipo"], Value = fila["id_tipo_asamblea"] }); } tipoasambleabix.DataSource = sl; tipoasambleabix.DisplayMember = "Text"; //http://stackoverflow.com/questions/3063320/combobox-adding-text-and-value-to-an-item-no-binding-source var resultado1 = conn.consultar("SELECT * FROM modelo.propiedad_horizontal; "); List<Select> sl1 = new List<Select>(); foreach (Dictionary<string, string> fila in resultado1) { int numVal1 = Int32.Parse(fila["nit"]); // tipoasambleabix.Items.Add(new ListItem ( fila["nombre"], numVal)); sl1.Add(new Select() { Text = fila["nit"] + "- " + fila["nombre"], Value = fila["nit"] }); } comboBox1.DataSource = sl1; comboBox1.DisplayMember = "Text"; }
void Registro_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '¡') { entro = true; return; } if (entro == true) { ConexionPostgres conn = new ConexionPostgres(); var resultado = conn.consultar("SELECT * FROM modelo.asamblea; "); var texto = this.lectura.Text; string[] textos = texto.Split('\''); if (e.KeyChar == 49) { string uni = textos[1].Remove(textos[1].Length - 1); //MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'PRESENCIAL ."); label3.Text=("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'PRESENCIAL ."); var cadenaSql = "INSERT INTO modelo.asamblea_unidad_residencial(nit, numero_unidad, fecha, id_tipo_asistencia_inicial) VALUES ('" + textos[0] + "','" + uni + "','" + this.fecha + "','1');"; conn.registrar(cadenaSql); } if (e.KeyChar == 50) { string uni = textos[1].Remove(textos[1].Length - 1); MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'PODER ."); var cadenaSql = "INSERT INTO modelo.asamblea_unidad_residencial(nit, numero_unidad, fecha, id_tipo_asistencia_inicial) VALUES ('" + textos[0] + "','" + uni + "','" + this.fecha + "','2');"; conn.registrar(cadenaSql); } entro = false; } }
private void Registro_Load(object sender, EventArgs e) { //$("body").keyup(function(e){ console.log(e)}) //this.TopMost = true; //this.FormBorderStyle = FormBorderStyle.None; this.WindowState = FormWindowState.Maximized; ConexionPostgres conn = new ConexionPostgres(); }
private void button2_Click(object sender, EventArgs e) { MessageBox.Show("ESTE PROCESO TARDARA UNOS MINUTOS, ESPERE MIENTRAS SE GENERA EL ARCHIVO, SALDRA LA CONFIRMACION DEL MISMO"); ConexionPostgres conn = new ConexionPostgres(); Select sl1 = comboBox1.SelectedItem as Select; string nit = sl1.Value; var resultado = conn.consultar("SELECT * FROM modelo.unidad_residencial WHERE nit = '"+nit+"'; "); foreach (Dictionary<string, string> fila in resultado) { var codigo = fila["nit"] + "-" + fila["numero_unidad"]+"+"; string barcode = codigo; Bitmap bitm = new Bitmap(barcode.Length * 25, 130); using (Graphics graphic = Graphics.FromImage(bitm)) { Font newfont = new Font("Bar-code 39 lesbar", 25); PointF point = new PointF(10f, 50f); SolidBrush black = new SolidBrush(Color.Black); SolidBrush white = new SolidBrush(Color.White); graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height); graphic.DrawString("*" + barcode + "*", newfont, black, point); //dibujar el rectangulo del rededor Pen blackpen = new Pen(Color.Black, 1); Rectangle rec = new Rectangle(0,0,290,120); graphic.DrawRectangle(blackpen, rec); //escribir encabezado y pie de pagina var cadenaSql1 = "select nombre from modelo.propiedad_horizontal where nit='" + nit+"' "; var nombre1 = conn.consultar(cadenaSql1); var nombre = conn.consultar(cadenaSql1)[0]["nombre"]; string drawstring = nombre; Font drawfont = new Font("arial", 16); SolidBrush drawbrush = new SolidBrush(Color.Black); float x = 5f; float y = 10f; graphic.DrawString(drawstring,drawfont, drawbrush,x,y); var codigo1 = fila["nombre_completo"] + "-" + fila["numero_unidad"]; string drawstring1 = codigo1; Font drawfont1 = new Font("arial", 10); SolidBrush drawbrush1 = new SolidBrush(Color.Black); float x1 = 10f; float y1= 95f; graphic.DrawString(drawstring1, drawfont1, drawbrush1, x1, y1); } using (MemoryStream Mmst = new MemoryStream()) { string nombreImagen = "ImagenesBarras\\"+ fila["nit"] + "-" + fila["numero_unidad"] + ".png"; bitm.Save(nombreImagen, ImageFormat.Jpeg); } } string[] fotos = new string[resultado.ToArray().Length]; for (int indice = 0; indice < resultado.ToArray().Length; indice++) { Dictionary<string, string> fila = resultado.ToArray()[indice]; fotos[indice] = "ImagenesBarras\\" + fila["nit"] + "-" + fila["numero_unidad"] + ".png"; } Pdf documentoPdf = new Pdf(); string nuevo = documentoPdf.crearPdf(fotos); MessageBox.Show("El documento ha sido creado en la ruta: "+nuevo); }
private void votarPorOpcion(char opcion) { //carcater esta entre 48='0' y 57= '9' http://www.asciitable.com/ if (48 <= opcion && opcion <= 57) { ConexionPostgres conn = new ConexionPostgres(); var texto = this.textBox1.Text; string[] textos = texto.Split('\''); string numero_unidad = textos[1].Remove(textos[1].Length - 1); string nit = textos[0]; MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: " + opcion.ToString()); var cadenaSql = "INSERT INTO modelo.voto (id_pregunta, numero_unidad, id_opcion, nit, fecha) VALUES ('"+this.id_pregunta_actual +"','"+numero_unidad+"','"+opcion.ToString()+"','"+nit+"','"+this.fecha+"');"; conn.registrar(cadenaSql); } }
private void GenerarCodigo_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; ConexionPostgres conn = new ConexionPostgres(); var resultado = conn.consultar("SELECT * FROM modelo.propiedad_horizontal; "); List<Select> sl = new List<Select>(); foreach (Dictionary<string, string> fila in resultado) { int numVal = Int32.Parse(fila["nit"]); // tipoasambleabix.Items.Add(new ListItem ( fila["nombre"], numVal)); sl.Add(new Select() { Text = fila["nit"] + "- " + fila["nombre"], Value = fila["nit"] }); } comboBox1.DataSource = sl; comboBox1.DisplayMember = "Text"; }
private void button1_Click(object sender, EventArgs e) { ConexionPostgres conn = new ConexionPostgres(); var cadenaSql = "INSERT INTO modelo.propiedad_horizontal(nit, nombre) values ('" + nit.Text + "','" + nombrePropiedad.Text + "');"; var resultado = conn.registrar(cadenaSql); if (resultado) { nit.Text = ""; nombrePropiedad.Text = ""; MessageBox.Show("LA PROPIEDAD HA SIDO REGISTRADA CONTINUE CON EL REGISTRO DE LA ASAMBLEA"); } else { MessageBox.Show("LA PROPIEDAD NO HA SIDO REGISTRADA "); } }
void Registro_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '¡') { entro = true; return; } if (entro == true) { ConexionPostgres conn = new ConexionPostgres(); var resultado = conn.consultar("SELECT * FROM modelo.asamblea; "); var texto = this.textBox1.Text; string[] textos = texto.Split('\''); MessageBox.Show(textos[1]); // 49=1 50=2 51=3 if (e.KeyChar == '1') { string uni = textos[1].Remove(textos[1].Length - 1); MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'PRESENCIAL ."); var cadenaSql = "UPDATE modelo.asamblea_unidad_residencial SET id_tipo_asistencia_final ='1' WHERE nit = '" + textos[0] + "'AND numero_unidad= '"+uni+ "' AND fecha='" + this.fecha + "' AND id_tipo_asistencia_final ='3';"; conn.registrar(cadenaSql); } if (e.KeyChar == '2') { string uni = textos[1].Remove(textos[1].Length - 1); MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'PODER ."); var cadenaSql = "UPDATE modelo.asamblea_unidad_residencial SET id_tipo_asistencia_final ='2' WHERE nit = '" + textos[0] + "'AND numero_unidad= '" + uni + "' AND fecha='" + this.fecha + "' AND id_tipo_asistencia_final ='3';"; conn.registrar(cadenaSql); } if (e.KeyChar == '3') { string uni = textos[1].Remove(textos[1].Length - 1); MessageBox.Show("UNIDAD " + textos[1] + "LA OPCION SELECTIONADA FUE: '" + e.KeyChar.ToString() + "'DESCARGAR ANTES DE FINALIZAR ."); var cadenaSql = "UPDATE modelo.asamblea_unidad_residencial SET id_tipo_asistencia_final ='4' WHERE nit = '" + textos[0] + "'AND numero_unidad= '" + uni + "' AND fecha='" + this.fecha + "' AND id_tipo_asistencia_final ='3';"; conn.registrar(cadenaSql); } entro = false; } }
private void button5_Click(object sender, EventArgs e) { ConexionPostgres conn = new ConexionPostgres(); //var cadenaSqlñ = "SELECT sum(coeficiente) FROM modelo.unidad_residencial WHERE nit='" + this.valor + "';"; // var result = conn.consultar(cadenaSqlñ); //if (System.Convert.ToString(asistenciaCasoCoeficientes) != "11.645") { string quorum = ""; var cadenaSql = "SELECT sum(b.coeficiente) FROM modelo.asamblea_unidad_residencial AS a LEFT JOIN modelo.unidad_residencial AS b ON (a.numero_unidad = b.numero_unidad AND a.nit = b.nit) WHERE a.nit='" + this.valor + "' AND a.fecha='" + this.fecha + "';"; double asistenciaCasoCoeficientes = Double.Parse(conn.consultar(cadenaSql)[0]["sum"]); cadenaSql = "SELECT sum(coeficiente) FROM modelo.unidad_residencial WHERE nit='" + this.valor + "';"; double registradosCasoCoeficientes = Double.Parse(conn.consultar(cadenaSql)[0]["sum"]); var cadenaSql1 = "SELECT sum(b.coeficiente) FROM modelo.asamblea_unidad_residencial AS a LEFT JOIN modelo.unidad_residencial AS b ON (a.numero_unidad = b.numero_unidad AND a.nit = b.nit) WHERE a.nit='" + this.valor + "' AND a.fecha='" + this.fecha + "' and id_tipo_asistencia_final ='4';"; var registro = conn.consultar(cadenaSql1); if (registro[0]["sum"] != "") { double registradosCasoUnidadesdescargue = Double.Parse(conn.consultar(cadenaSql1)[0]["sum"]); double porcentaje1 = (100 * (asistenciaCasoCoeficientes - registradosCasoUnidadesdescargue) / registradosCasoCoeficientes); porcentaje1 = Math.Round(porcentaje1, 2); quorum = (porcentaje1).ToString(); label5.Text = quorum + "%"; label5.Visible = true; } else { double porcentaje = (100 * (asistenciaCasoCoeficientes) / registradosCasoCoeficientes); porcentaje = Math.Round(porcentaje, 2); quorum = (porcentaje).ToString(); label5.Text = quorum + "%"; label5.Visible = true; } // } // else // { // label5.Text = "0%"; // label5.Visible = true; // } }
private void button4_Click(object sender, EventArgs e) { Select sl = tipoasambleabix.SelectedItem as Select; string valor = sl.Value; Select sl1 = comboBox1.SelectedItem as Select; string valor1 = sl1.Value; ConexionPostgres conn = new ConexionPostgres(); var cadenaSql = "INSERT INTO modelo.asamblea(nit, nombre, fecha, tiempo_inicial, tiempo_final, id_tipo_asamblea) VALUES('" + valor1 + "','" + nombreasamblea.Text + "', '" + dtp.Value.Date.Year + "-" + dtp.Value.Date.Month + "-" + dtp.Value.Date.Day + "', '" + horaasamblea.Text + "', '" + horafinal.Text + "', '" + valor + "'); "; var resultado = conn.registrar(cadenaSql); if (resultado) { nombreasamblea.Text = ""; horaasamblea.Text = ""; horafinal.Text = ""; MessageBox.Show("SE REALIZÓ EL REGISTRO DE LA ASAMBLEA CONTINUAR EN EL FORMULARIO PRINCIPAL"); } else { MessageBox.Show("NO SE REALIZÓ EL REGISTRO DE LA ASAMBLEA"); } }
private void button2_Click(object sender, EventArgs e) { string[] opcionesText = new string[10]; opcionesText[0] = textBox1.Text; opcionesText[1] = textBox2.Text; opcionesText[2] = textBox3.Text; opcionesText[3] = textBox4.Text; opcionesText[4] = textBox5.Text; opcionesText[5] = textBox6.Text; opcionesText[6] = textBox7.Text; opcionesText[7] = textBox8.Text; opcionesText[8] = textBox9.Text; opcionesText[9] = textBox10.Text; List<string> opciones = new List<string>(); for (int i = 0; i<opcionesText.ToArray().Length; i++) { if (opcionesText[i] != "") { opciones.Add(opcionesText[i]); } } ConexionPostgres conn = new ConexionPostgres(); var cadenaSql = "INSERT INTO modelo.pregunta(pregunta) VALUES('"+ textBox12.Text+ "') RETURNING id_pregunta;"; var id_pregunta = conn.consultar(cadenaSql)[0]["id_pregunta"]; Select sl1 = comboBox1.SelectedItem as Select; //var cadenaSql2 = "INSERT INTO modelo.pregunta_actual(nit, fecha,id_pregunta) VALUES('" + this.valor + "','"+this.fecha+"','"+id_pregunta+"') ;"; var cadenaSql2 = "DELETE FROM modelo.pregunta_actual WHERE nit = '"+this.valor+"'; INSERT INTO modelo.pregunta_actual(nit, fecha, id_pregunta) VALUES('"+this.valor+"', '"+this.fecha+"', '"+id_pregunta+"'); "; conn.registrar(cadenaSql2); for (int i = 0; i < opciones.ToArray().Length; i++) { var id_opcion = i + 1; var cadenaSql1 = "INSERT INTO modelo.opcion_pregunta(id_opcion, id_pregunta, opcion) VALUES('" + id_opcion + "', '"+id_pregunta+"', '" + opciones[i] + "')"; conn.registrar(cadenaSql1); } MessageBox.Show("LA PREGRUNTA HA SIDO REGISTRADA CONTINUE CON LA VOTACION"); Votacion voto = new Votacion(this.fecha, this.valor); voto.Show(); }
private void button8_Click(object sender, EventArgs e) { ConexionPostgres conn1 = new ConexionPostgres(); var cadenaSql = string.Format("SELECT * FROM modelo.asamblea; "); var resultado = conn1.registrar(cadenaSql); if (resultado) { MessageBox.Show("verificada la conexion"); } }
private void button8_Click(object sender, EventArgs e) { ConexionPostgres conn = new ConexionPostgres(); var cadena = "SELECT id_pregunta from modelo.pregunta_actual where nit='" + this.valor + "'"; var id_pregunta = conn.consultar(cadena)[0]["id_pregunta"]; XSSFWorkbook workbook = new XSSFWorkbook(); //Se crea una hoja para el libro de la (hoja de cálculo) XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet1"); ; //Creo una variable que es similar a la que se retorna en las consultas SQL var cadenaSql = " SELECT DISTINCT ur.nit, ur.numero_unidad, ur.nombre_completo, ur.coeficiente, v.id_pregunta, v.id_opcion FROM modelo.unidad_residencial AS ur LEFT OUTER JOIN modelo.voto AS v ON ur.numero_unidad = v.numero_unidad left outer JOIN modelo.pregunta_actual AS pa ON pa.id_pregunta=v.id_pregunta WHERE ur.nit = '" + this.valor + "' and v.id_pregunta = '" + id_pregunta + "' order by ur.numero_unidad asc;"; var resultado = conn.consultar(cadenaSql); var cadenasql = " SELECT p.pregunta FROM modelo.pregunta AS p LEFT OUTER JOIN modelo.voto AS v ON p.id_pregunta = '" + id_pregunta + "' LEFT OUTER JOIN modelo.pregunta_actual AS pa ON pa.id_pregunta = v.id_pregunta WHERE v.nit = '" + this.valor + "' "; var result = conn.consultar(cadenasql); var Cadenasql = "SELECT DISTINCT o.id_opcion, o.opcion FROM modelo.opcion_pregunta AS o LEFT OUTER JOIN modelo.voto AS v ON o.id_pregunta = '" + id_pregunta + "' LEFT OUTER JOIN modelo.pregunta_actual AS pa ON pa.id_pregunta = '" + id_pregunta + "' WHERE v.nit = '" + this.valor + "' ORDER BY o.id_opcion "; var Resultado = conn.consultar(Cadenasql); //Se escriben las cabeceras del reporte, primero se crea la fila var primerFilaExcel = sheet.CreateRow(1); //También creo una fuente NEGRILLA para ponerselas a esas celdas var boldFont = workbook.CreateFont(); boldFont.FontHeightInPoints = 11; boldFont.FontName = "Calibri"; boldFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; var style = workbook.CreateCellStyle(); style.SetFont(boldFont); //Se crea una celda, se le pone el estilo NEGRILLA y se le pone el valor var rowExcel = sheet.GetRow(1); rowExcel = sheet.GetRow(1); var cell = primerFilaExcel.CreateCell(0); cell.CellStyle = style; cell.SetCellValue("NIT"); //OTRA CELDA cell = primerFilaExcel.CreateCell(1); cell.CellStyle = style; cell.SetCellValue("NUMERO UNIDAD"); //OTRA CELDA cell = primerFilaExcel.CreateCell(2); cell.CellStyle = style; cell.SetCellValue("NOMBRE"); //OTRA CELDA cell = primerFilaExcel.CreateCell(3); cell.CellStyle = style; cell.SetCellValue("COEFICIENTE"); ////OTRA CELDA cell = primerFilaExcel.CreateCell(4); cell.CellStyle = style; cell.SetCellValue("VOTACION"); ////OTRA CELDA cell = primerFilaExcel.CreateCell(8); cell.CellStyle = style; cell.SetCellValue("NUMERO"); ////OTRA CELDA cell = primerFilaExcel.CreateCell(9); cell.CellStyle = style; cell.SetCellValue("OPCION"); ////OTRA CELDA cell = primerFilaExcel.CreateCell(10); cell.CellStyle = style; cell.SetCellValue("NUMERO DE VOTOS"); ////OTRA CELDA cell = primerFilaExcel.CreateCell(11); cell.CellStyle = style; cell.SetCellValue("COEFICIENTE"); //Se desocupa la variables para que no ocupen espacio cell = null; primerFilaExcel = null; int b = 0; Dictionary<string, string> fila1 = result[b]; var filaExcel1 = sheet.CreateRow(0);//La fila comienza desde la posición 2 filaExcel1.CreateCell(0).SetCellValue(fila1["pregunta"]); //Se crea un for como siempre que recorre el resultado for (int a = 1; a < Resultado.ToArray().Length; a++) { string quorum1 = ""; Dictionary<string, string> fila3 = Resultado[a]; var filaExcell = sheet.CreateRow(a + 2);//La fila comienza desde la posición 2 filaExcell.CreateCell(8).SetCellValue(fila3["id_opcion"]); filaExcell.CreateCell(9).SetCellValue(fila3["opcion"]); //var coef = "SELECT sum(UR.coeficiente) FROM modelo.unidad_residencial AS ur LEFT OUTER JOIN modelo.voto AS v ON ur.numero_unidad = v.numero_unidad left outer JOIN modelo.pregunta_actual AS pa ON pa.id_pregunta=v.id_pregunta WHERE ur.nit = '"+this.valor+"' and v.id_pregunta = '"+id_pregunta+"' AND v.id_opcion='"+a+"';"; //double registradosCasoCoeficientes1 = Double.Parse(conn.consultar(coef)[0]["sum"]); //quorum1 = (registradosCasoCoeficientes1).ToString(); } //var rowExcel = sheet.GetRow(1); for (int i = 0; i < resultado.Count; i++) { Dictionary<string, string> fila = resultado[i]; var filaExcel = sheet.CreateRow(i + 2);//La fila comienza desde la posición 2 filaExcel.CreateCell(0).SetCellValue(fila["nit"]); filaExcel.CreateCell(1).SetCellValue(fila["numero_unidad"]); filaExcel.CreateCell(2).SetCellValue(fila["nombre_completo"]); filaExcel.CreateCell(3).SetCellValue(fila["coeficiente"]); filaExcel.CreateCell(4).SetCellValue(fila["id_opcion"]); } using (var fs = new FileStream("votacion" + this.valor + ".xlsx", FileMode.Create, FileAccess.Write)) { workbook.Write(fs); fs.Close(); //borrar anuncio cuando ya no sea necesario MessageBox.Show("El archivo se guardó en la ruta: " + fs.Name); } }
private void button7_Click(object sender, EventArgs e) { ConexionPostgres conn = new ConexionPostgres(); ConexionPostgres conn1 = new ConexionPostgres(); string quorum1 = ""; var cadenaSqll = "SELECT sum(b.coeficiente) FROM modelo.asamblea_unidad_residencial AS a LEFT JOIN modelo.unidad_residencial AS b ON (a.numero_unidad = b.numero_unidad AND a.nit = b.nit) WHERE a.nit='" + this.valor + "' AND a.fecha='" + this.fecha + "';"; double asistenciaCasoCoeficientes1 = Double.Parse(conn1.consultar(cadenaSqll)[0]["sum"]); cadenaSqll = "SELECT sum(coeficiente) FROM modelo.unidad_residencial WHERE nit='" + this.valor + "';"; double registradosCasoCoeficientes1 = Double.Parse(conn1.consultar(cadenaSqll)[0]["sum"]); double porcentaje1 = (100 * (asistenciaCasoCoeficientes1) / registradosCasoCoeficientes1); porcentaje1 = Math.Round(porcentaje1, 2); quorum1 = (porcentaje1).ToString(); string quorum = ""; var cadenaSql2 = "SELECT sum(b.coeficiente) FROM modelo.asamblea_unidad_residencial AS a LEFT JOIN modelo.unidad_residencial AS b ON (a.numero_unidad = b.numero_unidad AND a.nit = b.nit) WHERE a.nit='" + this.valor + "' AND a.fecha='" + this.fecha + "';"; double asistenciaCasoCoeficientes = Double.Parse(conn.consultar(cadenaSql2)[0]["sum"]); cadenaSql2 = "SELECT sum(coeficiente) FROM modelo.unidad_residencial WHERE nit='" + this.valor + "';"; double registradosCasoCoeficientes = Double.Parse(conn.consultar(cadenaSql2)[0]["sum"]); var cadenaSql1 = "SELECT sum(b.coeficiente) FROM modelo.asamblea_unidad_residencial AS a LEFT JOIN modelo.unidad_residencial AS b ON (a.numero_unidad = b.numero_unidad AND a.nit = b.nit) WHERE a.nit='" + this.valor + "' AND a.fecha='" + this.fecha + "' and id_tipo_asistencia_final ='4';"; var registro = conn.consultar(cadenaSql1); if (registro[0]["sum"] != "") { double registradosCasoUnidadesdescargue = Double.Parse(conn.consultar(cadenaSql1)[0]["sum"]); double porcentaje2 = (100 * (asistenciaCasoCoeficientes - registradosCasoUnidadesdescargue) / registradosCasoCoeficientes); porcentaje1 = Math.Round(porcentaje1, 2); quorum = (porcentaje1).ToString(); } else { double porcentaje = (100 * (asistenciaCasoCoeficientes) / registradosCasoCoeficientes); porcentaje = Math.Round(porcentaje, 2); quorum = (porcentaje).ToString(); } //Cómo tú usaste XLSX para la lectura de archivos utilicé esta librería //Si quieres XlS sería otro cuento //Se crea un libro de trabajo (como siempre pueden ser atributos de la clase si se desea usar en varios m[etodos) XSSFWorkbook workbook = new XSSFWorkbook(); //Se crea una hoja para el libro de la (hoja de cálculo) XSSFSheet sheet = (XSSFSheet)workbook.CreateSheet("Sheet1"); ; //Creo una variable que es similar a la que se retorna en las consultas SQL var cadenaSql = " SELECT ur.nit, ur.numero_unidad, ur.nombre_completo, ur.coeficiente, ur.documento, CASE WHEN aur.id_tipo_asistencia_inicial=1 THEN 'presencial' WHEN aur.id_tipo_asistencia_inicial=2 THEN 'poder' WHEN aur.id_tipo_asistencia_inicial=3 THEN 'no asistio' ELSE 'no asistio' END AS tipo_asistencia_inicial, CASE WHEN aur.id_tipo_asistencia_final=1 THEN 'presencial' WHEN aur.id_tipo_asistencia_final=2 THEN 'poder' WHEN aur.id_tipo_asistencia_final=3 THEN 'no asistio' WHEN aur.id_tipo_asistencia_final=4 THEN 'se retiro antes de finalizar' ELSE 'no asistio' END AS tipo_asistencia_final FROM modelo.unidad_residencial AS ur LEFT OUTER JOIN modelo.asamblea_unidad_residencial AS aur ON ur.numero_unidad = aur.numero_unidad WHERE ur.nit='" + this.valor + "' order by ur.numero_unidad asc;"; var resultado = conn.consultar(cadenaSql); //List<Dictionary<string, string>> resultado = new List<Dictionary<string, string>>(); //resultado.Add(new Dictionary<string, string>{ // { "nit", "999999999" }, // { "nombre", "Primera asamblea de Jennifer, mucha plata" }, // { "fecha", "2016-01-29" }, // { "id", "1" } //}); //resultado.Add(new Dictionary<string, string>{ // { "nit", "999999999" }, // { "nombre", "Un gran día 1234569" }, // { "fecha", "2069-01-29" }, // { "id", "2" } //}); ////Se termina la creación de la variable //Se escriben las cabeceras del reporte, primero se crea la fila var primerFilaExcel = sheet.CreateRow(0); var segundaFilaExcel = sheet.CreateRow(1); //También creo una fuente NEGRILLA para ponerselas a esas celdas var boldFont = workbook.CreateFont(); boldFont.FontHeightInPoints = 11; boldFont.FontName = "Calibri"; boldFont.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; var style = workbook.CreateCellStyle(); style.SetFont(boldFont); //Se crea una celda, se le pone el estilo NEGRILLA y se le pone el valor var cell = primerFilaExcel.CreateCell(0); cell.CellStyle = style; cell.SetCellValue("NIT"); //OTRA CELDA cell = primerFilaExcel.CreateCell(1); cell.CellStyle = style; cell.SetCellValue("NUMERO UNIDAD"); //OTRA CELDA cell = primerFilaExcel.CreateCell(2); cell.CellStyle = style; cell.SetCellValue("NOMBRE"); //OTRA CELDA cell = primerFilaExcel.CreateCell(3); cell.CellStyle = style; cell.SetCellValue("COEFICIENTE"); //OTRA CELDA cell = primerFilaExcel.CreateCell(4); cell.CellStyle = style; cell.SetCellValue("DOCUMENTO"); //OTRA CELDA cell = primerFilaExcel.CreateCell(5); cell.CellStyle = style; cell.SetCellValue("ASISTENCIA INICIAL"); //OTRA CELDA cell = primerFilaExcel.CreateCell(6); cell.CellStyle = style; cell.SetCellValue("ASISTENCIA FINAL"); //OTRA CELDA cell = primerFilaExcel.CreateCell(7); cell.CellStyle = style; cell.SetCellValue("QUORUM INICIAL"); //OTRA CELDA cell = primerFilaExcel.CreateCell(8); cell.CellStyle = style; cell.SetCellValue(""); //OTRA CELDA cell = primerFilaExcel.CreateCell(9); cell.CellStyle = style; cell.SetCellValue("QUORUM FINAL"); //Se desocupa la variables para que no ocupen espacio cell = null; primerFilaExcel = null; int contadornoasistio = 0, contadornoasistiof = 0; int contadornpoder = 0, contadornpoderf = 0; int contadorpresen = 0, contadorpresenf = 0, contadorreutiro = 0; //Se crea un for como siempre que recorre el resultado for (int i = 0; i < resultado.Count; i++) { Dictionary<string, string> fila = resultado[i]; var filaExcel = sheet.CreateRow(i + 1);//La fila comienza desde la posición 1 filaExcel.CreateCell(0).SetCellValue(fila["nit"]); filaExcel.CreateCell(1).SetCellValue(fila["numero_unidad"]); filaExcel.CreateCell(2).SetCellValue(fila["nombre_completo"]); filaExcel.CreateCell(3).SetCellValue(fila["coeficiente"]); filaExcel.CreateCell(4).SetCellValue(fila["documento"]); filaExcel.CreateCell(5).SetCellValue(fila["tipo_asistencia_inicial"]); filaExcel.CreateCell(6).SetCellValue(fila["tipo_asistencia_final"]); if (fila["tipo_asistencia_inicial"] == "no asistio") { contadornoasistio++; } if (fila["tipo_asistencia_inicial"] == "poder") { contadornpoder++; } if (fila["tipo_asistencia_inicial"] == "presencial") { contadorpresen++; } if (fila["tipo_asistencia_final"] == "no asistio") { contadornoasistiof++; } if (fila["tipo_asistencia_final"] == "poder") { contadornpoderf++; } if (fila["tipo_asistencia_final"] == "presencial") { contadorpresenf++; } if (fila["tipo_asistencia_final"] == "se retiro antes de finalizar") { contadorreutiro++; } } var rowExcel = sheet.GetRow(1); rowExcel = sheet.GetRow(4); rowExcel.CreateCell(7).SetCellValue("No Asistió"); rowExcel.CreateCell(8).SetCellValue(contadornoasistio); rowExcel.CreateCell(9).SetCellValue("No Asistió"); rowExcel.CreateCell(10).SetCellValue(contadornoasistiof); rowExcel = sheet.GetRow(2); rowExcel.CreateCell(7).SetCellValue("Por Poder"); rowExcel.CreateCell(8).SetCellValue(contadornpoder); rowExcel.CreateCell(9).SetCellValue("Por Poder"); rowExcel.CreateCell(10).SetCellValue(contadornpoderf); rowExcel = sheet.GetRow(3); rowExcel.CreateCell(7).SetCellValue("Presencial"); rowExcel.CreateCell(8).SetCellValue(contadorpresen); rowExcel.CreateCell(9).SetCellValue("Presencial"); rowExcel.CreateCell(10).SetCellValue(contadorpresenf); rowExcel = sheet.GetRow(5); rowExcel.CreateCell(9).SetCellValue("Se retiro"); rowExcel.CreateCell(10).SetCellValue(contadorreutiro); rowExcel = sheet.GetRow(6); rowExcel.CreateCell(8).SetCellValue(quorum1 + "%"); rowExcel.CreateCell(10).SetCellValue(quorum + "%"); //Falta validar si el archivo está o no abierto por otra aplicación... var cadenaSql11 = "select nombre from modelo.propiedad_horizontal where nit='" + this.valor + "' "; var nombre1 = conn.consultar(cadenaSql11); var nombre = conn.consultar(cadenaSql11)[0]["nombre"]; using (var fs = new FileStream("lista_asistencia-" + nombre + ".xlsx", FileMode.Create, FileAccess.Write)) { workbook.Write(fs); fs.Close(); //borrar anuncio cuando ya no sea necesario MessageBox.Show("El archivo se guardó en la ruta: " + fs.Name); } }
private void button2_Click(object sender, EventArgs e) { string ruta = this.buscarDoc(); ConexionPostgres conn = new ConexionPostgres(); FileStream fs; try { fs = new FileStream(ruta, FileMode.Open, FileAccess.Read); } catch { MessageBox.Show("El archivo está siendo usado por otro programa. Asegurese de haber seleccionado el archivo correcto."); return; } XSSFWorkbook wb = new XSSFWorkbook(fs); string nombreHoja = ""; for (int i = 0; i < wb.Count; i++) { nombreHoja = wb.GetSheetAt(i).SheetName; } XSSFSheet sheet = (XSSFSheet)wb.GetSheet(nombreHoja); try { for (int row = 1; row <= sheet.LastRowNum; row++) { if (sheet.GetRow(row) != null) //null is when the row only contains empty cells { var fila = sheet.GetRow(row); var nit = fila.GetCell(0).ToString(); var numero_unidad = fila.GetCell(1).ToString(); var nombre_completo = fila.GetCell(2).ToString(); var coeficiente = fila.GetCell(3).ToString().Replace(",", "."); var documento = fila.GetCell(4).ToString(); var cadenaSql = string.Format( @"INSERT INTO modelo.unidad_residencial ( nit, numero_unidad, nombre_completo, coeficiente, documento ) VALUES ( '{0}', '{1}', '{2}', '{3}', '{4}' );", nit, numero_unidad, nombre_completo, coeficiente, documento ); var resultado = conn.registrar(cadenaSql); if (!resultado)//Falló la consulta { MessageBox.Show("El registro NIT:" + nit + ", Número Unidad:" + numero_unidad + ", Nombre Completo:" + nombre_completo + ", Coeficiente:" + coeficiente + ", Número Documento:" + documento + " ,no pudo ser completado de manera exitosa, revise los datos (están mal o ya existen o se encontro elemento en blanco)."); MessageBox.Show(cadenaSql); return; } } else { MessageBox.Show("realizado"); } } MessageBox.Show("Datos cargados correctamente."); } catch { MessageBox.Show("Algo pasó con la carga de archivos, asegúrese de que ha cargado el archivo correcto con datos válidos."); } //Se cierra el archivo fs.Close(); }
private void cargarComboBoxNitPropiedad() { ConexionPostgres conn = new ConexionPostgres(); var resultado = conn.consultar("SELECT * FROM modelo.propiedad_horizontal; "); List<Select> sl = new List<Select>(); foreach (Dictionary<string, string> fila in resultado) { int numVal = Int32.Parse(fila["nit"]); // tipoasambleabix.Items.Add(new ListItem ( fila["nombre"], numVal)); sl.Add(new Select() { Text = fila["nit"] + "-" + fila["nombre"] , Value = fila["nit"] }); } comboBox1.DataSource = sl; comboBox1.DisplayMember = "Text"; //http://stackoverflow.com/questions/3063320/combobox-adding-text-and-value-to-an-item-no-binding-source MessageBox.Show("NIT actualizado"); }
private void button5_Click(object sender, EventArgs e) { Select sl = comboBox1.SelectedItem as Select; string valor = sl.Value; string fecha = dtp.Value.Date.Year + "-" + dtp.Value.Date.Month + "-" + dtp.Value.Date.Day; ConexionPostgres conn = new ConexionPostgres(); var cadenaSql = "select count(*) from modelo.asamblea where nit='"+ valor+ "' AND fecha='"+fecha+"';"; var cuenta = conn.consultar(cadenaSql)[0]["count"]; if (cuenta== "1") { var cadenaSql1 = "select nombre from modelo.asamblea where nit='" + valor + "' AND fecha='"+fecha+"';"; var nombre = conn.consultar(cadenaSql1)[0]["nombre"]; MessageBox.Show("ESTA INGRESANDO A: "+nombre); OpcionesAsamblea op = new OpcionesAsamblea(fecha, valor); op.Show(); } }