private void InitLoadProductDicList(string selectedFilename) { listBox1.Items.Clear(); foreach (ProductDic product in _productDics) { listBox1.Items.Add(product); } listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged); if (listBox1.Items.Count != 0) { ProductDic selectedPdc = null; if (!string.IsNullOrWhiteSpace(selectedFilename)) { foreach (ProductDic product in _productDics) { if (selectedFilename == product.FileName) { selectedPdc = product; break; } } } if (selectedPdc == null) { selectedPdc = _productDics[0]; } listBox1.SelectedItem = selectedPdc; } }
void listBox1_SelectedIndexChanged(object sender, EventArgs e) { TryAskSave(); ProductDic product = listBox1.SelectedItem as ProductDic; LoadCurProductColorTable(product); }
private void Export() { using (SaveFileDialog diag = new SaveFileDialog()) { diag.Title = "导出产品颜色表"; diag.Filter = "产品颜色表(*.pct)|*.pct|所有文件(*.*)|*.*"; ProductDic product = listBox1.SelectedItem as ProductDic; diag.FileName = Path.GetFileNameWithoutExtension(product.FileName); if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filename = diag.FileName; ProductColorTableParser.WriteToXml(_selectedProductColorTables, filename); } } }
private void InitLoadColorTables(string selectedFilename) { ProductColorTableParser parser = new ProductColorTableParser(); string[] files = parser.LoadColorTables(); ProductDic[] pdcs = new ProductDic[files.Length]; for (int i = 0; i < files.Length; i++) { ProductDic pdc = new ProductDic(); pdc.FileName = files[i]; pdc.ProductIdentify = Path.GetFileNameWithoutExtension(files[i]); pdcs[i] = pdc; } TrySetProductDicName(pdcs); _productDics = pdcs; InitLoadProductDicList(selectedFilename); }
private void LoadCurProductColorTable(ProductDic product) { _selectedProductDic = product; _selectedProductColorTables = null; _selectedProductColorTable = null; if (product == null || string.IsNullOrWhiteSpace(product.FileName)) { ClearPcts(); return; } ProductColorTableParser parser = new ProductColorTableParser(); _selectedProductColorTables = ProductColorTableParser.Parse(product.FileName); if (_selectedProductColorTables == null) { ClearPcts(); } else { LoadColorTable(_selectedProductColorTables); } }