Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OilTable oilTable = new OilTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter_        = double.Parse(numericUpDown1.Value.ToString()),
                Kilometer     = double.Parse(numericUpDown2.Value.ToString())
            };
            OilModel oilModel = new OilModel();

            oilModel.OilTable.Add(oilTable);
            oilModel.SaveChanges();
            Clear();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            OilTable data = new OilTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter         = (double)numericUpDown1.Value,
                Kilometer     = (double)numericUpDown2.Value,
            };

            try
            {
                OilModel context = new OilModel();
                context.OilTable.Add(data);
                context.SaveChanges();
                MessageBox.Show("存檔完成");
            }
            catch (Exception ex)
            {
                MessageBox.Show($"發生錯誤{ex.ToString()}");
            }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            OilTable data = new OilTable()
            {
                RefuelingDate = dateTimePicker1.Value,
                Liter         = decimal.ToInt32(numericUpDown1.Value),
                Kilometer     = decimal.ToInt32(numericUpDown2.Value)
            };

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