Ejemplo n.º 1
0
        private void preencher_terminais()
        {
            ListViewItem item;
            //DBApp db = new DBApp();
            //SqlCommand comm = db.Conn.CreateCommand();

            //comm.CommandText = "SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_IND FROM Terminais ORDER BY TRM_DESCRICAO";
            //SqlDataReader reader = comm.ExecuteReader();

            DBApp         db     = new DBApp();
            SqlDataReader reader = db.getReader("SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_IND FROM Terminais ORDER BY TRM_DESCRICAO");

            listRelogios.Items.Clear();

            while (reader.Read())
            {
                item      = new ListViewItem();
                item.Text = reader["TRM_DESCRICAO"].ToString().Trim();
                item.SubItems.Add(reader["TRM_IP"].ToString().Trim());
                item.SubItems.Add(reader["TRM_PORTA"].ToString().Trim());
                item.SubItems.Add(reader["TRM_IND"].ToString());
                item.ImageIndex = 0;
                listRelogios.Items.Add(item);
            }

            reader.Close();
            db.closeConnection();
        }
Ejemplo n.º 2
0
        public static bool EnviarFuncionariosSelecao(int Terminal, Principal form, ListView listFuncionarios, TextBox edLog)
        {
            if (listFuncionarios.SelectedIndices.Count == 0)
            {
                return(false);
            }

            bool Ok = false;

            Types.Terminal TerminalDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);

            Rede rede = new Rede(TerminalDados.IP, edLog);

            if (!rede.Gertec_Conectar())
            {
                return(Ok);
            }

            if (listFuncionarios.SelectedIndices.Count > 1)
            {
                rede.log.AddLog(String.Format(Consts.FUNCIONARIOS_ENVIANDO, listFuncionarios.SelectedIndices.Count));
            }

            form.CANCELAR = false;

            for (int i = 0; i <= listFuncionarios.SelectedIndices.Count - 1; i++)
            {
                int    index     = listFuncionarios.SelectedIndices[i];
                string EnviadoEm = listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_ENVIADOEM].Text;

                if (EnviadoEm != String.Empty)
                {
                    rede.log.AddLog(String.Format(Consts.PIS_JA_EXISTE, listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_PIS].Text));
                }
                else
                {
                    int Funcionario = Convert.ToInt32(listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_IND].Text);

                    if (EnviarFuncionario(db, rede, Terminal, Funcionario))
                    {
                        Ok = true;
                    }
                }

                Application.DoEvents();

                if (form.CANCELAR)
                {
                    rede.log.AddLog(Consts.CANCELADO);
                    break;
                }
            }

            rede.Gertec_Desconectar();
            return(true);
        }
Ejemplo n.º 3
0
        //private void processar_marcacoes(int Terminal, string Arquivo)
        //{
        //    Marcacoes marcacoes = new Marcacoes(Arquivo);
        //    DBApp db = new DBApp();
        //    Log log = new Log(edLog);
        //    db.ProcessarMarcacoes(Grupo, marcacoes.listMarcacoes, log);
        //}

        private void ExcluirTerminal(int Terminal)
        {
            DBApp db = new DBApp();

            db.executeCommand(String.Format("DELETE FROM Terminais WHERE TRM_IND = {0}", Terminal));
            preencher_terminais();
        }
Ejemplo n.º 4
0
        private void RepEdicao_Load(object sender, EventArgs e)
        {
            if (Terminal > 0)
            {
                db = new DBApp();

                //SqlCommand Comm = db.Conn.CreateCommand();
                //Comm.CommandText = "SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, " +
                //                   "TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL FROM Terminais WHERE TRM_IND = " + Terminal.ToString() + " " +
                //                   "ORDER BY TRM_DESCRICAO";
                //SqlDataReader reader = Comm.ExecuteReader();

                SqlDataReader reader = db.getReader("SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, " +
                                                    "TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL FROM Terminais WHERE TRM_IND = " + Terminal.ToString() + " " +
                                                    "ORDER BY TRM_DESCRICAO");
                reader.Read();

                edDescricao.Text   = reader["TRM_DESCRICAO"].ToString().Trim();
                edIp.Text          = reader["TRM_IP"].ToString().Trim();
                edPorta.Text       = reader["TRM_PORTA"].ToString().Trim();
                edRazaoSocial.Text = reader["TRM_RAZAOSOCIAL"].ToString().Trim();
                edCnpj.Text        = reader["TRM_CNPJ"].ToString().Trim();
                edCpf.Text         = reader["TRM_CPF"].ToString().Trim();
                edEndereco.Text    = reader["TRM_ENDERECO"].ToString().Trim();
                edNumero.Text      = reader["TRM_NUMERO"].ToString().Trim();
                edSerial.Text      = reader["TRM_SERIAL"].ToString().Trim();
                reader.Close();
                db.closeConnection();
            }
            else
            {
                edPorta.Text = Consts.PORTAPADRAO.ToString();
            }
        }
 private void LoadData()
 {
     Globals.ChronoLoadData.Start();
     try
     {
         DBApp.Open();
         LettersBindingSource.DataSource = DBApp.LettersAsBindingList;
         if (Globals.IsDebugExecutable) // TODO remove when ready
         {
             DBHebrew.TakeLettriqs();
             TermsBindingSource.DataSource    = DBHebrew.TermsHebrewAsBindingList;
             LettriqsBindingSource.DataSource = DBHebrew.TermLettriqsAsBindingList;
         }
     }
     catch (Exception ex)
     {
         DisplayManager.ShowError(SysTranslations.ApplicationMustExit.GetLang() + Globals.NL2 +
                                  SysTranslations.ContactSupport.GetLang());
         ex.Manage();
         Environment.Exit(-1);
     }
     finally
     {
         Globals.ChronoLoadData.Stop();
         Settings.BenchmarkLoadData = Globals.ChronoLoadData.ElapsedMilliseconds;
     }
 }
