public static void Add(FilePathRule rule) { if (rule != null) { listFilePathRule.Add(rule); } }
public static void EditRule(int index, FilePathRule rule) { if (index < listFilePathRule.Count) { listFilePathRule[index] = rule; } }
/// <summary> /// 执行命名规则按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSiteName_Click(object sender, EventArgs e) { Dictionary <string, string> dictPath; if (listViewFile.SelectedItems.Count > 1) { dictPath = new Dictionary <string, string>(); for (int i = 0; i < listViewFile.SelectedItems.Count; i++) { dictPath.Add(listViewFile.SelectedItems[i].SubItems[5].Text, ""); } } else { dictPath = new Dictionary <string, string>(); for (int i = 0; i < listViewFile.Items.Count; i++) { dictPath.Add(listViewFile.Items[i].SubItems[5].Text, ""); } } FilePathRule.Clear(); FilePathRule.Add(GetFilePathRule(groupBoxPrefix, out string strErrorPrefix)); FilePathRule.Add(GetFilePathRule(groupBoxMiddle, out string strErrorMiddle)); FilePathRule.Add(GetFilePathRule(groupBoxPostfix, out string strErrorPostfix)); FilePathRule.ForceExtension(chkEditExt.Checked, txtEditExt.Text); if (strErrorPrefix != "OK") { MessageBox.Show(strErrorPrefix, "文件名前缀错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (strErrorMiddle != "OK") { MessageBox.Show(strErrorMiddle, "文件名中间错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (strErrorPostfix != "OK") { MessageBox.Show(strErrorPostfix, "文件名后缀错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (FilePathRule.RuleCount() <= 0) { MessageBox.Show("无使能任何命名规格,请先配置命名规则。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (dictPath.Count == 0) { MessageBox.Show("目标文件目录为空,请先导入文件。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FilePathRule.Rename(dictPath); foreach (KeyValuePair <string, string> item in dictPath) { objFilePathSet.Edit(item.Key, item.Value); } UpdataListViewFile(listViewFile, dictPath); }
public static void EditRule(string ruleName, FilePathRule rule) { for (int i = 0; i < listFilePathRule.Count; i++) { if (listFilePathRule[i].Name == ruleName) { EditRule(i, rule); } } }