Senin, Oktober 30, 2017

Cara Membuat Program Laundry Sederhana Menggunakan Visual Studio

Asalamualaikum wr. wb

Di postingan kali ini mimin ingin berbagi sedikit pengetahuan tentang bahasa pemrograman visual studio C# atau biasa disebut C Sharp.

Apa Sih Visual Studio C Sharp?

Visual Studio C Sharp adalah sautu bahasa pemrograman yang berorientasi objek atau OOP (Object-Oriented Programming). Jadi Visual Studio C Sharp ini tampilan hasil programnya mengarah ke tampilan secara visual atau bukan tampilan seperti program console. lalu mengapa bukan tampilan console, karena program yang berbasis Visual / OOP yang paling banyak digandrungi oleh para programmer dunia. Selengkapnya .....


Ok langsung saja ke pembahasannya ya...

CARA MEMBUAT PROGRAM LAUNDRY DI VISUAL STUDIO C# 

Script Codingnya :

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;
using System.Data.SqlClient;
namespace ProjectLaundry
{
    public partial class Customer : Form
    {
        public Customer()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)

        {
            // TODO: This line of code loads data into the 'laundryDBDataSet.customer' table. You can move, or remove it, as needed.
            this.customerTableAdapter.Fill(this.laundryDBDataSet.customer);

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(global::ProjectLaundry.Properties.Settings.Default.LaundryDBConnectionString);
            try
            {

                string sql = "INSERT INTO customer(Id,nama,alamat,no_telp,berat_cucian,jenis_pakaian,total_bayar) values(" + txtID.Text + ",'" + txtNama.Text + "','" + txtAlamat.Text + "','" + txtTelp.Text + "','" + cmbBerat.Text + "','" + cmbJenis.Text + "','" + txtTotal.Text+ "')";

                SqlCommand exesql = new SqlCommand(sql, con);
                con.Open();
                exesql.ExecuteNonQuery();


                string c = txtID.Text;

                string i = txtNama.Text;
                string n = txtAlamat.Text;
                string t = txtTelp.Text;
                string a = cmbBerat.Text;
                string u = cmbJenis.Text;
                MessageBox.Show("INFORMASI DATA CUSTOMER!! \n\n" + "\n ID\t\t : " + c + "\n Nama\t\t : " + i + "\n Alamat\t\t : " + n + "\n No.Telp\t\t : " + t + "\n Berat\t\t : " + a + " Kg" + "\n Jenis Cucian\t : " + u + "\n");
                MessageBox.Show("Saved Succesfully!!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.customerTableAdapter.Fill(this.laundryDBDataSet.customer);

                txtTotal.Text = "";

               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                con.Close();
            }
        }

        private void btnBayar_Click(object sender, EventArgs e)

        {
            int total;
            int harga = 5000;
            int j = int.Parse(cmbBerat.Text);
            total = j * harga;

            MessageBox.Show("INFORMASI TRANSAKSI!! \n\n" + "Harga Awal\t: Rp."+harga+ "\nBerat Cucian\t: "+j+" Kg" + "\nRumusnya\t: " + "(Berat Cucian  X  Harga Awal)\t\n"+ "Jadi Total\t\t: Rp."+total+"\t");

            txtTotal.Text = total.ToString();
            
        }

        private void btnUpdate_Click(object sender, EventArgs e)

        {
            SqlConnection con = new SqlConnection(global::ProjectLaundry.Properties.Settings.Default.LaundryDBConnectionString);
            try
            {

                string sql = "UPDATE customer set nama='" + txtNama.Text +"', alamat='"+ txtAlamat.Text+ "', no_telp='"+ txtTelp.Text+ "', berat_cucian='"+ cmbBerat.Text + "', jenis_pakaian='"+ cmbJenis.Text+ "', total_bayar='"+ txtTotal.Text + "' WHERE Id='" + txtID.Text + "'";

                SqlCommand exesql = new SqlCommand(sql, con);
                con.Open();
                exesql.ExecuteNonQuery();

                MessageBox.Show("Updated Succesfully!!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.customerTableAdapter.Fill(this.laundryDBDataSet.customer);

            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                con.Close();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)

        {
            SqlConnection con = new SqlConnection(global::ProjectLaundry.Properties.Settings.Default.LaundryDBConnectionString);
            try
            {

                string sql = "DELETE FROM customer WHERE Id='" + txtID.Text + "'";

                SqlCommand exesql = new SqlCommand(sql, con);
                con.Open();
                exesql.ExecuteNonQuery();

                MessageBox.Show("Deleted Succesfully!!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.customerTableAdapter.Fill(this.laundryDBDataSet.customer);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                con.Close();
            }
        }

        private void txtReset_Click(object sender, EventArgs e)

        {
            txtID.Text = "";
            txtNama.Text = "";
            txtAlamat.Text = "";
            txtTelp.Text = "";
            cmbBerat.Text = "";
            cmbJenis.Text = "";
            txtTotal.Text = "";
        }
    }
}


Hasil Running Programnya Seperti Berikut.



Tampilan Ketika Running


Tampilan Ketika User Menginputkan Data





Previous Post
Next Post