Ejemplo n.º 6
0
        public override bool sendFuncionario(Types.Funcionario Funcionario)
        {
            base.sendFuncionario(Funcionario);

            RepProtocol.Empregado empregado = new RepProtocol.Empregado();
            empregado.CNTLS = String.IsNullOrEmpty(Funcionario.Proximidade) ? "0" : Convert.ToInt64(Funcionario.Proximidade).ToString("X");
            empregado.ID    = Funcionario.Crachas[0].ToString();
            empregado.KBD   = Funcionario.Crachas[0].ToString();
            empregado.Nome  = Funcionario.Nome;
            empregado.PIS   = Funcionario.Pis;

            AssepontoRep.DBApp bd = new DBApp();

            string msg = "";

            if (bd.FuncionarioEstaNoTerminal(TerminalDados.Indice, Funcionario.Ind))
            {
                repProtocol.EditEmployee(empregado, out msg);
            }
            else
            {
                repProtocol.SetEmployee(empregado, out msg);
            }

            LogMensagem(msg);

            return(msg == MSGOK);
        }
        public ActionResult AddColumn(string appName, string tableName, DBColumn column)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);

            if (table.Select().ToList().Count != 0 && column.canBeNull == false)//condition for not null column, which can be created only in empty table
            {
                TempData["message-error"] = "Table " + tableName + " must be empty if you want to add NOT NULL column.";
                return RedirectToAction("Details", new { @appName = appName, @tableName = tableName });
            }
            else if (table.columns.SingleOrDefault(x => x.Name == column.Name) != null)//condition for column name, column name can not be equal with other names in table
            {
                TempData["message-error"] = "Table " + tableName + " has already column with name " + column.Name + ".";
                return RedirectToAction("Details", new { @appName = appName, @tableName = tableName });
            }

            table.columns.AddToDB(column);
            app.SaveChanges();
            TempData["message-success"] = "Column " + column.Name + " was successfully added.";

            return RedirectToAction("Details", new { @appName = appName, @tableName = tableName });
        }
Ejemplo n.º 8
0
        public static void EnviaInfoEmpresa(int Terminal, TextBox edLog)
        {
            Types.Terminal   TerminalDados;
            Types.Empregador EmpregadorDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);

            db.LerEmpresa(Terminal, out EmpregadorDados);

            Rede rede = new Rede(TerminalDados.IP, TerminalDados.Porta, edLog);

            if (TerminalDados.SupervisorPis == "" || TerminalDados.SupervisorCodigo == 0 || TerminalDados.SupervisorSenha == 0)
            {
                rede.log.AddLog(AssepontoRep.Consts.DADOS_SUPERVISOR_NAO_DEFINIDOS);
            }
            else
            {
                if (rede.Dimep_EnviaEmpresa(EmpregadorDados.PessoaTipo, EmpregadorDados.Pessoa, EmpregadorDados.Nome, EmpregadorDados.Cei, EmpregadorDados.Endereco))
                {
                    rede.Dimep_InsereFuncionarioMasterListaEnvio(TerminalDados.SupervisorPis, TerminalDados.SupervisorCodigo.ToString(), TerminalDados.SupervisorSenha.ToString());
                    rede.Dimep_EnviaFuncionariosMasterListaEnvio();
                }
            }
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        public static void EnviaConfiguracao(int Terminal, TextBox edLog)
        {
            Types.Terminal TerminalDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);

            Rede rede = new Rede(TerminalDados.IP, TerminalDados.Porta, edLog);

            rede.Dimep_EnviaConfiguracao();
        }
Ejemplo n.º 12
0
        public static void EnviaDataHora(int Terminal, TextBox edLog)
        {
            Types.Terminal TerminalDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);

            Rede rede = new Rede(TerminalDados.IP, edLog);

            rede.Gertec_AtualizaDataHora();
        }
Ejemplo n.º 13
0
        public ActionResult Create(DBApp model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
                return View(model);

            DBApp.connectionString = (new Entities()).Database.Connection.ConnectionString;
            if (string.IsNullOrWhiteSpace(model.DisplayName))
                model.DisplayName = model.Name;

            model.Create();

            return RedirectToAction("Index");
        }
