Ini SC
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace _
{
public partial class Form1 : Form
{
MySqlConnection conn = new MySqlConnection("server=localhost; database=db_ujianvisual2; uid=root; pwd=persibsalawasna");
MySqlCommand cmd;
MySqlDataAdapter adp;
int harga;
int banyaknya;
int total;
int bayar;
int kembalian;
public Form1()
{
InitializeComponent();
//testkoneksi();
BuatGrid();
cmbmakanan();
}
private void testkoneksi()
{
try
{
conn.Open();
MessageBox.Show("terkoneksi");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void BuatGrid()
{
dataGridView1.ColumnCount = 6;
dataGridView1.Columns[0].Name = "Kode";
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Name = "Menu";
dataGridView1.Columns[2].Name = "Kategori";
dataGridView1.Columns[2].Visible = false;
dataGridView1.Columns[3].Name = "Deskripsi";
dataGridView1.Columns[3].Visible = false;
dataGridView1.Columns[4].Name = "Harga";
dataGridView1.Columns[5].Name = "Foto";
dataGridView1.Columns[5].Visible = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.MultiSelect = false;
dataGridView1.ReadOnly = true;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
private void alirData(string kategori)
{
dataGridView1.Rows.Clear();
string query = "SELECT * FROM tb_barang WHERE id_kategori = '" + kategori + "'";
cmd = new MySqlCommand(query, conn);
try
{
conn.Open();
adp = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow r in dt.Rows)
{
dataGridView1.Rows.Add(r[0].ToString(),
r[1].ToString(),
r[2].ToString(),
r[3].ToString(),
r[4].ToString(),
r[5].ToString());
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cmbmakanan()
{
string query = "Select DISTINCT id_kategori From tb_barang";
cmd = new MySqlCommand(query, conn);
try
{
conn.Open();
adp = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow r in dt.Rows)
{
comboBox1.Items.Add(r[0].ToString());
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string par = comboBox1.SelectedItem.ToString();
alirData(par);
}
private void btn_order_Click(object sender, EventArgs e)
{
if (!listBox1.Items.Contains(dataGridView1.SelectedRows[0].Cells[1].Value.ToString()))
{
listBox1.Items.Add(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
}
Totalbyr();
}
private void btn_hapus_Click(object sender, EventArgs e)
{
int a = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(a);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_namamenu.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
txt_harga.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
//pictureBox1.Image = Image.FromFile(dataGridView1.SelectedRows[0].Cells[5].Value.ToString());
pictureBox1.ImageLocation = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
richTextBox1.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
}
private void Totalbyr()
{
harga = int.Parse(txt_harga.Text);
banyaknya = int.Parse(txt_banyak.Text);
total += (harga * banyaknya);
txt_totalbayar.Text = total.ToString();
}
private void SyaratBayar()
{
bayar = int.Parse(txt_bayar.Text);
if (bayar >= total)
{
kembalian = bayar - total;
txt_kembalian.Text = kembalian.ToString();
}
else
{
MessageBox.Show("Uang anda Kurang");
}
}
private void btn_bayar_Click(object sender, EventArgs e)
{
SyaratBayar();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace _
{
public partial class Form1 : Form
{
MySqlConnection conn = new MySqlConnection("server=localhost; database=db_ujianvisual2; uid=root; pwd=persibsalawasna");
MySqlCommand cmd;
MySqlDataAdapter adp;
int harga;
int banyaknya;
int total;
int bayar;
int kembalian;
public Form1()
{
InitializeComponent();
//testkoneksi();
BuatGrid();
cmbmakanan();
}
private void testkoneksi()
{
try
{
conn.Open();
MessageBox.Show("terkoneksi");
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void BuatGrid()
{
dataGridView1.ColumnCount = 6;
dataGridView1.Columns[0].Name = "Kode";
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Name = "Menu";
dataGridView1.Columns[2].Name = "Kategori";
dataGridView1.Columns[2].Visible = false;
dataGridView1.Columns[3].Name = "Deskripsi";
dataGridView1.Columns[3].Visible = false;
dataGridView1.Columns[4].Name = "Harga";
dataGridView1.Columns[5].Name = "Foto";
dataGridView1.Columns[5].Visible = false;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.AllowUserToDeleteRows = false;
dataGridView1.MultiSelect = false;
dataGridView1.ReadOnly = true;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
}
private void alirData(string kategori)
{
dataGridView1.Rows.Clear();
string query = "SELECT * FROM tb_barang WHERE id_kategori = '" + kategori + "'";
cmd = new MySqlCommand(query, conn);
try
{
conn.Open();
adp = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow r in dt.Rows)
{
dataGridView1.Rows.Add(r[0].ToString(),
r[1].ToString(),
r[2].ToString(),
r[3].ToString(),
r[4].ToString(),
r[5].ToString());
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void cmbmakanan()
{
string query = "Select DISTINCT id_kategori From tb_barang";
cmd = new MySqlCommand(query, conn);
try
{
conn.Open();
adp = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
foreach (DataRow r in dt.Rows)
{
comboBox1.Items.Add(r[0].ToString());
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string par = comboBox1.SelectedItem.ToString();
alirData(par);
}
private void btn_order_Click(object sender, EventArgs e)
{
if (!listBox1.Items.Contains(dataGridView1.SelectedRows[0].Cells[1].Value.ToString()))
{
listBox1.Items.Add(dataGridView1.SelectedRows[0].Cells[1].Value.ToString());
}
Totalbyr();
}
private void btn_hapus_Click(object sender, EventArgs e)
{
int a = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(a);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
txt_namamenu.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
txt_harga.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
//pictureBox1.Image = Image.FromFile(dataGridView1.SelectedRows[0].Cells[5].Value.ToString());
pictureBox1.ImageLocation = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
richTextBox1.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
}
private void Totalbyr()
{
harga = int.Parse(txt_harga.Text);
banyaknya = int.Parse(txt_banyak.Text);
total += (harga * banyaknya);
txt_totalbayar.Text = total.ToString();
}
private void SyaratBayar()
{
bayar = int.Parse(txt_bayar.Text);
if (bayar >= total)
{
kembalian = bayar - total;
txt_kembalian.Text = kembalian.ToString();
}
else
{
MessageBox.Show("Uang anda Kurang");
}
}
private void btn_bayar_Click(object sender, EventArgs e)
{
SyaratBayar();
}
}
}
0 komentar:
Posting Komentar