Esempio n. 1
0
    protected void btnAtualizar_Click(object sender, ImageClickEventArgs e)
    {
        string cPIS;
        string cNome;
        int    nCodigo;
        string cSenha;
        string cBarras;
        int    nRFID;
        int    priv;
        bool   lOK;
        int    id = Convert.ToInt32(((sender as ImageButton).Parent as GridViewDataItemTemplateContainer).KeyValue);
        TBPontoEletronicoModel pontoEletronico = new TBPontoEletronicoModel();

        pontoEletronico = pontoEletronicoSrv.GetPontoEletronicoByID(id);

        try
        {
            int ok   = 0;
            int erro = 0;
            if (conexao(true, pontoEletronico))
            {
                List <TBUsuarioInfo> usuarios = pontoEletronicoSrv.GetUsuariosImportacao(id, Session["IDEmpresa"].ToString());
                foreach (var usuario in usuarios)
                {
                    cPIS    = usuario.PIS_GERADO;
                    cNome   = usuario.DSUsuario;
                    nCodigo = 0;
                    cSenha  = string.Empty;
                    cBarras = string.Empty;
                    nRFID   = 0;
                    priv    = 0;
                    _rep.GravarUsuario(Convert.ToInt64(cPIS), cNome, nCodigo, cSenha, cBarras, nRFID, priv, out lOK);
                    string log;
                    if (!_rep.GetLastLog(out log))
                    {
                        erro++;
                        log = "";
                    }
                    else
                    {
                        ok++;
                    }
                }
            }
            _rep.Desconectar();
            this.Page.RegisterStartupScript("MSG", @"<script language='javascript'> alert('" + ok + ": atualizados, " + erro + ": não atualizados.');</script>");
        }
        catch (Exception ex)
        {
            this.Page.RegisterStartupScript("MSG", @"<script language='javascript'> alert('Erro ao atualizar Coloaboradores');</script>");
        }
    }
Esempio n. 2
0
 public void ConnectLoop()
 {
     int tries = 10;
     Console.WriteLine("Tentando se conectar {0} vezes com REP no endereço {1}:{2}", tries, Config.repIP, Config.repPort);
     RepCid rep = new RepCid();
     int idle = 0;
     for (int i = 0; i < tries; i++)
     {
         rep.iDClassLogin = Config.repLogin;
         rep.iDClassPassword = Config.repSenha;
         rep.ConnectTimeout = 15000;
         var status = rep.Conectar(Config.repIP, Config.repPort);
         rep.Desconectar();
         switch (status)
         {
             case RepCid.ErrosRep.OK:
                 break;
             case RepCid.ErrosRep.ErroNaoOcioso:
                 Console.WriteLine("Tentativa {0}: não ocioso", i);
                 idle++;
                 break;
             default:
                 Assert.Fail("Tentativa {0}: erro inválido ({1})", i, status.ToString());
                 break;
         }
     }
     Console.WriteLine("Quantidade de tentativas com REP ocupado: {0}", idle);
 }
Esempio n. 3
0
        public void Config_NetworkSet()
        {
            bool   gravou;
            string ip = repIP; // "192.168.0.147";

            // ATENÇÃO: se este teste falhar parcialmente todos os demais deve ser o ultimo teste a ser executado
            if (rep.GravarConfigRede(ip, "255.255.0.0", "192.168.0.1", 443, out gravou) && gravou)
            {
                Console.WriteLine("Nova configuração gravada");
                rep.Desconectar();
                Thread.Sleep(ip == repIP ? 5000 : 30000); // tempo para o ip mudar...
                if (rep.Conectar(ip, 443) == RepCid.ErrosRep.OK)
                {
                    Console.WriteLine("Conectado ao novo IP");
                    if (rep.GravarConfigRede(repIP, "255.255.254.0", "192.168.0.1", 443, out gravou) && gravou)
                    {
                        Thread.Sleep(ip == repIP ? 5000 : 30000); // tempo para o ip mudar...
                        Console.WriteLine("Voltou ao IP padrão");
                    }
                    else
                    {
                        Assert.Fail("Erro ao gravar configurações antiga de rede");
                    }
                }
                else
                {
                    Assert.Fail("Erro ao conectar o REP no novo IP:" + ip);
                }
            }
            else
            {
                Assert.Fail("Erro ao mudar configuração de rede");
            }
        }
