c#



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        int harga;
        double diskon = 0;
        int total = 0;
        int totalbayar = 0;
        int cash = 0;
        int kembali = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "1111")
            {
                harga = 45000;
                textBox1.Text = "Mouse";
                textBox2.Text = "Rp "+ harga;
                numericUpDown1.Focus();
            }
            else if (comboBox1.Text == "2222")
            {
                harga = 65000;
                textBox1.Text = "KeyBoard";
                textBox2.Text = "Rp " + harga;
                numericUpDown1.Focus();
            }
            else if (comboBox1.Text == "3333")
            {
                harga = 200000;
                textBox1.Text = "Speaker";
                textBox2.Text = "Rp " + harga;
                numericUpDown1.Focus();
            }
            else if (comboBox1.Text == "4444")
            {
                harga = 450000;
                textBox1.Text = "Harddisk 500Gb";
                textBox2.Text = "Rp " + harga;
                numericUpDown1.Focus();
            }
            else if (comboBox1.Text == "5555")
            {
                harga = 80000;
                textBox1.Text = "Flashdisk 4Gb";
                textBox2.Text = "Rp " + harga;
                numericUpDown1.Focus();
            }
            else if (comboBox1.Text == "6666")
            {
                harga = 150000;
                textBox1.Text = "WebCam";
                textBox2.Text = "Rp " + harga;
                numericUpDown1.Focus();
            }
            else {
                textBox1.Text = "";
                textBox2.Text = "";
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            hapus();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "Input")
            {
                groupBox1.Enabled = true;
                groupBox2.Enabled = true;
                groupBox3.Enabled = true;
              
                button2.Enabled = true;
                comboBox1.Focus();
                button1.Text = "Hitung";

            }else if (button1.Text == "Hitung")
       {
                hitung();
                if (radioButton1.Checked == true)
                {
                    if (inputcash.Text == "")
                    {
                        MessageBox.Show("Masukkan jumlah uang cash!!", "Peringatan", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        inputcash.Focus();
                    }
                }
                else if (radioButton2.Checked == true)
                {
                    inputcash.Text = "";
                    tcash.Text = "";
                    tkembali.Text = "";
                }
                cash = Convert.ToInt32(inputcash.Text);
                kembali = (cash - totalbayar);
                tampil();
       }
          
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            hapus();
            button1.Text = "Input";
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            groupBox5.Enabled = true;
            inputcash.Enabled = true;
            hitung();
            tampil();
        }

        public void hapus()
        {
            groupBox1.Enabled = false;
            groupBox3.Enabled = false;
            groupBox5.Enabled = false;
            button2.Enabled = false;

            comboBox1.Items.Clear();
            comboBox1.Items.Add("1111");
            comboBox1.Items.Add("2222");
            comboBox1.Items.Add("3333");
            comboBox1.Items.Add("4444");
            comboBox1.Items.Add("5555");
            comboBox1.Items.Add("6666");

            comboBox1.Text = "Pilih";
            textBox1.Text = "";
            textBox2.Text = "";
            inputcash.Text = "";
          
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            inputcash.Enabled = false;
            diskon = 0;
            total = 0;
            totalbayar = 0;
            cash = 0;
            kembali = 0;
            tampil();
        }

        public void tampil()
        {
            tsubtotal.Text = "Rp " + Convert.ToString(total);
            tdiskon.Text = "Rp " + Convert.ToString(diskon);
            ttotal.Text = "Rp " + Convert.ToString(totalbayar);
            tcash.Text = "Rp " + (cash).ToString();
            tkembali.Text = "Rp " + (kembali).ToString();
        }

        public void hitung()
        {
            total = (harga * Convert.ToInt32(numericUpDown1.Value));
            if (radioButton1.Checked == true)
            {
                diskon = Convert.ToInt32(0.1 * total);
            }
            else if (radioButton2.Checked == true)
            {
                diskon = Convert.ToInt32(0.05 * total);
            }

            totalbayar = Convert.ToInt32(total - diskon);
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            groupBox5.Enabled = false;
            inputcash.Text = "";
            hitung();
            cash = 0;
            kembali = 0;
            tampil();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void tdiskon_TextChanged(object sender, EventArgs e)
        {

        }

    }
}

Tidak ada komentar: