Ejemplo n.º 1
0
        private void BindData()
        {
            var context = new RefuleModel();
            var list    = context.RefuleTable.ToList();

            dataGridView1.DataSource = list;
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            var Startdate = dateTimePicker1.Value;
            var Enddate   = dateTimePicker2.Value;

            RefuleModel a        = new RefuleModel();
            var         middate1 = a.RefuleTable.Where((x) => x.RefuelingDate >= Startdate);
            var         middate2 = middate1.Where((x) => x.RefuelingDate <= Enddate);
            var         list1    = middate2.ToList();

            dataGridView1.DataSource = list1;

            var TotalLiter     = a.RefuleTable.Sum(x => x.Liter);
            var TotalKilometer = a.RefuleTable.Sum(x => x.Kilometer);
            var TotalAverage   = TotalKilometer / TotalLiter;

            label4.Text = TotalAverage.ToString();
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            RefuleTable data = new RefuleTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter         = (double)numericUpDown1.Value,
                Kilometer     = (double)numericUpDown2.Value
            };

            try
            {
                RefuleModel context = new RefuleModel();
                context.RefuleTable.Add(data);
                context.SaveChanges();
                MessageBox.Show("存檔完成");
            }
            catch (Exception ex)
            { MessageBox.Show($"發生錯誤{ex.ToString()}"); }
        }