LISTING PROGRAM
1. home.cs
using System;
using System.Drawing;
using System.Windows.Forms;
namespace home1 {
public partial class home : Form {
public home() {
InitializeComponent(); }
void Button1Click(object sender, EventArgs e) {
if (username_box.Text=="admin" && pass_box.Text=="123"){ Form m=new MainForm();
this.Hide(); m.ShowDialog();
} }
void Button2Click(object sender, EventArgs e) {
DialogResult button= MessageBox.Show("EXIT from the app?","EXIT",
MessageBoxButtons.YesNo,MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if(button==DialogResult.Yes) Application.Exit(); }
} }
2. MainForm.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace home1 {
public partial class MainForm : Form {
public MainForm() {
InitializeComponent(); }
void ABOUTToolStripMenuItemClick(object sender, EventArgs e) {
Form c=new about(); c.Show();
}
void METODEToolStripMenuItemClick(object sender, EventArgs e) {
Form f=new metode(); f.Show();
}
void DATAToolStripMenuItemClick(object sender, EventArgs e) {
Form a=new datalahan(); a.Show(); }
void HELPToolStripMenuItemClick(object sender, EventArgs e) {
Form h=new help(); h.Show();
} }
}
3. datalahan.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq.Expressions;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.OleDb;
namespace home1 {
public partial class datalahan : Form {
string konfigur= "server=localhost;uid=root;password=;database =db_pasar;";
double c1,c2,c3,c4,c5,c6,c7,c8;
double c1_pm,c2_pm,c3_pm,c4_pm,c5_pm,c6_pm,c7_pm,c8_pm;
double c1_pm_ideal,c2_pm_ideal,c3_pm_ideal,c4_pm_ideal,c5_pm_i deal,c6_pm_ideal,c7_pm_ideal,c8_pm_ideal;
double c1_pm_gap,c2_pm_gap,c3_pm_gap,c4_pm_gap,c5_pm_gap,c6_pm _gap,c7_pm_gap,c8_pm_gap;
double cf,sf,skor;
double waktupmfix1=0,waktupmfix2=0; DateTime waktupmawal,waktupmakhir; string TimePM;
void Button1Click(object sender, EventArgs e) {
try
waktupmawal=DateTime.Now; hitungCF();
hitungSF(); hitungskor();
string MyConnection2 = "datasource=localhost;port=3306 ;username=root;password=";
string Query = "insert into db_pasar.pasar(nama,C1,C2,C3,C4,C5,C6,C7,C8)
values('" +this.namapasar.Text+ "','" +c1+ "','" +c2+ "','" +c3+ "','" +c4+ "','" +c5+ "','" +c6+ "','" +c7+ "','" +c8+ "');";
string Query2 = "insert into
db_pasar.pasar_pm(nama,C1,C2,C3,C4,C5,C6,C7,C8,ideal_c1,ideal_c2,ideal _c3,ideal_c4,ideal_c5,ideal_c6,ideal_c7,ideal_c8,gap_c1,gap_c2,gap_c3, gap_c4,gap_c5,gap_c6,gap_c7,gap_c8,core_factor,secondary_factor,skor) values('" +this.namapasar.Text+ "','" +c1_pm+ "','" +c2_pm+ "','" +c3_ pm+ "','" +c4_pm+ "','" +c5_pm+ "','" +c6_pm+ "','" +c7_pm+ "','" +c8_ pm+ "','" +c1_pm_ideal+ "','" +c2_pm_ideal+ "','" +c3_pm_ideal+ "','" +c4_pm_ideal+ "','" +c5_pm_ideal+ "','" +c6_pm_ideal+ "','" +c7_pm_ide al+ "','" +c8_pm_ideal+ "','" +c1_pm_gap+ "','" +c2_pm_gap+ "','" +c3_ pm_gap+ "','" +c4_pm_gap+ "','" +c5_pm_gap+ "','" +c6_pm_gap+ "','" +c 7_pm_gap+ "','" +c8_pm_gap+ "','" +cf+ "','" +sf+ "','" +skor+ "');"; MySqlConnection MyConn2
= new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataReader MyReader2; MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader(); MessageBox.Show("Save Data");
MyConn2.Close();
MySqlConnection konekpm = new MySqlConnection(MyConnection2); MySqlCommand
mycomand_pm= new MySqlCommand(Query2,konekpm); MySqlDataReader baca_pm;
konekpm.Open();
baca_pm=mycomand_pm.ExecuteReader(); konekpm.Close();
insertpasar();
waktupmakhir=DateTime.Now;
TimeSpan waktupm=waktupmakhir.Subtract(waktupmawal); waktupmfix2=waktupm.TotalSeconds;
}
catch (Exception ex){
MessageBox.Show(ex.Message); } }
void insertpasar() {
try
{
string MyConnection2
= "datasource=localhost;port=3306;username=root;password="; string query2="insert into
MySqlCommand MyCommand3 = new MySqlCommand(query2, MyConn2);
MySqlDataReader MyReader2; MyConn2.Open();
MyReader2 = MyCommand3.ExecuteReader(); MyConn2.Close();
}
catch (Exception ex){
MessageBox.Show(ex.Message); }
}
void statuslahanSelectedIndexChanged(object sender, EventArgs e)
{
if (statuslahan.SelectedIndex==0){ c1=2;
c1_pm=2;
c1_pm_ideal=2-4; c1_pm_gap=3; }
else if (statuslahan.SelectedIndex==1){ c1=4;
c1_pm=4;
c1_pm_ideal=4-4; c1_pm_gap=5;
} }
void Unsur1SelectedIndexChanged(object sender, EventArgs e) {
if (unsur1.SelectedIndex==0){ c2=1;
c2_pm=1;
c2_pm_ideal=1-4; c2_pm_gap=2; }
else if (unsur1.SelectedIndex==1){ c2=2;
c2_pm=2;
c2_pm_ideal=2-4; c2_pm_gap=3; }
else if (unsur1.SelectedIndex==2){ c2=3;
c2_pm=3;
c2_pm_ideal=3-4; c2_pm_gap=4; }
else if (unsur1.SelectedIndex==3){ c2=4;
c2_pm=4;
else if (unsur1.SelectedIndex==4){ c2=5;
c2_pm=5;
c2_pm_ideal=5-4; c2_pm_gap=4.5; } }
void Unsur2SelectedIndexChanged(object sender, EventArgs e) {
if (unsur2.SelectedIndex==0){ c3=0;
c3_pm=0;
c3_pm_ideal=0-3; c3_pm_gap=3; }
else if (unsur2.SelectedIndex==1){ c3=1;
c3_pm=1;
c3_pm_ideal=1-3; c3_pm_gap=3; }
else if (unsur2.SelectedIndex==2){ c3=2;
c3_pm=2;
c3_pm_ideal=2-3; c3_pm_gap=4; }
else if (unsur2.SelectedIndex==3){ c3=3;
c3_pm=3;
c3_pm_ideal=3-3; c3_pm_gap=5; }
else if (unsur2.SelectedIndex==4){ c3=4;
c3_pm=4;
c3_pm_ideal=4-3; c3_pm_gap=4.5; }
else if (unsur2.SelectedIndex==5){ c3=5;
c3_pm=5;
c3_pm_ideal=5-3; c3_pm_gap=3.5; } }
void Unsur3SelectedIndexChanged(object sender, EventArgs e) {
if (unsur3.SelectedIndex==0){ c4=1;
c4_pm_ideal=1-3; c4_pm_gap=3; }
else if (unsur3.SelectedIndex==1){ c4=2;
c4_pm=2;
c4_pm_ideal=2-3; c4_pm_gap=4; }
else if (unsur3.SelectedIndex==2){ c4=3;
c4_pm=3;
c4_pm_ideal=3-3; c4_pm_gap=5; }
else if (unsur3.SelectedIndex==3){ c4=4;
c4_pm=4;
c4_pm_ideal=4-3; c4_pm_gap=4.5; }
else if (unsur3.SelectedIndex==4){ c4=5;
c4_pm=5;
c4_pm_ideal=5-3; c4_pm_gap=3.5; } }
void Persentase1SelectedIndexChanged(object sender, EventArgs e)
{
if (persentase1.SelectedIndex==0){ c5=1;
c5_pm=1;
c5_pm_ideal=1-4; c5_pm_gap=2; }
else if (persentase1.SelectedIndex==1){ c5=2;
c5_pm=2;
c5_pm_ideal=2-4; c5_pm_gap=3; }
else if (persentase1.SelectedIndex==2){ c5=3;
c5_pm=3;
c5_pm_ideal=3-4; c5_pm_gap=4; }
else if (persentase1.SelectedIndex==3){ c5=4;
c5_pm_ideal=4-4; c5_pm_gap=5;
} }
void Persentase2SelectedIndexChanged(object sender, EventArgs e)
{
if (persentase2.SelectedIndex==0){ c6=1;
c6_pm=1;
c6_pm_ideal=1-4; c6_pm_gap=2; }
else if (persentase2.SelectedIndex==1){ c6=2;
c6_pm=2;
c6_pm_ideal=2-4; c6_pm_gap=3; }
else if (persentase2.SelectedIndex==2){ c6=3;
c6_pm=3;
c6_pm_ideal=3-4; c6_pm_gap=4; }
else if (persentase2.SelectedIndex==3){ c6=4;
c6_pm=4;
c6_pm_ideal=4-4;
c6_pm_gap=5; }
}
void Persentase3SelectedIndexChanged(object sender, EventArgs e)
{
if (persentase3.SelectedIndex==0){ c7=1;
c7_pm=1;
c7_pm_ideal=1-4; c7_pm_gap=2; }
else if (persentase3.SelectedIndex==1){ c7=2;
c7_pm=2;
c7_pm_ideal=2-4; c7_pm_gap=3; }
else if (persentase3.SelectedIndex==2){ c7=3;
c7_pm=3;
}
else if (persentase3.SelectedIndex==3){ c7=4;
c7_pm=4;
c7_pm_ideal=4-4;
c7_pm_gap=5; }
}
void Persentase4SelectedIndexChanged(object sender, EventArgs e)
{
if (persentase4.SelectedIndex==0){ c8=1;
c8_pm=1;
c8_pm_ideal=1-4; c8_pm_gap=2; }
else if (persentase4.SelectedIndex==1){ c8=2;
c8_pm=2;
c8_pm_ideal=2-4; c8_pm_gap=3; }
else if (persentase4.SelectedIndex==2){ c8=3;
c8_pm=3;
c8_pm_ideal=3-4; c8_pm_gap=4; }
else if (persentase4.SelectedIndex==3){ c8=4;
c8_pm=4;
c8_pm_ideal=4-4;
c8_pm_gap=5; }
}
void Button4Click(object sender, EventArgs e) {
try
{
string MyConnection2
= "server=localhost;port=3306;username=root;password=";
string Query = "select * from db_pasar.pasar;"; MySqlConnection MyConn2
= new MySqlConnection(MyConnection2); MySqlCommand MyCommand2
= new MySqlCommand(Query, MyConn2); MyConn2.Open();
MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable(); MyAdapter.Fill(dTable);
dataGridView1.DataSource = dTable; MyConn2.Close();
string MyConnectionpm
= "server=localhost;port=3306;username=root;password=";
string Querypm = "select nama,c1,c2,c3,c4,c5,c6,c7,c8 from db_pasar.pasar_pm;";
MySqlConnection MyConnpm = new MySqlConnection(MyConnectionpm); MySqlCommand MyCommandpm
= new MySqlCommand(Querypm, MyConnpm); MyConnpm.Open();
MySqlDataAdapter MyAdapterpm = new MySqlDataAdapter();
MyAdapterpm.SelectCommand = MyCommandpm; DataTable dTablepm = new DataTable(); MyAdapterpm.Fill(dTablepm);
dataGridView2.DataSource = dTablepm; MyConnpm.Close();
}
catch (Exception ex){
MessageBox.Show(ex.Message); } }
void pm_ideal(){ try {
string MyConnectionpm
= "server=localhost;port=3306;username=root;password="; string Querypm = "select
nama,ideal_c1,ideal_c2,ideal_c3,ideal_c4,ideal_c5,ideal_c6,ideal_c7,id eal_c8 from db_pasar.pasar_pm;";
MySqlConnection MyConnpm = new MySqlConnection(MyConnectionpm); MySqlCommand MyCommandpm
= new MySqlCommand(Querypm, MyConnpm); MyConnpm.Open();
MySqlDataAdapter MyAdapterpm = new MySqlDataAdapter(); MyAdapterpm.SelectCommand = MyCommandpm;
DataTable dTablepm = new DataTable(); MyAdapterpm.Fill(dTablepm);
dataGridView3.DataSource = dTablepm; MyConnpm.Close();
}
catch(Exception ex){
MessageBox.Show(ex.Message); }
}
void pm_gap(){ try {
string MyConnectionpm
= "server=localhost;port=3306;username=root;password="; string Querypm = "select
nama,gap_c1,gap_c2,gap_c3,gap_c4,gap_c5,gap_c6,gap_c7,gap_c8 from db_pasar.pasar_pm;";
MySqlConnection MyConnpm = new MySqlConnection(MyConnectionpm); MySqlCommand MyCommandpm
MySqlDataAdapter MyAdapterpm = new MySqlDataAdapter();
MyAdapterpm.SelectCommand = MyCommandpm; DataTable dTablepm = new DataTable(); MyAdapterpm.Fill(dTablepm);
dataGridView4.DataSource = dTablepm; MyConnpm.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); }
}
void hitungCF(){ try{
cf=(c2_pm_gap+c3_pm_gap+c4_pm_gap+c5_pm_gap)/4; }
catch(Exception ex)
{
MessageBox.Show(ex.Message); }
}
void hitungSF(){ try{
sf=(c1_pm_gap+c6_pm_gap+c7_pm_gap+c8_pm_gap)/4; }
catch(Exception ex)
{
MessageBox.Show(ex.Message); }
}
void hitungskor(){ try{
skor=(cf*0.6)+(sf*0.4); }
catch(Exception ex)
{
MessageBox.Show(ex.Message); }
}
void Button3Click(object sender, EventArgs e) {
string namahapus =
dataGridView1.CurrentRow.Cells[0].Value.ToString(); string hapus="DELETE FROM pasar WHERE nama='"+ namahapus + "'";
string hapusrankSAW="DELETE FROM rankingpasar WHERE nama='"+ namahapus + "'";
string hapuspm="DELETE FROM pasar_pm WHERE nama='"+ namahapus + "'";
DialogResult result = MessageBox.Show("hapus
?","konfirmasi",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning); if(result==DialogResult.OK)
{
konek.Open();
cmd.ExecuteNonQuery();
konek.Close();
MySqlConnection konek1 = newMySqlConnection(konfigur); MySqlCommand cmd1
= new MySqlCommand(hapusrankSAW,konek1); konek1.Open();
cmd1.ExecuteNonQuery();
MySqlConnection konek2 = new MySqlConnection(konfigur);
MySqlCommand cmd2 = new MySqlCommand(hapuspm,konek2); konek2.Open();
cmd2.ExecuteNonQuery();
konek2.Close(); }
}
void Button5Click(object sender, EventArgs e) {
Form a=new MainForm(); a.Show();
this.Dispose(); }
} }
4. metode.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;
using System.Data.OleDb;
namespace home1 {
public partial class metode : Form {
string TimePM;
MySqlConnection koneksi2 =
new MySqlConnection("server=localhost;port=3306;username=root; password=");
double maxc1,maxc2,maxc3,maxc4,minc5,minc6,minc7,minc8; double tertinggi=0;
string lahanterbaik,temp_pm;
DateTime waktupmawal,waktupmakhir,waktusawawal,waktusawakhir;
public metode(string time){ InitializeComponent(); TimePM = time;
}
void Button1Click(object sender, EventArgs e) {
{
waktusawawal=DateTime.Now;
double hc1,hc2,hc3,hc4,hc5,hc6,hc7,hc8; string MyConnection2
= "server=localhost;port=3306;username=root;password="; MySqlConnection MyConn2
= new MySqlConnection(MyConnection2); MyConn2.Open();
MySqlCommand command1 = new MySqlCommand("select max(C1) from db_pasar.pasar",MyConn2);
maxc1=Convert.ToDouble(command1.ExecuteScalar().ToStri ng());
MySqlCommand command2 = new MySqlCommand("select max(C2) from db_pasar.pasar",MyConn2);
maxc2=Convert.ToDouble(command2.ExecuteScalar().ToStri ng());
MySqlCommand command3 = new MySqlCommand("select max(C3) from db_pasar.pasar",MyConn2);
maxc3=Convert.ToDouble(command3.ExecuteScalar().ToStri ng());
MySqlCommand command4 = new MySqlCommand("select max(C4) from db_pasar.pasar",MyConn2);
maxc4=Convert.ToDouble(command4.ExecuteScalar().ToStri ng());
MySqlCommand command5 = new MySqlCommand("select min(C5) from db_pasar.pasar",MyConn2);
minc5=Convert.ToDouble(command5.ExecuteScalar().ToStri ng());
MySqlCommand command6 = new MySqlCommand("select min(C6) from db_pasar.pasar",MyConn2);
minc6=Convert.ToDouble(command6.ExecuteScalar().ToStri ng());
MySqlCommand command7 = new MySqlCommand("select min(C7) from db_pasar.pasar",MyConn2);
minc7=Convert.ToDouble(command7.ExecuteScalar().ToStri ng());
MySqlCommand command8 = new MySqlCommand("select min(C8) from db_pasar.pasar",MyConn2);
minc8=Convert.ToDouble(command8.ExecuteScalar().ToStri ng());
MySqlCommand kueri = new MySqlCommand("SELECT * FROM db_pasar.pasar",MyConn2);
string temp;
MySqlDataReader dr;
dr = kueri.ExecuteReader();
while(dr.Read()) {
temp = dr["nama"].ToString();
hc4 = (Convert.ToDouble(dr["C4"]))/maxc4; hc5 = minc5/(Convert.ToDouble(dr["C5"])); hc6 = minc6/(Convert.ToDouble(dr["C6"])); hc7 = minc7/(Convert.ToDouble(dr["C7"]));
hc8 = minc8/(Convert.ToDouble(dr["C8"]));
double skor
= (hc1*3)+(hc2*4)+(hc3*4)+(hc4*4)+(hc5*5)+(hc6*5)+(hc7*5)+(hc8*5); if (tertinggi <=skor){
tertinggi=skor; lahanterbaik=temp; }
updateskorpasar(temp,skor); }
MyConn2.Close();
lihatcoredansecondary(); lihatskorpm();
}
catch (Exception ex) {
MessageBox.Show(ex.Message); }
lihatperangkinganpasar(); sawtinggi.Text=lahanterbaik;
waktusawakhir=DateTime.Now;
TimeSpan waktusaw=waktusawakhir.Subtract(waktusawawal); double waktusawfix=waktusaw.TotalMilliseconds;
timeSaw.Text=waktusawfix.ToString();
datatertinggi_pm(); timePM.Text=TimePM; }
void lihatcoredansecondary(){ try{
string MyConnection2
= "server=localhost;port=3306;username=root;password="; string Query = "select
nama,core_factor,secondary_factor from db_pasar.pasar_pm;"; MySqlConnection MyConn2
= new MySqlConnection(MyConnection2); MySqlCommand MyCommand2
= new MySqlCommand(Query, MyConn2); MyConn2.Open();
MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable(); MyAdapter.Fill(dTable);
dataGridView1.DataSource = dTable; string nama1=
dataGridView1.CurrentRow.Cells[0].Value.ToString(); MyConn2.Close();
}
catch (Exception ex) {
MessageBox.Show(ex.Message); }
void lihatskorpm(){ try{
string MyConnection2
= "server=localhost;port=3306;username=root;password="; string Query = "select nama,skor from db_pasar.pasar_pm ORDER BY skor DESC;";
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2
= new MySqlCommand(Query, MyConn2); MyConn2.Open();
MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable(); MyAdapter.Fill(dTable);
dataGridView2.DataSource = dTable;
string nama1=dataGridView2.CurrentRow.Cells[0].Value.T oString();
pmtinggi.Text=nama1 MyConn2.Close(); }
catch (Exception ex) {
MessageBox.Show(ex.Message); }
}
void lihatperangkinganpasar() {
try{
string MyConnection2
= "server=localhost;port=3306;username=root;password=";
string Query = "select * from db_pasar.rankingpasar ORDER BY skor DESC;";
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2
= new MySqlCommand(Query, MyConn2); MyConn2.Open();
MySqlDataAdapter MyAdapter = new MySqlDataAdapter(); MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable(); MyAdapter.Fill(dTable);
dataGridView4.DataSource = dTable; MyConn2.Close();
}catch(Exception){
MessageBox.Show("Ada Error"); }
} }