Пример #1
0
        private void btnCancelMaintenance_Click(object sender, EventArgs e)
        {
            DialogResult dropMaintenance = MessageBox.Show("Vill du verkligen avboka den aktuella banskötseln?", "Avboka banskötsel", MessageBoxButtons.OKCancel);
            if (dropMaintenance == DialogResult.OK)
            {
                selectedMaintenance = (Maintenance)lbUpcomingMaintenance.SelectedItem;
                NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=grp3vt13;User Id=grp3vt13;Password=XmFGFwX6t;SSL=true");
                try
                {
                    string sql = "DELETE FROM golfround WHERE id = " + selectedMaintenance.maintenanceId + "";
                    conn.Open();
                    NpgsqlCommand command = new NpgsqlCommand(sql, conn);
                    int antal = command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {

                    MessageBox.Show("Det finns inget underhåll att avboka.");
                }
                finally
                {
                    conn.Close();
                }
                lbUpcomingMaintenance.DataSource = Methods.GetUpcomingMaintenance();
            }

            else if (dropMaintenance == DialogResult.Cancel)
            { }
        }
Пример #2
0
        public static List <Maintenance> GetUpcomingMaintenance() //hämtar alla kommande underhåll
        {
            List <Maintenance>       maintenanceList = new List <Maintenance>();
            ConnectionStringSettings settings        = ConfigurationManager.ConnectionStrings[conString];
            NpgsqlConnection         conn            = new NpgsqlConnection(settings.ConnectionString);

            conn.Open();
            NpgsqlCommand    command = new NpgsqlCommand("SELECT id, date, startingtime, endtime FROM golfround WHERE date >= NOW() AND staff_id IS NOT null ORDER BY date", conn);
            NpgsqlDataReader dr      = command.ExecuteReader();

            while (dr.Read())
            {
                Maintenance maintenances = new Maintenance
                {
                    maintenanceId    = (int)dr["id"],
                    maintenanceDate  = (DateTime)dr["date"],
                    maintenanceStart = (string)dr["startingtime"],
                    maintenanceEnd   = (string)dr["endtime"],
                };
                maintenanceList.Add(maintenances);
            }
            conn.Close();
            return(maintenanceList);
        }