예제 #1
0
        public void TryDeleting(Company company, bool shouldDeleteOperador)
        {
            Exception ex = new CompanyRepositorio().Delete(company, shouldDeleteOperador);

            if (ex != null)
            {
                throw ex;
            }
        }
예제 #2
0
        public Respuesta()
        {
            Id = 0;

            AccionText = string.Empty;

            NumeroControl = new NumeroControl();

            company = new Company();

            RepresentanteAutorizado = string.Empty;

            Operador = new Operador();

            Zona = false;

            Urb = string.Empty;

            Calle = string.Empty;

            Carretera = string.Empty;

            KM = 0;

            HM = 0;

            MunicipioId = 0;

            CodigoPostal = string.Empty;

            Accion = 0;

            AccionText = string.Empty;

            PersonaContactar = string.Empty;

            Comentarios = string.Empty;

            EvidenciaMarcadoPaths = new LinkedList<string>();
        }
        public Company GetCompany(string nombre)
        {
            Company company = new Company();

            //using (SqlConnection conn = new SQL().GetConnection())
            using (SqlConnection conn = new SQL().GetLocalConnection())
            {
                SqlCommand cmd = new SqlCommand(@"SELECT EmpresaID, NombreEmpresa, UrbBarrioCondDF + ' ' + ApartBoxCalleDF + ' ' + MunicipioDF
                                                + ' ' + SectorDF + ' ' + EstadoPaisDF + ' ' + CodigoPostalDF FROM Empresas WHERE NombreEmpresa = @NombreEmpresa;", conn);

                cmd.Parameters.AddWithValue("NombreEmpresa", nombre);

                conn.Open();

                cmd.ExecuteNonQuery();

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int col = 0;

                    company = new Company()
                    {
                        EmpresaID = reader.GetInt32(col++),

                        NombreEmpresa = reader.GetString(col++),

                        DireccionFisica = reader.GetString(col++)
                    };
                }
            }

            return company;
        }
        public Company GetCompany(User user)
        {
            Company company = new Company();

            //using (SqlConnection conn = new SQL().GetConnection())
            using (SqlConnection conn = new SQL().GetLocalConnection())
            {
                SqlCommand cmd = new SqlCommand(@"SELECT TipoExcDem,  EsOperador, CorreoElectronico, EmpresaID, NombreEmpresa, UrbBarrioCond + ', ' + ApartBoxCalle 
                                                + ', ' + Sector + ', ' + EstadoPais, UrbBarrioCondDF + ', ' + ApartBoxCalleDF + ', ' + MunicipioDF
                                                + ', ' + SectorDF + ', ' + EstadoPaisDF + ', ' + CodigoPostalDF, RepresentanteAutorizado
                                                , TelOficina, TelTrabajo, Celular, CodigoPostal, Municipio, Comentarios 
                                                FROM Empresas WHERE NombreEmpresa = @NombreEmpresa;", conn);

                cmd.Parameters.AddWithValue("NombreEmpresa", user.EmpresaID);

                //cmd.Parameters.AddWithValue("UsuarioID", "*****@*****.**"); //Test only

                conn.Open();

                cmd.ExecuteNonQuery();

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    int col = 0;

                    company = new Company()
                    {     
                        TipoExcavador = Convert.ToInt32(reader.GetString(col++)),

                        EsOperador = reader.GetBoolean(col++),

                        CorreoElectronico = reader.GetString(col++),

                        EmpresaID = reader.GetInt32(col++),

                        NombreEmpresa = reader.GetString(col++),

                        DireccionPostal = reader.GetString(col++),

                        DireccionFisica = reader.GetString(col++),

                        RepresentanteAutorizado = reader.GetString(col++),

                        TelOficina = reader.GetString(col++),

                        TelTrabajo = reader.GetString(col++),

                        Celular = reader.GetString(col++),

                        CodigoPostal = reader.GetString(col++),

                        Municipio = reader.GetString(col++),

                        Comentario = reader.GetString(col++)
                    };
                }
            }

            return company;
        }
예제 #5
0
        protected void gvNombreEmp_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Eliminar"))
            {
                int selectedRowIndex = Convert.ToInt32(e.CommandArgument);

                GridViewRow selectedRow = gvNombreEmp.Rows[selectedRowIndex];

                Company company = new Company
                {
                    Nombre = selectedRow.Cells[0].Text
                };

                //Para evitar que se borre una empresa sin culpa de duplicidad, el dropdown decide si 
                //se elimina solo la empresa o solo el operador.
                new CompanyServicio().TryDeleting(company, BuscaPorDDL.SelectedIndex > 0);

                BuscaPorDDL_SelectedIndexChanged(sender, EventArgs.Empty);
            }
        }
