public List <datosAlmacenados> auditoriaMensual(string empresa, string año, string mes) { string querySQL; SqlConnection conex = new SqlConnection(); conex.ConnectionString = cadenaConexion; conex.Open(); querySQL = "select FECHA_REG,FM_DEL,FM_AL,BM_DEL,BM_AL,V_DEL,V_AL,TB_DEL,TB_AL,TF_DEL,TF_AL,MONTO from VENTA where venta.USUARIO = '" + empresa + "' and MONTH(venta.FECHA_REG)=" + mes + " and YEAR(venta.FECHA_REG)=" + año; SqlCommand cmd = new SqlCommand(querySQL, conex); SqlDataReader valoresTabla = cmd.ExecuteReader(); List <datosAlmacenados> listaDatos = new List <datosAlmacenados>(); while (valoresTabla.Read()) { datosAlmacenados usuario = new datosAlmacenados(); usuario.fecha = valoresTabla[0].ToString(); usuario.FM_DEL = valoresTabla[1].ToString(); usuario.FM_AL = valoresTabla[2].ToString(); usuario.BM_DEL = valoresTabla[3].ToString(); usuario.BM_AL = valoresTabla[4].ToString(); usuario.V_DEL = valoresTabla[5].ToString(); usuario.V_AL = valoresTabla[6].ToString(); usuario.TB_DEL = valoresTabla[7].ToString(); usuario.TB_AL = valoresTabla[8].ToString(); usuario.TF_DEL = valoresTabla[9].ToString(); usuario.TF_AL = valoresTabla[10].ToString(); usuario.SOLES = valoresTabla[11].ToString(); listaDatos.Add(usuario); } conex.Close(); return(listaDatos); }
//public void CerrarConexion(SqlConnection conex) //{ // conex.Close(); //} public List <datosAlmacenados> cargaActual(string mesConsulta, string añoConsulta) { var usuario = (Usuario)HttpContext.Current.Session["login"]; SqlConnection conexion = new SqlConnection(); conexion.ConnectionString = cadenaConexion; conexion.Open(); //Read from the database //#region armar fecha //DateTime fecha = DateTime.Now; //int mes = fecha.Month; //int año = fecha.Year; //int dias = System.DateTime.DaysInMonth(año, mes); //#endregion SqlCommand command = new SqlCommand("sp_cargaActual", conexion); command.Parameters.AddWithValue("@mes", mesConsulta); command.Parameters.AddWithValue("@year", añoConsulta); command.Parameters.AddWithValue("@usuario", usuario.usuario); command.CommandType = System.Data.CommandType.StoredProcedure; List <datosAlmacenados> cargaAct = new List <datosAlmacenados>(); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { //no funciona! datosAlmacenados data = new datosAlmacenados(); data.fecha = dataReader[0].ToString(); data.FM_DEL = dataReader[1].ToString(); data.FM_AL = dataReader[2].ToString(); data.BM_DEL = dataReader[3].ToString(); data.BM_AL = dataReader[4].ToString(); data.V_DEL = dataReader[5].ToString(); data.V_AL = dataReader[6].ToString(); data.TB_DEL = dataReader[7].ToString(); data.TB_AL = dataReader[8].ToString(); data.TF_DEL = dataReader[9].ToString(); data.TF_AL = dataReader[10].ToString(); data.SOLES = dataReader[11].ToString(); data.CIERRE = dataReader[12].ToString(); cargaAct.Add(data); } conexion.Close(); return(cargaAct); }
private bool Import_To_Grid(string FilePath, string Extension, string month, string regAño, string regMes) { string conStr = ""; switch (Extension) { case ".xls": //Excel 97-03 conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"].ConnectionString; break; case ".xlsx": //Excel 07 conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"].ConnectionString; break; } conStr = String.Format(conStr, FilePath, "no"); OleDbConnection connExcel = new OleDbConnection(conStr); OleDbCommand cmdExcel = new OleDbCommand(); OleDbDataAdapter oda = new OleDbDataAdapter(); DataTable dt = new DataTable(); cmdExcel.Connection = connExcel; //Get the name of First Sheet connExcel.Open(); DataTable dtExcelSchema; dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString(); connExcel.Close(); //Read Data from First Sheet cmdExcel.CommandText = "SELECT * From [" + SheetName + "A4:Q35]"; oda.SelectCommand = cmdExcel; oda.Fill(dt); List <datosAlmacenados> list = new List <datosAlmacenados>(); foreach (DataRow myDatarow in dt.Rows) { datosAlmacenados excelData = new datosAlmacenados(); excelData.fecha = validarNoSeQue(myDatarow.ItemArray[0].ToString()); excelData.FM_DEL = validarNoSeQue(myDatarow.ItemArray[1].ToString()); excelData.FM_AL = validarNoSeQue(myDatarow.ItemArray[2].ToString()); excelData.BM_DEL = validarNoSeQue(myDatarow.ItemArray[3].ToString()); excelData.BM_AL = validarNoSeQue(myDatarow.ItemArray[4].ToString()); excelData.V_DEL = validarNoSeQue(myDatarow.ItemArray[5].ToString()); excelData.V_AL = validarNoSeQue(myDatarow.ItemArray[6].ToString()); excelData.TB_DEL = validarNoSeQue(myDatarow.ItemArray[7].ToString()); excelData.TB_AL = validarNoSeQue(myDatarow.ItemArray[8].ToString()); excelData.TF_DEL = validarNoSeQue(myDatarow.ItemArray[9].ToString()); excelData.TF_AL = validarNoSeQue(myDatarow.ItemArray[10].ToString()); excelData.SOLES = validarNoSeQue(myDatarow.ItemArray[11].ToString()); list.Add(excelData); } //var user = HttpContext.Current.Session["Login"].ToString(); //string css = "<style type='text/css'> #tresultado table tr td[colspan='3']{ font-weight: bold;} #tresultado table{ border-spacing: 0px;} #tresultado th{ font-family:'Calibri',sans-serif; font-size:12pt; color:#385B83; font-weight:bold; background-color:#DEDFDE; height:30px; } #tresultado tbody td { border-bottom:#92D050 solid 1px; width: 10%; } </style>"; string relacion = "<table> <thead> <tr> <th >TIPO DE ERROR</th> <th >DESDE</th> <th >HASTA</th> <th >COOR X,Y (excel)</th> </tr> </thead> <tbody>"; relacion += validarCorrelacion(list) + "</body></table>"; int cont = relacion.Length; if (cont <= 515) { RegistrarDatos(list, month, regAño, regMes); mensaje("Se registraron los datos correctamente"); Thread.Sleep(10000); tablaResultado.InnerHtml = ""; //EnvioCorreo(relacion, user); } else { var a = list; RegistrarDatos(list, month, regAño, regMes); guardarInconsistencia(relacion); //tablaResultado.InnerHtml = relacion; no se mostrara mensaje de error! temp //Thread.Sleep(15000); si no se muestra mensaje de error la espera no es necesaria //tablaResultado.InnerHtml = ""; no existe ninguna inyeccion de html. No hay necesidad de limpiar mensaje("Se registraron los datos con algunas obs"); //ArmarReporte(list); } //---------Fin test-------- connExcel.Close(); return(false); }