XTable - 副本.cpp 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  1. // XTable.cpp : implementation file
  2. #include "stdafx.h"
  3. #include "YLGL.h"
  4. #include "XTable.h"
  5. #include "InputDate.h"
  6. #include "MemDC.h"
  7. #include "TodayForm2.h"
  8. #define XTABLE_CLASSNAME _T("XTableCtrl") // Window class name
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // XTable
  13. IMPLEMENT_DYNAMIC(XTable, CWnd)
  14. BEGIN_MESSAGE_MAP(XTable, CWnd)
  15. ON_WM_PAINT()
  16. ON_WM_KEYDOWN()
  17. ON_WM_LBUTTONDOWN()
  18. ON_WM_LBUTTONDBLCLK()
  19. ON_MESSAGE(WM_USER_EDIT_END,OnEditEnd)
  20. ON_WM_ERASEBKGND()
  21. END_MESSAGE_MAP()
  22. XTable::XTable(int rows, int cols)
  23. {
  24. RegisterWindowClass ();
  25. defaultCell.table = this;
  26. defaultHeight = 20;
  27. defaultWidth = 80;
  28. cells = NULL;
  29. rowHeight = NULL;
  30. colWidth = NULL;
  31. this->rows = 0;
  32. this->cols = 0;
  33. SetRows (rows);
  34. SetCols (cols);
  35. focusRow = 0;
  36. focusCol = 0;
  37. m_bFocusFrame=1;
  38. m_nCurShow=-1;
  39. m_nticks=::GetTickCount ();
  40. m_mode=0;
  41. }
  42. XTable::~XTable()
  43. {
  44. if(cells)delete [] cells;
  45. if(rowHeight)delete [] rowHeight;
  46. if(colWidth)delete [] colWidth;
  47. }
  48. // creates the control - use like any other window create control
  49. BOOL XTable::Create(const RECT& rect, CWnd* pParentWnd, UINT nID, DWORD dwStyle)
  50. {
  51. ASSERT(pParentWnd->GetSafeHwnd());
  52. if (!CWnd::Create(XTABLE_CLASSNAME, NULL, dwStyle, rect, pParentWnd, nID))
  53. return FALSE;
  54. return TRUE;
  55. }
  56. int XTable::ToXML (CMarkup& markup)
  57. {
  58. markup.AddChildElem ("table");
  59. markup.AddChildAttr("border", "1");
  60. markup.IntoElem ();
  61. for (int i = 0; i < GetRows (); i ++)
  62. {
  63. markup.AddChildElem ("tr");
  64. markup.IntoElem();
  65. for (int j = 0; j < GetCols (); j ++)
  66. {
  67. XCell* cell = GetCells (i, j);
  68. if (cell->colSpan > 0 && cell->rowSpan > 0)
  69. {
  70. markup.AddChildElem ("td");
  71. if (cell->colSpan == 1 && i == 0)
  72. markup.AddChildAttr ("width", GetColWidth (j));
  73. if (cell->rowSpan == 1 && j == 0)
  74. markup.AddChildAttr ("height", GetRowHeight (i));
  75. cell->ToXML (markup);
  76. }
  77. }
  78. markup.OutOfElem();
  79. }
  80. markup.OutOfElem();
  81. return 0;
  82. }
  83. int XTable::FromXML (CMarkup& markup)
  84. {
  85. markup.IntoElem ();
  86. int maxCol = 0;
  87. int maxRow = 0;
  88. int row = 0;
  89. int col = 0;
  90. SetCols (MAX_COLS);
  91. SetRows (MAX_ROWS);
  92. while (markup.FindChildElem("tr"))
  93. {
  94. markup.IntoElem();
  95. col = 0;
  96. while (markup.FindChildElem("td"))
  97. {
  98. XCell* cell;
  99. while (true)
  100. {
  101. cell = GetCells (row, col);
  102. if (!cell)
  103. break;
  104. if (cell->colSpan >= 1 && cell->rowSpan >= 1)
  105. break;
  106. col ++;
  107. }
  108. cell->FromXML (markup);
  109. if (cell->colSpan > 1 || cell->rowSpan > 1)
  110. JoinCells (row, col, row+cell->rowSpan-1, col+cell->colSpan-1);
  111. if (cell->colSpan == 1 && markup.GetChildAttr("width") != "")
  112. {
  113. int width = atoi (markup.GetChildAttr("width"));
  114. if (row == 0 || width > GetColWidth(col))
  115. SetColWidth (col, width);
  116. }
  117. if (cell->rowSpan == 1 && markup.GetChildAttr("height") != "")
  118. {
  119. int height = atoi (markup.GetChildAttr("height"));
  120. if (col == 0 || height > GetRowHeight(row))
  121. SetRowHeight (row, height);
  122. }
  123. col += cell->colSpan;
  124. if (col > maxCol) maxCol = col;
  125. if (row + cell->rowSpan > maxRow) maxRow = row + cell->rowSpan;
  126. }
  127. markup.OutOfElem();
  128. row ++;
  129. }
  130. markup.OutOfElem();
  131. SetRows (maxRow);
  132. SetCols (maxCol);
  133. return 0;
  134. }
  135. int XTable::SetRows(int newRows)
  136. {
  137. if (rows < 0 || rows > MAX_ROWS) return -1;
  138. if (rows == newRows) return 0;
  139. int cellsSize = cols * rows;
  140. XCell* newCells = cells;
  141. int* newRowHeight = new int [newRows];
  142. if ( rows < newRows)
  143. {
  144. if (cellsSize < newRows * cols)
  145. {
  146. cellsSize *= 2;
  147. if (cellsSize < newRows * cols)
  148. cellsSize = newRows * cols;
  149. newCells = new XCell [cellsSize];
  150. //复制旧数据
  151. for (int i = 0; i < rows; i++)
  152. {
  153. for(int j = 0; j < cols ; j++)
  154. {
  155. newCells [i * cols +j] = cells [i * cols +j];
  156. }
  157. newRowHeight [i] = rowHeight [i];
  158. }
  159. }
  160. //初始化新数据
  161. for (int i = rows; i < newRows; i++)
  162. {
  163. for (int j = 0; j < cols; j++)
  164. {
  165. newCells [i * cols + j] = defaultCell;
  166. newCells [i * cols + j].SetSpan (1, 1);
  167. }
  168. newRowHeight [i] = defaultHeight;
  169. }
  170. delete [] rowHeight;
  171. rowHeight = newRowHeight;
  172. }
  173. else
  174. {
  175. if (cellsSize > newRows * cols * 2)
  176. {
  177. cellsSize = newRows * cols;
  178. newCells = new XCell [cellsSize];
  179. }
  180. //复制数据
  181. for (int i = 0; i < newRows; i ++)
  182. {
  183. for (int j = 0; j < cols; j++)
  184. newCells [i * cols + j] = cells[i * cols +j];
  185. }
  186. }
  187. if (newCells != cells)
  188. {
  189. delete [] cells;
  190. cells = newCells;
  191. }
  192. rows = newRows;
  193. return 0;
  194. }
  195. int XTable::GetRows()
  196. {
  197. return rows;
  198. }
  199. int XTable::SetCols(int newCols)
  200. {
  201. if (newCols < 0 || newCols > MAX_COLS) return -1;
  202. if (this->cols == newCols) return 0;
  203. int cellsSize = cols * rows;
  204. XCell* newCells = cells;
  205. int* newColWidth = new int [newCols];
  206. if ( cols < newCols)
  207. {
  208. if (cellsSize < newCols * rows)
  209. {
  210. cellsSize *= 2;
  211. if (cellsSize < newCols * rows)
  212. cellsSize = newCols * rows;
  213. newCells = new XCell [cellsSize];
  214. //复制旧数据
  215. for (int i = 0; i < rows; i++)
  216. {
  217. for(int j = 0; j < cols ; j++)
  218. {
  219. newCells [i * newCols +j] = cells [i * cols +j];
  220. newColWidth[j] = colWidth [j];
  221. }
  222. }
  223. }
  224. //初始化新数据
  225. for (int i = 0; i < rows; i++)
  226. {
  227. for (int j = cols; j < newCols; j++)
  228. {
  229. newCells [i * newCols + j] = defaultCell;
  230. newCells [i * newCols + j].SetSpan (1, 1);
  231. newColWidth[j] = defaultWidth;
  232. }
  233. }
  234. delete [] colWidth;
  235. colWidth = newColWidth;
  236. }
  237. else
  238. {
  239. if (cellsSize > newCols * rows * 2)
  240. {
  241. cellsSize = newCols * rows;
  242. newCells = new XCell [cellsSize];
  243. }
  244. //复制数据
  245. for (int i = 0; i < rows; i ++)
  246. {
  247. for (int j = 0; j < newCols; j++)
  248. newCells [i * newCols + j] = cells[i * cols +j];
  249. }
  250. }
  251. if (newCells != cells)
  252. {
  253. delete [] cells;
  254. cells = newCells;
  255. }
  256. cols = newCols;
  257. return 0;
  258. }
  259. int XTable::GetCols()
  260. {
  261. return cols;
  262. }
  263. int XTable::JoinCells (int startRow, int startCol, int endRow, int endCol)
  264. {
  265. if (startRow < 0 || startRow >= rows) return -1;
  266. if (endRow < 0 || startRow >= rows) return -1;
  267. if (startCol < 0 || startCol >= cols) return -1;
  268. if (endCol < 0 || endCol >= cols) return -1;
  269. if (startRow > endRow || startCol > endCol) return -1;
  270. for (int i = startRow; i <= endRow; i++)
  271. {
  272. for (int j = startCol; j <=endCol; j++)
  273. {
  274. cells [i * cols + j].SetSpan(0,0);
  275. }
  276. }
  277. cells [startRow * cols + startCol].SetSpan(endRow - startRow+1, endCol - startCol+1);
  278. return 0;
  279. }
  280. int XTable::UnjoinCells (int row, int col)
  281. {
  282. if (row < 0 || row >= this->rows) return -1;
  283. if (col < 0 || col >= this->cols) return -1;
  284. if (cells [row * cols + col].rowSpan <= 1 && cells [row * cols + col].colSpan <= 1 ) return -1;
  285. for (int i = row; i <= row + cells [row * cols + col].rowSpan; i++)
  286. {
  287. for (int j = col; j <= cells [row * cols + col].colSpan; j++)
  288. {
  289. cells[i*cols+j] = defaultCell;
  290. cells [i * cols + j].SetSpan(1,1);
  291. }
  292. }
  293. return 0;
  294. }
  295. int XTable::SetRowHeight(int row, int height)
  296. {
  297. rowHeight [row] = height;
  298. return 0;
  299. }
  300. int XTable::GetRowHeight(int row)
  301. {
  302. return rowHeight [row];
  303. }
  304. int XTable::SetColWidth(int col, int width)
  305. {
  306. colWidth [col] = width;
  307. return 0;
  308. }
  309. int XTable::GetColWidth(int col)
  310. {
  311. return colWidth [col];
  312. }
  313. int XTable::GetRowsHeight(int startRow, int endRow)
  314. {
  315. if (startRow < 0 || startRow >= rows) return -1;
  316. if (endRow < 0 || endRow >= rows) return -1;
  317. if (startRow > endRow) return -1;
  318. int height = 0;
  319. for (int i = startRow; i <= endRow; i++)
  320. {
  321. height += rowHeight[i];
  322. }
  323. return height;
  324. }
  325. int XTable::GetColsWidth(int startCol, int endCol)
  326. {
  327. if (startCol < 0 || startCol >= cols) return -1;
  328. if (endCol < 0 || endCol >= cols) return -1;
  329. if (startCol > endCol) return -1;
  330. int width = 0;
  331. for (int i = startCol; i <= endCol; i++)
  332. {
  333. width += colWidth[i];
  334. }
  335. return width;
  336. }
  337. int XTable::SetCells(int row, int col, XCell& cell)
  338. {
  339. cells[row * cols + col] = cell;
  340. return 0;
  341. }
  342. XCell* XTable::GetCells(int row, int col)
  343. {
  344. return &cells [row * cols + col];
  345. }
  346. int XTable::SetText(int row, int col, CString str)
  347. {
  348. XCell* cell = GetCells (row, col);
  349. if (!cell) return -1;
  350. return cell->SetText (str);
  351. }
  352. CString XTable::GetText(int row, int col)
  353. {
  354. return cells[row * cols + col].GetText();
  355. }
  356. int XTable::SetTextColor(int row, int col, COLORREF color)
  357. {
  358. cells[row * cols + col].SetTextColor(color);
  359. return 0;
  360. }
  361. COLORREF XTable::GetTextColor(int row, int col)
  362. {
  363. return cells[row * cols + col].GetTextColor();
  364. }
  365. int XTable::SetTextFont(int row, int col, CFont& font)
  366. {
  367. cells[row * cols + col].SetTextFont(&font);
  368. return 0;
  369. }
  370. CFont* XTable::GetTextFont(int row, int col)
  371. {
  372. return cells[row * cols + col].GetTextFont();
  373. }
  374. int XTable::SetTextFontSize(int row, int col, int size)
  375. {
  376. cells[row * cols + col].SetTextFontSize(size);
  377. return 0;
  378. }
  379. int XTable::GetTextFontSize(int row, int col)
  380. {
  381. return cells[row * cols + col].GetTextFontSize();
  382. }
  383. int XTable::SetOverlap (int row, int col, bool enable)
  384. {
  385. XCell* cell = GetCells (row, col);
  386. if (!cell) return -1;
  387. return cell->SetOverlap (enable);
  388. }
  389. bool XTable::GetOverlap (int row, int col)
  390. {
  391. XCell* cell = GetCells (row, col);
  392. if (!cell) return false;
  393. return cell->GetOverlap ();
  394. }
  395. int XTable::SetAlignment (int row, int col, int align)
  396. {
  397. XCell* cell = GetCells (row, col);
  398. if (!cell) return -1;
  399. return cell->SetAlignment (align);
  400. }
  401. int XTable::GetAlignment (int row, int col)
  402. {
  403. XCell* cell = GetCells (row, col);
  404. if (!cell) return -1;
  405. return cell->GetAlignment ();
  406. }
  407. int XTable::SetWordbreak (int row, int col, bool wordbreak)
  408. {
  409. XCell* cell = GetCells (row, col);
  410. if (!cell) return -1;
  411. return cell->SetWordbreak (wordbreak);
  412. }
  413. bool XTable::GetWordbreak (int row, int col)
  414. {
  415. XCell* cell = GetCells (row, col);
  416. if (!cell) return false;
  417. return cell->GetWordbreak ();
  418. }
  419. int XTable::SetBackColor(int row, int col, COLORREF color)
  420. {
  421. cells[row * cols + col].SetBackColor(color);
  422. return 0;
  423. }
  424. COLORREF XTable::GetBackColor(int row, int col)
  425. {
  426. return cells[row * cols + col].GetBackColor();
  427. }
  428. int XTable::SetBackMode(int row, int col, int mode)
  429. {
  430. cells[row * cols + col].SetBackMode(mode);
  431. return 0;
  432. }
  433. int XTable::GetBackMode(int row, int col)
  434. {
  435. return cells[row * cols + col].GetBackMode();
  436. }
  437. RECT XTable::GetRect(int row, int col)
  438. {
  439. RECT rect;
  440. try
  441. {
  442. int rowSpan = GetCells(row, col)->rowSpan;
  443. int colSpan = GetCells(row, col)->colSpan;
  444. rect.top = GetRowsHeight(0, row-1);
  445. rect.left = GetColsWidth(0, col-1);
  446. rect.bottom = rect.top + GetRowsHeight (row, row + rowSpan-1);
  447. rect.right = rect.left + GetColsWidth (col, col + colSpan-1);
  448. }
  449. catch(...)
  450. {
  451. }
  452. return rect;
  453. }
  454. bool XTable::HitTest (CPoint point, int& row, int& col)
  455. {
  456. try
  457. {
  458. for (int i= 0; i < rows; i++)
  459. {
  460. for(int j=0; j < rows; j++)
  461. {
  462. RECT rect = GetRect (i,j);
  463. if (rect.top <= point.y && rect.bottom > point.y && rect.left <= point.x && rect.right > point.x)
  464. {
  465. row = i;
  466. col = j;
  467. return true;
  468. }
  469. }
  470. }
  471. }
  472. catch(...)
  473. {
  474. }
  475. return false;
  476. }
  477. void XTable::OnDraw(CDC* pDC)
  478. {
  479. static bool lock = false;
  480. if (lock) return;
  481. if (!::IsWindow(m_hWnd)) return;
  482. lock = true;
  483. Draw (pDC);
  484. lock = false;
  485. }
  486. int XTable::Draw(CDC* pDC)
  487. {
  488. try
  489. {
  490. for (int i = 0; i < rows; i++)
  491. {
  492. for (int j = 0; j < cols; j++)
  493. {
  494. XCell& cell = cells[i*cols+j];
  495. if (cell.colSpan !=0 && cell.rowSpan != 0)
  496. {
  497. RECT rect = GetRect(i,j);
  498. if (cell.GetOverlap())
  499. {
  500. RECT textRect = GetRect(i,j);
  501. cell.CalcTextRect(pDC, &textRect);
  502. if (textRect.right > rect.right)
  503. {
  504. for (j = j+1; j < cols; j ++)
  505. {
  506. if (cells[i*cols+j].text != "")
  507. break;
  508. rect.right += colWidth [j];
  509. if (rect.right > textRect.right)
  510. break;
  511. }
  512. j --;
  513. }
  514. }
  515. cell.Draw(pDC,rect);
  516. }
  517. }
  518. }
  519. if (focusCol && m_bFocusFrame && focusRow < rows && focusCol < cols) //**
  520. {
  521. RECT rect = GetRect (focusRow, 1);
  522. RECT rect2 = GetRect (focusRow, cols-1);
  523. RECT rect3=rect;
  524. if(rect2.right>rect3.right)
  525. rect3.right =rect2.right ;
  526. GetCells (focusRow, focusCol)->DrawHitBorder(pDC, rect3, RGB(255, 0, 20));
  527. }
  528. }
  529. catch(...)
  530. {
  531. }
  532. return 0;
  533. }
  534. // XTable message handlers
  535. void XTable::OnPaint()
  536. {
  537. CPaintDC dc(this); // device context for painting
  538. CMemDC MemDC(&dc);
  539. OnDraw(&MemDC);
  540. }
  541. BOOL XTable::OnEraseBkgnd(CDC* pDC)
  542. {
  543. return TRUE;
  544. }
  545. void XTable::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  546. {
  547. CPoint point;
  548. RECT rect = GetRect(focusRow,focusCol);
  549. point.x = rect.left;
  550. point.y = rect.top;
  551. switch (nChar)
  552. {
  553. case VK_DOWN:
  554. point.y =rect.bottom + 1;
  555. break;
  556. case VK_UP:
  557. point.y =point.y -2;
  558. break;
  559. case VK_LEFT:
  560. point.x = point.x - 2;
  561. break;
  562. case VK_RIGHT:
  563. point.x =rect.right + 1;
  564. break;
  565. default:
  566. return ;
  567. }
  568. HitTest (point,focusRow,focusCol);
  569. Invalidate();
  570. CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
  571. }
  572. void XTable::OnLButtonDown(UINT nFlags, CPoint point)
  573. {
  574. ::PostMessage(this->GetSafeHwnd(),WM_USER_EDIT_END,1,1);
  575. if(!m_bFocusFrame)return;
  576. HitTest (point,focusRow,focusCol);
  577. SetFocus ();
  578. Invalidate();
  579. CWnd::OnLButtonDown(nFlags, point);
  580. }
  581. void XTable::OnEditEnd(WPARAM wParam,LPARAM lParam)
  582. {
  583. if(m_nCurShow==-1)return;
  584. int nAdd=0;
  585. if(m_mode==4)nAdd=1;
  586. if(m_nCurShow==0)
  587. {
  588. if(wParam == TRUE)
  589. {
  590. CString strText(_T(""));
  591. m_edit.GetWindowText(strText);
  592. DWORD dwData = m_edit.GetCtrlData();
  593. int nItem= dwData>>16;
  594. int nIndex = dwData&0x0000ffff;
  595. CString oldtext=GetText(nItem,nIndex);
  596. SetText(nItem,nIndex,strText);
  597. AddName(nItem,11+nAdd, g_user.name);
  598. // SetText(nItem,11+nAdd, g_user.name);
  599. if(nIndex==9+nAdd)
  600. {
  601. if(atoi(GetText(nItem,9+nAdd))>0 )
  602. {
  603. SetBackColor (nItem,9+nAdd, RGB(255,0,0));
  604. }
  605. else SetBackColor (nItem,9+nAdd, RGB(0,255,0));
  606. }
  607. if(nIndex==12+nAdd)
  608. {
  609. if(GetText(nItem,12+nAdd)=="未到" )
  610. {
  611. SetBackColor (nItem,12+nAdd, RGB(255,0,0));
  612. }
  613. else
  614. SetBackColor (nItem,12+nAdd, RGB(0,255,0));
  615. }
  616. if(oldtext!=strText)
  617. Save(nItem);
  618. }
  619. m_edit.ShowWindow(SW_HIDE); m_nCurShow=-1; CalRowHeight();
  620. }
  621. else if(m_nCurShow==1)
  622. {
  623. if(wParam == TRUE)
  624. {
  625. CString strText(_T(""));
  626. m_combobox.GetWindowText(strText);
  627. if(strText.IsEmpty ())
  628. {
  629. m_combobox.ShowWindow(SW_HIDE); m_nCurShow=-1;
  630. return;
  631. }
  632. int pos=m_combobox.GetCurSel ();
  633. if(pos==-1)
  634. {
  635. m_combobox.ShowWindow(SW_HIDE); m_nCurShow=-1;
  636. DWORD dwData = m_combobox.GetCtrlData();
  637. int nItem= dwData>>16;
  638. int nIndex = dwData&0x0000ffff;
  639. CString oldtext=GetText(nItem,nIndex);
  640. SetText(nItem,nIndex,strText);
  641. AddName(nItem,11+nAdd, g_user.name);
  642. SetText(nItem,12+nAdd,"未到");
  643. if(oldtext!=strText)
  644. Save(nItem);
  645. m_combobox.ShowWindow(SW_HIDE); m_nCurShow=-1; CalRowHeight();
  646. return;
  647. }
  648. if(m_acCombo.m_posarray.GetSize ()<=pos)
  649. {
  650. m_combobox.ShowWindow(SW_HIDE); m_nCurShow=-1;
  651. DWORD dwData = m_combobox.GetCtrlData();
  652. int nItem= dwData>>16;
  653. int nIndex = dwData&0x0000ffff;
  654. CString oldtext=GetText(nItem,nIndex);
  655. SetText(nItem,nIndex,strText);
  656. AddName(nItem,11+nAdd, g_user.name);
  657. SetText(nItem,12+nAdd,"未到");
  658. if(oldtext!=strText)
  659. Save(nItem);
  660. }
  661. else
  662. {
  663. int pos2=m_acCombo.m_posarray.ElementAt (pos);
  664. m_id=m_pClientArray->ElementAt (pos2).ElementAt (0);
  665. DWORD dwData = m_combobox.GetCtrlData();
  666. int nItem= dwData>>16;
  667. int nIndex = dwData&0x0000ffff;
  668. CString oldtext=GetText(nItem,nIndex);
  669. SetText(nItem,nIndex,strText);
  670. if(!m_pClientArray->ElementAt (pos2).ElementAt (3).IsEmpty ())
  671. SetText(nItem,2,m_pClientArray->ElementAt (pos2).ElementAt (3)+" "+m_pClientArray->ElementAt (pos2).ElementAt (4));
  672. else
  673. SetText(nItem,2,m_pClientArray->ElementAt (pos2).ElementAt (4));
  674. if(m_mode==4)
  675. {
  676. g_sendhead.bsql=0;
  677. CString filter="id='"+m_id+"' and kind<>'5'";
  678. g_sendhead.code[0]=56;
  679. g_sendhead.tabcount=1;
  680. g_bNoConnDlg=1;
  681. g_pMainWnd->ProcessChatMessageRequest2(filter); g_bNoConnDlg=0;
  682. if(g_bSendOK)
  683. {
  684. DataToArray(&g_List1array);
  685. CString str;
  686. for(int i=0; i<g_List1array.GetSize (); i++)
  687. { if(g_List1array.ElementAt (i).ElementAt (20)!="2")continue;
  688. str+=g_List1array.ElementAt (i).ElementAt (0);
  689. str+=",";
  690. }
  691. str.TrimRight (",");
  692. SetText(nItem,4,str);
  693. }
  694. }
  695. SetText(nItem,4+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (5));
  696. SetText(nItem,5+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (6));
  697. SetText(nItem,6+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (7));
  698. SetText(nItem,7+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (8));
  699. SetText(nItem,8+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (9));
  700. SetText(nItem,9+nAdd,m_pClientArray->ElementAt (pos2).ElementAt (10));
  701. if(atoi(GetText(nItem,9+nAdd))>0 )
  702. {
  703. SetBackColor (nItem,9+nAdd, RGB(255,0,0));
  704. }
  705. else SetBackColor (nItem,9+nAdd, RGB(0,255,0));
  706. if(!m_pClientArray->ElementAt (pos2).ElementAt (11).IsEmpty ())
  707. SetText(nItem,10+nAdd,"服装:"+m_pClientArray->ElementAt (pos2).ElementAt (11));
  708. AddName(nItem,11+nAdd, g_user.name);
  709. SetText(nItem,12+nAdd,"未到");
  710. if(oldtext!=strText)
  711. Save(nItem);
  712. }
  713. }
  714. m_combobox.ShowWindow(SW_HIDE); m_nCurShow=-1; CalRowHeight();
  715. }
  716. else if(m_nCurShow==2)
  717. {
  718. if(wParam == TRUE)
  719. {
  720. CString strText(_T(""));
  721. m_combobox2.GetWindowText(strText);
  722. DWORD dwData = m_combobox2.GetCtrlData();
  723. int nItem= dwData>>16;
  724. int nIndex = dwData&0x0000ffff;
  725. CString oldtext=GetText(nItem,nIndex);
  726. SetText(nItem,nIndex,strText);
  727. // SetText(nItem,11+nAdd, g_user.name);
  728. AddName(nItem,11+nAdd, g_user.name);
  729. if(nIndex==12+nAdd)
  730. {
  731. if(GetText(nItem,12+nAdd)=="未到" )
  732. {
  733. SetBackColor (nItem,12+nAdd, RGB(255,0,0));
  734. }
  735. else
  736. SetBackColor (nItem,12+nAdd, RGB(0,255,0));
  737. }
  738. if(oldtext!=strText)
  739. Save(nItem);
  740. //Invalidate();
  741. }
  742. m_combobox2.ShowWindow(SW_HIDE); m_nCurShow=-1; CalRowHeight();
  743. }
  744. }
  745. void XTable::ShowEdit(BOOL bShow,int nItem,int nIndex,CRect rcCtrl)
  746. {
  747. try
  748. {
  749. if(m_edit.m_hWnd == NULL)
  750. {
  751. m_edit.Create(ES_AUTOHSCROLL|WS_CHILD|ES_LEFT|ES_WANTRETURN|WS_BORDER,CRect(0,0,0,0),this,IDC_EDIT1);
  752. m_edit.ShowWindow(SW_HIDE);
  753. CFont tpFont;
  754. tpFont.CreateStockObject(DEFAULT_GUI_FONT);
  755. m_edit.SetFont(&tpFont);
  756. tpFont.DeleteObject();
  757. }
  758. if(bShow == TRUE)
  759. {
  760. CString strItem = GetText(nItem,nIndex);
  761. m_edit.MoveWindow(rcCtrl);
  762. m_edit.ShowWindow(SW_SHOW);
  763. m_edit.SetWindowText(strItem);
  764. ::SetFocus(m_edit.GetSafeHwnd());
  765. m_edit.SetSel(-1);
  766. m_edit.SetCtrlData(MAKEWPARAM(nIndex,nItem));
  767. }
  768. else
  769. m_edit.ShowWindow(SW_HIDE);
  770. }
  771. catch(...)
  772. {
  773. }
  774. }
  775. void XTable::ShowSearchClientComboBox(BOOL bShow,int nItem,int nIndex,CRect rcCtrl)
  776. {
  777. try
  778. {
  779. if(m_combobox.m_hWnd == NULL)
  780. {
  781. m_combobox.Create(WS_VSCROLL|WS_CHILD|CBS_DROPDOWN,CRect(0,0,0,0),this,100);
  782. m_combobox.ShowWindow(SW_HIDE);
  783. m_acCombo.m_mode =1;
  784. m_acCombo.Init(&m_combobox);
  785. m_acCombo.m_pArray=m_pClientArray;
  786. m_combobox.SetFocus ();
  787. }
  788. if(bShow == TRUE)
  789. {
  790. CString strItem = GetText(nItem,nIndex);
  791. rcCtrl.bottom+=300;
  792. m_combobox.MoveWindow(rcCtrl);
  793. m_combobox.ShowWindow(SW_SHOW);
  794. m_combobox.SetWindowText(strItem);
  795. ::SetFocus(m_combobox.GetSafeHwnd());
  796. m_combobox.SetCtrlData(MAKEWPARAM(nIndex,nItem));
  797. }
  798. else
  799. m_combobox.ShowWindow(SW_HIDE);
  800. }
  801. catch(...)
  802. {
  803. }
  804. }
  805. void XTable::ShowSearchClientComboBoxTime(BOOL bShow,int nItem,int nIndex,int type,CRect rcCtrl)
  806. {
  807. try
  808. {
  809. if(m_combobox2.m_hWnd == NULL)
  810. {
  811. m_combobox2.Create(WS_VSCROLL|WS_CHILD|CBS_DROPDOWN,CRect(0,0,0,0),this,100);
  812. m_combobox2.ShowWindow(SW_HIDE);
  813. m_combobox2.SetFocus ();
  814. }
  815. m_combobox2.ResetContent ();
  816. if(type==0)
  817. {
  818. m_combobox2.AddString ("9:00");
  819. m_combobox2.AddString ("9:30");
  820. m_combobox2.AddString ("10:00");
  821. m_combobox2.AddString ("10:30");
  822. m_combobox2.AddString ("11:00");
  823. m_combobox2.AddString ("11:30");
  824. m_combobox2.AddString ("12:00");
  825. m_combobox2.AddString ("13:00");
  826. m_combobox2.AddString ("14:00");
  827. m_combobox2.AddString ("15:00");
  828. m_combobox2.AddString ("16:00");
  829. m_combobox2.AddString ("17:00");
  830. m_combobox2.AddString ("18:00");
  831. m_combobox2.AddString ("19:00");
  832. m_combobox2.AddString ("20:00");
  833. m_combobox2.AddString ("21:00");
  834. }
  835. else if(type==1)
  836. {
  837. for(int i=0; i<pTxtypearray->GetSize (); i++)
  838. m_combobox2.AddString (pTxtypearray->ElementAt (i).ElementAt (0));
  839. }
  840. else if(type==2)
  841. {
  842. for(int ii=0; ii<g_userarray.GetSize (); ii++)
  843. {
  844. if("摄影部"== g_userarray.ElementAt (ii).ElementAt(2) )
  845. m_combobox2.AddString ( g_userarray.ElementAt (ii).ElementAt(1) );
  846. }
  847. }
  848. else if(type==3)
  849. {
  850. for(int ii=0; ii<g_userarray.GetSize (); ii++)
  851. {
  852. if("化妆部"== g_userarray.ElementAt (ii).ElementAt(2) )
  853. m_combobox2.AddString ( g_userarray.ElementAt (ii).ElementAt(1) );
  854. }
  855. }
  856. else if(type==4)
  857. {
  858. for(int ii=0; ii<g_userarray.GetSize (); ii++)
  859. {
  860. // if("化妆部"== g_userarray.ElementAt (ii).ElementAt(2) )
  861. m_combobox2.AddString ( g_userarray.ElementAt (ii).ElementAt(1) );
  862. }
  863. }
  864. else if(type==5)
  865. {
  866. m_combobox2.AddString ("未到");
  867. m_combobox2.AddString ("已到");
  868. }
  869. if(bShow == TRUE)
  870. {
  871. CString strItem = GetText(nItem,nIndex);
  872. rcCtrl.bottom+=300;
  873. m_combobox2.MoveWindow(rcCtrl);
  874. m_combobox2.ShowWindow(SW_SHOW);
  875. m_combobox2.SetWindowText(strItem);
  876. ::SetFocus(m_combobox2.GetSafeHwnd());
  877. m_combobox2.SetCtrlData(MAKEWPARAM(nIndex,nItem));
  878. }
  879. else
  880. m_combobox2.ShowWindow(SW_HIDE);
  881. }
  882. catch(...)
  883. {
  884. }
  885. }
  886. void XTable::OnLButtonDblClk(UINT nFlags, CPoint point)
  887. {
  888. try
  889. {
  890. if(!m_bFocusFrame)return;
  891. if(HitTest (point,focusRow,focusCol)==0)return;
  892. if(IsDateRow(focusRow))return;
  893. RECT rect = GetRect (focusRow,focusCol);
  894. if(focusCol==0)return;
  895. int nAdd=0;
  896. if(m_mode==4)nAdd=1;
  897. if(focusRow>0)
  898. {
  899. for(int i=0; i<focusRow; i++)
  900. {
  901. if(""==GetText(i,1))
  902. {
  903. AfxMessageBox("请从上方空白处开始填起!", MB_ICONINFORMATION);
  904. return;
  905. }
  906. }
  907. }
  908. if(focusCol==1)
  909. { m_nCurShow=1;
  910. ShowSearchClientComboBox(TRUE,focusRow,focusCol,rect);
  911. }
  912. else if(""==GetText(focusRow,1))
  913. {
  914. AfxMessageBox("请先填写客人姓名!", MB_ICONINFORMATION);
  915. return;
  916. }
  917. if(focusCol==11+nAdd)return;
  918. if(focusCol==3)
  919. { m_nCurShow=2;
  920. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,0,rect);
  921. }
  922. else if(focusCol==4+nAdd)
  923. { m_nCurShow=2;
  924. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,1,rect);
  925. }
  926. else if(focusCol==6+nAdd)
  927. { m_nCurShow=2;
  928. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,2,rect);
  929. }
  930. else if(focusCol==7+nAdd)
  931. { m_nCurShow=2;
  932. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,3,rect);
  933. }
  934. else if(focusCol==8+nAdd)
  935. { m_nCurShow=2;
  936. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,4,rect);
  937. }
  938. else if(focusCol==12+nAdd)
  939. { m_nCurShow=2;
  940. ShowSearchClientComboBoxTime(TRUE,focusRow,focusCol,5,rect);
  941. }
  942. else if(focusCol!=1)
  943. { m_nCurShow=0;
  944. ShowEdit(TRUE,focusRow,focusCol,rect);
  945. }
  946. }
  947. catch(...)
  948. {
  949. }
  950. CWnd::OnLButtonDown(nFlags, point);
  951. }
  952. BOOL XTable::RegisterWindowClass()
  953. {
  954. WNDCLASS wndcls;
  955. HINSTANCE hInst = AfxGetInstanceHandle();
  956. if (!(::GetClassInfo(hInst, XTABLE_CLASSNAME, &wndcls)))
  957. {
  958. // otherwise we need to register a new class
  959. wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  960. wndcls.lpfnWndProc = ::DefWindowProc;
  961. wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
  962. wndcls.hInstance = hInst;
  963. wndcls.hIcon = NULL;
  964. wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
  965. wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
  966. wndcls.lpszMenuName = NULL;
  967. wndcls.lpszClassName = XTABLE_CLASSNAME;
  968. if (!AfxRegisterClass(&wndcls))
  969. {
  970. AfxThrowResourceException();
  971. return FALSE;
  972. }
  973. }
  974. return TRUE;
  975. }
  976. int XTable::Test2 ()
  977. {
  978. defaultHeight = 20;
  979. CStringArray array;
  980. if(m_mode==4)
  981. {
  982. array.Add ("姓名");
  983. array.Add ("电话");
  984. array.Add ("时间");
  985. array.Add ("婚庆内容");
  986. array.Add ("类别");
  987. array.Add ("价格");
  988. array.Add ("摄影");
  989. #ifdef CHILD_VERSION
  990. array.Add ("引导");
  991. #else
  992. array.Add ("化妆");
  993. #endif
  994. array.Add ("门市");
  995. array.Add ("欠款");
  996. array.Add ("备注");
  997. array.Add ("录入");
  998. array.Add ("是否到店");
  999. }
  1000. else
  1001. {
  1002. array.Add ("姓名");
  1003. array.Add ("电话");
  1004. array.Add ("时间");
  1005. array.Add ("类别");
  1006. array.Add ("价格");
  1007. array.Add ("摄影");
  1008. #ifdef CHILD_VERSION
  1009. array.Add ("引导");
  1010. #else
  1011. array.Add ("化妆");
  1012. #endif
  1013. array.Add ("门市");
  1014. array.Add ("欠款");
  1015. array.Add ("备注");
  1016. array.Add ("录入");
  1017. array.Add ("是否到店");
  1018. }
  1019. int cols=array.GetSize();
  1020. CRect rc;
  1021. GetClientRect(rc);
  1022. defaultWidth = (rc.Width()-10)/cols;
  1023. SetCols (1);
  1024. SetRows (2);
  1025. SetCols (cols+1);
  1026. COLORREF col1=RGB(0xC8, 0x96, 0x96);
  1027. COLORREF col2=RGB(0x64,0x96,0xC8);
  1028. for (int i = 0; i < 2; i ++)
  1029. SetBackColor (i, 0, col1);
  1030. for ( i = 0; i < cols+1; i ++)
  1031. SetBackColor (0, i, col1);
  1032. SetRowHeight (0, 10);
  1033. SetColWidth (0, 10);
  1034. for(i=0; i<cols; i++)
  1035. {
  1036. SetBackColor (1,i+1, col2);
  1037. SetText (1,i+1, array.ElementAt (i));
  1038. }
  1039. Invalidate();
  1040. return 0;
  1041. }
  1042. ///edit
  1043. XTableEdit::XTableEdit()
  1044. {
  1045. }
  1046. XTableEdit::~XTableEdit()
  1047. {
  1048. }
  1049. BEGIN_MESSAGE_MAP(XTableEdit, CEdit)
  1050. //{{AFX_MSG_MAP(XTableEdit)
  1051. ON_WM_KILLFOCUS()
  1052. ON_WM_SETFOCUS()
  1053. //}}AFX_MSG_MAP
  1054. END_MESSAGE_MAP()
  1055. /////////////////////////////////////////////////////////////////////////////
  1056. // XTableEdit message handlers
  1057. void XTableEdit::SetCtrlData(DWORD dwData)
  1058. {
  1059. m_dwData = dwData;
  1060. }
  1061. DWORD XTableEdit::GetCtrlData()
  1062. {
  1063. return m_dwData;
  1064. }
  1065. void XTableEdit::OnKillFocus(CWnd* pNewWnd)
  1066. {
  1067. CEdit::OnKillFocus(pNewWnd);
  1068. CWnd* pParent = this->GetParent();
  1069. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,0);
  1070. }
  1071. BOOL XTableEdit::PreTranslateMessage(MSG* pMsg)
  1072. {
  1073. if(pMsg->message == WM_KEYDOWN)
  1074. {
  1075. if(pMsg->wParam == VK_RETURN)
  1076. {
  1077. CWnd* pParent = this->GetParent();
  1078. m_bExchange = TRUE;
  1079. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,0);
  1080. }
  1081. else if(pMsg->wParam == VK_ESCAPE)
  1082. {
  1083. CWnd* pParent = this->GetParent();
  1084. m_bExchange = FALSE;
  1085. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,0);
  1086. }
  1087. }
  1088. return CEdit::PreTranslateMessage(pMsg);
  1089. }
  1090. void XTableEdit::OnSetFocus(CWnd* pOldWnd)
  1091. {
  1092. CEdit::OnSetFocus(pOldWnd);
  1093. m_bExchange = TRUE;
  1094. }
  1095. XTableComboBox::XTableComboBox()
  1096. {
  1097. }
  1098. XTableComboBox::~XTableComboBox()
  1099. {
  1100. }
  1101. BEGIN_MESSAGE_MAP(XTableComboBox, CComboBox)
  1102. //{{AFX_MSG_MAP(XTableComboBox)
  1103. ON_WM_KILLFOCUS()
  1104. ON_WM_SETFOCUS()
  1105. ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
  1106. //}}AFX_MSG_MAP
  1107. END_MESSAGE_MAP()
  1108. /////////////////////////////////////////////////////////////////////////////
  1109. // XTableComboBox message handlers
  1110. void XTableComboBox::SetCtrlData(DWORD dwData)
  1111. {
  1112. m_dwData = dwData;
  1113. }
  1114. DWORD XTableComboBox::GetCtrlData()
  1115. {
  1116. return m_dwData;
  1117. }
  1118. void XTableComboBox::OnKillFocus(CWnd* pNewWnd)
  1119. {
  1120. CComboBox::OnKillFocus(pNewWnd);
  1121. /* CWnd* pParent = this->GetParent();
  1122. if(((XTable*)pParent)->m_nCurShow!=-1)
  1123. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);*/
  1124. }
  1125. BOOL XTableComboBox::PreTranslateMessage(MSG* pMsg)
  1126. {
  1127. if(pMsg->message == WM_KEYDOWN)
  1128. {
  1129. if(pMsg->wParam == VK_RETURN)
  1130. {
  1131. CWnd* pParent = this->GetParent();
  1132. m_bExchange = TRUE;
  1133. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1134. }
  1135. else if(pMsg->wParam == VK_ESCAPE)
  1136. {
  1137. CWnd* pParent = this->GetParent();
  1138. m_bExchange = FALSE;
  1139. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1140. }
  1141. }
  1142. return CComboBox::PreTranslateMessage(pMsg);
  1143. }
  1144. void XTableComboBox::OnSetFocus(CWnd* pOldWnd)
  1145. {
  1146. CComboBox::OnSetFocus(pOldWnd);
  1147. m_bExchange = TRUE;
  1148. }
  1149. void XTableComboBox::OnCloseup()
  1150. {
  1151. // TODO: Add your control notification handler code here
  1152. CWnd* pParent = this->GetParent();
  1153. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1154. }
  1155. //
  1156. XTableTreeComboBox::XTableTreeComboBox()
  1157. {
  1158. }
  1159. XTableTreeComboBox::~XTableTreeComboBox()
  1160. {
  1161. }
  1162. BEGIN_MESSAGE_MAP(XTableTreeComboBox, CTreeComboBox)
  1163. //{{AFX_MSG_MAP(XTableTreeComboBox)
  1164. ON_WM_KILLFOCUS()
  1165. ON_WM_SETFOCUS()
  1166. ON_CONTROL_REFLECT(CBN_CLOSEUP, OnCloseup)
  1167. //}}AFX_MSG_MAP
  1168. END_MESSAGE_MAP()
  1169. /////////////////////////////////////////////////////////////////////////////
  1170. // XTableTreeComboBox message handlers
  1171. void XTableTreeComboBox::SetCtrlData(DWORD dwData)
  1172. {
  1173. m_dwData = dwData;
  1174. }
  1175. DWORD XTableTreeComboBox::GetCtrlData()
  1176. {
  1177. return m_dwData;
  1178. }
  1179. void XTableTreeComboBox::OnKillFocus(CWnd* pNewWnd)
  1180. {
  1181. CTreeComboBox::OnKillFocus(pNewWnd);
  1182. /* CWnd* pParent = this->GetParent();
  1183. if(((XTable*)pParent)->m_nCurShow!=-1)
  1184. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);*/
  1185. }
  1186. BOOL XTableTreeComboBox::PreTranslateMessage(MSG* pMsg)
  1187. {
  1188. if(pMsg->message == WM_KEYDOWN)
  1189. {
  1190. if(pMsg->wParam == VK_RETURN)
  1191. {
  1192. CWnd* pParent = this->GetParent();
  1193. m_bExchange = TRUE;
  1194. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1195. }
  1196. else if(pMsg->wParam == VK_ESCAPE)
  1197. {
  1198. CWnd* pParent = this->GetParent();
  1199. m_bExchange = FALSE;
  1200. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1201. }
  1202. }
  1203. return CTreeComboBox::PreTranslateMessage(pMsg);
  1204. }
  1205. void XTableTreeComboBox::OnSetFocus(CWnd* pOldWnd)
  1206. {
  1207. CTreeComboBox::OnSetFocus(pOldWnd);
  1208. m_bExchange = TRUE;
  1209. }
  1210. void XTableTreeComboBox::OnCloseup()
  1211. {
  1212. // TODO: Add your control notification handler code here
  1213. CWnd* pParent = this->GetParent();
  1214. ::PostMessage(pParent->GetSafeHwnd(),WM_USER_EDIT_END,m_bExchange,1);
  1215. }
  1216. //
  1217. void XTable::CalRowHeight()
  1218. {
  1219. CString str; CPaintDC dc(this);
  1220. for(int i=0; i<GetRows(); i++)
  1221. {
  1222. SetRowHeight (i, 20);
  1223. for(int j=1; j<GetCols(); j++)
  1224. {
  1225. str=GetText(i, j);
  1226. RECT rect = GetRect(i,j);
  1227. RECT textRect=rect;
  1228. this->SetWordbreak (i, j, 0);
  1229. XCell* cell = GetCells (i, j);
  1230. cell->CalcTextRect(&dc, &textRect);
  1231. if (textRect.right > rect.right || textRect.bottom > rect.bottom)
  1232. {
  1233. this->SetWordbreak (i, j, 1);
  1234. textRect=rect;
  1235. cell->CalcTextRect(&dc, &textRect);
  1236. rect.bottom =textRect.bottom+2;
  1237. // if(rect.bottom-rect.top>100)rect.bottom=rect.top+100;
  1238. SetRowHeight (i, rect.bottom-rect.top);
  1239. }
  1240. }
  1241. }
  1242. Invalidate();
  1243. }
  1244. void XTable::Save(int row)
  1245. {
  1246. if(m_mode==4)
  1247. {
  1248. Save2(row);return;
  1249. }
  1250. if(IsHasRightsnew(2)==0)return;
  1251. if(::GetTickCount ()-m_nticks<1000)return;
  1252. m_nticks=::GetTickCount ();
  1253. int oldrow=row;
  1254. BOOL bFind=0;
  1255. for(int i=0; i<m_daterowposarray.GetSize (); i++)
  1256. {
  1257. if(row<m_daterowposarray.ElementAt (i))
  1258. {
  1259. row-=i;bFind=1;
  1260. break;
  1261. }
  1262. if(row==m_daterowposarray.ElementAt (i))
  1263. return;
  1264. }
  1265. if(bFind==0)row-=m_daterowposarray.GetSize ();
  1266. if(row>=m_pListArray->GetSize())//新预约
  1267. {
  1268. CString name=GetText(oldrow, 1);
  1269. CString phone=GetText(oldrow, 2);
  1270. CString time=GetText(oldrow, 3);
  1271. CString type=GetText(oldrow, 4);
  1272. CString price=GetText(oldrow, 5);
  1273. CString waiter1=GetText(oldrow, 6);
  1274. CString waiter2=GetText(oldrow, 7);
  1275. CString receptionist=GetText(oldrow, 8);
  1276. CString arrearage=GetText(oldrow, 9);
  1277. CString remark=GetText(oldrow, 10);
  1278. CString clerk=GetText(oldrow, 11);
  1279. CString arrive=GetText(oldrow, 12);
  1280. CString timestamp=CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S");
  1281. CString date=((TodayForm2*)(GetParent()->GetParent()))->GetDate();
  1282. if(name.IsEmpty())return;
  1283. CString sql,sql2;
  1284. sql.Format ("insert into todaytake([name],[phone],[time],[type],[price],[waiter1],[waiter2],[receptionist],\
  1285. [arrearage],[remark],[clerk],[timestamp],[date],[mode],[arrive],[id])values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%d','%s','%s')", \
  1286. name,phone,time,type,price,waiter1,waiter2,receptionist,arrearage,remark,clerk,timestamp,date,m_mode,arrive,m_id);
  1287. if(m_mode==0)
  1288. {
  1289. sql2.Format ("***update dindan set [time2]='%s' where [id]='%s'", date, m_id);
  1290. }
  1291. else if(m_mode==1)
  1292. {
  1293. sql2.Format ("***update dindan set [time4]='%s' where [id]='%s'", date, m_id);
  1294. }
  1295. else if(m_mode==2)
  1296. {
  1297. sql2.Format ("***update dindan set [time6]='%s' where [id]='%s'", date, m_id);
  1298. }
  1299. else if(m_mode==3)
  1300. {
  1301. sql2.Format ("***update dindan set [time5]='%s' where [id]='%s'", date, m_id);
  1302. }
  1303. sql+=sql2;
  1304. g_sendhead.bsql=1;
  1305. g_pMainWnd->ProcessChatMessageRequest2(sql); //if(g_bSendOK==0)return;
  1306. ((TodayForm2*)(GetParent()->GetParent()))->ReLoad1();
  1307. }
  1308. else
  1309. {
  1310. CString name=GetText(oldrow, 1);
  1311. CString phone=GetText(oldrow, 2);
  1312. CString time=GetText(oldrow, 3);
  1313. CString type=GetText(oldrow, 4);
  1314. CString price=GetText(oldrow, 5);
  1315. CString waiter1=GetText(oldrow, 6);
  1316. CString waiter2=GetText(oldrow, 7);
  1317. CString receptionist=GetText(oldrow, 8);
  1318. CString arrearage=GetText(oldrow, 9);
  1319. CString remark=GetText(oldrow, 10);
  1320. CString clerk=GetText(oldrow, 11);
  1321. CString arrive=GetText(oldrow, 12);
  1322. CString timestamp=m_pListArray->ElementAt(row).ElementAt(13);
  1323. if(name.IsEmpty())return;
  1324. CString sql;
  1325. sql.Format ("update todaytake set [name]='%s',[phone]='%s',[time]='%s',[type]='%s',[price]='%s',[waiter1]='%s',\
  1326. [waiter2]='%s',[receptionist]='%s',[arrearage]='%s',[remark]='%s',[clerk]='%s',[arrive]='%s' where [timestamp]='%s'", \
  1327. name,phone,time,type,price,waiter1,waiter2,receptionist,arrearage,remark,clerk,arrive,timestamp);
  1328. g_sendhead.bsql=1;
  1329. g_pMainWnd->ProcessChatMessageRequest2(sql);
  1330. }
  1331. }
  1332. void XTable::Save2(int row)
  1333. {
  1334. if(IsHasRightsnew(2)==0)return;
  1335. if(::GetTickCount ()-m_nticks<1000)return;
  1336. m_nticks=::GetTickCount ();
  1337. int oldrow=row;
  1338. BOOL bFind=0;
  1339. for(int i=0; i<m_daterowposarray.GetSize (); i++)
  1340. {
  1341. if(row<m_daterowposarray.ElementAt (i))
  1342. {
  1343. row-=i;bFind=1;
  1344. break;
  1345. }
  1346. if(row==m_daterowposarray.ElementAt (i))
  1347. return;
  1348. }
  1349. if(bFind==0)row-=m_daterowposarray.GetSize ();
  1350. if(row>=m_pListArray->GetSize())//新预约
  1351. {
  1352. CString name=GetText(oldrow, 1);
  1353. CString phone=GetText(oldrow, 2);
  1354. CString time=GetText(oldrow, 3);
  1355. CString content=GetText(oldrow, 4);
  1356. CString type=GetText(oldrow, 5);
  1357. CString price=GetText(oldrow, 6);
  1358. CString waiter1=GetText(oldrow, 7);
  1359. CString waiter2=GetText(oldrow, 8);
  1360. CString receptionist=GetText(oldrow, 9);
  1361. CString arrearage=GetText(oldrow, 10);
  1362. CString remark=GetText(oldrow, 11);
  1363. CString clerk=GetText(oldrow, 12);
  1364. CString arrive=GetText(oldrow, 13);
  1365. CString timestamp=CTime::GetCurrentTime ().Format ("%Y%m%d%H%M%S");
  1366. CString date=((TodayForm2*)(GetParent()->GetParent()))->GetDate();
  1367. if(name.IsEmpty())return;
  1368. CString sql;
  1369. sql.Format ("insert into todaytake([name],[phone],[time],[type],[price],[waiter1],[waiter2],[receptionist],\
  1370. [arrearage],[remark],[clerk],[timestamp],[date],[mode],[content],[arrive],[id])values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%d','%s','%s','%s')", \
  1371. name,phone,time,type,price,waiter1,waiter2,receptionist,arrearage,remark,clerk,timestamp,date,m_mode,content,arrive,m_id);
  1372. g_sendhead.bsql=1;
  1373. g_pMainWnd->ProcessChatMessageRequest2(sql); //if(g_bSendOK==0)return;
  1374. ((TodayForm2*)(GetParent()->GetParent()))->ReLoad1();
  1375. }
  1376. else
  1377. {
  1378. CString name=GetText(oldrow, 1);
  1379. CString phone=GetText(oldrow, 2);
  1380. CString time=GetText(oldrow, 3);
  1381. CString content=GetText(oldrow, 4);
  1382. CString type=GetText(oldrow, 5);
  1383. CString price=GetText(oldrow, 6);
  1384. CString waiter1=GetText(oldrow, 7);
  1385. CString waiter2=GetText(oldrow, 8);
  1386. CString receptionist=GetText(oldrow, 9);
  1387. CString arrearage=GetText(oldrow, 10);
  1388. CString remark=GetText(oldrow, 11);
  1389. CString clerk=GetText(oldrow, 12);
  1390. CString arrive=GetText(oldrow, 13);
  1391. CString timestamp=m_pListArray->ElementAt(row).ElementAt(14);
  1392. if(name.IsEmpty())return;
  1393. CString sql;
  1394. sql.Format ("update todaytake set [name]='%s',[phone]='%s',[time]='%s',[type]='%s',[price]='%s',[waiter1]='%s',\
  1395. [waiter2]='%s',[receptionist]='%s',[arrearage]='%s',[remark]='%s',[clerk]='%s',[content]='%s',[arrive]='%s' where [timestamp]='%s'", \
  1396. name,phone,time,type,price,waiter1,waiter2,receptionist,arrearage,remark,clerk,content,arrive,timestamp);
  1397. g_sendhead.bsql=1;
  1398. g_pMainWnd->ProcessChatMessageRequest2(sql);
  1399. }
  1400. }
  1401. void XTable::DeleteCur()
  1402. {
  1403. int row=focusRow;
  1404. CString name=GetText(row, 1);
  1405. BOOL bFind=0;
  1406. for(int i=0; i<m_daterowposarray.GetSize (); i++)
  1407. {
  1408. if(row<m_daterowposarray.ElementAt (i))
  1409. {
  1410. row-=i;bFind=1;
  1411. break;
  1412. }
  1413. if(row==m_daterowposarray.ElementAt (i))
  1414. return;
  1415. }
  1416. if(bFind==0)row-=m_daterowposarray.GetSize ();
  1417. if(row>=m_pListArray->GetSize())
  1418. return;
  1419. if(AfxMessageBox("确定删除客人"+name+"的预约资料吗?", MB_YESNO|MB_ICONINFORMATION)!=IDYES)return;
  1420. int size=m_pListArray->ElementAt(row).GetSize ();
  1421. CString timestamp=m_pListArray->ElementAt(row).ElementAt(size-2);
  1422. CString sql;
  1423. sql.Format ("delete from todaytake where [timestamp]='%s'", timestamp);
  1424. g_sendhead.bsql=1;
  1425. g_pMainWnd->ProcessChatMessageRequest2(sql);
  1426. ((TodayForm2*)(GetParent()->GetParent()))->ReLoad1();
  1427. }
  1428. void XTable::OtherDate()
  1429. {
  1430. int row=focusRow;
  1431. CString name=GetText(row, 1);
  1432. BOOL bFind=0;
  1433. for(int i=0; i<m_daterowposarray.GetSize (); i++)
  1434. {
  1435. if(row<m_daterowposarray.ElementAt (i))
  1436. {
  1437. row-=i;bFind=1;
  1438. break;
  1439. }
  1440. if(row==m_daterowposarray.ElementAt (i))
  1441. return;
  1442. }
  1443. if(bFind==0)row-=m_daterowposarray.GetSize ();
  1444. if(row>=m_pListArray->GetSize())
  1445. return;
  1446. int size=m_pListArray->ElementAt(row).GetSize ();
  1447. CString date=m_pListArray->ElementAt(row).ElementAt(size-3);
  1448. CString timestamp=m_pListArray->ElementAt(row).ElementAt(size-2);
  1449. CString id=m_pListArray->ElementAt(row).ElementAt(size-1);
  1450. InputDate dlg;
  1451. dlg.m_date =date;
  1452. dlg.m_name =name;
  1453. dlg.m_name =m_pListArray->ElementAt(row).ElementAt(0);
  1454. if(dlg.DoModal ()!=IDOK)return;
  1455. CString sql,sql2;
  1456. sql.Format ("update todaytake set [date]='%s' where [timestamp]='%s'", dlg.m_date, timestamp);
  1457. g_sendhead.bsql=1;
  1458. if(m_mode==0)
  1459. {
  1460. sql2.Format ("***update dindan set [time2]='%s' where [id]='%s'", dlg.m_date, id);
  1461. }
  1462. else if(m_mode==1)
  1463. {
  1464. sql2.Format ("***update dindan set [time4]='%s' where [id]='%s'", dlg.m_date, id);
  1465. }
  1466. else if(m_mode==2)
  1467. {
  1468. sql2.Format ("***update dindan set [time6]='%s' where [id]='%s'", dlg.m_date, id);
  1469. }
  1470. else if(m_mode==3)
  1471. {
  1472. sql2.Format ("***update dindan set [time5]='%s' where [id]='%s'", dlg.m_date, id);
  1473. }
  1474. sql+=sql2;
  1475. g_pMainWnd->ProcessChatMessageRequest2(sql);
  1476. ((TodayForm2*)(GetParent()->GetParent()))->ReLoad1();
  1477. }
  1478. BOOL XTable::IsDateRow(int row)
  1479. {
  1480. try
  1481. {
  1482. for(int i=0; i<m_daterowposarray.GetSize (); i++)
  1483. {
  1484. if(row==m_daterowposarray.ElementAt (i))
  1485. return 1;
  1486. }
  1487. }
  1488. catch(...)
  1489. {
  1490. }
  1491. return 0;
  1492. }
  1493. CString XTable::GetWeek(CString date)
  1494. {
  1495. if(date.GetLength ()!=10)return "";
  1496. COleDateTime dtDay(atoi(date.Mid (0,4)),atoi(date.Mid (5,2)),atoi(date.Mid (8,2)), 0, 0, 0);
  1497. int nDayWeek = dtDay.GetDayOfWeek()-1; //得到星期几,1=Sunday, 2=Monday,
  1498. CString DayOfWeek[7]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
  1499. CString sdate;
  1500. if(nDayWeek>=0 && nDayWeek<=6)
  1501. sdate=DayOfWeek[nDayWeek];
  1502. else
  1503. sdate="无效日期";
  1504. return sdate;
  1505. }
  1506. int XTable::Test()
  1507. {
  1508. CStringArray array;
  1509. if(m_mode==4)
  1510. {
  1511. array.Add ("姓名");
  1512. array.Add ("电话");
  1513. array.Add ("时间");
  1514. array.Add ("婚庆内容");
  1515. array.Add ("类别");
  1516. array.Add ("价格");
  1517. array.Add ("摄影");
  1518. #ifdef CHILD_VERSION
  1519. array.Add ("引导");
  1520. #else
  1521. array.Add ("化妆");
  1522. #endif
  1523. array.Add ("门市");
  1524. array.Add ("欠款");
  1525. array.Add ("备注");
  1526. array.Add ("录入");
  1527. array.Add ("是否到店");
  1528. }
  1529. else
  1530. {
  1531. array.Add ("姓名");
  1532. array.Add ("电话");
  1533. array.Add ("时间");
  1534. array.Add ("类别");
  1535. array.Add ("价格");
  1536. array.Add ("摄影");
  1537. #ifdef CHILD_VERSION
  1538. array.Add ("引导");
  1539. #else
  1540. array.Add ("化妆");
  1541. #endif
  1542. array.Add ("门市");
  1543. array.Add ("欠款");
  1544. array.Add ("备注");
  1545. array.Add ("录入");
  1546. array.Add ("是否到店");
  1547. }
  1548. int cols=array.GetSize();
  1549. int nAdd=0;
  1550. if(m_mode==4)nAdd=1;
  1551. CRect rc;
  1552. GetClientRect(rc);
  1553. defaultWidth = (rc.Width()-10)/cols;
  1554. int halfwid=defaultWidth;
  1555. SetCols (1);
  1556. SetRows (256);
  1557. SetCols (cols+1);
  1558. for(int i=0; i<rows; i++)
  1559. {
  1560. for(int j=0; j<cols; j++)
  1561. {
  1562. SetText (i, j+1, "");
  1563. }
  1564. }
  1565. COLORREF col1=RGB(0xC8, 0x96, 0x96);
  1566. COLORREF col2=RGB(0x64,0x96,0xC8);
  1567. COLORREF yellow=RGB(255,255,0);
  1568. COLORREF green=RGB(0,255,255);
  1569. for ( i = 0; i < 46; i ++)
  1570. SetBackColor (i, 0, col1);
  1571. SetColWidth ( 0, 10);
  1572. m_datearray.RemoveAll ();
  1573. m_daterowposarray.RemoveAll ();
  1574. int datesize=0;
  1575. int aa=0;
  1576. CString curdate;
  1577. CStringArray typearray;
  1578. CArray<int,int>typecountarray;
  1579. int pos;
  1580. int oldpos;
  1581. for(i=0; i<m_pListArray->GetSize()+datesize; i++)
  1582. {
  1583. if(m_pListArray->ElementAt(aa).ElementAt(12+nAdd)!=curdate && curdate!="")
  1584. {
  1585. //汇总行
  1586. CString str=" 今日预约: ";
  1587. CString temp;
  1588. for(int a=0; a<typearray.GetSize (); a++)
  1589. {
  1590. temp.Format ("%s:%d ", typearray.ElementAt (a), typecountarray.ElementAt (a));
  1591. str+=temp;
  1592. }
  1593. SetText (oldpos, 1, GetText(oldpos, 1)+str );
  1594. typearray.RemoveAll (); typecountarray.RemoveAll ();
  1595. }
  1596. if(::FindArray (&m_datearray, m_pListArray->ElementAt(aa).ElementAt(12+nAdd))==-1)
  1597. {
  1598. curdate=m_pListArray->ElementAt(aa).ElementAt(12+nAdd);
  1599. m_datearray.Add ( curdate );
  1600. m_daterowposarray.Add (i);
  1601. datesize=m_datearray.GetSize ();
  1602. JoinCells (i,1,i,12+nAdd);
  1603. SetAlignment (i,1,DT_CENTER);
  1604. SetBackColor (i,1, green);
  1605. SetText (i, 1, curdate+" "+GetWeek(curdate) );
  1606. oldpos=i;
  1607. continue;
  1608. }
  1609. pos=::FindArray (&typearray, m_pListArray->ElementAt(aa).ElementAt(3+nAdd));
  1610. if(pos==-1)
  1611. {
  1612. typearray.Add (m_pListArray->ElementAt(aa).ElementAt(3+nAdd));
  1613. typecountarray.Add (1);
  1614. }
  1615. else
  1616. {
  1617. int size=typecountarray.ElementAt (pos);
  1618. typecountarray.SetAt (pos, size+1);
  1619. }
  1620. for(int j=0; j<cols; j++)
  1621. {
  1622. SetText (i, j+1, m_pListArray->ElementAt(aa).ElementAt(j));
  1623. if(j==8+nAdd && atoi(m_pListArray->ElementAt(aa).ElementAt(j))>0 )
  1624. {
  1625. SetBackColor (i,j+1, RGB(255,0,0));
  1626. }
  1627. else if(j==8+nAdd)SetBackColor (i,j+1, RGB(0,255,0));
  1628. if(j==11+nAdd && m_pListArray->ElementAt(aa).ElementAt(j)=="未到" )
  1629. {
  1630. SetBackColor (i,j+1, RGB(255,0,0));
  1631. }
  1632. else if(j==11+nAdd)SetBackColor (i,j+1, RGB(0,255,0));
  1633. }
  1634. aa++;
  1635. }
  1636. if(m_pListArray->GetSize())
  1637. {
  1638. //汇总行
  1639. CString str=" 今日预约: ";
  1640. CString temp;
  1641. for(int a=0; a<typearray.GetSize (); a++)
  1642. {
  1643. temp.Format ("%s:%d ", typearray.ElementAt (a), typecountarray.ElementAt (a));
  1644. str+=temp;
  1645. }
  1646. SetText (oldpos, 1, GetText(oldpos, 1)+str );
  1647. }
  1648. CalRowHeight();
  1649. return 0;
  1650. JoinCells (3,5,4,6);
  1651. SetText (3,5, "This cell contains multiline text, which provides multiline edit.张三, 李四, 王五Using default font张三, 李四, 王五Using default font");
  1652. SetWordbreak (3,5,true);
  1653. return 0;
  1654. JoinCells (3,7,5,8);
  1655. SetText (3,7, "This cell contains multiline text, which provides multiline edit.");
  1656. SetWordbreak (3,7,true);
  1657. SetText (4,1, "You can even edit a long (cell overlapping) string.");
  1658. SetOverlap(4,1,true);
  1659. SetText (4,3, "Test");
  1660. JoinCells (5,1,6,2);
  1661. SetText (5,1, "Enter your name here.");
  1662. JoinCells (5,3,5,4);
  1663. SetText (5,3, "Enter your text here ...");
  1664. JoinCells (8,1,8,8);
  1665. SetBackColor (8,1, RGB(0x64,0x96,0xC8));
  1666. SetText (8,1, "Default edit controls also allow us to customize user's editing experience by:");
  1667. JoinCells (10,1,10,2);
  1668. SetBackColor (10,1, RGB(0xDC,0xC8,0xB4));
  1669. SetText (10,1, "Converting input to upper case:");
  1670. SetText (10,3, "TYPE HERE ...");
  1671. JoinCells (10,5,10,6);
  1672. SetBackColor (10,5, RGB(0xDC,0xC8,0xB4));
  1673. SetText (10,5, "Converting input to lower case:");
  1674. SetText (10,7, "type here ...");
  1675. JoinCells (11,1,11,2);
  1676. SetBackColor (11,1, RGB(0xDC,0xC8,0xB4));
  1677. SetText (11,1, "Allowing password input:");
  1678. SetText (11,3, "*********");
  1679. SetText (11,5, "Entered password was:*********");
  1680. SetOverlap(11,5,true);
  1681. JoinCells (12,1,12,2);
  1682. SetBackColor (12,1, RGB(0xDC,0xC8,0xB4));
  1683. SetText (12,1, "Allowing aligned input:");
  1684. SetText (12,3, "Left aligned");
  1685. SetText (12,5, "Centered");
  1686. SetAlignment (12,5,DT_CENTER);
  1687. SetText (12,7, "Right aligned");
  1688. SetAlignment (12,7,DT_RIGHT);
  1689. JoinCells (14,1,14,8);
  1690. SetBackColor (14,1, RGB(0x64,0x96,0xC8));
  1691. SetText (14,1, "Ultimate Grid allow us to process user's input with various notifications.");
  1692. JoinCells (16,1,16,5);
  1693. SetBackColor (16,1, RGB(0xDC,0xC8,0xB4));
  1694. SetText (16,1, "We can verify data it is entered, for example to limit number of char to 4:");
  1695. SetText (16,6, "<Type here>");
  1696. JoinCells (17,1,17,5);
  1697. SetBackColor (17,1, RGB(0xDC,0xC8,0xB4));
  1698. SetText (17,1, "or that the numeric value entered is under 500 (number < 500):");
  1699. SetText (17,6, "<Type here>");
  1700. JoinCells (18,1,18,5);
  1701. SetBackColor (18,1, RGB(0xDC,0xC8,0xB4));
  1702. SetText (18,1, "We can also test user's input after it is completed, or force user's input:");
  1703. SetText (18,6, "<Type here>");
  1704. JoinCells (20,1,20,8);
  1705. SetBackColor (20,1, RGB(0x64,0x96,0xC8));
  1706. SetText (20,1, "The Ultimate Grid also allows us to use other edit controls when needed:");
  1707. JoinCells (22,1,23,5);
  1708. SetBackColor (22,1, RGB(0xDC,0xC8,0xB4));
  1709. SetText (22,1, "Just by setting a mask on a cell, the grid will change edit controls to use a mask edit. By default Ultimate Grid creates an instance of CUGMEdit to use as mask edit control.");
  1710. SetWordbreak (22,1,true);
  1711. JoinCells (22,6,22,7);
  1712. SetText (22,6, "<Select mask>");
  1713. JoinCells (23,6,23,7);
  1714. SetText (23,6, "<Type here>");
  1715. JoinCells (25,1,27,5);
  1716. SetBackColor (25,1, RGB(0xDC,0xC8,0xB4));
  1717. SetText (25,1, "The Ultimate Grid 5 also comes with a set of advanced edit control previosly only found in Ultimate ToolBox. We can now easily incorporate powerful controls like COXMaskEdit, COXNumericEdit, and COXCurrencyEdit into our applications.");
  1718. SetWordbreak (25,1,true);
  1719. JoinCells (29,1,30,5);
  1720. SetBackColor (29,1, RGB(0xDC,0xC8,0xB4));
  1721. SetText (29,1, "The COXMaskEdit works very similarly to the default mask edit control, to use it just set a mask on a cell and inform the grid that you want to use different edit control.");
  1722. SetWordbreak (29,1,true);
  1723. JoinCells (29,6,29,8);
  1724. SetText (29,6, "<Select mask>");
  1725. JoinCells (30,6,30,8);
  1726. SetText (30,6, "<Type here>");
  1727. JoinCells (32,1,33,5);
  1728. SetBackColor (32,1, RGB(0xDC,0xC8,0xB4));
  1729. SetText (32,1, "The COXNumericEdit and COXCurrencyEdit on the other hand allow us to provide additional setup information that will drive the way the edit control will behave.");
  1730. SetWordbreak (32,1,true);
  1731. JoinCells (35,1,35,2);
  1732. SetBackColor (35,1, RGB(0xDC,0xC8,0xB4));
  1733. SetText (35,1, "Using COXNumericEdit:");
  1734. JoinCells (35,3,35,4);
  1735. SetText (35,3, "<Type here>");
  1736. JoinCells (35,5,35,6);
  1737. SetBackColor (35,5, RGB(0xDC,0xC8,0xB4));
  1738. SetText (35,5, "Using COXCurrencyEdit:");
  1739. JoinCells (35,7,35,8);
  1740. SetText (35,7, "<Type here>");
  1741. JoinCells (36,1,36,3);
  1742. SetBackColor (36,1, RGB(0x64,0x96,0xC8));
  1743. SetText (36,1, "Following are properties we can set.");
  1744. JoinCells (36,5,36,7);
  1745. SetBackColor (36,5, RGB(0x64,0x96,0xC8));
  1746. SetText (36,5, "Following are properties we can set.");
  1747. JoinCells (37,1,37,2);
  1748. SetBackColor (37,1, RGB(0xDC,0xC8,0xB4));
  1749. SetText (37,1, "Decimal digit count :");
  1750. JoinCells (37,5,37,6);
  1751. SetBackColor (37,5, RGB(0xDC,0xC8,0xB4));
  1752. SetText (37,5, "Decimal digit count :");
  1753. JoinCells (38,1,38,2);
  1754. SetBackColor (38,1, RGB(0xDC,0xC8,0xB4));
  1755. SetText (38,1, "Decimal Separator :");
  1756. JoinCells (38,5,38,6);
  1757. SetBackColor (38,5, RGB(0xDC,0xC8,0xB4));
  1758. SetText (38,5, "Decimal Separator :");
  1759. JoinCells (39,1,39,2);
  1760. SetBackColor (39,1, RGB(0xDC,0xC8,0xB4));
  1761. SetText (39,1, "Fractional digit count :");
  1762. JoinCells (39,5,39,6);
  1763. SetBackColor (39,5, RGB(0xDC,0xC8,0xB4));
  1764. SetText (39,5, "Fractional digit count :");
  1765. JoinCells (40,1,40,2);
  1766. SetBackColor (40,1, RGB(0xDC,0xC8,0xB4));
  1767. SetText (40,1, "Group Separator :");
  1768. JoinCells (40,5,40,6);
  1769. SetBackColor (40,5, RGB(0xDC,0xC8,0xB4));
  1770. SetText (40,5, "Group Separator :");
  1771. JoinCells (41,1,41,2);
  1772. SetBackColor (41,1, RGB(0xDC,0xC8,0xB4));
  1773. SetText (41,1, "Digits in group :");
  1774. JoinCells (41,5,41,6);
  1775. SetBackColor (41,5, RGB(0xDC,0xC8,0xB4));
  1776. SetText (41,5, "Digits in group :");
  1777. JoinCells (42,1,42,2);
  1778. SetBackColor (42,1, RGB(0xDC,0xC8,0xB4));
  1779. SetText (42,1, "Negative Format :");
  1780. JoinCells (42,5,42,6);
  1781. SetBackColor (42,5, RGB(0xDC,0xC8,0xB4));
  1782. SetText (42,5, "Positive Format :");
  1783. JoinCells (43,1,43,2);
  1784. SetBackColor (43,1, RGB(0xDC,0xC8,0xB4));
  1785. SetText (43,1, "Show leading zero :");
  1786. JoinCells (43,5,43,6);
  1787. SetBackColor (43,5, RGB(0xDC,0xC8,0xB4));
  1788. SetText (43,5, "Negative Format :");
  1789. JoinCells (44,5,44,6);
  1790. SetBackColor (44,5, RGB(0xDC,0xC8,0xB4));
  1791. SetText (44,5, "Currency name :");
  1792. JoinCells (45,5,45,6);
  1793. SetBackColor (45,5, RGB(0xDC,0xC8,0xB4));
  1794. SetText (45,5, "Show leading zero :");
  1795. return 0;
  1796. }
  1797. void XTable::ModeChange(int mode)
  1798. {
  1799. m_mode=mode;
  1800. }
  1801. void XTable::AddName(int row, int col, CString str)
  1802. {
  1803. CString oldtext=GetText(row,col);
  1804. if(oldtext.IsEmpty ())
  1805. {
  1806. SetText(row,col, str);
  1807. return;
  1808. }
  1809. if(oldtext.Find (str)!=-1)return;
  1810. SetText(row,col, oldtext+","+str);
  1811. }
  1812. //化妆师