예제 #1
0
    private void RemoveConcert(long id)
    {
        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();

        SqlCommand cmd = new SqlCommand("delete from concerts where id=" + id, con);

        cmd.ExecuteNonQuery();
    }
예제 #2
0
    private int displayConcertsBySqlCommand(string sql)
    {
        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();
        SqlCommand cmd = new SqlCommand(sql, con);

        SqlDataReader reader = cmd.ExecuteReader();
        int           index  = 0;

        Response.Write("<div class='concert_list'>");

        while (reader.Read())
        {
            if (index > CONCERT_PAGE_COUNT - 1)
            {
                index++;
                break;
            }

            ConcertInfo CInfo = new ConcertInfo();
            CInfo.ConcertID   = long.Parse(reader["id"].ToString());
            CInfo.Name        = reader["name"].ToString();
            CInfo.Poster      = reader["poster"].ToString();
            CInfo.Description = reader["description"].ToString();
            CInfo.Actor       = reader["actor"].ToString();

            string strShortDes = (CInfo.Description.Length <= SHORT_DESCRIPTION_COUNT) ?
                                 CInfo.Description : CInfo.Description.Substring(0, SHORT_DESCRIPTION_COUNT);

            Response.Write("<div class='home_poster'>" +
                           "<a href='DetailWeb.aspx?id=" + CInfo.ConcertID + "'>" +
                           "<img class='home_poster' src='/" + CInfo.Poster + "'/>" +
                           "</a></div>");

            Response.Write("<div class='home_text_info'>");

            Response.Write("<a href='DetailWeb.aspx?id=" + CInfo.ConcertID + "'>" +
                           "<span class='concert_name'>" + CInfo.Name + "</span></a><br/>" +
                           "表演:" + CInfo.Actor + "<br/>" +
                           "<br/>" + strShortDes);

            Response.Write("</div>");


            index++;
        }

        Response.Write("</div>");
        reader.Close();
        con.Close();
        return(index);
    }
예제 #3
0
    private void RemoveScreening(long screeningid)
    {
        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();

        SqlCommand cmd = new SqlCommand("delete from seats where screeningid=" + screeningid, con);

        cmd.ExecuteNonQuery();
        cmd = new SqlCommand("delete from screenings where screeningid=" + screeningid, con);
        cmd.ExecuteNonQuery();

        con.Close();
    }
예제 #4
0
    private void MakeSure()
    {
        List <int> Tackets = CheckAvaliable();

        if (Tackets.Count == 0)
        {
            return;
        }

        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();
        SqlCommand    cmd    = new SqlCommand("select name from concerts where id=" + ConcertIndex, con);
        SqlDataReader reader = cmd.ExecuteReader();

        reader.Read();
        string NameBuffer     = reader["name"].ToString();
        string LocationBuffer = ScStock[pflist.SelectedIndex].Location;
        string TimeBuffer     = ScStock[pflist.SelectedIndex].Time;
        float  PriceBuffer    = ScStock[pflist.SelectedIndex].Price;
        string SeatsBuffer    = "";
        string PrintBuffer    = "音樂會名稱:" + NameBuffer + "\\n";

        reader.Close();

        PrintBuffer += "演出地點:" + LocationBuffer + "\\n";
        PrintBuffer += "演出時間:" + TimeBuffer + "\\n";
        PrintBuffer += "售票單價:" + PriceBuffer + "\\n";
        PrintBuffer += "已購買座位爲:";

        Tackets.ForEach
        (
            delegate(int index)
        {
            SeatsBuffer += index + " ";
            cmd          = new SqlCommand("update seats set avaliable='0' where avaliable='1' and screeningid=" + ScStock[pflist.SelectedIndex].ScreeningID + "and position=" + index, con);
            cmd.ExecuteNonQuery();
        }
        );
        con.Close();

        CreateBill(long.Parse(Session["id"].ToString()), NameBuffer, ScStock[pflist.SelectedIndex].ScreeningID, ScStock[pflist.SelectedIndex].Location, ScStock[pflist.SelectedIndex].Time, SeatsBuffer, ScStock[pflist.SelectedIndex].Price * Tackets.Count);

        PrintBuffer += SeatsBuffer + "\\n";
        PrintBuffer += "總價:" + ScStock[pflist.SelectedIndex].Price * Tackets.Count + "元";

        Response.Write("<script language='javascript'>alert('" + PrintBuffer + "'); location.href='DetailWeb.aspx?id=" + ConcertIndex + "&index=" + pflist.SelectedIndex + "'</script>");
    }
