Exemplo n.º 1
0
        private void LoadAll()
        {
            dt_items = LoadDatagrid();
            itemsDataGrid.ItemsSource = dt_items.DefaultView;

            dt_locations = LoadLocationsFromDB();
            placeList    = new ArrayList();
            foreach (DataRow r in dt_locations.Rows)
            {
                ItemNameClass place = new ItemNameClass(Int32.Parse(r[0].ToString()), r[1].ToString());
                placeList.Add(place);
            }
            locationComboBox.ItemsSource = placeList;

            dt_types = LoadPartTypesFromDB();
            typelist = new ArrayList();
            foreach (DataRow r in dt_types.Rows)
            {
                ItemNameClass itemtype = new ItemNameClass(Int32.Parse(r[0].ToString()), r[1].ToString());
                typelist.Add(itemtype);
            }
            typeComboBox.ItemsSource = typelist;

            dt_suppliers = LoadSuppliersFromDB();
            supplierlist = new ArrayList();
            foreach (DataRow r in dt_suppliers.Rows)
            {
                ItemNameClass sup = new ItemNameClass(Int32.Parse(r[0].ToString()), r[1].ToString());
                supplierlist.Add(sup);
            }
            supplierComboBox.ItemsSource = supplierlist;
        }
        private void OK_Btn_Click(object sender, RoutedEventArgs e)
        {
            SQLiteCommand sql_cmd = database.CreateCommand();
            String        sql_string;


            if (iDTBox.Text == string.Empty)
            {
                // if iDTBox is empty then this is a new record
                int grpindex = typeGroupComboBox.SelectedIndex;
                if (grpindex == -1)
                {
                    // there is no group type selected
                    sql_string = "INSERT INTO ItemType (ItemType) VALUES ('"
                                 + typeNameTBox.Text + "');";
                }
                else
                {
                    // there is a group selected
                    ItemNameClass selected = (ItemNameClass)itemtypes[grpindex];
                    sql_string = "INSERT INTO ItemType (ItemType, TypeGroup) VALUES ('"
                                 + typeNameTBox.Text + "', '" + selected.getID() + "');";
                }
                sql_cmd.CommandText = sql_string;
                sql_cmd.ExecuteNonQuery();
                LoadDataGrid();
            }
            else
            // else this is an update
            {
                int index    = Int32.Parse("0" + iDTBox.Text);
                int grpindex = typeGroupComboBox.SelectedIndex;
                if (grpindex == -1)
                {
                    // if no group selected
                    sql_string = "UPDATE ItemType SET ItemType = '" + typeNameTBox.Text +
                                 "' WHERE typeID = '" + index + "';";
                }
                else
                {
                    ItemNameClass selected = (ItemNameClass)itemtypes[grpindex];
                    sql_string = "UPDATE ItemType SET ItemType = '" + typeNameTBox.Text +
                                 "', TypeGroup = '" + selected.getID() + "' WHERE typeID = '" + index + "';";
                }
                sql_cmd.CommandText = sql_string;
                sql_cmd.ExecuteNonQuery();
                LoadDataGrid();
            }

            // clear all textboxes and reset okbtn to add new
            iDTBox.Text       = string.Empty;
            typeNameTBox.Text = string.Empty;
            typeGroupComboBox.SelectedIndex = -1;
            OK_Btn.Content = "Add New";
        }
        private void LoadDataGrid()
        {
            SQLiteCommand sql_cmd = database.CreateCommand();

            sql_cmd.CommandText = "SELECT * FROM Item";
            dt_items            = new DataTable();
            SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql_cmd);

            adapter.Fill(dt_items);
            itemsDataGrid.ItemsSource = dt_items.DefaultView;

            // need to also load location, suppliers and itemtypes
            sql_cmd.CommandText = "SELECT * FROM Locations";
            SQLiteDataReader reader = sql_cmd.ExecuteReader();

            placelist = new ArrayList();
            while (reader.Read())
            {
                // placelist.Add(reader.GetString(1));
                places = new ItemNameClass(reader.GetInt32(0), reader.GetString(1));
                placelist.Add(places);
            }
            locComboBox.ItemsSource = placelist;
            reader.Close();

            // need to also load  itemtypes
            sql_cmd.CommandText = "SELECT * FROM ItemType";
            reader   = sql_cmd.ExecuteReader();
            typelist = new ArrayList();
            while (reader.Read())
            {
                types = new ItemNameClass(reader.GetInt32(0), reader.GetString(1));
                typelist.Add(types);
            }
            typeComboBox.ItemsSource = typelist;
            reader.Close();

            // need to also load  suppliers
            sql_cmd.CommandText = "SELECT * FROM Suppliers";
            reader       = sql_cmd.ExecuteReader();
            supplierlist = new ArrayList();
            while (reader.Read())
            {
                suppliers = new ItemNameClass(reader.GetInt32(0), reader.GetString(1));
                supplierlist.Add(suppliers);
            }
            supplierComboBox.ItemsSource = supplierlist;
            reader.Close();
        }
        private void LoadDataGrid()
        {
            SQLiteCommand sql_cmd = database.CreateCommand();

            dt_itemTypes        = new DataTable();
            sql_cmd.CommandText = "SELECT * FROM ItemType";
            SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql_cmd);

            adapter.Fill(dt_itemTypes);
            typeDataGrid.ItemsSource = dt_itemTypes.DefaultView;
            itemtypes.Clear();
            foreach (DataRow r in dt_itemTypes.Rows)
            {
                types = new ItemNameClass(Int32.Parse(r[0].ToString()), r[1].ToString());
                itemtypes.Add(types);
            }
            typeGroupComboBox.ItemsSource = itemtypes;
        }
