Пример #1
0
        public ActionResult Edit(hospitales hospitales)
        {
            hospitales ohospitales = new hospitales();

            ohospitales.Cod_hospital = System.Convert.ToInt32(hospitales.Cod_hospital);
            ohospitales = hospitalesData.Select_Record(hospitales);

            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = hospitalesData.Update(ohospitales, hospitales);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Update");
                }
            }
            // ComboBox
            ViewData["Cod_medico"] = new SelectList(hospitales_medicoData.List(), "Cod_medico", "Cedula", hospitales.Cod_medico);

            return(View(hospitales));
        }
Пример #2
0
        // GET: /hospitales/Delete/<id>
        public ActionResult Delete(
            Int32?Cod_hospital
            )
        {
            if (
                Cod_hospital == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            dtmedico = hospitales_medicoData.SelectAll();

            hospitales hospitales = new hospitales();

            hospitales.Cod_hospital = System.Convert.ToInt32(Cod_hospital);
            hospitales        = hospitalesData.Select_Record(hospitales);
            hospitales.medico = new medico()
            {
                Cod_medico = (Int32)hospitales.Cod_medico
                , Cedula   = (from DataRow rowmedico in dtmedico.Rows
                              where hospitales.Cod_medico == (int)rowmedico["Cod_medico"]
                              select(String) rowmedico["Cedula"]).FirstOrDefault()
            };

            if (hospitales == null)
            {
                return(HttpNotFound());
            }
            return(View(hospitales));
        }
Пример #3
0
        // GET: /hospitales/Edit/<id>
        public ActionResult Edit(
            Int32?Cod_hospital
            )
        {
            if (
                Cod_hospital == null
                )
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            hospitales hospitales = new hospitales();

            hospitales.Cod_hospital = System.Convert.ToInt32(Cod_hospital);
            hospitales = hospitalesData.Select_Record(hospitales);

            if (hospitales == null)
            {
                return(HttpNotFound());
            }
            // ComboBox
            ViewData["Cod_medico"] = new SelectList(hospitales_medicoData.List(), "Cod_medico", "Cedula", hospitales.Cod_medico);

            return(View(hospitales));
        }
Пример #4
0
        public ActionResult Create([Bind(Include =
                                             "Nombre"
                                             + "," + "Ciudad"
                                             + "," + "Tlefono"
                                             + "," + "Cod_medico"
                                         )] hospitales hospitales)
        {
            if (ModelState.IsValid)
            {
                bool bSucess = false;
                bSucess = hospitalesData.Add(hospitales);
                if (bSucess == true)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Can Not Insert");
                }
            }
            // ComboBox
            ViewData["Cod_medico"] = new SelectList(hospitales_medicoData.List(), "Cod_medico", "Cedula", hospitales.Cod_medico);

            return(View(hospitales));
        }
Пример #5
0
        public static List <hospitales> List()
        {
            List <hospitales> hospitalesList  = new List <hospitales>();
            SqlConnection     connection      = hospitalData.GetConnection();
            String            selectProcedure = "[hospitales_servicios_hospitales17Select]";
            SqlCommand        selectCommand   = new SqlCommand(selectProcedure, connection);

            try
            {
                connection.Open();
                SqlDataReader reader     = selectCommand.ExecuteReader();
                hospitales    hospitales = new hospitales();
                while (reader.Read())
                {
                    hospitales = new hospitales();
                    hospitales.Cod_hospital = System.Convert.ToInt32(reader["Cod_hospital"]);
                    hospitales.Nombre       = Convert.ToString(reader["Nombre"]);
                    hospitalesList.Add(hospitales);
                }
                reader.Close();
            }
            catch (SqlException)
            {
                return(hospitalesList);
            }
            finally
            {
                connection.Close();
            }
            return(hospitalesList);
        }
Пример #6
0
        public ActionResult DeleteConfirmed(
            Int32?Cod_hospital
            )
        {
            hospitales hospitales = new hospitales();

            hospitales.Cod_hospital = System.Convert.ToInt32(Cod_hospital);
            hospitales = hospitalesData.Select_Record(hospitales);

            bool bSucess = false;

            bSucess = hospitalesData.Delete(hospitales);
            if (bSucess == true)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("", "Can Not Delete");
            }
            return(null);
        }
Пример #7
0
        public static hospitales Select_Record(hospitales hospitalesPara)
        {
            hospitales    hospitales      = new hospitales();
            SqlConnection connection      = hospitalData.GetConnection();
            string        selectProcedure = "[hospitalesSelect]";
            SqlCommand    selectCommand   = new SqlCommand(selectProcedure, connection);

            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.Parameters.AddWithValue("@Cod_hospital", hospitalesPara.Cod_hospital);
            try
            {
                connection.Open();
                SqlDataReader reader
                    = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    hospitales.Cod_hospital = System.Convert.ToInt32(reader["Cod_hospital"]);
                    hospitales.Nombre       = reader["Nombre"] is DBNull ? null : reader["Nombre"].ToString();
                    hospitales.Ciudad       = reader["Ciudad"] is DBNull ? null : reader["Ciudad"].ToString();
                    hospitales.Tlefono      = reader["Tlefono"] is DBNull ? null : reader["Tlefono"].ToString();
                    hospitales.Cod_medico   = reader["Cod_medico"] is DBNull ? null : (Int32?)reader["Cod_medico"];
                }
                else
                {
                    hospitales = null;
                }
                reader.Close();
            }
            catch (SqlException)
            {
                return(hospitales);
            }
            finally
            {
                connection.Close();
            }
            return(hospitales);
        }
Пример #8
0
        public static bool Delete(hospitales hospitales)
        {
            SqlConnection connection      = hospitalData.GetConnection();
            string        deleteProcedure = "[hospitalesDelete]";
            SqlCommand    deleteCommand   = new SqlCommand(deleteProcedure, connection);

            deleteCommand.CommandType = CommandType.StoredProcedure;
            deleteCommand.Parameters.AddWithValue("@OldCod_hospital", hospitales.Cod_hospital);
            if (hospitales.Nombre != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldNombre", hospitales.Nombre);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldNombre", DBNull.Value);
            }
            if (hospitales.Ciudad != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldCiudad", hospitales.Ciudad);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldCiudad", DBNull.Value);
            }
            if (hospitales.Tlefono != null)
            {
                deleteCommand.Parameters.AddWithValue("@OldTlefono", hospitales.Tlefono);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldTlefono", DBNull.Value);
            }
            if (hospitales.Cod_medico.HasValue == true)
            {
                deleteCommand.Parameters.AddWithValue("@OldCod_medico", hospitales.Cod_medico);
            }
            else
            {
                deleteCommand.Parameters.AddWithValue("@OldCod_medico", DBNull.Value);
            }
            deleteCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int);
            deleteCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output;
            try
            {
                connection.Open();
                deleteCommand.ExecuteNonQuery();
                int count = System.Convert.ToInt32(deleteCommand.Parameters["@ReturnValue"].Value);
                if (count > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException)
            {
                return(false);
            }
            finally
            {
                connection.Close();
            }
        }