示例#1
0
        public static bool AddBookToDataBase(Book bookToAdd)
        {
            try
            {

                using (StreamWriter writer = new StreamWriter(FileOperations.FilePath, true))
                {
                    writer.WriteLine(bookToAdd);
                }

                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
示例#2
0
        protected void addBtn_Click(object sender, EventArgs e)
        {
            var bookToAdd = new Book(
                this.titleTextBox.Text,
                this.authorTextBox.Text,
                double.Parse(this.priceTextBox.Text));

            if (FileOperations.AddBookToDataBase(bookToAdd))
            {
                this.MessageLabel.Text = "Success!";
                this.titleTextBox.Text = string.Empty;
                this.authorTextBox.Text = string.Empty;
                this.priceTextBox.Text = string.Empty;
            }
            else
            {
                this.MessageLabel.ForeColor = System.Drawing.Color.Red;
                this.MessageLabel.Text = "Failure!";
                this.titleTextBox.Text = string.Empty;
                this.authorTextBox.Text = string.Empty;
                this.priceTextBox.Text = string.Empty;
            }
        }