//Ini buat nambah data ke database
        private void MinjemBos()
        {
            String path = Path.Combine(pathNow, @"..\..\");
            string connectionString2 = string.Format(Properties.Settings.Default.ConnectionString2, Path.Combine(path, "BukuPinjaman.accdb")
                                                     , Environment.CurrentDirectory);
            string connectionString3 = string.Format(Properties.Settings.Default.ConnectionString3, Path.Combine(path, "TambahBuku.accdb")
                                                     , Environment.CurrentDirectory);

            string   ID            = tbID.Text;
            string   Nama_Peminjam = tbNamaPeminjam.Text;
            string   ISBN          = tbKodeBuku.Text;
            string   Judul         = tbNamaBuku.Text;
            string   Penulis       = tbPenulisBuku.Text;
            string   jumlahPinjam  = tbPinjam.Text;
            int      stok          = Convert.ToInt32(tbStok.Text);
            DateTime tanggalDari   = dtpDari.Value;
            DateTime tanggalSampai = dtpSampai.Value;
            int      sisa          = stok - Convert.ToInt32(jumlahPinjam);

            if (CekAdaApaNgga(ID) && CekAdaApaNgga(sisa))
            {
                string insertSQL2 = string.Format(Properties.Settings.Default.InsertSQL2, ID, Nama_Peminjam, ISBN, Judul, Penulis, tanggalDari, tanggalSampai, jumlahPinjam);
                using (OleDbConnection connection = new OleDbConnection(connectionString2))
                {
                    // The insertSQL string contains a SQL statement that
                    // inserts a new row in the source table.
                    OleDbCommand command = new OleDbCommand(insertSQL2);

                    // Set the Connection to the new OleDbConnection.
                    command.Connection = connection;

                    // Open the connection and execute the insert command.
                    try
                    {
                        connection.Open();
                        command.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        MessageBox.Show("Kelar bosq");
                        connection.Close();
                    }

                    /*SqlConnection con = new SqlConnection();
                     * SqlCommand cmd = new SqlCommand("sp_insert", con);
                     * cmd.CommandType = CommandType.StoredProcedure;
                     * cmd.Parameters.AddWithValue("@Id", tbID.Text);
                     * cmd.Parameters.AddWithValue("@Nama", tbNamaPeminjam.Text);
                     * cmd.Parameters.AddWithValue("@Kode_Buku", tbKodeBuku.Text);
                     * cmd.Parameters.AddWithValue("@Nama_Buku", tbNamaBuku.Text);
                     * cmd.Parameters.AddWithValue("@Batas_Peminjaman", dtpSampai.Text);
                     * con.Open();
                     * int i = cmd.ExecuteNonQuery();
                     *
                     * con.Close();
                     *
                     * if (i != 0)
                     * {
                     *  MessageBox.Show(i + "Data Saved");
                     * }*/
                }
                string updateSql = "UPDATE TambahBuku SET Stock =" + sisa + " WHERE ISBN = '" + ISBN + "'";
                using (OleDbConnection connection = new OleDbConnection(connectionString3))
                    using (OleDbCommand cmd = connection.CreateCommand())
                    {
                        cmd.CommandText = updateSql;
                        cmd.Parameters.AddWithValue("Stock", sisa);
                        cmd.Connection = connection;
                        connection.Open();
                        {
                            OleDbDataReader read = cmd.ExecuteReader();
                        }
                    }
            }
            else if (!CekAdaApaNgga(ID))
            {
                MessageBox.Show("Member dengan ID tersebut sepertinya tidak ada..");
                DialogResult dialogResult = MessageBox.Show("Mau daftar menjadi member?", "Tambah member?", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    LogIn logIn = new LogIn();
                    logIn.tm.Close();
                    TambahMember tm = new TambahMember(Nama_Peminjam);
                    tm.Show();
                    this.Visible = false;
                }
                if (dialogResult == DialogResult.No)
                {
                    MessageBox.Show("Semua memang butuh waktu.");
                }
            }
            else if (!CekAdaApaNgga(sisa))
            {
                MessageBox.Show("Bukunya kurang bos, itu yang diserahkan buku siapa tu?");
            }
        }
示例#2
0
        private void button7_Click(object sender, EventArgs e)
        {
            LogIn tt = new LogIn();

            tt.Show();
        }