public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); this.marcacoes = marcacoes; string Answer = ""; if (tipoimportacao == TipoImportacaoMarcacoes.Backup) { if (!GetNMarcacoes()) { return(false); } if (NMarcacoes == 0) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); return(false); } } int NsrInicio = (tipoimportacao == TipoImportacaoMarcacoes.OnlyNew ? (new DBApp()).getLastNsr(TerminalDados.Indice) + 1 : 1); Send(String.Format("01+RR+00+N]999999999]{0}", NsrInicio), out Answer); return(ProcessAnswer(Answer)); }
public ActionResult DeleteConfirmed(int id) { Marcacoes marcacoes = db.Marcacoes.Find(id); db.Marcacoes.Remove(marcacoes); db.SaveChanges(); return(RedirectToAction("Index")); }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); bool Result = false; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice); int NRegistrosLidos = 0; short porta = (short)TerminalDados.Porta; if (Connect(0)) { //string Ponteir = starRep.VerificarNSRPonteiro(TerminalDados.IP, porta, numeroTentativas, tempoEsperaMilissegundos); //int ultimoNSR = Convert.ToInt32(starRep.VerificarUltimoNSR(TerminalDados.IP, porta, numeroTentativas, tempoEsperaMilissegundos)); try { string resposta = starRep.ColetarMarcacoes(TerminalDados.IP, porta, numeroTentativas, tempoEsperaMilissegundos, ProximoNsr + 1, "|"); while (!string.IsNullOrEmpty(resposta) && !resposta.ToLower().Equals("erro")) { string[] respostas = resposta.Split('|'); NRegistrosLidos = Convert.ToInt32(respostas[0]); for (int i = 1; i < NRegistrosLidos + 1; i++) { string b = respostas[i].Substring(0, 9); string c = b + 3 + respostas[i].Substring(9); AssepontoRep.Marcacoes.Marcacao mrc = new AssepontoRep.Marcacoes.Marcacao(); if (marcacoes.InterpretarRegistroAfd(c, out mrc)) { if (mrc.Tipo == Marcacoes.TiposRegistroAfd.Marcacao) { marcacoes.Add(mrc); } } } resposta = string.Empty; } if (marcacoes.Count == 0) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } Result = true; } catch (Exception ex) { log.AddLog(ex.Message); } finally { starRep.Fecha_Comunicacao(); } } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); bool Result = false; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; int Contador = 0; MRPRecord[] registrosMRP; if (Dimep_Conectar()) { try { _watchComm.RepositioningMRPRecordsPointer(ProximoNsr.ToString()); registrosMRP = this._watchComm.InquiryMRPRecords(false, false, true, false); while (registrosMRP != null) { foreach (MRPRecord registroMRP in registrosMRP) { if (registroMRP is MRPRecord_RegistrationMarkingPoint) { string Pis = ((MRPRecord_RegistrationMarkingPoint)registroMRP).Pis; DateTime DataHora = ((MRPRecord_RegistrationMarkingPoint)registroMRP).DateTimeMarkingPoint; int Nsr = Convert.ToInt32(((MRPRecord_RegistrationMarkingPoint)registroMRP).NSR); marcacoes.Add(Pis, DataHora, Nsr); Contador++; if (Nsr > ProximoNsr) { ProximoNsr = Nsr; } } } registrosMRP = _watchComm.ConfirmationReceiptMRPRecords(); } base.FinalizarImportacaoMarcacoes(marcacoes, ProcessarMarcacoesAoImportar.ProcessarSim); } catch (Exception ex) { log.AddLog(ex.Message); } finally { Dimep_Desconectar(); } } return(Result); }
public ActionResult Edit([Bind(Include = "MarcacaoID,DataMarcacoes,MedicoFK,PacienteFK,EspecialidadeFK")] Marcacoes marcacoes) { if (ModelState.IsValid) { db.Entry(marcacoes).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MedicoFK = new SelectList(db.Medicos, "MedicoID", "Nome", marcacoes.MedicoFK); ViewBag.PacienteFK = new SelectList(db.Pacientes, "PacienteID", "Nome", marcacoes.PacienteFK); return(View(marcacoes)); }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { bool Result = false; base.LerMarcacoes(marcacoes, tipoimportacao); string nsr = ""; string pis = ""; int year = 0; int month = 0; int day = 0; int hour = 0; int min = 0; int sec = 0; int iIndex = 0; int idwErrorCode = -9; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; bool connect = Connect(TerminalDados.Indice); //bioRep.SetSeekPosition(TerminalDados.Indice, ProximoNsr); if (connect) { log.AddLog("PROCESSANDO MARCAÇÕES...", true); bioRep.EnableDevice(TerminalDados.Indice, false); while (bioRep.GetAttLogs_BZ900(TerminalDados.Indice, out nsr, out pis, out year, out month, out day, out hour, out min, out sec)) { DateTime DataHora = new DateTime(year, month, day, hour, min, sec); marcacoes.Add(pis, DataHora, Convert.ToInt32(nsr)); if (iIndex % 50 == 0) { System.Threading.Thread.Sleep(200); } iIndex++; Result = true; } bioRep.GetLastError(ref idwErrorCode); } if (iIndex == 0) { Result = false; } bioRep.EnableDevice(TerminalDados.Indice, true); return(Result); }
/// <summary> /// detalhes de uma consulta /// </summary> /// <returns></returns> // GET: Marcacoes/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Marcacoes marcacoes = db.Marcacoes.Find(id); if (marcacoes == null) { return(HttpNotFound()); } return(View(marcacoes)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Marcacoes marcacoes = db.Marcacoes.Find(id); if (marcacoes == null) { return(HttpNotFound()); } ViewBag.MedicoFK = new SelectList(db.Medicos, "MedicoID", "Nome", marcacoes.MedicoFK); ViewBag.PacienteFK = new SelectList(db.Pacientes, "PacienteID", "Nome", marcacoes.PacienteFK); return(View(marcacoes)); }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); bool ExpirouTimeout = false; for (int y = 1; y <= 1; y++) { RecebeMarcacoesTCP(marcacoes); if (ExpirouTimeout) { log.AddLog(String.Format("RECONECTANDO APÓS TIMEOUT [TENTATIVA {0}]", y)); for (int i = 5; i > 0; i--) { if (i == 1) { log.AddLog("CONECTANDO EM 1 SEGUNDO"); } else { log.AddLog(String.Format("CONECTANDO EM {0} SEGUNDOS", i)); } Application.DoEvents(); Wr.Classes.Utils.Pause(1); if (Cancelar) { log.AddLog("RECONEXÃO CANCELADA"); break; } } } else { break; } } return(marcacoes.Count > 0); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { DBApp db = new DBApp(); Connect(TerminalDados.Indice); string from = ""; string to = ""; RepProtocol.FiltroRegistro f; if (tipoimportacao == TipoImportacaoMarcacoes.OnlyNew) { f = RepProtocol.FiltroRegistro.NsrRange; RepProtocol.MrpStatus st = repProtocol.GetMrpStatus(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; from = ProximoNsr.ToString().PadLeft(9, '0'); to = st.LastNSR.ToString(); } else { f = RepProtocol.FiltroRegistro.All; } List <string> r = repProtocol.GetRegs(f, from, to); foreach (string linha in r) { Marcacoes.Marcacao marcacao = new Marcacoes.Marcacao(); marcacoes.InterpretarRegistroAfd(linha, out marcacao); if (marcacao.Tipo == Marcacoes.TiposRegistroAfd.Marcacao) { marcacoes.Add(marcacao); } } //Wr.Classes.Files.WriteFile(@"c:\arquivo.txt", r); return(marcacoes.Count > 0); }
public static void ImportarMarcacoesTerminal(int Terminal, TextBox edLog) { Types.Terminal TerminalDados; DBApp db = new DBApp(); WinRegistry Registro = new WinRegistry("Assecont", "Asseponto4"); db.getDadosTerminal(Terminal, out TerminalDados); Rede rede = new Rede(TerminalDados.IP, TerminalDados.Porta, edLog); string Arquivo = Folders.folderMarcacoes(TerminalDados.Descricao) + String.Format("{0:yyyy MM dd hhmm}", DateTime.Now) + ".txt"; Marcacoes marcacoes = new Marcacoes(Arquivo); if (rede.Dimep_ImportarMarcacoes(Terminal, TerminalDados.Descricao, marcacoes)) { Utilitarios.setArquivoImportacao(Consts.TERMINALNOME, Registro, Arquivo); db.ProcessarMarcacoes(TerminalDados.Grupo, marcacoes, rede.log); } }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { bool Result = base.LerMarcacoes(marcacoes, tipoimportacao); string nsr = "200"; string pis; int ano; int mes; int dia; int hora; int min; int sec; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; string ArquivoTemp = Path.GetTempFileName(); int Contador = 0; bioRep.SetSeekPosition(numeroRep, ProximoNsr); bool connect = Connect(TerminalDados.Indice); if (connect) { log.AddLog("PROCESSANDO MARCAÇÕES...", true); List <string> arquivo = new List <string>(); Wr.Classes.Files.ReadFile(ArquivoTemp, arquivo); while (bioRep.GetAttLogs(numeroRep, out nsr, out pis, out ano, out mes, out dia, out hora, out min, out sec)) { DateTime DataHora = new DateTime(ano, mes, dia, hora, min, sec); marcacoes.Add(pis, DataHora, Convert.ToInt32(nsr)); Contador++; Result = true; } } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); Connect(TerminalDados.Indice); //log.AddLog("INICIANDO IMPORTAÇÂO DE MARCAÇÔES"); DBApp bd = new DBApp(); int ultimonsr = bd.getLastNsr(TerminalDados.Indice); DateTime inicial = Convert.ToDateTime("01/01/2010"); DateTime final = DateTime.Now; DataTable table = new DataTable(); string lista = ""; if (Rep.LerAFD_ViaLista(TerminalDados.IP, TerminalDados.Porta, Convert.ToInt32(TerminalDados.SupervisorSenha), inicial.ToString("yyyyMMdd"), final.ToString("yyyyMMdd"), ref lista, ultimonsr, "|", ";")) { string[] registros = lista.Split(new string[] { ";" }, StringSplitOptions.None); string[] campos; foreach (string registro in registros) { campos = registro.Split(new string[] { "|" }, StringSplitOptions.None); string nsr = campos[0]; string tipo = campos[1]; if (tipo.Trim() == "3") { string data = campos[2]; string hora = campos[3]; string pis = campos[4]; DateTime datetime = Convert.ToDateTime(data.Substring(0, 2) + "/" + data.Substring(2, 2) + "/" + data.Substring(4, 4) + " " + hora.Substring(0, 2) + ":" + hora.Substring(2, 2)); marcacoes.Add(pis, datetime, Convert.ToInt32(nsr)); } } return(true); } else { LogErro(); return(false); } }
public ActionResult Create([Bind(Include = "MarcacaoID,DataMarcacoes,MedicoFK,PacienteFK,EspecialidadeFK")] Marcacoes marcacoes) { if (ModelState.IsValid) { //busca o id do utilizador autenticado var userid = User.Identity.GetUserId(); //iguala o id do paciente ao id do utilizador autenticado var user = (from r in db.Pacientes where r.ExternalId == userid select r.PacienteID).Single(); //valor do novo id da marcação, calculado a partir da contagem das marcações + 1 var marcId = db.Marcacoes.Count() + 1; //associa a MarcacaoID das marcacoes ao novo id marcacoes.MarcacaoID = marcId; //associa o PacienteFK ao user marcacoes.PacienteFK = user; //verifica se está algum médico na dropdown selecionado if (marcacoes.MedicoFK == 0) { TempData["notice"] = "Por favor, selecione um médico válido."; } else { db.Marcacoes.Add(marcacoes); db.SaveChanges(); return(RedirectToAction("Index")); } } ViewBag.EspecialidadeFK = new SelectList(db.Especialidades, "EspecialidadeID", "Designacao"); ViewBag.MedicoFK = new SelectList(db.Medicos, "MedicoID", "Nome", marcacoes.MedicoFK); ViewBag.PacienteFK = new SelectList(db.Pacientes, "PacienteID", "Nome", marcacoes.PacienteFK); return(View(marcacoes)); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { try { int NRegistrosLidos = 0; if (!File.Exists(FILE_PATH + FILE_CONFIGURATION)) { Files.WriteFile(FILE_PATH + FILE_CONFIGURATION, (new List <string>())); } bool Result = processStart("/co " + FILE_PATH, Args()); if (Result) { //int ProximoNsr = (new DBApp()).getLastNsr(TerminalDados.Indice) + 1; List <string> Arquivos = new List <string>(); List <string> Novo = new List <string>(); Files.DirSearch(FILE_PATH, "*.txt", Arquivos); foreach (string arquivo in Arquivos) { List <string> conteudo = new List <string>(); Files.ReadFile(arquivo, conteudo); foreach (string cLinha in conteudo) { AssepontoRep.Marcacoes.Marcacao mrc = new AssepontoRep.Marcacoes.Marcacao(); if (marcacoes.InterpretarRegistroAfd(cLinha, out mrc)) { if (mrc.Tipo == Marcacoes.TiposRegistroAfd.Marcacao) { marcacoes.Add(mrc); } } NRegistrosLidos++; } File.Delete(arquivo); } //if (marcacoes.Count == 0) //{ // log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); //} } else { log.AddLog(Consts.ERRO_ENVIO_COMANDO); } getLog(); return(Result); } catch (Exception ex) { log.AddLog(ex.Message); } return(false); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { Disconnect(TerminalDados.Indice); Connect(TerminalDados.Indice); List <string> lstrEventData; string[] split; DBApp bd = new DBApp(); int last = bd.getLastNsr(TerminalDados.Indice); uint uiNSR = Convert.ToUInt32(last == 0 ? 1 : last); try { this._objController.RequestTotalNSR(); System.Threading.Thread.Sleep(100); lstrEventData = this._objController.GetEventData(); split = lstrEventData[6].Split(new string[] { " : " }, StringSplitOptions.None); uint uiMaxNSR = Convert.ToUInt32(split[1]); log.AddLog(":: ATENÇÃO :: A IMPORTAÇÃO DESSE RELÓGIO PODE DEMORAR, NÃO FINALIZE"); log.AddLog(" ATÉ QUE TENHA TERMINADO ..."); log.AddLog("AGUARDE..."); System.Threading.Thread.Sleep(100); for (uint i = uiNSR; i <= uiMaxNSR; i++) { this._objController.RequestEventByNSR(i); int seg = 0; System.Threading.Thread.Sleep(100); EConnectionState state = EConnectionState.SendingData; while (state == EConnectionState.SendingData) { state = this._objController.GetConnectionState(); //System.Threading.Thread.Sleep(100); seg++; } if (state == EConnectionState.DataReceived) { this._objController.SetConnectionState(EConnectionState.Connected); System.Threading.Thread.Sleep(100); lstrEventData = this._objController.GetEventData(); if (lstrEventData == null) { throw new Exception("Evento não encontrado."); } int tipo = -1; for (int c = 0; c < lstrEventData.Count; c++) { if (lstrEventData[c].Contains("Tipo do Registro")) { split = lstrEventData[c].Split(new string[] { " : " }, StringSplitOptions.None); tipo = Convert.ToInt32(split[1]); break; } } Marcacoes.Marcacao marc; if (tipo == 3) { marc = new Marcacoes.Marcacao(); marc.Tipo = Marcacoes.TiposRegistroAfd.Marcacao; split = lstrEventData[7].Split(new string[] { " : " }, StringSplitOptions.None); string nsr = split[1]; marc.NSR = Convert.ToInt32(nsr); split = lstrEventData[9].Split(new string[] { " : " }, StringSplitOptions.None); string datetime = split[1].Trim(); split = lstrEventData[10].Split(new string[] { " : " }, StringSplitOptions.None); datetime = datetime + " " + split[1].Trim(); marc.DataHora = Convert.ToDateTime(datetime); split = lstrEventData[11].Split(new string[] { " : " }, StringSplitOptions.None); string pis = split[1].Replace(".", "").Replace("-", "").Trim(); marc.Pis = pis; marcacoes.Add(marc); } } } bd.setLastNsr(TerminalDados.Indice, (int)uiMaxNSR); bool retorno = (marcacoes.Count > 0); Disconnect(TerminalDados.Indice); return(retorno); } catch (Exception exError) { log.AddLog(Consts.ERRO_ENVIO_COMANDO); log.AddLog("Descrição ", true); log.AddLog(exError.Message); Disconnect(TerminalDados.Indice); return(false); } }
public bool KeyPass_ImportarMarcacoes(int Terminal, string TerminalNome, Marcacoes marcacoes) { bool Result = false; //DBApp db = new DBApp(); //int ProximoNsr = db.getLastNsr(Terminal) + 1; //int Contador = 0; //MRPRecord[] registrosMRP; //log.AddLog(Consts.INICIALIZANDO_IMPORTACAO_ARQUIVO); //if (KeyPass_Conectar()) //{ // try // { // _watchComm.RepositioningMRPRecordsPointer(ProximoNsr.ToString()); // registrosMRP = this._watchComm.InquiryMRPRecords(false, false, true, false); // while (registrosMRP != null) // { // foreach (MRPRecord registroMRP in registrosMRP) // { // if (registroMRP is MRPRecord_RegistrationMarkingPoint) // { // string Pis = ((MRPRecord_RegistrationMarkingPoint)registroMRP).Pis; // DateTime DataHora = ((MRPRecord_RegistrationMarkingPoint)registroMRP).DateTimeMarkingPoint; // int Nsr = Convert.ToInt32(((MRPRecord_RegistrationMarkingPoint)registroMRP).NSR); // marcacoes.Add(Pis, DataHora, Nsr); // Contador++; // if (Nsr > ProximoNsr) // ProximoNsr = Nsr; // } // } // registrosMRP = _watchComm.ConfirmationReceiptMRPRecords(); // } // if (Contador > 0) // { // string Arquivo = marcacoes.SaveToFile(); // log.AddLog(String.Format(Consts.ARQUIVO_GERADO, Arquivo)); // Result = true; // db.setLastNsr(Terminal, ProximoNsr); // } // else // { // log.AddLog(Consts.SEM_MARCACOES); // } // } // catch (Exception ex) // { // log.AddLog(ex.Message); // } // finally // { // KeyPass_Desconectar(); // } //} return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes) { Connect(TerminalDados.IP, TerminalDados.Porta); bool Result = false; int NRegistrosLidos = 0; StringBuilder PIS = new StringBuilder(11); StringBuilder DataHora = new StringBuilder(19); StringBuilder NSR = new StringBuilder(20); StringBuilder MensagemErro = new StringBuilder(256); //Marcacoes marcacoes = new Marcacoes(TerminalDados); log.AddLog(Consts.INICIALIZANDO_IMPORTACAO_ARQUIVO); REPZPM_DLL.ID_Comando = REPZPM_DLL.DLLREP_BuscaPonto(REPZPM_DLL.Handle, DataInicio: ("dd/MM/yyyy"), DataFim: ("dd/MM/yyyy")); if (REPZPM_DLL.ID_Comando > 0) { /*Retorna a quantidade de registros*/ NRegistros = REPZPM_DLL.DLLREP_TotalRetornos(REPZPM_DLL.Handle); log.AddLog(String.Format(Consts.TOTAL_MARCACOES, NRegistros)); if (NRegistros > 0) { for (int i = 1; i <= NRegistros; i++) { REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_RetornoPonto(REPZPM_DLL.Handle, i, PIS, DataHora, NSR); if (REPZPM_DLL.Retorno == 1) { marcacoes.Add(PIS.ToString(), Convert.ToDateTime(DataHora.ToString()), Convert.ToInt32(NSR.ToString())); log.AddLogUnformatted(PIS.ToString().PadRight(18) + DataHora + " " + NSR); NRegistrosLidos++; } else { REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_ObtemMensagemErro(REPZPM_DLL.Handle, MensagemErro, 1); log.AddLog(Convert.ToString(MensagemErro)); } } } else { log.AddLog(Consts.SEM_MARCACOES_NOVAS); } } Result = (NRegistrosLidos > 0); if (Result) { marcacoes.SaveToFile(); log.AddLogUnformatted(String.Format(Consts.ARQUIVO_GERADO, marcacoes.Arquivo)); log.AddLineBreak(); } else { log.AddLog(Consts.SEM_MARCACOES_NOVAS); } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { bool Result = false; int NRegistrosLidos = 0; Connect(); try { DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; if (!_rep.BuscarAFD(ProximoNsr)) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } else { string cLinha; while (_rep.LerAFD(out cLinha)) { AssepontoRep.Marcacoes.Marcacao mrc = new AssepontoRep.Marcacoes.Marcacao(); if (marcacoes.InterpretarRegistroAfd(cLinha, out mrc)) { if (mrc.Tipo == Marcacoes.TiposRegistroAfd.Marcacao) { marcacoes.Add(mrc); } } //if (Convert.ToInt32(cLinha.Substring(9, 1)) == (int)(Marcacoes.TiposRegistroAfd.Marcacao)) //{ // string PIS = cLinha.Substring(22, 12).Replace("\n", "").Replace("\t", "").Replace("\r", ""); // string DataHora = cLinha.Substring(10, 12); // string NSR = cLinha.Substring(0, 9); // marcacoes.Add(PIS, extrairDateTime(DataHora), Convert.ToInt32(NSR)); //} NRegistrosLidos++; } if (NRegistrosLidos == 0) { log.AddLog(Consts.ERRO_ENVIO_COMANDO); } if (marcacoes.Count == 0) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } Result = true; } } catch (Exception ex) { log.AddLog(ex.Message); Result = false; } finally { _rep.Desconectar(); } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { bool Result = base.LerMarcacoes(marcacoes, tipoimportacao); DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice) + 1; string ArquivoTemp = Path.GetTempFileName(); int Contador = 0; if (Connect(TerminalDados.Indice)) { int resultado = envioDll.LeCadastro(TerminalDados.IP, 5, ProximoNsr.ToString(), ArquivoTemp); if (resultado == 0) { List <string> arquivo = new List <string>(); Wr.Classes.Files.ReadFile(ArquivoTemp, arquivo); foreach (string S in arquivo) { string[] linhaReg = S.Split(';'); if (linhaReg[1] == Convert.ToInt32(Marcacoes.TiposRegistroAfd.Marcacao).ToString()) { string Pis = linhaReg[4]; try { DateTime DataHora = new DateTime( Convert.ToInt32(linhaReg[2].Substring(4, 4)), Convert.ToInt32(linhaReg[2].Substring(2, 2)), Convert.ToInt32(linhaReg[2].Substring(0, 2)), Convert.ToInt32(linhaReg[3].Substring(0, 2)), Convert.ToInt32(linhaReg[3].Substring(2, 2)), 0 ); int Nsr = Convert.ToInt32(linhaReg[0]); marcacoes.Add(Pis, DataHora, Nsr); Contador++; Result = true; } catch { log.AddLog(S); Result = false; } } } File.Delete(ArquivoTemp); Disconnect(TerminalDados.Indice); } else { Disconnect(TerminalDados.Indice); LogMensagem(resultado); } } return(Result); }
public bool Dimep_ImportarMarcacoes(int Terminal, string TerminalNome, Marcacoes marcacoes) { bool Result = false; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(Terminal) + 1; int Contador = 0; MRPRecord[] registrosMRP; log.AddLog(AssepontoRep.Consts.INICIALIZANDO_IMPORTACAO_ARQUIVO); if (Dimep_Conectar()) { try { _watchComm.RepositioningMRPRecordsPointer(ProximoNsr.ToString()); registrosMRP = this._watchComm.InquiryMRPRecords(false, false, true, false); while (registrosMRP != null) { foreach (MRPRecord registroMRP in registrosMRP) { if (registroMRP is MRPRecord_RegistrationMarkingPoint) { string Pis = ((MRPRecord_RegistrationMarkingPoint)registroMRP).Pis; DateTime DataHora = ((MRPRecord_RegistrationMarkingPoint)registroMRP).DateTimeMarkingPoint; int Nsr = Convert.ToInt32(((MRPRecord_RegistrationMarkingPoint)registroMRP).NSR); marcacoes.Add(Pis, DataHora, Nsr); Contador++; if (Nsr > ProximoNsr) { ProximoNsr = Nsr; } } } registrosMRP = _watchComm.ConfirmationReceiptMRPRecords(); } if (Contador > 0) { string Arquivo = marcacoes.SaveToFile(); log.AddLog(String.Format(AssepontoRep.Consts.ARQUIVO_GERADO, Arquivo)); Result = true; db.setLastNsr(Terminal, ProximoNsr); } else { log.AddLog(AssepontoRep.Consts.SEM_MARCACOES); } } catch (Exception ex) { log.AddLog(ex.Message); } finally { Dimep_Desconectar(); } } return(Result); }
private bool RecebeMarcacoesTCP(Marcacoes marcacoes) { bool Result = false; DBApp db = new DBApp(); int NSR = db.getLastNsr(TerminalDados.Indice); if (NSR == 0) { NSR = 1; } string mensagem = "!06,R,004,"; string CRC = CalculaCRC(mensagem, CalculaNsr(NSR)); bool primeiro = true; TcpClient sock = new TcpClient(); NetworkStream stream; sock.Connect(TerminalDados.IP, TerminalDados.Porta); stream = sock.GetStream(); EnviaMensagem(mensagem.Substring(0, 10), stream); EnviaNSR(NSR, stream); EnviaMensagem(",", stream); EnviaMensagem(CRC, stream); bool recolhe = true; log.AddLog(string.Format(Consts.INICIALIZANDO_IMPORTACAO_ARQUIVO_NSR, NSR)); while (recolhe) { Application.DoEvents(); if (sock.Available > 9) { byte[] comeco = new byte[10]; stream.Read(comeco, 0, 10); string cabecalho = ConverteMensagem(comeco); if (cabecalho == "!06,I,002,") { stream.Read(new byte[sock.Available], 0, sock.Available); break; } int quantidadeBytes = Convert.ToInt32(cabecalho.Substring(6, 3)); byte[] byMarcacoes = new byte[quantidadeBytes]; while (sock.Available <= quantidadeBytes) { } stream.Read(byMarcacoes, 0, byMarcacoes.Length); log.AddLog(CortaMensagem(byMarcacoes, marcacoes, out NSR).ToString() + " restantes"); byte[] limpa = new byte[3]; stream.Read(limpa, 0, limpa.Length); EnviaMensagem("!06,I,002,06,78", stream); primeiro = false; Application.DoEvents(); } } if (Cancelar) { log.AddLog("CANCELADO"); } else if (primeiro) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } stream.Close(); sock.Close(); return(marcacoes.Count > 0); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { Connect(TerminalDados.IP, TerminalDados.Porta); bool Result = false; int NRegistrosLidos = 0; DateTime DataInicial; DateTime DataFinal; StringBuilder PIS = new StringBuilder(11); StringBuilder DataHora = new StringBuilder(19); StringBuilder NSR = new StringBuilder(20); StringBuilder MensagemErro = new StringBuilder(256); //Marcacoes marcacoes = new Marcacoes(TerminalDados); if (!getPeriodo(out DataInicial, out DataFinal)) { return(false); } REPZPM_DLL.ID_Comando = REPZPM_DLL.DLLREP_BuscaPonto(REPZPM_DLL.Handle, DataInicial.ToString("dd/MM/yyyy"), DataFinal.ToString("dd/MM/yyyy")); if (REPZPM_DLL.ID_Comando > 0) { /*Retorna a quantidade de registros*/ NRegistros = REPZPM_DLL.DLLREP_TotalRetornos(REPZPM_DLL.Handle); log.AddLog(String.Format(Consts.MARCACOES_A_PROCESSAR, NRegistros)); if (NRegistros > 0) { for (int i = 1; i <= NRegistros; i++) { REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_RetornoPonto(REPZPM_DLL.Handle, i, PIS, DataHora, NSR); if (REPZPM_DLL.Retorno == 1) { marcacoes.Add(PIS.ToString(), Convert.ToDateTime(DataHora.ToString()), Convert.ToInt32(NSR.ToString())); log.AddLogUnformatted(PIS.ToString().PadRight(18) + DataHora + " " + NSR); NRegistrosLidos++; } else { REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_ObtemMensagemErro(REPZPM_DLL.Handle, MensagemErro, 1); log.AddLog(Convert.ToString(MensagemErro)); } } } else { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } } Result = (NRegistrosLidos > 0); if (REPZPM_DLL.ID_Comando == -2) { log.AddLog("Erro de comunicação!"); } else { if (Result) { marcacoes.SaveToFile(); log.AddLogUnformatted(String.Format(Consts.ARQUIVO_GERADO, marcacoes.Arquivo)); log.AddLineBreak(); } else { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, TipoImportacaoMarcacoes tipoimportacao) { base.LerMarcacoes(marcacoes, tipoimportacao); bool Result = false; DBApp db = new DBApp(); int ProximoNsr = db.getLastNsr(TerminalDados.Indice); int NRegistrosLidos = 0, statusColeta = 0, nsr = 0, ret = 0, tentativas = 0; bool recebeuUltimoBilhete = false; string dadosRegistro = string.Empty; if (Connect(0)) { try { nsr = ProximoNsr; while (!recebeuUltimoBilhete) { nsr++; ret = innerRep.SolicitarRegistroNsr(nsr); //string UltimoRegistro = innerRep.LerNumUltimoNsr(); if (ret == 0) { statusColeta = innerRep.LerStatusColeta(); tentativas = 0; while (statusColeta < 2 && tentativas < 1000) { Thread.Sleep(10); Application.DoEvents(); Thread.Sleep(10); statusColeta = innerRep.LerStatusColeta(); tentativas++; } if ((statusColeta == (int)Sdk_Inner_Rep.InnerRepPlusSDK.StatusLeitura.FINALIZADA_COM_ULTIMO_REGISTRO) || (statusColeta == (int)Sdk_Inner_Rep.InnerRepPlusSDK.StatusLeitura.FINALIZADA_COM_REGISTRO)) { string numSerie = innerRep.LerNumSerieRep(); statusColeta = innerRep.LerResultadoColeta(); dadosRegistro = innerRep.LerRegistroLinha(); if (dadosRegistro != "" && dadosRegistro != null) { AssepontoRep.Marcacoes.Marcacao mrc = new AssepontoRep.Marcacoes.Marcacao(); if (marcacoes.InterpretarRegistroAfd(dadosRegistro, out mrc)) { if (mrc.Tipo == Marcacoes.TiposRegistroAfd.Marcacao) { marcacoes.Add(mrc); } } } NRegistrosLidos++; } if ((statusColeta == (int)Sdk_Inner_Rep.InnerRepPlusSDK.StatusLeitura.FINALIZADA_SEM_REGISTRO) || (statusColeta == (int)Sdk_Inner_Rep.InnerRepPlusSDK.StatusLeitura.FINALIZADA_COM_ULTIMO_REGISTRO)) { recebeuUltimoBilhete = true; } } } if (marcacoes.Count == 0) { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } innerRep.FinalizarLeitura(); Result = true; } catch (Exception ex) { log.AddLog(ex.Message); } } return(Result); }
public override bool LerMarcacoes(Marcacoes marcacoes, AssepontoRep.Bridge.TipoImportacaoMarcacoes tipoimportacao) { Connect(TerminalDados.Indice); bool Result = false; int NRegistrosLidos = 0; DateTime DataInicial; DateTime DataFinal; StringBuilder PIS = new StringBuilder(11); StringBuilder DataHora = new StringBuilder(19); StringBuilder NSR = new StringBuilder(20); StringBuilder MensagemErro = new StringBuilder(256); //Marcacoes marcacoes = new Marcacoes(TerminalDados); if (!getPeriodo(out DataInicial, out DataFinal)) { return(false); } //REPZPM_DLL.ID_Comando = REPZPM_DLL.DLLREP_BuscaPonto(REPZPM_DLL.Handle, DataInicial.ToString("dd/MM/yyyy"), DataFinal.ToString("dd/MM/yyyy")); //if (REPZPM_DLL.ID_Comando == -4) //{ int count = 1; do { REPZPM_DLL.ID_Comando = REPZPM_DLL.DLLREP_BuscaPonto(REPZPM_DLL.Handle, DataInicial.ToString("dd/MM/yyyy"), DataFinal.ToString("dd/MM/yyyy")); if (REPZPM_DLL.ID_Comando == -4) { int timeout = REPZPM_DLL.DLLREP_LeTimeout(REPZPM_DLL.Handle); if (timeout != -1) { REPZPM_DLL.DLLREP_DefineTimeout(REPZPM_DLL.Handle, (timeout * (count + 1))); } else { REPZPM_DLL.DLLREP_DefineTimeout(REPZPM_DLL.Handle, 100000); } } count++; }while (REPZPM_DLL.ID_Comando == -4 && count <= 11); //} if (REPZPM_DLL.ID_Comando >= 0) { /*Retorna a quantidade de registros*/ NRegistros = REPZPM_DLL.DLLREP_TotalRetornos(REPZPM_DLL.Handle); log.AddLog(String.Format(Consts.MARCACOES_A_PROCESSAR, NRegistros)); if (NRegistros > 0) { for (int i = 1; i <= NRegistros; i++) { REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_RetornoPonto(REPZPM_DLL.Handle, i, PIS, DataHora, NSR); if (REPZPM_DLL.Retorno > 0) { marcacoes.Add(PIS.ToString(), Convert.ToDateTime(DataHora.ToString()), Convert.ToInt32(NSR.ToString())); log.AddLogUnformatted(PIS.ToString().PadRight(18) + DataHora + " " + NSR); NRegistrosLidos++; } else { //REPZPM_DLL.Retorno = REPZPM_DLL.DLLREP_ObtemMensagemErro(REPZPM_DLL.Handle, MensagemErro, 1); //log.AddLog(Convert.ToString(MensagemErro)); int ret = REPZPM_DLL.DLLREP_ObtemCodigoErro(REPZPM_DLL.Handle, REPZPM_DLL.Retorno); log.AddLog(REPZPM_DLL.Trata_Retorno_DLL(ret)); } } } else { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } Result = (NRegistrosLidos > 0); if (Result) { marcacoes.SaveToFile(); log.AddLogUnformatted(String.Format(Consts.ARQUIVO_GERADO, marcacoes.Arquivo)); log.AddLineBreak(); } else { log.AddLog(Consts.MARCACOES_NAO_HA_NOVAS); } } else { Result = false; log.AddLog(REPZPM_DLL.Trata_Retorno_DLL(REPZPM_DLL.ID_Comando)); } Disconnect(TerminalDados.Indice); return(Result); }
private int CortaMensagem(byte[] vetorBytes, Marcacoes marcacoes, out int intNSR) { string NFR = ConverteMensagem(vetorBytes, vetorBytes.Length - 17, 17); string restantesStr = ConverteMensagem(vetorBytes, 1, 8); int restantesInt = Convert.ToInt32(restantesStr, 16); intNSR = 0; for (int i = 9; i < vetorBytes.Length;) { intNSR = (vetorBytes[i + 3] << 24) | (vetorBytes[i + 2] << 16) | (vetorBytes[i + 1] << 8) | vetorBytes[i]; string NSR = Convert.ToString(intNSR); //string NSR = Convert.ToString((vetorBytes[i + 3] << 24) | (vetorBytes[i + 2] << 16) | (vetorBytes[i + 1] << 8) | vetorBytes[i]); if (NSR.Length < 9) { for (int j = NSR.Length; j < 9; j++) { NSR = "0" + NSR; } } i = i + 4; string dia = Convert.ToInt32(BitConverter.ToString(vetorBytes, i, 1), 16).ToString(); if (dia.Length == 1) { dia = "0" + dia; } string mes = Convert.ToInt32(BitConverter.ToString(vetorBytes, i + 1, 1), 16).ToString(); if (mes.Length == 1) { mes = "0" + mes; } string ano = Convert.ToInt32(BitConverter.ToString(vetorBytes, i + 2, 1), 16).ToString(); if (ano.Length == 1) { ano = "200" + ano; } if (ano.Length == 2) { ano = "20" + ano; } string datafinal = dia + "/" + mes + "/" + ano; i = i + 3; string hora = Convert.ToInt32(BitConverter.ToString(vetorBytes, i, 1), 16).ToString(); if (hora.Length == 1) { hora = "0" + hora; } string minuto = Convert.ToInt32(BitConverter.ToString(vetorBytes, i + 1, 1), 16).ToString(); if (minuto.Length == 1) { minuto = "0" + minuto; } string segundo = Convert.ToInt32(BitConverter.ToString(vetorBytes, i + 2, 1), 16).ToString(); if (segundo.Length == 1) { segundo = "0" + segundo; } string horariofinal = String.Format("{0}:{1}", hora, minuto); i = i + 3; string PIS = ConverteMensagem(vetorBytes, i, 12); i = i + 12; marcacoes.Add(PIS, Convert.ToDateTime(datafinal + horariofinal), Convert.ToInt32(NSR)); if (i >= (vetorBytes.Length - 17)) { return(restantesInt); } } return(restantesInt); }