示例#1
0
 public NotebookWindow(Notebook notebook, User user)
 {
     this.currentNotebook = notebook;
     this.currentUser = user;
     InitializeComponent();
     loadFields();
 }
示例#2
0
        public void insertNotebook(Notebook notebook)
        {
            String sql;
            if (notebook.getId() > 0)
            {
                sql = "UPDATE notebook " +
                             "SET name = @name, description = @description " +
                             "WHERE notebookId = @notebookId";

            }
            else
            {
                sql = "INSERT INTO notebook (userId, name, description)" +
                          "VALUES (@userId, @name, @description)";
            }
            SqlCommand query = new SqlCommand(sql, con);
            SqlParameter parName = new SqlParameter("@name", SqlDbType.VarChar);
            SqlParameter parUserId = new SqlParameter("@userId", SqlDbType.Int);
            SqlParameter parDescription = new SqlParameter("@description", SqlDbType.VarChar);
            SqlParameter parNotebookId = new SqlParameter("@notebookId", SqlDbType.Int);

            parNotebookId.Value = notebook.getId();
            parUserId.Value = notebook.getUserId();
            parName.Value = notebook.getName();
            parDescription.Value = notebook.getDescription();

            query.Parameters.Add(parNotebookId);
            query.Parameters.Add(parUserId);
            query.Parameters.Add(parName);
            query.Parameters.Add(parDescription);

            try
            {
                this.openCon();
                query.ExecuteScalar();
                this.closeCon();
            }
            catch (Exception e)
            {
                Console.WriteLine("Adding note failed");
                Console.WriteLine(e.Message);
                this.closeCon();
            }
        }
示例#3
0
        public List<Notebook> getNotebooks(int userId)
        {
            SqlDataReader reader;
            List<Notebook> notebooklist = new List<Notebook>();

            SqlCommand query = new SqlCommand("SELECT * FROM notebook WHERE userId = @userId", con);
            SqlParameter parUserId = new SqlParameter("@userId", SqlDbType.Int);
            parUserId.Value = userId;
            query.Parameters.Add(parUserId);
            this.openCon();
            try
            {
                reader = query.ExecuteReader();

                while (reader.Read())
                {
                    Notebook notebook = new Notebook(Convert.ToInt32(reader["notebookId"].ToString()),
                                        Convert.ToInt32(reader["userId"].ToString()),
                                        reader["name"].ToString(),
                                        reader["description"].ToString());
                    notebooklist.Add(notebook);
                }
            }
            catch (SqlException e)
            {
                Console.WriteLine(e.Message);
            }
            this.closeCon();
            return notebooklist;
        }
示例#4
0
 public NotebookWindow(User user)
 {
     InitializeComponent();
     this.currentUser = user;
     this.currentNotebook = new Notebook(0, currentUser.getId(), "", "");
 }