From 047c7cbd047e11fba8d7872e69a11a13e463aec4 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期一, 13 十月 2025 17:40:39 +0800
Subject: [PATCH] 1.保存单条记录。
---
SourceCode/Bond/Servo/CPageGlassList.cpp | 204 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 203 insertions(+), 1 deletions(-)
diff --git a/SourceCode/Bond/Servo/CPageGlassList.cpp b/SourceCode/Bond/Servo/CPageGlassList.cpp
index eabdf81..0d0d5c1 100644
--- a/SourceCode/Bond/Servo/CPageGlassList.cpp
+++ b/SourceCode/Bond/Servo/CPageGlassList.cpp
@@ -372,6 +372,55 @@
return true;
}
+// 杈呭姪鍑芥暟锛氬皢 ANSI CString 鍐欏叆鏂囦欢涓� UTF-8 缂栫爜
+bool CPageGlassList::WriteAnsiStringAsUtf8ToFile(const CString& ansiContent, const CString& filePath)
+{
+ CFile file;
+ if (!file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
+ return false;
+ }
+
+ // 鍐欏叆 UTF-8 BOM
+ const unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
+ file.Write(bom, 3);
+
+ // 灏� ANSI 杞崲涓� Unicode
+ int unicodeLength = MultiByteToWideChar(CP_ACP, 0,
+ ansiContent, ansiContent.GetLength(),
+ NULL, 0);
+
+ if (unicodeLength <= 0) {
+ file.Close();
+ return false;
+ }
+
+ wchar_t* unicodeBuffer = new wchar_t[unicodeLength + 1];
+ MultiByteToWideChar(CP_ACP, 0,
+ ansiContent, ansiContent.GetLength(),
+ unicodeBuffer, unicodeLength);
+ unicodeBuffer[unicodeLength] = 0;
+
+ // 灏� Unicode 杞崲涓� UTF-8
+ int utf8Length = WideCharToMultiByte(CP_UTF8, 0,
+ unicodeBuffer, unicodeLength,
+ NULL, 0, NULL, NULL);
+
+ bool success = false;
+ if (utf8Length > 0) {
+ char* utf8Buffer = new char[utf8Length];
+ WideCharToMultiByte(CP_UTF8, 0,
+ unicodeBuffer, unicodeLength,
+ utf8Buffer, utf8Length, NULL, NULL);
+
+ file.Write(utf8Buffer, utf8Length);
+ delete[] utf8Buffer;
+ success = true;
+ }
+
+ delete[] unicodeBuffer;
+ file.Close();
+ return success;
+}
// CPageGlassList 瀵硅瘽妗�
@@ -426,6 +475,7 @@
ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CPageGlassList::OnBnClickedButtonPrevPage)
ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CPageGlassList::OnBnClickedButtonNextPage)
ON_NOTIFY(ELCN_SHOWFULLTEXT, IDC_LIST_ALARM, &CPageGlassList::OnShowFullText)
+ ON_BN_CLICKED(IDC_BUTTON_EXPORT_ROW, &CPageGlassList::OnBnClickedButtonExportRow)
END_MESSAGE_MAP()
// ===== 绉佹湁灏忓伐鍏� =====
@@ -1240,6 +1290,158 @@
}
}
+void CPageGlassList::OnBnClickedButtonExportRow()
+{
+ int nSelected = m_listCtrl.GetSelectionMark();
+ if (nSelected == -1) {
+ AfxMessageBox(_T("璇峰厛閫夋嫨涓�琛岃褰曪紒"));
+ return;
+ }
+
+ // 鐩存帴浠庣涓�鍒楄幏鍙� ID
+ CString strId = m_listCtrl.GetItemText(nSelected, 1);
+
+ if (strId.IsEmpty()) {
+ AfxMessageBox(_T("WIP璁板綍鏆備笉鏀寔淇濆瓨"));
+ return;
+ }
+
+ // 鏁版嵁搴撹褰�
+ long long recordId = _ttoi64(strId);
+
+ // 浠庢暟鎹簱鏌ヨ瀹屾暣璁板綍
+ auto& db = GlassLogDb::Instance();
+ auto row = db.queryById(recordId);
+
+ if (!row) {
+ AfxMessageBox(_T("鏌ヨ璁板綍澶辫触"));
+ return;
+ }
+
+ // 浣跨敤 Glass ID 鏋勫缓榛樿鏂囦欢鍚�
+ CString strDefaultFileName;
+ CString strGlassId = row->classId.c_str();
+
+ // 绉婚櫎鏂囦欢鍚嶄腑鐨勯潪娉曞瓧绗�
+ CString strSanitizedGlassId = strGlassId;
+ strSanitizedGlassId.Remove('\\');
+ strSanitizedGlassId.Remove('/');
+ strSanitizedGlassId.Remove(':');
+ strSanitizedGlassId.Remove('*');
+ strSanitizedGlassId.Remove('?');
+ strSanitizedGlassId.Remove('"');
+ strSanitizedGlassId.Remove('<');
+ strSanitizedGlassId.Remove('>');
+ strSanitizedGlassId.Remove('|');
+
+ strDefaultFileName.Format(_T("Glass_%s.json"), strSanitizedGlassId);
+
+ // 鏂囦欢淇濆瓨瀵硅瘽妗嗭紝璁剧疆榛樿鏂囦欢鍚�
+ CFileDialog fileDialog(FALSE, _T("json"), strDefaultFileName,
+ OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
+ _T("JSON Files (*.json)|*.json|CSV Files (*.csv)|*.csv||"));
+
+ if (fileDialog.DoModal() != IDOK) return;
+
+ CString filePath = fileDialog.GetPathName();
+ CString fileExt = fileDialog.GetFileExt();
+
+ if (fileExt.CompareNoCase(_T("json")) == 0) {
+ // 淇濆瓨涓� JSON
+ if (!row->pretty.empty()) {
+ CFile file;
+ if (file.Open(filePath, CFile::modeCreate | CFile::modeWrite)) {
+ file.Write(row->pretty.c_str(), row->pretty.length());
+ file.Close();
+
+ CString strSuccess;
+ strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负JSON鏂囦欢锛歕n%s"), filePath);
+ AfxMessageBox(strSuccess);
+ }
+ else {
+ AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
+ }
+ }
+ else {
+ AfxMessageBox(_T("璇ヨ褰曟病鏈塉SON鏁版嵁"));
+ }
+ }
+ else {
+ // 淇濆瓨涓� CSV 鏍煎紡 - 鍒嗘寮�
+ CString csvContent;
+
+ // === 绗竴閮ㄥ垎锛氬熀纭�淇℃伅 ===
+ csvContent += _T("=== 鍩虹淇℃伅 ===\n");
+ csvContent += _T("ID,Cassette搴忓垪鍙�,Job搴忓垪鍙�,Glass ID,鐗╂枡绫诲瀷,鐘舵��,寮�濮嬫椂闂�,缁撴潫鏃堕棿,缁戝畾Glass ID,AOI缁撴灉,璺緞\n");
+
+ CString baseInfoRow;
+ baseInfoRow.Format(_T("%lld,%d,%d,%s,%d,%d,%s,%s,%s,%d,%s\n"),
+ row->id, row->cassetteSeqNo, row->jobSeqNo,
+ CString(row->classId.c_str()), row->materialType, row->state,
+ CString(row->tStart.c_str()), CString(row->tEnd.c_str()),
+ CString(row->buddyId.c_str()), row->aoiResult,
+ CString(row->path.c_str()));
+ csvContent += baseInfoRow;
+
+ // === 绗簩閮ㄥ垎锛氬伐鑹哄弬鏁� ===
+ csvContent += _T("\n=== 宸ヨ壓鍙傛暟 ===\n");
+
+ // 濡傛灉鏈� pretty 瀛楁锛岃В鏋愬伐鑹哄弬鏁�
+ if (!row->pretty.empty()) {
+ SERVO::CGlass tempGlass;
+ if (GlassJson::FromString(row->pretty, tempGlass)) {
+ auto& params = tempGlass.getParams();
+ if (!params.empty()) {
+ // 宸ヨ壓鍙傛暟琛ㄥご - 璋冩暣鍚庣殑鍒�
+ csvContent += _T("鍙傛暟鍚嶇О,鍙傛暟ID,鏁板��,鏈哄櫒鍗曞厓\n");
+
+ // 宸ヨ壓鍙傛暟鏁版嵁 - 璋冩暣鍚庣殑鏍煎紡
+ for (auto& param : params) {
+ CString paramRow;
+ CString valueStr;
+
+ // 鏍规嵁鍙傛暟绫诲瀷鏍煎紡鍖栨暟鍊�
+ if (param.getValueType() == PVT_INT) {
+ valueStr.Format(_T("%d"), param.getIntValue());
+ }
+ else {
+ valueStr.Format(_T("%.3f"), param.getDoubleValue());
+ }
+
+ // 璋冩暣鍚庣殑鏍煎紡锛氬幓鎺夋暟鍊肩被鍨嬪垪
+ paramRow.Format(_T("%s,%s,%s,%s\n"),
+ CString(param.getName().c_str()),
+ CString(param.getId().c_str()),
+ valueStr,
+ CString(param.getUnit().c_str())); // 杩欓噷鏄剧ず鏈哄櫒鍗曞厓
+
+ csvContent += paramRow;
+ }
+ }
+ else {
+ csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+ }
+ }
+ else {
+ csvContent += _T("鏃犳硶瑙f瀽宸ヨ壓鍙傛暟\n");
+ }
+ }
+ else {
+ csvContent += _T("鏃犲伐鑹哄弬鏁版暟鎹甛n");
+ }
+
+ // 浣跨敤杈呭姪鍑芥暟淇濆瓨涓� UTF-8 缂栫爜
+ if (WriteAnsiStringAsUtf8ToFile(csvContent, filePath)) {
+ CString strSuccess;
+ strSuccess.Format(_T("璁板綍宸蹭繚瀛樹负CSV鏂囦欢锛歕n%s"), filePath);
+ AfxMessageBox(strSuccess);
+ }
+ else {
+ AfxMessageBox(_T("淇濆瓨鏂囦欢澶辫触"));
+ }
+ }
+}
+
void CPageGlassList::OnBnClickedButtonPrevPage()
{
if (m_nCurPage > 1) {
@@ -1595,4 +1797,4 @@
}
return CDialogEx::PreTranslateMessage(pMsg);
-}
+}
\ No newline at end of file
--
Gitblit v1.9.3