我們有一個標籤打印機A4 +,我們使用它們爲我們的倉庫打印了大量的標籤,因爲我們想要打印每一個都不同於另一個的標籤,我們決定製作一個DBF文件每次打印作業時,每次DBF文件包含不同記錄數時,我們的Web服務向A4 +打印機發出ftp請求並將DBF文件ftp到打印機,然後將打印命令發送到打印機並打印DBF文件。大多數情況下,所有步驟都會成功完成,但有時打印機上的DBF文件與Web服務上的dbf文件有點不同,並且差異位於文件頭上,這種差異會導致問題發生,因此打印機將打印標籤但不打印到DBF文件的末尾,例如,如果DBF文件包含500條記錄,打印機只打印300條記錄或不同的數字,然後繼續打印但標籤不包含數據,則表示300打印機不打印讀取dbf文件並且標籤是相當原始的,但是因爲打印命令是500(DBF文件也包含500個記錄),它繼續將標籤饋送到500.FTP文件發送不正確
我們比較服務器上的兩個DBF文件哪些主機Web服務(這是我們創建dbf文件的地方)以及打印機上的ftp文件,它們是相同的,只是文件頭上的一點點就是diiffrent,它造成這個問題。
我包含了我們製作DBF文件的代碼,以及我們用於將此文件轉換爲打印機的代碼,並且還附加了兩個DBF文件的示例。
我們的團隊在該項目上工作,我們正在研究您網站上的幫助,但是在這一點上,我們可以看到一切正常,我們無法調試此案例,也許您可以幫助我們解決此問題。
------------------------創建DBF文件------------------- -----------------------------------
private bool EportDBF(string filePath, List<BarcodeData> list)
{
string tableName = string.Empty;
string folderPath = string.Empty;
GetFileNameAndPath(filePath, ref tableName, ref folderPath);
string connString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + folderPath + "; Extended Properties=DBASE IV;";
string createStatement = "Create Table " + tableName + " (";
string insertStatement = "Insert Into " + tableName + " Values (";
string insertTemp = string.Empty;
OleDbConnection conn = new OleDbConnection(connString);
try
{
createStatement += "[RW] varchar(4), ";
createStatement += "[CODE] varchar(16), ";
createStatement += "[DESC] varchar(16), ";
createStatement += "[WEIGHT] varchar(16), ";
createStatement += "[DATE] varchar(32), ";
createStatement += "[RCODE] varchar(16), ";
createStatement += "[BCODE] varchar(16))";
conn.Open();
DataSet dsFill = new DataSet();
OleDbDataAdapter daInsertTable = new OleDbDataAdapter(createStatement, conn);
daInsertTable.Fill(dsFill);
int row = 1001;
foreach (var item in list)
{
insertTemp = insertStatement;
insertTemp += "'" + row++ + "' , ";
insertTemp += "'" + item.ItemCode + "' , ";
insertTemp += "'0' , ";
insertTemp += "'" + item.Weight + "' , ";
insertTemp += "'" + item.DateTime + "' , ";
insertTemp += "'" + item.ReferenceCode + "' , ";
insertTemp += "'" + item.Barcode.ToString() + "') ;";
daInsertTable = new OleDbDataAdapter(insertTemp, conn);
daInsertTable.Fill(dsFill);
}
conn.Close();
conn.Dispose();
}
catch (Exception ex)
{
conn.Close();
conn.Dispose();
return false;
}
return true;
}
-------- ---------------- FTP DBF文件打印機----------------------------- --------------
private bool UpLoadDBF(List<BarcodeData> barcodeDatas, string path)
{
try
{
EportDBF(path, barcodeDatas);
FtpWebRequest request;
FtpWebResponse response;
Stream sourceStream = new MemoryStream();
Stream requestStream = sourceStream;
StreamReader reader = new StreamReader(path);
try
{
request = (FtpWebRequest)WebRequest.Create("ftp://" + printerIP + "/card/barcodes.dbf");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.KeepAlive = false;
request.Credentials = new NetworkCredential(user, password);
byte[] byteArray = Encoding.Default.GetBytes(reader.ReadToEnd());
sourceStream = new MemoryStream(byteArray);
try
{
requestStream = request.GetRequestStream();
}
finally
{
request.ContentLength = sourceStream.Length;
byte[] buffer = new byte[sourceStream.Length];
int count = 2048;
if (sourceStream.Length < count)
count = (int) sourceStream.Length;
int bytesRead = sourceStream.Read(buffer, 0, count);
do
{
requestStream.Write(buffer, 0, bytesRead);
bytesRead = sourceStream.Read(buffer, 0, count);
} while (bytesRead > 0);
sourceStream.Close();
requestStream.Close();
}
}
catch (Exception ex)
{
}
finally
{
request = null;
sourceStream.Close();
sourceStream.Dispose();
reader.Close();
reader.Dispose();
requestStream.Close();
requestStream.Dispose();
}
}
catch (Exception ex)
{
return false;
}
return true;
}
所以感謝inadvance
非常感謝,文件流正常工作 – ali