コード例 #1
0
        protected void bt_simpan_Click(object sender, EventArgs e)
        {
            DatabaseClass d = new DatabaseClass();

            string id    = tb_id.Text.ToString();
            string nama  = tb_nama.Text.ToString();
            string jenis = tb_jenis.Text.ToString();
            string harga = tb_harga.Text.ToString();

            if (nama.Length == 0 || jenis.Length == 0 || harga.Length == 0)
            {
                return;
            }

            try
            {
                d.openDb();

                var s = "insert into barang values " +
                        "('" + id + "', '" + nama + "', '" + jenis + "', " + harga + ")";

                d.execute(s);

                loadGrid();
                kosong();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                d.closeDB();
            }
        }
コード例 #2
0
        private void loadGrid()
        {
            DatabaseClass d = new DatabaseClass();

            try
            {
                d.openDb();
                var s = "select * from barang";
                dt = new DataTable();
                dt = d.read(s);

                /*
                 * Console.WriteLine(dt.Rows.Count.ToString());
                 * if (dt.Rows.Count == 0)
                 * {
                 *  DataRow row = dt.NewRow();
                 *  dt.Rows.Add(row);
                 * }
                 * */

                gv.DataSource = dt;
                gv.DataBind();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                d.closeDB();
            }
        }
コード例 #3
0
        protected void onRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            DatabaseClass d = new DatabaseClass();

            try
            {
                string id    = (gv.Rows[e.RowIndex].FindControl("lbl_id") as Label).Text.ToString().Trim();
                string nama  = (gv.Rows[e.RowIndex].FindControl("tb_nama") as TextBox).Text.ToString().Trim();
                string jenis = (gv.Rows[e.RowIndex].FindControl("tb_jenis") as TextBox).Text.ToString();
                string harga = (gv.Rows[e.RowIndex].FindControl("tb_harga") as TextBox).Text.ToString().Trim();

                d.openDb();

                var s = "update barang set nama = '" + nama + "', jenis = '" + jenis + "', " +
                        "harga = " + harga + "  where id_barang = '" + id + "'";
                Console.WriteLine(s);
                d.execute(s);

                onRowCancelingEdit(null, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                d.closeDB();
            }
        }
コード例 #4
0
        protected void onRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            DatabaseClass d = new DatabaseClass();

            try
            {
                string id = (gv.Rows[e.RowIndex].FindControl("lbl_id") as Label).Text.ToString().Trim();

                d.openDb();
                var s = "delete barang where id_barang = '" + id + "'";
                Console.WriteLine(s);
                d.execute(s);

                onRowCancelingEdit(null, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                d.closeDB();
            }
        }