Esempio n. 4
0
        public void ConnectLoop()
        {
            int tries = 10;

            Console.WriteLine("Tentando se conectar {0} vezes com REP no endereço {1}:{2}", tries, Config.repIP, Config.repPort);
            RepCid rep  = new RepCid();
            int    idle = 0;

            for (int i = 0; i < tries; i++)
            {
                rep.iDClassLogin    = Config.repLogin;
                rep.iDClassPassword = Config.repSenha;
                rep.ConnectTimeout  = 15000;
                var status = rep.Conectar(Config.repIP, Config.repPort);
                rep.Desconectar();
                switch (status)
                {
                case RepCid.ErrosRep.OK:
                    break;

                case RepCid.ErrosRep.ErroNaoOcioso:
                    Console.WriteLine("Tentativa {0}: não ocioso", i);
                    idle++;
                    break;

                default:
                    Assert.Fail("Tentativa {0}: erro inválido ({1})", i, status.ToString());
                    break;
                }
            }
            Console.WriteLine("Quantidade de tentativas com REP ocupado: {0}", idle);
        }
Esempio n. 5
0
        //public static RepCid ConectarREP(string ip, int port, uint @passcode, string user, string password)
        //{
        //    RepCid rep = null;
        //    if (rep == null)
        //    {
        //        rep = new RepCid();
        //        rep.iDClassLogin = user;
        //        rep.iDClassPassword = password;
        //        rep.iDClassPort = 8000;
        //        Controlid.RepCid.ErrosRep status = rep.Conectar(ip, port, @passcode);
        //        string Retorno = status == RepCid.ErrosRep.OK ? "Conectado" : "Erro ao Conectar";
        //    }
        //    return rep;
        //}

        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();

            LogErro(_rep.Conectar(TerminalDados.IP, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Esempio n. 6
0
        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();
            //string con = "";
            //if (TerminalDados.IP.Replace(" ", "").Contains("dns:"))
            //{
            //    IPAddress[] ip = Dns.GetHostAddresses(TerminalDados.IP.Replace(" ", "").Replace("dns:", ""));
            //    con = ip[0].ToString();
            //}
            //else
            //    con = TerminalDados.IP;

            LogErro(_rep.Conectar(TerminalDados.IP, TerminalDados.Porta, 0));//, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Esempio n. 7
0
        public override bool Connect(int Terminal)
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            Controlid.RepCid.ErrosRep status;
            bool gravou;
            bool Retorno;

            _rep = new RepCid();
            _rep.iDClassLogin    = TerminalDados.OperadorLogin;
            _rep.iDClassPassword = TerminalDados.OperadorSenha;
            _rep.iDClassPort     = TerminalDados.Porta;
            status  = _rep.Conectar(TerminalDados.IP, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo));
            Retorno = status == RepCid.ErrosRep.OK ? true : false;

            LogErro(status);
            return(Retorno);
        }
Esempio n. 8
0
        private void Connect()
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();
            string con = "";

            if (TerminalDados.IP.Contains("www."))
            {
                IPAddress[] ip = Dns.GetHostAddresses(TerminalDados.IP);
                con = ip[0].ToString();
            }
            else
            {
                con = TerminalDados.IP;
            }

            LogErro(_rep.Conectar(con, TerminalDados.Porta, Convert.ToUInt32(string.IsNullOrEmpty(TerminalDados.SupervisorCodigo) ? "0" : TerminalDados.SupervisorCodigo)));
        }