예제 #5
0
    private void LoadConcerts()
    {
        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();
        SqlCommand    cmd    = new SqlCommand("select id,name from concerts", con);
        SqlDataReader reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            ConcertInfo Info = new ConcertInfo();
            Info.ConcertID = long.Parse(reader["id"].ToString());
            Info.Name      = reader["name"].ToString();
            Concerts.Add(Info);
            LoadScreenings(Info.ConcertID);
        }
        reader.Close();
        con.Close();
    }
예제 #6
0
    private void LoadSqlSeatsInfo()
    {
        SqlConnection SqlServer = InfoSqlConnect.createConnection();

        SqlServer.Open();

        SqlCommand    cmd    = new SqlCommand("select * from seats where screeningid=" + ScStock[pflist.SelectedIndex].ScreeningID, SqlServer);
        SqlDataReader reader = cmd.ExecuteReader();

        ScStock[pflist.SelectedIndex].Seats = new List <SeatInfo>();
        while (reader.Read())
        {
            SeatInfo Info = new SeatInfo();
            Info.Position    = int.Parse(reader["position"].ToString());
            Info.IsAvaliable = reader["avaliable"].ToString() == "1";
            ScStock[pflist.SelectedIndex].Seats.Add(Info);
        }
        SqlServer.Close();
    }
예제 #7
0
    private bool ConcertInsert()
    {
        SqlConnection con = InfoSqlConnect.createConnection();

        con.Open();
        ConcertInfo info = new ConcertInfo();

        info.ConcertID   = long.Parse(TBId.Text);
        info.Name        = TBName.Text;
        info.Description = TBDescription.Text;
        info.Actor       = TBActor.Text;
        if (UploadImage.FileName == null || UploadImage.FileName.Length <= 0)
        {
            info.Poster = "";
        }
        else
        {
            info.Poster = "image/poster/" + UploadImage.FileName;
        }

        SqlCommand cmd = new SqlCommand("insert into concerts values(" +
                                        info.ConcertID + ",'" +
                                        info.Name + "','" +
                                        info.Description + "','" +
                                        info.Actor + "','" +
                                        info.Poster + "')", con);

        int res = -1;

        try
        {
            res = cmd.ExecuteNonQuery();
        }
        catch
        {
            return(false);
        }
        if (res < 0)
        {
            return(false);
        }
        return(true);
    }
예제 #8
0
    private void CancelBill(string message)
    {
        long id = long.Parse(message.Split('#')[0]);

        SqlConnection con = UserSqlConnect.createConnection();

        con.Open();
        SqlCommand cmd = new SqlCommand("delete from bill where id=" + id, con);

        cmd.ExecuteNonQuery();
        con.Close();

        con = InfoSqlConnect.createConnection();
        con.Open();

        long          sid         = long.Parse(message.Split('#')[1]);
        List <string> SeatsBuffer = new List <string>(message.Split('#')[2].Trim().Split(' '));

        SeatsBuffer.ForEach(strPosition => { cmd = new SqlCommand("update seats set avaliable='1' where avaliable='0' and screeningid=" + sid + "and position=" + strPosition, con); cmd.ExecuteNonQuery(); });
        con.Close();
    }
예제 #9
0
    private void LoadScreenings(long id)
    {
        List <ScreeningsInfo> Screenings = new List <ScreeningsInfo>();
        SqlConnection         con        = InfoSqlConnect.createConnection();

        con.Open();
        SqlCommand    cmd    = new SqlCommand("select * from screenings where id=" + id, con);
        SqlDataReader reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            ScreeningsInfo Info = new ScreeningsInfo();
            Info.ScreeningID = long.Parse(reader["screeningid"].ToString());
            Info.Location    = reader["location"].ToString();
            Info.Time        = reader["time"].ToString();
            Screenings.Add(Info);
        }
        ScreeningStock.Add(Screenings);
        reader.Close();
        con.Close();
    }
예제 #10
0
    private void LoadSqlSceeningsInfo()
    {
        SqlConnection SqlServer = InfoSqlConnect.createConnection();

        SqlServer.Open();
        SqlCommand    cmd    = new SqlCommand("select * from screenings where id=" + ConcertIndex, SqlServer);
        SqlDataReader reader = cmd.ExecuteReader();

        while (reader.Read())
        {
            ScreeningsInfo Info = new ScreeningsInfo();
            Info.ScreeningID = long.Parse(reader["screeningid"].ToString());
            Info.Time        = reader["time"].ToString();
            Info.Location    = reader["location"].ToString();
            Info.Price       = float.Parse(reader["price"].ToString());
            Info.Seats       = new List <SeatInfo>();
            ScStock.Add(Info);
            pflist.Items.Add(Info.Location);
            TimeInfo.Text  = "演出時間:" + Info.Time;
            PriceInfo.Text = "座位單價:" + Info.Price + "元";
        }

        SqlServer.Close();
    }
