コード例 #1
0
        private void Update_Btn_Click(object sender, RoutedEventArgs e)
        {
            int selected = dataGrid1.SelectedIndex;

            if (selected == -1)
            {
                MessageBox.Show("Select an item to edit");
            }
            else
            {
                List <string> categories    = new List <string>();
                List <string> manufacturers = new List <string>();

                DataView view = new DataView(dt);

                DataTable distinctCategories = new DataTable();
                distinctCategories = view.ToTable(true, "Category");
                foreach (DataRow row in distinctCategories.Rows)
                {
                    categories.Add(row[0].ToString());
                }

                DataTable distinctManufacturer = new DataTable();
                distinctManufacturer = view.ToTable(true, "Manufacturer");
                foreach (DataRow row in distinctManufacturer.Rows)
                {
                    manufacturers.Add(row[0].ToString());
                }


                product = new LogicLayer.Objects.Product();
                DataRowView tempRow = (DataRowView)dataGrid1.SelectedItems[0];
                product.productName  = tempRow["ProductName"].ToString();
                product.price        = int.Parse(tempRow["OfferedPrice"].ToString());
                product.category     = tempRow["Category"].ToString();
                product.manufacturer = tempRow["Manufacturer"].ToString();
                product.quantity     = int.Parse(tempRow["Quantity"].ToString());
                product.dateAdded    = DateTime.Parse(tempRow["DateAdded"].ToString());

                Stock_AddItem stock_Add = new Stock_AddItem(product, true);
                stock_Add.SetComboValues(categories, manufacturers);

                if (stock_Add.ShowDialog() == true)
                {
                    dt.Rows[selected]["ProductName"]  = product.productName;
                    dt.Rows[selected]["OfferedPrice"] = product.price.ToString();
                    dt.Rows[selected]["Category"]     = product.category;
                    dt.Rows[selected]["Manufacturer"] = product.manufacturer;
                    dt.Rows[selected]["Quantity"]     = product.quantity.ToString();
                    dt.Rows[selected]["DateAdded"]    = product.dateAdded;

                    UpdateData();
                }
            }
        }
コード例 #2
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            List <string> categories    = new List <string>();
            List <string> manufacturers = new List <string>();

            DataView view = new DataView(dt);

            DataTable distinctCategories = new DataTable();

            distinctCategories = view.ToTable(true, "Category");
            foreach (DataRow row in distinctCategories.Rows)
            {
                categories.Add(row[0].ToString());
            }

            DataTable distinctManufacturer = new DataTable();

            distinctManufacturer = view.ToTable(true, "Manufacturer");
            foreach (DataRow row in distinctManufacturer.Rows)
            {
                manufacturers.Add(row[0].ToString());
            }

            product = new LogicLayer.Objects.Product();
            Stock_AddItem stock_Add = new Stock_AddItem(product, false);

            stock_Add.SetComboValues(categories, manufacturers);
            if (stock_Add.ShowDialog() == true)
            {
                DataRow dr = dt.NewRow();

                dr["ProductName"]  = product.productName;
                dr["OfferedPrice"] = product.price.ToString();
                dr["Category"]     = product.category;
                dr["Manufacturer"] = product.manufacturer;
                dr["Quantity"]     = product.quantity.ToString();
                dr["DateAdded"]    = product.dateAdded;
                dt.Rows.Add(dr);
                UpdateData();
            }
        }