Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        private void button12_Click(object sender, EventArgs e)
        {
            try {
                string returnValue;
                using (SqlConnection conn = new SqlConnection()) {
                    conn.ConnectionString = @"Data Source=" + Properties.Settings.Default.Server + "; Initial Catalog=" + Properties.Settings.Default.DBName + "; Integrated Security=True";
                    using (SqlCommand sqlcmd = new SqlCommand("SELECT nama FROM karyawan WHERE NIK = @nik", conn)) {
                        sqlcmd.Parameters.Add("@nik", SqlDbType.VarChar).Value = txtPassword.Text;
                        conn.Open();
                        returnValue = (string)sqlcmd.ExecuteScalar();
                    }
                }

                if (String.IsNullOrEmpty(returnValue))
                {
                    MessageBox.Show(this, "NIK Salah!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPassword.Text = "";
                }
                else
                {
                    DateTime dt   = DateTime.Now;
                    var      list = new List <string[]>()
                    {
                    };

                    using (SqlConnection myConnection = new SqlConnection()) {
                        string     oString = "SELECT * FROM lokasi WHERE jenis_kend = 'Karyawan'";
                        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  = "Karyawan";
                            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();
                        }
                    }
                    if (Properties.Settings.Default.greet)
                    {
                        if (Properties.Settings.Default.customgreet)
                        {
                            SpeechSynthesizer sc = new SpeechSynthesizer();
                            sc.SpeakAsync(Properties.Settings.Default.greettext);
                        }
                        else
                        {
                            frm.playWelcome();
                        }
                    }
                    frmInfo frmd = new frmInfo();
                    frmd.lbTempat.Text  = didapat;
                    frmd.lbKet.Text     = "Karyawan - " + returnValue;
                    frmd.timer1.Enabled = true;
                    frmd.ShowDialog(this);
                    this.Dispose();
                }
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString());
            }
        }