示例#1
0
        private void btn_check_schedule_Click(object sender, EventArgs e)
        {
            string  sql = null, member = null, S_id = null, sql1 = null;
            methods m = new methods();

            //bool flag = false;
            listBox_avai_seat.Items.Clear();

            sql = "select [Bus Management System].dbo.Shedule.S_id from [Bus Management System].dbo.Shedule where"
                  + "[Bus Management System].dbo.Shedule.S_Time='" + combo_bustime1.Text + "' and"
                  + " [Bus Management System].dbo.Shedule.Ro_id=(select Road.Road_id from Road "
                  + "where Road.[Route Name]='" + combo_route1.Text + "')";
            member = "S_id";
            S_id   = m.id_sender(sql, member);
            if (S_id == null)
            {
                MessageBox.Show("Wrong Schedule");
            }
Tag:
            sql = "(select BS_id from [Bus Management System].dbo.Bus_Shedule_manage where "
                  + "[Bus Management System].dbo.Bus_Shedule_manage.Date='" + dateTimePicker_ticket1.Text + "' and "
                  + "[Bus Management System].dbo.Bus_Shedule_manage.S_id="
                  + "(select S_id from [Bus Management System].dbo.Shedule where "
                  + "[Bus Management System].dbo.Shedule.S_Time='" + combo_bustime1.Text + "' and "
                  + "[Bus Management System].dbo.Shedule.Ro_id="
                  + "(select Road.Road_id from Road where Road.[Route Name]='" + combo_route1.Text + "')))";
            member = "BS_id";

            string BS_id = m.id_sender(sql, member);

            if (m.flag_of_method)
            {
                string[] arr;

                Console.WriteLine("HMM:" + BS_id);
                sql    = "select  Ticket.[Name Of Seat] from Ticket where Ticket.BS_id='" + BS_id + "'";
                member = "Name Of Seat";
                arr    = m.sendarray(sql, member);
                arr.Reverse();
                for (int i = m.counter; i >= 0; i--)
                {
                    Console.WriteLine("" + arr[i]);
                }
                for (int j = 0; j < m.seat.Length; j++)
                {
                    bool bo = false;
                    for (int i = 0; i <= m.counter; i++)
                    {
                        if (arr[i] != m.seat[j])
                        {
                            bo = true;
                        }
                        if (arr[i] == m.seat[j])
                        {
                            bo = false;
                            break;
                        }
                    }
                    if (bo)
                    {
                        listBox_avai_seat.Items.Add(m.seat[j]);
                    }
                }
                if (m.counter == -1)
                {
                    for (int j = 0; j < m.seat.Length; j++)
                    {
                        listBox_avai_seat.Items.Add(m.seat[j]);
                    }
                }
            }
            else if (!m.flag_of_method)
            {
                bool insert_flag = false;
                sql = "select [Bus Management System].dbo.Shedule.S_id from [Bus Management System].dbo.Shedule where"
                      + "[Bus Management System].dbo.Shedule.S_Time='" + combo_bustime1.Text + "' and"
                      + " [Bus Management System].dbo.Shedule.Ro_id=(select Road.Road_id from Road "
                      + "where Road.[Route Name]='" + combo_route1.Text + "')";
                member = "S_id";
                //string tes_id = null;
                S_id = m.id_sender(sql, member);
                if (S_id == null)
                {
                    //MessageBox.Show("Wrong Schedule");
                    insert_flag = true;
                }
                if (!insert_flag)
                {
                    sql = "insert into Bus_Shedule_manage (S_id,Date) values ('" + S_id + "','" + dateTimePicker_ticket1.Text + "')";
                    m.single_tab_data_Insert(sql);
                    goto Tag;
                }

                //Console.WriteLine("S_id:" + S_id);
                //Console.WriteLine("\n" + dateTimePicker_ticket1.Text);


                // m.single_tab_data_Insert(sql);
            }
        }