Ejemplo n.º 14
0
        public static void EnviaInfoEmpresa(int Terminal, TextBox edLog)
        {
            Types.Terminal   TerminalDados;
            Types.Empregador EmpregadorDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);
            db.LerEmpresa(Terminal, out EmpregadorDados);

            Rede rede = new Rede(TerminalDados.IP, edLog);

            rede.Gertec_EnviaEmpresa(EmpregadorDados.PessoaTipo, EmpregadorDados.Pessoa, EmpregadorDados.Nome, EmpregadorDados.Cei, EmpregadorDados.Endereco);
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        private void definirPróximoNSRToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DBApp db = new DBApp();

            int Terminal = Convert.ToInt32(listRelogios.Items[listRelogios.SelectedIndices[0]].SubItems[Consts.TRM_SUBITEM_IND].Text);

            int uNsr = db.getLastNsr(Terminal);

            string sNsr = uNsr.ToString();

            if (InputBox.Show("Informe o Último Nsr", "NSR", ref sNsr) == DialogResult.OK)
            {
                db.setLastNsr(Terminal, Convert.ToInt32(sNsr));
            }
        }
Ejemplo n.º 17
0
        public static void EnviarFuncionariosTerminal(int Terminal, Principal form, TextBox edLog)
        {
            Types.Terminal TerminalDados;

            DBApp      db   = new DBApp();
            SqlCommand comm = db.Conn.CreateCommand();

            db.getDadosTerminal(Terminal, out TerminalDados);

            Rede rede = new Rede(TerminalDados.IP, edLog);

            if (rede.Gertec_Conectar())
            {
                form.CANCELAR = false;

                SqlDataAdapter da = new SqlDataAdapter("SELECT FUNC_IND, FUNC_PIS, TRMF_ARMAZENADO_NO_TERMINAL " +
                                                       "FROM Funcionarios " +
                                                       "INNER JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
                                                       "WHERE TRMF_TERMINAL = " + Terminal + " AND FUNC_PIS IS NOT NULL " +
                                                       "ORDER BY FUNC_NOME", db.Conn);
                DataSet ds = new DataSet();
                da.Fill(ds);
                rede.log.AddLog(String.Format(Consts.FUNCIONARIOS_ENVIANDO, ds.Tables[0].Rows.Count));

                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (Convert.ToInt32(dr["TRMF_ARMAZENADO_NO_TERMINAL"]) == 1)
                    {
                        rede.log.AddLog(String.Format(Consts.PIS_JA_EXISTE, dr["FUNC_PIS"].ToString()));
                    }
                    else
                    {
                        EnviarFuncionario(db, rede, Terminal, Convert.ToInt32(dr["FUNC_IND"].ToString()));
                    }

                    Application.DoEvents();

                    if (form.CANCELAR)
                    {
                        rede.log.AddLog(Consts.CANCELADO);
                        break;
                    }
                }
            }

            rede.Gertec_Desconectar();
        }
Ejemplo n.º 18
0
        static bool EnviarFuncionario(DBApp db, Rede rede, int Terminal, int Funcionario)
        {
            bool Result = false;

            //string TecladoPassword = "";
            string Cracha = "";
            string Pis    = "";

            SqlDataAdapter da = new SqlDataAdapter("SELECT FUNC_NOME, FUNC_PIS, CRA_NUMERO, TRMF_TECLADO, " +
                                                   "TRMF_TECLADO_PASSWORD, TRMF_PROXIMIDADE, TRMF_CODIGOBARRAS " +
                                                   "FROM Funcionarios " +
                                                   "LEFT JOIN Crachas ON CRA_FUNC = FUNC_IND " +
                                                   "LEFT JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
                                                   "WHERE FUNC_IND = " + Funcionario + " AND TRMF_TERMINAL = " + Terminal + " " +
                                                   "ORDER BY FUNC_NOME", db.Conn);
            DataSet ds = new DataSet();

            da.Fill(ds);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                if (dr["CRA_NUMERO"] != DBNull.Value)
                {
                    Cracha = dr["CRA_NUMERO"].ToString().Trim();
                }
                else
                {
                    Cracha = "";
                }

                Pis = dr["FUNC_PIS"].ToString().Trim();

                if (Pis[0] == Convert.ToChar("0"))
                {
                    Pis = Pis.Substring(1);
                }

                if (Pis != string.Empty)
                {
                    rede.Dimep_InsereFuncionarioListaEnvio(dr["FUNC_NOME"].ToString().Trim(), Pis, Cracha);
                    FuncionariosAtualizados.Add(Funcionario);
                    Result = true;
                }
            }

            return(Result);
        }