예제 #11
0
    private List <int> CheckAvaliable()
    {
        List <int> SeatPicked = new List <int>();

        bool SaleOff = true;

        ScStock[pflist.SelectedIndex].Seats.ForEach
        (
            delegate(SeatInfo SInfo)
        {
            if (SInfo.CBID.Checked)
            {
                SeatPicked.Add(SInfo.Position);
            }
            if (SInfo.IsAvaliable)
            {
                SaleOff = false;
            }
        }
        );

        if (SaleOff)
        {
            Response.Write("<script language='javascript'>alert('該場票已售完哦!'); location.href='DetailWeb.aspx?id=" + ConcertIndex + "';</script>");
            return(new List <int>());
        }

        if (SeatPicked.Count < 1)
        {
            Response.Write("<script language='javascript'>alert('還沒有選票哦!');</script>");
            return(new List <int>());
        }



        SqlConnection SqlServer = InfoSqlConnect.createConnection();

        SqlServer.Open();

        bool arror = false;

        SeatPicked.ForEach
        (
            delegate(int index)
        {
            SqlCommand cmd       = new SqlCommand("select * from seats where screeningid=" + ScStock[pflist.SelectedIndex].ScreeningID + "and position=" + index, SqlServer);
            SqlDataReader reader = cmd.ExecuteReader();
            reader.Read();
            if (reader["avaliable"].ToString() != "1")
            {
                arror = true;
                return;
            }
            reader.Close();
        }
        );

        SqlServer.Close();
        if (arror)
        {
            return(new List <int>());
        }

        return(SeatPicked);
    }
예제 #12
0
    private bool InsertScreeningsAndSeats()
    {
        DataTable dataTableScreenings = new DataTable();

        dataTableScreenings.Columns.AddRange(new DataColumn[] {
            new DataColumn("id", typeof(long)),
            new DataColumn("screeningid", typeof(long)),
            new DataColumn("location", typeof(string)),
            new DataColumn("time", typeof(string)),
            new DataColumn("price", typeof(float))
        });

        DataTable dataTableSeats = new DataTable();

        dataTableSeats.Columns.AddRange(new DataColumn[] {
            new DataColumn("screeningid", typeof(long)),
            new DataColumn("avaliable", typeof(char)),
            new DataColumn("position", typeof(int)),
        });

        int  AllSeats  = 0;
        long concertid = long.Parse(TBId.Text);

        string[] lines = TBPer.Value.Split('\n');
        for (int i = 0; i < lines.Length; i++)
        {
            if (lines[i].Length <= 0)
            {
                continue;
            }

            string[] args         = lines[i].Split('#');
            long     screeningsid = long.Parse(args[0]);
            string   location     = args[1];
            string   time         = args[2];
            float    price        = float.Parse(args[3]);
            int      seatCount    = int.Parse(args[4]);
            AllSeats += seatCount;

            DataRow rowScreening = dataTableScreenings.NewRow();
            rowScreening[0] = concertid;
            rowScreening[1] = screeningsid;
            rowScreening[2] = location;
            rowScreening[3] = time;
            rowScreening[4] = price;
            dataTableScreenings.Rows.Add(rowScreening);

            for (int j = 1; j <= seatCount; j++)
            {
                DataRow rowSeat = dataTableSeats.NewRow();
                rowSeat[0] = screeningsid;
                rowSeat[1] = '1';
                rowSeat[2] = j;
                dataTableSeats.Rows.Add(rowSeat);
            }
        }

        SqlConnection con      = InfoSqlConnect.createConnection();
        SqlBulkCopy   bulkCopy = new SqlBulkCopy(con);

        con.Open();
        bulkCopy.DestinationTableName = "screenings";
        bulkCopy.BatchSize            = lines.Length;

        try
        {
            if (dataTableScreenings.Rows.Count > 0)
            {
                bulkCopy.WriteToServer(dataTableScreenings);
            }
        }
        catch
        {
            con.Close();
            return(false);
        }

        bulkCopy.DestinationTableName = "seats";
        bulkCopy.BatchSize            = AllSeats;
        bulkCopy.WriteToServer(dataTableSeats);

        con.Close();

        return(true);
    }