Beispiel #1
0
        //Pulsa Section
        public void AddPulsa()
        {
            int    id   = 0;
            string nohp = "";
            int    harga;

            do
            {
                Console.Write("Input NoHp: ");
                nohp = Console.ReadLine();
            } while (nohp.Equals(""));

            do
            {
                Console.Write("Input Harga Pulsa: ");
                harga = Convert.ToInt32(Console.ReadLine());
            } while (harga < 0);


            Pulsa pulsa = new Pulsa(id, harga, nohp);

            pulsaRepository.Insert(pulsa);

            Console.WriteLine("Insert Data Success!");
            Console.ReadKey();
        }
Beispiel #2
0
        public void UpdatePulsa()
        {
            List <Pulsa> listPulsa = pulsaRepository.View();

            if (listPulsa.Count == 0)
            {
                Console.WriteLine(" ");
                Console.WriteLine("There is no data here ....");
            }
            else
            {
                int i = 1;
                foreach (var item in listPulsa)
                {
                    Console.WriteLine("");
                    Console.WriteLine("Pulsa {0}", i++);
                    Console.WriteLine("================");
                    Console.WriteLine("Nama : " + item.NoHp);
                    Console.WriteLine("Harga : " + item.Harga);
                    Console.WriteLine();
                }

                int idx = -1;
                do
                {
                    Console.Write("Barang Index [1-{0}] [type `0` to exit]: ", listPulsa.Count);
                    idx = int.Parse(Console.ReadLine());
                } while (idx < 0 || idx > listPulsa.Count);
                if (idx != 0)
                {
                    int    id      = listPulsa.ElementAt(idx - 1).Id;
                    string newnohp = "";
                    int    newharga;

                    do
                    {
                        Console.Write("Input NoHp: ");
                        newnohp = Console.ReadLine();
                    } while (newnohp.Equals(""));

                    do
                    {
                        Console.Write("Input Harga Pulsa: ");
                        newharga = Convert.ToInt32(Console.ReadLine());
                    } while (newharga < 0);


                    Pulsa pulsa = new Pulsa(id, newharga, newnohp);
                    pulsaRepository.Update(pulsa);

                    Console.WriteLine("Update Data Success!");
                    Console.ReadKey();
                }
            }
        }
Beispiel #3
0
        public void Insert(Pulsa pulsa)
        {
            string query = "INSERT INTO Pulsa VALUES(@NoHp, @Harga)";

            command.Parameters.Add("@NoHp", SqlDbType.VarChar, 255).Value = pulsa.NoHp;
            command.Parameters.Add("@Harga", SqlDbType.Int).Value         = pulsa.Harga;

            command.Connection  = connection;
            command.CommandType = CommandType.Text;
            command.CommandText = query;

            connection.Open();

            command.ExecuteNonQuery();

            connection.Close();
            command.Dispose();
        }
Beispiel #4
0
        public void Update(Pulsa pulsa)
        {
            string query = "UPDATE Pulsa SET [NoHp] = @NoHp2, Harga = @Harga2 WHERE ID = @ID";

            command.Parameters.Add("@ID", SqlDbType.Int).Value             = pulsa.Id;
            command.Parameters.Add("@NoHp2", SqlDbType.VarChar, 255).Value = pulsa.NoHp;
            command.Parameters.Add("@Harga2", SqlDbType.Int).Value         = pulsa.Harga;

            command.Connection  = connection;
            command.CommandType = CommandType.Text;
            command.CommandText = query;

            connection.Open();

            command.ExecuteNonQuery();

            connection.Close();
            command.Dispose();
        }
Beispiel #5
0
        public List <Pulsa> View()
        {
            SqlDataReader reader;

            List <Pulsa> listPulsa = new List <Pulsa>();

            string query = "SELECT * FROM Pulsa";

            command.Connection  = connection;
            command.CommandType = CommandType.Text;
            command.CommandText = query;

            connection.Open();

            reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    int    id    = Convert.ToInt32(reader["ID"].ToString());
                    int    harga = Convert.ToInt32(reader["Harga"].ToString());
                    string nohp  = reader["NoHp"].ToString();

                    Pulsa pulsa = new Pulsa(id, harga, nohp);

                    listPulsa.Add(pulsa);
                }
            }

            reader.Close();
            connection.Close();
            command.Dispose();

            return(listPulsa);
        }