private void adicionaAnexoBase(int CodTitulo, string ArquivoAnexo, string TipoAnexo, string NomeAnexo, DateTime DtGeracao, string HrGeracao) { int iCodAnexo = 1; ClassWebBI.ClassFuncoes clFuncoes = new ClassWebBI.ClassFuncoes(); SqlCommand sCommand = new SqlCommand(); SqlParameter pCodTitulo = new SqlParameter("@COD_TITULO", System.Data.SqlDbType.Int); sCommand.Parameters.Add(pCodTitulo); sCommand.Parameters["@COD_TITULO"].Value = CodTitulo; SqlParameter pNome = new SqlParameter("@NOME", System.Data.SqlDbType.VarChar, 50); sCommand.Parameters.Add(pNome); sCommand.Parameters["@NOME"].Value = NomeAnexo; SqlParameter pTipoAnexo = new SqlParameter("@TIPO_ANEXO", System.Data.SqlDbType.VarChar, 20); sCommand.Parameters.Add(pTipoAnexo); sCommand.Parameters["@TIPO_ANEXO"].Value = TipoAnexo; SqlParameter pDtGeracao = new SqlParameter("@DT_GERACAO", System.Data.SqlDbType.DateTime); sCommand.Parameters.Add(pDtGeracao); sCommand.Parameters["@DT_GERACAO"].Value = DtGeracao; SqlParameter pHrGeracao = new SqlParameter("@HR_GERACAO", System.Data.SqlDbType.VarChar, 5); sCommand.Parameters.Add(pHrGeracao); sCommand.Parameters["@HR_GERACAO"].Value = HrGeracao; SqlParameter pCodAnexo = new SqlParameter("@COD_ANEXO", System.Data.SqlDbType.Int); sCommand.Parameters.Add(pCodAnexo); sCommand.Parameters["@COD_ANEXO"].Value = iCodAnexo; byte[] fArquivo = null; fArquivo = clFuncoes.CarregarArquivo(@ArquivoAnexo); SqlParameter pAnexo = new SqlParameter("@ARQUIVO", System.Data.SqlDbType.Image, fArquivo.Length); sCommand.Parameters.Add(pAnexo); sCommand.Parameters["@ARQUIVO"].Value = fArquivo; sCommand.CommandText = "SELECT COD_ANEXO FROM EXCEL_TITULO_ANEXOS WHERE NOME = @NOME"; string sNovoAnexo = clFuncoes.ExecScalar(sCommand); if (sNovoAnexo == "") { sCommand.CommandText = "SELECT MAX(COD_ANEXO) AS NUM_ANEXO FROM EXCEL_TITULO_ANEXOS"; string sCodAnexo = clFuncoes.ExecScalar(sCommand); try { iCodAnexo = Convert.ToInt32(sCodAnexo) + 1; } catch { } pCodAnexo.Value = iCodAnexo; sCommand.CommandText = "INSERT INTO EXCEL_TITULO_ANEXOS (COD_ANEXO, NOME, COD_TITULO, ARQUIVO, TIPO, DT_GERACAO, HR_GERACAO)" + " VALUES (" + " @COD_ANEXO" + ", @NOME" + ", @COD_TITULO" + ", @ARQUIVO" + ", @TIPO_ANEXO" + ", @DT_GERACAO" + ", @HR_GERACAO" + ")"; string sAux = clFuncoes.ExecNonQuery(sCommand); } else { try { iCodAnexo = Convert.ToInt32(sNovoAnexo); pCodAnexo.Value = iCodAnexo; sCommand.CommandText = "UPDATE EXCEL_TITULO_ANEXOS" + " SET NOME = @NOME" + ", COD_TITULO = @COD_TITULO" + ", ARQUIVO = @ARQUIVO" + ", TIPO = @TIPO_ANEXO" + ", DT_GERACAO = @DT_GERACAO" + ", HR_GERACAO = @HR_GERACAO" + " WHERE COD_ANEXO = @COD_ANEXO"; string sAux = clFuncoes.ExecNonQuery(sCommand); } catch { } } }
public string setExcel(string Tipo) { ClassWebBI.ClassFuncoes clFuncoes = new ClassWebBI.ClassFuncoes(); SqlCommand sCommand = new SqlCommand(); SqlParameter pCodigo = new SqlParameter("@COD_EXCEL", System.Data.SqlDbType.Int); sCommand.Parameters.Add(pCodigo); sCommand.Parameters["@COD_EXCEL"].Value = fcod_excel; SqlParameter pNome = new SqlParameter("@NOME", System.Data.SqlDbType.VarChar, 100); sCommand.Parameters.Add(pNome); sCommand.Parameters["@NOME"].Value = fnome; SqlParameter pGrupo = new SqlParameter("@COD_GRUPO", System.Data.SqlDbType.VarChar, 10); sCommand.Parameters.Add(pGrupo); sCommand.Parameters["@COD_GRUPO"].Value = fcod_grupo; SqlParameter pAtivo = new SqlParameter("@ATIVO", System.Data.SqlDbType.Bit); sCommand.Parameters.Add(pAtivo); sCommand.Parameters["@ATIVO"].Value = fativo; if (fnome_arquivo != "") { byte[] fArquivo = null; fArquivo = clFuncoes.CarregarArquivo(fnome_arquivo); SqlParameter pExcel = new SqlParameter("@ARQUIVO", System.Data.SqlDbType.Image, fArquivo.Length); sCommand.Parameters.Add(pExcel); sCommand.Parameters["@ARQUIVO"].Value = fArquivo; } if (Tipo == "Incluir") { sCommand.CommandText = "INSERT INTO EXCEL (COD_EXCEL, NOME, ATIVO, ARQUIVO, COD_GRUPO)" + " VALUES (" + " @COD_EXCEL" + ", @NOME" + ", @ATIVO" + ", @ARQUIVO" + ", @COD_GRUPO )"; } else if (fnome_arquivo != "") { sCommand.CommandText = "UPDATE EXCEL" + " SET NOME = @NOME" + ", ATIVO = @ATIVO" + ", ARQUIVO = @ARQUIVO" + ", COD_GRUPO = @COD_GRUPO" + " WHERE COD_EXCEL = @COD_EXCEL"; } else { sCommand.CommandText = "UPDATE EXCEL" + " SET NOME = @NOME" + ", ATIVO = @ATIVO" + ", COD_GRUPO = @COD_GRUPO" + " WHERE COD_EXCEL = @COD_EXCEL"; } string sAux = clFuncoes.ExecNonQuery(sCommand); return(sAux); }
public void atualizaExcel(int CodExcel) { string Arquivo = salvaArquivoExcel(CodExcel); if (!File.Exists(Arquivo)) { return; } Application xlsApp = new Application(); if (xlsApp == null) { return; } Workbook workbook = xlsApp.Workbooks.Open(Arquivo); workbook.RefreshAll(); workbook.Close(true); workbook = null; xlsApp.Quit(); xlsApp = null; GC.Collect(); GC.WaitForPendingFinalizers(); ClassWebBI.ClassFuncoes clFuncoes = new ClassWebBI.ClassFuncoes(); SqlCommand sCommand = new SqlCommand(); SqlParameter pCodigo = new SqlParameter("@COD_EXCEL", System.Data.SqlDbType.Int); sCommand.Parameters.Add(pCodigo); sCommand.Parameters["@COD_EXCEL"].Value = CodExcel; SqlParameter pAtualiza = new SqlParameter("@DT_ATUALIZA", System.Data.SqlDbType.DateTime); sCommand.Parameters.Add(pAtualiza); sCommand.Parameters["@DT_ATUALIZA"].Value = clFuncoes.GetProperties("fData"); SqlParameter pHrAtualiza = new SqlParameter("@HR_ATUALIZA", System.Data.SqlDbType.VarChar, 5); sCommand.Parameters.Add(pHrAtualiza); sCommand.Parameters["@HR_ATUALIZA"].Value = DateTime.Now.ToString("HH:mm"); byte[] fArquivo = null; fArquivo = clFuncoes.CarregarArquivo(Arquivo); SqlParameter pExcel = new SqlParameter("@ARQUIVO", System.Data.SqlDbType.Image, fArquivo.Length); sCommand.Parameters.Add(pExcel); sCommand.Parameters["@ARQUIVO"].Value = fArquivo; sCommand.CommandText = "UPDATE EXCEL" + " SET DT_ATUALIZA = @DT_ATUALIZA" + ", ARQUIVO = @ARQUIVO" + ", HR_ATUALIZA = @HR_ATUALIZA" + " WHERE COD_EXCEL = @COD_EXCEL"; string sAux = clFuncoes.ExecNonQuery(sCommand); }