Ejemplo n.º 19
0
        private void btOk_Click(object sender, EventArgs e)
        {
            //SqlConnection Conn = DB.Connection();
            //SqlCommand Comm = Conn.CreateCommand();

            DBApp db = new DBApp();

            db.openConnection();
            SqlCommand Comm = db.Conn.CreateCommand();

            if (Terminal > 0)
            {
                Comm.CommandText = "UPDATE Terminais SET TRM_DESCRICAO = @DESCRICAO, TRM_IP = @IP, " +
                                   "TRM_PORTA = @PORTA, TRM_GRUPO = @GRUPO, TRM_FABRICANTE = @FABRICANTE, " +
                                   "TRM_RAZAOSOCIAL = @RAZAOSOCIAL, TRM_CNPJ = @CNPJ, TRM_CPF = @CPF, TRM_ENDERECO = @ENDERECO, TRM_NUMERO = @NUMERO, TRM_SERIAL = @SERIAL " +
                                   "WHERE TRM_IND = " + Terminal.ToString();
            }
            else
            {
                Comm.CommandText = "INSERT INTO Terminais (TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_GRUPO, " +
                                   "TRM_FABRICANTE, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL) VALUES (@DESCRICAO, " +
                                   "@IP, @PORTA, @GRUPO, @FABRICANTE, @RAZAOSOCIAL, @CNPJ, @CPF, @ENDERECO, @NUMERO, @SERIAL)";
            }

            Comm.Parameters.Add(new SqlParameter("@DESCRICAO", edDescricao.Text));
            Comm.Parameters.Add(new SqlParameter("@IP", edIp.Text));
            Comm.Parameters.Add(new SqlParameter("@PORTA", edPorta.Text));
            Comm.Parameters.Add(new SqlParameter("@GRUPO", Grupo));
            Comm.Parameters.Add(new SqlParameter("@FABRICANTE", "TRIX"));

            Comm.Parameters.Add(new SqlParameter("@RAZAOSOCIAL", edRazaoSocial.Text));

            Comm.Parameters.Add(new SqlParameter("@CNPJ", edCnpj.Text));
            Comm.Parameters.Add(new SqlParameter("@CPF", edCpf.Text));

            Comm.Parameters.Add(new SqlParameter("@ENDERECO", edEndereco.Text));
            Comm.Parameters.Add(new SqlParameter("@NUMERO", edNumero.Text));
            Comm.Parameters.Add(new SqlParameter("@SERIAL", edSerial.Text));

            Comm.ExecuteNonQuery();
            db.closeConnection();
            //Conn.Close();

            this.Close();
        }
Ejemplo n.º 20
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, null);

            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);
        }
Ejemplo n.º 21
0
        private void preencher_funcionarios(int Terminal)
        {
            ListViewItem item;
            DBApp        db = new DBApp();
            //SqlCommand comm = db.Conn.CreateCommand();

            //comm.CommandText = "SELECT FUNC_NOME, CAR_DESCRICAO, CRA_NUMERO, FUNC_PIS, FUNC_IND, " +
            //    "dbo.fn_getdatetime(TRMF_ARMAZENADO_EM) AS TRMF_ARMAZENADO_EM " +
            //    "FROM Funcionarios " +
            //    "LEFT JOIN Cargos ON CAR_IND = FUNC_CARGO " +
            //    "LEFT JOIN Crachas ON CRA_FUNC = FUNC_IND " +
            //    "INNER JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
            //    "WHERE TRMF_TERMINAL = " + Terminal + " AND FUNC_DT_DEM IS NULL AND FUNC_MARCADO_EXCLUSAO = 0 " +
            //    "ORDER BY FUNC_NOME";
            //SqlDataReader reader = comm.ExecuteReader();

            SqlDataReader reader = db.getReader("SELECT FUNC_NOME, CAR_DESCRICAO, CRA_NUMERO, FUNC_PIS, FUNC_IND, " +
                                                "dbo.fn_getdatetime(TRMF_ARMAZENADO_EM) AS TRMF_ARMAZENADO_EM " +
                                                "FROM Funcionarios " +
                                                "LEFT JOIN Cargos ON CAR_IND = FUNC_CARGO " +
                                                "LEFT JOIN Crachas ON CRA_FUNC = FUNC_IND " +
                                                "INNER JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
                                                "WHERE TRMF_TERMINAL = " + Terminal + " AND FUNC_DT_DEM IS NULL AND FUNC_MARCADO_EXCLUSAO = 0 " +
                                                "ORDER BY FUNC_NOME");

            listFuncionarios.Items.Clear();

            while (reader.Read())
            {
                item      = new ListViewItem();
                item.Text = reader["FUNC_NOME"].ToString().Trim();
                item.SubItems.Add(reader["CAR_DESCRICAO"].ToString().Trim());
                item.SubItems.Add(reader["CRA_NUMERO"].ToString());
                item.SubItems.Add(reader["FUNC_PIS"].ToString().Trim());
                item.SubItems.Add(reader["FUNC_IND"].ToString());
                item.SubItems.Add(reader["TRMF_ARMAZENADO_EM"].ToString());
                listFuncionarios.Items.Add(item);
            }

            reader.Close();
            db.closeConnection();
        }
