我發現,如果你右擊一個變量,然後單擊「轉到定義」它是一個更容易找到對變量的引用。我右鍵單擊另一個通過MainForm調用的變量,發現它們都是通過SearchCriteria文件調用的。我不得不通過SearchCriteria.cs文件在MainForm.cs文件中引用addzipdir_checkbox值,然後在SearchProcess.cs文件中調用它。
這裏是我的SearchCriteria.cs文件代碼:
public class SearchCriteria
{
private String Corp;
private String OrderNumber;
private String Campaign;
private String City;
private String State;
private String Zip;
private String SourcePath;
private String TargetPath;
private bool SearchOR;
private bool SearchAND;
private bool addzipdirectory_checkBox;
public SearchCriteria()
{
}
public SearchCriteria(String Corp,
String OrderNumber,
String Campaign,
String City,
String State,
String Zip,
String SourcePath,
String TargetPath,
bool SearchOR,
bool SearchAND,
bool addzipdirectory_checkBox)
{
this.Corp = Corp;
this.OrderNumber = OrderNumber;
this.Campaign = Campaign;
this.City = City;
this.State = State;
this.Zip = Zip;
this.SourcePath = SourcePath;
this.TargetPath = TargetPath;
this.SearchOR = SearchOR;
this.SearchAND = SearchAND;
this.addzipdirectory_checkBox = addzipdirectory_checkBox;
}
public bool get_addzipdir_checkBox()
{
return addzipdirectory_checkBox;
}
public void set_addzipdir_checkBox(bool x)
{
addzipdirectory_checkBox = x;
}
}
這裏是我的Searchprocess.cs文件代碼:
// Copy the file if ANY of the search criteria have been met
if (found)
{
m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"FOUND: Order_No: " + Order_No +
" barcode: " + barcode +
" MailerCode: " + MailerCode +
" AgentID: " + AgentID +
" City: " + City +
" State: " + State +
" ZIP: " + ZIP});
//passes values to TransferFile
TransferFile(directory, barcode, AgentID, ZIP);
}
} // end for that finds each matching record
}
// find and copy the file to the target directory string ZIP
private void TransferFile(string sourceDir, string filename, string AgentID, string ZIP)
{
string fullFileName = filename + ".pdf";
string fullFileNameAndPath = sourceDir + "\\" + fullFileName;
string targetFileAndPath;
if (m_sc.get_addzipdir_checkBox()==true)
{
// adds the given lead's agentid and zip code to the targetpath string
string targetzipdir = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP;
// If the given lead's zip code subdirectory doesn't exist, create it.
if (!Directory.Exists(targetzipdir))
{
Directory.CreateDirectory(targetzipdir);
}
targetFileAndPath = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP + "\\" + fullFileName;
} // end if addzipdir_checkBox.Equals(true)
我相信檢查框應更新變量的地方,讓你可以引用變量而不是其他形式的控件。 – 2011-02-24 21:45:54
我加了一行bool addzipdirectory_checkbox = 1;在第一個if語句下,if(addzipdir_checkBox.Equals(true))但我仍然無法在searchprocess.cs文件中引用它。我應該使用invoke語句來使它像這樣m_form.Invoke(m_form.m_DelegateAddString,new Object [] {「Search on State:」+ m_sc.get_State()});或者如果(m_sc.get_SearchAND()== true) m_form.Invoke(m_form.m_DelegateAddString,new Object [] {「Search for All」}); }或從Utility.Properties.Settings.Default中將其帶入。區? – 2011-02-25 14:28:53