UAS Pemrograman Visual
“C# - Database”
Oleh :
Andriyan Dwi P. (115623003)
D3 MANAJEMEN INFORMATIKA A
JURUSAN TEKNIK ELEKTR...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
1 | P a g e
SOAL UJIAN
1. Buat aplikasi yang menghasilkan ouput di ba...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
2 | P a g e
No.1)
CONSOLE
a. Source code :
using System;
using System...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
3 | P a g e
b. Source code :
using System;
using System.Collections.G...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
4 | P a g e
c. Source code :
using System;
using System.Collections.G...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
5 | P a g e
d. Source code :
using System;
using System.Collections.G...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
6 | P a g e
Screenshoot :
WINDOWS FORM
Source code :
using System;
us...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
7 | P a g e
richTxtHasil.AppendText(Environment.NewLine);
}
}
private...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
8 | P a g e
}
}
c = c - 1;
}
richTxtHasil.AppendText(Environment.NewL...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
9 | P a g e
No. 2) Database : MySQL
LOGIN
Source Code :
using System;...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
10 | P a g e
MySqlConnection myConn = new MySqlConnection(myConnectio...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
11 | P a g e
{
e.Cancel = true;
}
}
}
}
Screenshoot :
Setelah berhasi...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
12 | P a g e
namespace UAS_no2
{
public partial class MenuUtama : For...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
13 | P a g e
while (myReader.Read())
{
string sNama = myReader.GetStr...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
14 | P a g e
"values('" + this.txtID.Text + "','" + this.txtFname.Tex...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
15 | P a g e
fillCombo();
}
private void btnHapus_Click(object sender...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
16 | P a g e
string sUmur = myReader.GetString("umur");
txtID.Text = ...
[LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013
17 | P a g e
private void rbtnLaki_CheckedChanged(object sender, Even...
Upcoming SlideShare
Loading in...5
×

Pemrograman visual

363

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
363
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Pemrograman visual

  1. 1. UAS Pemrograman Visual “C# - Database” Oleh : Andriyan Dwi P. (115623003) D3 MANAJEMEN INFORMATIKA A JURUSAN TEKNIK ELEKTRO FAKULTAS TEKNIK UNIVERSITAS NEGERI SURABAYA 2013
  2. 2. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 1 | P a g e SOAL UJIAN 1. Buat aplikasi yang menghasilkan ouput di bawah ini ; a) ******* b) * ****** ** ***** *** **** **** *** ***** ** ****** * ******* c) ******* d)* * ****** ** ** ***** *** *** **** **** **** *** ***** ***** ** ****** ****** * ************** ** *** **** ***** ****** ******* 2. Buat aplikasi database yang terdiri dari form Login,form input data(tambah,edit,simpan,delete,batal) database yang digunakan : mysql, sqlserver express, posgresql Nb : soal no.2 semakin lengkap aplikasinya semakin baik nilainya.
  3. 3. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 2 | P a g e No.1) CONSOLE a. Source code : using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace UAS_no1 { class a { static void Main(string[] args) { string lagi; do { int a, i, j; Console.WriteLine("Berapa Baris Bintang ?"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("-----------------------------"); for (i = a; i >= 1; i--) { for (j = i; j >= 1; j--) { Console.Write("*"); } Console.WriteLine(); } Console.Write("Apakah Anda ingin lagi ?[y/t] n"); lagi = Convert.ToString(Console.ReadLine()); } while (lagi == "y" || lagi == "Y"); } } } Screenshoot :
  4. 4. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 3 | P a g e b. Source code : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UAS_1b { class b { static void Main(string[] args) { string lagi; do { int a, i, j; Console.WriteLine("Berapa Baris Bintang ?"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("-----------------------------"); for (i = 1; i <= a; i++) { for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.Write("Apakah Anda ingin lagi ?[y/t] n"); lagi = Convert.ToString(Console.ReadLine()); } while (lagi == "y" || lagi == "Y"); } } } Screenshoot :
  5. 5. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 4 | P a g e c. Source code : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UAS_1c { class c { static void Main(string[] args) { string lagi; do { int a, i, j; Console.WriteLine("Berapa Baris Bintang ?"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("-----------------------------"); for (i = a; i >= 1; i--) { for (j = i; j >= 1; j--) { Console.Write("*"); } Console.WriteLine(); } for (i = 1; i <= a; i++) { for (j = 1; j <= i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.Write("Apakah Anda ingin lagi ?[y/t] n"); lagi = Convert.ToString(Console.ReadLine()); } while (lagi == "y" || lagi == "Y"); } } } Screenshoot :
  6. 6. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 5 | P a g e d. Source code : using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace UAS_1d { class d { static void Main(string[] args) { string lagi; do { int a, i, j; Console.WriteLine("Berapa Baris Bintang ?"); a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("-----------------------------"); { int b, c, d; d = 1; c = a - 1; Console.Write("n"); for (i = 0; i < a * 2 - 1; i++) { if (i < a) { for (j = 0; j < a * 2 - 1; j++) { b = a - c; if ((j < b) || (j >= (b + 2 * c - 1))) { Console.Write("*"); } else { Console.Write(" "); } } c = c - 1; } Console.WriteLine(); } } Console.Write("Apakah Anda ingin lagi ?[y/t] n"); lagi = Convert.ToString(Console.ReadLine()); } while (lagi == "y" || lagi == "Y"); } } }
  7. 7. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 6 | P a g e Screenshoot : WINDOWS FORM Source code : 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 UAS_no1 { public partial class UAS_1 : Form { public UAS_1() { InitializeComponent(); } int a, i, j; private void btnReset_Click(object sender, EventArgs e) { txtBaris.ResetText(); richTxtHasil.ResetText(); } private void btnA_Click(object sender, EventArgs e) { a = System.Convert.ToInt32(txtBaris.Text); for (i = a; i >= 1; i--) { for (j = i; j >= 1; j--) { richTxtHasil.AppendText("*"); }
  8. 8. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 7 | P a g e richTxtHasil.AppendText(Environment.NewLine); } } private void btnB_Click(object sender, EventArgs e) { a = System.Convert.ToInt32(txtBaris.Text); for (i = 1; i <= a; i++) { for (j = 1; j <= i; j++) { richTxtHasil.AppendText("*"); } richTxtHasil.AppendText(Environment.NewLine); } } private void btnC_Click(object sender, EventArgs e) { a = System.Convert.ToInt32(txtBaris.Text); for (i = a; i >= 1; i--) { for (j = i; j >= 1; j--) { richTxtHasil.AppendText("*"); } richTxtHasil.AppendText(Environment.NewLine); } for (i = 1; i <= a; i++) { for (j = 1; j <= i; j++) { richTxtHasil.AppendText("*"); } richTxtHasil.AppendText(Environment.NewLine); } } private void btnD_Click(object sender, EventArgs e) { int b, c, d; d = 1; c = a - 1; a = System.Convert.ToInt32(txtBaris.Text); Console.Write("n"); for (i = 0; i < a * 2 - 1; i++) { if (i < a) { for (j = 0; j < a * 2 - 1; j++) { b = a - c; if ((j < b) || (j >= (b + 2 * c - 1))) { richTxtHasil.AppendText("*"); } else { richTxtHasil.AppendText(" ");
  9. 9. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 8 | P a g e } } c = c - 1; } richTxtHasil.AppendText(Environment.NewLine); } } } } Screenshoot :
  10. 10. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 9 | P a g e No. 2) Database : MySQL LOGIN Source Code : 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 MySql.Data.MySqlClient; namespace UAS_no2 { public partial class Login : Form { public Login() { InitializeComponent(); txtPassword.PasswordChar = '*'; txtPassword.MaxLength = 9; } private void btnLogin_Click(object sender, EventArgs e) { try { string myConnection = "datasource=localhost;port=3306;username=root;password=";
  11. 11. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 10 | P a g e MySqlConnection myConn = new MySqlConnection(myConnection); MySqlCommand SelectCommand = new MySqlCommand("select * from visual.login where username='" + this.txtUsername.Text + "' and password='" + this.txtPassword.Text + "' ;", myConn); MySqlDataReader myReader; myConn.Open(); myReader = SelectCommand.ExecuteReader(); int count = 0; while (myReader.Read()) { count = count + 1; } if (count == 1) { MessageBox.Show("Username dan password Anda benar"); this.Hide(); MenuUtama f2 = new MenuUtama(); f2.ShowDialog(); } else if (count > 1) { MessageBox.Show("Duplicate Username dan Password . . . Access denied"); } else { MessageBox.Show("Username dan password Anda Salah. . . Please try again !"); myConn.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnReset_Click(object sender, EventArgs e) { txtUsername.ResetText(); txtPassword.ResetText(); } private void Login_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dialog = MessageBox.Show("Beneran sudah selesai nie ? hhe", "Exit", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { Application.Exit(); } else if (dialog == DialogResult.No)
  12. 12. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 11 | P a g e { e.Cancel = true; } } } } Screenshoot : Setelah berhasil melakukan proses login, user akan langsung masuk ke Form Menu Utama, dimana pada form ini proses Insert, Update, Delete dan proses menampilkan data terjadi. Menu Utama Source Code : 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.IO; using MySql.Data.MySqlClient;
  13. 13. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 12 | P a g e namespace UAS_no2 { public partial class MenuUtama : Form { public MenuUtama() { InitializeComponent(); fillCombo(); load_table(); Load_chart(); } string kelamin; void Load_chart() { string constring = "datasource=localhost;port=3306;username=root;password="; string lihat = "select * from visual.biodata;"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdLihat = new MySqlCommand(lihat, conDatabase); MySqlDataReader myReader; try { conDatabase.Open(); myReader = cmdLihat.ExecuteReader(); while (myReader.Read()) { this.chart1.Series["Umur"].Points.AddXY(myReader.GetString("fname"), myReader.GetString("Umur")); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } void fillCombo() { string constring = "datasource=localhost;port=3306;username=root;password="; string lihat = "select * from visual.biodata;"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdLihat = new MySqlCommand(lihat, conDatabase); MySqlDataReader myReader; try { conDatabase.Open(); myReader = cmdLihat.ExecuteReader();
  14. 14. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 13 | P a g e while (myReader.Read()) { string sNama = myReader.GetString("fname"); comboBox1.Items.Add(sNama); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } void load_table() { string constring = "datasource=localhost;port=3306;username=root;password="; string lihat = "select idbiodata as 'ID', fname as 'First Name', lname as 'Last Name', Umur, gender as 'Jenis Kelamin', tanggallahir as 'Tanggal Lahir' from visual.biodata;"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdLihat = new MySqlCommand(lihat, conDatabase); try { MySqlDataAdapter sda = new MySqlDataAdapter(); sda.SelectCommand = cmdLihat; DataTable dbdataset = new DataTable(); sda.Fill(dbdataset); BindingSource bSource = new BindingSource(); bSource.DataSource = dbdataset; dataGridView1.DataSource = bSource; sda.Update(dbdataset); } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void btnSimpan_Click(object sender, EventArgs e) { byte[] imageBt= null; FileStream fstream = new FileStream(this.txtImage_loc.Text, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fstream); imageBt = br.ReadBytes((int)fstream.Length); string constring = "datasource=localhost;port=3306;username=root;password="; string insert = "insert into visual.biodata (idbiodata,fname,lname,umur,gender,tanggallahir,gambar)"+
  15. 15. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 14 | P a g e "values('" + this.txtID.Text + "','" + this.txtFname.Text + "','" + this.txtLname.Text + "','" + this.txtUmur.Text + "','"+kelamin+"','"+this.dateTimePicker1.Text+"','"+this.pictureBox1+"');"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdInsert = new MySqlCommand(insert, conDatabase); MySqlDataReader MyReader; try{ conDatabase.Open(); //cmdInsert.Parameters.Add(new MySqlParameter("@IMG", imageBt)); MyReader = cmdInsert.ExecuteReader(); MessageBox.Show("Tersimpan"); }catch(Exception ex) { MessageBox.Show(ex.Message); } load_table(); //fillCombo(); } private void btnReset_Click(object sender, EventArgs e) { txtID.ResetText(); txtFname.ResetText(); txtLname.ResetText(); txtUmur.ResetText(); } private void btnEdit_Click(object sender, EventArgs e) { string constring = "datasource=localhost;port=3306;username=root;password="; string update = "update visual.biodata set idbiodata='" + this.txtID.Text + "',fname='" + this.txtFname.Text + "',lname='" + this.txtLname.Text + "',umur='" + this.txtUmur.Text + "',tanggallahir='"+this.dateTimePicker1.Text+"' where idbiodata='" + this.txtID.Text + "';"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdUpdate = new MySqlCommand(update, conDatabase); MySqlDataReader myReader; try { conDatabase.Open(); myReader = cmdUpdate.ExecuteReader(); MessageBox.Show("Ter-update"); } catch (Exception ex) { MessageBox.Show(ex.Message); } load_table();
  16. 16. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 15 | P a g e fillCombo(); } private void btnHapus_Click(object sender, EventArgs e) { string constring = "datasource=localhost;port=3306;username=root;password="; string hapus = "delete from visual.biodata where idbiodata='" + this.txtID.Text + "';"; string lihat = "select * from visual.biodata"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdHapus = new MySqlCommand(hapus, conDatabase); MySqlCommand cmdLihat = new MySqlCommand(lihat, conDatabase); MySqlDataReader myReader; try { conDatabase.Open(); myReader = cmdHapus.ExecuteReader(); MessageBox.Show("Terhapus"); } catch (Exception ex) { MessageBox.Show(ex.Message); } load_table(); //fillCombo(); } //private void button1_Click(object sender, EventArgs e) //{ //string namestr = txtFname.Text; //comboBox1.Items.Add(namestr); //} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { string constring = "datasource=localhost;port=3306;username=root;password="; string lihat = "select * from visual.biodata where fname='" + comboBox1.Text + "'"; MySqlConnection conDatabase = new MySqlConnection(constring); MySqlCommand cmdLihat = new MySqlCommand(lihat, conDatabase); MySqlDataReader myReader; try { conDatabase.Open(); myReader = cmdLihat.ExecuteReader(); while (myReader.Read()) { string sID = myReader.GetString("idbiodata"); string sFname = myReader.GetString("fname"); string sLname = myReader.GetString("lname");
  17. 17. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 16 | P a g e string sUmur = myReader.GetString("umur"); txtID.Text = sID; txtFname.Text = sFname; txtLname.Text = sLname; txtUmur.Text = sUmur; //byte[] imgg = (byte[])(myReader["gambar"]); //if (imgg == null) //{ // pictureBox1.Image = null; // } // else // { // MemoryStream mStream = new MemoryStream(imgg); // pictureBox1.Image = System.Drawing.Image.FromStream(mStream); // } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex]; txtID.Text = row.Cells["ID"].Value.ToString(); txtFname.Text = row.Cells["First Name"].Value.ToString(); txtLname.Text = row.Cells["Last Name"].Value.ToString(); txtUmur.Text = row.Cells["Umur"].Value.ToString(); } } private void MenuUtama_FormClosing(object sender, FormClosingEventArgs e) { DialogResult dialog = MessageBox.Show("Beneran sudah selesai nie ? hhe", "Exit", MessageBoxButtons.YesNo); if (dialog == DialogResult.Yes) { Application.Exit(); } else if (dialog == DialogResult.No) { e.Cancel = true; } }
  18. 18. [LAPORAN UAS PEMROGRAMAN VISUAL] Kamis, 20 Juni 2013 17 | P a g e private void rbtnLaki_CheckedChanged(object sender, EventArgs e) { kelamin = "Laki-laki"; } private void rbtnPerempuan_CheckedChanged(object sender, EventArgs e) { kelamin = "Perempuan"; } private void btnLoadChart_Click(object sender, EventArgs e) { Load_chart(); } private void button1_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png"; dlg.Title = "Pilih Foto Diri"; if (dlg.ShowDialog() == DialogResult.OK) { string picloc = dlg.FileName.ToString(); txtImage_loc.Text = picloc; pictureBox1.ImageLocation = picloc; } } } } Screenshoot :

×