Ejemplo n.º 22
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, edLog);

            string    Arquivo   = Folders.folderMarcacoes(TerminalDados.Descricao) + String.Format("{0:yyyy MM dd hhmm}", DateTime.Now) + ".txt";
            Marcacoes marcacoes = new Marcacoes(Arquivo);

            if (rede.Gertec_ImportarMarcacoes(Terminal, TerminalDados.Descricao, marcacoes))
            {
                Utilitarios.setArquivoImportacao(Registro, Arquivo);
                db.ProcessarMarcacoes(TerminalDados.Grupo, marcacoes, rede.log);
            }
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
        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);
            }
        }
Ejemplo n.º 25
0
        public static bool ExcluirFuncionariosSelecao(int Terminal, ListView listFuncionarios, TextBox edLog)
        {
            bool Result = false;

            Types.Terminal TerminalDados;

            DBApp db = new DBApp();

            db.getDadosTerminal(Terminal, out TerminalDados);

            Rede rede = new Rede(TerminalDados.IP, edLog);

            if (!rede.Gertec_Conectar())
            {
                return(Result);
            }

            if (listFuncionarios.SelectedIndices.Count > 1)
            {
                rede.log.AddLog(String.Format(Consts.FUNCIONARIOS_EXCLUINDO, listFuncionarios.SelectedIndices.Count));
            }

            for (int i = 0; i <= listFuncionarios.SelectedIndices.Count - 1; i++)
            {
                int    index       = listFuncionarios.SelectedIndices[i];
                string Nome        = listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_NOME].Text;
                string Pis         = listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_PIS].Text;
                int    Funcionario = Convert.ToInt32(listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_IND].Text);

                if (rede.Gertec_ExcluirFuncionario(Nome, Pis))
                {
                    db.MarcarFuncionarioComoNaoEnviado(Terminal, Funcionario);
                    Result = true;
                }
            }

            rede.Gertec_Desconectar();
            return(Result);
        }
Ejemplo n.º 26
0
        private void MarcarSelecionadosComoNaoEnviados()
        {
            List <int> FuncionariosSelecionados = new List <int>();

            if (listFuncionarios.SelectedIndices.Count == 0)
            {
                return;
            }

            for (int i = 0; i <= listFuncionarios.SelectedIndices.Count - 1; i++)
            {
                int index       = listFuncionarios.SelectedIndices[i];
                int Funcionario = Convert.ToInt32(listFuncionarios.Items[index].SubItems[Consts.FUNC_SUBITEM_IND].Text);
                FuncionariosSelecionados.Add(Funcionario);
            }

            DBApp db = new DBApp();

            int Terminal = Convert.ToInt32(listRelogios.Items[listRelogios.SelectedIndices[0]].SubItems[Consts.TRM_SUBITEM_IND].Text);

            db.MarcarFuncionariosComoEnviados(Terminal, FuncionariosSelecionados);
            atualizar_funcionarios_teminal();
        }
        public ActionResult AddCheck(string appName, string tableName, FormCollection fc)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            foreach (string checkConstraint in table.GetCheckConstraints()) //constraint name control in table
            {
                if (checkConstraint == "CHK_" + appName + "_" + tableName + "_" + fc["checkName"])
                {
                    TempData["message-error"] = "Check constraint with name " + checkConstraint + " is already exist.";
                    return RedirectToAction("Index", new { @appName = appName });
                }
            }

            int i = 0;
            Conditions con = new Conditions(new SqlQuery());
            Condition_Operators ope = new Condition_Operators(con);
            Condition_concat concat = new Condition_concat(con);
            while (fc["column[" + i + "]"] != null)
            {
                DBColumn col = table.columns.SingleOrDefault(x => x.Name == fc["column[" + i + "]"]);
                object val = table.ConvertValue(col, fc["value[" + i + "]"]);
                con.column(col.Name);
                con.isCheck = true;
                if (i != 0) concat.and();
                ope = table.GetConditionOperators(con, fc["conOperator[" + i + "]"], val);
                i++;
            }
            table.AddCheck(fc["checkName"], con);
            app.SaveChanges();
            TempData["message-success"] = "Check constraint " + fc["checkName"] + " was successfully added into table " + tableName + ".";
            return RedirectToAction("Index", new { @appName = appName });
        }
        public ActionResult Create(string appName, DBTable model)
        {
            if (!string.IsNullOrWhiteSpace(model.tableName))
            {
                DBApp app = new DBApp()
                {
                    Name = appName,
                    ConnectionString = (new Entities()).Database.Connection.ConnectionString
                };

                model.Application = app;
                foreach (DBTable t in app.GetTables())//can not create table with name, which is already exist
                {
                    if (t.tableName == model.tableName)
                    {
                        TempData["message-error"] = "Table " + model.tableName + " can not be created. Table name " +
                        model.tableName + " is already exist.";
                        return RedirectToAction("Index", new { @appName = appName });
                    }
                }
                foreach (DBColumn c in model.columns)//column name must be unique in table, int p is for situation, when column is compared with itself
                {
                    int p = 0;
                    foreach (DBColumn d in model.columns)
                    {
                        if (c.Name == d.Name)
                        {
                            p = p + 1;
                            if (p > 1)
                            {
                                TempData["message-error"] = "Table " + model.tableName + " can not be created. Column name " +
                                                        c.Name + " is in table more then once.";
                                return RedirectToAction("Index", new { @appName = appName });
                            }
                        }
                    }
                }

                model.Create();
                foreach (DBColumn c in model.columns)//every colum with isUnique=true add query for AddUniqueValue into queries
                {
                    List<string> unique = new List<string>();
                    if (c.isUnique)
                    {
                        unique.Add(c.Name);
                        model.columns.AddUniqueValue(c.Name, unique);
                    }
                }
                app.SaveChanges();
                TempData["message-success"] = "Table " + model.tableName + " was successfully created.";
                return RedirectToAction("Index", new { @appName = appName });
            }

            return View(model);
        }
        public ActionResult DropColumn(string appName, string tableName, string columnName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            app.GetTable(tableName)
                .columns.DropFromDB(columnName);
            app.SaveChanges();

            TempData["message-success"] = "Column " + columnName + " was successfully dropped.";
            return RedirectToAction("Details", new { @appName = appName, @tableName = tableName });
        }
 public ActionResult DropDefault(string tableName, string appName)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     if (table.columns.GetDefaults().Count == 0) //is there some default value to drop?
     {
         TempData["message-error"] = "Table has no default value to drop.";
         return RedirectToAction("Index", new { @appName = appName });
     }
     ViewBag.Defaults = table.columns.GetDefaults();
     return View(table);
 }
 public ActionResult CreateCheck(string appName, string tableName)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     ViewBag.Column = table.columns.Select(x => x.Name);
     ViewBag.Operators = table.GetOperators();
     return View("AddCheck", table);
 }
        public ActionResult DropIndex(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            List<string> indexNames = new List<string>();

            foreach (DBIndex index in table.indices) //user can not drop cluster index, this foreach add every indexName into the list except cluster index´s name
            {
                if (index.indexName != "index_" + appName + tableName)
                {
                    indexNames.Add(index.indexName);
                }
            }

            if (indexNames.Count != 0)
            {
                ViewBag.indeces = indexNames;
                return View(table);
            }
            TempData["message-error"] = "Table has no index to drop.";
            return RedirectToAction("Index", new { @appName = appName });
        }
        public ActionResult CreateForeignKey(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            ViewBag.tables = app.GetTables().Select(t => t.tableName);
            ViewBag.Columns = table.columns.Select(x => x.Name);

            return View(new DBForeignKey() { sourceTable = table });
        }
