private void DeleteFitment_Button_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Do you want to delete selected fitments?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                using (var db = new ProductDBEntitie())
                {
                    DataGridRow row = (DataGridRow)(DataTable.ItemContainerGenerator.ContainerFromItem(DataTable.SelectedItem));
                    DataGridDetailsPresenter presenter = FindVisualChild <DataGridDetailsPresenter>(row);
                    DataTemplate             template  = presenter.ContentTemplate;
                    DataGrid dg = (DataGrid)template.FindName("datagridf", presenter);
                    DataGridCheckBoxColumn cb            = (DataGridCheckBoxColumn)template.FindName("NOf", presenter);
                    List <int>             deleteFitment = new List <int>();
                    foreach (Fitment f in dg.ItemsSource)
                    {
                        try
                        {
                            if (((CheckBox)cb.GetCellContent(f)).IsChecked == true)
                            {
                                deleteFitment.Add(f.id);
                                Fitment fitment = (from c in db.Fitment where c.id == f.id select c).FirstOrDefault();
                                if (fitment != null)
                                {
                                    db.Fitment.Remove(fitment);
                                    db.SaveChanges();
                                }
                            }
                        }
                        catch { }
                    }


                    new ReadFitmentsDB(dg, statusBar);
                }
            }
        }
 private void Delete_Button_Click(object sender, RoutedEventArgs e)
 {
     if (MessageBox.Show("Do you want to delete selected product?", "Confirm", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         foreach (var item in deleteProduct)
         {
             using (var db = new ProductDBEntitie())
             {
                 db.Product.Remove((from c in db.Product where c.sku == item select c).FirstOrDefault());
                 db.SaveChanges();
                 products.Remove((from c in products where c.sku == item select c).FirstOrDefault());
             }
         }
     }
 }
Beispiel #3
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (products != null)
            {
                Product product = new Product();
                product.sku = textBox.Text.ToString();
                using (var db = new ProductDBEntitie())
                {
                    db.Product.Add(product);
                    db.SaveChanges();
                }
                products.Add(product);
            }

            this.Close();
        }
Beispiel #4
0
        private void init_fitment()
        {
            fitment = new Fitment();
            Make make = new Make();

            string[] values = lines[i].Split('|');
            for (int j = 0; j < values.Count(); j++)
            {
                if (headers[j] == "Make")
                {
                    make.make1 = values[j];
                }
                else if (headers[j] == "Model")
                {
                    make.model = values[j];
                }
                else if (headers[j] == "ourMake")
                {
                    make.our_make = values[j];
                }
                else if (headers[j] == "ourMake")
                {
                    make.our_make = values[j];
                }
                else if (headers[j] == "ourModel")
                {
                    make.our_model = values[j];
                }
                else if (headers[j] == "_BodyTypeName_")
                {
                    make.body_type_name = values[j];
                }
                else if (headers[j] == "_MfrBodyCodeName_")
                {
                    make.mf_body_code_name = values[j];
                }
                else if (headers[j] == "ourBodyTypeName")
                {
                    make.our_body_type_name = values[j];
                }
                else
                {
                    try
                    {
                        fitment.init_fitment(headers[j], values[j]);
                    }
                    catch { }
                }
            }
            using (var db = new ProductDBEntitie())
            {
                try
                {
                    var make_ = (from c in db.Make
                                 where c.make1 == make.make1 && c.model == make.model && c.our_make == make.our_make && c.body_type_name == make.body_type_name
                                 select c).ToList();
                    if (make_.Count() == 0)
                    {
                        db.Make.Add(make);
                        db.SaveChanges();
                        fitment.id_make = make.id;
                        fitment.Make    = make;
                    }
                    else
                    {
                        fitment.id_make = make_.First().id;
                        fitment.Make    = make_.First();
                    }
                }
                catch { }

                fitment.Product = (from c in db.Product where c.sku == fitment.sku select c).FirstOrDefault();
                try
                {
                    BrandName brand = fitment.BrandName;
                    fitment.BrandName = null;
                    Make m = fitment.Make;
                    fitment.Make = null;
                    db.Fitment.Add(fitment);
                    db.SaveChanges();
                    fitment.Make      = m;
                    fitment.BrandName = brand;
                }
                catch (Exception e) {
                }
            }
        }
