Example #1
0
        async void lb4_napolnenie()//наполнение листбокса
        {
            log.Add("наполнение старт");
            treespis Treespis = (lb3.SelectedItem as TreeViewItem).Tag as treespis;
            var      json     = await Task.Run(() => loadsinch("load_object", "category=" + Treespis.id_server));                   // выполняется асинхронно

            log.Add("получили джсон ");
            List <Models3d> server = JsonConvert.DeserializeObject <List <Models3d> >(json);


            log.Add("преобразовани жсон в класс ");
            foreach (var elam in server)
            {
                if (Uri.IsWellFormedUriString(elam.jpg_path, UriKind.Absolute))
                {
                    BitmapImage bi3 = new BitmapImage();
                    bi3.BeginInit();
                    bi3.UriSource = new Uri(elam.jpg_path);
                    bi3.EndInit();

                    elam.jpgsource = bi3;
                    //   img_inp.Source =
                }
                else
                {
                    elam.jpgsource = null;
                }
            }

            log.Add("закончили цикл");


            lb4.ItemsSource = null;
            lb4.ItemsSource = (server);
        }
        //private const string MODEL_PATH = @"C:\!qwerty\TreeCadN\WpfApplication1\bin\Debug\3dsObject\User\Розетки\1_131483728943324771.3ds";

        public kommunikacii_dial_imp(kommunikacii_main ctx, string pathBD, Models3d model, treespis category)
        {
            InitializeComponent();

            this.ctx      = ctx;
            this.pathBD   = pathBD;
            this.model    = model;
            this.category = category;


            if (model != null)
            {
                alt_nazv = model.name;

                btn2.IsEnabled = false;
                tb1.IsEnabled  = false;

                tb1.Text = model.path;
                if ("/TreeCadN;component/Foto/nofoto.jpg" == model.jpg_path || !File.Exists(model.jpg_path))
                {
                    tb2.Text = "";
                }
                else
                {
                    tb2.Text = model.jpg_path;
                }
                if (!File.Exists(model.jpg_ugo))
                {
                    tb3.Text = "";
                }
                else
                {
                    tb3.Text = model.jpg_ugo;
                }
                tb4.Text = model.name;

                tx.Text = model.x;
                ty.Text = model.y;
                tz.Text = model.z;

                ModelVisual3D device3D  = new ModelVisual3D();
                Model3D       dmodel3ds = Display3d(model.path);

                device3D.Content = dmodel3ds;

                //     viewPort3d.Children.Add(device3D);
                //        viewPort3d.ZoomExtents();


                string path_copy = Environment.CurrentDirectory + @"\3dsObject\User\" + category.name + @"\" + model.name;
                var    asdsadd   = Directory.EnumerateFiles(path_copy, "*.*", SearchOption.TopDirectoryOnly)
                                   .Where(s => s.EndsWith(".jpg") || s.EndsWith(".png"));

                foreach (string elem in asdsadd)
                {
                    spisdop_fiel.Items.Add(elem);
                }
                spisdop_fiel.Items.Refresh();
            }
        }
Example #3
0
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            //подгрузить данные с сервера

            treespis        Treespis        = lb3.SelectedItem as treespis;
            var             json            = (new web_zapros()).load("load_object", "category=" + Treespis.id_server);
            List <Models3d> server_load_obj = JsonConvert.DeserializeObject <List <Models3d> >(json);

            //  MessageBox.Show(Treespis.id_server.ToString());
            //  List<treespis> Result = server_load.Where(a => server.Contains(a.name)).ToList();

            List <Models3d> result = new List <Models3d>();


            ///тест



            for (int i = 0; i < server_load_obj.Count(); i++)
            {
                bool estb = true;
                for (int y = 0; y < server_obj.Count(); y++)
                {
                    if (server_load_obj[i].id_server == server_obj[y].id_server)
                    {
                        estb = false;
                    }
                }
                string new_ = "0";
                if (estb)
                {
                    new_ = "1";
                }


                string path_copy = dir3ds + Treespis.name + @"\";
                Directory.CreateDirectory(path_copy);//создадим папку для weб

                //  MessageBox.Show(path_copy + server_load_obj[i].path);
                string path3ds    = path_copy + server_load_obj[i].path;
                string pathjpg    = "";
                string pathjpgugo = "";

                if (server_load_obj[i].jpg_path != "")
                {
                    pathjpg = path_copy + server_load_obj[i].jpg_path;
                }
                if (server_load_obj[i].jpg_ugo != "")
                {
                    pathjpgugo = path_copy + server_load_obj[i].jpg_ugo;
                }

                string ecad = "https://ecad.giulianovars.ru/3dmodels/NEW/";


                if (!(File.Exists(pathjpg) || pathjpg == ""))
                {
                    (new WebClient()).DownloadFile(ecad + server_load_obj[i].jpg_path, pathjpg);//скачиваем картинку
                }



                result.Add(new Models3d
                {
                    id         = server_load_obj[i].id,
                    path       = server_load_obj[i].path,
                    name       = server_load_obj[i].name,
                    jpg_path   = server_load_obj[i].jpg_path,
                    jpg_ugo    = server_load_obj[i].jpg_ugo,
                    x          = server_load_obj[i].x,
                    y          = server_load_obj[i].y,
                    z          = server_load_obj[i].z,
                    category   = server_load_obj[i].category,
                    id_server  = server_load_obj[i].id_server,
                    loc_3ds    = path3ds,
                    loc_jpg    = pathjpg,
                    loc_ugojpg = pathjpgugo,
                    polzgroup  = server_load_obj[i].polzgroup,
                    new_       = new_
                });
            }


            //    MessageBox.Show(result.Count().ToString());


            //  BD.conn("UPDATE `import3ds_server` SET  `new`='0' ");
            BD.conn("DELETE FROM `import3ds_server` WHERE category='" + Treespis.id_server + "'");
            foreach (Models3d elem in result)
            {
                BD.conn("INSERT INTO  `import3ds_server` (id_server, nazv,path3ds,pathjpg,pathjpgugo,x,y,z,category,new, loc_3ds, loc_jpg, loc_ugojpg, polzgroup)  VALUES ('" +
                        elem.id_server + "', '" +
                        elem.name + "', '" +
                        elem.path + "', '" +
                        elem.jpg_path + "', '" +
                        elem.jpg_ugo + "', '" +
                        elem.x + "', '" +
                        elem.y + "', '" +
                        elem.z + "', '" +
                        elem.category + "', '" +
                        elem.new_ + "', '" +
                        elem.loc_3ds + "','" +
                        elem.loc_jpg + "','" +
                        elem.loc_ugojpg + "','" +
                        elem.polzgroup + "')");
            }
            MessageBox.Show("Данные успешно обновлены");
            lb4_napolnenie();
        }