Ejemplo n.º 34
0
        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 ActionResult DropTable(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            app.GetTable(tableName).Drop();
            app.SaveChanges();
            TempData["message-success"] = "Table " + tableName + " was successfully dropped.";
            return RedirectToAction("Index", new { @appName = appName });
        }
        public ActionResult RenameTable(string appName, DBTable model)
        {
            string tableName = TempData["oldTableName"].ToString();
            if (!string.IsNullOrWhiteSpace(tableName))
            {
                DBApp app = new DBApp()
                {
                    Name = appName,
                    ConnectionString = (new Entities()).Database.Connection.ConnectionString
                };

                DBTable table = app.GetTable(tableName);
                table.Rename(model.tableName);
                app.SaveChanges();
                TempData["message-success"] = "Table " + tableName + " was successfully renamed to " + model.tableName + ".";
                return RedirectToAction("Index", new { @appName = appName });
            }

            return View();
        }
Ejemplo n.º 37
0
        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 ActionResult TruncateTable(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            table.Truncate();
            app.SaveChanges();

            return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
        }
        public ActionResult Constraint(string appName, string tableName, bool isDisable)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            ViewBag.Constraints = table.getConstraints(isDisable);

            if (isDisable)
            {
                if (table.getConstraints(isDisable).Count != 0)
                {
                    return View("DisableConstraint", table);
                }
                TempData["message-error"] = "Table has no constraint to disable.";
                return RedirectToAction("Index", new { @appName = appName });
            }
            else
            {
                if (table.getConstraints(isDisable).Count != 0)
                {
                    return View("EnableConstraint", table);

                }
                TempData["message-error"] = "Table has no constraint to enable.";
                return RedirectToAction("Index", new { @appName = appName });
            }
        }
        public ActionResult DeleteOrUpdate(string appName, string tableName, FormCollection fc)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            DBItem row = new DBItem();

            foreach (DBColumn c in table.columns)//converting to right data type
            {
                row.createProperty(c.ColumnId, c.Name, table.ConvertValue(c, fc.Get("col" + c.Name)));
                TempData.Remove(c.Name);
                TempData.Add(c.Name, row[c.Name]);
            }
            if (fc.Get("Update") != null)
            {
                ViewBag.Row = row.getAllProperties();
                return View("UpdateView", table);
            }
            else
            {
                table.Remove(row);
                app.SaveChanges();
                TempData["message-success"] = "Row was successfully deleted.";
                return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
            }
        }
        public ActionResult AddDefault(string appName, string tableName, string value, string defaultColumn)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            DBColumn c = table.columns.SingleOrDefault(s => s.Name == defaultColumn);
            object val = table.ConvertValue(c, value);

            table.columns.AddDefaultValue(defaultColumn, val);
            app.SaveChanges();
            return RedirectToAction("Index", new { @appName = appName });
        }
 public ActionResult DropCheck(string tableName, string appName)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     if (table.GetCheckConstraints().Count == 0)//is there some check constraint to drop?
     {
         TempData["message-error"] = "Table has no check constraint to drop.";
         return RedirectToAction("Index", new { @appName = appName });
     }
     ViewBag.Check = table.GetCheckConstraints();
     return View(table);
 }
        public ActionResult DropUnique(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            if (table.columns.GetUniqueConstrainst().Count == 0) //if there are not unique constraints, is no need to continue into the view for drop
            {
                TempData["message-error"] = "Table has no unique constraint.";
                return RedirectToAction("Index", new { @appName = appName });
            }
            ViewBag.Unique = table.columns.GetUniqueConstrainst();
            return View(table);
        }
        public ActionResult InsertSelect(string appName, string tableName, List<string> columnsA, List<string> columnsB, string tableB, FormCollection fc)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            Conditions con = new Conditions(new SqlQuery());
            if (fc["conOperator[0]"] != "")
            {
                Condition_Operators ope = new Condition_Operators(con);
                Condition_concat concat = new Condition_concat(con);
                int i = 0;
                while (fc["column[" + i + "]"] != null)
                {
                    DBColumn col = table.columns.SingleOrDefault(x => x.Name == fc["column[" + i + "]"]);
                    object val = table.ConvertValue(col, fc["value[" + i + "]"]);
                    con.column(col.Name);
                    if (i != 0) concat.and();
                    ope = table.GetConditionOperators(con, fc["conOperator[" + i + "]"], val);
                    i++;
                }
            }
            table.InsertSelect(columnsA, tableB, columnsB, con.ToString());
            app.SaveChanges();

            TempData["message-success"] = "Row(s) was successfully inserted.";
            return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
        }
        public ActionResult Details(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            TempData.Remove("oldTableName");
            TempData.Add("oldTableName", tableName);

            return View(app.GetTable(tableName));
        }
 public ActionResult InsertSelect(string appName, string tableName)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     ViewBag.Operators = table.GetOperators();
     return View(table);
 }
        public ActionResult CreatePrimaryKey(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);

            ViewBag.Columns = table.columns.Select(x => x.Name);
            return View(table);
        }