Exemplo n.º 5
0
        private void supplierComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // user has made a selection of supplier in the supplier combo box.
            // should reset other control to avoid confusion


            int selected = supplierComboBox.SelectedIndex;

            if (selected != -1)
            {
                lookforTBox.Text = String.Empty;
                locationComboBox.SelectedIndex = -1;
                typeComboBox.SelectedIndex     = -1;
                ItemNameClass sup      = (ItemNameClass)supplierComboBox.SelectedItem;
                int           supp_Id  = sup.getID();
                DataTable     dt_found = new DataTable();
                dt_found = retrieveItemsBySupplier(supp_Id);
                itemsDataGrid.ItemsSource = dt_found.DefaultView;
            }
        }
Exemplo n.º 6
0
        private void locationComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // called when user has selected a location in the location combo box.
            // should reset other controls


            int selected = locationComboBox.SelectedIndex;

            if (selected != -1)
            {
                lookforTBox.Text               = String.Empty;
                typeComboBox.SelectedIndex     = -1;
                supplierComboBox.SelectedIndex = -1;
                // confirmed selection made
                ItemNameClass loc      = (ItemNameClass)locationComboBox.SelectedItem;
                int           loc_ID   = loc.getID();
                DataTable     dt_found = new DataTable();
                dt_found = retrieveItemsByLocation(loc_ID);
                itemsDataGrid.ItemsSource = dt_found.DefaultView;
            }
        }
        private void LoadDatagrid()
        {
            dt_locations = new DataTable();
            SQLiteCommand load_cmd = database.CreateCommand();
            String        load_string;

            load_string          = "SELECT * FROM Locations";
            load_cmd.CommandText = load_string;
            SQLiteDataAdapter adapter = new SQLiteDataAdapter(load_cmd);

            adapter.Fill(dt_locations);
            locationdataGrid.ItemsSource = dt_locations.DefaultView;
            places.Clear();
            foreach (DataRow r in dt_locations.Rows)
            {
                place = new ItemNameClass(Int32.Parse(r[0].ToString()), r[1].ToString());
                places.Add(place);
            }
            groupFkCombobox.Items.DetachFromSourceCollection();

            groupFkCombobox.ItemsSource = places;
        }
        private void OK_Btn_Click(object sender, RoutedEventArgs e)
        {
            SQLiteCommand sql_cmd = database.CreateCommand();
            String        sql_string;

            // if the TBox is empty then this is a new entry else it is an update
            if (iDTBox.Text == String.Empty)
            {
                // this is a new entry
                // add to location table
                // MessageBox.Show("This is a new entry ");
                int groupindex = groupFkCombobox.SelectedIndex;
                if (groupindex == -1)
                {
                    sql_string = "INSERT INTO Locations (Location, Type) VALUES ('"
                                 + nameTBox.Text + "', '" + typeTBox.Text + "');";
                }
                else
                {
                    ItemNameClass selected = (ItemNameClass)places[groupindex];
                    sql_string = "INSERT INTO Locations (Location, Type, LocationFK) VALUES ('"
                                 + nameTBox.Text + "', '" + typeTBox.Text + "', '" + selected.getID() + "');";
                }
                // MessageBox.Show(sql_string);
                sql_cmd.CommandText = sql_string;
                sql_cmd.ExecuteNonQuery();
                LoadDatagrid();
            }
            else
            {
                // this is an update
                int index = Int32.Parse("0" + iDTBox.Text);
                {
                    // update the record at index
                    // MessageBox.Show("This is an update on entry " + index);
                    int groupindex = groupFkCombobox.SelectedIndex;
                    if (groupindex == -1)
                    {
                        sql_string = "UPDATE Locations SET Location, = '" + nameTBox.Text +
                                     "', Type = '" + typeTBox.Text + "' WHERE locID = '" + index + "';";
                    }
                    else
                    {
                        ItemNameClass selected = (ItemNameClass)places[groupindex];
                        sql_string = "UPDATE Locations SET Location = '" + nameTBox.Text + "', Type = '" +
                                     typeTBox.Text + "', LocationFK = '" + selected.getID() + "' WHERE locID = '" + index + "';";
                    }
                    // MessageBox.Show(sql_string);
                    sql_cmd.CommandText = sql_string;
                    sql_cmd.ExecuteNonQuery();
                    LoadDatagrid();
                }
            }

            // clear the entries in the textboxes
            iDTBox.Text   = String.Empty;
            nameTBox.Text = String.Empty;
            typeTBox.Text = String.Empty;
            groupFkCombobox.SelectedIndex = -1;
            OK_Btn.Content = "Add New";
            // default, with empty textboxes , is Add new record
        }