private void btnTrainList_Click(object sender, EventArgs e) { lvComplex.Clear(); TrainCtrl tc = new TrainCtrl(); gbLvName.Text = "信息视图-车组列表"; lvComplex.Columns.Add("车组名称", 120, HorizontalAlignment.Left); lvComplex.Columns.Add("车厢类型", 120, HorizontalAlignment.Left); lvComplex.Columns.Add("车厢节数", 120, HorizontalAlignment.Left); lvComplex.Columns.Add("容量", 120, HorizontalAlignment.Left); List <object[]> nameList = tc.loadVolume(); for (int k = 0; k < nameList.Count; k++) { ListViewGroup lvg = new ListViewGroup(); lvg.Header = nameList[k][0].ToString() + " 总容量 " + nameList[k][1].ToString(); lvComplex.Groups.Add(lvg); lvComplex.ShowGroups = true; List <object[]> trainList = tc.loadTrain(nameList[k][0].ToString()); ListViewItem[] lvi = new ListViewItem[trainList.Count]; for (int i = 0; i < trainList.Count; i++) { string[] subList = new string[4]; for (int j = 0; j <= 3; j++) { subList[j] = trainList[i][j].ToString(); } lvi[i] = new ListViewItem(subList); lvg.Items.Add(lvi[i]); } lvComplex.Items.AddRange(lvi); } }
private void btnTimeList_Click(object sender, EventArgs e) { lvComplex.Clear(); lvComplex.ShowGroups = false; TimetableCtrl ttc = new TimetableCtrl(); TrainCtrl tc = new TrainCtrl(); TicketCtrl tkc = new TicketCtrl(); gbLvName.Text = "信息视图-车次列表"; lvComplex.Columns.Add("车次", 90, HorizontalAlignment.Left); lvComplex.Columns.Add("车组方式", 60, HorizontalAlignment.Left); lvComplex.Columns.Add("始发站", 90, HorizontalAlignment.Left); lvComplex.Columns.Add("到达站", 90, HorizontalAlignment.Left); lvComplex.Columns.Add("发车时间", 120, HorizontalAlignment.Left); lvComplex.Columns.Add("运行时长", 90, HorizontalAlignment.Left); lvComplex.Columns.Add("票价", 60, HorizontalAlignment.Left); lvComplex.Columns.Add("余票", 60, HorizontalAlignment.Left); List <object[]> timeList = ttc.loadTimetable(); ListViewItem[] lvi = new ListViewItem[timeList.Count]; for (int i = 0; i < timeList.Count; i++) { List <object[]> ListTrain = tc.loadTrainSum(timeList[i][1].ToString()); int sold = tkc.serachTicketFromTimeId(timeList[i][0].ToString()).Count; string remain = (int.Parse(ListTrain[0][0].ToString()) - sold).ToString(); string[] subList = new string[8]; for (int j = 0; j <= 6; j++) { subList[j] = timeList[i][j].ToString(); } subList[7] = remain; lvi[i] = new ListViewItem(subList); } lvComplex.Items.AddRange(lvi); }
private void btnConfirm_Click(object sender, EventArgs e) { TicketCtrl tc = new TicketCtrl(); TimetableCtrl ttc = new TimetableCtrl(); TrainCtrl trc = new TrainCtrl(); string index = (tc.loadMaxId() + 1).ToString(); Ticket t = new Ticket(index, tbName.Text, tbPassId.Text, lvTimetable.SelectedItems[0].Text.ToString()); string trainName = ttc.loadTrainName(lvTimetable.SelectedItems[0].Text.ToString()); if (tc.loadTicket().Count < int.Parse(trc.loadTrain(trainName)[0][3].ToString())) { tc.saveTicket(t); this.Close(); } else { MessageBox.Show("该车次已售完", "购票失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } }