private void frmConfig_Load(object sender, EventArgs e) { ic = new initConnection(Properties.Settings.Default.Server, Properties.Settings.Default.DBName); txtHead1.Text = Properties.Settings.Default.Header1; txtHead2.Text = Properties.Settings.Default.Header2; txtServer.Text = Properties.Settings.Default.Server; txtDB.Text = Properties.Settings.Default.DBName; lblStatus.Text = "Status: " + (ic.isSQLConnected() ? "Terhubung" : "Tidak Terhubung"); greet.Checked = Properties.Settings.Default.greet; if (Properties.Settings.Default.greet == true) { custgreet.Visible = true; custgreet.Checked = Properties.Settings.Default.customgreet; if (Properties.Settings.Default.customgreet == true) { gbGreet.Visible = true; } else { gbGreet.Visible = false; } txtGreet.Text = Properties.Settings.Default.greettext; } else { custgreet.Visible = false; gbGreet.Visible = false; } }
private void button2_Click(object sender, EventArgs e) { if ((txtServer.Text == "") && (txtDBName.Text == "")) { MessageBox.Show(this, "Mohon isi informasi koneksi dengan valid!", "Invalid Connection", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { initConnection ic = new initConnection(txtServer.Text, txtDBName.Text); if (ic.isSQLConnected()) { Properties.Settings.Default.Server = txtServer.Text; Properties.Settings.Default.DBName = txtDBName.Text; Properties.Settings.Default.Save(); MessageBox.Show(this, "Berhasil terhubung dengan server!", "Connection Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); lbStatus.Text = "Status: Terhubung"; } else { MessageBox.Show(this, "Gagal terhubung dengan server!", "Connection Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); lbStatus.Text = "Status: Tidak Terhubung"; } } }
private void button3_Click(object sender, EventArgs e) { lblStatus.Text = "Status: Menghubungkan..."; ic = new initConnection(txtServer.Text, txtDB.Text); if (ic.isSQLConnected()) { lblStatus.Text = "Status: Terhubung"; Properties.Settings.Default.Server = txtServer.Text; Properties.Settings.Default.DBName = txtDB.Text; Properties.Settings.Default.Save(); MessageBox.Show(this, "Koneksi smart system berhasil terhubung ke database dan konfigurasi berhasil disimpan!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { lblStatus.Text = "Status: Tidak Terhubung"; MessageBox.Show(this, "Koneksi smart system gagal terhubung ke database", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void frmConfig_Load(object sender, EventArgs e) { txtHead1.Text = Properties.Settings.Default.header1; txtHead2.Text = Properties.Settings.Default.header2; txtFoot.Text = Properties.Settings.Default.footer; txtServer.Text = Properties.Settings.Default.Server; txtDBName.Text = Properties.Settings.Default.DBName; numtarif.Value = Properties.Settings.Default.tarifper; txtTrfMotor.Text = Properties.Settings.Default.tarifmotor.ToString(); txtTrfMobil.Text = Properties.Settings.Default.tarifmobil.ToString(); initConnection ic = new initConnection(Properties.Settings.Default.Server, Properties.Settings.Default.DBName); if (ic.isSQLConnected()) { lbStatus.Text = "Status: Terhubung"; } else { lbStatus.Text = "Status: Tidak Terhubung"; } }
private void button2_Click(object sender, EventArgs e) { try { button1.Enabled = false; button2.Enabled = false; DateTime dt = DateTime.Now; var list = new List <string[]>() { }; conn = new initConnection(Properties.Settings.Default.Server, Properties.Settings.Default.DBName); using (SqlConnection myConnection = new SqlConnection()) { string oString = "SELECT * FROM lokasi WHERE jenis_kend = 'Mobil'"; SqlCommand oCmd = new SqlCommand(oString, myConnection); myConnection.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True"; myConnection.Open(); using (SqlDataReader oReader = oCmd.ExecuteReader()) { while (oReader.Read()) { string[] baru = new string[2]; baru[0] = oReader["kode_lokasi"].ToString(); baru[1] = oReader["kuota"].ToString(); list.Add(baru); //matchingPerson.firstName = oReader["FirstName"].ToString(); //matchingPerson.lastName = oReader["LastName"].ToString(); } myConnection.Close(); } } using (SqlConnection bcc = new SqlConnection()) { bcc.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True"; bcc.Open(); foreach (string[] y in list) { string oString2 = "SELECT COUNT(*) FROM parkir WHERE kode_lokasi = '" + y[0] + "'"; SqlCommand oCmd2 = new SqlCommand(oString2, bcc); if (int.Parse(oCmd2.ExecuteScalar().ToString()) < int.Parse(y[1].ToString())) { didapat = y[0].ToString(); kode = dt.ToString("yyyyMMddHHmmss"); break; } } bcc.Close(); } if (didapat == "") { MessageBox.Show(this, "Tempat parkir penuh semua!!", "Not enough", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } else { using (SqlConnection scn = new SqlConnection()) { scn.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True"; scn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = scn; cmd.CommandText = "tambah_kend"; cmd.CommandType = CommandType.StoredProcedure; SqlParameter id_parkir = new SqlParameter("@id_parkir", SqlDbType.VarChar); SqlParameter jenis_kend = new SqlParameter("@jenis_kend", SqlDbType.VarChar); SqlParameter tgl_masuk = new SqlParameter("@tgl_masuk", SqlDbType.DateTime); SqlParameter kode_lokasi = new SqlParameter("@kode_lokasi", SqlDbType.VarChar); id_parkir.Value = kode; jenis_kend.Value = "Mobil"; tgl_masuk.Value = DateTime.Now; kode_lokasi.Value = didapat; cmd.Parameters.Add(id_parkir); cmd.Parameters.Add(jenis_kend); cmd.Parameters.Add(tgl_masuk); cmd.Parameters.Add(kode_lokasi); cmd.ExecuteNonQuery(); scn.Close(); } } PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(printMobil); // Set the printer name. //pd.PrinterSettings.PrinterName = "\\NS5\hpoffice //pd.PrinterSettings.PrinterName = "Zebra New GK420t" pd.Print(); if (Properties.Settings.Default.greet) { if (Properties.Settings.Default.customgreet) { SpeechSynthesizer sc = new SpeechSynthesizer(); sc.SpeakAsync(Properties.Settings.Default.greettext); } else { playWelcome(); } } frmInfo frm = new frmInfo(); frm.lbTempat.Text = didapat; frm.lbKet.Text = "Mobil"; frm.timer1.Enabled = true; frm.ShowDialog(this); } catch (Exception ex) { MessageBox.Show("Error: " + ex.ToString()); } finally { didapat = ""; kode = ""; button1.Enabled = true; button2.Enabled = true; } }