public static List<Forestallning> HamtaForestallningLista()
        {
            List<Forestallning> forestallningslista = new List<Forestallning>();
            NpgsqlConnection conn = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=pgmvaru_g4;User Id=pgmvaru_g4;Password=trapets;ssl=true");
            conn.Open();
            NpgsqlCommand command = new NpgsqlCommand("Select * from forestallning ORDER BY namn, datum, starttid ASC", conn);
            NpgsqlDataReader dr = command.ExecuteReader();

            while (dr.Read())
            {

                Forestallning forestallning = new Forestallning();

                forestallning.id = Convert.ToInt32(dr["id"]);
                forestallning.namn = (string)dr["namn"];
                forestallning.generellinfo = (string)dr["generell_info"];
                forestallning.open = (bool)dr["open"];
                forestallning.datum = Convert.ToDateTime(dr["datum"]);
                forestallning.starttid = Convert.ToDateTime(dr["starttid"]);
                forestallning.sluttid = Convert.ToDateTime(dr["sluttid"]);
                forestallning.vuxenpris = Convert.ToInt32(dr["vuxenpris"]);
                forestallning.ungdomspris = Convert.ToInt32(dr["ungdomspris"]);
                forestallning.barnpris = Convert.ToInt32(dr["barnpris"]);
                forestallning.forsaljningsslut = Convert.ToDateTime(dr["forsaljningslut"]);

                forestallningslista.Add(forestallning);
            }
            conn.Close();
            return forestallningslista;
        }
Example #2
0
        private void biljetterForHela()
        {
            Forestallning fore = new Forestallning();
            fore = (Forestallning)listBox_forestallning.SelectedItem;
            int antalv = Convert.ToInt32(textBox_vuxen.Text);
            int antalu = Convert.ToInt32(textBox_ungdom.Text);
            int antalb = Convert.ToInt32(textBox_barn.Text);

            for (int i = 0; i < antalv; i++)
            {
                Kund k = new Kund();

                foreach (Akt item in listBox_akter.SelectedItems)
                {
                    skapaHelaTempkop("vuxen", item, fore.vuxen, k);
                }
                session.kunder.Add(k);
            }
            for (int i = 0; i < antalu; i++)
            {
                Kund k = new Kund();

                foreach (Akt item in listBox_akter.SelectedItems)
                {
                    skapaHelaTempkop("ungdom", item, fore.ungdom, k);
                }
                session.kunder.Add(k);
            }
            for (int i = 0; i < antalb; i++)
            {
                Kund k = new Kund();

                foreach (Akt item in listBox_akter.SelectedItems)
                {
                    skapaHelaTempkop("barn", item, fore.barn, k);
            }
                session.kunder.Add(k);
            }
        }
Example #3
0
        private void uppdateraPris()
        {
            if (antal_ar_siffror() == true)
            {
                int totalpris = 0;
                int b = Convert.ToInt32(textBox_barn.Text);
                int u = Convert.ToInt32(textBox_ungdom.Text);
                int v = Convert.ToInt32(textBox_vuxen.Text);

                if (helaforestallningen() == true)
                {
                    Forestallning f = new Forestallning();
                    f = (Forestallning)listBox_forestallning.SelectedItem;
                    totalpris += f.vuxen * v;
                    totalpris += f.ungdom * u;
                    totalpris += f.barn * b;
                }
                else
                {
                    foreach (Akt item in listBox_akter.SelectedItems)
                    {
                        totalpris += item.barn * b;
                        totalpris += item.ungdom * u;
                        totalpris += item.vuxen * v;
                    }
                }

                session.totalpris = totalpris;
                label2.Visible = true;
                label2.Text = totalpris.ToString();

            }

            /*     if (session.hela == true)
                 {
                     totalpris += session.barn * session.forestallning.barn;
                     totalpris += session.ungdom * session.forestallning.ungdom;
                     totalpris += session.vuxna * session.forestallning.vuxen;
                 }
                 else
                 {
                     foreach (Akt item in session.biljetter)
                     {
                         totalpris += session.barn * item.barn;
                         totalpris += session.ungdom * item.ungdom;
                         totalpris += session.vuxna * item.vuxen;
                     }
                 }

                 session.totalpris = totalpris;
                 label2.Visible = true;
                 label2.Text = session.totalpris.ToString();

                 */
        }
