private bool bSaveMessage(int nIdMessage, int nTrysLeft) { bool bReturn = false; if (nTrysLeft == 0) { return(false); } mdlDataBaseAccess.Tabelas.XsdTbMensagens typDatSetMensagens = null; bLoadMessages(out typDatSetMensagens, false, false); clsMessage objMessage = Message_Copy(nIdMessage); if (objMessage.Deleted) { // DELETE mdlDataBaseAccess.Tabelas.XsdTbMensagens.tbMensagensRow dtrwMessage = typDatSetMensagens.tbMensagens.FindBynIdMessagenIdMessageType(nIdMessage, mdlConstantes.clsConstantes.ID_SCHEDULER_CONTRATOCAMBIO); if (dtrwMessage != null) { dtrwMessage.bDeleted = true; m_cls_dba_ConnectionDB.SetTbMensagens(typDatSetMensagens); if (m_cls_dba_ConnectionDB.Erro != null) { return(bSaveMessage(nTrysLeft - 1)); } else { return(true); } } else { return(true); } } else { bReturn = true; } if (bReturn == false) { return(bSaveMessage(nTrysLeft - 1)); } else { return(true); } }
private bool bSaveMessage(int nIdMessage, int nTrysLeft) { bool bReturn = false; if (nTrysLeft == 0) { return(false); } mdlDataBaseAccess.Tabelas.XsdTbMensagens typDatSetMensagens = null; bLoadMessages(out typDatSetMensagens, false); clsMessage objMessage = Message_Copy(nIdMessage); if (objMessage == null) { return(true); } if (objMessage.Deleted) { // DELETE mdlDataBaseAccess.Tabelas.XsdTbMensagens.tbMensagensRow dtrwMessage = typDatSetMensagens.tbMensagens.FindBynIdMessagenIdMessageType(nIdMessage, mdlConstantes.clsConstantes.ID_SCHEDULER_PERSONALIZED); if (dtrwMessage != null) { dtrwMessage.Delete(); m_cls_dba_ConnectionDB.SetTbMensagens(typDatSetMensagens); if (m_cls_dba_ConnectionDB.Erro != null) { vMessageNotDeleted(nIdMessage); } else { bMessage_Remove(nIdMessage); } return(m_cls_dba_ConnectionDB.Erro == null); } else { return(true); } } else if (objMessage.Updated) { // Updated // Hack: Make it } else if (objMessage.Inserted) { // INSERT mdlDataBaseAccess.Tabelas.XsdTbMensagens.tbMensagensRow dtrwMessage = typDatSetMensagens.tbMensagens.FindBynIdMessagenIdMessageType(nIdMessage, mdlConstantes.clsConstantes.ID_SCHEDULER_PERSONALIZED); if (dtrwMessage == null) { dtrwMessage = typDatSetMensagens.tbMensagens.NewtbMensagensRow(); dtrwMessage.nIdMessage = nIdMessage; dtrwMessage.nIdMessageType = mdlConstantes.clsConstantes.ID_SCHEDULER_PERSONALIZED; dtrwMessage.nIdMessageSubType = 1; dtrwMessage.dtEvent = objMessage.DateEvent; dtrwMessage.dtShow = objMessage.DateShow; dtrwMessage.bShow = objMessage.Show; dtrwMessage.mstrMessage = objMessage.Message; typDatSetMensagens.tbMensagens.AddtbMensagensRow(dtrwMessage); m_cls_dba_ConnectionDB.SetTbMensagens(typDatSetMensagens); if (m_cls_dba_ConnectionDB.Erro == null) { vMessageNotInserted(nIdMessage); return(true); } else { bReIdMessage(ref nIdMessage); return(bSaveMessage(nIdMessage, nTrysLeft - 1)); } } else { bReIdMessage(ref nIdMessage); return(bSaveMessage(nIdMessage, nTrysLeft - 1)); } } else { bReturn = true; } if (bReturn == false) { return(bSaveMessage(nIdMessage, nTrysLeft - 1)); } else { return(true); } }
private bool bSyncronizeMessages(int nTrys) { if (nTrys == 0) { return(false); } mdlDataBaseAccess.Tabelas.XsdTbMensagens typDatSetMensagens = null; if (bLoadMessages(out typDatSetMensagens, false, true)) { m_cls_dba_ConnectionDB.FonteDosDados = mdlDataBaseAccess.FonteDados.DataBase; bool bShowDialogErrors = m_cls_dba_ConnectionDB.ShowDialogsErrors; m_cls_dba_ConnectionDB.ShowDialogsErrors = false; mdlDataBaseAccess.Tabelas.XsdTbPes typDatSetPes = m_cls_dba_ConnectionDB.GetTbPes(null, null, null, null, null); m_cls_dba_ConnectionDB.ShowDialogsErrors = bShowDialogErrors; string strMessage = ""; mdlDataBaseAccess.Tabelas.XsdTbMensagens.tbMensagensRow dtrwMessage = null; // Inserting new Messages foreach (mdlDataBaseAccess.Tabelas.XsdTbPes.tbPEsRow dtrwPe in typDatSetPes.tbPEs.Rows) { // Chegada Prevista Transporte if (!dtrwPe.IsdtDeadlineChegadaPrevistaTransporteNull() && (dtrwPe.dtDeadlineChegadaPrevistaTransporte != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseChegadaTransporte, dtrwPe.dtDeadlineChegadaPrevistaTransporte, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_CHEGADATRANSPORTE, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_CHEGADATRANSPORTE, dtrwPe.dtDeadlineChegadaPrevistaTransporte.AddMinutes(-m_dMinutesBeforeShowChegadaTransporte), dtrwPe.dtDeadlineChegadaPrevistaTransporte, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineChegadaPrevistaTransporte) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineChegadaPrevistaTransporte; dtrwMessage.dtShow = dtrwPe.dtDeadlineChegadaPrevistaTransporte.AddMinutes(-m_dMinutesBeforeShowChegadaTransporte); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Lista Carga if (!dtrwPe.IsdtDeadlineListaCargaNull() && (dtrwPe.dtDeadlineListaCarga != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseListaCarga, dtrwPe.dtDeadlineListaCarga, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_LISTACARGA, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_LISTACARGA, dtrwPe.dtDeadlineListaCarga.AddMinutes(-m_dMinutesBeforeShowListaCarga), dtrwPe.dtDeadlineListaCarga, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineListaCarga) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineListaCarga; dtrwMessage.dtShow = dtrwPe.dtDeadlineListaCarga.AddMinutes(-m_dMinutesBeforeShowListaCarga); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Espelho BL if (!dtrwPe.IsdtDeadLineEspelhoBLNull() && (dtrwPe.dtDeadLineEspelhoBL != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseEspelhoBL, dtrwPe.dtDeadLineEspelhoBL, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_ESPELHOBL, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_ESPELHOBL, dtrwPe.dtDeadLineEspelhoBL.AddMinutes(-m_dMinutesBeforeShowEspelhoBL), dtrwPe.dtDeadLineEspelhoBL, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadLineEspelhoBL) { dtrwMessage.dtEvent = dtrwPe.dtDeadLineEspelhoBL; dtrwMessage.dtShow = dtrwPe.dtDeadLineEspelhoBL.AddMinutes(-m_dMinutesBeforeShowEspelhoBL); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Retirada Container Terminal if (!dtrwPe.IsdtDeadlineRetiradaContainerTerminalNull() && (dtrwPe.dtDeadlineRetiradaContainerTerminal != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseRetiradaContainerTerminal, dtrwPe.dtDeadlineRetiradaContainerTerminal, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_RETIRADACONTAINERTERMINAL, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_RETIRADACONTAINERTERMINAL, dtrwPe.dtDeadlineRetiradaContainerTerminal.AddMinutes(-m_dMinutesBeforeShowRetiradaContainerTerminal), dtrwPe.dtDeadlineRetiradaContainerTerminal, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineRetiradaContainerTerminal) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineRetiradaContainerTerminal; dtrwMessage.dtShow = dtrwPe.dtDeadlineRetiradaContainerTerminal.AddMinutes(-m_dMinutesBeforeShowRetiradaContainerTerminal); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Abertura Portao if (!dtrwPe.IsdtAberturaPortaoNull() && (dtrwPe.dtAberturaPortao != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseAberturaPortao, dtrwPe.dtAberturaPortao, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_ABERTURAPORTAO, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_ABERTURAPORTAO, dtrwPe.dtAberturaPortao.AddMinutes(-m_dMinutesBeforeShowAberturaPortao), dtrwPe.dtAberturaPortao, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtAberturaPortao) { dtrwMessage.dtEvent = dtrwPe.dtAberturaPortao; dtrwMessage.dtShow = dtrwPe.dtAberturaPortao.AddMinutes(-m_dMinutesBeforeShowAberturaPortao); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Fechamento Portao if (!dtrwPe.IsdtDeadlineFechamentoPortaoNull() && (dtrwPe.dtDeadlineFechamentoPortao != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseFechamentoPortao, dtrwPe.dtDeadlineFechamentoPortao, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_FECHAMENTOPORTAO, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_FECHAMENTOPORTAO, dtrwPe.dtDeadlineFechamentoPortao.AddMinutes(-m_dMinutesBeforeShowFechamentoPortao), dtrwPe.dtDeadlineFechamentoPortao, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineFechamentoPortao) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineFechamentoPortao; dtrwMessage.dtShow = dtrwPe.dtDeadlineFechamentoPortao.AddMinutes(-m_dMinutesBeforeShowFechamentoPortao); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Liberacao Receita Federal if (!dtrwPe.IsdtDeadlineLiberacaoRFNull() && (dtrwPe.dtDeadlineLiberacaoRF != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseLiberacaoRF, dtrwPe.dtDeadlineLiberacaoRF, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_LIBERACAORECEITAFEDERAL, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_LIBERACAORECEITAFEDERAL, dtrwPe.dtDeadlineLiberacaoRF.AddMinutes(-m_dMinutesBeforeShowLiberacaoRF), dtrwPe.dtDeadlineLiberacaoRF, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineLiberacaoRF) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineLiberacaoRF; dtrwMessage.dtShow = dtrwPe.dtDeadlineLiberacaoRF.AddMinutes(-m_dMinutesBeforeShowLiberacaoRF); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } // Outro if (!dtrwPe.IsdtDeadlineOutroNull() && (dtrwPe.dtDeadlineOutro != mdlConstantes.clsConstantes.DATANULA)) { strMessage = strReturnMessageMounted(m_strMessageBaseOutro, dtrwPe.dtDeadlineOutro, dtrwPe.idExportador, dtrwPe.idPE); if ((dtrwMessage = mesReturn(ref typDatSetMensagens, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_OUTRO, dtrwPe.idExportador, dtrwPe.idPE)) == null) { typDatSetMensagens.tbMensagens.AddtbMensagensRow(nNextId(ref typDatSetMensagens), mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE, mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE_SUBTYPE_OUTRO, dtrwPe.dtDeadlineOutro.AddMinutes(-m_dMinutesBeforeShowOutro), dtrwPe.dtDeadlineOutro, true, false, strMessage, dtrwPe.idExportador, dtrwPe.idPE); } else { if (dtrwMessage.dtEvent != dtrwPe.dtDeadlineOutro) { dtrwMessage.dtEvent = dtrwPe.dtDeadlineOutro; dtrwMessage.dtShow = dtrwPe.dtDeadlineOutro.AddMinutes(-m_dMinutesBeforeShowOutro); dtrwMessage.mstrMessage = strMessage; dtrwMessage.bDeleted = false; } } } } // Removing Messages foreach (mdlDataBaseAccess.Tabelas.XsdTbMensagens.tbMensagensRow dtrwMessageCurrent in typDatSetMensagens.tbMensagens.Rows) { if ((dtrwMessageCurrent.RowState != System.Data.DataRowState.Deleted) && (!dtrwMessageCurrent.bDeleted) && (dtrwMessageCurrent.nIdMessageType == mdlConstantes.clsConstantes.ID_SCHEDULER_DEADLINE)) { if (typDatSetPes.tbPEs.FindByidExportadoridPE(dtrwMessageCurrent.nIdExportador, dtrwMessageCurrent.strIdPe) == null) { dtrwMessageCurrent.Delete(); } } } m_cls_dba_ConnectionDB.SetTbMensagens(typDatSetMensagens); if (m_cls_dba_ConnectionDB.Erro == null) { return(true); } else { return(bSyncronizeMessages(nTrys - 1)); } } else { return(false); } }