protected void btnDevolver_Click(object sender, EventArgs e)
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            hidRetornarSetor.Value = "true";
            try
            {
                string lTramitacaoAnterior = string.Empty;

                lFields.Add(TRAMITACAOQD._TRA_ID, hidTRA_ID.Value);

                lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                lFields.Add(TRAMITACAOQD._TRA_REGUSER, Session["_SessionUser"].ToString());
                lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");
                lFields.Add(TRAMITACAOQD._SPED_ID, "5");
                lFields.Add(TRAMITACAOQD._TRA_OBSERVACAO, txtObservacaoTeste.Text);
                lReturn = TRAMITACAOTo.Update(lFields, LocalInstance.ConnectionInfo);

                exibirMensagem("Mensagem", "Diaria devolvida com sucesso", "ok", "AcompanharPedidoPlanejamento.aspx");

            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(false);
            }
        }
        public static OperationResult Insert(DataFieldCollection pValues, ConnectionInfo pInfo)
        {
            Transaction lTransaction;

             lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

             bool lLocalTransaction = (lTransaction != null);

             InsertCommand lInsert;

             OperationResult lReturn = new OperationResult(PORT_BANNERQD.TableName, PORT_BANNERQD.TableName);

             if (!lReturn.HasError){
             try{
             if (lLocalTransaction){
                 lReturn.Trace("Transação local, instanciando banco...");
             }

             lInsert = new InsertCommand(PORT_BANNERQD.TableName);

             lReturn.Trace("Adicionando campos ao objeto de insert");

             foreach (DataField lField in pValues.Keys){
                 lInsert.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
             }
             decimal lSequence;
             lSequence = DataBaseSequenceControl.GetNext(pInfo, "BAN_ID");
             lInsert.Fields.Add(PORT_BANNERQD._BAN_ID.Name, lSequence, (ItemType)PORT_BANNERQD._BAN_ID.DBType);

             lReturn.Trace("Executando o Insert");

             lInsert.Execute(lTransaction, false);

             if (!lReturn.HasError){
                 if (lLocalTransaction){
                     if (!lReturn.HasError){
                         lReturn.Trace("Insert finalizado, executando commit");

                         lTransaction.Commit();
                     }
                     else{
                         lTransaction.Rollback();
                     }
                 }
             }
             else{
                 if (lLocalTransaction)
                     lTransaction.Rollback();
             }
             }
             catch (Exception ex){
            lReturn.OperationException = new SerializableException(ex);

             if (lLocalTransaction)
                 lTransaction.Rollback();
             }
             }

             return lReturn;
        }
        private void InterfaceInclude()
        {
            try
            {
                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                lFields.Add(INTERACAOQD._CHA_ID, txtCHA_ID.Text);
                lFields.Add(INTERACAOQD._INT_REGDATE, DateTime.Now);
                lFields.Add(INTERACAOQD._INT_REGUSER, "USER");
                lFields.Add(INTERACAOQD._INT_STATUS, "A");

                lReturn = INTERACAOTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    MessageBox1.wuc_ShowMessage("Registro salvo com sucesso.", 1);
                    //LoadGrid();
                    Clear();
                }
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }
        protected void btnIndeferir_Click(object sender, EventArgs e)
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            try
            {

                if (btnIndeferir.Text == "INDEFERIR")
                {
                    txtOBS.Visible = true;
                    btnIndeferir.Text = "CONFIRMAR INDEFERIMENTO";
                }
                else
                {
                    string lTramitacao = string.Empty;

                    txtOBS.Visible = false;
                    btnIndeferir.Text = "INDEFERIR";
                    lTramitacao = hidTRA_ID.Value;

                    lFields.Add(TRAMITACAOQD._TRA_ID, lTramitacao);

                    lFields.Add(TRAMITACAOQD._SPED_ID, "4");

                    lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                    lFields.Add(TRAMITACAOQD._TRA_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");
                    lFields.Add(TRAMITACAOQD._TRA_OBSERVACAO, txtOBS.Text);

                    lReturn = TRAMITACAOTo.Update(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception ee = new Exception(lReturn.OperationException.Message);
                        throw ee;
                    }

                    btnImprimir.Visible = false;
                    PanelDadosDiaria.Visible = false;     //lobao
                    grvDestinacao.Visible = false;
                    grvPROPOSTO.Visible = false;
                    dvPropostos.Visible = false;
                    dvPedidos.Visible = true;
                    dvGPPARAFUNDOS.Visible = false;
                    DivDadosSuprimentoFundos.Visible = false;

                    LoadGridPlanejDeferido();
                    LoadGridPlanejIndeferido();
                    LoadGridPlanejTramitando();
                    LoadTabs();
                }
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(false);
            }
        }
        protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                if (e.CommandName != "Page") //Paginação
                {
                    int iIndice = (((GridView)sender).PageIndex * ((GridView)sender).PageSize) + int.Parse(e.CommandArgument.ToString());

                    if (e.CommandName == "Receber")
                    {
                        DataTable lRelatorios = (DataTable)ViewState["WRK_TABLE"];

                        if (lRelatorios.Rows.Count > 0)
                        {
                            DataTable lImagem = CORREGEDORIAIMGDo.GetCORREGEDORIAIMGByID(lRelatorios.Rows[iIndice]["CGDR_ID"].DBToDecimal(), LocalInstance.ConnectionInfo);

                            Session["_CGDR_ID_"] = lRelatorios.Rows[iIndice]["CGDR_ID"].DBToDecimal();

                            ////System.IO.FileStream wFile;
                            ////byte[] byteData = null;
                            ////byteData = (byte[])lImagem.Rows[0][CORREGEDORIAIMGQD._CGDR_IMG.Name];
                            ////wFile = new FileStream("c:\\" + lRelatorios.Rows[iIndice]["PES_NOME"].ToString() + "_" + lRelatorios.Rows[iIndice][CORREGEDORIAIMGQD._CGDR_NOME.Name].ToString(), FileMode.Append);
                            ////wFile.Write(byteData, 0, byteData.Length);
                            ////wFile.Close();

                            DataFieldCollection lFields = new DataFieldCollection();
                            OperationResult lReturn = new OperationResult();

                            lFields.Add(CORREGEDORIAIMGQD._CGDR_ID, lRelatorios.Rows[iIndice]["CGDR_ID"].DBToDecimal());
                            lFields.Add(CORREGEDORIAIMGQD._CGDR_SIT, 1);

                            lReturn = CORREGEDORIAIMGDo.Update(lFields, LocalInstance.ConnectionInfo);
                            if (!lReturn.IsValid)
                            {
                                Exception err = new Exception(lReturn.OperationException.Message.ToString());
                                throw err;
                            }
                            else
                            {
                                LoadGrid();
                            }
                        }
                    }
                }

            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }
        public static decimal GetNext(Transaction pTransaction, string pIDFieldValue)
        {
            decimal lID;

            // Inicializa operação
            OperationResult lReturn = new OperationResult(QueryDictionaries.SequencesQD.TableName, QueryDictionaries.SequencesQD.TableName);

            // Recupera Valor
            SelectCommand lSelectNext;

            string lSelectQuery = QueryDictionaries.SequencesQD.qSequencesMax;
            lSelectQuery += String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesQD._SEQ_NAME.Name);

            object lScalarReturn;

            lSelectNext = new SelectCommand(lSelectQuery);

            // Passagem dos Valores de Parametros para a Clausula WHERE [comando SELECT]
            lSelectNext.Fields.Add(QueryDictionaries.SequencesQD._SEQ_NAME.Name, pIDFieldValue, ItemType.String);

            // Recupera Valor do Select (Seq_Value)
            lScalarReturn = lSelectNext.ReturnScalar(pTransaction);

            if (lScalarReturn == null || lScalarReturn == DBNull.Value) lScalarReturn = 1;
            lID = Convert.ToDecimal(lScalarReturn);

            // Altera Valor da Sequence
            UpdateCommand lUpdate;
            lUpdate = new UpdateCommand(QueryDictionaries.SequencesQD.TableName);

            // Identificação dos Campos a serem Alterados
            lUpdate.Fields.Add(QueryDictionaries.SequencesQD._SEQ_VALUE.Name, lID, (ItemType) QueryDictionaries.SequencesQD._SEQ_VALUE.DBType);

            string lUpdateQuery;

            lUpdateQuery = String.Format("WHERE {0} = >>{0}", QueryDictionaries.SequencesQD._SEQ_NAME.Name);
            lUpdate.Condition = lUpdateQuery;

            // Passagem dos Valores para a Condição Where do Update
            lUpdate.Conditions.Add(QueryDictionaries.SequencesQD._SEQ_NAME.Name, pIDFieldValue);

            // Execução do UPDATE
            lUpdate.Execute(pTransaction);

            // Retorna novo valor da chave [SEQUENCE VALUE]
            return lID;
        }
        protected void btnAceitar_Click(object sender, EventArgs e)
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            try
            {

                lFields.Add(RELATORIOVIAGEMQD._RELVIA_ID,       lobRELVIA_ID);
                lFields.Add(RELATORIOVIAGEMQD._RELVIA_REGDATE,  DateTime.Now);
                lFields.Add(RELATORIOVIAGEMQD._RELVIA_REGUSER,  Session["_SessionUser"].ToString());
                lFields.Add(RELATORIOVIAGEMQD._RELVIA_STATUS,   "A");
                lFields.Add(RELATORIOVIAGEMQD._RELVIA_FINAN,    "OK");

                lReturn = RELATORIOVIAGEMTo.Update(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception ee = new Exception(lReturn.OperationException.Message.ToString());
                    throw ee;

                }

                string jscript = "";
                jscript +=
                    "window.opener.location.reload('../Aut/Admin/AcompanharPedidofinanceiro.aspx');";
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "refreshPageAnterior", jscript, true);

                ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true);
            }

            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception ee)
            {
                (new UnknownException(ee)).TratarExcecao(true);
            }
        }
 private static void ValidateInsert(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateConversion(pValues, pResult);
 }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(BairroQD._BRR_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(BairroQD._BRR_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(BairroQD._BRR_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(BairroQD._BRR_STATUS , pValues, pResult);
 }
        public static OperationResult Update(
            DataFieldCollection pValues,
            List<DataFieldCollection> pListAtuaInc,
            List<DataFieldCollection> pListAtuaUpd,
            DataFieldCollection pValuesAtuaExcluir,
            List<DataFieldCollection> pListPermissao,
            ConnectionInfo pInfo
        )
        {
            Transaction pTransaction;

            pTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (pTransaction != null);

            UpdateCommand lUpdate;

            OperationResult lReturn = new OperationResult(PessoaFuncaoQD.TableName, PessoaFuncaoQD.TableName);

            ValidateUpdate(pValues, lReturn);

            if (lReturn.IsValid)
            {
                try
                {
                    lUpdate = new UpdateCommand(PessoaFuncaoQD.TableName);

                    foreach (DataField lField in pValues.Keys)
                    {
                        if ((lField.Name != PessoaFuncaoQD._PESF_ID.Name))
                            lUpdate.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }

                    string lSql = "";
                    lSql = String.Format("WHERE {0} = <<{0}", PessoaFuncaoQD._PESF_ID.Name);
                    lUpdate.Condition = lSql;
                    lUpdate.Conditions.Add(PessoaFuncaoQD._PESF_ID.Name, pValues[PessoaFuncaoQD._PESF_ID].DBToDecimal());

                    lUpdate.Execute(pTransaction);

                    if (!lReturn.HasError)
                    {
                        //Excluir atuação do núcleo alterado
                        if (pValuesAtuaExcluir.Count > 0)
                        {
                            lReturn = AtuacaoDo.UpdateInativo(pValuesAtuaExcluir, pInfo);

                            if (lReturn.HasError)
                            {
                                pTransaction.Rollback();
                                return lReturn;
                            }
                        }

                        if (pListAtuaInc.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListAtuaInc)
                            {
                                lReturn = AtuacaoDo.Insert(lFields, pTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    pTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListAtuaUpd.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListAtuaUpd)
                            {
                                lReturn = AtuacaoDo.Update(lFields, pTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    pTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (pListPermissao.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListPermissao)
                            {
                                lReturn = SecurityUsersDtDo.Insert(lFields, pTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    pTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            pTransaction.Commit();
                        }
                        else
                        {
                            pTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            pTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        pTransaction.Rollback();
                }
            }

            return lReturn;
        }
        private void TramitacaoUpdate(string pOpcao)
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            try
            {
                lFields.Add(TRAMITACAOQD._TRA_ID, hidTRA_ID.Value);
                lFields.Add(TRAMITACAOQD._SPED_ID, pOpcao);
                lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                lFields.Add(TRAMITACAOQD._TRA_REGUSER, "USER");
                lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");

                //4 - indeferido
                if (pOpcao.Equals("4"))
                {

                }
                else if (pOpcao.Equals("3")) // 3 - DEFERIDO
                {
                    lReturn = TRAMITACAOTo.Update(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception e = new Exception(lReturn.OperationException.Message.ToString());
                        throw e;
                    }
                    else
                    {
                        TramitacaoInclude();
                    }
                }
            }
            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception e)
            {
                (new UnknownException(e)).TratarExcecao(true);
            }
        }
        private void InterfaceInclude()
        {
            try
            {
                LoginUserDo oUsuario = (LoginUserDo)Session["UsuarioAtual"];
                string pPath = "";

                if (chkTipoCaminho.Checked)
                    pPath = @"~\anexos\File\" + hdPathImgDestaque1.Value.Trim();
                else
                    pPath = txtBannerPath.Text;

                if(validaDados())
                {
                    DataFieldCollection lFields = new DataFieldCollection();
                    OperationResult lReturn = new OperationResult();

                    lFields.Add(PORT_BANNERQD._BAN_PATH, @"~\banners\" + hdPathImgDestaque.Value.Trim());
                    lFields.Add(PORT_BANNERQD._BAN_LINK, pPath);
                    lFields.Add(PORT_BANNERQD._BAN_ORDEM, txtBanOrdemDestaque.Text);
                    lFields.Add(PORT_BANNERQD._BAN_REGDATE, DateTime.Now);
                    lFields.Add(PORT_BANNERQD._BAN_REGUSER, oUsuario.LoginName.ToString());
                    lFields.Add(PORT_BANNERQD._BAN_REGSTATUS, "A");

                    lReturn = PORT_BANNERDo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        exibirMensagem(UpdatePanelPrincipal, "Cadastro de Banner", err.Message, "erro");
                    }
                    else
                    {
                        if (msg != "")
                        {
                            exibirMensagem(UpdatePanelPrincipal, "Cadastro de Banner", msg, "alerta");
                        }
                        else
                        {
                            exibirMensagem(UpdatePanelPrincipal, "Cadastro de Banner", "Banner cadastrado com sucesso");
                            Clear();
                        }
                    }
                }
            }
            catch (Exception err)
            {
                exibirMensagem(UpdatePanelPrincipal, "Cadastro de Banner", err.Message, "erro");
            }
        }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(NucleoxLocalidadeQD._NUCLOC_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(NucleoxLocalidadeQD._NUCLOC_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(NucleoxLocalidadeQD._NUCLOC_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(NucleoxLocalidadeQD._NUCLOC_STATUS, pValues, pResult);
 }
        private void InterfaceUpdateAnexoSuprimento(decimal pSUPFUNANX_ID)
        {
            try
            {
                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_ID, pSUPFUNANX_ID);
                lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGDATE, DateTime.Now);
                lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGUSER, Session["_SessionUser"].ToString());
                lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_STATUS, "I");

                lReturn = SuprimentoFundo_AnexoTo.Update(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    LoadGridAnexoSuprimento(hidKEY_ID.Value.DBToDecimal());
                    lblMSG.Text = "Registro Excluído";
                    lblMSG.Visible = true;
                }
            }
            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception e)
            {
                (new UnknownException(e)).TratarExcecao(true);
            }
        }
        private void IncludeImagem()
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            byte[] Anexo = new byte[0];
            string lTipo = "";
            if (hidTipo.Value.Equals("2")) //Diaria
            {
                #region Empenho
                //1 empenho
                if (btnImgEmpenho.FileName != "")
                {
                    //    lTipo = Path.GetExtension(Path.GetFileName(btnImgEmpenho.FileName));
                    //    Anexo = new byte[0];

                    //    if (lTipo.ToLower() == ".jpg")
                    //    {
                    Anexo = carregaAnexoEmpenho();

                    lFields.Clear();
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPRO_ID, hidPESF_ID.Value);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_TIPO, 1);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_IMG, Anexo);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGDATE, DateTime.Now);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_STATUS, "A");

                    lReturn = Diaria_Proposto_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //    }
                    //    else
                    //    {
                    //        lblMSG.Visible = true;
                    //        lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //    }
                }
                #endregion

                #region LIQUIDAÇÃO

                //2 LIQUIDAÇÃO
                if (btnImgLiquidacao.FileName != "")
                {
                    //lTipo = Path.GetExtension(Path.GetFileName(btnImgLiquidacao.FileName));
                    //Anexo = new byte[0];

                    //if (lTipo.ToLower() == ".jpg")
                    //{
                    Anexo = carregaAnexoLiquidacao();

                    lFields.Clear();
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPRO_ID, hidPESF_ID.Value);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_TIPO, 2);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_IMG, Anexo);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGDATE, DateTime.Now);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_STATUS, "A");

                    lReturn = Diaria_Proposto_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //}
                    //else
                    //{
                    //    lblMSG.Visible = true;
                    //    lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //}
                }
                #endregion

                #region OB
                //2 OB
                if (btnImgOb.FileName != "")
                {
                    //lTipo = Path.GetExtension(Path.GetFileName(btnImgOb.FileName));
                    //Anexo = new byte[0];

                    //if (lTipo.ToLower() == ".jpg")
                    //{
                    Anexo = carregaAnexoOb();

                    lFields.Clear();
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPRO_ID, hidPESF_ID.Value);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_TIPO, 3);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_IMG, Anexo);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGDATE, DateTime.Now);
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(Diaria_Proposto_AnexoQD._DIAPROANX_STATUS, "A");

                    lReturn = Diaria_Proposto_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //}
                    //else
                    //{
                    //    lblMSG.Visible = true;
                    //    lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //}
                }

                #endregion
            }
            else
            {
                //SUPRIMENTO

                #region Empenho
                //1 empenho
                if (btnImgEmpenho.FileName != "")
                {
                    //lTipo = Path.GetExtension(Path.GetFileName(btnImgEmpenho.FileName));
                    //Anexo = new byte[0];

                    //if (lTipo.ToLower() == ".jpg")
                    //{
                    Anexo = carregaAnexoEmpenho();

                    lFields.Clear();
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUN_ID, hidKEY_ID.Value);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_TIPO, 1);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_IMG, Anexo);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGDATE, DateTime.Now);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_STATUS, "A");

                    lReturn = SuprimentoFundo_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //}
                    //else
                    //{
                    //    lblMSG.Visible = true;
                    //    lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //}
                }
                #endregion

                #region LIQUIDAÇÃO
                if (btnImgLiquidacao.FileName != "")
                {
                    //lTipo = Path.GetExtension(Path.GetFileName(btnImgLiquidacao.FileName));
                    //Anexo = new byte[0];

                    //if (lTipo.ToLower() == ".jpg")
                    //{
                    Anexo = carregaAnexoLiquidacao();

                    lFields.Clear();
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUN_ID, hidKEY_ID.Value);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_TIPO, 2);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_IMG, Anexo);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGDATE, DateTime.Now);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_STATUS, "A");

                    lReturn = SuprimentoFundo_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //}
                    //else
                    //{
                    //    lblMSG.Visible = true;
                    //    lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //}
                }
                #endregion

                #region OB
                if (btnImgOb.FileName != "")
                {
                    //lTipo = Path.GetExtension(Path.GetFileName(btnImgOb.FileName));
                    //Anexo = new byte[0];

                    //if (lTipo.ToLower() == ".jpg")
                    //{
                    Anexo = carregaAnexoOb();

                    lFields.Clear();
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUN_ID, hidKEY_ID.Value);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_TIPO, 3);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_IMG, Anexo);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGDATE, DateTime.Now);
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(SuprimentoFundo_AnexoQD._SUPFUNANX_STATUS, "A");

                    lReturn = SuprimentoFundo_AnexoTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    //}
                    //else
                    //{
                    //    lblMSG.Visible = true;
                    //    lblMSG.Text = "Só possível salvar imagens JPG ou JPEG";
                    //}
                }
                #endregion
            }
        }
        private void InterfaceUpdate(decimal pNOTFIS_ID, string pStatus)
        {
            try
            {
                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                lFields.Add(NotaFiscalQD._NOTFIS_ID, pNOTFIS_ID);

                if (pStatus == "A")
                {
                    lFields.Add(NotaFiscalQD._NOTFIS_NUMERO, txtNOTFIS_NUMERO.Text);
                    lFields.Add(NotaFiscalQD._NOTFIS_VALOR, txtNOTFIS_VALOR.Text);
                    //lFields.Add(NotaFiscalQD._FIG_ID.Text);
                    //lFields.Add(NotaFiscalQD._PRESNOT_ID , txtPRESNOT_ID.Text);
                }

                lFields.Add(NotaFiscalQD._NOTFIS_REGDATE, DateTime.Now);
                lFields.Add(NotaFiscalQD._NOTFIS_REGUSER, "USER");
                lFields.Add(NotaFiscalQD._NOTFIS_STATUS, pStatus);

                lReturn = NotaFiscalTo.Update(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    MessageBox1.wuc_ShowMessage("Registro salvo com sucesso.", 1);
                    //Clear();
                }
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }
        private void TramitacaoInclude(string pSetorOri, decimal pDoc_id)
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lreturn = new OperationResult();
            string lSeqOrg;

            try
            {
                lSeqOrg = SETORTo.GetSEQUENCIAORGANOGRAMA_PRESTACAObySETOR(LocalInstance.ConnectionInfo, "N", pSetorOri);

                lFields.Add(TRAMITACAOQD._SORG_ID, lSeqOrg);
                //lFields.Add(TRAMITACAOQD._SET_IDDESTINO, lSetorDest);
                lFields.Add(TRAMITACAOQD._SPED_ID, 1);
                lFields.Add(TRAMITACAOQD._DOC_ID, hidDOC_ID.Value);

                lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                lFields.Add(TRAMITACAOQD._TRA_REGUSER, "USER");
                lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");

                lreturn = TRAMITACAOTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lreturn.IsValid)
                {
                    Exception exc = new Exception(lreturn.OperationException.Message.ToString());
                    throw exc;
                }
            }
            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception e)
            {
                (new UnknownException(e)).TratarExcecao(true);
            }
        }
        private bool PropostoUpdate()
        {
            if (hidTipo.Value.Equals("2")) //Diaria
            {
                try
                {
                    DataFieldCollection lFields = new DataFieldCollection();
                    OperationResult lReturn = new OperationResult();

                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_ID, hidPESF_ID.Value);

                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_NUMEROEMPENHO, txtEmpenho.Text);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_LIQUIDACAO, txtLiquidacao.Text);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_OB, txtOB.Text);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_PD, txtDOCSAL_SALDO.Text);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_EVENTO, txtEvento.Text);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_REGDATE, DateTime.Now);
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(DIARIA_PROPOSTOQD._DIAPRO_STATUS, "A");

                    lReturn = DIARIA_PROPOSTOTo.Update(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    else
                    {
                        //InterfaceIncludeDocumentoSaldo();
                        IncludeImagem();
                        return true;
                    }
                }
                catch (WebManagerException e)
                {
                    e.TratarExcecao(true);
                }
                catch (Exception err)
                {
                    (new UnknownException(err)).TratarExcecao(true);
                }
            }
            else //suprimento de fundo
            {
                try
                {
                    DataFieldCollection lFields = new DataFieldCollection();
                    OperationResult lReturn = new OperationResult();

                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_ID, hidKEY_ID.Value);

                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_NUMEROEMPENHO, txtEmpenho.Text);
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_LIQUIDACAO, txtLiquidacao.Text);
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_OB, txtOB.Text);
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_PD, txtDOCSAL_SALDO.Text);
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_REGDATE, DateTime.Now);
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_REGUSER, Session["_SessionUser"].ToString());
                    lFields.Add(SUPRIMENTOFUNDOQD._SUPFUN_STATUS, "A");

                    lReturn = SUPRIMENTOFUNDOTo.Update(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }
                    else
                    {
                        //InterfaceIncludeDocumentoSaldo();
                        IncludeImagem();
                        return true;
                    }
                }
                catch (WebManagerException e)
                {
                    e.TratarExcecao(true);
                }
                catch (Exception err)
                {
                    (new UnknownException(err)).TratarExcecao(true);
                }
            }
            return false;
        }
        private void InterfaceInclude()
        {
            try
            {
                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                String Aux;

                Aux = txtDESCCENTES_APRESENTACAO.Text.Replace("size", "");
                Aux = txtDESCCENTES_APRESENTACAO.Text.Replace("H1", "");
                Aux = txtDESCCENTES_APRESENTACAO.Text.Replace("H2", "");
                Aux = txtDESCCENTES_APRESENTACAO.Text.Replace("H3", "");
                Aux = txtDESCCENTES_APRESENTACAO.Text.Replace("H4", "");
                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_APRESENTACAO, Aux);
                Aux = txtDESCCENTES_OBJETIVO.Text.Replace("size", "");
                Aux = txtDESCCENTES_OBJETIVO.Text.Replace("H1", "");
                Aux = txtDESCCENTES_OBJETIVO.Text.Replace("H2", "");
                Aux = txtDESCCENTES_OBJETIVO.Text.Replace("H3", "");
                Aux = txtDESCCENTES_OBJETIVO.Text.Replace("H4", "");
                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_OBJETIVO, Aux);
                Aux = txtDESCCENTES_CONTATO.Text.Replace("size", "");
                Aux = txtDESCCENTES_CONTATO.Text.Replace("H1", "");
                Aux = txtDESCCENTES_CONTATO.Text.Replace("H2", "");
                Aux = txtDESCCENTES_CONTATO.Text.Replace("H3", "");
                Aux = txtDESCCENTES_CONTATO.Text.Replace("H4", "");
                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_CONTATO, Aux);

                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_REGDATE, DateTime.Now);
                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_REGUSER, "USER");
                lFields.Add(DESCCENTROESTUDOQD._DESCCENTES_STATUS, "A");

                lReturn = DESCCENTROESTUDOTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    MessageBox1.wuc_ShowMessage("Registro salvo com sucesso.", 1);
                    LoadGrid();
                    LoadCampos();

                }
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }
        private void TramitacaoUpdate()
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            try
            {
                lFields.Add(TRAMITACAOQD._TRA_ID, hidTRA_ID.Value);
                lFields.Add(TRAMITACAOQD._SPED_ID, "3");
                lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                lFields.Add(TRAMITACAOQD._TRA_REGUSER, Session["_SessionUser"].ToString());
                lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");

                lReturn = TRAMITACAOTo.Update(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception e = new Exception(lReturn.OperationException.Message.ToString());
                    throw e;
                }
                else
                {
                    TramitacaoInclude();
                }

            }
            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception e)
            {
                (new UnknownException(e)).TratarExcecao(true);
            }
        }
        private void TramitacaoInclude()
        {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lreturn = new OperationResult();

            try
            {
                DataTable lTableSetor = SETORTo.GetSEQUENCIAORGANOGRAMAbyTramitacao(LocalInstance.ConnectionInfo, hidTRA_ID.Value);
                string lProxProx = "", lProxSeqOrg = "";
                if (lTableSetor.Rows.Count > 0)
                {
                    lProxSeqOrg = lTableSetor.Rows[0]["SORG_IDCORRESPONDENTE"].ToString();
                    lProxProx = lTableSetor.Rows[0]["PROXIMO"].ToString();
                }

                lFields.Add(TRAMITACAOQD._SORG_ID, lProxSeqOrg);

                if (lProxProx.Length > 0)
                    lFields.Add(TRAMITACAOQD._SPED_ID, 1);
                else
                    lFields.Add(TRAMITACAOQD._SPED_ID, 3);

                lFields.Add(TRAMITACAOQD._DOC_ID, hidDOC_ID.Value);

                lFields.Add(TRAMITACAOQD._TRA_REGDATE, DateTime.Now);
                lFields.Add(TRAMITACAOQD._TRA_REGUSER, "USER");
                lFields.Add(TRAMITACAOQD._TRA_STATUS, "A");

                lreturn = TRAMITACAOTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lreturn.IsValid)
                {
                    Exception exc = new Exception(lreturn.OperationException.Message.ToString());
                    throw exc;
                }
            }
            catch (WebManagerException wex)
            {
                wex.TratarExcecao(true);
            }
            catch (Exception e)
            {
                (new UnknownException(e)).TratarExcecao(true);
            }
        }
        private void InterfaceUpdate(decimal pNATDES_ID,string pStatus)
        {
            try
            {
            DataFieldCollection lFields = new DataFieldCollection();
            OperationResult lReturn = new OperationResult();

            lFields.Add(NATUREZADESPESAQD._NATDES_ID , pNATDES_ID);

            if (pStatus == "A")
            {
            lFields.Add(NATUREZADESPESAQD._NATDES_CODIGO , txtNATDES_CODIGO.Text);
            lFields.Add(NATUREZADESPESAQD._NATDES_DESC , txtNATDES_DESC.Text);
            }

            lFields.Add(NATUREZADESPESAQD._NATDES_REGDATE, DateTime.Now);
            lFields.Add(NATUREZADESPESAQD._NATDES_REGUSER, "USER");
            lFields.Add(NATUREZADESPESAQD._NATDES_STATUS, pStatus);

            lReturn = NATUREZADESPESATo.Update(lFields, LocalInstance.ConnectionInfo);

            if (!lReturn.IsValid)
            {
            Exception err = new Exception(lReturn.OperationException.Message.ToString());
            throw err;
            }
            else
            {
            MessageBox1.wuc_ShowMessage("Registro salvo com sucesso.", 1);
            LoadGrid();
            Clear();
            }
            }
            catch (WebManagerException e)
            {
            e.TratarExcecao(true);
            }
            catch (Exception err)
            {
            (new UnknownException(err)).TratarExcecao(true);
            }
        }
        public static OperationResult Insert(
           DataFieldCollection pValuesPESF,
           List<DataFieldCollection> pListValuesATUA,
           DataFieldCollection pValuesSUSR,
           List<DataFieldCollection> pListValuesPERMISSAO,
           ConnectionInfo pInfo
        )
        {
            Transaction lTransaction;

            lTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (lTransaction != null);

            InsertCommand lInsert;

            OperationResult lReturn = new OperationResult(PessoaFuncaoQD.TableName, PessoaFuncaoQD.TableName);

            if (!lReturn.HasError)
            {
                try
                {
                    lInsert = new InsertCommand(PessoaFuncaoQD.TableName);

                    foreach (DataField lField in pValuesPESF.Keys)
                    {
                        lInsert.Fields.Add(lField.Name, pValuesPESF[lField], (ItemType)lField.DBType);
                    }
                    decimal lSequencePESF_ID;
                    lSequencePESF_ID = DataBaseSequenceControl.GetNext(pInfo, "PESF_ID");
                    lInsert.Fields.Add(PessoaFuncaoQD._PESF_ID.Name, lSequencePESF_ID, (ItemType)PessoaFuncaoQD._PESF_ID.DBType);

                    lReturn.SequenceControl = lSequencePESF_ID;

                    lInsert.Execute(lTransaction);

                    if (!lReturn.HasError)
                    {

                        if (pListValuesATUA.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesATUA)
                            {
                                lFields.Add(AtuacaoQD._PESF_ID, lSequencePESF_ID);

                                lReturn = AtuacaoDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        lReturn = SystemUserDo.Insert(pValuesSUSR, lTransaction, pInfo);
                        if (lReturn.HasError)
                        {
                            lTransaction.Rollback();
                            return lReturn;
                        }

                        if (pListValuesPERMISSAO.Count > 0)
                        {
                            foreach (DataFieldCollection lFields in pListValuesPERMISSAO)
                            {
                                lFields.Add(SecurityUsersDtQD._SU_ID, lSequencePESF_ID);

                                lReturn = SecurityUsersDtDo.Insert(lFields, lTransaction, pInfo);

                                if (lReturn.HasError)
                                {
                                    lTransaction.Rollback();
                                    return lReturn;
                                }
                            }
                        }

                        if (!lReturn.HasError)
                        {
                            lTransaction.Commit();
                        }
                        else
                        {
                            lTransaction.Rollback();
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            lTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        lTransaction.Rollback();
                }
            }

            return lReturn;
        }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(EscalaQD._ESC_ID, pValues, pResult);
     //GenericDataObject.ValidateRequired(EscalaQD._ESC_REGDATE, pValues, pResult);
     //GenericDataObject.ValidateRequired(EscalaQD._ESC_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(EscalaQD._ESC_STATUS, pValues, pResult);
 }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(PessoaFuncaoQD._PESF_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(PessoaFuncaoQD._PESF_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(PessoaFuncaoQD._PESF_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(PessoaFuncaoQD._PESF_STATUS, pValues, pResult);
 }
        private decimal InterfaceIncludeFigura(byte[] IMG)
        {
            decimal ID = 0;

            try
            {

                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                lFields.Add(FIGURASQD._FIG_IMAGEN, IMG);
                lFields.Add(FIGURASQD._FIG_NOME, "FIGURA");
                lFields.Add(FIGURASQD._FIG_FORMATO, ".jpg");
                lFields.Add(FIGURASQD._FIG_TAMANHO, IMG);
                lFields.Add(FIGURASQD._FIG_REGDATE, DateTime.Now);
                lFields.Add(FIGURASQD._FIG_REGUSER, "USER");
                lFields.Add(FIGURASQD._FIG_STATUS, "A");

                lReturn = FIGURASTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    ID = lReturn.SequenceControl;
                }
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
            return ID;
        }
        public static OperationResult Update(
            DataFieldCollection pValues,
            ConnectionInfo pInfo
        )
        {
            Transaction pTransaction;

            pTransaction = new Transaction(Instance.CreateDatabase(pInfo));

            bool lLocalTransaction = (pTransaction != null);

            UpdateCommand lUpdate;

            OperationResult lReturn = new OperationResult(PLANOINTERNOQD.TableName, PLANOINTERNOQD.TableName);

            ValidateUpdate(pValues, lReturn);

            if (lReturn.IsValid)
            {
                try
                {
                    if (lLocalTransaction)
                    {
                        lReturn.Trace("Transação local, instanciando banco...");
                    }

                    lUpdate = new UpdateCommand(PLANOINTERNOQD.TableName);

                    lReturn.Trace("Adicionando campos ao objeto de update");
                    foreach (DataField lField in pValues.Keys)
                    {
                        if ((lField.Name != PLANOINTERNOQD._PLANI_ID.Name))
                            lUpdate.Fields.Add(lField.Name, pValues[lField], (ItemType)lField.DBType);
                    }

                    string lSql = "";
                    lSql = String.Format("WHERE {0} = <<{0}", PLANOINTERNOQD._PLANI_ID.Name);
                    lUpdate.Condition = lSql;
                    lUpdate.Conditions.Add(PLANOINTERNOQD._PLANI_ID.Name, pValues[PLANOINTERNOQD._PLANI_ID].DBToDecimal());

                    lReturn.Trace("Executando o Update");

                    lUpdate.Execute(pTransaction);

                    if (!lReturn.HasError)
                    {
                        if (lLocalTransaction)
                        {
                            if (!lReturn.HasError)
                            {
                                lReturn.Trace("Update finalizado, executando commit");

                                pTransaction.Commit();
                            }
                            else
                            {
                                pTransaction.Rollback();
                            }
                        }
                    }
                    else
                    {
                        if (lLocalTransaction)
                            pTransaction.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    lReturn.OperationException = new SerializableException(ex);

                    if (lLocalTransaction)
                        pTransaction.Rollback();
                }
            }

            return lReturn;
        }
        private void InterfaceIncludeNotaFiscal(decimal notaid)
        {
            try
            {
                DataTable lTable = (DataTable)ViewState["WRK_TABLE"];

                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                CreateTableReceitaDespesa();
                DataTable lTableReceitaDespesa = (DataTable)ViewState["WRK_TABLE_RD"];

                for (int i = 0; i < lTable.Rows.Count; i++)
                {
                    lFields.Add(NotaFiscalQD._NOTFIS_NUMERO, lTable.Rows[i][NotaFiscalQD._NOTFIS_NUMERO.Name].ToString());
                    lFields.Add(NotaFiscalQD._NOTFIS_VALOR, lTable.Rows[i][NotaFiscalQD._NOTFIS_VALOR.Name].ToString());
                    lFields.Add(NotaFiscalQD._NOTFIS_TIPO, lTable.Rows[i][NotaFiscalQD._NOTFIS_TIPO.Name].DBToDecimal());

                    decimal fig_id = InterfaceIncludeFigura((byte[])lTable.Rows[i]["FIGURA"]);

                    if (fig_id == 0)
                    {
                        lFields.Clear();
                        continue;
                    }
                    lFields.Add(NotaFiscalQD._FIG_ID, fig_id);
                    lFields.Add(NotaFiscalQD._PRESNOT_ID, notaid);
                    lFields.Add(NotaFiscalQD._NOTFIS_REGDATE, DateTime.Now);
                    lFields.Add(NotaFiscalQD._NOTFIS_REGUSER, "USER");
                    lFields.Add(NotaFiscalQD._NOTFIS_STATUS, "A");

                    lReturn = NotaFiscalTo.Insert(lFields, LocalInstance.ConnectionInfo);

                    if (!lReturn.IsValid)
                    {
                        Exception err = new Exception(lReturn.OperationException.Message.ToString());
                        throw err;
                    }

                    lFields.Clear();

                    #region Tabela Relatorio
                    DataRow lRow = lTableReceitaDespesa.NewRow();

                    int lord = i + 2;
                    lRow["ORD"] = lord.ToString();
                    lRow[NotaFiscalQD._NOTFIS_DESCRICAO.Name] = lTable.Rows[i][NotaFiscalQD._NOTFIS_DESCRICAO.Name].ToString();
                    lRow[NotaFiscalQD._NOTFIS_NUMERO.Name] = lTable.Rows[i][NotaFiscalQD._NOTFIS_NUMERO.Name].ToString();

                    //if (lTable.Rows[i][NotaFiscalQD._NOTFIS_TIPO.Name].DBToDecimal() == (decimal)TipoNotaFiscal.NotaFiscal)
                    //    lRow["DEBITO"] = lTable.Rows[i][NotaFiscalQD._NOTFIS_VALOR.Name].DBToDecimal();
                    //else
                    lRow["CREDITO"] = lTable.Rows[i][NotaFiscalQD._NOTFIS_VALOR.Name].DBToDecimal();

                    lTableReceitaDespesa.Rows.Add(lRow);

                    #endregion
                }

                Session["WRK_PARAMETER_REGUSER"] = hidPES_NOME.Value;
                Session["WRK_PARAMETER_PORTARIA"] = hidPORT_NUMERO.Value;
                Session["WRK_TABLE"] = lTableReceitaDespesa;
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }
 private static void ValidateUpdate(DataFieldCollection pValues, OperationResult pResult)
 {
     GenericDataObject.ValidateRequired(PLANOINTERNOQD._PLANI_ID, pValues, pResult);
     GenericDataObject.ValidateRequired(PLANOINTERNOQD._PLANI_REGDATE, pValues, pResult);
     GenericDataObject.ValidateRequired(PLANOINTERNOQD._PLANI_REGUSER, pValues, pResult);
     GenericDataObject.ValidateRequired(PLANOINTERNOQD._PLANI_STATUS, pValues, pResult);
 }
        private void InterfaceIncludePrestacaoNotaFiscal()
        {
            decimal ID = 0;
            try
            {
                DataFieldCollection lFields = new DataFieldCollection();
                OperationResult lReturn = new OperationResult();

                lFields.Add(PrestacaoxNotaFiscalQD._PRES_ID, Session["PRES_ID"].ToString());
                lFields.Add(PrestacaoxNotaFiscalQD._PRESNOT_DATA, DateTime.Now);
                lFields.Add(PrestacaoxNotaFiscalQD._PRESNOT_REGDATE, DateTime.Now);
                lFields.Add(PrestacaoxNotaFiscalQD._PRESNOT_REGUSER, "USER");
                lFields.Add(PrestacaoxNotaFiscalQD._PRESNOT_STATUS, "A");

                lReturn = PrestacaoxNotaFiscalTo.Insert(lFields, LocalInstance.ConnectionInfo);

                if (!lReturn.IsValid)
                {
                    Exception err = new Exception(lReturn.OperationException.Message.ToString());
                    throw err;
                }
                else
                {
                    ID = lReturn.SequenceControl;
                    InterfaceIncludeNotaFiscal(ID);

                    string lSetorOri = (string)Session["_SessionSetor"];
                    TramitacaoInclude(lSetorOri, decimal.Parse(hidDOC_ID.Value));

                    MessageBox1.wuc_ShowMessage("Prestação Realizada com sucesso. Aguarde a proxima janela aparecer com o demonstrativo da receita e da espesa.",
                                    "AutDefault.aspx", "Reports/LoadReport.aspx?ReportName=SFReceitaDespesa.rpt", 1);

                    Session["PRES_ID"] = null;
                    Session["DOC_ID"] = null;
                    Session["KEY_ID"] = null;
                }
            }
            catch (WebManagerException e)
            {
                e.TratarExcecao(true);
            }
            catch (Exception err)
            {
                (new UnknownException(err)).TratarExcecao(true);
            }
        }