Exemplo n.º 1
0
 public Initialize()
 {
     //logsDb.This_days.Add(new This_day { Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString() });//匿名类对数据库进行赋值
     //logsDb.This_days.Add(new This_day { Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString() });
     //logsDb.This_days.Add(new This_day { Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString() });
     //logsDb.This_days.Add(new This_day { Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString() });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.Date.ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-1).ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-2).ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-3).ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-4).ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-6).ToShortDateString()
     });
     logsDb.This_days.Add(new This_day {
         Log = "今天天气好", Date_time = DateTime.Now.AddDays(-7).ToShortDateString()
     });
     logsDb.SaveChanges();//数据库保存
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            LogsDB log = new LogsDB();

            log.This_days.Add(new This_day {
                Log = textBox1.Text, Date_time = DateTime.Now.ToShortDateString()
            });
            log.SaveChanges();
            MessageBox.Show("添加成功");
            textBox1.Text = "";
            this.Close();
        }
Exemplo n.º 3
0
 private void button4_Click(object sender, EventArgs e)
 {
     if (listView1.SelectedItems.Count != 0)
     {
         ListViewItem item = new ListViewItem();
         for (int i = 0; i <= listView1.SelectedItems.Count; i++)
         {
             item = listView1.SelectedItems[i];
             listView1.Items.Remove(item);
             int        a   = Convert.ToInt16(item.Text);
             This_day[] day = logDb.This_days.SqlQuery("select *from This_day where id=" + a).ToArray();
             logDb.This_days.Remove(day[0]);
             logDb.SaveChanges();
         }
     }
 }
Exemplo n.º 4
0
        public Form2()
        {
            InitializeComponent();
            List <This_day> Logs = logDb.This_days.SqlQuery("select *from This_day where Date_time!='" + DateTime.Now.Date.ToShortDateString()
                                                            + "'order by Date_time ").ToList();

            foreach (var Re in Logs)
            {
                Logs ll = new Logs();
                ll.Date_time = Re.Date_time;
                ll.Log       = Re.Log;
                logDb.Logs.Add(ll);
                logDb.SaveChanges();
            }
            foreach (var log in logDb.Logs)
            {
                ListViewItem item = new ListViewItem();
                item.Text = log.id.ToString();
                item.SubItems.Add(log.Date_time);
                item.SubItems.Add(log.Log);
                listView1.Items.Add(item);
            }
        }