Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            List <string> configitems = File.ReadAllLines(@"firebaseconfig.config").ToList();


            client = new FireSharp.FirebaseClient(new FirebaseConfig()
            {
                AuthSecret = configitems[0],
                BasePath   = configitems[1]
            });

            if (client != null)
            {
                MessageBox.Show("Connection to database established");
            }

            dt.Columns.Add("Name of book");
            dt.Columns.Add("Issue date");
            dt.Columns.Add("Return date");
            dataGridView1.DataSource = dt;
            dates();
            rf.exporttodatagridview(dt, booklist, FilePath, client);
        }
        private async void button1_Click(object sender, EventArgs e)
        {
            if (!rf.CheckForInternetConnection())
            {
                MessageBox.Show("Please check internet connection before performing any task", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "")
            {
                string newtitle    = textBox1.Text;
                Book   updatedbook = new Book()
                {
                    name       = newtitle,
                    issuedate  = textBox2.Text,
                    returndate = textBox3.Text
                };
                FirebaseResponse response = await client.DeleteTaskAsync("Books lended/" + booktitle);

                SetResponse setResponse = await client.SetTaskAsync("Books lended/" + newtitle, updatedbook);

                if (booklist.Count > 0)
                {
                    booklist.Clear();
                }
                booklist = File.ReadAllLines(FilePath).ToList();
                File.WriteAllText(FilePath, string.Empty);
                foreach (string book in booklist)
                {
                    if (book != booktitle)
                    {
                        File.AppendAllText(FilePath, book + Environment.NewLine);
                    }
                    else
                    {
                        File.AppendAllText(FilePath, newtitle + Environment.NewLine);
                    }
                }
                rf.exporttodatagridview(dt, booklist, FilePath, client);
                this.Close();
            }
            else
            {
                MessageBox.Show("Invalid input for updating", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private async void button2_Click(object sender, EventArgs e)          /////  for deleteing
        {
            if (!rf.CheckForInternetConnection())
            {
                MessageBox.Show("Please check internet connection before performing any task", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            FirebaseResponse response = await client.DeleteTaskAsync("Books lended/" + booktitle);

            booklist.Clear();
            booklist = File.ReadAllLines(FilePath).ToList();
            File.WriteAllText(FilePath, string.Empty);
            foreach (string book in booklist)
            {
                if (book != booktitle)
                {
                    File.AppendAllText(FilePath, book + Environment.NewLine);
                }
            }
            rf.exporttodatagridview(dt, booklist, FilePath, client);
            this.Close();
        }