/// <summary> /// load xml config /// </summary> public List <string> loadLocalConfig() { List <string> sizeStrs = new List <string>(); try { string xmlPath = System.AppDomain.CurrentDomain.BaseDirectory + "config.xml"; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(xmlPath); XmlNode configNode = xmlDocument.SelectSingleNode("config"); XmlNodeList sizesList = configNode.SelectSingleNode("sizes").ChildNodes; foreach (XmlNode list in sizesList) { string sizeStr = list.InnerText; SizeConfig sc = new SizeConfig(sizeStr); sizes.Add(sc); sizeStrs.Add(sizeStr); } //other savePath = configNode.SelectSingleNode("savePath").InnerText; string saveFormatStr = configNode.SelectSingleNode("outputFormat").InnerText; outputFormat = getFormatByString(saveFormatStr); } catch (Exception ex) { MessageBox.Show(ex.Message); } return(sizeStrs); }
/// <summary> /// 更新尺寸配置 /// </summary> /// <param name="sizeConf"></param> public void updateSizeConfig(SizeConfig sizeConf, int index) { if (sizeConf.name == "" || sizeConf.name.Trim() == "") { MessageBox.Show("名称不能为空"); return; } if (sizeConf.size.Width > 0 && sizeConf.size.Width < 10000 && sizeConf.size.Height > 0 && sizeConf.size.Height < 10000) { bool isExist = false; string errorString = ""; int bakIndex = index; if (sizes == null || sizes.Count <= index) { MessageBox.Show("数据有问题惹 "); return; } sizes.RemoveAt(index); foreach (SizeConfig sizeConfig in sizes) { Size size = sizeConfig.size; if (size.Width == sizeConf.size.Width && size.Height == sizeConf.size.Height) { isExist = true; errorString = "这个尺寸已经存在输出配置里面啦"; break; } if (sizeConf.name == sizeConfig.name) { isExist = true; errorString = "有重名哦"; break; } } if (isExist) { MessageBox.Show(errorString); } else { sizes.Add(sizeConf); if (delegateForm is iConfigChange) { MessageBox.Show("更新成功~"); delegateForm.sizeConfigHasUpdate(sizeConf, bakIndex); } } } }
public void sizeConfigHasUpdate(SizeConfig sc, int changeIndex) { try { string item = string.Format("{0}*{1}-{2}", sc.size.Width, sc.size.Height, sc.name); listBox1.Items.RemoveAt(changeIndex); listBox1.Items.Add(item); } finally { } }
/// <summary> /// Add sub Size config /// </summary> /// <param name="sizeConf"></param> public void addSizeConfig(SizeConfig sizeConf) { if (sizeConf.name == "" || sizeConf.name.Trim() == "") { MessageBox.Show("名称不能为空"); return; } if (sizeConf.name.Contains('-')) { MessageBox.Show("名字不能包含[-]这个符号~我偷一下懒0.0"); return; } if (sizeConf.size.Width > 0 && sizeConf.size.Width < 10000 && sizeConf.size.Height > 0 && sizeConf.size.Height < 10000) { bool isExist = false; string errorString = ""; foreach (SizeConfig sizeConfig in sizes) { Size size = sizeConfig.size; if (size.Width == sizeConf.size.Width && size.Height == sizeConf.size.Height) { isExist = true; errorString = "这个尺寸已经存在输出配置里面啦"; break; } if (sizeConf.name == sizeConfig.name) { isExist = true; errorString = "有重名哦"; break; } } if (isExist) { MessageBox.Show(errorString); } else { sizes.Add(sizeConf); if (delegateForm is iConfigChange) { MessageBox.Show("添加成功~"); delegateForm.sizeConfigHasAdd(sizeConf); } } } }
private void addSizeConfig() { SizeConfig sizeConf = new SizeConfig(); sizeConf.size = new Size(decimal.ToInt32(numericUpDown1.Value), decimal.ToInt32(numericUpDown2.Value)); sizeConf.name = textBox1.Text; if (convertConf != null) { convertConf.addSizeConfig(sizeConf); } }
private void listBox1_DoubleClick(object sender, MouseEventArgs e) { try { int index = this.listBox1.IndexFromPoint(e.Location); if (index != System.Windows.Forms.ListBox.NoMatches) { curOperaIndex = index; string item = listBox1.Items[index].ToString(); SizeConfig sc = convConfig.sizes[index]; frmAddConfig frmAdd = new frmAddConfig(); frmAdd.removeBlock += new frmAddConfig.RemoveItemBlock(frmAdd_removeBlock); frmAdd.convertConf = convConfig; frmAdd.sizeConf = new SizeConfig(sc.name, sc.size); frmAdd.curItemIndex = index; frmAdd.ShowDialog(); //do your stuff here } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// interface /// </summary> /// <param name="sc"></param> public void sizeConfigHasAdd(SizeConfig sc) { string item = string.Format("{0}*{1}-{2}", sc.size.Width, sc.size.Height, sc.name); listBox1.Items.Add(item); }