Ejemplo n.º 48
0
        private void ler_grupo()
        {
            DBApp db = new DBApp();

            Grupo = Convert.ToInt32(db.getFieldValueInteger("SELECT TOP 1 GRU_IND FROM Grupos"));
        }
 public ActionResult DropForeignKey(string appName, string tableName)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     if (table.foreignKeys.GetForeignKeyForDrop().Count != 0) //if there are not foreign keys, is no need to continue into the view for drop
     {
         ViewBag.foreignKeys = table.foreignKeys.GetForeignKeyForDrop();
         return View(table);
     }
     TempData["message-error"] = "Table has no foreign key to drop.";
     return RedirectToAction("Index", new { @appName = appName });
 }
        public ActionResult CreateUnique(string appName, string tableName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            return View(table);
        }
Ejemplo n.º 51
0
        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 ActionResult InsertRow(string appName, string tableName, FormCollection fc)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            bool isClusterIndex = false;
            foreach (DBIndex index in table.indices) //looking for cluster index between all indeces
            {
                if (index.indexName == "index_" + appName + tableName)
                {
                    isClusterIndex = true;
                    break;
                }
            }
            if (!isClusterIndex)//condition for cluster, you can not insert/update/delete without cluster in Azure
            {
                TempData["message-error"] = "Row can not be inserted, because table does not have a cluster index. The cluster index is created when you first create a primary key.";
                return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
            }
            DBItem row = new DBItem();
            foreach (DBColumn c in table.columns)  //converting to right data type
            {
                if (fc.Get("col" + c.Name) == "")
                {
                    row.createProperty(c.ColumnId, c.Name, null);
                }
                else
                {
                    row.createProperty(c.ColumnId, c.Name, table.ConvertValue(c, fc.Get("col" + c.Name)));
                }
            }

            table.Add(row);
            app.SaveChanges();
            TempData["message-success"] = "Row was successfully inserted.";
            return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
        }
