/// <summary> /// Método que inserta el precio en la base de datos /// </summary> /// <param name="oEnvio">Objeto que se va a agregar a la base de datos</param> /// <returns>Retorna una string con la respuesta del storedprocedure</returns> public EnvioPaquete InsertarPrecioEnvio(EnvioPaquete oEnvio) { IDALPrecioEnvio _DALPrecioEnvio = new DALPrecioEnvio(); List <EnvioPaquete> lista = new List <EnvioPaquete>(); int error = 0; try { lista = this.ListaPrecios(); foreach (EnvioPaquete item in lista) { if ((oEnvio.KilometroInicial >= item.KilometroInicial && oEnvio.KilometroInicial <= item.KilometroFinal) || (oEnvio.KilometroFinal >= item.KilometroInicial && oEnvio.KilometroFinal <= item.KilometroFinal)) { error++; } } if (error > 0) { throw new Exception("No es posible agregar el rango deseado, revise si no está incluido en otro"); } else { return(_DALPrecioEnvio.InsertarPrecioEnvio(oEnvio)); } } catch (Exception er) { throw new Exception(er.Message); } }
public void BuscarPrecioEnvioID() { IBLLPrecioEnvio _BLLPrecioEnvio = new BLLPrecioEnvio(); string IDEnvio = "A"; EnvioPaquete pEnvio = new EnvioPaquete(); pEnvio = _BLLPrecioEnvio.MostrarXID(IDEnvio); System.Diagnostics.Debug.Write(pEnvio.TipoEnvio); }
public void ModificarPrecioEnvio() { IBLLPrecioEnvio _BLLPrecioEnvio = new BLLPrecioEnvio(); EnvioPaquete oEnvio = new EnvioPaquete(); EnvioPaquete pEnvio = new EnvioPaquete(); oEnvio.KilometroFinal = 6598; oEnvio.KilometroInicial = 8798; oEnvio.PrecioRango = 23235612; oEnvio.TipoEnvio = "T"; pEnvio = _BLLPrecioEnvio.ActualizarPrecioEnvio(oEnvio); System.Diagnostics.Debug.Write(pEnvio.TipoEnvio); }
public void InsertarPrecioEnvio() { IBLLPrecioEnvio _BLLPrecioEnvio = new BLLPrecioEnvio(); EnvioPaquete oEnvio = new EnvioPaquete(); EnvioPaquete pEnvio = new EnvioPaquete(); oEnvio.KilometroFinal = 5641; oEnvio.KilometroInicial = 9874; oEnvio.PrecioRango = 16515616; oEnvio.TipoEnvio = "T"; pEnvio = _BLLPrecioEnvio.InsertarPrecioEnvio(oEnvio); System.Diagnostics.Debug.Write(pEnvio.TipoEnvio); }
/// <summary> /// Metodo que modifica el precio que hay en la base de datos /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnModificar_Click(object sender, EventArgs e) { erpErrores.Clear(); IBLLPrecioEnvio _BLLPrecioKilometro = new BLLPrecioEnvio(); try { if (string.IsNullOrEmpty(txtTipoMod.Text)) { erpErrores.SetError(txtTipoMod, "No puede quedar vacío"); } else { if (nudKilometroInicialMod.Value == 0 && nudKilometroFinalMod.Value == 0) { erpErrores.SetError(nudKilometroFinalMod, "No puede ser cero a ambos lados"); } else { if (string.IsNullOrEmpty(mskPrecioMod.Text)) { erpErrores.SetError(mskPrecioMod, "No puede quedar vacío"); } else { EnvioPaquete oEnvio = new EnvioPaquete(); oEnvio.TipoEnvio = txtTipoMod.Text; oEnvio.KilometroInicial = (int)nudKilometroInicialMod.Value; oEnvio.KilometroFinal = (int)nudKilometroFinalMod.Value; oEnvio.PrecioRango = Convert.ToDouble(mskPrecioMod.Text); _BLLPrecioKilometro.ActualizarPrecioEnvio(oEnvio); EspaciosBlancoMod(); } } } } catch (Exception er) { StringBuilder msg = new StringBuilder(); msg.AppendFormat("Message {0}\n", er.Message); msg.AppendFormat("Source {0}\n", er.Source); msg.AppendFormat("InnerException {0}\n", er.InnerException); msg.AppendFormat("StackTrace {0}\n", er.StackTrace); msg.AppendFormat("TargetSite {0}\n", er.TargetSite); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); MessageBox.Show("Se ha producido el siguiente error " + er.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Método que obtiene los precios de envio de la base de datos /// </summary> /// <returns>Retorna una lista con los precios</returns> public List <EnvioPaquete> ListaPrecios() { List <EnvioPaquete> _ListPrecios = new List <EnvioPaquete>(); IConexion conexion = new Conexion(); DataSet dt = new DataSet(); using (SqlConnection conn = conexion.conexion()) { try { SqlCommand cmd = new SqlCommand("select * from [EnvioPaquete]", conn); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); foreach (DataRow dr in dt.Tables[0].Rows) { EnvioPaquete EnvioPaquete = new EnvioPaquete(); EnvioPaquete.TipoEnvio = dr["TipoEnvio"].ToString(); EnvioPaquete.PrecioRango = Convert.ToDouble(dr["PrecioRango"].ToString()); EnvioPaquete.KilometroInicial = Convert.ToInt32(dr["KilometroInicial"].ToString()); EnvioPaquete.KilometroFinal = Convert.ToInt32(dr["KilometroFinal"].ToString()); _ListPrecios.Add(EnvioPaquete); } } catch (SqlException sqlError) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } catch (Exception er) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } finally { conn.Close(); } } return(_ListPrecios); }
/// <summary> /// Metodo que actualiza un valor en la base de datos con el parametro recibido /// </summary> /// <param name="oEnvio">Parametro que actualizará en la base de datos</param> /// <returns>Retorna una string con la respuesta del storedProcedure</returns> public EnvioPaquete ActualizarPrecioEnvio(EnvioPaquete oEnvio) { string client = ""; IConexion conexion = new Conexion(); DataTable dt = new DataTable(); using (SqlConnection conn = conexion.conexion()) { try { string query = @"PA_ModificarPrecio"; SqlCommand comm = new SqlCommand(query, conn); comm.CommandType = CommandType.StoredProcedure; comm.Parameters.AddWithValue("@TipoEnvio", oEnvio.TipoEnvio); comm.Parameters.AddWithValue("@Precio", oEnvio.PrecioRango); comm.Parameters.AddWithValue("@KilometroInicial", oEnvio.KilometroInicial); comm.Parameters.AddWithValue("@KilometroFinal", oEnvio.KilometroFinal); SqlDataReader reader = comm.ExecuteReader(); while (reader.Read()) { client = oEnvio.TipoEnvio; } return(this.MostrarXID(oEnvio.TipoEnvio)); } catch (SqlException sqlError) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } catch (Exception er) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } finally { conn.Close(); } } }
/// <summary> /// Método que busca precios por ID /// </summary> /// <param name="id">ID</param> /// <returns>Retorna el Envio que se encuentre</returns> public EnvioPaquete MostrarXID(string id) { EnvioPaquete EnvioPaquete = new EnvioPaquete(); IConexion conexion = new Conexion(); DataSet dt = new DataSet(); using (SqlConnection conn = conexion.conexion()) { try { SqlCommand cmd = new SqlCommand(@"PA_MostrarEnvioXID", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", id); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); foreach (DataRow dr in dt.Tables[0].Rows) { EnvioPaquete.TipoEnvio = dr["TipoEnvio"].ToString(); EnvioPaquete.PrecioRango = Convert.ToDouble(dr["PrecioRango"].ToString()); EnvioPaquete.KilometroInicial = Convert.ToInt32(dr["KilometroInicial"].ToString()); EnvioPaquete.KilometroFinal = Convert.ToInt32(dr["KilometroFinal"].ToString()); } } catch (SqlException sqlError) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateSQLExceptionsErrorDetails(sqlError)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } catch (Exception er) { StringBuilder msg = new StringBuilder(); msg.AppendFormat(Utilitarios.CreateGenericErrorExceptionDetail(er)); _MyLogControlEventos.ErrorFormat("Error {0}", msg.ToString()); throw; } finally { conn.Close(); } } return(EnvioPaquete); }