Пример #1
0
        private void btnWriteCSV_Click(object sender, EventArgs e)
        {
            TextWriter  writer = new StreamWriter("users.csv");
            List <User> users  = UserDTOImplementation.getInstance().getAll();

            foreach (User user in users)
            {
                writer.WriteLine(CSVParser.setUser(user));
            }
            writer.Close();
        }
Пример #2
0
        public void openAddNotebookDialog(String id, String title)
        {
            Form addNotebookDialog = new Form {
                Width = 500, Height = 120, Text = "Add Notebook"
            };
            Label lblTitle = new Label()
            {
                Left = 10, Top = 20, Text = "Notebook Title :", Width = 100
            };
            TextBox txtTitle = new TextBox()
            {
                Left = 150, Top = 20, Width = 300
            };
            Button btnAdd = new Button()
            {
                Text = "Add", Left = 350, Width = 100, Top = 40
            };

            addNotebookDialog.AcceptButton = btnAdd;
            btnAdd.Click += (o, e) => {
                if (DataValidator.isValidTexts(txtTitle))
                {
                    Notebook notebookTemp = new Notebook();
                    bool     flag         = false;
                    notebookTemp.setAuthor(user.getFullName());
                    notebookTemp.setLastModified(DateTime.Now);
                    notebookTemp.setTitle(txtTitle.Text);
                    if (String.IsNullOrEmpty(id))
                    {
                        flag = notebookDTO.save(notebookTemp);
                    }
                    else
                    {
                        flag = notebookDTO.update(notebookTemp, DatabaseConstants.COLUMN_AUTHOR, DatabaseConstants.COLUMN_LASTMODIFIED, DatabaseConstants.COLUMN_TITLE);
                    }
                    notebook = notebookTemp;
                    user.setNotebookId(notebook.getId());
                    UserDTOImplementation.getInstance().update(user, DatabaseConstants.COLUMN_NOTEBOOKID);
                    UserMessages.messageStatus(flag);
                    refreshNotebookData();
                }
            };
            if (!String.IsNullOrEmpty(title))
            {
                txtTitle.Text = title;
            }
            addNotebookDialog.Controls.Add(btnAdd);
            addNotebookDialog.Controls.Add(lblTitle);
            addNotebookDialog.Controls.Add(txtTitle);
            addNotebookDialog.Show();
        }
Пример #3
0
 private void btnSwitch_Click(object sender, EventArgs e)
 {
     if (notebookListView.SelectedItems.Count == 0)
     {
         MessageBox.Show("Please Select a notebook");
     }
     else if (notebookListView.SelectedItems.Count != 1)
     {
         MessageBox.Show("Please Select only one notebook");
     }
     else
     {
         notebook = notebookDTO.getById(notebookListView.SelectedItems[0].Text);
         user.setNotebookId(notebook.getId());
         bool flag = UserDTOImplementation.getInstance().update(user, DatabaseConstants.COLUMN_NOTEBOOKID);
         UserMessages.messageStatus(flag);
     }
 }
Пример #4
0
        private void btnReadCSV_Click(object sender, EventArgs e)
        {
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            openFileDialog.Filter           = CSVParser.FILE;
            int counter = 0;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                Stream       fileStream = openFileDialog.OpenFile();
                StreamReader reader     = new StreamReader(fileStream);
                while (!reader.EndOfStream)
                {
                    counter += UserDTOImplementation.getInstance()
                               .save(CSVParser.getUser(reader.ReadLine())) ? 1 : 0;
                }
                reader.Close();
            }
            MessageBox.Show(counter + " was added successfully to the database");
        }