Example #4
0
        private void listBox_forestallning_SelectedIndexChanged(object sender, EventArgs e)
        {
            richTextBox2.Clear();
            label16.Text = "";
            label15.Text = "";

            Forestallning fs = new Forestallning();
            fs.akter = new List<Akt>();
            listBox_akter.Items.Clear();

            if ((Forestallning)listBox_forestallning.SelectedItem != null)
            {
                fs = (Forestallning)listBox_forestallning.SelectedItem;
                foreach (Akt akt in fs.akter)
                {
                    listBox_akter.Items.Add(akt);
                }
                label15.Visible = true;
                label16.Visible = true;

                label16.Text = fs.datum.ToShortDateString();
                label15.Text = fs.starttid.ToShortTimeString();
            }

            label5.Visible = false;
            label6.Visible = false;
            label7.Visible = false;

            noll();

            label10.Visible = true;
            label9.Visible = true;
            label8.Visible = true;

            label10.Text = fs.vuxen.ToString();
            label9.Text = fs.ungdom.ToString();
            label8.Text = fs.barn.ToString();

            richTextBox1.Text = fs.generellinfo;

            //string forestallning = listBox_forestallning.SelectedItem.ToString();
            //string query2 = "SELECT aktinfo, id FROM public.akter WHERE akter.forestallningsid = " + fs.id;
            //DataTable dt2 = new DataTable();
            //try
            //{
            //    NpgsqlDataAdapter da2 = new NpgsqlDataAdapter(query2, conn);
            //    da2.Fill(dt2);

            //    foreach (DataRow row2 in dt2.Rows)
            //    {
            //        string aktnamn = row2["aktinfo"].ToString();
            //        string aktid = row2["id"].ToString();
            //        Akt akt = new Akt();
            //        akt.namn = aktnamn;
            //        akt.id = Convert.ToInt32(aktid);
            //        fs.akter.Add(akt);

            //    }
            //}
            //catch (NpgsqlException ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }
Example #5
0
        private void Huvudsidan_Load(object sender, EventArgs e)
        {
            conn.Open();
            FriBokadeVecka();
            conn.Close();

            if (aktortyper.Contains(3) == true || aktortyper.Contains(4) == true || aktortyper.Contains(5) == true || aktortyper.Contains(6) == true || aktortyper.Contains(7) == true || aktortyper.Contains(9) == true)
            {
                this.button3.Enabled = true;
                this.button3.Visible = true;

            }
            if (aktortyper.Contains(8) == true)
            {
                this.button1.Visible = true;
                this.checkBox_fri.Visible = true;
                this.checkBox1.Visible = true;
            }

            session = new Tempkop();
            conn.Open();
            session.totalpris = 0; //För att kolla vid button click att inget är vallt

            //listBox_akter.SelectedIndex = -1;
            //listBox_forestallning.SelectedIndex = -1;
            DataTable dt = new DataTable();
            string query = "select * from forestallning";
            //string forenamn = "forestallning";
            //int forenummer = 1;
            try
            {
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, conn);
                da.Fill(dt);

                /*  DateTime slutdatum = new DateTime();
                  DateTime tid2 = new DateTime();
                  slutdatum = DateTime.Now;
                  tid2 = DateTime.Now;*/

                foreach (DataRow row in dt.Rows)
                {

                    if (harDenVarit(Convert.ToInt32(row["id"])) == false)
                    {
                        if ((bool)row["open"] == true)
                        {
                            DateTime slutdatum = (DateTime)row["forsaljningslut"];
                            if (slutdatum > DateTime.Now)
                            //  {
                            {
                                string info = row["generell_info"].ToString();
                                string namn = row["namn"].ToString();
                                string id = row["id"].ToString();
                                //  bool fri = (bool)row["fri_placering"];
                                int vuxen = Convert.ToInt32(row["vuxenpris"]);
                                int ungdom = Convert.ToInt32(row["ungdomspris"]);
                                int barn = Convert.ToInt32(row["barnpris"]);
                                DateTime datum = (DateTime)row["datum"];
                                DateTime tid = (DateTime)row["starttid"];
                                Forestallning fs = new Forestallning();
                                fs.akter = new List<Akt>();
                                fs.generellinfo = info;
                                fs.namn = namn;
                                fs.id = Convert.ToInt32(id);
                                // fs.friplacering = fri;
                                fs.barn = barn;
                                fs.ungdom = ungdom;
                                fs.vuxen = vuxen;
                                fs.datum = datum;
                                fs.starttid = tid;
                                fs.forsaljningsslut = slutdatum;
                                listBox_forestallning.Items.Add(fs);

                                //forenamn += forenummer;
                                //forenummer++;

                                string query2 = "select * from akter where forestallningsid = " + fs.id.ToString();
                                NpgsqlDataAdapter da2 = new NpgsqlDataAdapter(query2, conn);
                                DataTable dt2 = new DataTable();
                                da2.Fill(dt2);
                                foreach (DataRow row2 in dt2.Rows)
                                {
                                    Akt akt = new Akt();
                                    string aktinfo = row2["aktinfo"].ToString();
                                    string aktnamn = row2["aktnamn"].ToString();
                                    string aktid = row2["id"].ToString();
                                    //  int aktpris = Convert.ToInt32(row2["vuxenpris"]);
                                    int vuxen2 = Convert.ToInt32(row2["vuxenpris"]);
                                    int ungdom2 = Convert.ToInt32(row2["ungdomspris"]);
                                    int barn2 = Convert.ToInt32(row2["barnpris"]);
                                    DateTime tidakt = (DateTime)row2["starttid"];
                                    akt.namn = aktnamn;
                                    akt.id = Convert.ToInt32(aktid);
                                    akt.vuxen = vuxen2;
                                    akt.ungdom = ungdom2;
                                    akt.barn = barn2;
                                    akt.Starttid = tidakt;
                                    akt.Aktinfo = aktinfo;
                                    fs.akter.Add(akt);
                                }

                            }
                            //    }
                        }

                    }

                }
                //listBox_forestallning.Items.Add(namn);
            }
            catch (NpgsqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void buttonOppnaForsaljning_Click(object sender, EventArgs e)
 {
     Forestallning befintligforestallning = new Forestallning();
     befintligforestallning = (Forestallning)listBoxForestallning.SelectedItem;
     int fId = befintligforestallning.id;
     this.Hide();
     OppnaForestallning open = new OppnaForestallning(aktorlistaId, fId);
     open.ShowDialog();
     this.Close();
 }
        private void listBoxForestallning_SelectedIndexChanged(object sender, EventArgs e)
        {
            valdforestallning = (Forestallning)listBoxForestallning.SelectedItem;
            if (valdforestallning != null)
            {
                id = valdforestallning.id;
                listBoxAkt.DataSource = Databasmetoder.HamtaAktLista(valdforestallning.id);
                richTextBoxForestallning.Text = valdforestallning.generellinfo;
                labelForsaljningsslut.Text = ("t.o.m " + valdforestallning.forsaljningsslut.ToShortDateString());
            }
            else
            {
                labelForsaljningsslut.Visible = false;

            }
        }
        private void listBoxAkt_SelectedIndexChanged(object sender, EventArgs e)
        {
            valdforestallning = (Forestallning)listBoxForestallning.SelectedItem;
            if (valdforestallning != null)
            {
                valdakt = (Akt)listBoxAkt.SelectedItem;

                if (valdakt != null)
                {

                    richTextBoxAkter.Text = valdakt.Aktinfo.ToString();
                }
            }
        }
        public static void UppdateraAkt(int id, string namn, string aktinfo, DateTime starttid, DateTime sluttid, int vuxen, int ungdom, int barn)
        {
            NpgsqlConnection conn1 = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=pgmvaru_g4;User Id=pgmvaru_g4;Password=trapets;ssl=true");

            try
            {
                Forestallning fs = new Forestallning();
                conn1.Open();
                NpgsqlCommand command1 = new NpgsqlCommand(@"UPDATE akter SET aktnamn = :nyNamn, aktinfo = :nyAktinfo, starttid = :nyStarttid, sluttid = :nySluttid, vuxenpris = :nyVuxen, ungdomspris = :nyUngdom, barnpris = :nyBarn WHERE id = :nyId", conn1);

                command1.Parameters.Add(new NpgsqlParameter("nyNamn", DbType.String));
                command1.Parameters[0].Value = namn;
                command1.Parameters.Add(new NpgsqlParameter("nyAktinfo", DbType.String));
                command1.Parameters[1].Value = aktinfo;
                command1.Parameters.Add(new NpgsqlParameter("nyStarttid", DbType.DateTime));
                command1.Parameters[2].Value = starttid;
                command1.Parameters.Add(new NpgsqlParameter("nySluttid", DbType.DateTime));
                command1.Parameters[3].Value = sluttid;
                command1.Parameters.Add(new NpgsqlParameter("nyVuxen", DbType.Int32));
                command1.Parameters[4].Value = vuxen;
                command1.Parameters.Add(new NpgsqlParameter("nyUngdom", DbType.Int32));
                command1.Parameters[5].Value = ungdom;
                command1.Parameters.Add(new NpgsqlParameter("nyBarn", DbType.Int32));
                command1.Parameters[6].Value = barn;
                command1.Parameters.Add(new NpgsqlParameter("nyId", DbType.Int32));
                command1.Parameters[7].Value = id;

                int numberOfAffectedRows = command1.ExecuteNonQuery();

            }

            catch (NpgsqlException ex)
            {
                MessageBox.Show("Tyvärr uppstod ett fel! Vänligen kontrollera så att alla textboxar är korrekt ifyllda, se exempelkoden i textboxarna.");
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                conn1.Close();
            }
        }
        public static void TaBortAkt(int valdaktid)
        {
            NpgsqlConnection conn1 = new NpgsqlConnection("Server=webblabb.miun.se;Port=5432;Database=pgmvaru_g4;User Id=pgmvaru_g4;Password=trapets;ssl=true");

            try
            {
                Forestallning fs = new Forestallning();
                conn1.Open();
                string sql = "DELETE * FROM akt WHERE id = :valdaktid";
                NpgsqlCommand command1 = new NpgsqlCommand(sql);

                command1.Parameters.Add(new NpgsqlParameter("id", DbType.String));
                command1.Parameters[0].Value = valdaktid;

            }
            catch
            {

            }
            finally
            {

                conn1.Close();
            }
        }
Example #11
0
        // gammmal ifasts kod
        //try
        //{
        //namn = textBoxForestNamn.Text;
        //string generellinfo = richTextBoxForestInf.Text;
        // datum = Convert.ToDateTime(textBoxForestDatum1.Text);
        //DateTime starttid = Convert.ToDateTime(textBoxForestStarttid.Text);
        // DateTime sluttid = Convert.ToDateTime(textBoxForestSluttid.Text);
        //bool open = checkBoxForestallning1.Checked;
        //vuxenpris = Convert.ToInt32(textBoxVuxenpris.Text);
        //ungdomspris = Convert.ToInt32(textBoxUngdomspris.Text);
        //barnpris = Convert.ToInt32(textBoxBarnpris.Text);
        //  bool friplacering = false;
        // DateTime forsaljningsslut = Convert.ToDateTime(textBoxForsaljningsslut.Text);
        //if (checkBoxfriPlacering.Checked == true)
        //{
        //    friplacering = true;
        //}
        //if (checkBoxForestallning1.Checked == true)
        //{
        //    valdforestallning.open = true;
        //}
        //else
        //{
        //    checkBoxForestallning1.Checked = false;
        //}
        //if (starttid.TimeOfDay < sluttid.TimeOfDay)
        //        {
        //if (vuxenpris >= ungdomspris && vuxenpris >= barnpris && ungdomspris >= barnpris)
        //{
        //if (forsaljningsslut.Date <= datum.Date)
        //{
        //Databasmetoder.LaggTillNyForestallning(namn, generellinfo, datum, starttid, sluttid, vuxenpris, ungdomspris, barnpris);
        //listBoxAdminForestallning.DataSource = Databasmetoder.HamtaForestallningLista();
        //                   // buttonLaggTillForest.Enabled = false;
        //                   // listBoxAdminForestallning.SelectionMode = SelectionMode.One;
        //                conn.Close();
        //                    MessageBox.Show("Föreställningen är nu tillagd i föreställningslistan.");
        //                //}
        //else
        //{
        //    MessageBox.Show("Du bör inte sälja biljetter efter att föreställningen spelats klart.");
        //}
        //}
        //else
        //{
        //    MessageBox.Show("Vuxen är dyrast, sedan kommer ungdom följt av barn.");
        //}
        //}
        //else
        //{
        //    MessageBox.Show("Föreställningen är för kort!");
        //}
        //}
        //else
        //{
        //    MessageBox.Show("Sätt ett senare datum!");
        //}
        //}
        //catch (Exception)
        //{
        //    MessageBox.Show("Vänligen observera att alla textfält måste vara ifyllda korrekt, se exempelkod. Kontrollera även så att du inte glömt att fylla i ett textfält.");
        //}
        //    finally
        //    {
        //    conn.Close();
        //}
        //}
        private void listBoxAkter_SelectedIndexChanged(object sender, EventArgs e)
        {
            valdforestallning = (Forestallning)listBoxAdminForestallning.SelectedItem;
            if (valdforestallning != null && st != "skapaAkt")
            {
                valdakt = (Akt)listBoxAkter.SelectedItem;

                if (valdakt != null)
                {
                    textBoxAktnamn.Text = valdakt.namn.ToString();
                    richTextBoxAktInf.Text = valdakt.Aktinfo.ToString();
                    textBoxAktStarttid.Text = valdakt.Starttid.ToShortTimeString();
                    textBoxAktSluttid.Text = valdakt.Sluttid.ToShortTimeString();
                    textBoxAktVuxenpris.Text = valdakt.vuxen.ToString();
                    textBoxAktUngdPris.Text = valdakt.ungdom.ToString();
                    TextBoxAktBarnpris.Text = valdakt.barn.ToString();
                }

            }
        }
Example #12
0
        private void listBoxAdminForestallning_SelectedIndexChanged(object sender, EventArgs e)
        {
            textBoxForsaljningsslut.Clear();
              valdforestallning = (Forestallning)listBoxAdminForestallning.SelectedItem;
            if (valdforestallning != null && st != "skapaForestallning")
            {
                  listBoxAkter.DataSource = Databasmetoder.HamtaAktLista(valdforestallning.id);
                  textBoxForestNamn.Text = valdforestallning.namn;
                  richTextBoxForestInf.Text = valdforestallning.generellinfo;
                  textBoxForestDatum1.Text = valdforestallning.datum.ToShortDateString();
                  textBoxForestStarttid.Text = valdforestallning.starttid.ToShortTimeString();
                  textBoxForestSluttid.Text = valdforestallning.sluttid.ToShortTimeString();
                  textBoxVuxenpris.Text = valdforestallning.vuxenpris.ToString();
                  textBoxUngdomspris.Text = valdforestallning.ungdomspris.ToString();
                  textBoxBarnpris.Text = valdforestallning.barnpris.ToString();
                  textBoxForsaljningsslut.Text = valdforestallning.forsaljningsslut.ToShortDateString();

                  if (valdforestallning.friplacering == true)
                  {
                      checkBoxfriPlacering.Checked = true;
                  }
                  else
                  {
                      checkBoxfriPlacering.Checked = false;
                  }

                  if (valdforestallning.open == true)
                  {
                      checkBoxForestallning1.Checked = true;
                  }
                  else
                  {
                      checkBoxForestallning1.Checked = false;
                  }

                      conn.Close();

                      }
        }
Example #13
0
        private void listBoxFöreställning_SelectedIndexChanged(object sender, EventArgs e)
        {
            valdforestallning = (Forestallning)listBoxForestallning.SelectedItem;
            if (valdforestallning != null)
            {
                Rapport();

            }
            else
            {
                MessageBox.Show("Vänligen välj en föreställning för att kunna få en rapport på denna.");
            }
        }
Example #14
0
        private void FinalPage_Load(object sender, EventArgs e)
        {
            tk.fardig = true;

            if (tk.biljetter.Count > 0 && tk.biljetter[0].forestallning.friplacering == true)
            {
                textBox_epost.Text = tk.epost;
                conn.Open();
                foreach (Biljett bilj in tk.biljetter)
                {

                    laggTilliDatabasenBiljetter();

                    richTextBox1.Text += " Biljett ID: " + bilj.ToString();
                    richTextBox1.Text += " \n Föreställningsnamn: " + bilj.forestallning.namn;
                    richTextBox1.Text += " \n Akt: " + bilj.akter.namn;
                    richTextBox1.Text += "\n Datum: " + bilj.forestallning.datum.ToShortDateString();
                    richTextBox1.Text += " \n Tid: " + bilj.akter.Starttid.ToShortTimeString();
                    richTextBox1.Text += "\n Plats: Fri placering";
                    richTextBox1.Text += "\n Pris: " + bilj.pris.ToString();
                    richTextBox1.Text += "\n " + bilj.biljettyp + " \n  \n -------------------------------  \n \n";
                }
                conn.Close();
            }
            else if (tk.biljetter.Count > 0)
            {
                if (tk.biljetter[0].resserverad == true)
                {
                    textBox_epost.Text = tk.epost;
                }

                int totalt = tk.vuxna + tk.ungdom + tk.barn;
                int antalAkter = tk.akter.Count;

                if (tk.biljetter != null)
                {
                    if (tk.hela == true)
                    {
                        foreach (Kund k in tk.kunder)
                        {
                            laddaKundRich(k);
                        }
                    }
                    else
                    {
                        foreach (Biljett bilj in tk.biljetter)
                        {
                            laddaHelafore(bilj);
                        }
                    }
                }
            }
            else
            {
                string query = "select * from kund";

                DataTable dt = new DataTable();
                NpgsqlDataAdapter da = new NpgsqlDataAdapter(query, conn);

                da.Fill(dt);

                conn.Open();

                foreach (DataRow row in dt.Rows)
                {
                    Kund k = new Kund();
                    k.kund_id = (Convert.ToInt32(row["id"]));
                    k.fornamn = (row["namn"].ToString());
                    k.efternamn = (row["efternamn"].ToString());
                    k.epost = (row["mail"].ToString());

                    string query2 = "SELECT biljett.id, akter.aktnamn, forestallning.namn, biljett.pris, biljett.kund_id, forestallning.datum, forestallning.starttid, biljett.plats_id, biljett.fri_placering FROM public.forestallning, public.biljett, public.akter WHERE biljett.forestallning_id = forestallning.id AND biljett.akt_id = akter.id And kund_id = ";
                    query2 += k.kund_id.ToString() + ";";
                    DataTable dt2 = new DataTable();
                    NpgsqlDataAdapter da2 = new NpgsqlDataAdapter(query2, conn);

                    da2.Fill(dt2);

                    foreach (DataRow row2 in dt2.Rows)
                    {
                        Biljett b = new Biljett();
                        Forestallning f = new Forestallning();
                        Akt a = new Akt();
                        b.forestallning = f;
                        b.akter = a;

                        b.biljett_id = (Convert.ToInt32(row2["id"]));
                        b.pris = (Convert.ToInt32(row2["pris"]));
                        b.forestallning.namn = ((row2["namn"]).ToString());
                        b.akter.namn = ((row2["aktnamn"]).ToString());
                        if ((bool)row2["fri_placering"] == false)
                        {
                            b.plats_id = (Convert.ToInt32((row2["plats_id"])));
                        }

                        b.forestallning.datum = (DateTime)row2["datum"];
                        b.akter.Starttid = (DateTime)row2["starttid"];
                        k.bilj.Add(b);
                        tk.biljetter.Add(b);
                    }
                    listBox_kunder.Items.Add(k);
                }
                conn.Close();
            }
        }