//---------------------------------------------------------- public string Sua_Thong_Tin_Vat_Lieu_Project(UIApplication uiapp, Document doc) { string result = "F"; try { data_material_project item = (data_material_project)thong_tin_vat_lieu_project.SelectedItem; if (!string.IsNullOrEmpty(ten_vat_lieu.Text)) { if (my_material_project.Any(x => x.ten_vat_lieu_project == ten_vat_lieu.Text) == false || item.ten_vat_lieu_project == ten_vat_lieu.Text) { if (my_material_project.Any(x => x.ma_cong_tac_project == ma_cong_tac.Text) == false || item.ma_cong_tac_project == ma_cong_tac.Text) { Transaction tr1 = new Transaction(doc); tr1.Start("Create Material"); Material material = item.material_project; System.Windows.Media.Color shading = ((SolidColorBrush)color_shading.Background).Color; System.Windows.Media.Color surface = ((SolidColorBrush)color_surface.Background).Color; System.Windows.Media.Color cut = ((SolidColorBrush)color_cut.Background).Color; string time = DateTime.Now.ToString(); string ton = item.ton; if (!string.IsNullOrEmpty(ton_value.Text)) { ton = ton_value.Text; } material.Name = ten_vat_lieu.Text; F_GetSchema.SetDataStorage(material, Source.MCT[1], Source.MCT[0], ma_cong_tac.Text); F_GetSchema.SetDataStorage(material, Source.DV[1], Source.DV[0], don_vi.Text); F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], ton); F_GetSchema.SetDataStorage(material, Source.USER[1], Source.USER[0], user); F_GetSchema.SetDataStorage(material, Source.TIME[1], Source.TIME[0], time); material.SurfaceBackgroundPatternId = ((data_fill_pattern)name_surface.SelectedItem).pattern_id; material.SurfaceBackgroundPatternColor = new Color(surface.R, surface.G, surface.B); material.CutBackgroundPatternId = ((data_fill_pattern)name_cut.SelectedItem).pattern_id; material.CutBackgroundPatternColor = new Color(cut.R, cut.G, cut.B); if (use_appearence.IsChecked == false) { material.Color = new Color(shading.R, shading.G, shading.B); material.Transparency = Convert.ToInt32(tranparency_value.Text); } tr1.Commit(); Transaction tr2 = new Transaction(doc); tr2.Start("Edit Material"); F_SetAppearanceAsset.set_appearance_asset(doc, material); tr2.Commit(); my_material_project.Remove(item); my_material_project.Add(new data_material_project() { material_project = material, ma_cong_tac_project = ma_cong_tac.Text, ten_vat_lieu_project = ten_vat_lieu.Text, don_vi_project = don_vi.Text, user = user, time = time, mau_vat_lieu = material.Color, do_trong_suot_vat_lieu = material.Transparency, id_surface = material.SurfaceBackgroundPatternId, mau_surface = material.SurfaceBackgroundPatternColor, id_cut = material.CutBackgroundPatternId, mau_cut = material.CutBackgroundPatternColor, ton = ton, color = Support.Check_Color(ma_cong_tac.Text), color_sort = Support.Check_Color(ma_cong_tac.Text).ToString() }); result = "S"; } else { MessageBox.Show("The material id you supplied is already in use. Enter a unique id.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("The material name you supplied is already in use.Enter a unique name.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } else { MessageBox.Show("The material name not null or empty.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } return(result); }
//---------------------------------------------------------- public string Tao_Vat_Lieu_Moi_Excel(UIApplication uiapp, Document doc) { string result = "F"; string name = ""; try { foreach (data_material_excel data in data_create) { if (my_material_project.Any(x => x.ten_vat_lieu_project == data.ten_vat_lieu_excel) == false) { if (my_material_project.Any(x => x.ma_cong_tac_project == data.ma_cong_tac_excel) == false || string.IsNullOrEmpty(data.ma_cong_tac_excel)) { try { ElementId material_id_new = Material.Create(doc, data.ten_vat_lieu_excel); Material material = doc.GetElement(material_id_new) as Material; string time = DateTime.Now.ToString(); material.Name = data.ten_vat_lieu_excel; F_GetSchema.SetDataStorage(material, Source.MCT[1], Source.MCT[0], data.ma_cong_tac_excel); F_GetSchema.SetDataStorage(material, Source.DV[1], Source.DV[0], data.don_vi_excel); F_GetSchema.SetDataStorage(material, Source.TON[1], Source.TON[0], data.ton); F_GetSchema.SetDataStorage(material, Source.USER[1], Source.USER[0], user); F_GetSchema.SetDataStorage(material, Source.TIME[1], Source.TIME[0], time); material.SurfaceBackgroundPatternId = data.id_surface_excel; material.SurfaceBackgroundPatternColor = data.mau_surface_excel; material.CutBackgroundPatternId = data.id_cut_excel; material.CutBackgroundPatternColor = data.mau_cut_excel; material.Color = data.mau_vat_lieu_excel; material.Transparency = data.do_trong_suot_vat_lieu_excel; F_SetAppearanceAsset.set_appearance_asset(doc, material); my_material_project.Add(new data_material_project() { material_project = material, ma_cong_tac_project = data.ma_cong_tac_excel, ten_vat_lieu_project = data.ten_vat_lieu_excel, don_vi_project = data.don_vi_excel, user = user, time = time, mau_vat_lieu = material.Color, do_trong_suot_vat_lieu = material.Transparency, id_surface = material.SurfaceBackgroundPatternId, mau_surface = material.SurfaceBackgroundPatternColor, id_cut = material.CutBackgroundPatternId, mau_cut = material.CutBackgroundPatternColor, ton = data.ton, color = Support.Check_Color(data.ma_cong_tac_excel), color_sort = Support.Check_Color(data.ma_cong_tac_excel).ToString() }); result = "S"; } catch (Exception) { name += data.ten_vat_lieu_excel + Environment.NewLine; } } else { //MessageBox.Show(data.ma_cong_tac_excel + Environment.NewLine + "The material id you supplied is already in use. Enter a unique id.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); name += data.ten_vat_lieu_excel + Environment.NewLine; } } else { //MessageBox.Show(data.ten_vat_lieu_excel + Environment.NewLine + "The material name you supplied is already in use. Enter a unique name.", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); name += data.ten_vat_lieu_excel + Environment.NewLine; } } if (!string.IsNullOrEmpty(name)) { MessageBox.Show("The material name error :" + Environment.NewLine + name, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); result = "F"; } return(result); }