0

Laporan dan Aplikasi rental menggunakan C sharp/ C# (5)

Posted by jujur on 3:26 PM

Psoude-Code


Form Login

==============
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 index
{
   public partial class login : Form
   {
       public string priviledge;
       private string sql;
       private DataTable tuser;
       private kon koneksi = new kon();
       private user iuser = new user();
       public string loggedId;
       public string loggedname;
       private kripto encript = new kripto();


       public login()
       {
           InitializeComponent();
       }


       private void login_Load(object sender, EventArgs e)
       {
           inisialisasi();
       }


       private void inisialisasi()
       {
           inama.Text = "";
           ipass.Text = "";
       }


       private void button1_Click(object sender, EventArgs e)
       {
           if (inama.Text == "")
           {
               MessageBox.Show(" Username Belum Terisi ","Informasi",MessageBoxButtons.OK,MessageBoxIcon.Information);
               inama.Focus();
           }
           else if (ipass.Text == "")
           {
               MessageBox.Show(" Password Belum Terisi ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
               ipass.Focus();
           }
           else
           {
               iuser.nama = inama.Text;
               iuser.password = ipass.Text;
               sql = "select*from operator where id='" + iuser.nama + "' and password='" + encript.enkripsi(iuser.password) + "'";
              tuser = koneksi.tampil_data(sql);
              if (tuser.Rows.Count == 0)
              {
                  MessageBox.Show(" Login Gagal ", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                  inisialisasi();
                  iuser.nama = "";
                  iuser.password = "";
                  inama.Focus();
              }
              else
              {
                  priviledge = tuser.Rows[0].ItemArray.GetValue(5).ToString();
                  loggedname = tuser.Rows[0].ItemArray.GetValue(1).ToString();
                  this.Hide();
                  home hom = new home(priviledge,loggedname,iuser.nama);
                  hom.Show();
              }
          }
       }


       private void button2_Click(object sender, EventArgs e)
       {
           Application.Exit();
       }
      
       private void ipass_KeyDown(object sender, KeyEventArgs e)
       {
           if (e.KeyCode == Keys.Enter)
           {
               button1_Click(sender, e);
           }
       }


   }
}


Form Home

=============
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 index
{
   public partial class home : Form
   {
       private kon koneksi = new kon();
       private string sql;
       private string priviledge= null;
       private string nama_user = "";
       private string id;
       private Fuser fuser = new Fuser();
       private DataTable tbpelanggan = new DataTable();
       private login log = new login();
       private pengembalian fpengembalian = null;
       private rental frental = null;
       private tampil_sopir sop = new tampil_sopir();
       private fmobil fmobil1 = new fmobil();
       private harga fsewa = new harga();
       private ubah_pass fubah = null;
       private report laporan = new report();
       public home(string x, string y, string z)
       {
           priviledge = x;
           InitializeComponent();
           nama_user = y;
           id = z;
       }


      private void home_Load(object sender, EventArgs e)
       {
           if (priviledge == "admin")
           {
               master_menu.Enabled = true;
               laporan_menu.Enabled = true;
               tsb_mobil.Enabled = true;
               tsb_pelanggan.Enabled = true;
               tsb_sopir.Enabled = true;
               tsb_user.Enabled = true;
               tsb_harga.Enabled = true;
               tsb_laporan.Enabled = true;
               user.Text = "Admin  :  " + nama_user + "  ";
           }
           else
           {
               master_menu.Enabled = false;
               laporan_menu.Enabled = false;
               tsb_mobil.Enabled = false;
               tsb_pelanggan.Enabled = false;
               tsb_sopir.Enabled = false;
               tsb_user.Enabled = false;
               tsb_harga.Enabled = false;
               tsb_laporan.Enabled = false;
               user.Text = "operator   :  " + nama_user + "  ";
           }
           
           hari.Text = ","+DateTimeOffset.Now.DayOfWeek.ToString()+"  ";
           tanggal.Text = "  " + DateTimeOffset.Now.Year.ToString() + " - " + DateTimeOffset.Now.Month.ToString() + " - " + DateTimeOffset.Now.Day.ToString()+"  ";
           frental = new rental(priviledge, nama_user);
           frental.MdiParent = this;
           frental.Show();
           sewaToolStripMenuItem.Enabled = false;
           tsb_sewa.Enabled = false;
        }


       private void kembali_aktif()
       {
           fpengembalian = new pengembalian();
           fpengembalian.MdiParent = this;
           frental.Close();
           frental = null;
           pengembalianToolStripMenuItem.Enabled = false;
           tsb_kembalian.Enabled = false;
           sewaToolStripMenuItem.Enabled = true;
           tsb_sewa.Enabled = true;
           fpengembalian.Show();
       }


       private void sewa_aktif()
       {
           frental = new rental(priviledge, nama_user);
           frental.MdiParent = this;
           fpengembalian.Close();
           fpengembalian = null;
           sewaToolStripMenuItem.Enabled = false;
           tsb_sewa.Enabled = false;
           pengembalianToolStripMenuItem.Enabled = true;
           tsb_kembalian.Enabled = true;
           frental.Show();
       }
       private void dataPelangganToolStripMenuItem_Click(object sender, EventArgs e)
       {
           TampilPelanggan DPelanggan = new TampilPelanggan();
           DPelanggan.ShowDialog();


       }


       private void logout_menu_Click(object sender, EventArgs e)
       {
           this.Text = "Rental Mobil";
           log.ShowDialog();
       }


       private void dataMobilToolStripMenuItem_Click(object sender, EventArgs e)
       {
           fmobil1.ShowDialog();
       }


       private void tsb_pelanggan_Click(object sender, EventArgs e)
       {
           TampilPelanggan fpel = new TampilPelanggan();
           fpel.ShowDialog();
       }


       private void dataUserToolStripMenuItem_Click(object sender, EventArgs e)
       {
           fuser.ShowDialog();
       }


       private void home_FormClosed_1(object sender, FormClosedEventArgs e)
       {
           Application.Exit();
       }


       private void dataSopirToolStripMenuItem_Click(object sender, EventArgs e)
       {
           sop.ShowDialog();
       }


       private void dataHargaToolStripMenuItem_Click(object sender, EventArgs e)
       {
           fsewa.ShowDialog();
       }


       private void pengembalianToolStripMenuItem_Click(object sender, EventArgs e)
       {


           kembali_aktif();   
       }


       private void sewaToolStripMenuItem_Click(object sender, EventArgs e)
       {
           sewa_aktif();
       }


       private void tsb_sewa_Click(object sender, EventArgs e)
       {
           sewa_aktif();
       }


       private void tsb_kembalian_Click(object sender, EventArgs e)
       {
           kembali_aktif();
       }


       private void laporan_menu_Click(object sender, EventArgs e)
       {
           laporan.ShowDialog();
       }


       private void tsb_mobil_Click(object sender, EventArgs e)
       {
           fmobil1.ShowDialog();
       }


       private void tsb_sopir_Click(object sender, EventArgs e)
       {
           sop.ShowDialog();
       }


       private void tsb_user_Click(object sender, EventArgs e)
       {
           fuser.ShowDialog();
       }


       private void tsb_harga_Click(object sender, EventArgs e)
       {
           fsewa.ShowDialog();
       }


       private void ubah_pass_Click(object sender, EventArgs e)
       {
           fubah = new ubah_pass(id);
           fubah.ShowDialog();
       }


       private void logout_ts_Click(object sender, EventArgs e)
       {
           this.Hide();
           log.Show();


       }


       private void tsb_laporan_Click(object sender, EventArgs e)
       {
           laporan.ShowDialog();
       }


   }
}

Form mobil

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 index
{
   public partial class fmobil : Form
   {
       private string sql;
       private kon koneksi = new kon();
       private DataTable tbmobil = new DataTable();
       public fmobil()
       {
           InitializeComponent();
           warna();
       }
       public void warna()
       {
           label1.BackColor = System.Drawing.Color.Transparent;
           label2.BackColor = System.Drawing.Color.Transparent;
           label3.BackColor = System.Drawing.Color.Transparent;
           label4.BackColor = System.Drawing.Color.Transparent;
           label5.BackColor = System.Drawing.Color.Transparent;
           label6.BackColor = System.Drawing.Color.Transparent;
           Pencarian.BackColor = System.Drawing.Color.Transparent;
       }
      
       private void inisialisasi()
       {
           txtid.Text = "";
           txtmerk.Text = "";
           txtwarna.Text = "";
           txttahun.Text = "";
           txtkode_mobil.Text = "";
           cbstatus.Text = "pilih salah satu";
           txtpencarian.Text = "";
           txtkode_mobil.Items.Clear();
           isi_kodesewa();
           button_edit.Enabled = false;
           button_hapus.Enabled = false;
           btn_simpan.Enabled = true;
           txtid.Focus();
       }
       
       private void lihatSemuaData()
       {
           sql = "select*from mobil order by id desc";
           tbmobil = koneksi.tampil_data(sql);
           dgvmobil.DataSource = tbmobil;
       }


       private void Form1_Load(object sender, EventArgs e)
       {
           lihatSemuaData();
           inisialisasi();
       }
       private void btn_simpan_Click(object sender, EventArgs e)
       {
           if (txtid.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtmerk.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox merk terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtwarna.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textboxwarna terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txttahun.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox tahun terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtkode_mobil.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox kode harga terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (cbstatus.Text == "pilih salah satu")
           {
               MessageBox.Show("Silahkan mengisi Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else
           {


               mobil m = new mobil();
               m.Id = txtid.Text;
               m.Merk = txtmerk.Text;
               m.Warna = txtwarna.Text;
               m.Tahun = txttahun.Text;
               m.Kode_mobil = txtkode_mobil.Text;
               m.Status = cbstatus.Text;
               sql = "insert into mobil (id,merk,warna,tahun,kode_mobil,status)values('" + m.Id + "','" + m.Merk + "','" + m.Warna + "','" + m.Tahun + "','" + m.Kode_mobil + "','" + m.Status + "')";
               koneksi.dml(sql);
               Form1_Load(sender, e);
           }
       }
      
       private void button3_Click(object sender, EventArgs e)
       {
           if (txtid.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtmerk.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox merk terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtwarna.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textboxwarna terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txttahun.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox tahun terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtkode_mobil.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox kode harga terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (cbstatus.Text == "pilih salah satu")
           {
               MessageBox.Show("Silahkan mengisi Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else
           {
               mobil m = new mobil();
               m.Id = txtid.Text;
               m.Merk = txtmerk.Text;
               m.Warna = txtwarna.Text;
               m.Tahun = txttahun.Text;
               m.Kode_mobil = txtkode_mobil.Text;
               m.Status = cbstatus.Text;
               sql = "update mobil set merk='" + m.Merk + "', warna='" + m.Warna + "', tahun='" + m.Tahun + "', kode_mobil ='" + m.Kode_mobil + "', status='" + m.Status + "' where id='"+m.Id+"'";
               koneksi.dml(sql);
               MessageBox.Show("Update telah berhasil di lakukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
               inisialisasi();
               lihatSemuaData();
           }
       }
             


       private void button2_Click(object sender, EventArgs e)
       {
            if (txtid.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtmerk.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox merk terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtwarna.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textboxwarna terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txttahun.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox tahun terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (txtkode_mobil.Text == "")
           {
               MessageBox.Show("Silahkan mengisi textbox kode harga terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else if (cbstatus.Text == "pilih salah satu")
           {
               MessageBox.Show("Silahkan mengisi Id terlebih dahulu", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
           }
           else
           {
               mobil m = new mobil();
               m.Id = txtid.Text;


               sql = "delete from mobil where id='"+m.Id+"'";
               koneksi.dml(sql);
               MessageBox.Show("Delete telah berhasil di lakukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
               inisialisasi();
               lihatSemuaData();
           }
       }
             
                      
       //}


     


       private void btn_tambah_Click(object sender, EventArgs e)
       {
           RecursiveClearTextBoxes(this.Controls);
       }


       private void RecursiveClearTextBoxes(Control.ControlCollection cc)
       {


           foreach (Control ctrl in cc)
           {
              TextBox tb = ctrl as TextBox;
            if (tb != null)
             tb.Clear();             
            else
             RecursiveClearTextBoxes(ctrl.Controls);
            }


          }              


     private void btn_keluar_Click(object sender, EventArgs e)
       {
           Close();
       }


    


     private void dgvmobil_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
     {
         txtid.Text= dgvmobil.SelectedCells[0].Value.ToString();
         txtmerk.Text = dgvmobil.SelectedCells[1].Value.ToString();
         txtwarna.Text = dgvmobil.SelectedCells[2].Value.ToString();
         txttahun.Text = dgvmobil.SelectedCells[3].Value.ToString();
         txtkode_mobil.Text = dgvmobil.SelectedCells[4].Value.ToString();
         cbstatus.Text = dgvmobil.SelectedCells[5].Value.ToString();
         btn_simpan.Enabled = false;
         button_edit.Enabled = true;
         button_hapus.Enabled = true;
     }


     private void btn_batal_Click(object sender, EventArgs e)
     {
         inisialisasi();
     }


     private void txtpencarian_TextChanged(object sender, EventArgs e)
     {


     }


     private void txtpencarian_KeyUp(object sender, KeyEventArgs e)
     {
         if (txtpencarian.Text == "")
         {
             sql = "select*from mobil order by id asc";
             tbmobil = koneksi.tampil_data(sql);
             dgvmobil.DataSource = tbmobil;
         }
         else
         {
             sql = "select*from mobil where id like '%" + txtpencarian.Text + "%'";
             tbmobil = koneksi.tampil_data(sql);
             if (tbmobil.Rows.Count == 0)
             {
                 sql = "select*from mobil where status like'%" + txtpencarian.Text + "%'";
                 tbmobil = koneksi.tampil_data(sql);
                
                 if (tbmobil.Rows.Count == 0)
                 {
                     sql = "select*from mobil where merk like '%" + txtpencarian.Text + "%'";
                     tbmobil = koneksi.tampil_data(sql);
                     
                     if (tbmobil.Rows.Count == 0)
                     {
                         sql = "select*from mobil where tahun like '%" + txtpencarian.Text + "%'";
                         tbmobil = koneksi.tampil_data(sql);
                         if (tbmobil.Rows.Count == 0)
                         {
                             sql = "select*from mobil where kode_mobil like '%" + txtpencarian.Text + "%'";
                             tbmobil = koneksi.tampil_data(sql);
                             if (tbmobil.Rows.Count == 0)
                             {
                                 sql = "select*from mobil where warna like '%" + txtpencarian.Text + "%'";
                                 tbmobil = koneksi.tampil_data(sql);
                                 if (tbmobil.Rows.Count == 0)
                                 {
                                     MessageBox.Show("Pencarian tidak di temukan", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                     txtpencarian.Text = "";
                                 }
                                 else
                                 {
                                     dgvmobil.DataSource = tbmobil;
                                 }
                             }
                             else
                             {
                                 dgvmobil.DataSource = tbmobil;
                             }
                         }
                         else
                         {
                             dgvmobil.DataSource = tbmobil;
                         }
                     }
                     else
                     {
                         dgvmobil.DataSource = tbmobil;
                     }
                 }
                 else
                 {
                     dgvmobil.DataSource = tbmobil;
                 }
             }
             else
             {
                 dgvmobil.DataSource = tbmobil;
             }
         }
     }


     private void isi_kodesewa()
     {
         sql = "select*from harga_sewa order by id desc";
         for (int i = 0; i < 4; i++)
         {
             txtkode_mobil.Items.Add(koneksi.tampil_data(sql).Rows[i].ItemArray.GetValue(1).ToString());
         }
     }
     private void txtkode_mobil_KeyUp(object sender, KeyEventArgs e)
     {
         if (txtkode_mobil.Text != "")
         {
             sql = "select*from harga_sewa where golongan ='" + txtkode_mobil.Text + "'";
             if (koneksi.tampil_data(sql).Rows.Count == 0)
             {
                 txtkode_mobil.Text="";
             }
         }
         else
         {
             txtkode_mobil.Text = "";
         }
     }
  }
}


NEXT

0 Comments

Copyright Jujur Soaloon Sitangang Lipan All rights reserved. Theme by Sitanggang. | Bloggerized by Soalparna.