Ejemplo n.º 1
0
        public List <COURIER> GetDataByid(int id)
        {
            List <COURIER> items = new List <COURIER>();

            using (var conn = new SqlConnection(connString))
            {
                Message = "";
                try
                {
                    conn.Open();
                    SqlCommand command = new SqlCommand("SELECT [id], [courier_name] FROM Courier WHERE id = @id", conn);
                    command.Parameters.AddWithValue("@id", id);
                    SqlDataReader reader = command.ExecuteReader();
                    COURIER       item   = new COURIER();
                    while (reader.Read())
                    {
                        item = new COURIER();
                        if (reader[0] != DBNull.Value)
                        {
                            item.id = Convert.ToInt32(reader[0]);
                        }
                        if (reader[1] != DBNull.Value)
                        {
                            item.courier_name = Convert.ToString(reader[1]);
                        }
                        items.Add(item);
                    }
                }
                catch (Exception ex)
                {
                    Message = ex.Message;
                }
            }
            return(items);
        }
Ejemplo n.º 2
0
 public void Update(COURIER courier)
 {
     using (var conn = new SqlConnection(connString))
     {
         try
         {
             Message = "";
             conn.Open();
             SqlCommand command = new SqlCommand("UPDATE Courier SET courier_name = @courier_name WHERE id = @id", conn);
             command.CommandType = System.Data.CommandType.Text;
             if (courier.id != null)
             {
                 command.Parameters.AddWithValue("@id", courier.id);
             }
             else
             {
                 command.Parameters.AddWithValue("@id", DBNull.Value);
             }
             if (courier.courier_name != null)
             {
                 command.Parameters.AddWithValue("@courier_name", courier.courier_name);
             }
             else
             {
                 command.Parameters.AddWithValue("@courier_name", DBNull.Value);
             }
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Message = ex.Message;
         }
     }
 }
Ejemplo n.º 3
0
 public void Add(COURIER courier)
 {
     using (var conn = new SqlConnection(connString))
     {
         try
         {
             Message = "";
             conn.Open();
             SqlCommand command = new SqlCommand("INSERT INTO Courier ([id], [courier_name]) VALUES(@id, @courier_name)", conn);
             command.CommandType = System.Data.CommandType.Text;
             if (courier.id != null)
             {
                 command.Parameters.AddWithValue("@id", courier.id);
             }
             else
             {
                 command.Parameters.AddWithValue("@id", DBNull.Value);
             }
             if (courier.courier_name != null)
             {
                 command.Parameters.AddWithValue("@courier_name", courier.courier_name);
             }
             else
             {
                 command.Parameters.AddWithValue("@courier_name", DBNull.Value);
             }
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Message = ex.Message;
         }
     }
 }
Ejemplo n.º 4
0
 public void Remove(COURIER id)
 {
     using (var conn = new SqlConnection(connString))
     {
         try
         {
             Message = "";
             conn.Open();
             SqlCommand command = new SqlCommand("DELETE Courier WHERE id = @id", conn);
             command.CommandType = System.Data.CommandType.Text;
             if (id.id != null)
             {
                 command.Parameters.AddWithValue("@id", id.id);
             }
             else
             {
                 command.Parameters.AddWithValue("@id", DBNull.Value);
             }
             command.ExecuteNonQuery();
         }
         catch (Exception ex)
         {
             Message = ex.Message;
         }
     }
 }
Ejemplo n.º 5
0
        public void Delete(COURIER courier)
        {
            COURIERRepository rep = new COURIERRepository(connectionString);

            rep.Remove(courier);
        }
Ejemplo n.º 6
0
        public void Put(COURIER courier)
        {
            COURIERRepository rep = new COURIERRepository(connectionString);

            rep.Update(courier);
        }
Ejemplo n.º 7
0
        public void Post(COURIER courier)
        {
            COURIERRepository rep = new COURIERRepository(connectionString);

            rep.Add(courier);
        }