示例#1
0
        public DetCarInfo GetSavedCar(int ID)
        {
            DetCarInfo   sc    = new DetCarInfo();
            String       query = String.Format("SELECT car.ID, Company, Model, Year, Category, Type, Fuel, Transmission, Drive, Engine, DischargeS, DischargeO, DischargeM, Power, MaxSpeed, Seats, Doors, Acceleration, Price, Pledge FROM {0}.car, {0}.company, {0}.drive, {0}.fuel, {0}.transmission, {0}.type, {0}.category WHERE car.Company_ID = company.ID AND car.Category_ID = category.ID AND car.Type_ID = type.ID AND car.Fuel_ID = fuel.ID AND car.Transmission_ID = transmission.ID AND car.Drive_ID = drive.ID AND car.ID = {1}", DataBase, ID);
            MySqlCommand cmd   = new MySqlCommand(query, serverconn);

            try
            {
                serverconn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();
                reader.Read();
                sc.Id           = int.Parse(reader["ID"].ToString());
                sc.Company      = reader["Company"].ToString();
                sc.Model        = reader["Model"].ToString();
                sc.Category     = reader["Category"].ToString();
                sc.Year         = int.Parse(reader["Year"].ToString());
                sc.Type         = reader["Type"].ToString();
                sc.Fuel         = reader["Fuel"].ToString();
                sc.Transmission = reader["Transmission"].ToString();
                sc.Drive        = reader["Drive"].ToString();
                sc.Engine       = int.Parse(reader["Engine"].ToString());
                sc.DischargeS   = double.Parse(reader["DischargeS"].ToString());
                sc.DischargeO   = double.Parse(reader["DischargeO"].ToString());
                sc.DischargeM   = double.Parse(reader["DischargeM"].ToString());
                sc.Power        = int.Parse(reader["Power"].ToString());
                sc.Maxspeed     = int.Parse(reader["MaxSpeed"].ToString());
                sc.Seats        = int.Parse(reader["Seats"].ToString());
                sc.Doors        = int.Parse(reader["Doors"].ToString());
                sc.Acceleration = double.Parse(reader["Acceleration"].ToString());
                sc.Price        = int.Parse(reader["Price"].ToString());
                sc.Pledge       = int.Parse(reader["Pledge"].ToString());
            }
            catch (MySqlException ex)
            {
                switch (ex.Number)
                {
                case 1042:
                {
                    MessageBox.Show("Немає доступу до серверу");
                    sc = null;
                }
                break;
                }
            }
            finally
            {
                serverconn.Close();
            }
            return(sc);
        }
        private void CarInfo_Click(object sender, MouseButtonEventArgs e)
        {
            DataRowView row = dataGrid.SelectedItem as DataRowView;

            if (row != null)
            {
                int        value = int.Parse(row.Row.ItemArray[0].ToString());
                DetCarInfo sc    = s.GetSavedCar(value);
                if (sc != null)
                {
                    new DetailedInfoWindow(s, sc).ShowDialog();
                }
            }
        }
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            DataRowView row = dataGrid.SelectedItem as DataRowView;

            if (row != null)
            {
                int        value = int.Parse(row.Row.ItemArray[0].ToString());
                DetCarInfo sc    = s.GetSavedCar(value);
                if (sc != null)
                {
                    edw = new EditWindow(s, sc);
                    if (edw.ShowDialog() == true)
                    {
                        UpdateTable();
                    }
                }
            }
        }
示例#4
0
 public EditWindow(Session s, DetCarInfo cinfo)
 {
     InitializeComponent();
     this.s     = s;
     this.cinfo = cinfo;
 }