예제 #6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="company"></param>
        /// <param name="shouldDeleteOperador">Flag that indicates if only operador should deleted or if company is the only deletion</param>
        /// <returns></returns>
        public Exception Delete(Company company, bool shouldDeleteOperador)
        {
            using (SqlConnection conn = new SQL().GetLocalConnection())
            {
                SqlCommand cmd = new SqlCommand(@"DELETE FROM @FROM WHERE @WHERE = @NombreEmpresa; @OPERADOR", conn);

                if (shouldDeleteOperador)
                {
                    cmd.CommandText = cmd.CommandText.Replace("@FROM", "Operadores");

                    cmd.CommandText = cmd.CommandText.Replace("@WHERE", "Operador");

                    cmd.CommandText = cmd.CommandText.Replace("@OPERADOR", string.Empty);

                    cmd.CommandText = string.Format("{0} UPDATE Empresas SET EsOperador = {1} WHERE NombreEmpresa = @NombreEmpresa", cmd.CommandText
                        , 0);
                }

                else
                {
                    cmd.CommandText = cmd.CommandText.Replace("@FROM", "Empresas");

                    cmd.CommandText = cmd.CommandText.Replace("@WHERE", "NombreEmpresa");

                    cmd.CommandText = cmd.CommandText.Replace("@OPERADOR", "DELETE FROM Operadores WHERE Operador = @NombreEmpresa;");
                }

                cmd.Parameters.AddWithValue("NombreEmpresa", company.Nombre.Replace("amp;", string.Empty));

                conn.Open();

                using (SqlTransaction transaction = conn.BeginTransaction())
                {
                    cmd.Transaction = transaction;

                    try
                    {
                        cmd.ExecuteNonQuery();

                        transaction.Commit();

                        return null;
                    }

                    catch (Exception ex)
                    {
                        transaction.Rollback();

                        #region Log errors
                        String errorLog = "Date: " + DateTime.Now.ToLongDateString() + "\r\n Empresa:" + company.Nombre
                                            + "\r\n Message: " + ex.Message + "\r\n Source: "
                                            + ex.Source + "\r\n Stacktrace: " + ex.StackTrace + "\r\n TargetSite: " + ex.TargetSite.ToString() + "\r\n\r\n";

                        //File.WriteAllText("AveriasLog.txt", errorLog);

                        return ex;
                        #endregion
                    }
                }

            }
        }
        public static Company GetCompanyByName(string nombre)
        {
            Company company = new Company();

            //using (SqlConnection conn = new SQL().GetConnection())
            using (SqlConnection conn = new SQL().GetLocalConnection())
            {
                using (SqlCommand cmd = new SqlCommand(@"SELECT TOP 1 * FROM Empresas WHERE NombreEmpresa LIKE @like;", conn))
                {
                    cmd.CommandText = cmd.CommandText.Replace("@like", string.Format("'%{0}%'", nombre));

                    conn.Open();

                    cmd.ExecuteNonQuery();

                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            int col = 0;

                            company = new Company()
                            {
                                EmpresaID = reader.GetInt32(col++),

                                TipoExcavador = Convert.ToInt32(reader.GetString(col++)),

                                Nombre = reader.GetString(col++),

                                RepresentanteAutorizado = reader.GetString(col++),

                                DireccionPostal = string.Format("{0} {1} {2} {3} {4} {5}", reader.GetString(col++), reader.GetString(col++),
                                reader.GetString(col++), reader.GetString(col++), reader.GetString(col++), reader.GetString(col++)),

                                EsOperador = reader.GetBoolean(col++),

                                TelOficina = reader.GetString(col++),

                                TelTrabajo = reader.GetString(col++),

                                Celular = reader.GetString(col++),

                                DireccionFisica = string.Format("{0} {1} {2} {3} {4} {5}", reader.GetString(col++), reader.GetString(col++),
                                reader.GetString(col++), reader.GetString(col++), reader.GetString(col++), reader.GetString(col++)),

                                Comentario = reader.GetString(col++),

                                CorreoElectronico = reader.GetString(col++)
                            };
                        }
                    }
                }
            }

            return company;
        }