UPhoneBoxDlg.cpp 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287
  1. // UPhoneBoxDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "UPhoneBox.h"
  5. #include "UPhoneBoxDlg.h"
  6. #include "setbusytonedlg.h"
  7. #include "SetVolumeDlg.h"
  8. #include <afxtempl.h>
  9. #include "Lzari.h"
  10. #include "NotFindDlg.h"
  11. #include "outsourcingDlg.h"
  12. #include "MyLock.h"
  13. #include "WorkerDlg.h"
  14. #include "Client2Dlg.h"
  15. #include <tlhelp32.h>
  16. #include "Booking.h"
  17. #include "AddOldClient.h"
  18. #include "AddOldClient2.h"
  19. #include "PhoneComing.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. extern CString g_ip;
  26. #define NEW_DEVICE 18666
  27. //#define TEST_WINDOW 1
  28. BOOL g_bok = 0;
  29. CArray<CStringArray, CStringArray>g_cominfoarray;
  30. BOOL g_bAutoRun = 0;
  31. #define WM_ICON_NOTIFY WM_USER+12
  32. CString g_recordpath[10];
  33. CUPhoneBoxDlg *g_pMainWnd = NULL;
  34. #define RECOED_DIR "recorder-dir\\"
  35. CUPhoneBoxDlg *pusb = NULL;
  36. extern CFont g_listctrlfont;
  37. BOOL g_bCallOut[10] = { 1 };
  38. HWND g_hwnd[10] = { NULL };
  39. CArray<int, int>yearposarray[10];
  40. CStringArray idarray[10];
  41. CString g_phone[10];
  42. BOOL g_bChildVersion = 0;
  43. BOOL g_bNewBooking = 0;
  44. #define WNDNUM 100
  45. Booking g_dlgbooking[WNDNUM];
  46. outsourcingDlg g_dlgoutsourcing[WNDNUM];
  47. NotFindDlg g_dlgnotfind[WNDNUM];
  48. Client2Dlg g_dlgclient2[WNDNUM];
  49. WorkerDlg g_dlgWorkerDlg[WNDNUM];
  50. AddOldClient g_dlgOldClient[WNDNUM];
  51. AddOldClient2 g_dlgOldClient2[WNDNUM];
  52. PhoneComing g_dlgphonecoming[2];
  53. typedef struct
  54. {
  55. int idpos;
  56. char phone[30];
  57. char str1[100];
  58. char str2[100];
  59. char str3[100];
  60. char str4[100];
  61. char str5[500];
  62. }CLIENTINFO;
  63. DWORD g_tick = 0;
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CAboutDlg dialog used for App About IDM_CLOSE
  66. CArray<CStringArray, CStringArray>g_arraydata[10][10];//年,代码
  67. #pragma comment(lib,"phonic_ubox.lib")
  68. int g_nYearpos = -1;
  69. BOOL g_bReturned2 = 0;
  70. #define DISCONNECT_TIMER (WM_USER + 101)
  71. #define LOGINFAILED_TIMER (WM_USER + 102)
  72. void DeleteSubFiles(CString strDir)
  73. {
  74. try
  75. {
  76. strDir.TrimRight("\\");
  77. CFileFind tempFind;
  78. CString tempFileFind;
  79. tempFileFind.Format("%s\\*.*", strDir);
  80. BOOL IsFinded = (BOOL)tempFind.FindFile(tempFileFind);
  81. while (IsFinded)
  82. {
  83. IsFinded = (BOOL)tempFind.FindNextFile();
  84. if (!tempFind.IsDots())
  85. {
  86. if (!tempFind.IsDirectory())
  87. {
  88. CString foundFileName;
  89. foundFileName.Format("%s", tempFind.GetFileName());
  90. CString tempFileName;
  91. tempFileName.Format("%s\\%s", strDir, foundFileName);
  92. DeleteFile(tempFileName);
  93. }
  94. }
  95. }
  96. tempFind.Close();
  97. }
  98. catch (...)
  99. {
  100. }
  101. }
  102. /////////////////////////////////////////////////////////////////////////////
  103. static void HandleClientNetEvent2(IN SOCKET hSocket, IN ETransportEvent eEvent,
  104. IN void *pDataBuf, IN unsigned long nDataLen,
  105. IN int nError, IN void *pContext)
  106. {
  107. if (nError != TRANSPORT_OK) return;
  108. CUPhoneBoxDlg *pDlg = (CUPhoneBoxDlg *)pContext;
  109. if (NULL == pDlg) return;
  110. pDlg->ProcessNetEvent(eEvent, pDataBuf, nDataLen);
  111. }
  112. void CALLBACK ProcPhonicCallBack(
  113. UBOX_HANDLE uboxHnd //设备句柄
  114. , int eventID //事件,参考UBOX_EVENT的定义
  115. , unsigned long param1 //下面几个参数不同的事件,其含义不同
  116. , unsigned long param2
  117. , unsigned long param3
  118. , unsigned long param4
  119. );
  120. class CAboutDlg : public CDialog
  121. {
  122. public:
  123. CAboutDlg();
  124. // Dialog Data
  125. //{{AFX_DATA(CAboutDlg)
  126. enum {
  127. IDD = IDD_ABOUTBOX
  128. };
  129. //}}AFX_DATA
  130. // ClassWizard generated virtual function overrides
  131. //{{AFX_VIRTUAL(CAboutDlg)
  132. protected:
  133. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  134. //}}AFX_VIRTUAL
  135. // Implementation
  136. protected:
  137. //{{AFX_MSG(CAboutDlg)
  138. //}}AFX_MSG
  139. DECLARE_MESSAGE_MAP()
  140. };
  141. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  142. {
  143. //{{AFX_DATA_INIT(CAboutDlg)
  144. //}}AFX_DATA_INIT
  145. }
  146. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  147. {
  148. CDialog::DoDataExchange(pDX);
  149. //{{AFX_DATA_MAP(CAboutDlg)
  150. //}}AFX_DATA_MAP
  151. }
  152. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  153. //{{AFX_MSG_MAP(CAboutDlg)
  154. // No message handlers
  155. //}}AFX_MSG_MAP
  156. END_MESSAGE_MAP()
  157. /////////////////////////////////////////////////////////////////////////////
  158. // CUPhoneBoxDlg dialog
  159. CUBoxLine* CUPhoneBoxDlg::get_line_by_ID(size_t lineID_)
  160. {
  161. CUBoxLine* pLine = NULL;
  162. for (size_t lineID = 0; lineID < MAX_DEVICE; lineID++)
  163. {
  164. if (ubox_device[lineID].line_id() == lineID_)
  165. {
  166. pLine = static_cast<CUBoxLine*>(&ubox_device[lineID]);
  167. break;
  168. }
  169. }
  170. return pLine;
  171. }
  172. CUBoxLine* CUPhoneBoxDlg::get_line_by_handle(UBOX_HANDLE handle)
  173. {
  174. CUBoxLine* pLine = NULL;
  175. for (size_t lineID = 0; lineID < MAX_DEVICE; lineID++)
  176. {
  177. if (ubox_device[lineID].line_handel() == handle)
  178. {
  179. pLine = static_cast<CUBoxLine*>(&ubox_device[lineID]);
  180. break;
  181. }
  182. }
  183. return pLine;
  184. }
  185. CUPhoneBoxDlg::CUPhoneBoxDlg(CWnd* pParent /*=NULL*/)
  186. : CDialog(CUPhoneBoxDlg::IDD, pParent)
  187. {
  188. //{{AFX_DATA_INIT(CUPhoneBoxDlg)
  189. //}}AFX_DATA_INIT
  190. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  191. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  192. m_hIcon2 = AfxGetApp()->LoadIcon(IDI_ICON1);
  193. g_listctrlfont.CreatePointFont(110, _T("System"));
  194. CString version = _T("Version 1.0");
  195. g_bAutoRun = AfxGetApp()->GetProfileInt(version, "brun", 0);
  196. }
  197. void CUPhoneBoxDlg::DoDataExchange(CDataExchange* pDX)
  198. {
  199. CDialog::DoDataExchange(pDX);
  200. //{{AFX_DATA_MAP(CUPhoneBoxDlg)
  201. DDX_Control(pDX, IDC_DISSTATE, m_list);
  202. DDX_Control(pDX, IDC_DISINFOR, m_dis);
  203. //}}AFX_DATA_MAP
  204. }
  205. BEGIN_MESSAGE_MAP(CUPhoneBoxDlg, CDialog)
  206. //{{AFX_MSG_MAP(CUPhoneBoxDlg)
  207. ON_WM_SYSCOMMAND()
  208. ON_WM_PAINT()
  209. ON_WM_QUERYDRAGICON()
  210. ON_COMMAND(IDM_CLOSEAGC, OnCloseagc)
  211. ON_COMMAND(IDM_DIALPHONENUM, OnDialphonenum)
  212. ON_COMMAND(IDM_GETHANGTHRESHOLD, OnGethangthreshold)
  213. ON_COMMAND(IDM_GETHARDWAREVERSION, OnGethardwareversion)
  214. ON_COMMAND(IDM_GETPRODUCTNAME, OnGetproductname)
  215. ON_COMMAND(IDM_GETUSERNUM, OnGetusernum)
  216. ON_COMMAND(IDM_OPENBUZZER, OnOpenbuzzer)
  217. ON_COMMAND(IDM_OPENCONFIGUREMODE, OnOpenconfiguremode)
  218. ON_COMMAND(IDM_OPENMSGSWITCH, OnOpenmsgswitch)
  219. ON_COMMAND(IDM_PAUSEPLAY, OnPauseplay)
  220. ON_COMMAND(IDM_PLAYFILE, OnPlayfile)
  221. ON_COMMAND(IDM_READEEPROM, OnReadeeprom)
  222. ON_COMMAND(IDM_READEEPROMEX, OnReadeepromex)
  223. ON_COMMAND(IDM_READLINEVOLTAGE, OnReadlinevoltage)
  224. ON_COMMAND(IDM_RECORDFILE, OnRecordfile)
  225. ON_COMMAND(IDM_RECORDSTREAM, OnRecordstream)
  226. ON_COMMAND(IDM_SETHANGTHRESHOLD, OnSethangthreshold)
  227. ON_COMMAND(IDM_SETHOOKOFFTHRESHOLD, OnSethookoffthreshold)
  228. ON_COMMAND(IDM_SOFTHANGUP, OnSofthangup)
  229. ON_COMMAND(IDM_SOFTHOOKOFF, OnSofthookoff)
  230. ON_COMMAND(IDM_STOPPLAY, OnStopplay)
  231. ON_COMMAND(IDM_STOPREADLINEVOLTAGE, OnStopreadlinevoltage)
  232. ON_COMMAND(IDM_STOPRECORD, OnStoprecord)
  233. ON_COMMAND(IDM_WRITEEEPROM, OnWriteeeprom)
  234. ON_COMMAND(IDM_SETBUSYTONE, OnSetBusyTone)
  235. ON_COMMAND(IMD_GETHOOKOFFTHRESHOLD, OnGethookoffthreshold)
  236. ON_NOTIFY(NM_DBLCLK, IDC_DISSTATE, OnDblclkOpt)
  237. ON_WM_DESTROY()
  238. ON_COMMAND(IDM_RESTART, OnRestart)
  239. ON_COMMAND(IDM_SET_VOLUME, OnSetVolume)
  240. ON_WM_TIMER()
  241. ON_COMMAND(IDM_CLOSE, OnClose)
  242. ON_COMMAND(IDM_AUTORUN, OnAutorun)
  243. //}}AFX_MSG_MAP
  244. ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
  245. ON_MESSAGE(WM_USER + 200, OnNewClient)
  246. END_MESSAGE_MAP()
  247. /////////////////////////////////////////////////////////////////////////////
  248. // CUPhoneBoxDlg message handlers
  249. int GetDlgPos(int type)
  250. {
  251. if (type == 0)
  252. {
  253. for (int i = 0; i < WNDNUM; i++)
  254. {
  255. if (g_dlgbooking[i].GetSafeHwnd() == NULL)return i;
  256. }
  257. return -1;
  258. }
  259. else if (type == 1)
  260. {
  261. for (int i = 0; i < WNDNUM; i++)
  262. {
  263. if (g_dlgoutsourcing[i].GetSafeHwnd() == NULL)return i;
  264. }
  265. return -1;
  266. }
  267. else if (type == 2)
  268. {
  269. for (int i = 0; i < WNDNUM; i++)
  270. {
  271. if (g_dlgnotfind[i].GetSafeHwnd() == NULL)return i;
  272. }
  273. return -1;
  274. }
  275. else if (type == 3)
  276. {
  277. for (int i = 0; i < WNDNUM; i++)
  278. {
  279. if (g_dlgclient2[i].GetSafeHwnd() == NULL)return i;
  280. }
  281. return -1;
  282. }
  283. else if (type == 4)
  284. {
  285. for (int i = 0; i < WNDNUM; i++)
  286. {
  287. if (g_dlgWorkerDlg[i].GetSafeHwnd() == NULL)return i;
  288. }
  289. return -1;
  290. }
  291. else if (type == 5)
  292. {
  293. if (g_bChildVersion)
  294. {
  295. for (int i = 0; i < WNDNUM; i++)
  296. {
  297. if (g_dlgOldClient2[i].GetSafeHwnd() == NULL)return i;
  298. }
  299. }
  300. else
  301. {
  302. for (int i = 0; i < WNDNUM; i++)
  303. {
  304. if (g_dlgOldClient[i].GetSafeHwnd() == NULL)return i;
  305. }
  306. }
  307. return -1;
  308. }
  309. }
  310. LRESULT CUPhoneBoxDlg::OnTrayNotification(WPARAM wParam, LPARAM lParam)
  311. {
  312. return m_TrayIcon.OnTrayNotification(wParam, lParam);
  313. }
  314. LRESULT CUPhoneBoxDlg::OnNewClient(WPARAM wParam, LPARAM lParam)
  315. {
  316. CLIENTINFO *pClientInfo = (CLIENTINFO*)wParam;
  317. g_dlgphonecoming[pClientInfo->idpos].CheckTimer(); // 来电对话框;
  318. if (lParam == 0) // 订单顾客详情;
  319. {
  320. int pos = GetDlgPos(1);
  321. if (pos == -1)
  322. {
  323. delete pClientInfo;
  324. return 0;
  325. }
  326. g_dlgoutsourcing[pos].m_linepos = pClientInfo->idpos;
  327. g_dlgoutsourcing[pos].m_phone = pClientInfo->phone;
  328. delete pClientInfo;
  329. g_dlgoutsourcing[pos].Create(IDD_DLGoutsourcingdlg, g_pMainWnd);
  330. g_dlgoutsourcing[pos].ShowWindow(1);
  331. }
  332. else if (lParam == 1) // 未知来电;
  333. {
  334. int pos = GetDlgPos(2);
  335. if (pos == -1)
  336. {
  337. delete pClientInfo;
  338. return 0;
  339. }
  340. g_dlgnotfind[pos].m_linepos = pClientInfo->idpos;
  341. g_dlgnotfind[pos].m_phone = pClientInfo->phone;
  342. delete pClientInfo;
  343. g_dlgnotfind[pos].Create(IDD_DLGNotFind, g_pMainWnd);
  344. g_dlgnotfind[pos].ShowWindow(1);
  345. }
  346. else if (lParam == 2) // 意向客户;
  347. {
  348. int pos = GetDlgPos(3);
  349. if (pos == -1)
  350. {
  351. delete pClientInfo;
  352. return 0;
  353. }
  354. g_dlgclient2[pos].m_linepos = pClientInfo->idpos;
  355. g_dlgclient2[pos].m_phone = pClientInfo->phone;
  356. g_dlgclient2[pos].m_name = pClientInfo->str1;
  357. g_dlgclient2[pos].m_sex = pClientInfo->str2;
  358. g_dlgclient2[pos].m_addr = pClientInfo->str3;
  359. g_dlgclient2[pos].m_qq = pClientInfo->str4;
  360. g_dlgclient2[pos].m_bz = pClientInfo->str5;
  361. delete pClientInfo;
  362. g_dlgclient2[pos].Create(IDD_DLGClient2, g_pMainWnd);
  363. g_dlgclient2[pos].ShowWindow(1);
  364. }
  365. else if (lParam == 3) // 员工电话;
  366. {
  367. int pos = GetDlgPos(4);
  368. if (pos == -1)
  369. {
  370. delete pClientInfo;
  371. return 0;
  372. }
  373. g_dlgWorkerDlg[pos].m_linepos = pClientInfo->idpos;
  374. g_dlgWorkerDlg[pos].m_phone = pClientInfo->phone;
  375. g_dlgWorkerDlg[pos].m_name = pClientInfo->str1;
  376. g_dlgWorkerDlg[pos].m_sex = pClientInfo->str2;
  377. g_dlgWorkerDlg[pos].m_bm = pClientInfo->str3;
  378. delete pClientInfo;
  379. g_dlgWorkerDlg[pos].Create(IDD_DLGWorker, g_pMainWnd);
  380. g_dlgWorkerDlg[pos].ShowWindow(1);
  381. }
  382. else if (lParam == 4) // 添加儿童或婚纱顾客信息;
  383. {
  384. int pos = GetDlgPos(5);
  385. if (pos == -1)
  386. {
  387. delete pClientInfo;
  388. return 0;
  389. }
  390. if (g_bChildVersion) // 儿童版本;
  391. {
  392. g_dlgOldClient2[pos].m_linepos = pClientInfo->idpos;
  393. g_dlgOldClient2[pos].m_phone = pClientInfo->phone;
  394. delete pClientInfo;
  395. g_dlgOldClient2[pos].Create(IDD_DLGAddOldClient2, g_pMainWnd);
  396. g_dlgOldClient2[pos].ShowWindow(1);
  397. }
  398. else // 婚纱版本;
  399. {
  400. g_dlgOldClient[pos].m_linepos = pClientInfo->idpos;
  401. g_dlgOldClient[pos].m_phone = pClientInfo->phone;
  402. delete pClientInfo;
  403. g_dlgOldClient[pos].Create(IDD_DLGAddOldClient, g_pMainWnd);
  404. g_dlgOldClient[pos].ShowWindow(1);
  405. }
  406. }
  407. }
  408. BOOL CUPhoneBoxDlg::OnInitDialog()
  409. {
  410. SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_HIDEWINDOW);
  411. ModifyStyleEx(WS_EX_APPWINDOW, WS_EX_TOOLWINDOW);
  412. CDialog::OnInitDialog();
  413. g_tick = ::GetTickCount();
  414. g_pMainWnd = this;
  415. g_dlgphonecoming[0].Create(IDD_DLGPhoneComing, g_pMainWnd);
  416. g_dlgphonecoming[1].Create(IDD_DLGPhoneComing, g_pMainWnd);
  417. // Add "About..." menu item to system menu.
  418. // IDM_ABOUTBOX must be in the system command range.
  419. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  420. ASSERT(IDM_ABOUTBOX < 0xF000);
  421. CMenu* pSysMenu = GetSystemMenu(FALSE);
  422. if (pSysMenu != NULL)
  423. {
  424. CString strAboutMenu;
  425. strAboutMenu.LoadString(IDS_ABOUTBOX);
  426. if (!strAboutMenu.IsEmpty())
  427. {
  428. pSysMenu->AppendMenu(MF_SEPARATOR);
  429. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  430. }
  431. }
  432. // Set the icon for this dialog. The framework does this automatically
  433. // when the application's main window is not a dialog
  434. SetIcon(m_hIcon, TRUE); // Set big icon
  435. SetIcon(m_hIcon, FALSE); // Set small icon
  436. // TODO: Add extra initialization here
  437. m_font.CreateFont(16, 0, 0, 0, FW_NORMAL, 0, 0, 0,
  438. DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
  439. DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial");
  440. m_list.SetFont(&m_font);
  441. /*-----------------------------------------------------------*/
  442. m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
  443. m_list.SetBkColor(RGB(247, 247, 255));
  444. m_list.SetTextColor(RGB(0, 0, 255));
  445. m_list.SetTextBkColor(RGB(247, 247, 255));
  446. m_list.InsertColumn(0, "LineID", LVCFMT_LEFT, 60);
  447. m_list.InsertColumn(1, "productname", LVCFMT_LEFT, 120);
  448. m_list.InsertColumn(2, "State", LVCFMT_LEFT, 100);
  449. m_list.InsertColumn(3, "Key", LVCFMT_LEFT, 120);
  450. m_list.InsertColumn(4, "CallerNum", LVCFMT_LEFT, 120);
  451. m_list.InsertColumn(5, "other", LVCFMT_LEFT, 120);
  452. WriteLogin("打开来电精灵!");
  453. ubox_open_logfile(0);
  454. ((CButton *)GetDlgItem(IDC_AUDORECORD))->SetCheck(TRUE);
  455. if (ubox_open(::ProcPhonicCallBack, UBOX_WORK_MODE(0)))
  456. {
  457. WriteLogin(" 打开来电精灵失败! ");
  458. m_dis.InsertString(m_dis.GetCount(), "open device error");
  459. m_dis.SetCurSel(m_dis.GetCount() - 1);
  460. }
  461. pusb = this;
  462. char s_szName[MAX_PATH];
  463. ::GetModuleFileName(NULL, s_szName, MAX_PATH);
  464. strPath = s_szName;
  465. size_t dotPos = strPath.ReverseFind('\\');
  466. if (dotPos != -1)
  467. {
  468. strPath.Delete(dotPos, strPath.GetLength() - dotPos);
  469. }
  470. DeleteSubFiles(strPath + "\\" + RECOED_DIR);
  471. SetTimer(1, 10, NULL); // 10ms间隔执行;
  472. RefreshData();
  473. SetTimer(5, 30 * 60 * 1000, NULL); // 30分钟间隔执行;
  474. return TRUE;
  475. }
  476. void CUPhoneBoxDlg::OnSysCommand(UINT nID, LPARAM lParam)
  477. {
  478. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  479. {
  480. CAboutDlg dlgAbout;
  481. dlgAbout.DoModal();
  482. }
  483. else
  484. {
  485. CDialog::OnSysCommand(nID, lParam);
  486. }
  487. }
  488. // If you add a minimize button to your dialog, you will need the code below
  489. // to draw the icon. For MFC applications using the document/view model,
  490. // this is automatically done for you by the framework.
  491. void CUPhoneBoxDlg::OnPaint()
  492. {
  493. if (IsIconic())
  494. {
  495. CPaintDC dc(this); // device context for painting
  496. SendMessage(WM_ICONERASEBKGND, (WPARAM)dc.GetSafeHdc(), 0);
  497. // Center icon in client rectangle
  498. int cxIcon = GetSystemMetrics(SM_CXICON);
  499. int cyIcon = GetSystemMetrics(SM_CYICON);
  500. CRect rect;
  501. GetClientRect(&rect);
  502. int x = (rect.Width() - cxIcon + 1) / 2;
  503. int y = (rect.Height() - cyIcon + 1) / 2;
  504. // Draw the icon
  505. dc.DrawIcon(x, y, m_hIcon);
  506. }
  507. else
  508. {
  509. CDialog::OnPaint();
  510. }
  511. }
  512. // The system calls this to obtain the cursor to display while the user drags
  513. // the minimized window.
  514. HCURSOR CUPhoneBoxDlg::OnQueryDragIcon()
  515. {
  516. return (HCURSOR)m_hIcon;
  517. }
  518. void CUPhoneBoxDlg::OnCloseagc()
  519. {
  520. // TODO: Add your command handler code here
  521. CUBoxLine* pLine = NULL;
  522. pLine = get_line_by_ID(m_iClickItemID);
  523. if (pLine)
  524. {
  525. UBOX_HANDLE hdl = pLine->line_handel();
  526. if (pLine->get_agc())
  527. {
  528. pLine->set_agc(false);
  529. ubox_close_agc(hdl, false); //open agc
  530. }
  531. else
  532. {
  533. pLine->set_agc(true);
  534. ubox_close_agc(hdl, true); //close agc
  535. }
  536. }
  537. }
  538. void CUPhoneBoxDlg::OnDialphonenum()
  539. {
  540. // TODO: Add your command handler code here
  541. CUBoxLine* pLine = NULL;
  542. pLine = get_line_by_ID(m_iClickItemID);
  543. if (pLine)
  544. {
  545. UBOX_HANDLE hdl = pLine->line_handel();
  546. if (pLine->SendDtmfDlg.DoModal() == IDOK)
  547. {
  548. int res = ubox_get_product_ID(hdl);
  549. if ((res == 1) || (res == 4))
  550. {
  551. ubox_soft_hook_off(hdl);
  552. Sleep(1000);
  553. }
  554. if (ubox_send_dtmf(hdl, pLine->SendDtmfDlg.m_phonenum) != 0)
  555. m_dis.InsertString(m_dis.GetCount(), "dial num failed");
  556. }
  557. }
  558. m_dis.SetCurSel(m_dis.GetCount() - 1);
  559. }
  560. void CUPhoneBoxDlg::OnGethangthreshold()
  561. {
  562. // TODO: Add your command handler code here
  563. CUBoxLine* pLine = NULL;
  564. pLine = get_line_by_ID(m_iClickItemID);
  565. if (pLine)
  566. {
  567. char buff[100];
  568. UBOX_HANDLE hdl = pLine->line_handel();
  569. int res = ubox_get_hang_threshold(hdl);
  570. if (res > 0)
  571. {
  572. sprintf(buff, "Hang threshold:%dV", res);
  573. m_dis.InsertString(m_dis.GetCount(), buff);
  574. }
  575. else
  576. {
  577. if (res == -6)
  578. m_dis.InsertString(m_dis.GetCount(), "this function work in configure mode");
  579. else
  580. m_dis.InsertString(m_dis.GetCount(), "get hook off threshold failed");
  581. }
  582. }
  583. m_dis.SetCurSel(m_dis.GetCount() - 1);
  584. }
  585. void CUPhoneBoxDlg::OnGethardwareversion()
  586. {
  587. // TODO: Add your command handler code here
  588. CUBoxLine* pLine = NULL;
  589. pLine = get_line_by_ID(m_iClickItemID);
  590. if (pLine)
  591. {
  592. char buff[100];
  593. UBOX_HANDLE hdl = pLine->line_handel();
  594. float ver;
  595. int res = ubox_get_device_versionnum(hdl, ver);
  596. if (res == 0)
  597. {
  598. sprintf(buff, "hardware ver:V%2.1f", ver);
  599. m_dis.InsertString(m_dis.GetCount(), buff);
  600. }
  601. else
  602. m_dis.InsertString(m_dis.GetCount(), "get hardware ver failed");
  603. }
  604. m_dis.SetCurSel(m_dis.GetCount() - 1);
  605. }
  606. void CUPhoneBoxDlg::OnGetproductname()
  607. {
  608. // TODO: Add your command handler code here
  609. CUBoxLine* pLine = NULL;
  610. pLine = get_line_by_ID(m_iClickItemID);
  611. if (pLine)
  612. {
  613. UBOX_HANDLE hdl = pLine->line_handel();
  614. int res = ubox_get_product_ID(hdl);
  615. if (res > 0)
  616. {
  617. CString str;
  618. switch (res)
  619. {
  620. case 1:
  621. str = "FI3102A";
  622. break;
  623. case 2:
  624. str = "FI3002B";
  625. break;
  626. case 3:
  627. str = "FI3001B";
  628. break;
  629. case 4:
  630. str = "FI3101A";
  631. break;
  632. default:
  633. str = "unkown product";
  634. }
  635. m_dis.InsertString(m_dis.GetCount(), str);
  636. }
  637. else
  638. m_dis.InsertString(m_dis.GetCount(), "get product id failed");
  639. }
  640. m_dis.SetCurSel(m_dis.GetCount() - 1);
  641. }
  642. void CUPhoneBoxDlg::OnGetusernum()
  643. {
  644. // TODO: Add your command handler code here
  645. CUBoxLine* pLine = NULL;
  646. pLine = get_line_by_ID(m_iClickItemID);
  647. int res;
  648. if (pLine)
  649. {
  650. UBOX_HANDLE hdl = pLine->line_handel();
  651. unsigned char num[10];
  652. res = ubox_get_usernum(hdl, num, 10);
  653. if (res > 0)
  654. {
  655. int i;
  656. CString str = "USer num:";
  657. for (i = 0; i < res; i++)
  658. str += num[i];
  659. m_dis.InsertString(m_dis.GetCount(), str);
  660. }
  661. else
  662. m_dis.InsertString(m_dis.GetCount(), "get user num failed");
  663. }
  664. m_dis.SetCurSel(m_dis.GetCount() - 1);
  665. }
  666. void CUPhoneBoxDlg::OnOpenbuzzer()
  667. {
  668. // TODO: Add your command handler code here
  669. CUBoxLine* pLine = NULL;
  670. pLine = get_line_by_ID(m_iClickItemID);
  671. if (pLine)
  672. {
  673. UBOX_HANDLE hdl = pLine->line_handel();
  674. if (pLine->get_buzzerSwitch())
  675. {
  676. pLine->set_buzzerSwitch(false);
  677. ubox_open_buzzer_switch(hdl, false); //close buzzer
  678. }
  679. else
  680. {
  681. pLine->set_buzzerSwitch(true);
  682. ubox_open_buzzer_switch(hdl, true); //open buzzer
  683. }
  684. m_dis.SetCurSel(m_dis.GetCount() - 1);
  685. }
  686. }
  687. void CUPhoneBoxDlg::OnOpenconfiguremode()
  688. {
  689. // TODO: Add your command handler code here
  690. ubox_close();
  691. m_list.DeleteAllItems();
  692. int i;
  693. for (i = 0; i < MAX_DEVICE; i++)
  694. ubox_device[i].handl_plug_out();
  695. if (ubox_open(::ProcPhonicCallBack, UBOX_WORK_MODE(2)) == 0) //
  696. {
  697. m_dis.InsertString(m_dis.GetCount(), "use configure mode open device ok");
  698. }
  699. else
  700. m_dis.InsertString(m_dis.GetCount(), "use configure mode open device failed");
  701. m_dis.SetCurSel(m_dis.GetCount() - 1);
  702. }
  703. void CUPhoneBoxDlg::OnOpenmsgswitch()
  704. {
  705. // TODO: Add your command handler code here
  706. CUBoxLine* pLine = NULL;
  707. pLine = get_line_by_ID(m_iClickItemID);
  708. if (pLine)
  709. {
  710. UBOX_HANDLE hdl = pLine->line_handel();
  711. if (pLine->get_MessageSwitch())
  712. {
  713. pLine->set_MessageSwitch(false);
  714. ubox_set_message_param(hdl, false); //close buzzer
  715. }
  716. else
  717. {
  718. pLine->set_MessageSwitch(true);
  719. ubox_set_message_param(hdl, true); //open buzzer
  720. }
  721. m_dis.SetCurSel(m_dis.GetCount() - 1);
  722. }
  723. }
  724. void CUPhoneBoxDlg::OnPauseplay()
  725. {
  726. // TODO: Add your command handler code here
  727. CUBoxLine* pLine = NULL;
  728. pLine = get_line_by_ID(m_iClickItemID);
  729. if (pLine)
  730. {
  731. int res;
  732. UBOX_HANDLE hdl = pLine->line_handel();
  733. if (pLine->bplaypause)
  734. {
  735. pLine->bplaypause = false;
  736. res = ubox_play_pause(hdl);
  737. }
  738. else
  739. {
  740. pLine->bplaypause = true;
  741. res = ubox_play_pause(hdl);
  742. }
  743. if (res == 0)
  744. {
  745. m_dis.InsertString(m_dis.GetCount(), "play pause,click this menu continued playing file");
  746. }
  747. else
  748. m_dis.InsertString(m_dis.GetCount(), "set play pause failed");
  749. }
  750. m_dis.SetCurSel(m_dis.GetCount() - 1);
  751. }
  752. void CUPhoneBoxDlg::OnPlayfile()
  753. {
  754. // TODO: Add your command handler code here
  755. CUBoxLine* pLine = NULL;
  756. pLine = get_line_by_ID(m_iClickItemID);
  757. int res;
  758. if (pLine)
  759. {
  760. UBOX_HANDLE hdl = pLine->line_handel();
  761. CFileDialog dlg(true);
  762. if (dlg.DoModal() == IDOK)
  763. {
  764. res = ubox_play_file(hdl, dlg.GetPathName());
  765. if (res != 0)
  766. m_dis.InsertString(m_dis.GetCount(), "play file failed");
  767. }
  768. m_dis.SetCurSel(m_dis.GetCount() - 1);
  769. }
  770. }
  771. void CUPhoneBoxDlg::OnReadeeprom()
  772. {
  773. // TODO: Add your command handler code here
  774. CUBoxLine* pLine = NULL;
  775. pLine = get_line_by_ID(m_iClickItemID);
  776. int res;
  777. if (pLine)
  778. {
  779. UBOX_HANDLE hdl = pLine->line_handel();
  780. unsigned char data[8];
  781. res = ubox_read_eeprom(hdl, 0, data, 8);
  782. if (res != 0)
  783. m_dis.InsertString(m_dis.GetCount(), "read eeprom data failed");
  784. else
  785. {
  786. m_dis.InsertString(m_dis.GetCount(), "Read rom data from addr 0-7:");
  787. char buff[100];
  788. sprintf(buff, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
  789. m_dis.InsertString(m_dis.GetCount(), buff);
  790. }
  791. }
  792. m_dis.SetCurSel(m_dis.GetCount() - 1);
  793. }
  794. void CUPhoneBoxDlg::OnReadeepromex()
  795. {
  796. // TODO: Add your command handler code here
  797. CUBoxLine* pLine = NULL;
  798. pLine = get_line_by_ID(m_iClickItemID);
  799. int res;
  800. if (pLine)
  801. {
  802. UBOX_HANDLE hdl = pLine->line_handel();
  803. unsigned char data[8];
  804. res = ubox_read_eepromEx(hdl, 0, data, 8);
  805. if (res != 0)
  806. m_dis.InsertString(m_dis.GetCount(), "read eeprom data failed");
  807. else
  808. {
  809. m_dis.InsertString(m_dis.GetCount(), "Read eepromdata from addr 0-7:");
  810. char buff[100];
  811. sprintf(buff, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
  812. m_dis.InsertString(m_dis.GetCount(), buff);
  813. }
  814. }
  815. m_dis.SetCurSel(m_dis.GetCount() - 1);
  816. }
  817. void CUPhoneBoxDlg::OnReadlinevoltage()
  818. {
  819. // TODO: Add your command handler code here
  820. CUBoxLine* pLine = NULL;
  821. pLine = get_line_by_ID(m_iClickItemID);
  822. int res;
  823. if (pLine)
  824. {
  825. UBOX_HANDLE hdl = pLine->line_handel();
  826. res = ubox_start_read_line_voltage(hdl);
  827. if (res != 0)
  828. m_dis.InsertString(m_dis.GetCount(), "Start read line Voltage failed");
  829. }
  830. m_dis.SetCurSel(m_dis.GetCount() - 1);
  831. }
  832. void CUPhoneBoxDlg::OnRecordfile()//摘机开始录音;
  833. {
  834. // TODO: Add your command handler code here
  835. CUBoxLine* pLine = NULL;
  836. pLine = get_line_by_ID(m_iClickItemID);
  837. int res;
  838. if (pLine)
  839. {
  840. UBOX_HANDLE hdl = pLine->line_handel();
  841. CString sFilter =
  842. "Wave Files(*.wav)|*.wav";
  843. CFileDialog dlgOpen(FALSE, "WAV", 0, OFN_HIDEREADONLY,
  844. (LPCTSTR)sFilter, NULL);
  845. if (dlgOpen.DoModal() == IDOK)
  846. {
  847. res = ubox_record_file(hdl, (LPCTSTR)(dlgOpen.GetPathName()), CODER_MP3);
  848. if (res != 0)
  849. {
  850. m_dis.InsertString(m_dis.GetCount(), "record file failed");
  851. }
  852. }
  853. m_dis.SetCurSel(m_dis.GetCount() - 1);
  854. }
  855. }
  856. void CUPhoneBoxDlg::OnRecordstream()
  857. {
  858. // TODO: Add your command handler code here
  859. CUBoxLine* pLine = get_line_by_ID(m_iClickItemID);
  860. if (pLine)
  861. {
  862. UBOX_HANDLE hdl = pLine->line_handel();
  863. CString sFilter =
  864. "Wave Files(*.wav)|*.wav";
  865. CFileDialog dlgOpen(FALSE, "WAV", 0, OFN_HIDEREADONLY,
  866. (LPCTSTR)sFilter, NULL);
  867. if (dlgOpen.DoModal() == IDOK)
  868. {
  869. pLine->fpstream = fopen((LPCTSTR)(dlgOpen.GetPathName()), "wb+");
  870. if (!pLine->fpstream)
  871. m_dis.InsertString(m_dis.GetCount(), "create file failed");
  872. else
  873. {
  874. WORD fmt = WAVE_FORMAT_ALAW; //WAVE_FORMAT_MULAW WAVE_FORMAT_PCM
  875. WaveFileHeader pcmWavHeader(0, fmt);
  876. int res = fwrite((const char*)&pcmWavHeader, sizeof(pcmWavHeader), 1, pLine->fpstream);
  877. if (res != 1)
  878. {
  879. m_dis.InsertString(m_dis.GetCount(), "write file head failed");
  880. m_dis.SetCurSel(m_dis.GetCount() - 1);
  881. }
  882. }
  883. if (ubox_record_stream(hdl, CODER_ALAW) != 0)
  884. {
  885. m_dis.InsertString(m_dis.GetCount(), "stream record failed");
  886. if (pLine->fpstream)
  887. {
  888. fclose(pLine->fpstream);
  889. pLine->fpstream = NULL;
  890. }
  891. }
  892. }
  893. }
  894. }
  895. void CUPhoneBoxDlg::OnSethangthreshold()
  896. {
  897. // TODO: Add your command handler code here
  898. CUBoxLine* pLine = NULL;
  899. pLine = get_line_by_ID(m_iClickItemID);
  900. if (pLine)
  901. {
  902. UBOX_HANDLE hdl = pLine->line_handel();
  903. int value_d = atoi(pLine->threshold.m_hangTh.GetBuffer(pLine->threshold.m_hangTh.GetLength()));
  904. if (pLine->threshold.DoModal() == IDOK)
  905. {
  906. if (ubox_set_hang_threshold(hdl, value_d) != 0)
  907. m_dis.InsertString(m_dis.GetCount(), "set hookoff threshold faild");
  908. }
  909. pLine->threshold.m_hangTh.ReleaseBuffer();
  910. }
  911. m_dis.SetCurSel(m_dis.GetCount() - 1);
  912. }
  913. void CUPhoneBoxDlg::OnSethookoffthreshold()
  914. {
  915. // TODO: Add your command handler code here
  916. CUBoxLine* pLine = NULL;
  917. pLine = get_line_by_ID(m_iClickItemID);
  918. //setthreshold threshold;
  919. if (pLine)
  920. {
  921. UBOX_HANDLE hdl = pLine->line_handel();
  922. int value_d = atoi(pLine->threshold.m_hookoffTh.GetBuffer(pLine->threshold.m_hookoffTh.GetLength()));
  923. if (pLine->threshold.DoModal() == IDOK)
  924. {
  925. if (ubox_set_hookoff_threshold(hdl, value_d) != 0)
  926. m_dis.InsertString(m_dis.GetCount(), "set hookoff threshold faild");
  927. }
  928. pLine->threshold.m_hookoffTh.ReleaseBuffer();
  929. }
  930. m_dis.SetCurSel(m_dis.GetCount() - 1);
  931. }
  932. void CUPhoneBoxDlg::OnSofthangup()
  933. {
  934. // TODO: Add your command handler code here
  935. CUBoxLine* pLine = NULL;
  936. pLine = get_line_by_ID(m_iClickItemID);
  937. if (pLine)
  938. {
  939. UBOX_HANDLE hdl = pLine->line_handel();
  940. if (ubox_soft_hook_on(hdl) != 0)
  941. {
  942. // MessageBox("soft hookon failed!","提示",MB_OK);
  943. m_dis.InsertString(m_dis.GetCount(), "soft hookon failed!");
  944. }
  945. }
  946. m_dis.SetCurSel(m_dis.GetCount() - 1);
  947. }
  948. void CUPhoneBoxDlg::OnSofthookoff()
  949. {
  950. // TODO: Add your command handler code here
  951. CUBoxLine* pLine = NULL;
  952. pLine = get_line_by_ID(m_iClickItemID);
  953. if (pLine)
  954. {
  955. UBOX_HANDLE hdl = pLine->line_handel();
  956. if (ubox_soft_hook_off(hdl) != 0)
  957. {
  958. m_dis.InsertString(m_dis.GetCount(), "soft hook off failed");
  959. }
  960. }
  961. }
  962. void CUPhoneBoxDlg::OnStopplay()
  963. {
  964. // TODO: Add your command handler code here
  965. CUBoxLine* pLine = NULL;
  966. pLine = get_line_by_ID(m_iClickItemID);
  967. int res;
  968. if (pLine)
  969. {
  970. UBOX_HANDLE hdl = pLine->line_handel();
  971. res = ubox_stop_play(hdl);
  972. if (res != 0)
  973. m_dis.InsertString(m_dis.GetCount(), "stop play file failed");
  974. }
  975. m_dis.SetCurSel(m_dis.GetCount() - 1);
  976. }
  977. void CUPhoneBoxDlg::OnStopreadlinevoltage()
  978. {
  979. // TODO: Add your command handler code here
  980. CUBoxLine* pLine = NULL;
  981. pLine = get_line_by_ID(m_iClickItemID);
  982. int res;
  983. if (pLine)
  984. {
  985. UBOX_HANDLE hdl = pLine->line_handel();
  986. res = ubox_stop_read_line_voltage(hdl);
  987. if (res != 0)
  988. m_dis.InsertString(m_dis.GetCount(), "stop read line voltage failed");
  989. }
  990. m_dis.SetCurSel(m_dis.GetCount() - 1);
  991. }
  992. void CUPhoneBoxDlg::OnStoprecord()
  993. {
  994. // TODO: Add your command handler code here
  995. CUBoxLine* pLine = NULL;
  996. pLine = get_line_by_ID(m_iClickItemID);
  997. int res;
  998. if (pLine)
  999. {
  1000. UBOX_HANDLE hdl = pLine->line_handel();
  1001. res = ubox_stop_record(hdl);
  1002. if (res != 0)
  1003. m_dis.InsertString(m_dis.GetCount(), "stop recorder file failed");
  1004. if (pLine->fpstream)
  1005. {
  1006. WORD fmt = WAVE_FORMAT_ALAW; //WAVE_FORMAT_MULAW WAVE_FORMAT_PCM
  1007. fseek(pLine->fpstream, 0, SEEK_END);
  1008. long filesize = ftell(pLine->fpstream);
  1009. fseek(pLine->fpstream, 0, SEEK_SET);
  1010. WaveFileHeader pcmWavHeader(filesize - sizeof(WaveFileHeader), fmt);
  1011. int res = fwrite((const char*)&pcmWavHeader, sizeof(pcmWavHeader), 1, pLine->fpstream);
  1012. if (res != 1)
  1013. {
  1014. m_dis.InsertString(m_dis.GetCount(), "write file head failed");
  1015. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1016. }
  1017. fclose(pLine->fpstream);
  1018. pLine->fpstream = NULL;
  1019. }
  1020. }
  1021. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1022. }
  1023. void CUPhoneBoxDlg::OnWriteeeprom()
  1024. {
  1025. // TODO: Add your command handler code here
  1026. // TODO: Add your command handler code here
  1027. CUBoxLine* pLine = NULL;
  1028. pLine = get_line_by_ID(m_iClickItemID);
  1029. int res;
  1030. if (pLine)
  1031. {
  1032. UBOX_HANDLE hdl = pLine->line_handel();
  1033. unsigned char data[8] = { 170, 2, 3, 4, 98, 6, 7, 255 }; //1->0x1 255->0xFF data[i]<256;
  1034. res = ubox_write_eeprom(hdl, 0, data, 8); //data [0,255]
  1035. if (res != 0)
  1036. m_dis.InsertString(m_dis.GetCount(), "read eepromex data failed");
  1037. else
  1038. {
  1039. m_dis.InsertString(m_dis.GetCount(), "write data ok");
  1040. }
  1041. }
  1042. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1043. }
  1044. void CUPhoneBoxDlg::OnSetBusyTone()
  1045. {
  1046. CUBoxLine* pLine = NULL;
  1047. pLine = get_line_by_ID(m_iClickItemID);
  1048. if (pLine)
  1049. {
  1050. long hdl = pLine->line_handel();
  1051. CSetBusyToneDlg Dlg;
  1052. if (Dlg.DoModal() == IDOK)
  1053. {
  1054. tagBusyInfo busyinfo;
  1055. busyinfo.busy_dual_frequency = Dlg.m_bDualTone ? 1 : 0;
  1056. busyinfo.busy_frequency0 = Dlg.m_lFrequency0;
  1057. busyinfo.busy_frequency1 = Dlg.m_Frequencey1;
  1058. busyinfo.busy_on = Dlg.m_lBusyOn / 10;
  1059. busyinfo.busy_off = Dlg.m_lBusyOff / 10;
  1060. busyinfo.busy_on_off_error = Dlg.m_lTimeError / 10;
  1061. busyinfo.busy_enery_gate = Dlg.m_lBusyEnergy;
  1062. busyinfo.busy_period_count = Dlg.m_lBusyCount;
  1063. ubox_set_busy_tone(hdl, busyinfo);
  1064. }
  1065. }
  1066. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1067. }
  1068. void CUPhoneBoxDlg::OnSetVolume()
  1069. {
  1070. CUBoxLine* pLine = NULL;
  1071. pLine = get_line_by_ID(m_iClickItemID);
  1072. if (pLine)
  1073. {
  1074. long hdl = pLine->line_handel();
  1075. CSetVolumeDlg dlg;
  1076. if (dlg.DoModal() == IDOK)
  1077. {
  1078. ubox_set_Speakervolume(hdl, dlg.m_lSpkVol);
  1079. ubox_set_volume(hdl, dlg.m_lMicVol);
  1080. }
  1081. }
  1082. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1083. }
  1084. void CUPhoneBoxDlg::OnGethookoffthreshold()
  1085. {
  1086. // TODO: Add your command handler code here
  1087. CUBoxLine* pLine = NULL;
  1088. pLine = get_line_by_ID(m_iClickItemID);
  1089. if (pLine)
  1090. {
  1091. char buff[100];
  1092. UBOX_HANDLE hdl = pLine->line_handel();
  1093. int res = ubox_get_hookoff_threshold(hdl);
  1094. if (res > 0)
  1095. {
  1096. sprintf(buff, "hookoff threshold:%dV", res);
  1097. m_dis.InsertString(m_dis.GetCount(), buff);
  1098. }
  1099. else
  1100. {
  1101. if (res == -6)
  1102. m_dis.InsertString(m_dis.GetCount(), "this function work in configure mode");
  1103. else
  1104. m_dis.InsertString(m_dis.GetCount(), "get hook off threshold failed");
  1105. }
  1106. }
  1107. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1108. }
  1109. void CUPhoneBoxDlg::OnDblclkOpt(NMHDR* pNMHDR, LRESULT* pResult)
  1110. {
  1111. // TODO: Add your control notification handler code here
  1112. m_iClickItemID = m_list.GetSelectionMark();
  1113. PopOpt(m_iClickItemID);
  1114. *pResult = 0;
  1115. }
  1116. void CUPhoneBoxDlg::PopOpt(int index)
  1117. {
  1118. // ClientToScreen (&(m_ClickPoint));
  1119. CMenu TMenu;
  1120. CMenu * pMenu;
  1121. //CWnd
  1122. RECT rect;
  1123. m_list.GetWindowRect(&rect);
  1124. if (TMenu.LoadMenu(IDR_MENU_OPT))
  1125. {
  1126. pMenu = TMenu.GetSubMenu(0);
  1127. CUBoxLine* pLine = NULL;
  1128. pLine = get_line_by_ID(index);
  1129. if (pMenu&& pLine)
  1130. {
  1131. if (pLine->get_agc())
  1132. pMenu->CheckMenuItem(IDM_CLOSEAGC, MF_CHECKED);
  1133. else
  1134. pMenu->CheckMenuItem(IDM_CLOSEAGC, MF_UNCHECKED);
  1135. if (pLine->get_buzzerSwitch())
  1136. pMenu->CheckMenuItem(IDM_OPENBUZZER, MF_CHECKED);
  1137. else
  1138. pMenu->CheckMenuItem(IDM_OPENBUZZER, MF_UNCHECKED);
  1139. if (pLine->get_MessageSwitch())
  1140. pMenu->CheckMenuItem(IDM_OPENMSGSWITCH, MF_CHECKED);
  1141. else
  1142. pMenu->CheckMenuItem(IDM_OPENMSGSWITCH, MF_UNCHECKED);
  1143. if (pLine->bplaypause)
  1144. pMenu->CheckMenuItem(IDM_PAUSEPLAY, MF_CHECKED);
  1145. else
  1146. pMenu->CheckMenuItem(IDM_PAUSEPLAY, MF_UNCHECKED);
  1147. pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON,
  1148. 100 + rect.left, /*m_ClickPoint.y*/100,
  1149. this, NULL);
  1150. }
  1151. }
  1152. }
  1153. void CUPhoneBoxDlg::OnDestroy()
  1154. {
  1155. g_listctrlfont.DeleteObject();
  1156. ubox_close();
  1157. OnDisconnect();
  1158. g_dlgphonecoming[0].DestroyWindow();
  1159. g_dlgphonecoming[1].DestroyWindow();
  1160. CDialog::OnDestroy();
  1161. // TODO: Add your message handler code here
  1162. }
  1163. void CUPhoneBoxDlg::OnPLugInPhonicusb(UBOX_HANDLE uboxHandle)
  1164. {
  1165. // TODO: Add your control notification handler code here
  1166. char str[50];
  1167. CUBoxLine* pLine = NULL;
  1168. pLine = get_line_by_handle(INVALID_UBOX_HANDLE);
  1169. if (pLine)
  1170. {
  1171. sprintf(str, "%d", m_list.GetItemCount() + 1);
  1172. pLine->handl_plug_in(uboxHandle, m_list.GetItemCount());
  1173. int nn = m_list.InsertItem(m_list.GetItemCount(), str);
  1174. m_list.SetItemText(m_list.GetItemCount() - 1, 2, "Plug In");
  1175. int res = ubox_get_product_ID(uboxHandle);
  1176. if (res > 0)
  1177. {
  1178. CString str;
  1179. switch (res)
  1180. {
  1181. case 1:
  1182. str = "FI3102A";
  1183. break;
  1184. case 2:
  1185. str = "FI3002B";
  1186. break;
  1187. case 3:
  1188. str = "FI3001B";
  1189. break;
  1190. case 4:
  1191. str = "FI3101A";
  1192. break;
  1193. default:
  1194. str = "unkown product";
  1195. return;
  1196. }
  1197. m_list.SetItemText(m_list.GetItemCount() - 1, 1, str);
  1198. BYTE buf[16];
  1199. memset(buf, 0, 16);
  1200. ubox_get_usernum(uboxHandle, buf, 16);
  1201. CString clientno = buf;
  1202. clientno.TrimLeft();
  1203. clientno.TrimRight();
  1204. #ifdef NEW_DEVICE
  1205. if (clientno.GetLength() < 8)
  1206. {
  1207. AfxMessageBox("硬件版本错误,请及时与经销商联系更换,对您造成的不便请谅解!电话:4006-067068 18665281860");
  1208. return;
  1209. }
  1210. if (clientno.Left(8) == "02065722")
  1211. g_bok = 1;
  1212. else
  1213. AfxMessageBox("硬件版本错误,请及时与经销商联系更换,对您造成的不便请谅解!电话:4006-067068 18665281860");
  1214. #else
  1215. g_bok = 1;
  1216. #endif
  1217. if (g_bok)
  1218. m_TrayIcon.SetIcon(m_hIcon2);
  1219. WriteLogin("设备连接OK");
  1220. }
  1221. }
  1222. }
  1223. void CUPhoneBoxDlg::OnCallIdPhonicusb(UBOX_HANDLE uboxHandle, char* callid)
  1224. {
  1225. // TODO: Add your control notification handler code here
  1226. CUBoxLine* pLine = NULL;
  1227. pLine = get_line_by_handle(uboxHandle);
  1228. if (pLine)
  1229. {
  1230. int lineID = pLine->line_id();
  1231. CString phone = callid;
  1232. if (phone.GetLength() > 2)
  1233. {
  1234. if (phone.Left(2) == "01")
  1235. {
  1236. if (phone.Left(3) != "010")phone.TrimLeft("0");
  1237. }
  1238. }
  1239. m_list.SetItemText(lineID, 4, phone);
  1240. g_bCallOut[lineID] = 0;
  1241. CString strMsg = _T("");
  1242. strMsg.Format(_T("来电线路:%d,%d, 来电号码:%s"),lineID,uboxHandle,phone);
  1243. WriteLogin(strMsg);
  1244. #if _DEBUG
  1245. TRACE("来电号码:");
  1246. TRACE(phone);
  1247. TRACE("\n");
  1248. #endif
  1249. ShowClient(lineID, phone);
  1250. }
  1251. }
  1252. void CUPhoneBoxDlg::OnCallOutFinishPhonicusb(UBOX_HANDLE uboxHandle)
  1253. {
  1254. // TODO: Add your control notification handler code here
  1255. CUBoxLine* pLine = NULL;
  1256. pLine = get_line_by_handle(uboxHandle);
  1257. if (pLine)
  1258. {
  1259. int lineID = pLine->line_id();
  1260. m_list.SetItemText(lineID, 5, "CallOutFinish");
  1261. }
  1262. }
  1263. //CODER_MP3
  1264. void CUPhoneBoxDlg::OnDeviceAlarmPhonicusb(UBOX_HANDLE uboxHandle)
  1265. {
  1266. // TODO: Add your control notification handler code here
  1267. // MessageBox("device alarm,please reboot software,or plug out USB device!","prompt",MB_OK);
  1268. }
  1269. void CUPhoneBoxDlg::OnDeviceErrorPhonicusb(UBOX_HANDLE uboxHandle)
  1270. {
  1271. // TODO: Add your control notification handler code here
  1272. // MessageBox("device error,please reboot software,or plug out USB device!","prompt",MB_OK);
  1273. }
  1274. void GetRealNo(CString &str)
  1275. {
  1276. char c = '0';
  1277. for (int i = 0; i<str.GetLength(); i++)
  1278. {
  1279. c = str.GetAt(i);
  1280. if (c>'9' || c<'0')
  1281. break;
  1282. }
  1283. if (c>'9' || c < '0')
  1284. {
  1285. int pos = str.Find(c);
  1286. if (pos != -1)str = str.Left(pos);
  1287. }
  1288. /* int pos=str.Find ("*");
  1289. if(pos!=-1)
  1290. str=str.Left (pos);
  1291. pos=str.Find ("#");
  1292. if(pos!=-1)
  1293. str=str.Left (pos);*/
  1294. if (str.Left(1) == "1" && str.GetLength()>11)
  1295. str = str.Left(11);
  1296. }
  1297. void CUPhoneBoxDlg::OnDtmfKeyPhonicusb(UBOX_HANDLE uboxHandle, char dtmfCode)
  1298. {
  1299. // TODO: Add your control notification handler code here clear_dtmf_key
  1300. CUBoxLine* pLine = NULL;
  1301. pLine = get_line_by_handle(uboxHandle);
  1302. if (pLine)
  1303. {
  1304. int lineID = pLine->line_id();
  1305. pLine->set_dtmf_key(dtmfCode);
  1306. CString str = pLine->get_dtmfky();
  1307. m_list.SetItemText(lineID, 3, str);
  1308. GetRealNo(str);
  1309. if (str.GetLength() > 2)
  1310. {
  1311. if (str.Left(2) == "01")
  1312. {
  1313. if (str.Left(3) != "010")str.TrimLeft("0");
  1314. }
  1315. }
  1316. g_phone[lineID] = str;
  1317. }
  1318. }
  1319. void CUPhoneBoxDlg::OnHangIngPhonicusb(UBOX_HANDLE uboxHandle)
  1320. {
  1321. // TODO: Add your control notification handler code here
  1322. CUBoxLine* pLine = NULL;
  1323. pLine = get_line_by_handle(uboxHandle);
  1324. if (pLine)
  1325. {
  1326. int lineID = pLine->line_id();
  1327. m_list.SetItemText(lineID, 2, "Hang");
  1328. }
  1329. }
  1330. void CUPhoneBoxDlg::OnHangUpPhonicusb(UBOX_HANDLE uboxHandle)
  1331. {
  1332. // TODO: Add your control notification handler code here
  1333. CUBoxLine* pLine = NULL;
  1334. pLine = get_line_by_handle(uboxHandle);
  1335. if (pLine)
  1336. {
  1337. int lineID = pLine->line_id();
  1338. m_list.SetItemText(lineID, 2, "Hangup");
  1339. pLine->clear_dtmf_key();
  1340. // if((((CButton *)GetDlgItem(IDC_AUDORECORD))->GetState()) &&pLine->brecord)
  1341. if (pLine->brecord)
  1342. {
  1343. pLine->brecord = false;
  1344. ubox_stop_record(uboxHandle);
  1345. }
  1346. ExitWindow(lineID, 1);
  1347. }
  1348. m_dis.InsertString(m_dis.GetCount(), "hang up");
  1349. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1350. }
  1351. void CUPhoneBoxDlg::OnHookOffPhonicusb(UBOX_HANDLE uboxHandle)
  1352. {
  1353. // TODO: Add your control notification handler code here
  1354. CUBoxLine* pLine = NULL;
  1355. pLine = get_line_by_handle(uboxHandle);
  1356. if (pLine)
  1357. {
  1358. int lineID = pLine->line_id();
  1359. m_list.SetItemText(lineID, 2, "hookoff");
  1360. // if((((CButton *)GetDlgItem(IDC_AUDORECORD))->GetState()) &&!pLine->brecord)
  1361. if (!pLine->brecord)
  1362. {
  1363. pLine->brecord = true;
  1364. autoRecordFile(uboxHandle);
  1365. }
  1366. }
  1367. m_dis.InsertString(m_dis.GetCount(), "hook off");
  1368. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1369. }
  1370. void CUPhoneBoxDlg::OnLineIdlePhonicusb(UBOX_HANDLE uboxHandle)
  1371. {
  1372. // TODO: Add your control notification handler code here
  1373. }
  1374. void CUPhoneBoxDlg::OnLineVoltagePhonicusb(UBOX_HANDLE uboxHandle, long voltage)
  1375. {
  1376. // TODO: Add your control notification handler code here
  1377. char buff[100];
  1378. sprintf(buff, "line voltage:%d V", voltage);
  1379. m_dis.InsertString(m_dis.GetCount(), buff);
  1380. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1381. }
  1382. void CUPhoneBoxDlg::OnPlayEndPhonicusb(UBOX_HANDLE uboxHandle)
  1383. {
  1384. // TODO: Add your control notification handler code here
  1385. CUBoxLine* pLine = NULL;
  1386. pLine = get_line_by_handle(uboxHandle);
  1387. if (pLine)
  1388. {
  1389. int lineID = pLine->line_id();
  1390. m_list.SetItemText(lineID, 5, "play end");
  1391. }
  1392. }
  1393. void CUPhoneBoxDlg::OnPlayErrorPhonicusb(UBOX_HANDLE uboxHandle)
  1394. {
  1395. // TODO: Add your control notification handler code here
  1396. CUBoxLine* pLine = NULL;
  1397. pLine = get_line_by_handle(uboxHandle);
  1398. if (pLine)
  1399. {
  1400. int lineID = pLine->line_id();
  1401. m_list.SetItemText(lineID, 5, "play error");
  1402. }
  1403. }
  1404. void CUPhoneBoxDlg::OnPlugOutPhonicusb(UBOX_HANDLE uboxHandle)
  1405. {
  1406. // TODO: Add your control notification handler code here
  1407. CUBoxLine* pLine = NULL;
  1408. pLine = get_line_by_handle(uboxHandle);
  1409. if (pLine)
  1410. {
  1411. int lineID = pLine->line_id();
  1412. m_list.SetItemText(lineID, 2, "plug out");
  1413. pLine->handl_plug_out();
  1414. m_TrayIcon.SetIcon(m_hIcon);
  1415. }
  1416. }
  1417. void CUPhoneBoxDlg::OnPolarityPhonicusb(UBOX_HANDLE uboxHandle, long lineSign)
  1418. {
  1419. // TODO: Add your control notification handler code here
  1420. CUBoxLine* pLine = NULL;
  1421. pLine = get_line_by_handle(uboxHandle);
  1422. CString str;
  1423. if (lineSign)
  1424. str = "polarity - ";
  1425. else
  1426. str = "polarity + ";
  1427. if (pLine)
  1428. {
  1429. int lineID = pLine->line_id();
  1430. m_list.SetItemText(lineID, 5, str);
  1431. }
  1432. m_dis.InsertString(m_dis.GetCount(), str);
  1433. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1434. }
  1435. void CUPhoneBoxDlg::OnRingPhonicusb(UBOX_HANDLE uboxHandle)
  1436. {
  1437. // TODO: Add your control notification handler code here
  1438. CUBoxLine* pLine = NULL;
  1439. pLine = get_line_by_handle(uboxHandle);
  1440. if (pLine)
  1441. {
  1442. int lineID = pLine->line_id();
  1443. m_dis.InsertString(m_dis.GetCount(), "ring");
  1444. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1445. m_list.SetItemText(lineID, 2, "ring");
  1446. if (!pLine->brecord)
  1447. {
  1448. pLine->brecord = true;
  1449. autoRecordFile(uboxHandle);
  1450. }
  1451. }
  1452. }
  1453. void CUPhoneBoxDlg::OnRingCancelPhonicusb(UBOX_HANDLE uboxHandle)
  1454. {
  1455. // TODO: Add your control notification handler code here UBOX_EVENT_STREAM_VOICE
  1456. #if _DEBUG
  1457. TRACE("振铃取消\n");
  1458. #endif
  1459. CUBoxLine* pLine = NULL;
  1460. pLine = get_line_by_handle(uboxHandle);
  1461. if (pLine)
  1462. {
  1463. int lineID = pLine->line_id();
  1464. m_list.SetItemText(lineID, 2, "Miss call");
  1465. if (pLine->brecord)
  1466. {
  1467. pLine->brecord = false;
  1468. ubox_stop_record(uboxHandle);
  1469. }
  1470. ExitWindow(lineID, 0);
  1471. }
  1472. }
  1473. void CUPhoneBoxDlg::OnRingStopPhonicusb(UBOX_HANDLE uboxHandle)
  1474. {
  1475. // TODO: Add your control notification handler code here
  1476. CUBoxLine* pLine = NULL;
  1477. pLine = get_line_by_handle(uboxHandle);
  1478. if (pLine)
  1479. {
  1480. int lineID = pLine->line_id();
  1481. m_list.SetItemText(lineID, 2, "ring stop");
  1482. }
  1483. }
  1484. void CUPhoneBoxDlg::OnStreamVoicePhonicusb(UBOX_HANDLE uboxHandle, char* pVoice, long len)
  1485. {
  1486. // TODO: Add your control notification handler code here ubox_record_file
  1487. CUBoxLine* pLine = NULL;
  1488. pLine = get_line_by_handle(uboxHandle);
  1489. if (pLine)
  1490. {
  1491. if (pLine->fpstream)
  1492. {
  1493. int res = fwrite(pVoice, sizeof(char), len, pLine->fpstream);
  1494. if (res != len)
  1495. {
  1496. m_dis.InsertString(m_dis.GetCount(), "stream data write file failed");
  1497. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1498. }
  1499. }
  1500. }
  1501. }
  1502. void CUPhoneBoxDlg::OnToneBusyPhonicusb(UBOX_HANDLE uboxHandle)
  1503. {
  1504. // TODO: Add your control notification handler code here
  1505. CUBoxLine* pLine = NULL;
  1506. pLine = get_line_by_handle(uboxHandle);
  1507. if (pLine)
  1508. {
  1509. int lineID = pLine->line_id();
  1510. m_list.SetItemText(lineID, 5, "tone busy");
  1511. int res = ubox_get_product_ID(uboxHandle);
  1512. if ((res == 1) || (res == 4))
  1513. ubox_soft_hook_on(uboxHandle);
  1514. }
  1515. m_dis.InsertString(m_dis.GetCount(), "tone busy");
  1516. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1517. }
  1518. void CUPhoneBoxDlg::autoRecordFile(UBOX_HANDLE hdl)
  1519. {
  1520. char filename[MAX_PATH * 2];
  1521. SYSTEMTIME nowTime;
  1522. ::GetLocalTime(&nowTime);
  1523. sprintf(filename, "%s\\%sline-%d-%04d-%02d-%02d-%02d-%02d-%02d-%03d.mp3",
  1524. strPath, RECOED_DIR,
  1525. hdl, nowTime.wYear, nowTime.wMonth, nowTime.wDay,
  1526. nowTime.wHour, nowTime.wMinute, nowTime.wSecond,
  1527. nowTime.wMilliseconds);
  1528. try
  1529. {
  1530. if (ubox_record_file(hdl, filename, CODER_MP3) != 0)
  1531. {
  1532. m_dis.InsertString(m_dis.GetCount(), "auto record file faild");
  1533. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1534. }
  1535. else
  1536. {
  1537. CUBoxLine* pLine = NULL;
  1538. pLine = get_line_by_handle(hdl);
  1539. if (pLine)
  1540. {
  1541. int lineID = pLine->line_id();
  1542. g_recordpath[lineID] = filename;
  1543. }
  1544. }
  1545. }
  1546. catch (...)
  1547. {
  1548. WriteLogin("保存录音文件时出错");
  1549. }
  1550. }
  1551. void CALLBACK ProcPhonicCallBack(
  1552. UBOX_HANDLE uboxHnd //设备句柄
  1553. , int eventID //事件,参考UBOX_EVENT的定义
  1554. , unsigned long param1 //下面几个参数不同的事件,其含义不同
  1555. , unsigned long param2
  1556. , unsigned long param3
  1557. , unsigned long param4
  1558. )
  1559. {
  1560. if (pusb)
  1561. {
  1562. pusb->handle_event(uboxHnd, eventID, param1, param2, param3, param4);
  1563. }
  1564. }
  1565. void CUPhoneBoxDlg::handle_event(
  1566. UBOX_HANDLE uboxHnd
  1567. , int eventID //事件,参考UBOX_EVENT的定义
  1568. , unsigned long param1 //下面几个参数不同的事件,其含义不同
  1569. , unsigned long param2
  1570. , unsigned long param3
  1571. , unsigned long param4)
  1572. {
  1573. //CString ss;
  1574. //ss.Format("线路句柄:%d,事件ID:%d", uboxHnd,eventID);
  1575. //WriteLogin(ss);
  1576. switch (eventID)
  1577. {
  1578. case UBOX_EVENT_DEVICE_PLUG_OUT: //检测到设备拔出,
  1579. {
  1580. OnPlugOutPhonicusb(uboxHnd);
  1581. CString strMsg = _T("");
  1582. strMsg.Format(_T("检测到设备拔出,线路句柄:%d"),uboxHnd);
  1583. WriteLogin(strMsg);
  1584. #if _DEBUG
  1585. TRACE("检测到设备拔出\n");
  1586. #endif
  1587. }
  1588. break;
  1589. case UBOX_EVENT_LINE_RESET: //复位:摘机->挂机,振铃->停振 硬件LED灭 已经将该事件分为两个挂机和停振事件
  1590. {
  1591. CString strMsg = _T("");
  1592. strMsg.Format(_T("复位:摘机->挂机,振铃->停振,线路句柄:%d"),uboxHnd);
  1593. WriteLogin(strMsg);
  1594. #if _DEBUG
  1595. TRACE("复位:摘机->挂机,振铃->停振\n");
  1596. #endif
  1597. }
  1598. break;
  1599. case UBOX_EVENT_LINE_RINGING: //振铃,硬件LED亮 11
  1600. {
  1601. OnRingPhonicusb(uboxHnd);
  1602. CString strMsg = _T("");
  1603. strMsg.Format(_T("振铃,线路句柄:%d"),uboxHnd);
  1604. WriteLogin(strMsg);
  1605. #if _DEBUG
  1606. TRACE("振铃\n");
  1607. #endif
  1608. }
  1609. break;
  1610. case UBOX_EVENT_LINE_HOOK_OFF: //摘机,硬件LED亮
  1611. {
  1612. OnHookOffPhonicusb(uboxHnd);
  1613. CString strMsg = _T("");
  1614. strMsg.Format(_T("摘机,线路句柄:%d"),uboxHnd);
  1615. WriteLogin(strMsg);
  1616. #if _DEBUG
  1617. TRACE("摘机\n");
  1618. #endif
  1619. }
  1620. break;
  1621. case UBOX_EVENT_LINE_HANG: //检测到线路悬空 ,默认线路电压小于3V,认为线路悬空,硬件LED闪烁
  1622. {
  1623. OnHangIngPhonicusb(uboxHnd);
  1624. CString strMsg = _T("");
  1625. strMsg.Format(_T("检测到线路悬空,线路句柄:%d"),uboxHnd);
  1626. WriteLogin(strMsg);
  1627. #if _DEBUG
  1628. TRACE("检测到线路悬空\n");
  1629. #endif
  1630. }
  1631. break;
  1632. case UBOX_EVENT_STREAM_VOICE: //流式录音事件,param1是录音数据地址,需要转换,unsigned char* pvoice= (unsigned char*)param1
  1633. {
  1634. OnStreamVoicePhonicusb(uboxHnd, (char*)param1, param2);
  1635. CString strMsg = _T("");
  1636. strMsg.Format(_T("流式录音事件,线路句柄:%d"),uboxHnd);
  1637. WriteLogin(strMsg);
  1638. #if _DEBUG
  1639. TRACE("流式录音事件\n");
  1640. #endif
  1641. }
  1642. break;
  1643. case UBOX_EVENT_CALLER_ID: //param1是号码地址 param2是时间地址 param3是姓名地址 param4没有用
  1644. {
  1645. OnCallIdPhonicusb(uboxHnd, (char*)param1);
  1646. //CString strMsg = _T("");
  1647. // strMsg.Format(_T("来电事件:%d,%s"),uboxHnd,(char*)param1);
  1648. // WriteLogin("来电事件");
  1649. #if _DEBUG
  1650. TRACE("来电事件\n");
  1651. #endif
  1652. }
  1653. break;
  1654. case UBOX_EVENT_DTMF_DOWN: //按键事件,param1是按键键值
  1655. {
  1656. OnDtmfKeyPhonicusb(uboxHnd, (char)param1);
  1657. CString strMsg = _T("");
  1658. strMsg.Format(_T("按键事件,线路句柄:%d"),uboxHnd);
  1659. WriteLogin(strMsg);
  1660. #if _DEBUG
  1661. TRACE("按键事件\n");
  1662. #endif
  1663. }
  1664. break;
  1665. case UBOX_EVENT_DTMF_UP:
  1666. break;
  1667. case UBOX_EVENT_ALARM: //报警,param1参照UBOX_ALARM的定义,设备工作不正常,软件退出,检查设备驱动程序是否安装好
  1668. {
  1669. OnDeviceAlarmPhonicusb(uboxHnd);
  1670. CString strMsg = _T("");
  1671. strMsg.Format(_T("报警事件,线路句柄:%d"),uboxHnd);
  1672. WriteLogin(strMsg);
  1673. #if _DEBUG
  1674. TRACE("报警事件\n");
  1675. #endif
  1676. }
  1677. break;
  1678. case UBOX_EVENT_RING_CANCEL: //振铃取消,当末次振铃停止超过6秒,则触发此事件,
  1679. {
  1680. OnRingCancelPhonicusb(uboxHnd);
  1681. CString strMsg = _T("");
  1682. strMsg.Format(_T("振铃取消,线路句柄:%d"),uboxHnd);
  1683. WriteLogin(strMsg);
  1684. #if _DEBUG
  1685. TRACE("振铃取消\n");
  1686. #endif
  1687. }
  1688. break;
  1689. case UBOX_EVENT_LINE_VOLTAGE: //线路电压事件,param1是线路电压值,param1不会出现等于0的电压。
  1690. {
  1691. OnLineVoltagePhonicusb(uboxHnd, param1);
  1692. CString strMsg = _T("");
  1693. strMsg.Format(_T("线路电压事件,线路句柄:%d"),uboxHnd);
  1694. WriteLogin(strMsg);
  1695. #if _DEBUG
  1696. TRACE("线路电压事件\n");
  1697. #endif
  1698. }
  1699. break;
  1700. case UBOX_EVENT_DEVICE_PLUG_IN: //检测到设备插入,回调函数中param1、param2、param3、param4未使用,
  1701. {
  1702. OnPLugInPhonicusb(uboxHnd);
  1703. CString strMsg = _T("");
  1704. strMsg.Format(_T("检测到设备插入,线路句柄:%d"),uboxHnd);
  1705. WriteLogin(strMsg);
  1706. #if _DEBUG
  1707. TRACE("检测到设备插入\n");
  1708. #endif
  1709. }
  1710. break;
  1711. case UBOX_EVENT_DEVICE_ERROR: //设备错误,需要软件重新启动,不然接收不到主叫号码
  1712. {
  1713. OnDeviceErrorPhonicusb(uboxHnd);
  1714. CString strMsg = _T("");
  1715. strMsg.Format(_T("设备错误,线路句柄:%d"),uboxHnd);
  1716. WriteLogin(strMsg);
  1717. #if _DEBUG
  1718. TRACE("设备错误\n");
  1719. #endif
  1720. }
  1721. break;
  1722. case UBOX_EVENT_DEVICE_PLAY_END: //放音完毕
  1723. {
  1724. OnPlayEndPhonicusb(uboxHnd);
  1725. CString strMsg = _T("");
  1726. strMsg.Format(_T("放音完毕,线路句柄:%d"),uboxHnd);
  1727. WriteLogin(strMsg);
  1728. #if _DEBUG
  1729. TRACE("放音完毕\n");
  1730. #endif
  1731. }
  1732. break;
  1733. case UBOX_EVENT_DEVICE_PLAY_ERROR: //放音异常
  1734. {
  1735. OnPlayErrorPhonicusb(uboxHnd);
  1736. CString strMsg = _T("");
  1737. strMsg.Format(_T("放音异常,线路句柄:%d"),uboxHnd);
  1738. WriteLogin(strMsg);
  1739. #if _DEBUG
  1740. TRACE("放音异常\n");
  1741. #endif
  1742. }
  1743. break;
  1744. case UBOX_EVENT_DEVICE_BUSY_TONE: //检测到忙音,对方挂机
  1745. {
  1746. OnToneBusyPhonicusb(uboxHnd);
  1747. CString strMsg = _T("");
  1748. strMsg.Format(_T("检测到忙音,对方挂机,线路句柄:%d"),uboxHnd);
  1749. WriteLogin(strMsg);
  1750. #if _DEBUG
  1751. TRACE("检测到忙音,对方挂机\n");
  1752. #endif
  1753. }
  1754. break;
  1755. case UBOX_EVENT_CALLOUTFINISH: //呼出完成,表示拨号结束
  1756. {
  1757. OnCallOutFinishPhonicusb(uboxHnd);
  1758. CString strMsg = _T("");
  1759. strMsg.Format(_T("呼出完成,表示拨号结束,线路句柄:%d"),uboxHnd);
  1760. WriteLogin(strMsg);
  1761. #if _DEBUG
  1762. TRACE("呼出完成,表示拨号结束\n");
  1763. #endif
  1764. }
  1765. break;
  1766. case UBOX_EVENT_POLARITY: //检测到极性反转
  1767. {
  1768. OnPolarityPhonicusb(uboxHnd, param1);
  1769. CString strMsg = _T("");
  1770. strMsg.Format(_T("检测到极性反转,线路句柄:%d"),uboxHnd);
  1771. WriteLogin(strMsg);
  1772. #if _DEBUG
  1773. TRACE("检测到极性反转\n");
  1774. #endif
  1775. }
  1776. break;
  1777. case UBOX_EVENT_LINE_HOOK_UP: //挂机
  1778. {
  1779. OnHangUpPhonicusb(uboxHnd);
  1780. CString strMsg = _T("");
  1781. strMsg.Format(_T("挂机,线路句柄:%d"),uboxHnd);
  1782. WriteLogin(strMsg);
  1783. #if _DEBUG
  1784. TRACE("挂机\n");
  1785. #endif
  1786. }
  1787. break;
  1788. case UBOX_EVENT_LINE_RING_STOP: //停振 31
  1789. {
  1790. OnRingStopPhonicusb(uboxHnd);
  1791. CString strMsg = _T("");
  1792. strMsg.Format(_T("停振,线路句柄:%d"),uboxHnd);
  1793. WriteLogin(strMsg);
  1794. #if _DEBUG
  1795. TRACE("停振\n");
  1796. #endif
  1797. }
  1798. default:
  1799. break;
  1800. }
  1801. }
  1802. void CUPhoneBoxDlg::OnRestart()
  1803. {
  1804. // TODO: Add your command handler code here
  1805. ::ubox_close();
  1806. int i;
  1807. for (i = 0; i < MAX_DEVICE; i++)
  1808. ubox_device[i].handl_plug_out();
  1809. m_list.DeleteAllItems();
  1810. if (ubox_open(::ProcPhonicCallBack, UBOX_WORK_MODE(0)))
  1811. {
  1812. m_dis.InsertString(m_dis.GetCount(), "open device error");
  1813. m_dis.SetCurSel(m_dis.GetCount() - 1);
  1814. }
  1815. }
  1816. DWORD CUPhoneBoxDlg::GetConnectionID()
  1817. {
  1818. return m_dwConnectionID;
  1819. }
  1820. void CUPhoneBoxDlg::SetConnectionID(DWORD dwConnection)
  1821. {
  1822. m_dwConnectionID = dwConnection;
  1823. }
  1824. void CUPhoneBoxDlg::ProcessChatMessageRequest2(CString sql)
  1825. {
  1826. if (nNeedConn2)
  1827. {
  1828. if (OnConnect() == 0)
  1829. {
  1830. return;
  1831. }
  1832. else
  1833. nNeedConn2 = 0;
  1834. int aa = 100;
  1835. while (m_dwConnectionID == INVALID_SOCKET)
  1836. {
  1837. ::Sleep(50);
  1838. aa--;
  1839. if (aa == 0)break;
  1840. }
  1841. }
  1842. const char *szDataBuf = sql.GetBuffer(0);
  1843. sql.ReleaseBuffer();
  1844. ProcessChatMessageRequest((void*)szDataBuf, strlen(szDataBuf) + 1);
  1845. }
  1846. void CUPhoneBoxDlg::ProcessChatMessageRequest2(BYTE code)
  1847. {
  1848. if (nNeedConn2)
  1849. {
  1850. if (OnConnect() == 0)
  1851. {
  1852. return;
  1853. }
  1854. else
  1855. nNeedConn2 = 0;
  1856. int aa = 100;
  1857. while (m_dwConnectionID == INVALID_SOCKET)
  1858. {
  1859. ::Sleep(50);
  1860. aa--;
  1861. if (aa == 0)break;
  1862. }
  1863. }
  1864. ProcessChatMessageRequest(&code, sizeof(BYTE));
  1865. }
  1866. void CUPhoneBoxDlg::ProcessChatMessageRequest2(BYTE *pData, int length)
  1867. {
  1868. ProcessChatMessageRequest((void*)pData, length);
  1869. }
  1870. BOOL CUPhoneBoxDlg::ProcessChatMessageRequest(void *szDataBuf, int nDataLen)
  1871. {
  1872. g_bReturned2 = 0;
  1873. DWORD dwFromUserID = GetConnectionID();
  1874. WORD wMessageId = (MSG_CHATMESSAGE_REQ + 0X3FFF);
  1875. DWORD dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen;
  1876. BYTE *pSendData = new BYTE[dwDataLen];
  1877. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU*)pSendData;
  1878. memset(pChatMessage, 0x00, dwDataLen);
  1879. g_sendhead.length[98] = 987123768;
  1880. g_sendhead.length[99] = g_nYearpos;
  1881. memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
  1882. pChatMessage->tCommonMsg.dwConnectionID = GetConnectionID();
  1883. pChatMessage->tCommonMsg.wMessageId = wMessageId;
  1884. pChatMessage->dwFromUserID = dwFromUserID;
  1885. pChatMessage->dwToUserID = 15;
  1886. pChatMessage->wMessageLen = nDataLen;
  1887. memcpy(pChatMessage->byFileContent, szDataBuf, nDataLen);
  1888. TMessageHeader tHeader = { 0 };
  1889. tHeader.wMessageId = wMessageId;
  1890. tHeader.dwDataLen = dwDataLen;
  1891. BOOL bRet = 0;
  1892. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
  1893. if (ulSendLen != SOCKET_ERROR)
  1894. {
  1895. bRet = 1;
  1896. }
  1897. delete[] pSendData;
  1898. return bRet;
  1899. }
  1900. BOOL CUPhoneBoxDlg::OnConnect()
  1901. {
  1902. OnDisconnect();
  1903. CString strServerAddress = g_ip;
  1904. char *szServerAddress = strServerAddress.GetBuffer(0);
  1905. strServerAddress.ReleaseBuffer();
  1906. /*for Client, IP and Port can be 0,
  1907. and for Server, IP is LocalIP, and Port is Listening Port*/
  1908. int nResult = m_tClientTunnel.net_OpenSocket(Transport_Client,
  1909. 0,
  1910. HandleClientNetEvent2,
  1911. this);
  1912. if (TRANSPORT_OK != nResult)
  1913. {
  1914. return 0;
  1915. }
  1916. DWORD dwRemoteIPValue = inet_addr(szServerAddress);
  1917. nResult = m_tClientTunnel.net_Connect(dwRemoteIPValue, g_dwCSPort);
  1918. if (TRANSPORT_OK != nResult)
  1919. {
  1920. m_tClientTunnel.net_CloseSocket();
  1921. return 0;
  1922. }
  1923. return ProcessLoginRequest();
  1924. }
  1925. void CUPhoneBoxDlg::ProcessNetEvent(int nEventType, void *pRecvMsg, DWORD dwDataLen)
  1926. {
  1927. if (Transport_ReadEv == nEventType)
  1928. {
  1929. if (NULL == pRecvMsg) return;
  1930. TMessageHeader* pHeader = (TMessageHeader *)pRecvMsg;
  1931. char *pDataBuf = (char *)pRecvMsg + MESSAGE_HEADER_LEN;
  1932. WORD dwMessageID = pHeader->wMessageId;
  1933. switch (dwMessageID)
  1934. {
  1935. //case MSG_LOGIN_RESP:
  1936. case (MSG_LOGIN_RESP + 0X2FFF) :
  1937. {
  1938. LOGIN_RESULT_STRU tLoginResult = { 0 };
  1939. memcpy(&tLoginResult, pDataBuf, sizeof(LOGIN_RESULT_STRU));
  1940. ProcessLoginResponse(&tLoginResult);
  1941. break;
  1942. }
  1943. case MSG_USERINFO_RESP:
  1944. {
  1945. TUSERLIST_INFO_STRU tUserListInfo = { 0 };
  1946. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  1947. // ProcessUserListInfoResponse(&tUserListInfo);
  1948. break;
  1949. }
  1950. case MSG_LOGOUT_RESP:
  1951. {
  1952. TUSERLIST_INFO_STRU tUserListInfo = { 0 };
  1953. memcpy(&tUserListInfo, pDataBuf, sizeof(TUSERLIST_INFO_STRU));
  1954. // ProcessLogoutResponse(&tUserListInfo);
  1955. break;
  1956. }
  1957. //case MSG_CHATMESSAGE_RESP:
  1958. case (MSG_CHATMESSAGE_RESP + 0X4FFF) :
  1959. {
  1960. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
  1961. ProcessChatMessageResponse((void *)pChatMessage);
  1962. break;
  1963. }
  1964. default:
  1965. {
  1966. break;
  1967. }
  1968. }
  1969. }
  1970. else if (Transport_CloseEv == nEventType)
  1971. {
  1972. SetTimer(DISCONNECT_TIMER, 0, NULL);
  1973. }
  1974. ///////
  1975. }
  1976. void CUPhoneBoxDlg::OnDisconnect()
  1977. {
  1978. m_tClientTunnel.net_CloseSocket();
  1979. SetConnectionID(INVALID_SOCKET);
  1980. }
  1981. void CUPhoneBoxDlg::ProcessLoginResponse(void *pLoginResult)
  1982. {
  1983. if (NULL == pLoginResult) return;
  1984. LOGIN_RESULT_STRU *ptLoginResult = (LOGIN_RESULT_STRU *)pLoginResult;
  1985. DWORD dwConnectionID = ptLoginResult->tCommonMsg.dwConnectionID;
  1986. SetConnectionID(dwConnectionID);
  1987. BYTE byResult = ptLoginResult->byResult;
  1988. if (LOGIN_RESULT_SUC == byResult)
  1989. {
  1990. }
  1991. else
  1992. {
  1993. SetTimer(LOGINFAILED_TIMER, 0, NULL);
  1994. }
  1995. CString strCommentInfo("");
  1996. strCommentInfo.Format("%s. 用户代号: %ld",
  1997. ((LOGIN_RESULT_SUC == byResult) ? "登录成功" :
  1998. (LOGIN_RESULT_MULTI == byResult) ? "重复登录" :
  1999. (LOGIN_RESULT_NAMERROR == byResult) ? "名字不存在" :
  2000. (LOGIN_RESULT_PWERROR == byResult) ? "密码错误" : "登录失败"),
  2001. dwConnectionID);
  2002. // MessageBox((CString)strCommentInfo);
  2003. }
  2004. CString newGUID()
  2005. {
  2006. CString str;
  2007. GUID guid;
  2008. CoInitialize(NULL);
  2009. if (S_OK == ::CoCreateGuid(&guid))
  2010. {
  2011. str.Format(
  2012. "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
  2013. guid.Data1,
  2014. guid.Data2,
  2015. guid.Data3,
  2016. guid.Data4[0], guid.Data4[1],
  2017. guid.Data4[2], guid.Data4[3],
  2018. guid.Data4[4], guid.Data4[5],
  2019. guid.Data4[6], guid.Data4[7]);
  2020. }
  2021. CoUninitialize();
  2022. return str.Left(28);
  2023. }
  2024. BOOL CUPhoneBoxDlg::ProcessLoginRequest()
  2025. {
  2026. WORD wMessageId = (MSG_LOGIN_REQ + 0X1FFF);
  2027. TLOGIN_STRU tLogonInfo = { 0 };
  2028. tLogonInfo.tCommonMsg.dwConnectionID = GetConnectionID();
  2029. tLogonInfo.tCommonMsg.wMessageId = wMessageId;
  2030. CString strUserName = newGUID();
  2031. strUserName.TrimLeft();
  2032. strUserName.TrimRight();
  2033. strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
  2034. strUserName.TrimLeft();
  2035. strUserName.TrimRight();
  2036. strcpy(tLogonInfo.tUserInfo.szUserName, strUserName);
  2037. DWORD dwDataLen = sizeof(TLOGIN_STRU);
  2038. TMessageHeader tHeader = { 0 };
  2039. tHeader.wMessageId = wMessageId;
  2040. tHeader.dwDataLen = dwDataLen;
  2041. unsigned long ulSendLen = m_tClientTunnel.net_Send(&tHeader, (void *)&tLogonInfo, dwDataLen);
  2042. if (ulSendLen == SOCKET_ERROR)
  2043. {
  2044. return 0;
  2045. }
  2046. return 1;
  2047. }
  2048. DWORD g_ncount2 = 0;
  2049. CArray<CStringArray, CStringArray>g_List1array;
  2050. DWORD g_nLeng = 0;
  2051. BYTE *g_pData = NULL;
  2052. void CUPhoneBoxDlg::ProcessChatMessageResponse(void *pResponse)
  2053. {
  2054. if (NULL == pResponse) return;
  2055. TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pResponse;
  2056. int nMessageLen = pChatMessage->wMessageLen;
  2057. // if(nMessageLen==0)
  2058. // return;
  2059. if (g_pData)delete[]g_pData; g_pData = NULL;
  2060. g_pData = new BYTE[nMessageLen];
  2061. memcpy(g_pData, pChatMessage->byFileContent, nMessageLen);
  2062. memcpy(&g_sendhead, pChatMessage, sizeof(g_sendhead));
  2063. g_nLeng = nMessageLen;
  2064. if (nMessageLen <= sizeof(DWORD))
  2065. {
  2066. memcpy(&g_ncount2, pChatMessage->byFileContent, sizeof(DWORD));
  2067. }
  2068. g_bReturned2 = 1;
  2069. }
  2070. DWORD FindAppProcessID(CString path)
  2071. {
  2072. try
  2073. {
  2074. HANDLE handle = ::CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
  2075. PROCESSENTRY32 Info;
  2076. Info.dwSize = sizeof(PROCESSENTRY32);
  2077. path.MakeLower();
  2078. if (::Process32First(handle, &Info))
  2079. {
  2080. do
  2081. {
  2082. CString ss = Info.szExeFile;
  2083. ss.MakeLower();
  2084. if (ss.Find(path) != -1 || (!ss.CompareNoCase(path)))
  2085. {
  2086. ::CloseHandle(handle);
  2087. return Info.th32ProcessID;
  2088. }
  2089. } while (::Process32Next(handle, &Info));
  2090. ::CloseHandle(handle);
  2091. }
  2092. return -1;
  2093. }
  2094. catch (...)
  2095. {
  2096. }
  2097. }
  2098. void CUPhoneBoxDlg::OnClose()
  2099. {
  2100. DWORD id = FindAppProcessID("AutoRunUPhoneBox.exe");
  2101. if (id != -1)
  2102. {
  2103. HANDLE ProcessHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
  2104. if (ProcessHandle)TerminateProcess(ProcessHandle, 0);
  2105. }
  2106. CDialog::OnCancel();
  2107. }
  2108. void CUPhoneBoxDlg::OnAutorun() // 设置自动运行(注册表里设置启动项);
  2109. {
  2110. // TODO: Add your command handler code here
  2111. g_bAutoRun = !g_bAutoRun;
  2112. CString version = _T("Version 1.0");
  2113. AfxGetApp()->WriteProfileInt(version, "brun", g_bAutoRun);
  2114. TCHAR szKey[MAX_PATH];
  2115. HKEY hKey = 0;
  2116. DWORD disp = 0;
  2117. lstrcpy(szKey, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
  2118. if (g_bAutoRun)
  2119. {
  2120. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  2121. if (lResult == ERROR_SUCCESS)
  2122. {
  2123. TCHAR szDir[MAX_PATH];
  2124. ::GetModuleFileName(NULL, szDir, MAX_PATH);
  2125. lResult = RegSetValueEx(hKey, "YLGLMSGSERVER", 0, REG_SZ, (const unsigned char*)szDir, lstrlen(szDir));
  2126. RegCloseKey(hKey);
  2127. }
  2128. }
  2129. else
  2130. {
  2131. int lResult = RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &disp);
  2132. if (lResult == ERROR_SUCCESS)
  2133. {
  2134. RegDeleteValue(hKey, "YLGLMSGSERVER");
  2135. RegDeleteKey(hKey, "YLGLMSGSERVER");
  2136. RegCloseKey(hKey);
  2137. }
  2138. }
  2139. }
  2140. void DataToArray(CArray<CStringArray, CStringArray>*List1array)
  2141. {
  2142. List1array->RemoveAll();
  2143. if (g_nLeng == 0)return;
  2144. if (g_sendhead.code[0])
  2145. {
  2146. BYTE *lpszOut = NULL;
  2147. int nOutSize = 0;
  2148. CLzariEx Lzari;
  2149. Lzari.UnCompress(g_pData, g_nLeng, (const BYTE*&)lpszOut, nOutSize);
  2150. CMemFile memfile;
  2151. memfile.Attach(lpszOut, nOutSize);
  2152. Lzari.Release();
  2153. CArchive ar(&memfile, CArchive::load);
  2154. List1array->SetSize(g_sendhead.count[0]);
  2155. for (int ii = 0; ii < List1array->GetSize(); ii++)
  2156. {
  2157. List1array->ElementAt(ii).Serialize(ar);
  2158. }
  2159. ar.Close();
  2160. memfile.Detach();
  2161. }
  2162. else
  2163. {
  2164. CMemFile memfile;
  2165. memfile.Attach(g_pData, g_nLeng);
  2166. CArchive ar(&memfile, CArchive::load);
  2167. List1array->SetSize(g_sendhead.count[0]);
  2168. for (int ii = 0; ii < List1array->GetSize(); ii++)
  2169. {
  2170. List1array->ElementAt(ii).Serialize(ar);
  2171. }
  2172. ar.Close();
  2173. memfile.Detach();
  2174. }
  2175. }
  2176. void DataToArray(CArray<CStringArray, CStringArray>*List1array, CArray<CStringArray, CStringArray>*List2array, CArray<CStringArray, CStringArray>*List3array)
  2177. {
  2178. CArray<CStringArray, CStringArray>*parray[3] = { List1array, List2array, List3array };
  2179. DWORD bytereads = 0;
  2180. for (int i = 0; i < 3; i++)
  2181. {
  2182. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  2183. if (g_sendhead.code[i])
  2184. {
  2185. BYTE *lpszOut = NULL;
  2186. int nOutSize = 0;
  2187. CLzariEx Lzari;
  2188. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  2189. CMemFile memfile;
  2190. memfile.Attach(lpszOut, nOutSize);
  2191. Lzari.Release();
  2192. bytereads += g_sendhead.length[i];
  2193. CArchive ar(&memfile, CArchive::load);
  2194. parray[i]->SetSize(g_sendhead.count[i]);
  2195. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  2196. {
  2197. parray[i]->ElementAt(ii).Serialize(ar);
  2198. }
  2199. ar.Close();
  2200. memfile.Detach();
  2201. }
  2202. else
  2203. {
  2204. CMemFile memfile;
  2205. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  2206. bytereads += g_sendhead.length[i];
  2207. CArchive ar(&memfile, CArchive::load);
  2208. parray[i]->SetSize(g_sendhead.count[i]);
  2209. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  2210. {
  2211. parray[i]->ElementAt(ii).Serialize(ar);
  2212. }
  2213. ar.Close();
  2214. memfile.Detach();
  2215. }
  2216. }
  2217. }
  2218. void DataToArray(CArray<CStringArray, CStringArray>*List1array, CArray<CStringArray, CStringArray>*List2array, CArray<CStringArray, CStringArray>*List3array, CArray<CStringArray, CStringArray>*List4array, CArray<CStringArray, CStringArray>*List5array)
  2219. {
  2220. CArray<CStringArray, CStringArray>*parray[5] = { List1array, List2array, List3array, List4array, List5array };
  2221. DWORD bytereads = 0;
  2222. for (int i = 0; i < 5; i++)
  2223. {
  2224. parray[i]->RemoveAll(); if (g_sendhead.length[i] == 0)continue;
  2225. if (g_sendhead.code[i])
  2226. {
  2227. BYTE *lpszOut = NULL;
  2228. int nOutSize = 0;
  2229. CLzariEx Lzari;
  2230. Lzari.UnCompress(g_pData + bytereads, g_sendhead.length[i], (const BYTE*&)lpszOut, nOutSize);
  2231. CMemFile memfile;
  2232. memfile.Attach(lpszOut, nOutSize);
  2233. Lzari.Release();
  2234. bytereads += g_sendhead.length[i];
  2235. CArchive ar(&memfile, CArchive::load);
  2236. parray[i]->SetSize(g_sendhead.count[i]);
  2237. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  2238. {
  2239. parray[i]->ElementAt(ii).Serialize(ar);
  2240. }
  2241. ar.Close();
  2242. memfile.Detach();
  2243. }
  2244. else
  2245. {
  2246. CMemFile memfile;
  2247. memfile.Attach(g_pData + bytereads, g_sendhead.length[i]);
  2248. bytereads += g_sendhead.length[i];
  2249. CArchive ar(&memfile, CArchive::load);
  2250. parray[i]->SetSize(g_sendhead.count[i]);
  2251. for (int ii = 0; ii < parray[i]->GetSize(); ii++)
  2252. {
  2253. parray[i]->ElementAt(ii).Serialize(ar);
  2254. }
  2255. ar.Close();
  2256. memfile.Detach();
  2257. }
  2258. }
  2259. }
  2260. BOOL FindArray(CStringArray &array, CString str)
  2261. {
  2262. for (int i = 0; i < array.GetSize(); i++)
  2263. {
  2264. if (array.ElementAt(i) == str)return 1;
  2265. }
  2266. return 0;
  2267. }
  2268. BOOL nNeedConn2 = 1;//数据库服务器
  2269. // 获取数据库数据; yearpos = 0 表示的是db数据库;
  2270. void GetListData(BYTE code, CArray<CStringArray, CStringArray>*pListarray1, CString filter, int yearpos, int mode)
  2271. {
  2272. pListarray1->RemoveAll();
  2273. int arraypos = 0;
  2274. switch (code)
  2275. {
  2276. case 80:
  2277. arraypos = 0;
  2278. break;
  2279. case 90:
  2280. arraypos = 1;
  2281. break;
  2282. case 11:
  2283. arraypos = 2;
  2284. break;
  2285. case 138:
  2286. arraypos = 3;
  2287. break;
  2288. case 24:
  2289. arraypos = 4;
  2290. break;
  2291. case 181:
  2292. arraypos = 5;
  2293. break;
  2294. case 65:
  2295. arraypos = 6;
  2296. break;
  2297. case 56:
  2298. arraypos = 7;
  2299. break;
  2300. case 179:
  2301. arraypos = 8;
  2302. break;
  2303. case 53:
  2304. arraypos = 9;
  2305. break;
  2306. }
  2307. CArray<CStringArray, CStringArray>*pListarraySrc = &(g_arraydata[yearpos][arraypos]);
  2308. if (pListarraySrc == NULL)return;
  2309. int size = 0;
  2310. for (int i = 0; i < pListarraySrc->GetSize(); i++)
  2311. {
  2312. if (filter != "")
  2313. {
  2314. if (code == 80)
  2315. {
  2316. if (pListarraySrc->ElementAt(i).ElementAt(4).Find(filter) == -1)continue;
  2317. }
  2318. else if (code == 90)
  2319. {
  2320. if (pListarraySrc->ElementAt(i).ElementAt(3).Find(filter) == -1)continue;
  2321. }
  2322. else if (code == 11)
  2323. {
  2324. if (mode == 0)
  2325. {
  2326. if (pListarraySrc->ElementAt(i).ElementAt(61).Find(filter) == -1 && pListarraySrc->ElementAt(i).ElementAt(62).Find(filter) == -1)continue;
  2327. }
  2328. else if (mode == 1)
  2329. {
  2330. if (pListarraySrc->ElementAt(i).ElementAt(0) != filter)continue;
  2331. }
  2332. }
  2333. else if (code == 138)
  2334. {
  2335. if (pListarraySrc->ElementAt(i).ElementAt(3).Find(filter) == -1 && pListarraySrc->ElementAt(i).ElementAt(4).Find(filter) == -1)continue;
  2336. }
  2337. else if (code == 56)
  2338. {
  2339. if (pListarraySrc->ElementAt(i).ElementAt(22) != filter)continue;
  2340. if (pListarraySrc->ElementAt(i).ElementAt(20) == "5")continue;
  2341. if (pListarraySrc->ElementAt(i).ElementAt(0) == "入册")continue;
  2342. if (pListarraySrc->ElementAt(i).ElementAt(0) == "入底")continue;
  2343. }
  2344. else if (code == 181)
  2345. {
  2346. if (pListarraySrc->ElementAt(i).ElementAt(0) != filter)continue;
  2347. }
  2348. else if (code == 65)
  2349. {
  2350. CString m_phone, datetime;
  2351. int pos = filter.Find("\r\n");
  2352. if (pos == -1)return;
  2353. m_phone = filter.Left(pos);
  2354. datetime = filter.Right(filter.GetLength() - pos - 2);
  2355. if (pListarraySrc->ElementAt(i).ElementAt(0).Find(m_phone) == -1)continue;
  2356. if (pListarraySrc->ElementAt(i).ElementAt(2).Find(datetime) == -1)continue;
  2357. }
  2358. else if (code == 179)
  2359. {
  2360. //if(pListarraySrc->ElementAt(i).ElementAt(0)!=filter)continue;
  2361. }
  2362. else if (code == 53)
  2363. {
  2364. if (pListarraySrc->ElementAt(i).ElementAt(2) != filter)continue;
  2365. }
  2366. pListarray1->SetSize(size + 1, 1);
  2367. pListarray1->ElementAt(size).Copy(pListarraySrc->ElementAt(i));
  2368. size++;
  2369. }
  2370. else
  2371. {
  2372. pListarray1->SetSize(size + 1, 1);
  2373. pListarray1->ElementAt(size).Copy(pListarraySrc->ElementAt(i));
  2374. size++;
  2375. }
  2376. }
  2377. }
  2378. UINT ShowClientThread(DWORD wParam)
  2379. {
  2380. if (g_bok == 0)return 0;
  2381. if (::GetTickCount() - g_tick < 1000) return 0;
  2382. g_tick = ::GetTickCount();
  2383. CUPhoneBoxDlg *pdlg = g_pMainWnd;
  2384. int idpos = int(wParam);
  2385. yearposarray[idpos].RemoveAll();
  2386. idarray[idpos].RemoveAll();
  2387. CArray<CStringArray, CStringArray>Listarray1;
  2388. CArray<CStringArray, CStringArray>Listarray2;
  2389. CArray<CStringArray, CStringArray>Listarray3;//意向客户
  2390. CArray<CStringArray, CStringArray>Listarray4;//老客户
  2391. CString phone = g_phone[idpos];
  2392. CString addareaphone = "%" + phone;
  2393. int i;
  2394. CString str, filter, sql;
  2395. BYTE *pData;
  2396. int failcount = 0;
  2397. ll: if (failcount>3)return 0;
  2398. GetListData(80, &Listarray2, phone, 0, 0);
  2399. GetListData(90, &Listarray3, phone, 0, 0);
  2400. GetListData(11, &Listarray1, phone, 0, 0);
  2401. GetListData(138, &Listarray4, phone, 0, 0);
  2402. GetListData(24, &g_cominfoarray, "", 0, 0);
  2403. if (g_cominfoarray.ElementAt(0).ElementAt(46) == "2" || g_cominfoarray.ElementAt(0).ElementAt(46) == "3" || g_cominfoarray.ElementAt(0).ElementAt(46) == "6" || g_cominfoarray.ElementAt(0).ElementAt(46) == "7")
  2404. g_bChildVersion = 1;
  2405. if (atoi(g_cominfoarray.ElementAt(0).ElementAt(117)))//新摄控本
  2406. g_bNewBooking = 1;
  2407. for (int n = 0; n < Listarray1.GetSize(); n++)
  2408. {
  2409. if (FindArray(idarray[idpos], Listarray1.ElementAt(n).ElementAt(0)))
  2410. {
  2411. break;
  2412. }
  2413. idarray[idpos].Add(Listarray1.ElementAt(n).ElementAt(0));
  2414. yearposarray[idpos].Add(g_nYearpos);
  2415. }
  2416. //}
  2417. if (Listarray2.GetSize() == 0 && Listarray3.GetSize() == 0 && Listarray1.GetSize() == 0 && Listarray4.GetSize() == 0)
  2418. {
  2419. for (int aa = 0; aa < 2; aa++)
  2420. {
  2421. g_nYearpos = aa;
  2422. GetListData(11, &Listarray1, phone, g_nYearpos + 1, 0);
  2423. BOOL bExist = 0;
  2424. for (int n = 0; n < Listarray1.GetSize(); n++)
  2425. {
  2426. if (FindArray(idarray[idpos], Listarray1.ElementAt(n).ElementAt(0)))
  2427. {
  2428. bExist = 1;
  2429. break;
  2430. }
  2431. idarray[idpos].Add(Listarray1.ElementAt(n).ElementAt(0));
  2432. yearposarray[idpos].Add(g_nYearpos);
  2433. }
  2434. if (bExist)break;
  2435. }
  2436. }
  2437. else if (Listarray2.GetSize())
  2438. {
  2439. CLIENTINFO *p = new CLIENTINFO;
  2440. memset(p, 0, sizeof(p));
  2441. p->idpos = idpos;
  2442. strcpy(p->phone, phone);
  2443. strcpy(p->str1, Listarray2.ElementAt(0).ElementAt(1));
  2444. strcpy(p->str2, Listarray2.ElementAt(0).ElementAt(3));
  2445. strcpy(p->str3, Listarray2.ElementAt(0).ElementAt(2));
  2446. g_pMainWnd->PostMessage(WM_USER + 200, (DWORD)p, 3);
  2447. return 0;
  2448. }
  2449. else if (Listarray3.GetSize())//意向客户
  2450. {
  2451. CLIENTINFO *p = new CLIENTINFO;
  2452. memset(p, 0, sizeof(p));
  2453. p->idpos = idpos;
  2454. strcpy(p->phone, phone);
  2455. strcpy(p->str1, Listarray3.ElementAt(0).ElementAt(1));
  2456. strcpy(p->str2, Listarray3.ElementAt(0).ElementAt(2));
  2457. strcpy(p->str3, Listarray3.ElementAt(0).ElementAt(5));
  2458. strcpy(p->str4, Listarray3.ElementAt(0).ElementAt(4));
  2459. strcpy(p->str5, Listarray3.ElementAt(0).ElementAt(8));
  2460. g_pMainWnd->PostMessage(WM_USER + 200, (DWORD)p, 2);
  2461. return 0;
  2462. }
  2463. else if (Listarray4.GetSize())//老客户
  2464. {
  2465. CLIENTINFO *p = new CLIENTINFO;
  2466. memset(p, 0, sizeof(p));
  2467. p->idpos = idpos;
  2468. strcpy(p->phone, phone);
  2469. g_pMainWnd->PostMessage(WM_USER + 200, (DWORD)p, 4);
  2470. return 0;
  2471. }
  2472. if (idarray[idpos].GetSize() == 0)
  2473. {
  2474. CLIENTINFO *p = new CLIENTINFO;
  2475. memset(p, 0, sizeof(p));
  2476. p->idpos = idpos;
  2477. strcpy(p->phone, phone);
  2478. g_pMainWnd->PostMessage(WM_USER + 200, (DWORD)p, 1);
  2479. return 0;
  2480. }
  2481. CLIENTINFO *p = new CLIENTINFO;
  2482. memset(p, 0, sizeof(p));
  2483. p->idpos = idpos;
  2484. strcpy(p->phone, phone);
  2485. g_pMainWnd->PostMessage(WM_USER + 200, (DWORD)p, 0);
  2486. return 0;
  2487. }
  2488. UINT SaveThread(DWORD wParam)
  2489. {
  2490. if (g_bok == 0)return 0;
  2491. CUPhoneBoxDlg *pdlg = g_pMainWnd;
  2492. int idpos = int(wParam);
  2493. CString phone = g_phone[idpos];
  2494. if (phone.GetLength() < 3)return 1;
  2495. CString m_frompath = g_recordpath[idpos]; g_recordpath[idpos].Empty();
  2496. if (::PathFileExists(m_frompath) == 0)return 1;
  2497. CString m_savepath;
  2498. g_phone[idpos] = "";
  2499. yearposarray[idpos].RemoveAll();
  2500. idarray[idpos].RemoveAll();
  2501. CArray<CStringArray, CStringArray>Listarray1;
  2502. CArray<CStringArray, CStringArray>Listarray2;
  2503. CArray<CStringArray, CStringArray>Listarray3;
  2504. CArray<CStringArray, CStringArray>Listarray4;
  2505. int i;
  2506. CString str, filter, sql;
  2507. BYTE *pData;
  2508. int failcount = 0;
  2509. ll: if (failcount > 3)return 0;
  2510. GetListData(80, &Listarray2, phone, 0, 0);
  2511. GetListData(90, &Listarray3, phone, 0, 0);
  2512. GetListData(138, &Listarray4, phone, 0, 0);
  2513. if (Listarray2.GetSize() == 0 && Listarray3.GetSize() == 0 && Listarray4.GetSize() == 0)
  2514. {
  2515. for (int aa = -1; aa < 3; aa++)
  2516. {
  2517. g_nYearpos = aa;
  2518. GetListData(11, &Listarray1, phone, g_nYearpos + 1, 0);
  2519. BOOL bExist = 0;
  2520. for (int n = 0; n < Listarray1.GetSize(); n++)
  2521. {
  2522. if (FindArray(idarray[idpos], Listarray1.ElementAt(n).ElementAt(0)))
  2523. {
  2524. bExist = 1;
  2525. break;
  2526. }
  2527. idarray[idpos].Add(Listarray1.ElementAt(n).ElementAt(0));
  2528. yearposarray[idpos].Add(g_nYearpos);
  2529. }
  2530. if (bExist)break;
  2531. if (idarray[idpos].GetSize())break;//只选一条
  2532. }
  2533. }
  2534. else if (Listarray2.GetSize())
  2535. {
  2536. CString name = Listarray2.ElementAt(0).ElementAt(1);
  2537. CString datetime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
  2538. CString sql;
  2539. sql.Format("insert into [employeephonerecordout]([name],[phoneno],[datetime])values(\
  2540. '%s','%s','%s')", name, phone, datetime);
  2541. g_sendhead.bsql = 1;
  2542. g_nYearpos = -1;
  2543. g_pMainWnd->ProcessChatMessageRequest2(sql);
  2544. for (i = 0; i < 20; i++)
  2545. {
  2546. if (g_bReturned2)break;
  2547. ::Sleep(500);
  2548. }
  2549. if (i >= 20)
  2550. {
  2551. return 1;
  2552. }
  2553. datetime.Replace(":", "");
  2554. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\员工电话(拨出)", NULL);
  2555. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\员工电话(拨出)\\" + name, NULL);
  2556. m_savepath = "\\\\" + g_server2 + "\\电话录音(管理软件)$\\员工电话(拨出)\\" + name + "\\" + datetime + ".mp3";
  2557. try
  2558. {
  2559. if (::PathFileExists(m_frompath))
  2560. {
  2561. ::CopyFile(m_frompath, m_savepath, 0);
  2562. }
  2563. ::DeleteFile(m_frompath);
  2564. }
  2565. catch (...)
  2566. {
  2567. WriteLogin("保存录音文件时出错1");
  2568. }
  2569. return 0;
  2570. }
  2571. else if (Listarray3.GetSize())
  2572. {
  2573. CString name = Listarray3.ElementAt(0).ElementAt(1);
  2574. CString datetime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
  2575. CString sql;
  2576. sql.Format("insert into [client2phonerecordout]([name],[phoneno],[datetime])values(\
  2577. '%s','%s','%s')", name, phone, datetime);
  2578. g_sendhead.bsql = 1;
  2579. g_nYearpos = -1;
  2580. g_pMainWnd->ProcessChatMessageRequest2(sql);
  2581. for (i = 0; i < 20; i++)
  2582. {
  2583. if (g_bReturned2)break;
  2584. ::Sleep(500);
  2585. }
  2586. if (i >= 20)
  2587. {
  2588. return 1;
  2589. }
  2590. datetime.Replace(":", "");
  2591. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\意向客户(拨出)", NULL);
  2592. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\意向客户(拨出)\\" + phone, NULL);
  2593. m_savepath = "\\\\" + g_server2 + "\\电话录音(管理软件)$\\意向客户(拨出)\\" + phone + "\\" + datetime + ".mp3";
  2594. try
  2595. {
  2596. if (::PathFileExists(m_frompath))
  2597. {
  2598. ::CopyFile(m_frompath, m_savepath, 0);
  2599. }
  2600. ::DeleteFile(m_frompath);
  2601. }
  2602. catch (...)
  2603. {
  2604. WriteLogin("保存录音文件时出错1");
  2605. }
  2606. return 0;
  2607. }
  2608. else if (Listarray4.GetSize())
  2609. {
  2610. CString name = Listarray4.ElementAt(0).ElementAt(1);
  2611. name += ",";
  2612. name += Listarray4.ElementAt(0).ElementAt(2);
  2613. name.TrimRight(",");
  2614. CString datetime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
  2615. CString sql;
  2616. sql.Format("insert into [client3phonerecordout]([name],[phoneno],[datetime])values(\
  2617. '%s','%s','%s')", name, phone, datetime);
  2618. g_sendhead.bsql = 1;
  2619. g_nYearpos = -1;
  2620. g_pMainWnd->ProcessChatMessageRequest2(sql);
  2621. for (i = 0; i < 20; i++)
  2622. {
  2623. if (g_bReturned2)break;
  2624. ::Sleep(500);
  2625. }
  2626. if (i >= 20)
  2627. {
  2628. return 1;
  2629. }
  2630. datetime.Replace(":", "");
  2631. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\老客户(拨出)", NULL);
  2632. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\老客户(拨出)\\" + phone, NULL);
  2633. m_savepath = "\\\\" + g_server2 + "\\电话录音(管理软件)$\\老客户(拨出)\\" + phone + "\\" + datetime + ".mp3";
  2634. try
  2635. {
  2636. if (::PathFileExists(m_frompath))
  2637. {
  2638. ::CopyFile(m_frompath, m_savepath, 0);
  2639. }
  2640. ::DeleteFile(m_frompath);
  2641. }
  2642. catch (...)
  2643. {
  2644. WriteLogin("保存录音文件时出错1");
  2645. }
  2646. return 0;
  2647. }
  2648. if (idarray[idpos].GetSize() == 0)
  2649. {
  2650. CString datetime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
  2651. CString sql;
  2652. sql.Format("insert into [unknownphonerecordout]([phoneno],[datetime])values('%s','%s')", phone, datetime);
  2653. g_sendhead.bsql = 1;
  2654. g_nYearpos = -1;
  2655. g_pMainWnd->ProcessChatMessageRequest2(sql);
  2656. for (i = 0; i < 20; i++)
  2657. {
  2658. if (g_bReturned2)break;
  2659. ::Sleep(500);
  2660. }
  2661. if (i >= 20)
  2662. {
  2663. return 1;
  2664. }
  2665. datetime.Replace(":", "");
  2666. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\未知电话(拨出)", NULL);
  2667. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\未知电话(拨出)\\" + phone, NULL);
  2668. m_savepath = "\\\\" + g_server2 + "\\电话录音(管理软件)$\\未知电话(拨出)\\" + phone + "\\" + datetime + ".mp3";
  2669. try
  2670. {
  2671. if (::PathFileExists(m_frompath))
  2672. {
  2673. ::CopyFile(m_frompath, m_savepath, 0);
  2674. }
  2675. ::DeleteFile(m_frompath);
  2676. }
  2677. catch (...)
  2678. {
  2679. WriteLogin("保存录音文件时出错1");
  2680. }
  2681. return 0;
  2682. }
  2683. ///////订单客户
  2684. CString m_id = idarray[idpos].ElementAt(0);
  2685. g_nYearpos = yearposarray[idpos].ElementAt(0);
  2686. GetListData(181, &Listarray1, m_id, g_nYearpos + 1, 0);
  2687. if (Listarray1.GetSize())
  2688. {
  2689. CString m_name1 = Listarray1.ElementAt(0).ElementAt(1);
  2690. CString m_name2 = Listarray1.ElementAt(0).ElementAt(2);
  2691. CString name;
  2692. if (!m_name1.IsEmpty())
  2693. name = m_name1 + ",";
  2694. name += m_name2;
  2695. name.TrimRight(",");
  2696. CString datetime = CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S");
  2697. CString sql;
  2698. sql.Format("insert into [phonerecordout]([name],[phoneno],[datetime])values(\
  2699. '%s','%s','%s')", name, phone, datetime);
  2700. g_sendhead.bsql = 1;
  2701. g_nYearpos = -1;
  2702. g_pMainWnd->ProcessChatMessageRequest2(sql);
  2703. for (i = 0; i < 20; i++)
  2704. {
  2705. if (g_bReturned2)break;
  2706. ::Sleep(500);
  2707. }
  2708. if (i >= 20)
  2709. {
  2710. return 1;
  2711. }
  2712. datetime.Replace(":", "");
  2713. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\客户电话(拨出)", NULL);
  2714. ::CreateDirectory("\\\\" + g_server2 + "\\电话录音(管理软件)$\\客户电话(拨出)\\" + phone, NULL);
  2715. m_savepath = "\\\\" + g_server2 + "\\电话录音(管理软件)$\\客户电话(拨出)\\" + phone + "\\" + datetime + ".mp3";
  2716. try
  2717. {
  2718. if (::PathFileExists(m_frompath))
  2719. {
  2720. ::CopyFile(m_frompath, m_savepath, 0);
  2721. }
  2722. ::DeleteFile(m_frompath);
  2723. }
  2724. catch (...)
  2725. {
  2726. WriteLogin("保存录音文件时出错1");
  2727. }
  2728. return 0;
  2729. }
  2730. return 0;
  2731. }
  2732. void CUPhoneBoxDlg::ShowClient(int lineid, CString phone) // 显示客户详情;
  2733. {
  2734. g_dlgphonecoming[lineid].SetText(lineid, phone);
  2735. g_dlgphonecoming[lineid].ShowWindow(SW_SHOW);
  2736. MyLock lock("CUPhoneBoxDlgShowClient");
  2737. if (phone.IsEmpty())return;
  2738. if (g_phone[lineid] == phone)return;
  2739. g_phone[lineid] = phone;
  2740. if (g_hwnd[lineid])
  2741. {
  2742. #if _DEBUG
  2743. TRACE("显示客户详情,关闭前一线路对话框\n");
  2744. #endif
  2745. ::PostMessage(g_hwnd[lineid], WM_USER + 111, 0, 0);
  2746. }
  2747. AfxBeginThread((AFX_THREADPROC)ShowClientThread, (LPVOID)lineid);
  2748. }
  2749. void CUPhoneBoxDlg::ExitWindow(int lineID, BOOL bSave)
  2750. {
  2751. WriteLogin("ExitWindow");
  2752. g_dlgphonecoming[lineID].ShowWindow(SW_HIDE);
  2753. if (g_bCallOut[lineID])//打出
  2754. {
  2755. if (bSave)
  2756. AfxBeginThread((AFX_THREADPROC)SaveThread, (LPVOID)lineID);
  2757. }
  2758. else//打入
  2759. {
  2760. if (g_hwnd[lineID])
  2761. {
  2762. #if _DEBUG
  2763. TRACE("关闭前对话框并保存\n");
  2764. #endif
  2765. ::PostMessage(g_hwnd[lineID], WM_USER + 111, bSave, 0);
  2766. }
  2767. g_phone[lineID] = "";
  2768. }
  2769. g_bCallOut[lineID] = 1;
  2770. }
  2771. extern CString g_id;
  2772. extern CString g_name1;
  2773. extern CString g_name2;
  2774. void CUPhoneBoxDlg::OnTimer(UINT nIDEvent)
  2775. {
  2776. // TODO: Add your message handler code here and/or call default
  2777. if (DISCONNECT_TIMER == nIDEvent)
  2778. {
  2779. KillTimer(nIDEvent);
  2780. OnDisconnect();
  2781. }
  2782. else if (LOGINFAILED_TIMER == nIDEvent)
  2783. {
  2784. KillTimer(nIDEvent);
  2785. OnDisconnect();
  2786. }
  2787. else if (1 == nIDEvent)
  2788. {
  2789. KillTimer(1);
  2790. m_TrayIcon.Create(this, WM_ICON_NOTIFY, "客户来电显示系统", m_hIcon, IDR_MENUtray); //构造
  2791. // ShowWindow(SW_HIDE); // 隐藏窗口
  2792. #ifdef TEST_WINDOW
  2793. SetTimer(2, 8000, NULL);
  2794. #endif
  2795. }
  2796. else if (2 == nIDEvent)
  2797. {
  2798. KillTimer(2);
  2799. g_bok = 1;
  2800. g_bCallOut[0] = 0;
  2801. ShowClient(0, "18665281860");//18665281860/18666532220
  2802. SetTimer(3, 15000, NULL);
  2803. }
  2804. else if (3 == nIDEvent)
  2805. {
  2806. KillTimer(3);
  2807. ExitWindow(0, 1);
  2808. }
  2809. else if (4 == nIDEvent)
  2810. {
  2811. KillTimer(4);
  2812. ClientBooking(g_id, g_name1, g_name2);
  2813. }
  2814. else if (5 == nIDEvent)
  2815. {
  2816. RefreshData();
  2817. }
  2818. }
  2819. void CUPhoneBoxDlg::ClientBooking(CString id, CString name1, CString name2)
  2820. {
  2821. int pos = GetDlgPos(0);
  2822. if (pos == -1)return;
  2823. g_dlgbooking[pos].m_id = id;
  2824. g_dlgbooking[pos].m_name1 = name1;
  2825. g_dlgbooking[pos].m_name2 = name2;
  2826. g_dlgbooking[pos].Create(146, g_pMainWnd);
  2827. g_dlgbooking[pos].ShowWindow(1);
  2828. }
  2829. void CUPhoneBoxDlg::ShowAllWindow()
  2830. {
  2831. }
  2832. BOOL CheckExist(CString m_phone)
  2833. {
  2834. if (m_phone.IsEmpty())return 1;
  2835. if (m_phone.Left(1) != "1")return 1;
  2836. if (m_phone.GetLength() != 11)return 1;
  2837. CString datetime = CTime::GetCurrentTime().Format("%Y%m%d");
  2838. CArray<CStringArray, CStringArray>Listarray1;
  2839. //
  2840. datetime = datetime + "%";
  2841. g_nYearpos = -1;
  2842. CString filter = "phones='" + m_phone + "' and timestamp like '" + datetime + "'";
  2843. g_sendhead.bsql = 0;
  2844. g_sendhead.code[0] = 65;
  2845. g_sendhead.tabcount = 1;
  2846. g_bReturned2 = 0;
  2847. g_pMainWnd->ProcessChatMessageRequest2(filter);
  2848. int i;
  2849. for ( i = 0; i < 20; i++)
  2850. {
  2851. if (g_bReturned2)break;
  2852. ::Sleep(500);
  2853. }
  2854. if (i >= 20)
  2855. {
  2856. nNeedConn2 = 1;
  2857. return 1;
  2858. }
  2859. DataToArray(&Listarray1);
  2860. //
  2861. // GetListData(65, &Listarray1, m_phone+"\r\n"+datetime, 0, 0);
  2862. if (Listarray1.GetSize())return 1;
  2863. return 0;
  2864. }
  2865. //g_headerpath
  2866. /*
  2867. g_sendhead.code[0]=80;
  2868. g_sendhead.code[1]=90;
  2869. g_sendhead.code[2]=11;
  2870. g_sendhead.code[3]=138;
  2871. g_sendhead.code[4]=24;
  2872. g_sendhead.code[0]=181;
  2873. g_sendhead.code[0]=65;
  2874. g_sendhead.code[0]=56;
  2875. */
  2876. void CUPhoneBoxDlg::ReleaseData()
  2877. {
  2878. for (int i = 0; i < 10; i++)
  2879. {
  2880. for (int j = 0; j < 10; j++)
  2881. {
  2882. g_arraydata[i][j].RemoveAll();
  2883. }
  2884. }
  2885. }
  2886. DWORD g_length = 0;
  2887. BOOL g_bfirst = 1;
  2888. void CUPhoneBoxDlg::RefreshData()//从文件里获取用户数据;
  2889. {
  2890. int filecount = 1;
  2891. if (g_bfirst)
  2892. {
  2893. filecount = 10;
  2894. g_bfirst = 0;
  2895. }
  2896. CString dir = "\\\\" + g_server2 + "\\电话录音(管理软件)$";//未判断这个共享目录是否能打开;
  2897. #if 0
  2898. if (::PathFileExists(dir) == FALSE)
  2899. {
  2900. WriteLogin("共享目录:电话录音(管理软件)$ 不存在!");
  2901. }
  2902. #endif
  2903. CString path1, path2;
  2904. int i;
  2905. for ( i = 0; i < filecount; i++)
  2906. {
  2907. path1.Format("%s\\uphonedata%d.dat", dir, i);//服务端文件;
  2908. path2.Format("%s\\uphonedata%dtemp.dat", g_mainpath, i);//客户端文件;
  2909. ::DeleteFile(path2);
  2910. ::CopyFile(path1, path2, 0);//将path1 拷贝到 path2;
  2911. }
  2912. for (i = 0; i < filecount; i++)
  2913. {
  2914. path1.Format("%s\\uphonedata%dtemp.dat", g_mainpath, i);
  2915. path2.Format("%s\\uphonedata%d.dat", g_mainpath, i);
  2916. if (::PathFileExists(path1))
  2917. {
  2918. ::DeleteFile(path2);
  2919. ::CopyFile(path1, path2, 0);
  2920. }
  2921. }
  2922. CFile fp;
  2923. path2.Format("%s\\uphonedata%d.dat", g_mainpath, 0);
  2924. if (fp.Open(path2, CFile::modeRead) == 0)
  2925. {
  2926. return;
  2927. }
  2928. if (g_length == fp.GetLength())
  2929. {
  2930. fp.Close();
  2931. return;
  2932. }
  2933. g_length = fp.GetLength();
  2934. fp.Close();
  2935. ReleaseData();
  2936. for (i = 0; i < filecount; i++)
  2937. {
  2938. path2.Format("%s\\uphonedata%d.dat", g_mainpath, i);
  2939. if (fp.Open(path2, CFile::modeRead))
  2940. {
  2941. BYTE code;
  2942. DWORD length, arraysize;
  2943. for (int j = 0; j < 10; j++)
  2944. {
  2945. fp.Read(&code, sizeof(BYTE));
  2946. fp.Read(&length, sizeof(DWORD));
  2947. fp.Read(&arraysize, sizeof(DWORD));
  2948. if (length == 0 || arraysize == 0)
  2949. continue;
  2950. BYTE *pData = new BYTE[length];
  2951. fp.Read(pData, length);
  2952. CArray<CStringArray, CStringArray>*List1array = &(g_arraydata[i][j]);
  2953. List1array->RemoveAll();
  2954. if (code)
  2955. {
  2956. BYTE *lpszOut = NULL;
  2957. int nOutSize = 0;
  2958. CLzariEx Lzari;
  2959. Lzari.UnCompress(pData, length, (const BYTE*&)lpszOut, nOutSize);
  2960. CMemFile memfile;
  2961. memfile.Attach(lpszOut, nOutSize);
  2962. CArchive ar(&memfile, CArchive::load);
  2963. List1array->SetSize(arraysize);
  2964. for (int ii = 0; ii < List1array->GetSize(); ii++)
  2965. {
  2966. List1array->ElementAt(ii).Serialize(ar);
  2967. }
  2968. ar.Close();
  2969. memfile.Detach();
  2970. Lzari.Release();
  2971. }
  2972. else
  2973. {
  2974. CMemFile memfile;
  2975. memfile.Attach(pData, length);
  2976. CArchive ar(&memfile, CArchive::load);
  2977. List1array->SetSize(arraysize);
  2978. for (int ii = 0; ii < List1array->GetSize(); ii++)
  2979. {
  2980. List1array->ElementAt(ii).Serialize(ar);
  2981. }
  2982. ar.Close();
  2983. memfile.Detach();
  2984. }
  2985. delete[]pData;
  2986. }
  2987. fp.Close();
  2988. }
  2989. else
  2990. break;
  2991. }
  2992. }