UserDBProcess.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371
  1. ///////////////////////////////////////////////////////////
  2. //
  3. // File:
  4. // UserDBProcess.cpp
  5. // Author:
  6. // 严晓斌
  7. // Date:
  8. // 2008-05-23
  9. // Comments:
  10. // 主要用户信息、权限数据库处理模块
  11. //
  12. ///////////////////////////////////////////////////////////
  13. #include "stdafx.h"
  14. #include "Global.h"
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <memory.h>
  18. #include "Ado.h"
  19. #include "DBConnection.h"
  20. #include "PrintQueue.h"
  21. #include "ChineseRes/resource.h"
  22. //验证用户名、密码是否合法
  23. INT ValidateUser(CHAR *pUserID, CHAR *pUserPwd)
  24. {
  25. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  26. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  27. CADORecordset* pRSet = NULL;
  28. INT iRetCode = 0;
  29. int nRet = 0;
  30. try
  31. {
  32. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  33. {
  34. pRSet = new CADORecordset(g_pADODatabase);
  35. if (NULL == pRSet)
  36. {
  37. nRet = 0;
  38. }
  39. if(!_stricmp(g_strDBType, "PGSQL"))
  40. {
  41. sprintf(strSQLText, "select 1 from t_user_info where uid = \'%s\' and pwd = \'%s\' LIMIT 1", pUserID, pUserPwd);
  42. }
  43. else
  44. {
  45. sprintf(strSQLText, "select top 1 1 from t_user_info where uid = \'%s\' and pwd = \'%s\'", pUserID, pUserPwd);
  46. }
  47. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  48. if (iRetCode == 0)
  49. {
  50. nRet = -1;
  51. }
  52. if (pRSet->GetRecordCount() > 0)
  53. {
  54. nRet = 1;
  55. }
  56. }
  57. }
  58. catch (...)
  59. {
  60. if( pRSet )
  61. {
  62. delete pRSet;
  63. pRSet = NULL;
  64. }
  65. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  66. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  67. nRet = -1;
  68. }
  69. if( pRSet )
  70. {
  71. delete pRSet;
  72. pRSet = NULL;
  73. }
  74. return nRet;
  75. }
  76. //验证用户是否启用
  77. INT ValidateUserEnable(CHAR *pUserID, CHAR *pStatus)
  78. {
  79. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  80. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  81. CString str;
  82. CADORecordset* pRSet = NULL;
  83. INT iRetCode = 0;
  84. int nRecordCount = 0;
  85. try
  86. {
  87. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  88. {
  89. pRSet = new CADORecordset(g_pADODatabase);
  90. if (NULL == pRSet)
  91. {
  92. return -1;
  93. }
  94. sprintf(strSQLText, "select status from t_user_info where uid = \'%s\'", pUserID);
  95. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  96. if (iRetCode == 0)
  97. {
  98. delete pRSet;
  99. pRSet = NULL;
  100. return -1;
  101. }
  102. nRecordCount = pRSet->GetRecordCount();
  103. if (nRecordCount == 0)
  104. {
  105. if( pRSet )
  106. {
  107. delete pRSet;
  108. pRSet = NULL;
  109. }
  110. return 0;
  111. }
  112. if (!pRSet->IsFieldNull("status"))
  113. {
  114. pRSet->GetFieldValue("status", str);
  115. strcpy(pStatus, (char*)(LPCTSTR)str);
  116. }
  117. }
  118. }
  119. catch (...)
  120. {
  121. if( pRSet )
  122. {
  123. delete pRSet;
  124. pRSet = NULL;
  125. }
  126. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  127. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  128. return -1;
  129. }
  130. if( pRSet )
  131. {
  132. delete pRSet;
  133. pRSet = NULL;
  134. }
  135. return 0;
  136. }
  137. //修改密码
  138. INT ModifyPwd(CHAR *pUserID, CHAR *pUserPwd)
  139. {
  140. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  141. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  142. INT iRetCode = 0;
  143. try
  144. {
  145. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  146. {
  147. sprintf(strSQLText, "UPDATE t_user_info SET uid=\'%s\', pwd=\'%s\'",
  148. pUserID, pUserPwd);
  149. iRetCode = g_pADODatabase->Execute(strSQLText);
  150. }
  151. }
  152. catch (...)
  153. {
  154. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  155. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  156. return 0;
  157. }
  158. return iRetCode;
  159. }
  160. //添加用户信息
  161. INT AddUser(CHAR *pUserID, CHAR *pUserPwd, CHAR *pUserName, CHAR *pTel, CHAR *pMobileTel, CHAR *pEmail, CHAR *pFax, int nStatus)
  162. {
  163. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  164. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  165. INT iRetCode = 0;
  166. try
  167. {
  168. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  169. {
  170. sprintf(strSQLText, "insert into t_user_info(uid, pwd, username, tel, " \
  171. "mobiletel, email, fax, status) values (\'%s\', \'%s\', \'%s\', \'%s\', " \
  172. "\'%s\', \'%s\', \'%s\', %d)",
  173. pUserID, pUserPwd, pUserName, pTel, pMobileTel, pEmail, pFax, nStatus);
  174. iRetCode = g_pADODatabase->Execute(strSQLText);
  175. }
  176. }
  177. catch (...)
  178. {
  179. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  180. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  181. return 0;
  182. }
  183. return iRetCode;
  184. }
  185. //修改用户信息
  186. INT EditUser(int nID, CHAR *pUserName, CHAR *pTel, CHAR *pMobileTel, CHAR *pEmail, CHAR *pFax, int nStatus)
  187. {
  188. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  189. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  190. INT iRetCode = 0;
  191. try
  192. {
  193. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  194. {
  195. sprintf(strSQLText, "update t_user_info set username = \'%s\', tel = \'%s\', " \
  196. "mobiletel = \'%s\', email = \'%s\', fax = \'%s\', status = %d "
  197. "where id = %d",
  198. pUserName, pTel, pMobileTel, pEmail, pFax, nStatus, nID);
  199. iRetCode = g_pADODatabase->Execute(strSQLText);
  200. }
  201. }
  202. catch (...)
  203. {
  204. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  205. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  206. return 0;
  207. }
  208. return iRetCode;
  209. }
  210. //添加用户信息列表
  211. INT InsertUserList(CListCtrl *list)
  212. {
  213. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  214. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  215. CADORecordset* pRSet = NULL;
  216. INT iRetCode = 0;
  217. CString cstrValue, str;
  218. INT nID;
  219. CHAR strUserIDGet[MAX_NAME_LENGTH + 1] = "";
  220. CHAR strUserNameGet[MAX_NAME_LENGTH + 1] = "";
  221. int nRet = 0;
  222. CString strTel, strMobileTel, strEmail, strFax, strStatus;
  223. try
  224. {
  225. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  226. {
  227. pRSet = new CADORecordset(g_pADODatabase);
  228. if (NULL == pRSet)
  229. {
  230. nRet = -1;
  231. }
  232. sprintf(strSQLText, "select * from t_user_info where uid != \'admin\' order by id asc");
  233. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  234. if (iRetCode == 0)
  235. {
  236. nRet = -1;
  237. }
  238. if (pRSet->GetRecordCount() == 0)
  239. {
  240. nRet = -1;
  241. }
  242. for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ )
  243. {
  244. //获取Id
  245. if (!pRSet->IsFieldNull("ID"))
  246. {
  247. pRSet->GetFieldValue("ID", nID);
  248. cstrValue.Format("%d", nID);
  249. //list->SetItemText( i, 0, cstrValue );
  250. list->InsertItem(i, cstrValue);
  251. }
  252. //获取用户名
  253. if (!pRSet->IsFieldNull("uid"))
  254. {
  255. pRSet->GetFieldValue("uid", cstrValue);
  256. strcpy(strUserIDGet, (char*)(LPCTSTR)cstrValue);
  257. list->SetItemText( i, 1, cstrValue );
  258. }
  259. //获取用户姓名
  260. if (!pRSet->IsFieldNull("username"))
  261. {
  262. pRSet->GetFieldValue("username", cstrValue);
  263. strcpy(strUserNameGet, (char*)(LPCTSTR)cstrValue);
  264. list->SetItemText( i, 2, cstrValue );
  265. }
  266. else
  267. {
  268. list->SetItemText( i, 2, "" );
  269. }
  270. //获取电话
  271. if (!pRSet->IsFieldNull("tel"))
  272. {
  273. pRSet->GetFieldValue("tel", strTel);
  274. list->SetItemText( i, 3, strTel );
  275. }
  276. //获取手机
  277. if (!pRSet->IsFieldNull("mobiletel"))
  278. {
  279. pRSet->GetFieldValue("mobiletel", strMobileTel);
  280. list->SetItemText( i, 4, strMobileTel );
  281. }
  282. //获取Email
  283. if (!pRSet->IsFieldNull("email"))
  284. {
  285. pRSet->GetFieldValue("email", strEmail);
  286. list->SetItemText( i, 5, strEmail );
  287. }
  288. //获取Fax
  289. if (!pRSet->IsFieldNull("fax"))
  290. {
  291. pRSet->GetFieldValue("fax", strFax);
  292. list->SetItemText( i, 6, strFax );
  293. }
  294. //获取状态
  295. if (!pRSet->IsFieldNull("status"))
  296. {
  297. pRSet->GetFieldValue("status", strStatus);
  298. if( atoi(strStatus) == 0 )
  299. {
  300. str.LoadString(IDS_COMBO_ENABLE);
  301. list->SetItemText( i, 7, str);
  302. }
  303. else if( atoi(strStatus) == 1 )
  304. {
  305. str.LoadString(IDS_COMBO_DISABLE);
  306. list->SetItemText( i, 7, str );
  307. }
  308. }
  309. pRSet->MoveNext();
  310. }
  311. }
  312. }
  313. catch (...)
  314. {
  315. if( pRSet )
  316. {
  317. delete pRSet;
  318. pRSet = NULL;
  319. }
  320. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  321. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  322. nRet = -1;
  323. }
  324. if( pRSet )
  325. {
  326. delete pRSet;
  327. pRSet = NULL;
  328. }
  329. return nRet;
  330. }
  331. //删除用户信息 By 表自增ID
  332. INT DelUserInfo(int ID)
  333. {
  334. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  335. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  336. INT iRetCode = 0;
  337. try
  338. {
  339. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  340. {
  341. sprintf(strSQLText, "Delete from t_user_info where id = %d", ID);
  342. iRetCode = g_pADODatabase->Execute(strSQLText);
  343. }
  344. }
  345. catch (...)
  346. {
  347. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  348. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  349. return 0;
  350. }
  351. return iRetCode;
  352. }
  353. //删除用户角色信息
  354. INT DelUserRoleInfo(CHAR *pUserID)
  355. {
  356. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  357. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  358. INT iRetCode = 0;
  359. try
  360. {
  361. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  362. {
  363. sprintf(strSQLText, "Delete from t_role_user where userid = \'%s\'", pUserID);
  364. iRetCode = g_pADODatabase->Execute(strSQLText);
  365. }
  366. }
  367. catch (...)
  368. {
  369. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  370. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  371. return 0;
  372. }
  373. return iRetCode;
  374. }
  375. //删除用户已分配权限
  376. INT DelUserEquipInfo(CHAR *pUserID)
  377. {
  378. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  379. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  380. INT iRetCode = 0;
  381. try
  382. {
  383. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  384. {
  385. sprintf(strSQLText, "Delete from t_role_equip where userid = \'%s\'", pUserID);
  386. iRetCode = g_pADODatabase->Execute(strSQLText);
  387. }
  388. }
  389. catch (...)
  390. {
  391. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  392. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  393. return 0;
  394. }
  395. return iRetCode;
  396. }
  397. //得到用户信息最大ID
  398. INT GetUserMaxID( CHAR *pMaxID )
  399. {
  400. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  401. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  402. CString str;
  403. CADORecordset* pRSet = NULL;
  404. INT iRetCode = 0;
  405. int nRecordCount = 0;
  406. try
  407. {
  408. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  409. {
  410. pRSet = new CADORecordset(g_pADODatabase);
  411. if (NULL == pRSet)
  412. {
  413. return -1;
  414. }
  415. sprintf(strSQLText, "select id from t_user_info order by ID desc LIMIT 1");
  416. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  417. if (iRetCode == 0)
  418. {
  419. delete pRSet;
  420. pRSet = NULL;
  421. return -1;
  422. }
  423. nRecordCount = pRSet->GetRecordCount();
  424. if (nRecordCount == 0)
  425. {
  426. if( pRSet )
  427. {
  428. delete pRSet;
  429. pRSet = NULL;
  430. }
  431. return 0;
  432. }
  433. if (!pRSet->IsFieldNull("id"))
  434. {
  435. pRSet->GetFieldValue("id", str);
  436. strcpy(pMaxID, (char*)(LPCTSTR)str);
  437. }
  438. }
  439. }
  440. catch (...)
  441. {
  442. if( pRSet )
  443. {
  444. delete pRSet;
  445. pRSet = NULL;
  446. }
  447. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  448. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  449. return -1;
  450. }
  451. if( pRSet )
  452. {
  453. delete pRSet;
  454. pRSet = NULL;
  455. }
  456. return 0;
  457. }
  458. //得到用户信息ID
  459. INT GetUserID( CHAR *pID, CHAR *pUserID )
  460. {
  461. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  462. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  463. CString str;
  464. CADORecordset* pRSet = NULL;
  465. INT iRetCode = 0;
  466. int nRecordCount = 0;
  467. try
  468. {
  469. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  470. {
  471. pRSet = new CADORecordset(g_pADODatabase);
  472. if (NULL == pRSet)
  473. {
  474. return -1;
  475. }
  476. sprintf(strSQLText, "select id from t_user_info where uid = \'%s\'", pUserID);
  477. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  478. if (iRetCode == 0)
  479. {
  480. delete pRSet;
  481. pRSet = NULL;
  482. return -1;
  483. }
  484. nRecordCount = pRSet->GetRecordCount();
  485. if (nRecordCount == 0)
  486. {
  487. if( pRSet )
  488. {
  489. delete pRSet;
  490. pRSet = NULL;
  491. }
  492. return 0;
  493. }
  494. if (!pRSet->IsFieldNull("id"))
  495. {
  496. pRSet->GetFieldValue("id", str);
  497. strcpy(pID, (char*)(LPCTSTR)str);
  498. }
  499. if( pRSet )
  500. {
  501. delete pRSet;
  502. pRSet = NULL;
  503. }
  504. return nRecordCount;
  505. }
  506. }
  507. catch (...)
  508. {
  509. if( pRSet )
  510. {
  511. delete pRSet;
  512. pRSet = NULL;
  513. }
  514. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  515. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  516. return -1;
  517. }
  518. if( pRSet )
  519. {
  520. delete pRSet;
  521. pRSet = NULL;
  522. }
  523. return 0;
  524. }
  525. //添加用户组信息列表
  526. INT InsertUserGroupInfoList(CListCtrl *list, CHAR *pSQLText)
  527. {
  528. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  529. //CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  530. CADORecordset* pRSet = NULL;
  531. INT iRetCode = 0;
  532. int nRet = 0;
  533. CString strID, strGroupName, strGroupDesc;
  534. try
  535. {
  536. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  537. {
  538. pRSet = new CADORecordset(g_pADODatabase);
  539. if (NULL == pRSet)
  540. nRet = -1;
  541. iRetCode = pRSet->Open(pSQLText, CADORecordset::openQuery);
  542. if (iRetCode == 0)
  543. {
  544. nRet = -1;
  545. }
  546. if (pRSet->GetRecordCount() == 0)
  547. {
  548. nRet = -1;
  549. }
  550. for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ )
  551. {
  552. //ID
  553. if (!pRSet->IsFieldNull("ID"))
  554. {
  555. pRSet->GetFieldValue("ID", strID);
  556. list->InsertItem(i, strID);
  557. }
  558. //组名称
  559. if( !pRSet->IsFieldNull("groupname") )
  560. {
  561. pRSet->GetFieldValue("groupname", strGroupName);
  562. list->SetItemText( i, 1, strGroupName );
  563. }
  564. //组描述
  565. if( !pRSet->IsFieldNull("groupdesc") )
  566. {
  567. pRSet->GetFieldValue("groupdesc", strGroupDesc);
  568. list->SetItemText( i, 2, strGroupDesc );
  569. }
  570. pRSet->MoveNext();
  571. }
  572. }
  573. }
  574. catch (...)
  575. {
  576. if( pRSet )
  577. {
  578. delete pRSet;
  579. pRSet = NULL;
  580. }
  581. sprintf(strMsg, g_strErrorExecSql, pSQLText);
  582. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  583. nRet = -1;
  584. }
  585. if( pRSet )
  586. {
  587. delete pRSet;
  588. pRSet = NULL;
  589. }
  590. return nRet;
  591. }
  592. //添加用户组信息
  593. INT AddUserGroupInfo(CHAR *pGroupName, CHAR *pGroupDesc)
  594. {
  595. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  596. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  597. INT iRetCode = 0;
  598. try
  599. {
  600. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  601. {
  602. sprintf(strSQLText, "insert into t_user_group(groupname, groupdesc) values (\'%s\', " \
  603. "\'%s\')", pGroupName, pGroupDesc);
  604. iRetCode = g_pADODatabase->Execute(strSQLText);
  605. }
  606. }
  607. catch (...)
  608. {
  609. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  610. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  611. return 0;
  612. }
  613. return iRetCode;
  614. }
  615. //修改用户组信息
  616. INT EditUserGroupInfo(int nID, CHAR *pGroupName, CHAR *pGroupDesc)
  617. {
  618. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  619. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  620. INT iRetCode = 0;
  621. try
  622. {
  623. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  624. {
  625. sprintf(strSQLText, "update t_user_group set groupname = \'%s\', groupdesc = \'%s\' " \
  626. " where id = %d",
  627. pGroupName, pGroupDesc, nID);
  628. iRetCode = g_pADODatabase->Execute(strSQLText);
  629. }
  630. }
  631. catch (...)
  632. {
  633. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  634. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  635. return 0;
  636. }
  637. return iRetCode;
  638. }
  639. //删除用户组信息
  640. INT DelUserGroupInfo(int nID)
  641. {
  642. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  643. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  644. INT iRetCode = 0;
  645. try
  646. {
  647. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  648. {
  649. sprintf(strSQLText, "delete from t_user_group where id = %d", nID);
  650. iRetCode = g_pADODatabase->Execute(strSQLText);
  651. }
  652. }
  653. catch (...)
  654. {
  655. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  656. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  657. return 0;
  658. }
  659. return iRetCode;
  660. }
  661. //得到用户组信息最大ID
  662. INT GetUserGroupMaxID( CHAR *pMaxID )
  663. {
  664. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  665. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  666. CString str;
  667. CADORecordset* pRSet = NULL;
  668. INT iRetCode = 0;
  669. int nRecordCount = 0;
  670. try
  671. {
  672. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  673. {
  674. pRSet = new CADORecordset(g_pADODatabase);
  675. if (NULL == pRSet)
  676. {
  677. return -1;
  678. }
  679. sprintf(strSQLText, "select id from t_user_group order by ID desc LIMIT 1");
  680. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  681. if (iRetCode == 0)
  682. {
  683. delete pRSet;
  684. pRSet = NULL;
  685. return -1;
  686. }
  687. nRecordCount = pRSet->GetRecordCount();
  688. if (nRecordCount == 0)
  689. {
  690. if( pRSet )
  691. {
  692. delete pRSet;
  693. pRSet = NULL;
  694. }
  695. return 0;
  696. }
  697. if (!pRSet->IsFieldNull("id"))
  698. {
  699. pRSet->GetFieldValue("id", str);
  700. strcpy(pMaxID, (char*)(LPCTSTR)str);
  701. }
  702. }
  703. }
  704. catch (...)
  705. {
  706. if( pRSet )
  707. {
  708. delete pRSet;
  709. pRSet = NULL;
  710. }
  711. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  712. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  713. return -1;
  714. }
  715. if( pRSet )
  716. {
  717. delete pRSet;
  718. pRSet = NULL;
  719. }
  720. return 0;
  721. }
  722. //添加用户权限信息列表
  723. INT InsertUserPurviewInfoList(CListCtrl *list, CHAR *pSQLText)
  724. {
  725. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  726. //CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  727. CADORecordset* pRSet = NULL;
  728. INT iRetCode = 0;
  729. int nRet = 0;
  730. CString strID, strPurviewName, strPurviewDesc;
  731. try
  732. {
  733. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  734. {
  735. pRSet = new CADORecordset(g_pADODatabase);
  736. if (NULL == pRSet)
  737. nRet = -1;
  738. iRetCode = pRSet->Open(pSQLText, CADORecordset::openQuery);
  739. if (iRetCode == 0)
  740. {
  741. nRet = -1;
  742. }
  743. if (pRSet->GetRecordCount() == 0)
  744. {
  745. nRet = -1;
  746. }
  747. for( int i = 0; i < (int)pRSet->GetRecordCount(); i++ )
  748. {
  749. //ID
  750. if (!pRSet->IsFieldNull("ID"))
  751. {
  752. pRSet->GetFieldValue("ID", strID);
  753. list->InsertItem(i, strID);
  754. }
  755. //权限名称
  756. if( !pRSet->IsFieldNull("purview_name") )
  757. {
  758. pRSet->GetFieldValue("purview_name", strPurviewName);
  759. list->SetItemText( i, 1, strPurviewName );
  760. }
  761. //权限描述
  762. if( !pRSet->IsFieldNull("purview_desc") )
  763. {
  764. pRSet->GetFieldValue("purview_desc", strPurviewDesc);
  765. list->SetItemText( i, 2, strPurviewDesc );
  766. }
  767. pRSet->MoveNext();
  768. }
  769. }
  770. }
  771. catch (...)
  772. {
  773. if( pRSet )
  774. {
  775. delete pRSet;
  776. pRSet = NULL;
  777. }
  778. sprintf(strMsg, g_strErrorExecSql, pSQLText);
  779. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  780. nRet = -1;
  781. }
  782. if( pRSet )
  783. {
  784. delete pRSet;
  785. pRSet = NULL;
  786. }
  787. return nRet;
  788. }
  789. //添加用户权限信息
  790. INT AddUserPurviewInfo(CHAR *pPurviewName, CHAR *pPurviewDesc)
  791. {
  792. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  793. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  794. INT iRetCode = 0;
  795. try
  796. {
  797. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  798. {
  799. sprintf(strSQLText, "insert into t_user_purview(purview_name, purview_desc) values (\'%s\', " \
  800. "\'%s\')", pPurviewName, pPurviewDesc);
  801. iRetCode = g_pADODatabase->Execute(strSQLText);
  802. }
  803. }
  804. catch (...)
  805. {
  806. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  807. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  808. return 0;
  809. }
  810. return iRetCode;
  811. }
  812. //修改用户权限信息
  813. INT EditUserPurviewInfo(int nID, CHAR *pPurviewName, CHAR *pPurviewDesc)
  814. {
  815. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  816. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  817. INT iRetCode = 0;
  818. try
  819. {
  820. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  821. {
  822. sprintf(strSQLText, "update t_user_purview set purview_name = \'%s\', purview_desc = \'%s\' " \
  823. " where id = %d",
  824. pPurviewName, pPurviewDesc, nID);
  825. iRetCode = g_pADODatabase->Execute(strSQLText);
  826. }
  827. }
  828. catch (...)
  829. {
  830. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  831. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  832. return 0;
  833. }
  834. return iRetCode;
  835. }
  836. //删除用户权限信息
  837. INT DelUserPurviewInfo(int nID)
  838. {
  839. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  840. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  841. INT iRetCode = 0;
  842. try
  843. {
  844. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  845. {
  846. sprintf(strSQLText, "delete from t_user_purview where id = %d", nID);
  847. iRetCode = g_pADODatabase->Execute(strSQLText);
  848. }
  849. }
  850. catch (...)
  851. {
  852. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  853. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  854. return 0;
  855. }
  856. return iRetCode;
  857. }
  858. //得到用户权限信息最大ID
  859. INT GetUserPurviewMaxID( CHAR *pMaxID )
  860. {
  861. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  862. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  863. CString str;
  864. CADORecordset* pRSet = NULL;
  865. INT iRetCode = 0;
  866. int nRecordCount = 0;
  867. try
  868. {
  869. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  870. {
  871. pRSet = new CADORecordset(g_pADODatabase);
  872. if (NULL == pRSet)
  873. {
  874. return -1;
  875. }
  876. sprintf(strSQLText, "select id from t_user_purview order by ID desc LIMIT 1");
  877. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  878. if (iRetCode == 0)
  879. {
  880. delete pRSet;
  881. pRSet = NULL;
  882. return -1;
  883. }
  884. nRecordCount = pRSet->GetRecordCount();
  885. if (nRecordCount == 0)
  886. {
  887. if( pRSet )
  888. {
  889. delete pRSet;
  890. pRSet = NULL;
  891. }
  892. return 0;
  893. }
  894. if (!pRSet->IsFieldNull("id"))
  895. {
  896. pRSet->GetFieldValue("id", str);
  897. strcpy(pMaxID, (char*)(LPCTSTR)str);
  898. }
  899. }
  900. }
  901. catch (...)
  902. {
  903. if( pRSet )
  904. {
  905. delete pRSet;
  906. pRSet = NULL;
  907. }
  908. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  909. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  910. return -1;
  911. }
  912. if( pRSet )
  913. {
  914. delete pRSet;
  915. pRSet = NULL;
  916. }
  917. return 0;
  918. }
  919. //得到组权限已分配列表
  920. INT GetUserGroupPurviewAllocList( int nGroupID, CHAR *pGroupPurViewAllocIDList )
  921. {
  922. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  923. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  924. CString strID;
  925. CADORecordset* pRSet = NULL;
  926. INT iRetCode = 0;
  927. int nCount = 0, i;
  928. strcpy(pGroupPurViewAllocIDList, "");
  929. try
  930. {
  931. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  932. {
  933. pRSet = new CADORecordset(g_pADODatabase);
  934. if (NULL == pRSet)
  935. {
  936. return -1;
  937. }
  938. sprintf(strSQLText, "select id from t_user_purview where id not in " \
  939. "(select purview_id from t_user_group_purview "\
  940. "where group_id = %d) order by id asc", nGroupID);
  941. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  942. if (iRetCode == 0)
  943. {
  944. delete pRSet;
  945. pRSet = NULL;
  946. return -1;
  947. }
  948. nCount = pRSet->GetRecordCount();
  949. if (nCount == 0)
  950. {
  951. if( pRSet )
  952. {
  953. delete pRSet;
  954. pRSet = NULL;
  955. }
  956. return 0;
  957. }
  958. for( i = 0; i < nCount; i++ )
  959. {
  960. // 获取区域名称
  961. if (!pRSet->IsFieldNull("id"))
  962. {
  963. pRSet->GetFieldValue("id", strID);
  964. }
  965. strcat(pGroupPurViewAllocIDList, strID);
  966. strcat(pGroupPurViewAllocIDList, ",");
  967. pRSet->MoveNext();
  968. }
  969. if( pRSet )
  970. {
  971. delete pRSet;
  972. pRSet = NULL;
  973. }
  974. return nCount;
  975. }
  976. }
  977. catch (...)
  978. {
  979. if( pRSet )
  980. {
  981. delete pRSet;
  982. pRSet = NULL;
  983. }
  984. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  985. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  986. return -1;
  987. }
  988. if( pRSet )
  989. {
  990. delete pRSet;
  991. pRSet = NULL;
  992. }
  993. return 0;
  994. }
  995. //得到组权限未分配列表
  996. INT GetUserGroupPurviewNotAllocList( int nGroupID, CHAR *pGroupPurViewNotAllocIDList )
  997. {
  998. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  999. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1000. CString strID;
  1001. CADORecordset* pRSet = NULL;
  1002. INT iRetCode = 0;
  1003. int nCount = 0, i;
  1004. strcpy(pGroupPurViewNotAllocIDList, "");
  1005. try
  1006. {
  1007. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1008. {
  1009. pRSet = new CADORecordset(g_pADODatabase);
  1010. if (NULL == pRSet)
  1011. {
  1012. return -1;
  1013. }
  1014. sprintf(strSQLText, "select id from t_user_purview where id in " \
  1015. "(select purview_id from t_user_group_purview "\
  1016. "where group_id = %d) order by id asc", nGroupID);
  1017. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1018. if (iRetCode == 0)
  1019. {
  1020. delete pRSet;
  1021. pRSet = NULL;
  1022. return -1;
  1023. }
  1024. nCount = pRSet->GetRecordCount();
  1025. if (nCount == 0)
  1026. {
  1027. if( pRSet )
  1028. {
  1029. delete pRSet;
  1030. pRSet = NULL;
  1031. }
  1032. return 0;
  1033. }
  1034. for( i = 0; i < nCount; i++ )
  1035. {
  1036. // 获取区域名称
  1037. if (!pRSet->IsFieldNull("id"))
  1038. {
  1039. pRSet->GetFieldValue("id", strID);
  1040. }
  1041. strcat(pGroupPurViewNotAllocIDList, strID);
  1042. strcat(pGroupPurViewNotAllocIDList, ",");
  1043. pRSet->MoveNext();
  1044. }
  1045. if( pRSet )
  1046. {
  1047. delete pRSet;
  1048. pRSet = NULL;
  1049. }
  1050. return nCount;
  1051. }
  1052. }
  1053. catch (...)
  1054. {
  1055. if( pRSet )
  1056. {
  1057. delete pRSet;
  1058. pRSet = NULL;
  1059. }
  1060. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1061. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1062. return -1;
  1063. }
  1064. if( pRSet )
  1065. {
  1066. delete pRSet;
  1067. pRSet = NULL;
  1068. }
  1069. return 0;
  1070. }
  1071. //得到权限名称
  1072. INT GetUserPurviewName( int nID, CHAR *pPurviewName )
  1073. {
  1074. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1075. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1076. CString str;
  1077. CADORecordset* pRSet = NULL;
  1078. INT iRetCode = 0;
  1079. int nRecordCount = 0;
  1080. try
  1081. {
  1082. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1083. {
  1084. pRSet = new CADORecordset(g_pADODatabase);
  1085. if (NULL == pRSet)
  1086. {
  1087. return -1;
  1088. }
  1089. sprintf(strSQLText, "select purview_name from t_user_purview where id=%d", nID);
  1090. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1091. if (iRetCode == 0)
  1092. {
  1093. delete pRSet;
  1094. pRSet = NULL;
  1095. return -1;
  1096. }
  1097. nRecordCount = pRSet->GetRecordCount();
  1098. if (nRecordCount == 0)
  1099. {
  1100. if( pRSet )
  1101. {
  1102. delete pRSet;
  1103. pRSet = NULL;
  1104. }
  1105. return 0;
  1106. }
  1107. if (!pRSet->IsFieldNull("purview_name"))
  1108. {
  1109. pRSet->GetFieldValue("purview_name", str);
  1110. strcpy(pPurviewName, (char*)(LPCTSTR)str);
  1111. }
  1112. }
  1113. }
  1114. catch (...)
  1115. {
  1116. if( pRSet )
  1117. {
  1118. delete pRSet;
  1119. pRSet = NULL;
  1120. }
  1121. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1122. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1123. return -1;
  1124. }
  1125. if( pRSet )
  1126. {
  1127. delete pRSet;
  1128. pRSet = NULL;
  1129. }
  1130. return 0;
  1131. }
  1132. //得到权限ID
  1133. INT GetUserPurviewID( CHAR *pID, CHAR *pPurviewName )
  1134. {
  1135. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1136. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1137. CString str;
  1138. CADORecordset* pRSet = NULL;
  1139. INT iRetCode = 0;
  1140. int nRecordCount = 0;
  1141. try
  1142. {
  1143. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1144. {
  1145. pRSet = new CADORecordset(g_pADODatabase);
  1146. if (NULL == pRSet)
  1147. {
  1148. return -1;
  1149. }
  1150. sprintf(strSQLText, "select id from t_user_purview where purview_name=\'%s\'",
  1151. pPurviewName);
  1152. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1153. if (iRetCode == 0)
  1154. {
  1155. delete pRSet;
  1156. pRSet = NULL;
  1157. return -1;
  1158. }
  1159. nRecordCount = pRSet->GetRecordCount();
  1160. if (nRecordCount == 0)
  1161. {
  1162. if( pRSet )
  1163. {
  1164. delete pRSet;
  1165. pRSet = NULL;
  1166. }
  1167. return 0;
  1168. }
  1169. if (!pRSet->IsFieldNull("id"))
  1170. {
  1171. pRSet->GetFieldValue("id", str);
  1172. strcpy(pID, (char*)(LPCTSTR)str);
  1173. }
  1174. if( pRSet )
  1175. {
  1176. delete pRSet;
  1177. pRSet = NULL;
  1178. }
  1179. return nRecordCount;
  1180. }
  1181. }
  1182. catch (...)
  1183. {
  1184. if( pRSet )
  1185. {
  1186. delete pRSet;
  1187. pRSet = NULL;
  1188. }
  1189. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1190. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1191. return -1;
  1192. }
  1193. if( pRSet )
  1194. {
  1195. delete pRSet;
  1196. pRSet = NULL;
  1197. }
  1198. return 0;
  1199. }
  1200. //得到权限ID
  1201. INT GetUserPurviewID( int nGroupID, CHAR *pID, CHAR *pPurviewName )
  1202. {
  1203. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1204. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1205. CString str;
  1206. CADORecordset* pRSet = NULL;
  1207. INT iRetCode = 0;
  1208. int nRecordCount = 0;
  1209. try
  1210. {
  1211. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1212. {
  1213. pRSet = new CADORecordset(g_pADODatabase);
  1214. if (NULL == pRSet)
  1215. {
  1216. return -1;
  1217. }
  1218. sprintf(strSQLText, "select purview_id from t_user_group_purview a, t_user_purview b " \
  1219. "where a.purview_id = b.id and b.purview_name=\'%s\' and a.group_id = %d",
  1220. pPurviewName, nGroupID);
  1221. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1222. if (iRetCode == 0)
  1223. {
  1224. delete pRSet;
  1225. pRSet = NULL;
  1226. return -1;
  1227. }
  1228. nRecordCount = pRSet->GetRecordCount();
  1229. if (nRecordCount == 0)
  1230. {
  1231. if( pRSet )
  1232. {
  1233. delete pRSet;
  1234. pRSet = NULL;
  1235. }
  1236. return 0;
  1237. }
  1238. if (!pRSet->IsFieldNull("purview_id"))
  1239. {
  1240. pRSet->GetFieldValue("purview_id", str);
  1241. strcpy(pID, (char*)(LPCTSTR)str);
  1242. }
  1243. if( pRSet )
  1244. {
  1245. delete pRSet;
  1246. pRSet = NULL;
  1247. }
  1248. return nRecordCount;
  1249. }
  1250. }
  1251. catch (...)
  1252. {
  1253. if( pRSet )
  1254. {
  1255. delete pRSet;
  1256. pRSet = NULL;
  1257. }
  1258. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1259. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1260. return -1;
  1261. }
  1262. if( pRSet )
  1263. {
  1264. delete pRSet;
  1265. pRSet = NULL;
  1266. }
  1267. return 0;
  1268. }
  1269. //添加用户组权限信息
  1270. INT AddUserGroupPurviewInfo(int nGroupID, int nPurviewID, CHAR *pPurviewDesc)
  1271. {
  1272. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1273. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1274. INT iRetCode = 0;
  1275. try
  1276. {
  1277. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1278. {
  1279. sprintf(strSQLText, "insert into t_user_group_purview(group_id, purview_id, group_purview_desc) values (%d, %d, " \
  1280. "\'%s\')", nGroupID, nPurviewID, pPurviewDesc);
  1281. iRetCode = g_pADODatabase->Execute(strSQLText);
  1282. }
  1283. }
  1284. catch (...)
  1285. {
  1286. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1287. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1288. return 0;
  1289. }
  1290. return iRetCode;
  1291. }
  1292. //删除用户组权限信息
  1293. INT DelUserGroupPurviewInfo(int nGroupID, int nPurviewID)
  1294. {
  1295. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1296. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1297. INT iRetCode = 0;
  1298. try
  1299. {
  1300. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1301. {
  1302. sprintf(strSQLText, "delete from t_user_group_purview where group_id = %d and purview_id=%d",
  1303. nGroupID, nPurviewID);
  1304. iRetCode = g_pADODatabase->Execute(strSQLText);
  1305. }
  1306. }
  1307. catch (...)
  1308. {
  1309. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1310. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1311. return 0;
  1312. }
  1313. return iRetCode;
  1314. }
  1315. //得到已隶属于户组列表
  1316. INT GetUserGroupAllocList( CHAR *pUserID, CHAR *pGroupAllocIDList )
  1317. {
  1318. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1319. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1320. CString strID;
  1321. CADORecordset* pRSet = NULL;
  1322. INT iRetCode = 0;
  1323. int nCount = 0, i;
  1324. strcpy(pGroupAllocIDList, "");
  1325. try
  1326. {
  1327. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1328. {
  1329. pRSet = new CADORecordset(g_pADODatabase);
  1330. if (NULL == pRSet)
  1331. {
  1332. return -1;
  1333. }
  1334. sprintf(strSQLText, "select id from t_user_group where id not in " \
  1335. "(select group_id from t_role_user "\
  1336. "where userid = \'%s\') order by id asc", pUserID);
  1337. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1338. if (iRetCode == 0)
  1339. {
  1340. delete pRSet;
  1341. pRSet = NULL;
  1342. return -1;
  1343. }
  1344. nCount = pRSet->GetRecordCount();
  1345. if (nCount == 0)
  1346. {
  1347. if( pRSet )
  1348. {
  1349. delete pRSet;
  1350. pRSet = NULL;
  1351. }
  1352. return 0;
  1353. }
  1354. for( i = 0; i < nCount; i++ )
  1355. {
  1356. // 获取用户组ID
  1357. if (!pRSet->IsFieldNull("id"))
  1358. {
  1359. pRSet->GetFieldValue("id", strID);
  1360. }
  1361. strcat(pGroupAllocIDList, strID);
  1362. strcat(pGroupAllocIDList, ",");
  1363. pRSet->MoveNext();
  1364. }
  1365. if( pRSet )
  1366. {
  1367. delete pRSet;
  1368. pRSet = NULL;
  1369. }
  1370. return nCount;
  1371. }
  1372. }
  1373. catch (...)
  1374. {
  1375. if( pRSet )
  1376. {
  1377. delete pRSet;
  1378. pRSet = NULL;
  1379. }
  1380. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1381. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1382. return -1;
  1383. }
  1384. if( pRSet )
  1385. {
  1386. delete pRSet;
  1387. pRSet = NULL;
  1388. }
  1389. return 0;
  1390. }
  1391. //得到未隶属于户组列表
  1392. INT GetUserGroupNotAllocList( CHAR *pUserID, CHAR *pGroupNotAllocIDList )
  1393. {
  1394. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1395. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1396. CString strID;
  1397. CADORecordset* pRSet = NULL;
  1398. INT iRetCode = 0;
  1399. int nCount = 0, i;
  1400. strcpy(pGroupNotAllocIDList, "");
  1401. try
  1402. {
  1403. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1404. {
  1405. pRSet = new CADORecordset(g_pADODatabase);
  1406. if (NULL == pRSet)
  1407. {
  1408. return -1;
  1409. }
  1410. sprintf(strSQLText, "select id from t_user_group where id in " \
  1411. "(select group_id from t_role_user "\
  1412. "where userid = \'%s\') order by id asc", pUserID);
  1413. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1414. if (iRetCode == 0)
  1415. {
  1416. delete pRSet;
  1417. pRSet = NULL;
  1418. return -1;
  1419. }
  1420. nCount = pRSet->GetRecordCount();
  1421. if (nCount == 0)
  1422. {
  1423. if( pRSet )
  1424. {
  1425. delete pRSet;
  1426. pRSet = NULL;
  1427. }
  1428. return 0;
  1429. }
  1430. for( i = 0; i < nCount; i++ )
  1431. {
  1432. // 获取用户组ID
  1433. if (!pRSet->IsFieldNull("id"))
  1434. {
  1435. pRSet->GetFieldValue("id", strID);
  1436. }
  1437. strcat(pGroupNotAllocIDList, strID);
  1438. strcat(pGroupNotAllocIDList, ",");
  1439. pRSet->MoveNext();
  1440. }
  1441. if( pRSet )
  1442. {
  1443. delete pRSet;
  1444. pRSet = NULL;
  1445. }
  1446. return nCount;
  1447. }
  1448. }
  1449. catch (...)
  1450. {
  1451. if( pRSet )
  1452. {
  1453. delete pRSet;
  1454. pRSet = NULL;
  1455. }
  1456. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1457. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1458. return -1;
  1459. }
  1460. if( pRSet )
  1461. {
  1462. delete pRSet;
  1463. pRSet = NULL;
  1464. }
  1465. return 0;
  1466. }
  1467. //得到用户组名称
  1468. INT GetUserGroupName( int nID, CHAR *pGroupName )
  1469. {
  1470. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1471. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1472. CString str;
  1473. CADORecordset* pRSet = NULL;
  1474. INT iRetCode = 0;
  1475. int nRecordCount = 0;
  1476. try
  1477. {
  1478. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1479. {
  1480. pRSet = new CADORecordset(g_pADODatabase);
  1481. if (NULL == pRSet)
  1482. {
  1483. return -1;
  1484. }
  1485. sprintf(strSQLText, "select groupname from t_user_group where id=%d", nID);
  1486. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1487. if (iRetCode == 0)
  1488. {
  1489. delete pRSet;
  1490. pRSet = NULL;
  1491. return -1;
  1492. }
  1493. nRecordCount = pRSet->GetRecordCount();
  1494. if (nRecordCount == 0)
  1495. {
  1496. if( pRSet )
  1497. {
  1498. delete pRSet;
  1499. pRSet = NULL;
  1500. }
  1501. return 0;
  1502. }
  1503. if (!pRSet->IsFieldNull("groupname"))
  1504. {
  1505. pRSet->GetFieldValue("groupname", str);
  1506. strcpy(pGroupName, (char*)(LPCTSTR)str);
  1507. }
  1508. }
  1509. }
  1510. catch (...)
  1511. {
  1512. if( pRSet )
  1513. {
  1514. delete pRSet;
  1515. pRSet = NULL;
  1516. }
  1517. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1518. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1519. return -1;
  1520. }
  1521. if( pRSet )
  1522. {
  1523. delete pRSet;
  1524. pRSet = NULL;
  1525. }
  1526. return 0;
  1527. }
  1528. //得到用户组ID
  1529. INT GetUserGroupID( CHAR *pID, CHAR *pGroupName )
  1530. {
  1531. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1532. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1533. CString str;
  1534. CADORecordset* pRSet = NULL;
  1535. INT iRetCode = 0;
  1536. int nRecordCount = 0;
  1537. try
  1538. {
  1539. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1540. {
  1541. pRSet = new CADORecordset(g_pADODatabase);
  1542. if (NULL == pRSet)
  1543. {
  1544. return -1;
  1545. }
  1546. sprintf(strSQLText, "select id from t_user_group where groupname=\'%s\'",
  1547. pGroupName);
  1548. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1549. if (iRetCode == 0)
  1550. {
  1551. delete pRSet;
  1552. pRSet = NULL;
  1553. return -1;
  1554. }
  1555. nRecordCount = pRSet->GetRecordCount();
  1556. if (nRecordCount == 0)
  1557. {
  1558. if( pRSet )
  1559. {
  1560. delete pRSet;
  1561. pRSet = NULL;
  1562. }
  1563. return 0;
  1564. }
  1565. if (!pRSet->IsFieldNull("id"))
  1566. {
  1567. pRSet->GetFieldValue("id", str);
  1568. strcpy(pID, (char*)(LPCTSTR)str);
  1569. }
  1570. if( pRSet )
  1571. {
  1572. delete pRSet;
  1573. pRSet = NULL;
  1574. }
  1575. return nRecordCount;
  1576. }
  1577. }
  1578. catch (...)
  1579. {
  1580. if( pRSet )
  1581. {
  1582. delete pRSet;
  1583. pRSet = NULL;
  1584. }
  1585. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1586. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1587. return -1;
  1588. }
  1589. if( pRSet )
  1590. {
  1591. delete pRSet;
  1592. pRSet = NULL;
  1593. }
  1594. return 0;
  1595. }
  1596. //得到用户组ID
  1597. INT GetUserGroupID( CHAR *pUserID, CHAR *pID, CHAR *pGroupName )
  1598. {
  1599. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1600. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1601. CString str;
  1602. CADORecordset* pRSet = NULL;
  1603. INT iRetCode = 0;
  1604. int nRecordCount = 0;
  1605. try
  1606. {
  1607. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1608. {
  1609. pRSet = new CADORecordset(g_pADODatabase);
  1610. if (NULL == pRSet)
  1611. {
  1612. return -1;
  1613. }
  1614. sprintf(strSQLText, "select group_id from t_role_user a, t_user_group b " \
  1615. "where a.group_id = b.id and b.groupname=\'%s\' and a.userid = \'%s\'",
  1616. pGroupName, pUserID);
  1617. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1618. if (iRetCode == 0)
  1619. {
  1620. delete pRSet;
  1621. pRSet = NULL;
  1622. return -1;
  1623. }
  1624. nRecordCount = pRSet->GetRecordCount();
  1625. if (nRecordCount == 0)
  1626. {
  1627. if( pRSet )
  1628. {
  1629. delete pRSet;
  1630. pRSet = NULL;
  1631. }
  1632. return 0;
  1633. }
  1634. if (!pRSet->IsFieldNull("group_id"))
  1635. {
  1636. pRSet->GetFieldValue("group_id", str);
  1637. strcpy(pID, (char*)(LPCTSTR)str);
  1638. }
  1639. if( pRSet )
  1640. {
  1641. delete pRSet;
  1642. pRSet = NULL;
  1643. }
  1644. return nRecordCount;
  1645. }
  1646. }
  1647. catch (...)
  1648. {
  1649. if( pRSet )
  1650. {
  1651. delete pRSet;
  1652. pRSet = NULL;
  1653. }
  1654. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1655. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1656. return -1;
  1657. }
  1658. if( pRSet )
  1659. {
  1660. delete pRSet;
  1661. pRSet = NULL;
  1662. }
  1663. return 0;
  1664. }
  1665. //添加用户角色信息
  1666. INT AddUserPurviewInfo(CHAR *pUserID, int nGroupID, CHAR *pPurviewDesc)
  1667. {
  1668. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1669. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1670. INT iRetCode = 0;
  1671. try
  1672. {
  1673. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1674. {
  1675. sprintf(strSQLText, "insert into t_role_user(userid, group_id, roledesc) values (\'%s\', %d, " \
  1676. "\'%s\')", pUserID, nGroupID, pPurviewDesc);
  1677. iRetCode = g_pADODatabase->Execute(strSQLText);
  1678. }
  1679. }
  1680. catch (...)
  1681. {
  1682. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1683. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1684. return 0;
  1685. }
  1686. return iRetCode;
  1687. }
  1688. //删除用户角色信息
  1689. INT DelUserPurviewInfo(CHAR *pUserID, int nGroupID)
  1690. {
  1691. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1692. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1693. INT iRetCode = 0;
  1694. try
  1695. {
  1696. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1697. {
  1698. sprintf(strSQLText, "delete from t_role_user where userid = \'%s\' and group_id=%d",
  1699. pUserID, nGroupID);
  1700. iRetCode = g_pADODatabase->Execute(strSQLText);
  1701. }
  1702. }
  1703. catch (...)
  1704. {
  1705. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1706. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1707. return 0;
  1708. }
  1709. return iRetCode;
  1710. }
  1711. //插入时间计划
  1712. INT InsertDatePlan( int nPlanType, CHAR *pPlanID, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
  1713. {
  1714. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1715. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1716. INT iRetCode = 0;
  1717. try
  1718. {
  1719. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1720. {
  1721. sprintf(strSQLText, "insert into t_plan_info(plantype, planid, starttime, endtime, " \
  1722. "startweekofday, endweekofday) values (%d, \'%s\', %d, %d, %d, %d) ",
  1723. nPlanType, pPlanID, nStartHours, nEndHours, nStartWeek, nEndWeek);
  1724. iRetCode = g_pADODatabase->Execute(strSQLText);
  1725. }
  1726. }
  1727. catch (...)
  1728. {
  1729. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1730. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1731. return 0;
  1732. }
  1733. return iRetCode;
  1734. }
  1735. //插入时间计划
  1736. INT InsertDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort, int nStartHours, int nEndHours, int nStartWeek, int nEndWeek )
  1737. {
  1738. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1739. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1740. INT iRetCode = 0;
  1741. try
  1742. {
  1743. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1744. {
  1745. sprintf(strSQLText, "insert into t_plan_info(plantype, equip_type_id, equip_id, port, starttime, endtime, " \
  1746. "startweekofday, endweekofday) values (%d, %d, %d, %d, %d, %d, %d, %d) ",
  1747. nPlanType, nEquipTypeID, nEquipID, nPort, nStartHours, nEndHours, nStartWeek, nEndWeek);
  1748. iRetCode = g_pADODatabase->Execute(strSQLText);
  1749. }
  1750. }
  1751. catch (...)
  1752. {
  1753. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1754. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1755. return 0;
  1756. }
  1757. return iRetCode;
  1758. }
  1759. //删除原有的时间计划
  1760. INT DeleteDatePlan( int nPlanType, CHAR *pPlanID )
  1761. {
  1762. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1763. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1764. INT iRetCode = 0;
  1765. try
  1766. {
  1767. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1768. {
  1769. sprintf(strSQLText, "delete from t_plan_info where planid = \'%s\' and plantype=%d",
  1770. pPlanID, nPlanType);
  1771. iRetCode = g_pADODatabase->Execute(strSQLText);
  1772. }
  1773. }
  1774. catch (...)
  1775. {
  1776. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1777. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1778. return 0;
  1779. }
  1780. return iRetCode;
  1781. }
  1782. //删除原有的时间计划
  1783. INT DeleteDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort )
  1784. {
  1785. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1786. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1787. INT iRetCode = 0;
  1788. try
  1789. {
  1790. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1791. {
  1792. sprintf(strSQLText, "delete from t_plan_info where equip_type_id = %d and equip_id = %d and port = %d and plantype=%d",
  1793. nEquipTypeID, nEquipID, nPort, nPlanType);
  1794. iRetCode = g_pADODatabase->Execute(strSQLText);
  1795. }
  1796. }
  1797. catch (...)
  1798. {
  1799. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1800. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1801. return 0;
  1802. }
  1803. return iRetCode;
  1804. }
  1805. //删除原有的时间计划
  1806. INT DeleteDatePlan( int nPlanType, int nEquipTypeID, int nEquipID )
  1807. {
  1808. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  1809. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  1810. INT iRetCode = 0;
  1811. try
  1812. {
  1813. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1814. {
  1815. sprintf(strSQLText, "delete from t_plan_info where equip_type_id = %d and equip_id = %d and plantype=%d",
  1816. nEquipTypeID, nEquipID, nPlanType);
  1817. iRetCode = g_pADODatabase->Execute(strSQLText);
  1818. }
  1819. }
  1820. catch (...)
  1821. {
  1822. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1823. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1824. return 0;
  1825. }
  1826. return iRetCode;
  1827. }
  1828. //得到时间计划
  1829. INT GetDatePlan( int nPlanType, CHAR *pPlanID, unsigned char nBufDate[7][24] )
  1830. {
  1831. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1832. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1833. CString str;
  1834. CADORecordset* pRSet = NULL;
  1835. INT iRetCode = 0;
  1836. int nRecordCount = 0;
  1837. double fStartTime = 0,fEndTime = 0;
  1838. int nStartWeek = 0,nEndWeek = 0;
  1839. try
  1840. {
  1841. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1842. {
  1843. pRSet = new CADORecordset(g_pADODatabase);
  1844. if (NULL == pRSet)
  1845. {
  1846. return -1;
  1847. }
  1848. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  1849. "from t_plan_info where planid=\'%s\' and plantype = %d",
  1850. pPlanID, nPlanType);
  1851. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1852. if (iRetCode == 0)
  1853. {
  1854. delete pRSet;
  1855. pRSet = NULL;
  1856. return -1;
  1857. }
  1858. nRecordCount = pRSet->GetRecordCount();
  1859. if (nRecordCount == 0)
  1860. {
  1861. if( pRSet )
  1862. {
  1863. delete pRSet;
  1864. pRSet = NULL;
  1865. }
  1866. return 0;
  1867. }
  1868. for( int i = 0; i < nRecordCount; i++ )
  1869. {
  1870. if (!pRSet->IsFieldNull("starttime"))
  1871. {
  1872. pRSet->GetFieldValue("starttime", fStartTime);
  1873. }
  1874. if (!pRSet->IsFieldNull("endtime"))
  1875. {
  1876. pRSet->GetFieldValue("endtime", fEndTime);
  1877. }
  1878. if (!pRSet->IsFieldNull("startweekofday"))
  1879. {
  1880. pRSet->GetFieldValue("startweekofday", nStartWeek);
  1881. }
  1882. if (!pRSet->IsFieldNull("endweekofday"))
  1883. {
  1884. pRSet->GetFieldValue("endweekofday", nEndWeek);
  1885. }
  1886. for(int y = nStartWeek;y<nEndWeek+1;y++)
  1887. {
  1888. for(int x = int(fStartTime);x<int(fEndTime)+1;x++)
  1889. {
  1890. nBufDate[y][x] = 15;
  1891. }
  1892. }
  1893. pRSet->MoveNext();
  1894. }
  1895. if( pRSet )
  1896. {
  1897. delete pRSet;
  1898. pRSet = NULL;
  1899. }
  1900. return nRecordCount;
  1901. }
  1902. }
  1903. catch (...)
  1904. {
  1905. if( pRSet )
  1906. {
  1907. delete pRSet;
  1908. pRSet = NULL;
  1909. }
  1910. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  1911. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  1912. return -1;
  1913. }
  1914. if( pRSet )
  1915. {
  1916. delete pRSet;
  1917. pRSet = NULL;
  1918. }
  1919. return 0;
  1920. }
  1921. //得到时间计划
  1922. INT GetDatePlan( int nPlanType, int nEquipTypeID, int nEquipID, int nPort, unsigned char nBufDate[7][24] )
  1923. {
  1924. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  1925. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  1926. CString str;
  1927. CADORecordset* pRSet = NULL;
  1928. INT iRetCode = 0;
  1929. int nRecordCount = 0;
  1930. double fStartTime = 0,fEndTime = 0;
  1931. int nStartWeek = 0,nEndWeek = 0;
  1932. try
  1933. {
  1934. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  1935. {
  1936. pRSet = new CADORecordset(g_pADODatabase);
  1937. if (NULL == pRSet)
  1938. {
  1939. return -1;
  1940. }
  1941. sprintf(strSQLText, "select starttime, endtime, startweekofday, endweekofday " \
  1942. "from t_plan_info where equip_type_id=%d and equip_id = %d and port = %d and plantype = %d",
  1943. nEquipTypeID, nEquipID, nPort, nPlanType);
  1944. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  1945. if (iRetCode == 0)
  1946. {
  1947. delete pRSet;
  1948. pRSet = NULL;
  1949. return -1;
  1950. }
  1951. nRecordCount = pRSet->GetRecordCount();
  1952. if (nRecordCount == 0)
  1953. {
  1954. if( pRSet )
  1955. {
  1956. delete pRSet;
  1957. pRSet = NULL;
  1958. }
  1959. return 0;
  1960. }
  1961. for( int i = 0; i < nRecordCount; i++ )
  1962. {
  1963. if (!pRSet->IsFieldNull("starttime"))
  1964. {
  1965. pRSet->GetFieldValue("starttime", fStartTime);
  1966. }
  1967. if (!pRSet->IsFieldNull("endtime"))
  1968. {
  1969. pRSet->GetFieldValue("endtime", fEndTime);
  1970. }
  1971. if (!pRSet->IsFieldNull("startweekofday"))
  1972. {
  1973. pRSet->GetFieldValue("startweekofday", nStartWeek);
  1974. }
  1975. if (!pRSet->IsFieldNull("endweekofday"))
  1976. {
  1977. pRSet->GetFieldValue("endweekofday", nEndWeek);
  1978. }
  1979. for(int y = nStartWeek;y<nEndWeek+1;y++)
  1980. {
  1981. for(int x = int(fStartTime);x<int(fEndTime)+1;x++)
  1982. {
  1983. nBufDate[y][x] = 15;
  1984. }
  1985. }
  1986. pRSet->MoveNext();
  1987. }
  1988. if( pRSet )
  1989. {
  1990. delete pRSet;
  1991. pRSet = NULL;
  1992. }
  1993. return nRecordCount;
  1994. }
  1995. }
  1996. catch (...)
  1997. {
  1998. if( pRSet )
  1999. {
  2000. delete pRSet;
  2001. pRSet = NULL;
  2002. }
  2003. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2004. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2005. return -1;
  2006. }
  2007. if( pRSet )
  2008. {
  2009. delete pRSet;
  2010. pRSet = NULL;
  2011. }
  2012. return 0;
  2013. }
  2014. //得到组权限ID列表
  2015. INT GetUserGroupPurviewIDList( CHAR *pUserID, CHAR *pGroupPurViewIDList )
  2016. {
  2017. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2018. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2019. CString strID;
  2020. CADORecordset* pRSet = NULL;
  2021. INT iRetCode = 0;
  2022. int nCount = 0, i;
  2023. strcpy(pGroupPurViewIDList, "");
  2024. try
  2025. {
  2026. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2027. {
  2028. pRSet = new CADORecordset(g_pADODatabase);
  2029. if (NULL == pRSet)
  2030. {
  2031. return -1;
  2032. }
  2033. sprintf(strSQLText, "select group_id from t_role_user " \
  2034. "where userid = \'%s\'", pUserID);
  2035. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2036. if (iRetCode == 0)
  2037. {
  2038. delete pRSet;
  2039. pRSet = NULL;
  2040. return -1;
  2041. }
  2042. nCount = pRSet->GetRecordCount();
  2043. if (nCount == 0)
  2044. {
  2045. if( pRSet )
  2046. {
  2047. delete pRSet;
  2048. pRSet = NULL;
  2049. }
  2050. return 0;
  2051. }
  2052. for( i = 0; i < nCount; i++ )
  2053. {
  2054. // 获取区域名称
  2055. if (!pRSet->IsFieldNull("group_id"))
  2056. {
  2057. pRSet->GetFieldValue("group_id", strID);
  2058. }
  2059. strcat(pGroupPurViewIDList, strID);
  2060. strcat(pGroupPurViewIDList, ",");
  2061. pRSet->MoveNext();
  2062. }
  2063. if( pRSet )
  2064. {
  2065. delete pRSet;
  2066. pRSet = NULL;
  2067. }
  2068. return nCount;
  2069. }
  2070. }
  2071. catch (...)
  2072. {
  2073. if( pRSet )
  2074. {
  2075. delete pRSet;
  2076. pRSet = NULL;
  2077. }
  2078. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2079. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2080. return -1;
  2081. }
  2082. if( pRSet )
  2083. {
  2084. delete pRSet;
  2085. pRSet = NULL;
  2086. }
  2087. return 0;
  2088. }
  2089. //得到用户可控房间ID列表
  2090. INT GetUserRoomIDList( CHAR *pUserID, CHAR *pUserRoomIDList )
  2091. {
  2092. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2093. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2094. CString strID;
  2095. CADORecordset* pRSet = NULL;
  2096. INT iRetCode = 0;
  2097. int nCount = 0, i;
  2098. strcpy(pUserRoomIDList, "");
  2099. try
  2100. {
  2101. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2102. {
  2103. pRSet = new CADORecordset(g_pADODatabase);
  2104. if (NULL == pRSet)
  2105. {
  2106. return -1;
  2107. }
  2108. if( strcmp(pUserID, "admin") == 0 )
  2109. {
  2110. sprintf(strSQLText, "select id as room_id from t_base_room");
  2111. }
  2112. else
  2113. {
  2114. sprintf(strSQLText, "select distinct room_id from t_role_equip " \
  2115. "where userid = \'%s\'", pUserID);
  2116. }
  2117. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2118. if (iRetCode == 0)
  2119. {
  2120. delete pRSet;
  2121. pRSet = NULL;
  2122. return -1;
  2123. }
  2124. nCount = pRSet->GetRecordCount();
  2125. if (nCount == 0)
  2126. {
  2127. if( pRSet )
  2128. {
  2129. delete pRSet;
  2130. pRSet = NULL;
  2131. }
  2132. return 0;
  2133. }
  2134. for( i = 0; i < nCount; i++ )
  2135. {
  2136. // 获取区域名称
  2137. if (!pRSet->IsFieldNull("room_id"))
  2138. {
  2139. pRSet->GetFieldValue("room_id", strID);
  2140. }
  2141. strcat(pUserRoomIDList, strID);
  2142. strcat(pUserRoomIDList, ",");
  2143. pRSet->MoveNext();
  2144. }
  2145. if( pRSet )
  2146. {
  2147. delete pRSet;
  2148. pRSet = NULL;
  2149. }
  2150. return nCount;
  2151. }
  2152. }
  2153. catch (...)
  2154. {
  2155. if( pRSet )
  2156. {
  2157. delete pRSet;
  2158. pRSet = NULL;
  2159. }
  2160. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2161. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2162. return -1;
  2163. }
  2164. if( pRSet )
  2165. {
  2166. delete pRSet;
  2167. pRSet = NULL;
  2168. }
  2169. return 0;
  2170. }
  2171. //得到用户可控设备ID列表
  2172. INT GetUserEquipIDList( CHAR *pUserID, CHAR *pUserEquipTypeIDList, CHAR *pUserEquipIDList )
  2173. {
  2174. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2175. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2176. CString strEquipTypeID, strEquipID;
  2177. CADORecordset* pRSet = NULL;
  2178. INT iRetCode = 0;
  2179. int nCount = 0, i;
  2180. strcpy(pUserEquipIDList, "");
  2181. strcpy(pUserEquipTypeIDList, "");
  2182. try
  2183. {
  2184. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2185. {
  2186. pRSet = new CADORecordset(g_pADODatabase);
  2187. if (NULL == pRSet)
  2188. {
  2189. return -1;
  2190. }
  2191. if( strcmp(pUserID, "admin") == 0 )
  2192. {
  2193. sprintf(strSQLText,
  2194. "select id, equip_type_id from t_view_equip_all");
  2195. }
  2196. else
  2197. {
  2198. sprintf(strSQLText,
  2199. "select id, equip_type_id from t_view_equip_all " \
  2200. "where id in (select equip_id from t_role_equip " \
  2201. "where userid = \'%s\' ) ",
  2202. pUserID);
  2203. }
  2204. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2205. if (iRetCode == 0)
  2206. {
  2207. delete pRSet;
  2208. pRSet = NULL;
  2209. return -1;
  2210. }
  2211. nCount = pRSet->GetRecordCount();
  2212. if (nCount == 0)
  2213. {
  2214. if( pRSet )
  2215. {
  2216. delete pRSet;
  2217. pRSet = NULL;
  2218. }
  2219. return 0;
  2220. }
  2221. for( i = 0; i < nCount; i++ )
  2222. {
  2223. // 获取设备ID
  2224. if (!pRSet->IsFieldNull("id"))
  2225. {
  2226. pRSet->GetFieldValue("id", strEquipID);
  2227. }
  2228. // 获取设备类型ID
  2229. if (!pRSet->IsFieldNull("equip_type_id"))
  2230. {
  2231. pRSet->GetFieldValue("equip_type_id", strEquipTypeID);
  2232. }
  2233. strcat(pUserEquipIDList, strEquipID);
  2234. strcat(pUserEquipIDList, ",");
  2235. strcat(pUserEquipTypeIDList, strEquipTypeID);
  2236. strcat(pUserEquipTypeIDList, ",");
  2237. pRSet->MoveNext();
  2238. }
  2239. if( pRSet )
  2240. {
  2241. delete pRSet;
  2242. pRSet = NULL;
  2243. }
  2244. return nCount;
  2245. }
  2246. }
  2247. catch (...)
  2248. {
  2249. if( pRSet )
  2250. {
  2251. delete pRSet;
  2252. pRSet = NULL;
  2253. }
  2254. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2255. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2256. return -1;
  2257. }
  2258. if( pRSet )
  2259. {
  2260. delete pRSet;
  2261. pRSet = NULL;
  2262. }
  2263. return 0;
  2264. }
  2265. //得到该设备可控的用户信息列表
  2266. INT GetUserEquipInfoList( int nEquipTypeID, int nEquipID, CHAR *pTelList, CHAR *pMobileTelList, CHAR *pFaxList, CHAR *pEmailList )
  2267. {
  2268. CString str;
  2269. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2270. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2271. CHAR szTel[MAX_TEL_LENGTH + 1] = {0};
  2272. CHAR szMobileTel[MAX_TEL_LENGTH + 1] = {0};
  2273. CHAR szFaxTel[MAX_TEL_LENGTH + 1] = {0};
  2274. CHAR szEmail[MAX_EMAIL_LENGTH + 1] = {0};
  2275. CADORecordset* pRSet = NULL;
  2276. INT iRetCode = 0;
  2277. int nCount = 0, i;
  2278. strcpy(pTelList, "");
  2279. strcpy(pMobileTelList, "");
  2280. strcpy(pFaxList, "");
  2281. strcpy(pEmailList, "");
  2282. try
  2283. {
  2284. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2285. {
  2286. pRSet = new CADORecordset(g_pADODatabase);
  2287. if (NULL == pRSet)
  2288. {
  2289. return -1;
  2290. }
  2291. if( strcmp(g_strLoginUserID, "admin") == 0 )
  2292. {
  2293. sprintf(strSQLText, "select tel, mobiletel, fax, email from t_user_info where uid <> 'admin'");
  2294. }
  2295. else
  2296. {
  2297. sprintf(strSQLText, "select tel, mobiletel, fax, email from t_user_info where uid in (" \
  2298. "select userid from t_role_equip where equip_type_id = %d and equip_id = %d )",
  2299. nEquipTypeID, nEquipID);
  2300. }
  2301. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2302. if (iRetCode == 0)
  2303. {
  2304. delete pRSet;
  2305. pRSet = NULL;
  2306. return -1;
  2307. }
  2308. nCount = pRSet->GetRecordCount();
  2309. if (nCount == 0)
  2310. {
  2311. if( pRSet )
  2312. {
  2313. delete pRSet;
  2314. pRSet = NULL;
  2315. }
  2316. return 0;
  2317. }
  2318. for( i = 0; i < nCount; i++ )
  2319. {
  2320. // 获取电话号码
  2321. if (!pRSet->IsFieldNull("tel"))
  2322. {
  2323. pRSet->GetFieldValue("tel", str);
  2324. strcpy( szTel, (char *)(LPCTSTR)str );
  2325. }
  2326. // 获取手机号码
  2327. if (!pRSet->IsFieldNull("mobiletel"))
  2328. {
  2329. pRSet->GetFieldValue("mobiletel", str);
  2330. strcpy( szMobileTel, (char *)(LPCTSTR)str );
  2331. }
  2332. // 获取传真号码
  2333. if (!pRSet->IsFieldNull("fax"))
  2334. {
  2335. pRSet->GetFieldValue("fax", str);
  2336. strcpy( szFaxTel, (char *)(LPCTSTR)str );
  2337. }
  2338. // 获取Email
  2339. if (!pRSet->IsFieldNull("email"))
  2340. {
  2341. pRSet->GetFieldValue("email", str);
  2342. strcpy( szEmail, (char *)(LPCTSTR)str );
  2343. }
  2344. strcat(pTelList, szTel);
  2345. strcat(pTelList, ",");
  2346. strcat(pMobileTelList, szMobileTel);
  2347. strcat(pMobileTelList, ",");
  2348. strcat(pFaxList, szFaxTel);
  2349. strcat(pFaxList, ",");
  2350. strcat(pEmailList, szEmail);
  2351. strcat(pEmailList, ",");
  2352. pRSet->MoveNext();
  2353. }
  2354. if( pRSet )
  2355. {
  2356. delete pRSet;
  2357. pRSet = NULL;
  2358. }
  2359. return nCount;
  2360. }
  2361. }
  2362. catch (...)
  2363. {
  2364. if( pRSet )
  2365. {
  2366. delete pRSet;
  2367. pRSet = NULL;
  2368. }
  2369. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2370. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2371. return -1;
  2372. }
  2373. if( pRSet )
  2374. {
  2375. delete pRSet;
  2376. pRSet = NULL;
  2377. }
  2378. return 0;
  2379. }
  2380. //得到已分配设备名称列表
  2381. INT GetUserEquipAllocList( CHAR *pUserID, int nAreaID, CHAR *pEquipAllocIDList )
  2382. {
  2383. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2384. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2385. CString strID;
  2386. CADORecordset* pRSet = NULL;
  2387. INT iRetCode = 0;
  2388. int nCount = 0, i;
  2389. strcpy(pEquipAllocIDList, "");
  2390. try
  2391. {
  2392. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2393. {
  2394. pRSet = new CADORecordset(g_pADODatabase);
  2395. if (NULL == pRSet)
  2396. {
  2397. return -1;
  2398. }
  2399. sprintf(strSQLText,
  2400. "select equipdesc from t_view_equip_all " \
  2401. "where id in (select equip_id from t_role_equip where " \
  2402. "userid = \'%s\') " \
  2403. "and room_id in (select id from t_base_room where areaid = %d)",
  2404. pUserID, nAreaID);
  2405. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2406. if (iRetCode == 0)
  2407. {
  2408. delete pRSet;
  2409. pRSet = NULL;
  2410. return -1;
  2411. }
  2412. nCount = pRSet->GetRecordCount();
  2413. if (nCount == 0)
  2414. {
  2415. if( pRSet )
  2416. {
  2417. delete pRSet;
  2418. pRSet = NULL;
  2419. }
  2420. return 0;
  2421. }
  2422. for( i = 0; i < nCount; i++ )
  2423. {
  2424. // 获取设备ID
  2425. if (!pRSet->IsFieldNull("equipdesc"))
  2426. {
  2427. pRSet->GetFieldValue("equipdesc", strID);
  2428. }
  2429. strcat(pEquipAllocIDList, strID);
  2430. strcat(pEquipAllocIDList, ",");
  2431. pRSet->MoveNext();
  2432. }
  2433. if( pRSet )
  2434. {
  2435. delete pRSet;
  2436. pRSet = NULL;
  2437. }
  2438. return nCount;
  2439. }
  2440. }
  2441. catch (...)
  2442. {
  2443. if( pRSet )
  2444. {
  2445. delete pRSet;
  2446. pRSet = NULL;
  2447. }
  2448. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2449. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2450. return -1;
  2451. }
  2452. if( pRSet )
  2453. {
  2454. delete pRSet;
  2455. pRSet = NULL;
  2456. }
  2457. return 0;
  2458. }
  2459. //得到已分配设备名称列表
  2460. INT GetUserEquipAllocList( CHAR *pUserID, CHAR *pEquipAllocIDList )
  2461. {
  2462. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2463. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2464. CString strID;
  2465. CADORecordset* pRSet = NULL;
  2466. INT iRetCode = 0;
  2467. int nCount = 0, i;
  2468. strcpy(pEquipAllocIDList, "");
  2469. try
  2470. {
  2471. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2472. {
  2473. pRSet = new CADORecordset(g_pADODatabase);
  2474. if (NULL == pRSet)
  2475. {
  2476. return -1;
  2477. }
  2478. sprintf(strSQLText,
  2479. "select equipdesc from t_view_equip_all " \
  2480. "where id in (select equip_id from t_role_equip where " \
  2481. "userid = \'%s\') ",
  2482. pUserID);
  2483. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2484. if (iRetCode == 0)
  2485. {
  2486. delete pRSet;
  2487. pRSet = NULL;
  2488. return -1;
  2489. }
  2490. nCount = pRSet->GetRecordCount();
  2491. if (nCount == 0)
  2492. {
  2493. if( pRSet )
  2494. {
  2495. delete pRSet;
  2496. pRSet = NULL;
  2497. }
  2498. return 0;
  2499. }
  2500. for( i = 0; i < nCount; i++ )
  2501. {
  2502. // 获取设备描述
  2503. if (!pRSet->IsFieldNull("equipdesc"))
  2504. {
  2505. pRSet->GetFieldValue("equipdesc", strID);
  2506. }
  2507. strcat(pEquipAllocIDList, strID);
  2508. strcat(pEquipAllocIDList, ",");
  2509. pRSet->MoveNext();
  2510. }
  2511. if( pRSet )
  2512. {
  2513. delete pRSet;
  2514. pRSet = NULL;
  2515. }
  2516. return nCount;
  2517. }
  2518. }
  2519. catch (...)
  2520. {
  2521. if( pRSet )
  2522. {
  2523. delete pRSet;
  2524. pRSet = NULL;
  2525. }
  2526. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2527. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2528. return -1;
  2529. }
  2530. if( pRSet )
  2531. {
  2532. delete pRSet;
  2533. pRSet = NULL;
  2534. }
  2535. return 0;
  2536. }
  2537. //获取设备资料列表, 返回设备总数
  2538. INT GetEquipInfoListByRoomID(CHAR *pUserID, int nRoomID, CHAR *pStrEquipDescList)
  2539. {
  2540. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2541. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2542. CHAR strEquipIP[MAX_EQUIP_IP + 1] = {0};
  2543. CHAR strEquipDesc[MAX_EQUIP_DESC + 1] = {0};
  2544. CString str;
  2545. CADORecordset* pRSet = NULL;
  2546. INT iRetCode = 0;
  2547. int nCount = 0, i;
  2548. strcpy(pStrEquipDescList, "");
  2549. try
  2550. {
  2551. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2552. {
  2553. pRSet = new CADORecordset(g_pADODatabase);
  2554. if (NULL == pRSet)
  2555. {
  2556. return -1;
  2557. }
  2558. sprintf(strSQLText,
  2559. "select EquipDesc from t_view_equip_all " \
  2560. "where id not in (select equip_id from t_role_equip where " \
  2561. "room_id = %d and userid = \'%s\') " \
  2562. "and room_id = %d",
  2563. nRoomID, pUserID, nRoomID);
  2564. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2565. if (iRetCode == 0)
  2566. {
  2567. delete pRSet;
  2568. pRSet = NULL;
  2569. return -1;
  2570. }
  2571. nCount = pRSet->GetRecordCount();
  2572. if (nCount == 0)
  2573. {
  2574. if( pRSet )
  2575. {
  2576. delete pRSet;
  2577. pRSet = NULL;
  2578. }
  2579. return 0;
  2580. }
  2581. for( i = 0; i < nCount; i++ )
  2582. {
  2583. // 获取设备描述
  2584. if( !pRSet->IsFieldNull("EquipDesc") )
  2585. {
  2586. pRSet->GetFieldValue("EquipDesc", str);
  2587. strcpy(strEquipDesc, (char*)(LPCTSTR)str);
  2588. }
  2589. strcat(pStrEquipDescList, strEquipDesc);
  2590. strcat(pStrEquipDescList, ",");
  2591. pRSet->MoveNext();
  2592. }
  2593. if( pRSet )
  2594. {
  2595. delete pRSet;
  2596. pRSet = NULL;
  2597. }
  2598. return nCount;
  2599. }
  2600. }
  2601. catch (...)
  2602. {
  2603. if( pRSet )
  2604. {
  2605. delete pRSet;
  2606. pRSet = NULL;
  2607. }
  2608. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2609. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2610. return -1;
  2611. }
  2612. if( pRSet )
  2613. {
  2614. delete pRSet;
  2615. pRSet = NULL;
  2616. }
  2617. return 0;
  2618. }
  2619. //得到房间名称
  2620. INT GetRoomName( int nID, CHAR *pRoomName )
  2621. {
  2622. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  2623. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  2624. CString str;
  2625. CADORecordset* pRSet = NULL;
  2626. INT iRetCode = 0;
  2627. int nRecordCount = 0;
  2628. try
  2629. {
  2630. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2631. {
  2632. pRSet = new CADORecordset(g_pADODatabase);
  2633. if (NULL == pRSet)
  2634. {
  2635. return -1;
  2636. }
  2637. sprintf(strSQLText, "select roomdesc from t_base_room where id=%d", nID);
  2638. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2639. if (iRetCode == 0)
  2640. {
  2641. delete pRSet;
  2642. pRSet = NULL;
  2643. return -1;
  2644. }
  2645. nRecordCount = pRSet->GetRecordCount();
  2646. if (nRecordCount == 0)
  2647. {
  2648. if( pRSet )
  2649. {
  2650. delete pRSet;
  2651. pRSet = NULL;
  2652. }
  2653. return 0;
  2654. }
  2655. if (!pRSet->IsFieldNull("roomdesc"))
  2656. {
  2657. pRSet->GetFieldValue("roomdesc", str);
  2658. strcpy(pRoomName, (char*)(LPCTSTR)str);
  2659. }
  2660. }
  2661. }
  2662. catch (...)
  2663. {
  2664. if( pRSet )
  2665. {
  2666. delete pRSet;
  2667. pRSet = NULL;
  2668. }
  2669. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2670. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2671. return -1;
  2672. }
  2673. if( pRSet )
  2674. {
  2675. delete pRSet;
  2676. pRSet = NULL;
  2677. }
  2678. return 0;
  2679. }
  2680. //得到已分配设备权限列表中的EquipID
  2681. INT GetUserEquipID( CHAR *pUserID, CHAR *pEquipDesc, CHAR *pEquipID, CHAR *pEquipTypeID )
  2682. {
  2683. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  2684. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  2685. CString str;
  2686. CADORecordset* pRSet = NULL;
  2687. INT iRetCode = 0;
  2688. int nRecordCount = 0;
  2689. try
  2690. {
  2691. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2692. {
  2693. pRSet = new CADORecordset(g_pADODatabase);
  2694. if (NULL == pRSet)
  2695. {
  2696. return -1;
  2697. }
  2698. sprintf(strSQLText,
  2699. "select id, equip_type_id from t_view_equip_all where id in (" \
  2700. "select equip_id from t_role_equip where userid = \'%s\') " \
  2701. " and equipdesc = \'%s\'",
  2702. pUserID, pEquipDesc);
  2703. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2704. if (iRetCode == 0)
  2705. {
  2706. delete pRSet;
  2707. pRSet = NULL;
  2708. return -1;
  2709. }
  2710. nRecordCount = pRSet->GetRecordCount();
  2711. if (nRecordCount == 0)
  2712. {
  2713. if( pRSet )
  2714. {
  2715. delete pRSet;
  2716. pRSet = NULL;
  2717. }
  2718. return 0;
  2719. }
  2720. if (!pRSet->IsFieldNull("id"))
  2721. {
  2722. pRSet->GetFieldValue("id", str);
  2723. strcpy(pEquipID, (char*)(LPCTSTR)str);
  2724. }
  2725. if (!pRSet->IsFieldNull("equip_type_id"))
  2726. {
  2727. pRSet->GetFieldValue("equip_type_id", str);
  2728. strcpy(pEquipTypeID, (char*)(LPCTSTR)str);
  2729. }
  2730. if( pRSet )
  2731. {
  2732. delete pRSet;
  2733. pRSet = NULL;
  2734. }
  2735. return nRecordCount;
  2736. }
  2737. }
  2738. catch (...)
  2739. {
  2740. if( pRSet )
  2741. {
  2742. delete pRSet;
  2743. pRSet = NULL;
  2744. }
  2745. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2746. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2747. return -1;
  2748. }
  2749. if( pRSet )
  2750. {
  2751. delete pRSet;
  2752. pRSet = NULL;
  2753. }
  2754. return 0;
  2755. }
  2756. //添加房间权限信息
  2757. INT AddUserEquipInfo(CHAR *pUserID, int nEquipTypeID, int nEquipID, int nRoomID)
  2758. {
  2759. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2760. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2761. INT iRetCode = 0;
  2762. try
  2763. {
  2764. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2765. {
  2766. sprintf(strSQLText, "insert into t_role_equip(equip_id, equip_type_id, room_id, userid) values (%d, %d, %d, " \
  2767. "\'%s\')", nEquipID, nEquipTypeID, nRoomID, pUserID);
  2768. iRetCode = g_pADODatabase->Execute(strSQLText);
  2769. }
  2770. }
  2771. catch (...)
  2772. {
  2773. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2774. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2775. return 0;
  2776. }
  2777. return iRetCode;
  2778. }
  2779. //删除房间权限信息
  2780. INT DelUserEquipInfo(CHAR *pUserID, int nEquipTypeID, int nEquipID, int nRoomID)
  2781. {
  2782. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = "";
  2783. CHAR strSQLText[MAX_SQL_LENGTH + 1] = "";
  2784. INT iRetCode = 0;
  2785. try
  2786. {
  2787. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2788. {
  2789. sprintf(strSQLText, "delete from t_role_equip where equip_id = %d and room_id = %d " \
  2790. "and userid = \'%s\' and equip_type_id = %d",
  2791. nEquipID, nRoomID, pUserID, nEquipTypeID);
  2792. iRetCode = g_pADODatabase->Execute(strSQLText);
  2793. }
  2794. }
  2795. catch (...)
  2796. {
  2797. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2798. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2799. return 0;
  2800. }
  2801. return iRetCode;
  2802. }
  2803. //得到用户手机号码
  2804. INT GetUserMobileTel( CHAR *pUserID, CHAR *pMobileTel )
  2805. {
  2806. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  2807. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  2808. CString str;
  2809. CADORecordset* pRSet = NULL;
  2810. INT iRetCode = 0;
  2811. int nRecordCount = 0;
  2812. try
  2813. {
  2814. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2815. {
  2816. pRSet = new CADORecordset(g_pADODatabase);
  2817. if (NULL == pRSet)
  2818. {
  2819. return -1;
  2820. }
  2821. sprintf(strSQLText, "select mobiletel from t_user_info where uid=\'%s\'", pUserID);
  2822. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2823. if (iRetCode == 0)
  2824. {
  2825. delete pRSet;
  2826. pRSet = NULL;
  2827. return -1;
  2828. }
  2829. nRecordCount = pRSet->GetRecordCount();
  2830. if (nRecordCount == 0)
  2831. {
  2832. if( pRSet )
  2833. {
  2834. delete pRSet;
  2835. pRSet = NULL;
  2836. }
  2837. return 0;
  2838. }
  2839. if (!pRSet->IsFieldNull("mobiletel"))
  2840. {
  2841. pRSet->GetFieldValue("mobiletel", str);
  2842. strcpy(pMobileTel, (char*)(LPCTSTR)str);
  2843. }
  2844. }
  2845. }
  2846. catch (...)
  2847. {
  2848. if( pRSet )
  2849. {
  2850. delete pRSet;
  2851. pRSet = NULL;
  2852. }
  2853. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2854. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2855. return -1;
  2856. }
  2857. if( pRSet )
  2858. {
  2859. delete pRSet;
  2860. pRSet = NULL;
  2861. }
  2862. return 0;
  2863. }
  2864. //得到用户电话号码
  2865. INT GetUserTel( CHAR *pUserID, CHAR *pTel )
  2866. {
  2867. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  2868. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  2869. CString str;
  2870. CADORecordset* pRSet = NULL;
  2871. INT iRetCode = 0;
  2872. int nRecordCount = 0;
  2873. try
  2874. {
  2875. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2876. {
  2877. pRSet = new CADORecordset(g_pADODatabase);
  2878. if (NULL == pRSet)
  2879. {
  2880. return -1;
  2881. }
  2882. sprintf(strSQLText, "select tel from t_user_info where uid=\'%s\'", pUserID);
  2883. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2884. if (iRetCode == 0)
  2885. {
  2886. delete pRSet;
  2887. pRSet = NULL;
  2888. return -1;
  2889. }
  2890. nRecordCount = pRSet->GetRecordCount();
  2891. if (nRecordCount == 0)
  2892. {
  2893. if( pRSet )
  2894. {
  2895. delete pRSet;
  2896. pRSet = NULL;
  2897. }
  2898. return 0;
  2899. }
  2900. if (!pRSet->IsFieldNull("tel"))
  2901. {
  2902. pRSet->GetFieldValue("tel", str);
  2903. strcpy(pTel, (char*)(LPCTSTR)str);
  2904. }
  2905. }
  2906. }
  2907. catch (...)
  2908. {
  2909. if( pRSet )
  2910. {
  2911. delete pRSet;
  2912. pRSet = NULL;
  2913. }
  2914. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2915. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2916. return -1;
  2917. }
  2918. if( pRSet )
  2919. {
  2920. delete pRSet;
  2921. pRSet = NULL;
  2922. }
  2923. return 0;
  2924. }
  2925. //得到用户Email
  2926. INT GetUserEmail( CHAR *pUserID, CHAR *pEmail )
  2927. {
  2928. CHAR strMsg[MAX_MSG_LENGTH * 2 + 1] = {0};
  2929. CHAR strSQLText[MAX_SQL_LENGTH + 1] = {0};
  2930. CString str;
  2931. CADORecordset* pRSet = NULL;
  2932. INT iRetCode = 0;
  2933. int nRecordCount = 0;
  2934. try
  2935. {
  2936. if (g_pADODatabase != NULL && g_pADODatabase->IsOpen())
  2937. {
  2938. pRSet = new CADORecordset(g_pADODatabase);
  2939. if (NULL == pRSet)
  2940. {
  2941. return -1;
  2942. }
  2943. sprintf(strSQLText, "select email from t_user_info where uid=\'%s\'", pUserID);
  2944. iRetCode = pRSet->Open(strSQLText, CADORecordset::openQuery);
  2945. if (iRetCode == 0)
  2946. {
  2947. delete pRSet;
  2948. pRSet = NULL;
  2949. return -1;
  2950. }
  2951. nRecordCount = pRSet->GetRecordCount();
  2952. if (nRecordCount == 0)
  2953. {
  2954. if( pRSet )
  2955. {
  2956. delete pRSet;
  2957. pRSet = NULL;
  2958. }
  2959. return 0;
  2960. }
  2961. if (!pRSet->IsFieldNull("email"))
  2962. {
  2963. pRSet->GetFieldValue("email", str);
  2964. strcpy(pEmail, (char*)(LPCTSTR)str);
  2965. }
  2966. }
  2967. }
  2968. catch (...)
  2969. {
  2970. if( pRSet )
  2971. {
  2972. delete pRSet;
  2973. pRSet = NULL;
  2974. }
  2975. sprintf(strMsg, g_strErrorExecSql, strSQLText);
  2976. AddToPrintQueue(MSG_ERROR, MSG_DB_MD, strMsg, strlen(strMsg));
  2977. return -1;
  2978. }
  2979. if( pRSet )
  2980. {
  2981. delete pRSet;
  2982. pRSet = NULL;
  2983. }
  2984. return 0;
  2985. }