Ejemplo n.º 53
0
        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 ActionResult Index(string appName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            return View(app.GetTables());
        }
 public ActionResult DropConstraint(string tableName, string appName, string constraintName, bool? isPrimaryKey)
 {
     DBApp app = new DBApp()
     {
         Name = appName,
         ConnectionString = (new Entities()).Database.Connection.ConnectionString
     };
     DBTable table = app.GetTable(tableName);
     if (isPrimaryKey == true)
     {
         if (table.primaryKeys.Count == 0) //is there some primary key to drop?
         {
             TempData["message-error"] = "Table has no primary key to drop.";
             return RedirectToAction("Index", new { @appName = appName });
         }
     }
     table.DropConstraint(constraintName, isPrimaryKey);
     app.SaveChanges();
     TempData["message-success"] = "Constraint was successfully dropped.";
     return RedirectToAction("Index", new { @appName = appName });
 }
        public JsonResult getTableColumns(string tableName, string appName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);
            List<string> tableColumns = table.columns.Select(x => x.Name).ToList();

            return Json(tableColumns, JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 57
0
        public bool Gertec_ImportarMarcacoes(int Terminal, string TerminalNome, Marcacoes marcacoes)
        {
            bool  Result     = false;
            DBApp db         = new DBApp();
            int   ProximoNsr = db.getLastNsr(Terminal) + 1;

            string diretoriomarcacoes = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Asseponto\\Marcacoes\\" + TerminalNome;

            Wr.Classes.Files.ForceDirectories(diretoriomarcacoes);

            string ArquivoTemp = Path.GetTempFileName();

            System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");

            int Contador = 0;

            if (Gertec_Conectar())
            {
                int resultado = envioDll.LeCadastro(IP, 5, ProximoNsr.ToString(), ArquivoTemp);
                if (resultado == 0)
                {
                    FileStream   abreArquivoTxt = new FileStream(ArquivoTemp, FileMode.Open, FileAccess.Read);
                    StreamReader sr             = new StreamReader(abreArquivoTxt, iso_8859_1);
                    string       line           = "";

                    while ((line = sr.ReadLine()) != null)
                    {
                        string[] linhaReg = line.Split(';');
                        if (linhaReg[1] == "3")
                        {
                            string   Pis  = linhaReg[4];
                            bool     Erro = false;
                            DateTime DataHora;

                            try
                            {
                                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]);

                                if (Nsr > ProximoNsr)
                                {
                                    ProximoNsr = Nsr;
                                }

                                marcacoes.Add(Pis, DataHora, Nsr);
                                Contador++;
                            }
                            catch
                            {
                                log.AddLog(line);
                                Erro = true;
                            }
                        }
                    }

                    sr.Close();

                    File.Delete(ArquivoTemp);

                    Gertec_Desconectar();

                    if (Contador > 0)
                    {
                        string Arquivo = marcacoes.SaveToFile();
                        log.AddLog(String.Format(Consts.ARQUIVO_GERADO, Arquivo));

                        Result = true;
                    }
                    else
                    {
                        log.AddLog(Consts.SEM_MARCACOES);
                    }

                    if (ProximoNsr > 0)
                    {
                        db.setLastNsr(Terminal, ProximoNsr);
                    }
                }
                else
                {
                    Gertec_Desconectar();
                    LogMensagem(resultado);
                }
            }

            return(Result);
        }
        public ActionResult UpdateRow(string appName, string tableName, FormCollection fc)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            DBItem changes = new DBItem();
            DBItem oldVal = new DBItem();

            foreach (DBColumn c in table.columns)//converting to right data type
            {
                changes.createProperty(c.ColumnId, c.Name, table.ConvertValue(c, fc.Get("col" + c.Name)));
                oldVal.createProperty(c.ColumnId, c.Name, TempData[c.Name]);
            }
            table.Update(changes, oldVal);
            app.SaveChanges();
            TempData["message-success"] = "Row was successfully updated.";
            return RedirectToAction("Data", new { @appName = appName, @tableName = tableName });
        }
        public ActionResult DeleteIndex(string appName, string tableName, string indexName)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };

            DBTable table = app.GetTable(tableName);

            table.indices.DropFromDB(indexName);
            app.SaveChanges();
            TempData["message-success"] = "Index " + indexName + " of table " + tableName + " was successfully dropped.";
            return RedirectToAction("Index", new { @appName = appName });
        }
        public ActionResult DisableOrEnableConstraint(string appName, string tableName, FormCollection fc, bool isDisable)
        {
            DBApp app = new DBApp()
            {
                Name = appName,
                ConnectionString = (new Entities()).Database.Connection.ConnectionString
            };
            DBTable table = app.GetTable(tableName);
            string constraintName = (fc["all"] != null) ? "ALL" : fc["constraintName"];

            if (isDisable)
            {
                table.DisableConstraint(constraintName);
                TempData["message-success"] = "Constraint  of table " + tableName + " was successfully disabled.";
            }
            else
            {
                table.EnableConstraint(constraintName);
                TempData["message-success"] = "Constraint  of table " + tableName + " was successfully enabled.";
            }

            app.SaveChanges();

            return RedirectToAction("Index", new { @appName = appName });
        }