public frmLineModify(LineDataBean line) { InitializeComponent(); agent = SQLAgent.GetInstance(); cityList = agent.GetCityList(); foreach (var city in cityList) { cmbDep.Items.Add(city.cityName); cmbArr.Items.Add(city.cityName); if (city.cityId.Equals(line.depCity.ToString())) { cmbDep.Text = city.cityName; } if (city.cityId.Equals(line.arrCity.ToString())) { cmbArr.Text = city.cityName; } } id = line.id; txtNum.Text = line.trainNum; txtPrice.Text = line.price.ToString(); dateArr.Value = line.arrDate; dateDep.Value = line.depDate; }
private void btnOrder_Click(object sender, EventArgs e) { if (!isLogin) { MessageBox.Show("You must login before ordering", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); back.Invoke(); this.Close(); } else { int index = dataView.SelectedCells[0].RowIndex; LineDataBean line = lineList[index]; var orders = agent.GetOrdersByUser(this.user_id); foreach (var o in orders) { if (line.id == o.line_id) { MessageBox.Show("You have already ordered one ticket on this train", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } btnOrder.Enabled = false; List <int> seats = new List <int>(); for (int i = 1; i <= 50; i++) { seats.Add(i); } List <int> takenSeats = agent.GetSeatNumsByLine(line.id.ToString()); if (takenSeats.Count >= 50) { MessageBox.Show("This line has been sold out", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (var i in takenSeats) { seats.Remove(i); } Random rdm = new Random(DateTime.Now.TimeOfDay.Milliseconds); int seat = seats[rdm.Next() % 50]; var ret = MessageBox.Show("Train Num: " + dataView.Rows[index].Cells[1].Value + "\n" + "Depature City: " + dataView.Rows[index].Cells[2].Value + "\n" + "Arrival City: " + dataView.Rows[index].Cells[3].Value + "\n" + "Departure Time: " + dataView.Rows[index].Cells[5].Value + "\n" + "Arrival Time: " + dataView.Rows[index].Cells[6].Value + "\n" + "Seat NUm: " + seat + "\n" + "Price: " + dataView.Rows[index].Cells[4].Value, "Order Preview", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ret == DialogResult.Yes) { try { agent.AddOrder(user_id, line.id.ToString(), seat); MessageBox.Show("Tickets ordered", "Finished", MessageBoxButtons.OK, MessageBoxIcon.Information); frmLineRUD_Load(null, null); } catch (Exception ex) { MessageBox.Show("FATAL ERROR\nORDER CANCELED\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }