private void skapaHelaTempkop(string biljettyp, Akt akt, int pris, Kund k) { if (listBox_akter.SelectedItem != null && listBox_forestallning != null && antal_ar_siffror() == true) { // int loopar = 0; // Tempkop s2 = new Tempkop(); // session = s2; Biljett b = new Biljett(); b.hela = helaforestallningen(); b.akter = akt; b.forestallning = (Forestallning)listBox_forestallning.SelectedItem; b.biljettyp = biljettyp; b.pris = pris; b.resserverad = false; session.biljetter.Add(b); k.bilj.Add(b); } }
private void skapaTempkop(string biljettyp, Akt akt, int pris) { if (listBox_akter.SelectedItem != null && listBox_forestallning != null && antal_ar_siffror() == true) { // int loopar = 0; // Tempkop s2 = new Tempkop(); // session = s2; Biljett b = new Biljett(); b.hela= helaforestallningen(); b.akter = akt; b.forestallning = (Forestallning)listBox_forestallning.SelectedItem; b.biljettyp = biljettyp; b.pris = pris; b.resserverad = false; if(checkBox_fri.Checked == true) { b.forestallning.friplacering = true; } else { b.forestallning.friplacering = false; } session.biljetter.Add(b); // uppdateraPris(); // List<Akt> aktlista = new List<Akt>(); /* foreach (Akt akt in listBox_akter.SelectedItems) { aktlista.Add(akt); loopar++; } */ /* session.akter = aktlista; session.forestallning = (Forestallning)listBox_forestallning.SelectedItem; session.reservation = checkBox1.Checked; session.antal = 0; session.loopar = loopar; */ // antal_ar_siffror(); /* conn.Open(); LaggTillTempkop(); //behövs den? conn.Close(); */ /* int totalpris = 0; 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 aktlista) { 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(); */ } }
private int ReserveraBiljett(string kn) { conn.Close(); conn.Open(); try { string query = "INSERT INTO biljett (pris, forestallning_id, akt_id, biljettyp, plats_id, reserverad, tidsstampel, fri_placering) VALUES(@pris, @forestallning_id, @akt_id, @biljettyp, @plats_id, @reserverad, @tidsstampel, @fri_placering) RETURNING id;"; Biljett biljetten = new Biljett(); if (tk.biljetter[tk.fuskIgen].resserverad == true) { query = "INSERT INTO biljett (pris, forestallning_id, akt_id, biljettyp, plats_id, reserverad, tidsstampel, kund_id, fri_placering) VALUES(@pris, @forestallning_id, @akt_id, @biljettyp, @plats_id, @reserverad, @tidsstampel, @kund_id, @fri_placering) RETURNING id;"; } NpgsqlCommand command = new NpgsqlCommand(query, conn); tk.biljetter[tk.fuskIgen].plats_id = KnappId(kn); command.Parameters.AddWithValue("@pris", tk.biljetter[tk.fuskIgen ].pris); command.Parameters.AddWithValue("@forestallning_id", tk.biljetter[tk.fuskIgen].forestallning.id); command.Parameters.AddWithValue("@akt_id", tk.biljetter[tk.fuskIgen].akter.id); command.Parameters.AddWithValue("@biljettyp", tk.biljetter[tk.fuskIgen].biljettyp); command.Parameters.AddWithValue("@plats_id", tk.biljetter[tk.fuskIgen].plats_id); command.Parameters.AddWithValue("@reserverad", tk.biljetter[tk.fuskIgen].resserverad); command.Parameters.AddWithValue("@tidsstampel", DateTime.Now); command.Parameters.AddWithValue("@fri_placering", tk.biljetter[tk.fuskIgen].forestallning.friplacering); if (tk.biljetter[tk.fuskIgen].resserverad == true) { command.Parameters.AddWithValue("@kund_id", tk.biljetter[tk.fuskIgen].kund_id); } int x = (int)command.ExecuteScalar(); // biljett_id.Add(x); // tk.biljett_id.Add(x); tk.biljetter[tk.fuskIgen].biljett_id = x; tk.biljetter[tk.fuskIgen].kopt = true; tk.fuskIgen++; return x; } catch (Exception ex) { MessageBox.Show("Tyvärr blev platsen precis bokad"); return -1; //throw; } conn.Close(); // nyssInlagdBiljett(); //command.Parameters.AddWithValue("@tidsstampel", session.forestallning.ToString()); //command.Parameters.AddWithValue("@datum", session.vuxna); //command.Parameters.AddWithValue("@tid", session.ungdom); }
private int laggTillAnvandare() { try { string query = "INSERT INTO inlog (anvandarnamn, losenord, fornamn, efternamn, personnr) VALUES(@anvandarnamn, @losenord, @fornamn, @efternamn, @personnr) RETURNING id;"; Biljett biljetten = new Biljett(); NpgsqlCommand command = new NpgsqlCommand(query, conn); command.Parameters.AddWithValue("@anvandarnamn", textBox4.Text); command.Parameters.AddWithValue("@losenord", textBox5.Text); command.Parameters.AddWithValue("@fornamn", textBox1.Text); command.Parameters.AddWithValue("@efternamn", textBox2.Text); command.Parameters.AddWithValue("@personnr", textBox3.Text); int x = (int)command.ExecuteScalar(); // biljett_id.Add(x); // tk.biljett_id.Add(x); // tk.biljetter[tk.fuskIgen].biljett_id = x; // tk.biljetter[tk.fuskIgen].kopt = true; // tk.fuskIgen++; // return x; } catch (Exception ex) { MessageBox.Show("Hopsan " + ex.ToString()); return -1; //throw; } return -1; }
private int laggTilliDatabasenBiljetter() { string query = "INSERT INTO biljett (pris, forestallning_id, akt_id, biljettyp, reserverad, tidsstampel, fri_placering) VALUES(@pris, @forestallning_id, @akt_id, @biljettyp, @reserverad, @tidsstampel, @fri_placering) RETURNING id;"; Biljett biljetten = new Biljett(); if (tk.biljetter[tk.fuskIgen].resserverad == true) { query = "INSERT INTO biljett (pris, forestallning_id, akt_id, biljettyp, reserverad, tidsstampel, kund_id, fri_placering) VALUES(@pris, @forestallning_id, @akt_id, @biljettyp, @reserverad, @tidsstampel, @kund_id, @fri_placering) RETURNING id;"; } NpgsqlCommand command = new NpgsqlCommand(query, conn); command.Parameters.AddWithValue("@pris", tk.biljetter[tk.fuskIgen].pris); command.Parameters.AddWithValue("@forestallning_id", tk.biljetter[tk.fuskIgen].forestallning.id); command.Parameters.AddWithValue("@akt_id", tk.biljetter[tk.fuskIgen].akter.id); command.Parameters.AddWithValue("@biljettyp", tk.biljetter[tk.fuskIgen].biljettyp); command.Parameters.AddWithValue("@reserverad", tk.biljetter[tk.fuskIgen].resserverad); command.Parameters.AddWithValue("@tidsstampel", DateTime.Now); command.Parameters.AddWithValue("@fri_placering", tk.biljetter[tk.fuskIgen].forestallning.friplacering); if (tk.biljetter[tk.fuskIgen].resserverad == true) { command.Parameters.AddWithValue("@kund_id", tk.biljetter[tk.fuskIgen].kund_id); } int x = (int)command.ExecuteScalar(); tk.biljetter[tk.fuskIgen].biljett_id = x; tk.biljetter[tk.fuskIgen].kopt = true; tk.fuskIgen++; return x; }
private void laddaHelafore(Biljett bilj) { 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: " + platsnamn(bilj.plats_id.ToString()); richTextBox1.Text += "\n Pris: " + bilj.pris.ToString(); richTextBox1.Text += "\n " + bilj.biljettyp + " \n \n ------------------------------- \n \n"; }
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(); } }