Beispiel #5
0
        private void init_product()
        {
            product = new Product();
            Additionally0 additionally0 = new Additionally0();
            Additionally  additionally  = new Additionally();
            ForName       forName       = new ForName();

            string[] values = lines[i].Split('|');
            for (int j = 0; j < values.Count(); j++)
            {
                if (headers[j].Equals("IMG_1"))
                {
                    Resource res = new Resource();
                    res.img1 = values[j++];
                    try
                    {
                        if (headers[j].Equals("IMG_2"))
                        {
                            res.img2 = values[j++];
                        }
                        if (headers[j].Equals("IMG_3"))
                        {
                            res.img3 = values[j++];
                        }
                        if (headers[j].Equals("IMG_4"))
                        {
                            res.img4 = values[j++];
                        }
                        if (headers[j].Equals("PDF_1"))
                        {
                            res.pdf = values[j++];
                        }
                        if (headers[j].Equals("Icon"))
                        {
                            res.pdf = values[j++];
                        }
                    }
                    catch (IndexOutOfRangeException e) { }
                    using (var db = new ProductDBEntitie())
                    {
                        db.Resource.Add(res);
                        db.SaveChanges();
                        additionally.Resource    = res;
                        additionally.id_resource = res.id;
                    }

                    continue;
                }


                if (headers[j] == "forname1")
                {
                    forName.forname1 = values[j];
                    forName.forname2 = values[j + 1];
                    using (var db = new ProductDBEntitie())
                    {
                        try
                        {
                            db.ForName.Add(forName);
                            db.SaveChanges();
                        }
                        catch
                        {
                            string str = values[j + 1];
                            forName = (from c in db.ForName where c.forname2.Equals(str) select c).FirstOrDefault();
                        }
                        additionally0.id_forname = forName.id;
                        additionally0.ForName    = (ForName)forName;
                    }
                    j++;
                }
                if (headers[j] == "forname2")
                {
                    j++;
                }
                try
                {
                    if (!product.init_product(headers[j], values[j], ref additionally0))
                    {
                        product.init_product(headers[j], values[j], ref additionally);
                    }
                }
                catch { }
            }
            using (var db = new ProductDBEntitie())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        if (additionally0.ForName != null)
                        {
                            additionally0.ForName = null;
                            db.Additionally0.Add(additionally0);
                            db.SaveChanges();
                            product.id_additionally0 = additionally0.id;
                            product.Additionally0    = additionally0;
                        }
                    }
                    catch { }

                    try
                    {
                        if (additionally.Resource != null)
                        {
                            Resource res = additionally.Resource;
                            additionally.Resource = null;
                            db.Additionally.Add(additionally);
                            db.SaveChanges();
                            additionally.Resource   = res;
                            product.id_additionally = additionally.id;
                            product.Additionally    = additionally;
                        }
                    }
                    catch { }

                    try
                    {
                        BrandName drand = product.BrandName;
                        product.BrandName     = null;
                        product.Additionally  = null;
                        product.Additionally0 = null;
                        db.Product.Add(product);
                        db.SaveChanges();
                        product.BrandName     = drand;
                        additionally0.ForName = forName;
                        product.Additionally0 = additionally0;
                        product.Additionally  = additionally;
                        transaction.Commit();
                    }
                    catch (Exception e)
                    {
                        product = null;
                        transaction.Rollback();
                    }
                }
            }
        }
        private void datagridf_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            DataGridRow row = (DataGridRow)(DataTable.ItemContainerGenerator.ContainerFromItem(DataTable.SelectedItem));
            DataGridDetailsPresenter presenter = FindVisualChild <DataGridDetailsPresenter>(row);
            DataTemplate             template  = presenter.ContentTemplate;
            DataGrid dg = (DataGrid)template.FindName("datagridf", presenter);
            ObservableCollection <Fitment> fitments = new ObservableCollection <Fitment>();

            foreach (Fitment c in dg.ItemsSource)
            {
                fitments.Add(c);
            }
            TextBox t      = e.EditingElement as TextBox;
            String  value  = t.Text.ToString();
            String  header = e.Column.Header.ToString().ToUpper().Replace(" ", "");
            var     id     = (e.Row.DataContext as Fitment).id;

            if (id == 0)
            {
                using (var db = new ProductDBEntitie())
                {
                    Fitment f = new Fitment();
                    f.sku = (DataTable.SelectedItem as Product).sku;
                    db.Fitment.Add(f);
                    db.SaveChanges();
                    fitments.Add(f);
                    id = f.id;
                }
            }
            //mAKE
            using (var db = new ProductDBEntitie())
            {
                var fitment = (from c in db.Fitment where c.id == id select c).FirstOrDefault();
                var make    = (from c in db.Make where fitment.id_make == c.id select c).FirstOrDefault();
                if (make == null)
                {
                    make = new Make();
                    db.Make.Add(make);
                    db.SaveChanges();
                    fitment.id_make = make.id;
                    db.SaveChanges();
                }
                if (header == "MAKE")
                {
                    make.make1 = value;
                }
                else if (header == "MODEL")
                {
                    make.model = value;
                }
                else if (header == "OURMAKE")
                {
                    make.our_make = value;
                }
                else if (header == "OURMODEL")
                {
                    make.our_model = value;
                }
                else if (header == "BODYTYPENAME")
                {
                    make.body_type_name = value;
                }
                else if (header == "_MFRBODYCODENAME_")
                {
                    make.mf_body_code_name = value;
                }
                else if (header == "OURBODYTYPENAME")
                {
                    make.our_body_type_name = value;
                }
                else
                {
                    try
                    {
                        fitment.init_fitment(header, t.Text.ToString());
                    }
                    catch (Exception ee) { MessageBox.Show(ee.Message); }
                }
                db.SaveChanges();
            }
        }
        private void DataTable_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            TextBox t      = e.EditingElement as TextBox;
            String  value  = t.Text.ToString();
            String  header = e.Column.Header.ToString();
            var     sku    = (e.Row.DataContext as Product).sku;

            /// additionally additionally0
            ///
            if (sku != null)
            {
                using (var db = new ProductDBEntitie())
                {
                    var product = (from c in db.Product where c.sku == sku select c).FirstOrDefault();
                    if (product != null)
                    {
                        var additionally  = (from c in db.Additionally where c.id == product.id_additionally select c).FirstOrDefault();
                        var additionally0 = (from c in db.Additionally0 where c.id == product.id_additionally0 select c).FirstOrDefault();

                        if (additionally == null)
                        {
                            additionally = new Additionally();
                            db.Additionally.Add(additionally);
                            db.SaveChanges();
                            product.id_additionally = additionally.id;
                            db.SaveChanges();
                        }
                        Resource res = (from c in db.Resource where c.id == additionally.id_resource select c).FirstOrDefault();

                        if (header.Equals("IMG_1"))
                        {
                            res.img1 = value;
                        }
                        if (header.Equals("IMG_2"))
                        {
                            res.img2 = value;
                        }
                        if (header.Equals("IMG_3"))
                        {
                            res.img3 = value;
                        }
                        if (header.Equals("IMG_4"))
                        {
                            res.img4 = value;
                        }
                        if (header.Equals("PDF_1"))
                        {
                            res.pdf = value;
                        }
                        if (header.Equals("Icon"))
                        {
                            res.pdf = value;
                        }

                        db.Resource.Add(res);
                        db.SaveChanges();
                        additionally.Resource    = res;
                        additionally.id_resource = res.id;
                        db.SaveChanges();


                        if (additionally0 == null)
                        {
                            additionally0 = new Additionally0();
                            db.Additionally0.Add(additionally0);
                            db.SaveChanges();
                            product.id_additionally0 = additionally0.id;
                            db.SaveChanges();
                        }
                        var forName = (from c in db.ForName where c.id == additionally0.id_forname select c).FirstOrDefault();
                        if (header == "FORNAME1")
                        {
                            forName.forname1 = value;
                            try
                            {
                                db.ForName.Add(forName);
                                db.SaveChanges();
                            }
                            catch
                            {
                                string str = value;
                                forName = (from c in db.ForName where c.forname2.Equals(str) select c).FirstOrDefault();
                            }
                            additionally0.id_forname = forName.id;
                            additionally0.ForName    = (ForName)forName;
                            db.SaveChanges();
                            return;
                        }
                        if (header == "FORNAME2")
                        {
                            forName.forname2 = value;
                            try
                            {
                                db.ForName.Add(forName);
                                db.SaveChanges();
                            }
                            catch
                            {
                                string str = value;
                                forName = (from c in db.ForName where c.forname2.Equals(str) select c).FirstOrDefault();
                            }
                            additionally0.id_forname = forName.id;
                            additionally0.ForName    = (ForName)forName;
                            db.SaveChanges();
                            return;
                        }

                        try
                        {
                            if (!product.init_product(header, t.Text.ToString(), ref additionally0))
                            {
                                product.init_product(header, value, ref additionally);
                            }
                        }
                        catch (Exception ee) { MessageBox.Show(ee.Message); }
                        BrandName b = product.BrandName;
                        product.BrandName = null;
                        db.SaveChanges();
                        product.BrandName = b;
                    }
                }
            }
            else
            {
                SetSKU setSKU = new SetSKU(products);
                setSKU.ShowDialog();
            }
        }