Example #4
0
        public void lb1_napolnenie()//наполнение листбокса
        {
            try
            {
                log.Add("lb1_napolnenie старт");
                treespis        Treespis = lb2.SelectedItem as treespis;
                List <Models3d> modeli   = new List <Models3d>();
                log.Add("Преобразовали в класс");
                foreach (string elem in Directory.GetDirectories(dir3ds_user + "\\" + Treespis.name, "*", SearchOption.TopDirectoryOnly))
                {
                    try
                    {
                        string name = elem.Split('\\').Last();
                        log.Add("парсим элемент " + name);
                        var asdasd = Directory.GetFiles(elem, "*.3ds", SearchOption.TopDirectoryOnly);
                        if (!(asdasd.Length > 0))
                        {
                            return;
                        }
                        string path         = asdasd.First();
                        string jpg_path     = elem + "\\teh\\prev.jpg";
                        string jpg_ugo      = elem + "\\teh\\ugo.jpg";
                        string pathcategory = elem;
                        string confjson     = elem + "\\teh\\conf.json";



                        Models3dJSON zyx;


                        if (File.Exists(confjson))
                        {
                            using (StreamReader fstream = new StreamReader(confjson, System.Text.Encoding.Default))
                            {
                                zyx = JsonConvert.DeserializeObject <Models3dJSON>(fstream.ReadToEnd());
                            }
                        }
                        else
                        {
                            try
                            {
                                Model3D dmodel3ds = (new HelixToolkit.Wpf.ModelImporter()).Load(path);

                                zyx = new Models3dJSON()
                                {
                                    x = dmodel3ds.Bounds.SizeX.ToString("0"),
                                    z = dmodel3ds.Bounds.SizeY.ToString("0"),
                                    y = dmodel3ds.Bounds.SizeZ.ToString("0")
                                };
                            }
                            catch
                            {
                                zyx = new Models3dJSON()
                                {
                                    x = "100", y = "100", z = "100"
                                };
                            }



                            //генерируем JSON файл
                            string output = JsonConvert.SerializeObject(zyx);
                            using (FileStream fs = new FileStream(confjson, FileMode.OpenOrCreate))
                            {
                                // преобразуем строку в байты
                                byte[] array = System.Text.Encoding.Default.GetBytes(output);
                                // запись массива байтов в файл

                                fs.Write(array, 0, array.Length);
                            }
                        }



                        BitmapImage btmap;



                        if (!File.Exists(jpg_path))
                        {
                            jpg_path = "/TreeCadN;component/Foto/nofoto.jpg";

                            btmap = new BitmapImage(new Uri(jpg_path, UriKind.RelativeOrAbsolute));
                        }
                        else
                        {
                            btmap = new BitmapImage();
                            btmap.BeginInit();
                            btmap.UriSource   = new Uri(jpg_path);
                            btmap.CacheOption = BitmapCacheOption.OnLoad;
                            btmap.EndInit();
                        }



                        // img.Source = btmap;



                        modeli.Add(new Models3d
                        {
                            name         = name,
                            path         = path,
                            jpg_path     = jpg_path,
                            jpg_ugo      = jpg_ugo,
                            pathcategory = pathcategory,
                            x            = zyx.x,
                            y            = zyx.y,
                            z            = zyx.z,
                            bitmap_prev  = btmap
                        });
                    }
                    catch (Exception ex)
                    {
                        log.Add("фатал ошибка: " + ex.Message);
                    }
                }
                log.Add("Закончили цикл");

                //test
                lb1.ItemsSource = modeli;
                lb1.Items.Refresh();

                try
                {
                    object selitem = lb1.Items[lb1_selitem];


                    lb1.ScrollIntoView(selitem);
                    lb1.SelectedItem = (selitem);
                }
                catch
                {
                    lb1.ScrollIntoView(null);
                    lb1.SelectedItem = (null);
                }
            }
            catch (Exception ex)
            {
                log.Add("фатал ошибка: " + ex.Message);
            }
        }