示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Er du sikker?", "Bookning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    DataClasses1DataContext db = new DataClasses1DataContext();

                    var query_stillActiveBookings =
                        from b in db.Bookings

                        where b.bookingState == "ACTIVE"
                        where b.bookingResourceID == System.Environment.MachineName

                        select b;

                    foreach (var row in query_stillActiveBookings)
                    {
                        row.bookingEnd = DateTime.Now;
                        db.SubmitChanges();
                    }

                    Process p = new Process();

                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.FileName = "shutdown.exe";
                    p.StartInfo.Arguments = @"/r /f /t 0";
                    p.StartInfo.CreateNoWindow = true;

                    p.Start();

                    this.Close();
                }
                catch (Exception E)
                {
                }
            }
        }
示例#2
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                DataClasses1DataContext db = new DataClasses1DataContext();
                bool active = false;

                var query_selectExpiredBookings =
                                       from b in db.Bookings
                                       where b.bookingState == "ACTIVE"
                                       where b.bookingResourceID == System.Environment.MachineName
                                       select b;

                foreach (var item in query_selectExpiredBookings)
                {
                    active = true;
                }

                if (!active)
                {
                    Process p = new Process();

                    p.StartInfo.CreateNoWindow = true;
                    p.StartInfo.FileName = "shutdown.exe";
                    p.StartInfo.Arguments = @"/r /t 200";
                    p.StartInfo.CreateNoWindow = true;

                    p.Start();

                    this.Close();
                }
                else
                {
                    try
                    {
                        foreach (var item in query_selectExpiredBookings)
                        {
                            DateTime dtEND = (DateTime)item.bookingEnd;
                            TimeSpan ts = dtEND - DateTime.Now;

                            this.label1.Text = "Tid tilbage: " + ts.Hours.ToString() + ":" + ts.Minutes.ToString();
                            if (ts.Minutes <= 5 && this.TopMost==false) this.TopMost = true;
                        }
                    }
                    catch (Exception E)
                    {
                    }
                }

            }
            catch (Exception E)
            {
            }
        }