Ejemplo n.º 1
0
 private void btn_Addproductsub(object sender, RoutedEventArgs e)
 {
     if (this.createmode)
     {
         MessageBox.Show("Please save product first", "Information");
     }
     else
     {
         if (products_cb.SelectedItem == null)
         {
             MessageBox.Show("Please select product", "Information");
             return;
         }
         if (tb_productsubquantity.Text == "" || tb_productsubquantity.Text == "0")
         {
             MessageBox.Show("Please add quantity", "Information");
             return;
         }
         var products_cb_selectedobject    = products_cb.SelectedItem as data.dapper.product;
         data.dapper.productsub productsub = new data.dapper.productsub();
         productsub.fk_product_main_in_productsub = selectedproduct.id;
         productsub.fk_product_sub_in_productsub  = products_cb_selectedobject.id;
         productsub.quantity = Convert.ToInt32(tb_productsubquantity.Text);
         productsubrepo.save(productsub);
         dg.Items.Clear();
         var productsubs = this.productsubrepo.getproduct_productsubs(this.selectedproduct.id);
         foreach (var item in productsubs)
         {
             dg.Items.Add(item);
         }
         products_cb.SelectedItem   = null;
         tb_productsubquantity.Text = "";
     }
 }
Ejemplo n.º 2
0
        public void btn_removeproductsub(object sender, RoutedEventArgs e)
        {
            data.dapper.productsub obj = ((FrameworkElement)sender).DataContext as data.dapper.productsub;
            this.productsubrepo.delete(obj);
            dg.Items.Clear();
            var productsubs = this.productsubrepo.getproduct_productsubs(selectedproduct.id);

            foreach (var item in productsubs)
            {
                dg.Items.Add(item);
            }
            //var db = new dbctx();
            //var dbproductsub = db.productsub.Find(obj.id);
            //db.productsub.Remove(dbproductsub);
            //db.SaveChanges();
            //dg.Items.Clear();
            //var productsubs = db.productsub.Where(a => a.fk_product_product_productsub == selectedproduct.id).ToList();
            //foreach (var item in productsubs)
            //{
            //    dg.Items.Add(item);
            //}
        }