Esempio n. 9
0
        // Tenta efetuar a conexão e define a váriável '_rep' que será encapsulada
        private bool Connect(bool lShowOK)
        {
            if (_rep != null)
            {
                _rep.Desconectar();
            }

            _rep = new RepCid();

            string ip = txtIP.Text;

            if (_rep.Conectar(ip, (int)nudPort.Value, (uint)nudPassCode.Value) == RepCid.ErrosRep.OK)
            {
                if (!lShowOK)
                {
                    // Se não for para exibir os dialogos de confirmação de conexão já retorna a instancia da conexão
                    return(true);
                }
                string sn;
                uint   tam_bobina;
                uint   restante_bobina;
                uint   uptime;
                uint   cortes;
                uint   papel_acumulado;
                uint   nsr_atual;
                if (_rep.LerInfo(out sn, out tam_bobina, out restante_bobina, out uptime, out cortes, out papel_acumulado, out nsr_atual))
                {
                    if (sn == null)
                    {
                        sn = "?";
                    }
                }
                else
                {
                    sn = "(falhou)";
                }

                if (txtIP.Text != TesteRepCid.Properties.Settings.Default.IP ||
                    nudPort.Value != TesteRepCid.Properties.Settings.Default.Porta)
                {
                    if (MessageBox.Show("Conexão Aceita\r\n" +
                                        "SN: " + sn + "\r\n" +
                                        "NSR: " + nsr_atual.ToString() + "\r\n" +
                                        "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m\r\n" +
                                        "\r\nDeseja gravar esta conexão", "REP", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                    {
                        Settings.Default.IP       = txtIP.Text;
                        Settings.Default.Porta    = (int)nudPort.Value;
                        Settings.Default.PassCode = (uint)nudPassCode.Value;
                        Settings.Default.Save();
                    }
                }
                else
                {
                    MessageBox.Show("Sucesso na conexão com o REP!\r\n\r\n" +
                                    "SN: " + sn + "\r\n" +
                                    "NSR: " + nsr_atual.ToString() + "\r\n" +
                                    "Papel restante: " + (restante_bobina / 10.0f).ToString("0.0") + " m",
                                    "REP", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Conexão com o REP não está funcionando", "REP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
Esempio n. 10
0
		private void btnSave_Click(object sender, EventArgs e)
		{
			string cErro = "";
			try
			{
				_rep = ((frmMain)this.Owner).REP;
				if (_rep != null)
				{
					Button btn = (Button)sender;

					if (btn.Name == btnHorario.Name)
					{
						// Data e Horario de Verão
						if (!_rep.GravarDataHora(DateTime.Parse(txtData.Text).Add(TimeSpan.Parse(txtHora.Text))))
							cErro += "\r\nErro ao atualizar a Data e Hora";

						int iano = 0, imes = 0, idia = 0;
						int fano = 0, fmes = 0, fdia = 0;

						if (chkVeraoIni.Checked)
						{
							iano = dtpVeraoInicio.Value.Year;
							imes = dtpVeraoInicio.Value.Month;
							idia = dtpVeraoInicio.Value.Day;
						}
						if (chkVeraoFim.Checked)
						{
							fano = dtpVeraoFim.Value.Year;
							fmes = dtpVeraoFim.Value.Month;
							fdia = dtpVeraoFim.Value.Day;
						}

						if (hVeraoIAno != iano ||
							hVeraoIMes != imes ||
							hVeraoIDia != idia ||
							hVeraoFAno != fano ||
							hVeraoFMes != fmes ||
							hVeraoFDia != fdia)
						{
							bool gravou;
							if (!_rep.GravarConfigHVerao(iano, imes, idia,
								fano, fmes, fdia, out gravou) || !gravou)
								cErro += "\r\nErro ao registrar o Horário de Verão";
						}
					}
					else if (btn.Name == btnEmpresa.Name)
					{
						// Empregador (documento é só os digitos)
						//  CPF: 19221149870    => 11 digitos
						// CNPJ: 05343346000106 => 14 digitos
						// ------12345678901234

						// CIDFS.h (portaria)
						int nTipo = 0;
						if (txtCPFCNPJ.Text.Length == 14)
							nTipo = 1; // CNPJ
						else if (txtCPFCNPJ.Text.Length == 11)
							nTipo = 2; // CPF
						else
							cErro += "\r\nNumero de documento invalido (não é CPF e nem CNPJ)";

						bool gravou;
						if (nTipo > 0 && !(_rep.GravarEmpregador(txtCPFCNPJ.Text, nTipo, txtCEI.Text, txtRazaoSocial.Text, txtEndereco.Text, out gravou) && gravou))
							cErro += "\r\nErro ao atualizar os dados de Empregador";
					}

					else if (btn.Name == btnRede.Name)
					{
						// Ethernet
						bool gravou;
						if (!_rep.GravarConfigRede(txtIP.Text, txtMascara.Text, txtGateway.Text, Convert.ToUInt16(nudPort.Value), out gravou) || !gravou)
							cErro += "\r\nErro ao atualizar as configurações de Rede";
					}
				}
			}
			catch (Exception ex)
			{
				cErro += "\r\n" + "ERRO:" + ex.Message;
			}
			_rep.Desconectar();

			if (cErro != "")
				MessageBox.Show("Hove erros ao registrar as configurações:" + cErro, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
			else
				MessageBox.Show("REP ATUALIZADO", "Configurações", MessageBoxButtons.OK, MessageBoxIcon.Information);
		}
Esempio n. 11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataRow row;
            int     nTotal = 0;

            for (int i = 0; i < tbUsuarios.Rows.Count; i++)
            {
                row = tbUsuarios.Rows[i];
                if (row.RowState == DataRowState.Deleted || row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
                {
                    nTotal++;
                }
            }
            if (nTotal == 0)
            {
                return;
            }

            frmMain m = (frmMain)this.Owner;

            stProgress.Value   = 0;
            stProgress.Maximum = nTotal;
            stProgress.Visible = true;

            nTotal = 0;
            bool   lOK;
            RepCid _rep = m.REP;

            string cPIS;
            string cNome;
            int    nCodigo;
            string cSenha;
            string cBarras;
            int    nRFID;
            int    priv;

            for (int i = 0; i < tbUsuarios.Rows.Count; i++)
            {
                row = tbUsuarios.Rows[i];
                if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added)
                {
                    stInfo.Text      = "Gravando PIS: " + row["PIS"].ToString();
                    stProgress.Value = ++nTotal;

                    cPIS  = row["PIS"].ToString();
                    cNome = (string)row["Nome"];

                    if (cPIS == "" || cNome == "")
                    {
                        row.Delete();
                        i--;
                        continue;
                    }

                    if (row["Codigo"] != DBNull.Value)
                    {
                        nCodigo = Convert.ToInt32(row["Codigo"]);
                    }
                    else
                    {
                        nCodigo = 0;
                    }

                    if (row["Senha"] != DBNull.Value)
                    {
                        cSenha = row["Senha"].ToString();
                    }
                    else
                    {
                        cSenha = "";
                    }

                    if (row["Barras"] != DBNull.Value)
                    {
                        cBarras = row["Barras"].ToString();
                    }
                    else
                    {
                        cBarras = "";
                    }

                    if (row["rfID"] != DBNull.Value)
                    {
                        nRFID = Convert.ToInt32(row["rfID"]);
                    }
                    else
                    {
                        nRFID = 0;
                    }

                    if (row["PRIV"] != DBNull.Value)
                    {
                        priv = Convert.ToByte(row["PRIV"]);
                    }
                    else
                    {
                        priv = 0;
                    }

                    _rep.GravarUsuario(Convert.ToInt64(cPIS), cNome, nCodigo, cSenha, cBarras, nRFID, priv, out lOK);
                    string log;
                    if (!_rep.GetLastLog(out log))
                    {
                        log = "";
                    }
                    stInfo.Text += " OK " + log;

                    row.AcceptChanges();
                    Application.DoEvents();
                }
                else if (row.RowState == DataRowState.Deleted)
                {
                    row.RejectChanges();
                    if (_rep.RemoverUsuario(Convert.ToInt64(row["PIS"]), out lOK))
                    {
                        stProgress.Value = ++nTotal;
                        string log;
                        if (!_rep.GetLastLog(out log))
                        {
                            log = "";
                        }
                        stInfo.Text += " REMOVIDO " + log;
                        row.Delete();
                        row.AcceptChanges();
                        i--;
                    }
                }
            }

            _rep.Desconectar();

            stInfo.Text = "Atualizado " + nTotal + " usuário" + (nTotal > 0 ? "s" : "");
            if (nTotal < stProgress.Maximum)
            {
                stInfo.Text += " Erros: " + (stProgress.Maximum - nTotal);
            }
            else
            {
                stProgress.Visible = false;
            }
        }
Esempio n. 12
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string cErro = "";

            try
            {
                _rep = ((frmMain)this.Owner).REP;
                if (_rep != null)
                {
                    Button btn = (Button)sender;

                    if (btn.Name == btnHorario.Name)
                    {
                        // Data e Horario de Verão
                        if (!_rep.GravarDataHora(DateTime.Parse(txtData.Text).Add(TimeSpan.Parse(txtHora.Text))))
                        {
                            cErro += "\r\nErro ao atualizar a Data e Hora";
                        }

                        int iano = 0, imes = 0, idia = 0;
                        int fano = 0, fmes = 0, fdia = 0;

                        if (chkVeraoIni.Checked)
                        {
                            iano = dtpVeraoInicio.Value.Year;
                            imes = dtpVeraoInicio.Value.Month;
                            idia = dtpVeraoInicio.Value.Day;
                        }
                        if (chkVeraoFim.Checked)
                        {
                            fano = dtpVeraoFim.Value.Year;
                            fmes = dtpVeraoFim.Value.Month;
                            fdia = dtpVeraoFim.Value.Day;
                        }

                        if (hVeraoIAno != iano ||
                            hVeraoIMes != imes ||
                            hVeraoIDia != idia ||
                            hVeraoFAno != fano ||
                            hVeraoFMes != fmes ||
                            hVeraoFDia != fdia)
                        {
                            bool gravou;
                            if (!_rep.GravarConfigHVerao(iano, imes, idia,
                                                         fano, fmes, fdia, out gravou) || !gravou)
                            {
                                cErro += "\r\nErro ao registrar o Horário de Verão";
                            }
                        }
                    }
                    else if (btn.Name == btnEmpresa.Name)
                    {
                        // Empregador (documento é só os digitos)
                        //  CPF: 19221149870    => 11 digitos
                        // CNPJ: 05343346000106 => 14 digitos
                        // ------12345678901234

                        // CIDFS.h (portaria)
                        int nTipo = 0;
                        if (txtCPFCNPJ.Text.Length == 14)
                        {
                            nTipo = 1;                             // CNPJ
                        }
                        else if (txtCPFCNPJ.Text.Length == 11)
                        {
                            nTipo = 2;                             // CPF
                        }
                        else
                        {
                            cErro += "\r\nNumero de documento invalido (não é CPF e nem CNPJ)";
                        }

                        bool gravou;
                        if (nTipo > 0 && !(_rep.GravarEmpregador(txtCPFCNPJ.Text, nTipo, txtCEI.Text, txtRazaoSocial.Text, txtEndereco.Text, out gravou) && gravou))
                        {
                            cErro += "\r\nErro ao atualizar os dados de Empregador";
                        }
                    }

                    else if (btn.Name == btnRede.Name)
                    {
                        // Ethernet
                        bool gravou;
                        if (!_rep.GravarConfigRede(txtIP.Text, txtMascara.Text, txtGateway.Text, Convert.ToUInt16(nudPort.Value), out gravou) || !gravou)
                        {
                            cErro += "\r\nErro ao atualizar as configurações de Rede";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                cErro += "\r\n" + "ERRO:" + ex.Message;
            }
            _rep.Desconectar();

            if (cErro != "")
            {
                MessageBox.Show("Hove erros ao registrar as configurações:" + cErro, "ERRO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("REP ATUALIZADO", "Configurações", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }