【发布时间】:2014-09-22 23:07:37
【问题描述】:
我需要根据其他两列中文件名的最高名称来更新文件名。
例如:- 我有名为 221-8812_01 的 coumn3 和名为 221-8812_02 的 column4。所以我想将221-8812_02 文件名更新为column1。
反之亦然,如果我在 column3 中有一个名为 323-1111_03 的文件名,在 column3 中有一个名为 323-1111_02 的文件,那么我想在 column1 中更新 323-1111_03。
注意:-
我有像 323-2332_0A 和 323-2332_0B 这样的文件名。所以我需要更新 column1 中的 323-2332_0B。
或者可能是 111-4334_0D 和 111-4334_0C 所以我需要将 111-4334_0D 更新到 column1。
所以它就像 第一个服务器编号保持不变。在七个数字之后..当(_)下划线开始时..我需要比较..根据字母或数字升序!!!! 我该怎么做呢,
我的代码sn-p:
private void filter_table()
{
// create a check box in column0
DataGridViewCheckBoxColumn colCB = new DataGridViewCheckBoxColumn();
DatagridViewCheckBoxHeaderCell cbHeader = new DatagridViewCheckBoxHeaderCell();
colCB.HeaderCell = cbHeader;
dataGridView1.Columns.Add(colCB);
//Initialize Directory path
string draft = ini.ReadValue("Location", "Draft");
string release = ini.ReadValue("Location", "Release");
string drawing = ini.ReadValue("Location", "Drawing");
string archive = ini.ReadValue("Location", "Archive");
if (!System.IO.Directory.Exists(draft))
System.IO.Directory.CreateDirectory(draft);
if (!System.IO.Directory.Exists(release))
System.IO.Directory.CreateDirectory(release);
if (!System.IO.Directory.Exists(drawing))
System.IO.Directory.CreateDirectory(drawing);
if (!System.IO.Directory.Exists(archive))
System.IO.Directory.CreateDirectory(archive);
string[] arrDraft = Directory.GetFiles(draft, "*", SearchOption.AllDirectories);
string[] arrRelease = Directory.GetFiles(release, "*", SearchOption.AllDirectories);
string[] arrDrawing = Directory.GetFiles(drawing, "*", SearchOption.AllDirectories);
string[] arrArchive = Directory.GetFiles(archive, "*", SearchOption.AllDirectories);
dt.Columns.Add("Drawing_Number");
//dt.Columns["Part Number"].ReadOnly = true;
dt.Columns.Add("Drawing");
// dt.Columns["Drawing"].ReadOnly = true;
dt.Columns.Add("Draft Path");
// dt.Columns["Draft Path"].ReadOnly = true;
dt.Columns.Add("Release Path");
// dt.Columns["Release Path"].ReadOnly = true;
dt.Columns.Add("Error");
// dt.Columns["Error"].ReadOnly = true;
dt.Columns.Add("Archive");
// listing all the files according to the column3(draft path) filename.. and mating files from nearby column.
List<FileDetails> lst = new List<FileDetails>();
foreach (string file in arrDraft)
{
Finder finder = new Finder(Path.GetFileNameWithoutExtension(file).Substring(0, 7));
string abc = Array.Find(arrRelease, finder.Match);
string cdf = Array.Find(arrDrawing, finder.Match);
string ghi = Array.Find(arrArchive, finder.Match);
dt.Rows.Add(Path.GetFileNameWithoutExtension(file), cdf, file, abc, String.Empty, ghi);
}
dataGridView1.DataSource = dt;
}
private void Form1_Load(object sender, EventArgs e)
{
filter_table();
}
// Search predicate returns true if a string ends in "saurus".
private static bool MatchFileName(String s, String _match)
{
return ((s.Length > 5) && (s.Substring(0, 7).ToLower() == _match.ToLower()));
}
public class FileDetails
{
public string FileName;
public string Drawings;
public string FilePathDraft;
public string FilePathRelease;
public string Comment;
public string ErrorMsg;
}
public sealed class Finder
{
private readonly string _match;
public Finder(string match)
{
_match = match.ToLower();
}
//findin the match and showing in grid view
public bool Match(string s)
{
string fileName = s.Substring(s.LastIndexOf("\\") + 1);
return ((fileName.Length > 5) && (fileName.Substring(0, 8).ToLower() == _match));
}
}
【问题讨论】:
-
为什么
323-2332_0B“高于”323-2332_0A,但111-4334_0C高于111-4334_0D? -
@DourHighArch 我正在寻找 _0A、0B、0C .. 继续。到 0Z.. 而在数字上它就像 _01, 02, 03, 04, 05, 06, 07 .. 最后两个数字一样
-
@Shell.. 任何想法!!!
-
您需要的是一种方法(或 IComparable 的实现),它可以比较 2 个字符串并返回“更高”的字符串。我们无法帮助您进行比较逻辑,因为正如上面@DourHighArch 指出的那样,您的比较逻辑没有多大意义。即 B > A 但 C > D。一旦你知道哪个字符串的结果更高,你就可以继续更新你需要的任何列。
-
@failedprogramming 我已经指定了更高的原因..我正在寻找最后两个值.._0A、0B、0C..继续。到 0Z.. 而在数字上它就像 _01, 02, 03, 04, 05, 06, 07 .. 寻找最后两个数字