Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            RefuleTable data = new RefuleTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter         = (double)numericUpDown1.Value,
                Kilometer     = (double)numericUpDown2.Value
            };


            RefuleModels context = new RefuleModels();

            context.RefuleTable.Add(data);
            context.SaveChanges();
            MessageBox.Show("輸入成功");
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            RefuleModels context  = new RefuleModels();
            var          list     = context.RefuleTable;
            var          dataList = list.Where((x) => x.RefuelingDate >= dateTimePicker1.Value && x.RefuelingDate <= dateTimePicker2.Value).ToList();

            dataGridView1.DataSource = dataList;
            double kilometer = 0;
            double l         = 0;

            foreach (var d in dataList)
            {
                kilometer += d.Kilometer;
                l         += d.Liter;
            }

            label4.Text = (kilometer / l).ToString();
        }