Example #1
0
        public void Register(string email, string password, string fullname)
        {
            this.dbHandler = new DbHandler();
            int    idAccount = 0;
            String query1    = "INSERT INTO public.account (username, password) VALUES ('" + email + "','" + password + "')";

            try
            {
                con = dbHandler.connection();
                con.Open();

                command = new NpgsqlCommand(query1, con);
                command.ExecuteNonQuery();

                String query2 = "SELECT account.id_account FROM public.account WHERE account.username = '******'";

                using (command = new NpgsqlCommand(query2, con))
                {
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        idAccount = int.Parse(reader[0].ToString());
                    }
                }

                String query3 = "INSERT INTO public.author (name, id_account, default_account) VALUES ('" + fullname + "','" + idAccount + "',1)";

                command = new NpgsqlCommand(query3, con);

                command.ExecuteNonQuery();
            }
            catch (Exception msg)
            {
                System.Diagnostics.Debug.WriteLine(msg.ToString());
                throw;
            }
        }
Example #2
0
        //BUATAN KITAH
        public DataTable articleList(int id)
        {
            dbHandler    = new DbHandler();
            articleModel = new ArticleModel();
            string query = "SELECT a.id_article, a.tittle, a.year, ao.id_author FROM article a LEFT JOIN article_author aa on aa.id_article = a.id_article LEFT JOIN author ao on ao.id_author = aa.id_author WHERE ao.id_author = " + id + "";

            try
            {
                con = dbHandler.connection();
                con.Open();
                this.dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[4] {
                    new DataColumn("ID Artikel"), new DataColumn("Judul Artikel"), new DataColumn("Tahun"), new DataColumn("ID Author")
                });

                using (command = new NpgsqlCommand(query, con))
                {
                    reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        articleModel.idArtikel      = int.Parse(reader[0].ToString());
                        articleModel.judulArtikel   = reader[1].ToString();
                        articleModel.tahunArtikel   = int.Parse(reader[2].ToString());
                        articleModel.penulisArtikel = int.Parse(reader[3].ToString());
                    }
                }
                dt.Rows.Add(articleModel.idArtikel, articleModel.judulArtikel, articleModel.tahunArtikel, articleModel.penulisArtikel);

                con.Close();
            }
            catch (Exception msg)
            {
                System.Diagnostics.Debug.WriteLine(msg.ToString());
            }

            return(dt);
        }