DbConnector.cs 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. using Db_Core;
  2. using log4net;
  3. using SuperAdmin.Models;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.Common;
  7. using Oracle.ManagedDataAccess.Client;
  8. using System.Data;
  9. using ReportWeb.Models;
  10. using ReportWeb.Source;
  11. using ReportWebCore.Models.Http;
  12. namespace SuperAdmin.Source
  13. {
  14. /// <summary>
  15. /// Summary description for DbConnector
  16. /// </summary>
  17. public class DbConnector
  18. {
  19. private readonly ILog log = LogManager.GetLogger(typeof(DbConnector));
  20. private ConnectionType connType = ConnectionType.ORACLE;
  21. public List<Services> LoadListServices()
  22. {
  23. try
  24. {
  25. String sql = @"select * from sv where status = 1";
  26. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  27. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  28. stmt.CloseConnection();
  29. return rs;
  30. }
  31. catch (Exception ex)
  32. {
  33. log.Error("Error LoadListServices", ex);
  34. return null;
  35. }
  36. }
  37. public List<Services> LoadListServicesReport()
  38. {
  39. try
  40. {
  41. String sql = @"select * from sv join sv_report sr on sv.sv_code = sr.sv_code where sv.status = 1";
  42. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  43. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  44. stmt.CloseConnection();
  45. return rs;
  46. }
  47. catch (Exception ex)
  48. {
  49. log.Error("Error LoadListServicesReport", ex);
  50. return null;
  51. }
  52. }
  53. public List<Services> LoadListServicesAdv(int status)
  54. {
  55. try
  56. {
  57. String sql = @"select sv.id, sv.sv_code, sv.sv_name,
  58. a.msg_adv, a.adv_name, a.channel_adv, a.message_type, a.from_money, a.status, a.id adv_id , a.active_hour, a.max_number_msg
  59. from sv
  60. join sv_adv a
  61. on sv.sv_code = a.sv_code where sv.status = 1
  62. [ and a.status = ? ]";
  63. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  64. if (status >= 0)
  65. {
  66. stmt.SetParameter(0, status);
  67. }
  68. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  69. stmt.CloseConnection();
  70. return rs;
  71. }
  72. catch (Exception ex)
  73. {
  74. log.Error("Error LoadListServicesAdv", ex);
  75. return null;
  76. }
  77. }
  78. public List<Users> GetUserByName(string username)
  79. {
  80. try
  81. {
  82. log.Info("Error GetUserByName: " + username);
  83. String sql = @"select * from user_report where status = 1 and username = ?";
  84. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  85. log.Info(stmt.connectionString);
  86. stmt.SetParameters(username);
  87. var rs = Users.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  88. stmt.CloseConnection();
  89. return rs;
  90. }
  91. catch (Exception ex)
  92. {
  93. log.Error("Error GetUserByName", ex);
  94. return null;
  95. }
  96. }
  97. public Services GetServiceById(string serviceId)
  98. {
  99. try
  100. {
  101. String sql = @"select * from sv where status = 1 and id = ?";
  102. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  103. stmt.SetParameters(serviceId);
  104. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  105. stmt.CloseConnection();
  106. if (rs != null && rs.Count > 0)
  107. {
  108. return rs[0];
  109. }
  110. return null;
  111. }
  112. catch (Exception ex)
  113. {
  114. log.Error("Error GetServiceById", ex);
  115. return null;
  116. }
  117. }
  118. public Services GetServiceRpBySvCode(string svCode)
  119. {
  120. try
  121. {
  122. String sql = @"select * from sv_report where status = 1 and sv_code = ?";
  123. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  124. stmt.SetParameters(svCode);
  125. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  126. stmt.CloseConnection();
  127. if (rs != null && rs.Count > 0)
  128. {
  129. return rs[0];
  130. }
  131. return null;
  132. }
  133. catch (Exception ex)
  134. {
  135. log.Error("Error GetServiceRpBySvCode", ex);
  136. return null;
  137. }
  138. }
  139. public Services GetServiceAdvById(string advId)
  140. {
  141. try
  142. {
  143. String sql = @"select a.*, a.id adv_id from sv_adv a where id = ?";
  144. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  145. stmt.SetParameters(advId);
  146. var rs = Services.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  147. stmt.CloseConnection();
  148. if (rs != null && rs.Count > 0)
  149. {
  150. return rs[0];
  151. }
  152. return null;
  153. }
  154. catch (Exception ex)
  155. {
  156. log.Error("Error GetServiceAdvById", ex);
  157. return null;
  158. }
  159. }
  160. public List<DailyReport> GetCommonReport(DateTime fromDate, DateTime toDate)
  161. {
  162. DbConnection myConnection = null;
  163. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  164. String sqlCommand = "SELECT a.sv_code, sv.sv_name service_name, sv.id service_id, to_char(a.report_date,'dd/mm/yyyy') report_date, a.revenue, a.count_reg, a.paid_money, a.count_active, a.count_deactive, a.revenue_buy " +
  165. " FROM daily_report a, sv " +
  166. "WHERE a.sv_code = sv.sv_code AND report_date >= :fromDate AND report_date <= :toDate ORDER BY a.sv_code, a.report_date";
  167. try
  168. {
  169. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  170. {
  171. DbCommand myCommand = myConnection.CreateCommand();
  172. myCommand.CommandText = sqlCommand;
  173. myCommand.Parameters.Clear();
  174. // from date
  175. AddCmdParam(ref myCommand, "fromDate", fromDate);
  176. // todate
  177. AddCmdParam(ref myCommand, "toDate", toDate);
  178. DbDataReader reader = myCommand.ExecuteReader();
  179. return DailyReport.Parse((OracleDataReader)reader);
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. log.Error("Error GetDailyReport", ex);
  185. return null;
  186. }
  187. finally
  188. {
  189. try
  190. {
  191. if (myConnection != null)
  192. {
  193. myConnection.Close();
  194. }
  195. }
  196. catch { }
  197. }
  198. }
  199. public List<DailyReport> GetTotalReport(DateTime fromDate, DateTime toDate)
  200. {
  201. DbConnection myConnection = null;
  202. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  203. String sqlCommand = "SELECT to_char(a.report_date,'dd/mm/yyyy') report_date, sum(a.revenue) revenue," +
  204. " sum(a.count_reg) count_reg, sum(a.paid_money) paid_money, sum(a.count_active) count_active, sum(a.count_deactive) count_deactive FROM daily_report a " +
  205. "WHERE report_date >= :fromDate AND report_date <= :toDate GROUP by a.report_date ORDER BY a.report_date";
  206. try
  207. {
  208. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  209. {
  210. DbCommand myCommand = myConnection.CreateCommand();
  211. myCommand.CommandText = sqlCommand;
  212. myCommand.Parameters.Clear();
  213. // from date
  214. AddCmdParam(ref myCommand, "fromDate", fromDate);
  215. // todate
  216. AddCmdParam(ref myCommand, "toDate", toDate);
  217. DbDataReader reader = myCommand.ExecuteReader();
  218. return DailyReport.Parse((OracleDataReader)reader);
  219. }
  220. }
  221. catch (Exception ex)
  222. {
  223. log.Error("Error GetDailyReport", ex);
  224. return null;
  225. }
  226. finally
  227. {
  228. try
  229. {
  230. if (myConnection != null)
  231. {
  232. myConnection.Close();
  233. }
  234. }
  235. catch { }
  236. }
  237. }
  238. public List<DailyReport> GetDailyReport(string serviceCode, DateTime fromDate, DateTime toDate)
  239. {
  240. DbConnection myConnection = null;
  241. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  242. String sqlCommand =
  243. "SELECT a.sv_code, to_char(a.report_date,'dd/mm/yyyy') report_date, a.revenue, a.revenue_buy, a.count_reg, a.paid_money, a.count_active, a.count_deactive " +
  244. "FROM daily_report a " +
  245. "WHERE sv_code = :service_code AND report_date >= :fromDate AND report_date <= :toDate ORDER BY a.report_date desc";
  246. try
  247. {
  248. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  249. {
  250. DbCommand myCommand = myConnection.CreateCommand();
  251. myCommand.CommandText = sqlCommand;
  252. myCommand.Parameters.Clear();
  253. // service code
  254. AddCmdParam(ref myCommand, "service_code", serviceCode);
  255. // from date
  256. AddCmdParam(ref myCommand, "fromDate", fromDate);
  257. // todate
  258. AddCmdParam(ref myCommand, "toDate", toDate);
  259. DbDataReader reader = myCommand.ExecuteReader();
  260. return DailyReport.Parse((OracleDataReader)reader);
  261. }
  262. }
  263. catch (Exception ex)
  264. {
  265. log.Error("Error GetDailyReport", ex);
  266. return null;
  267. }
  268. finally
  269. {
  270. try
  271. {
  272. if (myConnection != null)
  273. {
  274. myConnection.Close();
  275. }
  276. }
  277. catch { }
  278. }
  279. }
  280. public List<DailyReport> GetDailyReportAccu(string serviceCode, DateTime fromDate, DateTime toDate)
  281. {
  282. DbConnection myConnection = null;
  283. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  284. String sqlCommand = "SELECT a.sv_code, to_char(a.report_date,'dd/mm/yyyy') report_date, a.revenue, a.revenue_buy, a.count_reg, a.paid_money, a.count_active, a.count_deactive " +
  285. "FROM daily_report a " +
  286. "WHERE sv_code = :service_code AND report_date >= :fromDate AND report_date <= :toDate ORDER BY a.report_date desc";
  287. try
  288. {
  289. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  290. {
  291. DbCommand myCommand = myConnection.CreateCommand();
  292. myCommand.CommandText = sqlCommand;
  293. myCommand.Parameters.Clear();
  294. // service code
  295. AddCmdParam(ref myCommand, "service_code", serviceCode);
  296. // from date
  297. AddCmdParam(ref myCommand, "fromDate", fromDate);
  298. // todate
  299. AddCmdParam(ref myCommand, "toDate", toDate);
  300. DbDataReader reader = myCommand.ExecuteReader();
  301. return DailyReport.Parse((OracleDataReader)reader);
  302. }
  303. }
  304. catch (Exception ex)
  305. {
  306. log.Error("Error GetDailyReport", ex);
  307. return null;
  308. }
  309. finally
  310. {
  311. try
  312. {
  313. if (myConnection != null)
  314. {
  315. myConnection.Close();
  316. }
  317. }
  318. catch { }
  319. }
  320. }
  321. public List<DailyReport> GetHourlyReport(string serviceCode, DateTime fromDate, DateTime toDate)
  322. {
  323. DbConnection myConnection = null;
  324. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  325. String sqlCommand =
  326. "SELECT a.sv_code, to_char(a.report_date,'dd/mm/yyyy hh24') report_date, a.revenue, a.revenue_buy, a.count_reg, a.paid_money, a.count_active, a.count_deactive " +
  327. "FROM hourly_report a " +
  328. "WHERE sv_code = :service_code AND report_date >= :fromDate AND report_date <= :toDate + 1 ORDER BY a.report_date desc";
  329. try
  330. {
  331. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  332. {
  333. DbCommand myCommand = myConnection.CreateCommand();
  334. myCommand.CommandText = sqlCommand;
  335. myCommand.Parameters.Clear();
  336. // service code
  337. AddCmdParam(ref myCommand, "service_code", serviceCode);
  338. // from date
  339. AddCmdParam(ref myCommand, "fromDate", fromDate);
  340. // todate
  341. AddCmdParam(ref myCommand, "toDate", toDate);
  342. DbDataReader reader = myCommand.ExecuteReader();
  343. return DailyReport.Parse((OracleDataReader)reader);
  344. }
  345. }
  346. catch (Exception ex)
  347. {
  348. log.Error("Error GetHourlyReport", ex);
  349. return null;
  350. }
  351. finally
  352. {
  353. try
  354. {
  355. if (myConnection != null)
  356. {
  357. myConnection.Close();
  358. }
  359. }
  360. catch { }
  361. }
  362. }
  363. public List<DailyReport> GetTotalHourlyReport(DateTime fromDate, DateTime toDate)
  364. {
  365. DbConnection myConnection = null;
  366. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  367. String sqlCommand = "SELECT to_char(a.report_date,'dd/mm/yyyy hh24') report_date, sum(a.revenue) revenue," +
  368. " sum(a.count_reg) count_reg, sum(a.paid_money) paid_money, sum(a.count_active) count_active, sum(a.count_deactive) count_deactive FROM hourly_report a " +
  369. "WHERE report_date >= trunc(:fromDate) AND report_date < trunc(:toDate) + 1 GROUP by a.report_date ORDER BY a.report_date";
  370. try
  371. {
  372. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  373. {
  374. DbCommand myCommand = myConnection.CreateCommand();
  375. myCommand.CommandText = sqlCommand;
  376. myCommand.Parameters.Clear();
  377. // from date
  378. AddCmdParam(ref myCommand, "fromDate", fromDate);
  379. // todate
  380. AddCmdParam(ref myCommand, "toDate", toDate);
  381. DbDataReader reader = myCommand.ExecuteReader();
  382. return DailyReport.Parse((OracleDataReader)reader);
  383. }
  384. }
  385. catch (Exception ex)
  386. {
  387. log.Error("Error GetTotalHourlyRerpot", ex);
  388. return null;
  389. }
  390. finally
  391. {
  392. try
  393. {
  394. if (myConnection != null)
  395. {
  396. myConnection.Close();
  397. }
  398. }
  399. catch { }
  400. }
  401. }
  402. public DataTable GetRevenueHourly(string serviceCode, DateTime fromDate, DateTime toDate)
  403. {
  404. DbConnection myConnection = null;
  405. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  406. String sqlCommand =
  407. @"select * from (SELECT sv_code, report_date,
  408. SUM(revenue) as TOTAL,
  409. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 0 AND to_number(to_char(report_hour, 'hh24')) < 1 THEN revenue ELSE 0 END) as h00,
  410. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 1 AND to_number(to_char(report_hour, 'hh24')) < 2 THEN revenue ELSE 0 END) as h01,
  411. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 2 AND to_number(to_char(report_hour, 'hh24')) < 3 THEN revenue ELSE 0 END) as h02,
  412. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 3 AND to_number(to_char(report_hour, 'hh24')) < 4 THEN revenue ELSE 0 END) as h03,
  413. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 4 AND to_number(to_char(report_hour, 'hh24')) < 5 THEN revenue ELSE 0 END) as h04,
  414. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 5 AND to_number(to_char(report_hour, 'hh24')) < 6 THEN revenue ELSE 0 END) as h05,
  415. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 6 AND to_number(to_char(report_hour, 'hh24')) < 7 THEN revenue ELSE 0 END) as h06,
  416. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 7 AND to_number(to_char(report_hour, 'hh24')) < 8 THEN revenue ELSE 0 END) as h07,
  417. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 8 AND to_number(to_char(report_hour, 'hh24')) < 9 THEN revenue ELSE 0 END) as h08,
  418. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 9 AND to_number(to_char(report_hour, 'hh24')) < 10 THEN revenue ELSE 0 END) as h09,
  419. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 10 AND to_number(to_char(report_hour, 'hh24')) < 11 THEN revenue ELSE 0 END) as h10,
  420. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 11 AND to_number(to_char(report_hour, 'hh24')) < 12 THEN revenue ELSE 0 END) as h11,
  421. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 12 AND to_number(to_char(report_hour, 'hh24')) < 13 THEN revenue ELSE 0 END) as h12,
  422. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 13 AND to_number(to_char(report_hour, 'hh24')) < 14 THEN revenue ELSE 0 END) as h13,
  423. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 14 AND to_number(to_char(report_hour, 'hh24')) < 15 THEN revenue ELSE 0 END) as h14,
  424. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 15 AND to_number(to_char(report_hour, 'hh24')) < 16 THEN revenue ELSE 0 END) as h15,
  425. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 16 AND to_number(to_char(report_hour, 'hh24')) < 17 THEN revenue ELSE 0 END) as h16,
  426. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 17 AND to_number(to_char(report_hour, 'hh24')) < 18 THEN revenue ELSE 0 END) as h17,
  427. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 18 AND to_number(to_char(report_hour, 'hh24')) < 19 THEN revenue ELSE 0 END) as h18,
  428. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 19 AND to_number(to_char(report_hour, 'hh24')) < 20 THEN revenue ELSE 0 END) as h19,
  429. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 20 AND to_number(to_char(report_hour, 'hh24')) < 21 THEN revenue ELSE 0 END) as h20,
  430. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 21 AND to_number(to_char(report_hour, 'hh24')) < 22 THEN revenue ELSE 0 END) as h21,
  431. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 22 AND to_number(to_char(report_hour, 'hh24')) < 23 THEN revenue ELSE 0 END) as h22,
  432. SUM(CASE WHEN to_number(to_char(report_hour, 'hh24')) >= 23 AND to_number(to_char(report_hour, 'hh24')) < 24 THEN revenue ELSE 0 END) as h23
  433. FROM(
  434. SELECT trunc(report_date) report_date,
  435. sv_code,
  436. revenue,
  437. report_date report_hour
  438. FROM hourly_report
  439. )
  440. GROUP BY sv_code, report_date
  441. )
  442. WHERE sv_code = :service_code AND report_date >= :fromDate AND report_date <= :toDate ORDER BY report_date desc";
  443. try
  444. {
  445. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  446. {
  447. DbCommand myCommand = myConnection.CreateCommand();
  448. myCommand.CommandText = sqlCommand;
  449. myCommand.Parameters.Clear();
  450. // service code
  451. AddCmdParam(ref myCommand, "service_code", serviceCode);
  452. // from date
  453. AddCmdParam(ref myCommand, "fromDate", fromDate);
  454. // todate
  455. AddCmdParam(ref myCommand, "toDate", toDate);
  456. DbDataReader reader = myCommand.ExecuteReader();
  457. var tb = new DataTable();
  458. tb.Load(reader);
  459. return tb;
  460. }
  461. }
  462. catch (Exception ex)
  463. {
  464. log.Error("Error GetRevenueHourly", ex);
  465. return null;
  466. }
  467. finally
  468. {
  469. try
  470. {
  471. if (myConnection != null)
  472. {
  473. myConnection.Close();
  474. }
  475. }
  476. catch { }
  477. }
  478. }
  479. public List<ChargeLog> GetChargeLog(Services sv, String msisdn, DateTime fromDate, DateTime toDate)
  480. {
  481. try
  482. {
  483. String sqlCommand = "SELECT * FROM " + sv.db_name + ".charge_log WHERE msisdn = ? AND insert_time >= ? AND insert_time - 1 <= ? ORDER BY insert_time desc";
  484. SqlStatement stmt = new SqlStatement(sqlCommand, BuildConnectionString(sv));
  485. stmt.SetParameters(msisdn, fromDate, toDate);
  486. return ChargeLog.Parse(stmt.ExecuteReader());
  487. }
  488. catch (Exception ex)
  489. {
  490. log.Error("Error GetChargeLog " + msisdn, ex);
  491. return null;
  492. }
  493. }
  494. public List<RegInfo> GetRegisterInfo(Services sv, String msisdn, DateTime fromDate, DateTime toDate)
  495. {
  496. try
  497. {
  498. String sqlCommand = "SELECT * FROM " + sv.db_name + ".reg_info WHERE msisdn = ? AND expire_time >= ? AND register_time - 1 <= ? ORDER BY register_time desc";
  499. SqlStatement stmt = new SqlStatement(sqlCommand, BuildConnectionString(sv));
  500. stmt.SetParameters(msisdn, fromDate, toDate);
  501. return RegInfo.Parse(stmt.ExecuteReader());
  502. }
  503. catch (Exception ex)
  504. {
  505. log.Error("Error Get RegInfo " + msisdn, ex);
  506. return null;
  507. }
  508. }
  509. // lucky spin
  510. public List<SpinLog> GetLuckySpin(String msisdn, DateTime fromDate, DateTime toDate)
  511. {
  512. try
  513. {
  514. String sqlCommand = "SELECT * FROM lucky_spin WHERE msisdn = ? AND expire_time >= ? AND insert_time - 1 <= ? ORDER BY expire_time desc";
  515. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  516. stmt.SetParameters(msisdn, fromDate, toDate);
  517. return SpinLog.Parse(stmt.ExecuteReader());
  518. }
  519. catch (Exception ex)
  520. {
  521. log.Error("Error Get Spin log " + msisdn, ex);
  522. return null;
  523. }
  524. }
  525. public int CountLuckySpin(String msisdn)
  526. {
  527. SqlStatement stmt = null;
  528. try
  529. {
  530. String sqlCommand = "select nvl(sum(added - used),0) remain_spin, nvl(sum(added),0) total_spin, nvl(sum(used),0) used_spin from lucky_spin "
  531. + " where msisdn = ? and expire_time > sysdate";
  532. stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  533. stmt.SetParameters(msisdn);
  534. using (OracleDataReader reader = (OracleDataReader)stmt.ExecuteReader(connType))
  535. {
  536. while (reader.Read())
  537. {
  538. return int.Parse(reader.GetValue("remain_spin").ToString());
  539. }
  540. return 0;
  541. }
  542. }
  543. catch (Exception ex)
  544. {
  545. log.Error("Error Get Spin log " + msisdn, ex);
  546. return 0;
  547. }
  548. finally
  549. {
  550. try
  551. {
  552. stmt.CloseConnection();
  553. }
  554. catch { }
  555. }
  556. }
  557. public List<LuckyCode> GetListLuckyCode(String msisdn, String code, String codeType, String period, String redeemStatus, DateTime? fromDate, DateTime? toDate)
  558. {
  559. try
  560. {
  561. String sqlCommand = @"
  562. SELECT *
  563. FROM (SELECT *
  564. FROM (SELECT a.id, a.msisdn, a.code, a.insert_time, a.expire_time, a.period,
  565. a.status, a.confirm_time, a.confirm_channel, a.fee, a.code_type FROM lucky_code a
  566. WHERE 1=1
  567. [ AND insert_time >= trunc(?) ]
  568. [ AND insert_time < trunc(?) + 1 ]
  569. [ AND msisdn like '%' || ? || '%' ]
  570. [ AND code = ? ]
  571. [ AND period = ? ]
  572. [ AND status = ? ]
  573. [ AND code_type = ? ]
  574. )
  575. lc
  576. UNION ALL
  577. (SELECT a.id, a.msisdn, a.code, a.insert_time, a.expire_time, a.period,
  578. a.status, a.confirm_time, a.confirm_channel, a.fee, a.code_type FROM lucky_code_his a
  579. WHERE 1=1
  580. [ AND insert_time >= trunc(?) ]
  581. [ AND insert_time < trunc(?) + 1 ]
  582. [ AND msisdn like '%' || ? || '%' ]
  583. [ AND code = ? ]
  584. [ AND period = ? ]
  585. [ AND status = ? ]
  586. [ AND code_type = ? ]
  587. )
  588. ) ";
  589. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  590. int numPa = 7;
  591. if (fromDate != null)
  592. {
  593. stmt.SetParameter(0, fromDate);
  594. stmt.SetParameter(0 + numPa, fromDate);
  595. }
  596. if (toDate != null)
  597. {
  598. stmt.SetParameter(1, toDate);
  599. stmt.SetParameter(1 + numPa, toDate);
  600. }
  601. if (msisdn != null && msisdn.Length > 0)
  602. {
  603. stmt.SetParameter(2, msisdn);
  604. stmt.SetParameter(2 + numPa, msisdn);
  605. }
  606. if (code != null && code.Length > 0)
  607. {
  608. stmt.SetParameter(3, code);
  609. stmt.SetParameter(3 + numPa, code);
  610. }
  611. if (period != null && period.Length > 0)
  612. {
  613. stmt.SetParameter(4, period);
  614. stmt.SetParameter(4 + numPa, period);
  615. }
  616. if (redeemStatus != null && redeemStatus != "-1" && redeemStatus.Length > 0)
  617. {
  618. stmt.SetParameter(5, redeemStatus);
  619. stmt.SetParameter(5 + numPa, redeemStatus);
  620. }
  621. if (codeType != null && codeType.Length > 0 && codeType != "-1")
  622. {
  623. stmt.SetParameter(6, codeType);
  624. stmt.SetParameter(6 + numPa, codeType);
  625. }
  626. return LuckyCode.Parse(stmt.ExecuteReader());
  627. }
  628. catch (Exception ex)
  629. {
  630. log.Error("Error GetListLuckyCode " + msisdn, ex);
  631. return null;
  632. }
  633. }
  634. // RANKING
  635. public List<UserCoin> GetRankingCoin(String msisdn, String month, int maxRow)
  636. {
  637. try
  638. {
  639. String sqlCommand =
  640. @"SELECT a.* FROM
  641. (SELECT *
  642. FROM ( SELECT rownum rank, a.*
  643. FROM (SELECT c.*, r.product_name, p.prize_id, p.process_time, p.execute_id
  644. FROM user_coin c
  645. left join (select * from reg_info where status = 1) r on c.msisdn = r.msisdn
  646. left join (select * from prize_winner where period = 3 and code_time >= to_date(?, 'mm/yyyy') and code_time <= ADD_MONTHS(to_date(?, 'mm/yyyy'), 1) ) p on c.msisdn = p.msisdn
  647. where c.start_time <= to_date(?, 'mm/yyyy') and c.end_time >= to_date(?, 'mm/yyyy')
  648. ORDER BY c.total_coin DESC, c.last_update) a )
  649. WHERE 1=1
  650. [ and msisdn = ? ]
  651. [ and rank <= ? ]
  652. ) a";
  653. //String sqlCommand = "SELECT * FROM (SELECT * FROM user_coin WHERE start_time <= to_date(?, 'mm/yyyy') and end_time >= to_date(?, 'mm/yyyy') " +
  654. // " [ and msisdn = ? ]" +
  655. // " ORDER BY total_coin desc, last_update) " +
  656. // " where 1=1 " +
  657. // " [and rownum <= ?]";
  658. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  659. stmt.SetParameter(0, month);
  660. stmt.SetParameter(1, month);
  661. stmt.SetParameter(2, month);
  662. stmt.SetParameter(3, month);
  663. if (msisdn != null & msisdn.Length > 0)
  664. {
  665. stmt.SetParameter(4, msisdn);
  666. }
  667. else
  668. {
  669. if (maxRow > 0)
  670. {
  671. stmt.SetParameter(5, maxRow);
  672. }
  673. }
  674. return UserCoin.Parse(stmt.ExecuteReader());
  675. }
  676. catch (Exception ex)
  677. {
  678. log.Error("Error Get ranking coin " + msisdn, ex);
  679. return null;
  680. }
  681. }
  682. public List<PrizeObj> GetListPrizeWinner(String msisdn, String period, DateTime? fromDate, DateTime? toDate)
  683. {
  684. try
  685. {
  686. String sqlCommand = @"
  687. SELECT *
  688. FROM ( SELECT pw.*,
  689. lch.status status,
  690. g.is_auto,
  691. g.times_prize,
  692. lp.description,
  693. lp.prize_name,
  694. lp.is_top
  695. FROM prize_winner pw
  696. LEFT JOIN
  697. list_prize lp
  698. ON pw.prize_id = lp.id
  699. LEFT JOIN
  700. group_prize g
  701. ON lp.sub_group_prize = g.sub_group_id
  702. left join
  703. execute_prize_his lch on lch.prize_winner_id = pw.id
  704. WHERE 1 = 1
  705. ORDER BY code_time DESC)
  706. WHERE 1=1
  707. [ AND code_time >= trunc(?) ]
  708. [ AND code_time < trunc(?) + 1 ]
  709. [ AND msisdn like '%' || ? || '%' ]
  710. [ AND period = ? ]";
  711. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  712. if (fromDate != null)
  713. {
  714. stmt.SetParameter(0, fromDate);
  715. }
  716. if (toDate != null)
  717. {
  718. stmt.SetParameter(1, toDate);
  719. }
  720. if (msisdn != null && msisdn.Length > 0)
  721. {
  722. stmt.SetParameter(2, msisdn);
  723. }
  724. if (period != null && period.Length > 0 && period != "-1")
  725. {
  726. stmt.SetParameter(3, period);
  727. }
  728. return PrizeObj.Parse(stmt.ExecuteReader());
  729. }
  730. catch (Exception ex)
  731. {
  732. log.Error("Error GetListPrizeWinner " + msisdn, ex);
  733. return null;
  734. }
  735. }
  736. public PrizeObj GetWinnerById(int id)
  737. {
  738. try
  739. {
  740. String sqlCommand = @"
  741. SELECT * FROM prize_winner where id = ?";
  742. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  743. stmt.SetParameters(id);
  744. List<PrizeObj> list = PrizeObj.Parse(stmt.ExecuteReader());
  745. return list[0];
  746. }
  747. catch (Exception ex)
  748. {
  749. log.Error("Error GetWinnerById " + id, ex);
  750. return null;
  751. }
  752. }
  753. public bool InsertPrizeWinner(String msisdn, int prizeId, String code, DateTime codeTime, int codeType)
  754. {
  755. try
  756. {
  757. String sql = @"INSERT INTO prize_winner (ID,MSISDN,PRIZE_ID,CODE,CODE_TIME,PROCESS_TIME,CODE_TYPE)
  758. VALUES(prize_winner_seq.nextval, ?, ?, ?, ?, NULL, ?)";
  759. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  760. stmt.SetParameters(msisdn, prizeId, code, codeTime, codeType);
  761. stmt.ExecuteNonQuery(connType);
  762. stmt.CloseConnection();
  763. return true;
  764. }
  765. catch (Exception ex)
  766. {
  767. log.Error("Error InsertService", ex);
  768. return false;
  769. }
  770. }
  771. public bool DeleteWinner(int id)
  772. {
  773. try
  774. {
  775. String sql = "DELETE FROM prize_winner WHERE id= ?";
  776. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  777. stmt.SetParameters(id);
  778. stmt.ExecuteNonQuery(connType);
  779. stmt.CloseConnection();
  780. return true;
  781. }
  782. catch (Exception ex)
  783. {
  784. log.Error("Error DeleteWinner", ex);
  785. return false;
  786. }
  787. }
  788. public bool UpdateSendWinner(int id, String user)
  789. {
  790. try
  791. {
  792. String sql = "UPDATE prize_winner set process_time = sysdate, processed_by = ? WHERE id= ?";
  793. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  794. stmt.SetParameters(user, id);
  795. stmt.ExecuteNonQuery(connType);
  796. stmt.CloseConnection();
  797. return true;
  798. }
  799. catch (Exception ex)
  800. {
  801. log.Error("Error UpdateSendWinner", ex);
  802. return false;
  803. }
  804. }
  805. public bool SendMessage(String messageCode, String msisdn, String channel)
  806. {
  807. try
  808. {
  809. String sql = @"insert into mt values(
  810. mt_seq.nextval, 0, ?, (select distinct(param_value) from config where param_name = ?), sysdate, 0, ?
  811. )";
  812. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  813. stmt.SetParameters(msisdn, messageCode, channel);
  814. stmt.ExecuteNonQuery(connType);
  815. stmt.CloseConnection();
  816. return true;
  817. }
  818. catch (Exception ex)
  819. {
  820. log.Error("Error InsertService", ex);
  821. return false;
  822. }
  823. }
  824. public List<PrizeObj> LoadListPrize(int period, int is_auto)
  825. {
  826. try
  827. {
  828. String sqlCommand = @"
  829. SELECT *
  830. FROM ( SELECT lp.id, g.period,
  831. g.channel,
  832. g.is_auto,
  833. lp.description,
  834. lp.prize_name,
  835. lp.is_top
  836. FROM list_prize lp
  837. LEFT JOIN
  838. group_prize g
  839. ON lp.sub_group_prize = g.sub_group_id
  840. WHERE 1 = 1 )
  841. WHERE 1=1 and period = ? and is_auto = ? ";
  842. SqlStatement stmt = new SqlStatement(sqlCommand, SqlConnString.GAMEPORTAL);
  843. stmt.SetParameters(period, is_auto);
  844. return PrizeObj.Parse(stmt.ExecuteReader());
  845. }
  846. catch (Exception ex)
  847. {
  848. log.Error("Error LoadListPrize ", ex);
  849. return null;
  850. }
  851. }
  852. private String BuildConnectionString(Services sv)
  853. {
  854. String desc = sv.connection_string.Split('@')[1];
  855. return "Data Source=" + desc + "; " +
  856. " User ID=" + sv.db_username + ";Password=" + sv.db_password + ";Max Pool Size=3;";
  857. }
  858. public bool InsertService(string svCode, string svName)
  859. {
  860. try
  861. {
  862. String sql = @"INSERT INTO sv (ID,SV_CODE,SV_NAME,STATUS)
  863. VALUES(sv_seq.nextval, ?, ?, 1)";
  864. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  865. stmt.SetParameters(svCode, svName);
  866. stmt.ExecuteNonQuery(connType);
  867. stmt.CloseConnection();
  868. return true;
  869. }
  870. catch (Exception ex)
  871. {
  872. log.Error("Error InsertService", ex);
  873. return false;
  874. }
  875. }
  876. public bool UpdateServiceInfo(string serviceId, string serviceCode, string serviceName)
  877. {
  878. try
  879. {
  880. String sql = @"Update sv set sv_code = ?, sv_name = ? where id = ?";
  881. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  882. stmt.SetParameters(serviceCode, serviceName, serviceId);
  883. stmt.ExecuteNonQuery(connType);
  884. stmt.CloseConnection();
  885. return true;
  886. }
  887. catch (Exception ex)
  888. {
  889. log.Error("Error UpdateServiceInfo", ex);
  890. return false;
  891. }
  892. }
  893. public bool UpdateServiceStatus(string svId, string status)
  894. {
  895. try
  896. {
  897. String sql = @"Update sv set status = ? where id = ?";
  898. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  899. stmt.SetParameters(status, svId);
  900. stmt.ExecuteNonQuery(connType);
  901. stmt.CloseConnection();
  902. return true;
  903. }
  904. catch (Exception ex)
  905. {
  906. log.Error("Error UpdateServiceStatus", ex);
  907. return false;
  908. }
  909. }
  910. public bool InsertSvReport(string svCode, string dbName, string connectionString, string dbUsername, string dbPassword, string sqlReportDaily, string sqlReportHourly)
  911. {
  912. try
  913. {
  914. String sql = @"INSERT INTO sv_report (SV_CODE,DB_NAME,CONNECTION_STRING,DB_USERNAME,DB_PASSWORD,SQL_REPORT_DAILY,SQL_REPORT_HOURLY,STATUS)
  915. VALUES(?, ?, ?, ?, ?, ?, ?, 1)";
  916. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  917. stmt.SetParameters(svCode, dbName, connectionString, dbUsername, dbPassword, sqlReportDaily, sqlReportHourly);
  918. stmt.ExecuteNonQuery(connType);
  919. stmt.CloseConnection();
  920. return true;
  921. }
  922. catch (Exception ex)
  923. {
  924. log.Error("Error InsertSvReport", ex);
  925. return false;
  926. }
  927. }
  928. public bool UpdateServiceRpInfo(string svCode, string dbName, string connectionString, string dbUsername, string dbPassword, string sqlReportDaily, string sqlReportHourly)
  929. {
  930. try
  931. {
  932. String sql = @"Update sv_report set DB_NAME = ?,CONNECTION_STRING = ?,DB_USERNAME = ?,DB_PASSWORD = ?,SQL_REPORT_DAILY = ?,SQL_REPORT_HOURLY = ?
  933. where sv_code = ?";
  934. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  935. stmt.SetParameters(dbName, connectionString, dbUsername, dbPassword, sqlReportDaily, sqlReportHourly, svCode);
  936. stmt.ExecuteNonQuery(connType);
  937. stmt.CloseConnection();
  938. return true;
  939. }
  940. catch (Exception ex)
  941. {
  942. log.Error("Error UpdateServiceRpInfo", ex);
  943. return false;
  944. }
  945. }
  946. public bool UpdateServiceRpStatus(string svCode, string status)
  947. {
  948. try
  949. {
  950. String sql = @"Update sv_report set status = ? where sv_code = ?";
  951. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  952. stmt.SetParameters(status, svCode);
  953. stmt.ExecuteNonQuery(connType);
  954. stmt.CloseConnection();
  955. return true;
  956. }
  957. catch (Exception ex)
  958. {
  959. log.Error("Error UpdateServiceRpStatus", ex);
  960. return false;
  961. }
  962. }
  963. public bool ClearPortDown(string portName)
  964. {
  965. try
  966. {
  967. String sql = @"UPDATE port_down SET end_time = sysdate WHERE port_name = ? AND end_time is null";
  968. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  969. stmt.SetParameters(portName);
  970. stmt.ExecuteNonQuery(connType);
  971. stmt.CloseConnection();
  972. return true;
  973. }
  974. catch (Exception ex)
  975. {
  976. log.Error("Error ClearPortDown", ex);
  977. return false;
  978. }
  979. }
  980. private void AddCmdParam(ref DbCommand myCommand, string paramName, object paramValue)
  981. {
  982. var parameter1 = myCommand.CreateParameter();
  983. parameter1.ParameterName = ":" + paramName;
  984. parameter1.Value = paramValue;
  985. myCommand.Parameters.Add(parameter1);
  986. }
  987. public List<Broadcast> GetBroadcastById(int broadcastId)
  988. {
  989. try
  990. {
  991. String sql =
  992. @"SELECT br.*, a.adv_name, a.id adv_id"
  993. + " FROM broadcast br JOIN sv_adv a on br.sv_adv_id = a.id "
  994. + " WHERE br.id = ? "
  995. + " ORDER BY schedule_time desc";
  996. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  997. stmt.SetParameters(broadcastId);
  998. var rs = Broadcast.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  999. stmt.CloseConnection();
  1000. return rs;
  1001. }
  1002. catch (Exception ex)
  1003. {
  1004. log.Error("Error GetBroadcastById", ex);
  1005. return null;
  1006. }
  1007. }
  1008. public List<Broadcast> LoadListBroadcast(DateTime? fromdate, DateTime? todate)
  1009. {
  1010. try
  1011. {
  1012. String sql =
  1013. @"SELECT br.*, a.adv_name, a.id adv_id"
  1014. + " FROM broadcast br JOIN sv_adv a on br.sv_adv_id = a.id "
  1015. + " WHERE 1=1 " +
  1016. " [ AND br.schedule_time >= ? ] " +
  1017. " [ and br.schedule_time <= ? + 1 ]"
  1018. + " ORDER BY schedule_time desc";
  1019. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1020. if (fromdate != null)
  1021. {
  1022. stmt.SetParameter(0, fromdate);
  1023. }
  1024. if (todate != null)
  1025. {
  1026. stmt.SetParameter(1, todate);
  1027. }
  1028. var rs = Broadcast.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1029. stmt.CloseConnection();
  1030. return rs;
  1031. }
  1032. catch (Exception ex)
  1033. {
  1034. log.Error("Error LoadListBroadcast", ex);
  1035. return null;
  1036. }
  1037. }
  1038. public bool InsertBroadcast(Broadcast broadcast)
  1039. {
  1040. try
  1041. {
  1042. String sql = @"INSERT INTO broadcast (ID,BROADCAST_NAME,IMPORT_FILE,COUNT_SUB,STATUS,SCHEDULE_TIME,FINISH_TIME,SV_ADV_ID,SV_CODE,MSG_ADV,
  1043. CHANNEL_ADV,MESSAGE_TYPE,COUNT_SUB_REAL,PROGRESS_SUB)
  1044. VALUES(?, ?, ?, ?, 0, ?, NULL, ?, ?, ?, ?, ?, 0, 0)";
  1045. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1046. stmt.SetParameters(
  1047. broadcast.id,
  1048. broadcast.broadcast_name,
  1049. broadcast.import_file,
  1050. broadcast.count_sub,
  1051. DateTime.ParseExact(broadcast.schedule_time, "dd/MM/yyyy HH:mm:ss", null),
  1052. broadcast.sv_adv_id,
  1053. broadcast.sv_code,
  1054. broadcast.msg_adv,
  1055. broadcast.channel_adv,
  1056. broadcast.message_type);
  1057. stmt.ExecuteNonQuery(connType);
  1058. stmt.CloseConnection();
  1059. return true;
  1060. }
  1061. catch (Exception ex)
  1062. {
  1063. log.Error("Error InsertSvReport", ex);
  1064. return false;
  1065. }
  1066. }
  1067. public bool UpdateBroadcast(Broadcast broadcast)
  1068. {
  1069. try
  1070. {
  1071. String sql = "UPDATE BROADCAST SET BROADCAST_NAME = ?, IMPORT_FILE = ?, COUNT_SUB = ?, STATUS = ?, SCHEDULE_TIME = ?, SV_ADV_ID = ?,"
  1072. + "SV_CODE = ?, MSG_ADV = ?, CHANNEL_ADV = ?, MESSAGE_TYPE = ? "
  1073. + " WHERE id = ?";
  1074. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1075. stmt.SetParameters(
  1076. broadcast.broadcast_name,
  1077. broadcast.import_file,
  1078. broadcast.count_sub,
  1079. broadcast.status,
  1080. DateTime.ParseExact(broadcast.schedule_time, "dd/MM/yyyy HH:mm:ss", null),
  1081. broadcast.sv_adv_id,
  1082. broadcast.sv_code,
  1083. broadcast.msg_adv,
  1084. broadcast.channel_adv,
  1085. broadcast.message_type,
  1086. broadcast.id);
  1087. stmt.ExecuteNonQuery(connType);
  1088. stmt.CloseConnection();
  1089. return true;
  1090. }
  1091. catch (Exception ex)
  1092. {
  1093. log.Error("Error UpdateBroadcast", ex);
  1094. return false;
  1095. }
  1096. }
  1097. public bool UpdateBroadcastStatus(int id, string status)
  1098. {
  1099. try
  1100. {
  1101. String sql = "UPDATE BROADCAST SET STATUS = ? WHERE id = ?";
  1102. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1103. stmt.SetParameters(status, id);
  1104. stmt.ExecuteNonQuery(connType);
  1105. stmt.CloseConnection();
  1106. return true;
  1107. }
  1108. catch (Exception ex)
  1109. {
  1110. log.Error("Error UpdateBroadcastStatus", ex);
  1111. return false;
  1112. }
  1113. }
  1114. public int ImportSubBroadcast(Broadcast broadcast, List<String> listMsisdn)
  1115. {
  1116. DbConnection myConnection = null;
  1117. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  1118. String sqlCommand = "INSERT INTO MT_EXTEND_TEMP (ID,MSISDN,MESSAGE,RECEIVE_TIME,SEND_TIME,RETRY_NUM,CHANNEL,MESSAGE_TYPE,BROADCAST_ID)"
  1119. + " VALUES(MT_EXTEND_seq.nextval, :msisdn, :message, sysdate, :send_time, 0, :channel, :message_type, :broadcast_id)";
  1120. int i = 0;
  1121. try
  1122. {
  1123. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  1124. {
  1125. DbTransaction transaction = myConnection.BeginTransaction();
  1126. DbCommand myCommand = myConnection.CreateCommand();
  1127. myCommand.Transaction = transaction;
  1128. myCommand.CommandText = sqlCommand;
  1129. for (i = 0; i < listMsisdn.Count; i++)
  1130. {
  1131. myCommand.Parameters.Clear();
  1132. AddCmdParam(ref myCommand, "msisdn", listMsisdn[i]);
  1133. AddCmdParam(ref myCommand, "message", broadcast.msg_adv);
  1134. AddCmdParam(ref myCommand, "send_time", DateTime.ParseExact(broadcast.schedule_time, "dd/MM/yyyy HH:mm:ss", null));
  1135. AddCmdParam(ref myCommand, "channel", broadcast.channel_adv);
  1136. AddCmdParam(ref myCommand, "message_type", broadcast.message_type);
  1137. AddCmdParam(ref myCommand, "broadcast_id", broadcast.id);
  1138. myCommand.ExecuteNonQuery();
  1139. if (i % 1000 == 999)
  1140. {
  1141. transaction.Commit();
  1142. transaction = myConnection.BeginTransaction();
  1143. myCommand.Transaction = transaction;
  1144. }
  1145. }
  1146. transaction.Commit();
  1147. return i;
  1148. }
  1149. }
  1150. catch (Exception ex)
  1151. {
  1152. log.Error("Error ImportSubBroadcast", ex);
  1153. return i;
  1154. }
  1155. finally
  1156. {
  1157. try
  1158. {
  1159. if (myConnection != null)
  1160. {
  1161. myConnection.Close();
  1162. }
  1163. }
  1164. catch { }
  1165. }
  1166. }
  1167. public bool InsertMtExtendFromTemp(int broadcastId)
  1168. {
  1169. DbConnection myConnection = null;
  1170. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  1171. String sqlCommand = "broadcast_from_temp";
  1172. try
  1173. {
  1174. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  1175. {
  1176. DbCommand myCommand = myConnection.CreateCommand();
  1177. myCommand.CommandType = CommandType.StoredProcedure;
  1178. myCommand.CommandText = sqlCommand;
  1179. myCommand.Parameters.Clear();
  1180. AddCmdParam(ref myCommand, "brid", broadcastId);
  1181. myCommand.ExecuteNonQuery();
  1182. return true;
  1183. }
  1184. }
  1185. catch (Exception ex)
  1186. {
  1187. log.Error("Error InsertMtExtendFromTemp", ex);
  1188. return false;
  1189. }
  1190. finally
  1191. {
  1192. try
  1193. {
  1194. if (myConnection != null)
  1195. {
  1196. myConnection.Close();
  1197. }
  1198. }
  1199. catch { }
  1200. }
  1201. }
  1202. public bool DeleteMtExtendTemp(int broadcastId)
  1203. {
  1204. try
  1205. {
  1206. String sql = "DELETE FROM mt_extend_temp WHERE broadcast_id= ?";
  1207. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1208. stmt.SetParameters(broadcastId);
  1209. stmt.ExecuteNonQuery(connType);
  1210. stmt.CloseConnection();
  1211. return true;
  1212. }
  1213. catch (Exception ex)
  1214. {
  1215. log.Error("Error DeleteMtExtendTemp", ex);
  1216. return false;
  1217. }
  1218. }
  1219. public bool DeleteMtExtend(int broadcastId)
  1220. {
  1221. try
  1222. {
  1223. String sql = "DELETE FROM mt_extend WHERE broadcast_id= ?";
  1224. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1225. stmt.SetParameters(broadcastId);
  1226. stmt.ExecuteNonQuery(connType);
  1227. stmt.CloseConnection();
  1228. return true;
  1229. }
  1230. catch (Exception ex)
  1231. {
  1232. log.Error("Error DeleteMtExtend", ex);
  1233. return false;
  1234. }
  1235. }
  1236. public int GetNextBroadcastId()
  1237. {
  1238. try
  1239. {
  1240. String sql = @"select broadcast_seq.nextval seq from dual";
  1241. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1242. OracleDataReader reader = (OracleDataReader)stmt.ExecuteReader(connType);
  1243. int seq = 0;
  1244. while (reader.Read())
  1245. {
  1246. seq = int.Parse(reader.GetValue(0).ToString());
  1247. }
  1248. stmt.CloseConnection();
  1249. return seq;
  1250. }
  1251. catch (Exception ex)
  1252. {
  1253. log.Error("Error GetNextBroadcastId", ex);
  1254. return 0;
  1255. }
  1256. }
  1257. public List<ReportDetail> GetReportDetail(DateTime fromDate, DateTime toDate)
  1258. {
  1259. DbConnection myConnection = null;
  1260. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  1261. String sqlCommand = @"SELECT a.sv_code, to_char(a.report_date,'dd/mm/yyyy') report_date, a.revenue_others, a.revenue_mocha,
  1262. a.revenue_web, a.revenue_buy_others, a.revenue_buy_mocha,
  1263. a.revenue_buy_web, a.count_reg_others, a.count_reg_mocha,
  1264. a.count_reg_web FROM report_detail a WHERE REPORT_DATE >= :fromDate and REPORT_DATE <= :toDate ORDER BY report_date desc";
  1265. // @"select
  1266. //'LUCKY_DRAW' SV_CODE,
  1267. // to_char(REPORT_DATE,'dd-mm-yyyy') REPORT_DATE,
  1268. //nvl(revenue_others,0) REVENUE_OTHERS,
  1269. //nvl(revenue_mocha,0) REVENUE_MOCHA,
  1270. //nvl(revenue_web,0) revenue_web,
  1271. //nvl(revenue_buy_others,0) REVENUE_BUY_OTHERS,
  1272. //nvl(revenue_buy_mocha,0) REVENUE_BUY_MOCHA,
  1273. //nvl(revenue_buy_web,0) revenue_buy_web,
  1274. //nvl(count_reg_others,0) count_reg_others ,
  1275. //nvl(count_reg_mocha,0) count_reg_mocha ,
  1276. //nvl(count_reg_web,0) count_reg_web
  1277. //from
  1278. //(
  1279. //select a.report_date, a.revenue_others, revenue_mocha, revenue_web, revenue_buy_others, revenue_buy_mocha, revenue_buy_web, count_reg_others, count_reg_mocha, count_reg_web from
  1280. //( select nvl(sum(fee),0) revenue_others, trunc(charge_time) REPORT_DATE from charge_log
  1281. // where charge_time >= :from_date and charge_time < :to_date + 1 and fee > 0 and product_name = 'Lucky_Draw' and channel not in ('1','4')
  1282. // group by trunc(charge_time) ) a
  1283. // left join
  1284. //(select nvl(sum(fee),0) revenue_mocha, trunc(charge_time) REPORT_DATE from charge_log
  1285. // where charge_time >= :from_date and charge_time < :to_date + 1 and fee > 0 and product_name = 'Lucky_Draw' and channel = '1'
  1286. // group by trunc(charge_time) ) a2 on a.report_date = a2.report_date
  1287. //left join
  1288. //(select nvl(sum(fee),0) revenue_web, trunc(charge_time) REPORT_DATE from charge_log
  1289. // where charge_time >= :from_date and charge_time < :to_date + 1 and fee > 0 and product_name = 'Lucky_Draw' and channel = '4'
  1290. // group by trunc(charge_time) ) a3 on a.report_date = a3.report_date
  1291. //left join
  1292. //(select nvl(sum(fee),0) revenue_buy_others, trunc(charge_time) REPORT_DATE from charge_log
  1293. // where charge_time >= :from_date and charge_time < :to_date + 1 and fee > 0 and product_name = 'Lucky_Draw' and description in ('Redeem')and channel not in ('1','4')
  1294. // group by trunc(charge_time) ) b on a.report_date = b.report_date
  1295. //left join
  1296. //(select nvl(sum(fee),0) revenue_buy_mocha, trunc(charge_time) REPORT_DATE from charge_log
  1297. // where charge_time >= :from_date and charge_time < :to_date+ 1 and fee > 0 and product_name = 'Lucky_Draw' and description in ('Redeem')and channel = '1'
  1298. // group by trunc(charge_time) ) b2 on a.report_date = b2.report_date
  1299. //left join
  1300. //(select nvl(sum(fee),0) revenue_buy_web, trunc(charge_time) REPORT_DATE from charge_log
  1301. // where charge_time >= :from_date and charge_time < :to_date+ 1 and fee > 0 and product_name = 'Lucky_Draw' and description in ('Redeem')and channel = '4'
  1302. // group by trunc(charge_time) ) b3 on a.report_date = b3.report_date
  1303. //left join
  1304. //(select count(*) count_reg_others, trunc(register_time) REPORT_DATE from reg_info
  1305. // where register_time >= :from_date and register_time < :to_date+ 1 and channel not in ('1','4')
  1306. // group by trunc(register_time) ) c on c.report_date = a.report_date
  1307. //left join
  1308. //(select count(*) count_reg_mocha, trunc(register_time) REPORT_DATE from reg_info
  1309. // where register_time >= :from_date and register_time < :to_date+ 1 and channel = '1'
  1310. // group by trunc(register_time) ) c2 on c2.report_date = a.report_date
  1311. //left join
  1312. //(select count(*) count_reg_web, trunc(register_time) REPORT_DATE from reg_info
  1313. // where register_time >= :from_date and register_time < :to_date+ 1 and channel = '4'
  1314. // group by trunc(register_time) ) c3 on c3.report_date = a.report_date
  1315. // ) a order by a.report_date desc ";
  1316. try
  1317. {
  1318. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  1319. {
  1320. DbCommand myCommand = myConnection.CreateCommand();
  1321. myCommand.CommandText = sqlCommand;
  1322. myCommand.Parameters.Clear();
  1323. // from date
  1324. AddCmdParam(ref myCommand, "fromDate", fromDate);
  1325. // todate
  1326. AddCmdParam(ref myCommand, "toDate", toDate);
  1327. DbDataReader reader = myCommand.ExecuteReader();
  1328. return ReportDetail.Parse((OracleDataReader)reader);
  1329. }
  1330. }
  1331. catch (Exception ex)
  1332. {
  1333. log.Error("Error GetReportDetail", ex);
  1334. return null;
  1335. }
  1336. finally
  1337. {
  1338. try
  1339. {
  1340. if (myConnection != null)
  1341. {
  1342. myConnection.Close();
  1343. }
  1344. }
  1345. catch { }
  1346. }
  1347. }
  1348. public List<WebserviceObj> GetWebserviceById(int wsId)
  1349. {
  1350. try
  1351. {
  1352. String sql =
  1353. @"SELECT * from webservice where ws_id = ?";
  1354. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1355. stmt.SetParameters(wsId);
  1356. var rs = WebserviceObj.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1357. stmt.CloseConnection();
  1358. return rs;
  1359. }
  1360. catch (Exception ex)
  1361. {
  1362. log.Error("Error GetWebserviceById", ex);
  1363. return null;
  1364. }
  1365. }
  1366. public List<WebserviceObj> LoadListWebserivce(String wsName)
  1367. {
  1368. try
  1369. {
  1370. String sql =
  1371. @"SELECT * from webservice WHERE ws_name = ?"
  1372. + " ORDER BY ws_code";
  1373. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1374. stmt.SetParameters(wsName);
  1375. var rs = WebserviceObj.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1376. stmt.CloseConnection();
  1377. return rs;
  1378. }
  1379. catch (Exception ex)
  1380. {
  1381. log.Error("Error LoadListWebserivce", ex);
  1382. return null;
  1383. }
  1384. }
  1385. public bool InsertWebservice(WebserviceObj wsObj)
  1386. {
  1387. try
  1388. {
  1389. String sql = @"INSERT INTO webservice (WS_ID,WS_NAME,WS_CODE,WSDL,MSG_TEMPLATE,STATUS)
  1390. VALUES(webservice_seq.nextval, ?, ?, ?, ?, 1)";
  1391. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1392. stmt.SetParameters(
  1393. wsObj.ws_name,
  1394. wsObj.ws_code,
  1395. wsObj.wsdl,
  1396. wsObj.msg_template);
  1397. stmt.ExecuteNonQuery(connType);
  1398. stmt.CloseConnection();
  1399. return true;
  1400. }
  1401. catch (Exception ex)
  1402. {
  1403. log.Error("Error InsertWebservice", ex);
  1404. return false;
  1405. }
  1406. }
  1407. public bool UpdateWebservice(WebserviceObj wsObj)
  1408. {
  1409. try
  1410. {
  1411. String sql = "UPDATE webservice SET WS_NAME = ?, WS_CODE = ?, WSDL = ?, MSG_TEMPLATE = ? "
  1412. + " WHERE WS_ID = ?";
  1413. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1414. stmt.SetParameters(
  1415. wsObj.ws_name,
  1416. wsObj.ws_code,
  1417. wsObj.wsdl,
  1418. wsObj.msg_template,
  1419. wsObj.ws_id);
  1420. stmt.ExecuteNonQuery(connType);
  1421. stmt.CloseConnection();
  1422. return true;
  1423. }
  1424. catch (Exception ex)
  1425. {
  1426. log.Error("Error UpdateWebservice", ex);
  1427. return false;
  1428. }
  1429. }
  1430. public bool UpdateWebserviceStatus(int id, string status)
  1431. {
  1432. try
  1433. {
  1434. String sql = "UPDATE webservice SET STATUS = ? WHERE ws_id = ?";
  1435. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1436. stmt.SetParameters(status, id);
  1437. stmt.ExecuteNonQuery(connType);
  1438. stmt.CloseConnection();
  1439. return true;
  1440. }
  1441. catch (Exception ex)
  1442. {
  1443. log.Error("Error UpdateWebserviceStatus", ex);
  1444. return false;
  1445. }
  1446. }
  1447. // SV ADV
  1448. public bool InsertSvAdv(string svCode, string msgAdv, string advName, string channelAdv, string messageType, string activeHour, string maxNumberMsg, string fromMoney)
  1449. {
  1450. try
  1451. {
  1452. String sql = @"INSERT INTO sv_adv (ID, SV_CODE,ADV_NAME,MSG_ADV,MSG_ADV_PUSH,CHANNEL_ADV,MESSAGE_TYPE,ACTIVE_HOUR,max_number_msg,FROM_MONEY,STATUS )
  1453. VALUES(sv_adv_seq.nextval, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)";
  1454. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1455. stmt.SetParameters(svCode, advName, msgAdv, msgAdv, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney);
  1456. stmt.ExecuteNonQuery(connType);
  1457. stmt.CloseConnection();
  1458. return true;
  1459. }
  1460. catch (Exception ex)
  1461. {
  1462. log.Error("Error InsertSvReport", ex);
  1463. return false;
  1464. }
  1465. }
  1466. //public bool InsertSvAdvHistory(string svCode, string messageType)
  1467. //{
  1468. // try
  1469. // {
  1470. // String sql = @"INSERT INTO sv_adv_history (ID,SV_CODE,START_TIME,END_TIME,COUNT_MSG,MESSAGE_TYPE)
  1471. // VALUES(sv_adv_history_seq.nextval, ?, sysdate, NULL, 0, ?)";
  1472. // SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1473. // stmt.SetParameters(svCode, messageType);
  1474. // stmt.ExecuteNonQuery(connType);
  1475. // stmt.CloseConnection();
  1476. // return true;
  1477. // }
  1478. // catch (Exception ex)
  1479. // {
  1480. // log.Error("Error InsertSvAdvHistory", ex);
  1481. // return false;
  1482. // }
  1483. //}
  1484. public bool UpdateServiceAdvInfo(string svCode, string msgAdv, string advName, string channelAdv, string messageType, string activeHour, string maxNumberMsg, string fromMoney, string advId)
  1485. {
  1486. try
  1487. {
  1488. String sql = @"Update sv_adv set sv_code = ?, msg_adv = ?,adv_name = ?,channel_adv = ?,message_type = ?,active_hour = ? ,max_number_msg=?,from_money = ?
  1489. where id = ?";
  1490. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1491. stmt.SetParameters(svCode, msgAdv, advName, channelAdv, messageType, activeHour, maxNumberMsg, fromMoney, advId);
  1492. stmt.ExecuteNonQuery(connType);
  1493. stmt.CloseConnection();
  1494. return true;
  1495. }
  1496. catch (Exception ex)
  1497. {
  1498. log.Error("Error UpdateServiceAdvInfo", ex);
  1499. return false;
  1500. }
  1501. }
  1502. public bool UpdateServiceAdvStatus(string advId, string status)
  1503. {
  1504. try
  1505. {
  1506. String sql = @"Update sv_adv set status = ? where id = ?";
  1507. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1508. stmt.SetParameters(status, advId);
  1509. stmt.ExecuteNonQuery(connType);
  1510. stmt.CloseConnection();
  1511. return true;
  1512. }
  1513. catch (Exception ex)
  1514. {
  1515. log.Error("Error UpdateServiceAdvStatus", ex);
  1516. return false;
  1517. }
  1518. }
  1519. //public bool UpdateServiceAdvEndTime(string svCode)
  1520. //{
  1521. // try
  1522. // {
  1523. // String sql = @"Update sv_adv_history set end_time = sysdate WHERE sv_code = ? and end_time is null";
  1524. // SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1525. // stmt.SetParameters(svCode);
  1526. // stmt.ExecuteNonQuery(connType);
  1527. // stmt.CloseConnection();
  1528. // return true;
  1529. // }
  1530. // catch (Exception ex)
  1531. // {
  1532. // log.Error("Error UpdateServiceAdvStatus", ex);
  1533. // return false;
  1534. // }
  1535. //}
  1536. // Service Adv schedule
  1537. public SvAdvSchedule GetSvAdvScheduleById(string scheduleId, int codeType)
  1538. {
  1539. try
  1540. {
  1541. String sql;
  1542. if (codeType == LuckyCardUtils.CodeType.LUCKY_CARD)
  1543. {
  1544. sql = @"select s.*, a.adv_name, d.sv_adv_id, d.sv_code, d.msg_adv, a.msg_adv_push, d.channel_adv, d.message_type, d.from_money,
  1545. d.active_hour, d.max_number_msg, d.id schedule_detail_id, nvl(d.percent,0) percent
  1546. from sv_adv_schedule s
  1547. left join sv_adv a on a.status = 1
  1548. left join sv_adv_schedule_detail d on s.id = d.schedule_id and d.sv_adv_id = a.id and d.status = 1
  1549. where s.id = ?";
  1550. }
  1551. else
  1552. {
  1553. sql = @"select s.*, a.adv_name, d.sv_adv_id, d.sv_code, d.msg_adv, d.msg_adv_push, d.channel_adv, d.message_type, d.from_money,
  1554. d.active_hour, d.max_number_msg, d.id schedule_detail_id, nvl(d.percent,0) percent
  1555. from sv_adv_schedule_call s
  1556. left join sv_adv a on a.status = 1
  1557. left join sv_adv_schedule_detail_call d on s.id = d.schedule_id and d.sv_adv_id = a.id and d.status = 1
  1558. where s.id = ?";
  1559. }
  1560. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1561. stmt.SetParameters(scheduleId);
  1562. var rs = SvAdvSchedule.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1563. stmt.CloseConnection();
  1564. if (rs != null && rs.Count > 0)
  1565. {
  1566. return rs[0];
  1567. }
  1568. return null;
  1569. }
  1570. catch (Exception ex)
  1571. {
  1572. log.Error("Error GetSvAdvScheduleById", ex);
  1573. return null;
  1574. }
  1575. }
  1576. public bool UpdateSvAdvScheduleInfo(SvAdvSchedule svAdvSchedule, int codeType)
  1577. {
  1578. DbConnection myConnection = null;
  1579. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  1580. String sqlUpdateSchedule = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1581. ? "UPDATE sv_adv_schedule SET from_date = :from_date, to_date = :to_date, schedule_name = :schedule_name, max_total_msg = :max_total_msg WHERE id = :id"
  1582. : "UPDATE sv_adv_schedule_call SET from_date = :from_date, to_date = :to_date, schedule_name = :schedule_name, max_total_msg = :max_total_msg WHERE id = :id";
  1583. String sqlDeleteAdv = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1584. ? "UPDATE sv_adv_schedule_detail SET status = 0 WHERE schedule_id = :schedule_id"
  1585. : "UPDATE sv_adv_schedule_detail_call SET status = 0 WHERE schedule_id = :schedule_id";
  1586. String sqlInsertAdv = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1587. ? @"INSERT INTO sv_adv_schedule_detail
  1588. (ID,SCHEDULE_ID,SV_ADV_ID,PERCENT,SV_CODE,MSG_ADV,CHANNEL_ADV,MESSAGE_TYPE,FROM_MONEY,ACTIVE_HOUR,MAX_NUMBER_MSG)
  1589. SELECT sv_adv_schedule_detail_seq.nextval,
  1590. :schedule_id, id, :percent, sv_code, msg_adv, channel_adv, message_type, from_money, active_hour,MAX_NUMBER_MSG FROM sv_adv WHERE id = :sv_adv_id"
  1591. : @"INSERT INTO sv_adv_schedule_detail_call
  1592. (ID,SCHEDULE_ID,SV_ADV_ID,PERCENT,SV_CODE,MSG_ADV,CHANNEL_ADV,MESSAGE_TYPE,FROM_MONEY,ACTIVE_HOUR,MAX_NUMBER_MSG)
  1593. SELECT sv_adv_schedule_detail_seq.nextval,
  1594. :schedule_id, id, :percent, sv_code, msg_adv, channel_adv, message_type, from_money, active_hour,MAX_NUMBER_MSG FROM sv_adv WHERE id = :sv_adv_id";
  1595. try
  1596. {
  1597. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  1598. {
  1599. DbTransaction transaction = myConnection.BeginTransaction();
  1600. DbCommand myCommand = myConnection.CreateCommand();
  1601. myCommand.Transaction = transaction;
  1602. // update schedule
  1603. myCommand.CommandText = sqlUpdateSchedule;
  1604. myCommand.Parameters.Clear();
  1605. AddCmdParam(ref myCommand, "from_date", svAdvSchedule.from_date);
  1606. AddCmdParam(ref myCommand, "to_date", svAdvSchedule.to_date);
  1607. AddCmdParam(ref myCommand, "schedule_name", svAdvSchedule.schedule_name);
  1608. AddCmdParam(ref myCommand, "max_total_msg", svAdvSchedule.max_total_msg);
  1609. AddCmdParam(ref myCommand, "id", svAdvSchedule.id);
  1610. myCommand.ExecuteNonQuery();
  1611. // delete old adv
  1612. myCommand.CommandText = sqlDeleteAdv;
  1613. myCommand.Parameters.Clear();
  1614. AddCmdParam(ref myCommand, "schedule_id", svAdvSchedule.id);
  1615. myCommand.ExecuteNonQuery();
  1616. // insert new adv
  1617. myCommand.CommandText = sqlInsertAdv;
  1618. for (int i = 0; i < svAdvSchedule.list_adv.Count; i++)
  1619. {
  1620. SvAdv adv = svAdvSchedule.list_adv[i];
  1621. myCommand.Parameters.Clear();
  1622. AddCmdParam(ref myCommand, "schedule_id", svAdvSchedule.id);
  1623. AddCmdParam(ref myCommand, "percent", adv.percent);
  1624. AddCmdParam(ref myCommand, "sv_adv_id", adv.id);
  1625. //AddCmdParam(ref myCommand, "sv_code", adv.sv_code);
  1626. //AddCmdParam(ref myCommand, "msg_adv", adv.msg_adv);
  1627. //AddCmdParam(ref myCommand, "channel_adv", adv.channel_adv);
  1628. //AddCmdParam(ref myCommand, "message_type", adv.message_type);
  1629. //AddCmdParam(ref myCommand, "from_money", adv.from_money);
  1630. myCommand.ExecuteNonQuery();
  1631. }
  1632. transaction.Commit();
  1633. return true;
  1634. }
  1635. }
  1636. catch (Exception ex)
  1637. {
  1638. log.Error("Error UpdateSvAdvScheduleInfo", ex);
  1639. return false;
  1640. }
  1641. finally
  1642. {
  1643. try
  1644. {
  1645. if (myConnection != null)
  1646. {
  1647. myConnection.Close();
  1648. }
  1649. }
  1650. catch { }
  1651. }
  1652. }
  1653. public bool UpdateSvAdvScheduleStatus(string scheduleId, string status, int codeType)
  1654. {
  1655. try
  1656. {
  1657. String sql = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1658. ? @"Update sv_adv_schedule set status = ? where id = ?"
  1659. : @"Update sv_adv_schedule_call set status = ? where id = ?";
  1660. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1661. stmt.SetParameters(status, scheduleId);
  1662. stmt.ExecuteNonQuery(connType);
  1663. stmt.CloseConnection();
  1664. return true;
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. log.Error("Error UpdateSvAdvScheduleStatus", ex);
  1669. return false;
  1670. }
  1671. }
  1672. public List<SvAdv> LoadListServicesAdv()
  1673. {
  1674. try
  1675. {
  1676. String sql = @"select sv.sv_code, sv.sv_name, a.msg_adv, a.adv_name, a.channel_adv, a.message_type,
  1677. a.from_money, a.active_hour, a.max_number_msg, a.status, a.id
  1678. from sv join sv_adv a on sv.sv_code = a.sv_code
  1679. where sv.status = 1
  1680. and a.status = 1 ORDER BY sv.sv_code ";
  1681. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1682. var rs = SvAdv.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1683. stmt.CloseConnection();
  1684. return rs;
  1685. }
  1686. catch (Exception ex)
  1687. {
  1688. log.Error("Error LoadListServicesAdv", ex);
  1689. return null;
  1690. }
  1691. }
  1692. public List<SvAdvSchedule> LoadListSvAdvSchedule(int month, int year, int codeType)
  1693. {
  1694. try
  1695. {
  1696. String sql = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1697. ? @"select s.*, d.sv_adv_id, d.sv_code, d.msg_adv, d.channel_adv, d.message_type, d.from_money,
  1698. d.id schedule_detail_id, nvl(d.percent,0) percent , sa.adv_name
  1699. from sv_adv_schedule s
  1700. left join sv_adv_schedule_detail d on s.id = d.schedule_id and d.status = 1
  1701. left join sv_adv sa on sa.id = d.sv_adv_id
  1702. where 1=1
  1703. and s.from_date < ? +1
  1704. and s.to_date >= ?
  1705. ORDER BY s.from_date desc"
  1706. : @"select s.*, d.sv_adv_id, d.sv_code, d.msg_adv, d.channel_adv, d.message_type, d.from_money,
  1707. d.id schedule_detail_id, nvl(d.percent,0) percent , sa.adv_name
  1708. from sv_adv_schedule_call s
  1709. left join sv_adv_schedule_detail_call d on s.id = d.schedule_id and d.status = 1
  1710. left join sv_adv_call sa on sa.id = d.sv_adv_id
  1711. where 1=1
  1712. and s.from_date < ? +1
  1713. and s.to_date >= ?
  1714. ORDER BY s.from_date desc";
  1715. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1716. DateTime max = new DateTime(year, month, DateTime.DaysInMonth(year, month));
  1717. DateTime min = new DateTime(year, month, 1);
  1718. stmt.SetParameters(max, min);
  1719. var rs = SvAdvSchedule.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1720. stmt.CloseConnection();
  1721. return rs;
  1722. }
  1723. catch (Exception ex)
  1724. {
  1725. log.Error("Error LoadListSvAdvSchedule", ex);
  1726. return null;
  1727. }
  1728. }
  1729. public List<SvAdv> LoadListSvAdvCounter(int month, int year, int codeType)
  1730. {
  1731. try
  1732. {
  1733. String sql = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1734. ? @"select nvl(c.schedule_detail_id,-1) schedule_detail_id,
  1735. nvl(c.counter,0) counter, nvl(c.create_time, s.from_date) start_time, nvl(c.report_date, trunc(s.from_date)) report_date,
  1736. nvl(s.to_date, trunc(c.report_date) + 1 - 1/86400) end_time, d.*, a.adv_name
  1737. from sv_adv_schedule_detail d
  1738. join sv_adv a on a.id = d.sv_adv_id
  1739. full outer join schedule_counter c on d.id = c.schedule_detail_id
  1740. left join sv_adv_schedule s on s.id = d.schedule_id
  1741. where 1=1
  1742. and nvl(c.create_time, s.from_date) < ? + 1
  1743. and nvl(c.create_time, s.to_date) >= ?
  1744. ORDER BY nvl(c.report_date, trunc(s.from_date)) desc, d.sv_code"
  1745. : @"select nvl(c.schedule_detail_id,-1) schedule_detail_id,
  1746. nvl(c.counter,0) counter, nvl(c.create_time, s.from_date) start_time, nvl(c.report_date, trunc(s.from_date)) report_date,
  1747. nvl(s.to_date, trunc(c.report_date) + 1 - 1/86400) end_time, d.*, a.adv_name
  1748. from sv_adv_schedule_detail_call d
  1749. join sv_adv a on a.id = d.sv_adv_id
  1750. full outer join schedule_counter_call c on d.id = c.schedule_detail_id
  1751. left join sv_adv_schedule_call s on s.id = d.schedule_id
  1752. where 1=1
  1753. and nvl(c.create_time, s.from_date) < ? + 1
  1754. and nvl(c.create_time, s.to_date) >= ?
  1755. ORDER BY nvl(c.create_time, s.from_date) desc, d.sv_code";
  1756. SqlStatement stmt = SqlStatement.FromString(sql, SqlConnString.GAMEPORTAL);
  1757. DateTime max = new DateTime(year, month, DateTime.DaysInMonth(year, month));
  1758. DateTime min = new DateTime(year, month, 1);
  1759. stmt.SetParameters(max, min);
  1760. var rs = SvAdv.Parse((OracleDataReader)stmt.ExecuteReader(connType));
  1761. stmt.CloseConnection();
  1762. return rs;
  1763. }
  1764. catch (Exception ex)
  1765. {
  1766. log.Error("Error LoadListSvAdvCounter", ex);
  1767. return null;
  1768. }
  1769. }
  1770. public bool InsertSvAdvSchedule(SvAdvSchedule svAdvSchedule, int codeType)
  1771. {
  1772. DbConnection myConnection = null;
  1773. SqlStatement stmt = new SqlStatement(SqlConnString.GAMEPORTAL);
  1774. String sqlGetScheduleId = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1775. ? "SELECT sv_adv_schedule_seq.nextval seq FROM DUAL"
  1776. : "SELECT sv_adv_schedule_call_seq.nextval seq FROM DUAL";
  1777. String sqlUpdateSchedule = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1778. ? @"INSERT INTO sv_adv_schedule (ID,FROM_DATE,TO_DATE,SCHEDULE_NAME,max_total_msg,STATUS)
  1779. VALUES(:schedule_id, :from_date, :to_date, :schedule_name, :max_total_msg, 1)"
  1780. : @"INSERT INTO sv_adv_schedule_call (ID,FROM_DATE,TO_DATE,SCHEDULE_NAME,max_total_msg,STATUS)
  1781. VALUES(:schedule_id, :from_date, :to_date, :schedule_name, :max_total_msg, 1)";
  1782. String sqlInsertAdv = codeType == LuckyCardUtils.CodeType.LUCKY_CARD
  1783. ? @"INSERT INTO sv_adv_schedule_detail
  1784. (ID,SCHEDULE_ID,SV_ADV_ID,PERCENT,SV_CODE,MSG_ADV,CHANNEL_ADV,MESSAGE_TYPE,FROM_MONEY,ACTIVE_HOUR,MAX_NUMBER_MSG)
  1785. SELECT sv_adv_schedule_detail_seq.nextval,
  1786. :schedule_id, id, :percent, sv_code, msg_adv, channel_adv, message_type, from_money, active_hour,MAX_NUMBER_MSG FROM sv_adv WHERE id = :sv_adv_id"
  1787. : @"INSERT INTO sv_adv_schedule_detail_call
  1788. (ID,SCHEDULE_ID,SV_ADV_ID,PERCENT,SV_CODE,MSG_ADV,CHANNEL_ADV,MESSAGE_TYPE,FROM_MONEY,ACTIVE_HOUR,MAX_NUMBER_MSG)
  1789. SELECT sv_adv_schedule_detail_seq.nextval,
  1790. :schedule_id, id, :percent, sv_code, msg_adv, channel_adv, message_type, from_money, active_hour,MAX_NUMBER_MSG FROM sv_adv WHERE id = :sv_adv_id";
  1791. // VALUES(sv_adv_schedule_detail_seq.nextval, :schedule_id, :sv_adv_id, :percent, :sv_code, :msg_adv, :channel_adv, :message_type, :from_money)";
  1792. try
  1793. {
  1794. using (myConnection = (DbConnection)stmt.GetConnection(connType))
  1795. {
  1796. DbTransaction transaction = myConnection.BeginTransaction();
  1797. DbCommand myCommand = myConnection.CreateCommand();
  1798. myCommand.Transaction = transaction;
  1799. // get sequence
  1800. myCommand.CommandText = sqlGetScheduleId;
  1801. myCommand.Parameters.Clear();
  1802. DbDataReader reader = myCommand.ExecuteReader();
  1803. if (reader.Read())
  1804. {
  1805. svAdvSchedule.id = reader.GetInt32(0);
  1806. }
  1807. // update schedule
  1808. myCommand.CommandText = sqlUpdateSchedule;
  1809. myCommand.Parameters.Clear();
  1810. AddCmdParam(ref myCommand, "schedule_id", svAdvSchedule.id);
  1811. AddCmdParam(ref myCommand, "from_date", svAdvSchedule.from_date);
  1812. AddCmdParam(ref myCommand, "to_date", svAdvSchedule.to_date);
  1813. AddCmdParam(ref myCommand, "schedule_name", svAdvSchedule.schedule_name);
  1814. AddCmdParam(ref myCommand, "max_total_msg", svAdvSchedule.max_total_msg);
  1815. myCommand.ExecuteNonQuery();
  1816. // insert new adv
  1817. myCommand.CommandText = sqlInsertAdv;
  1818. for (int i = 0; i < svAdvSchedule.list_adv.Count; i++)
  1819. {
  1820. SvAdv adv = svAdvSchedule.list_adv[i];
  1821. myCommand.Parameters.Clear();
  1822. AddCmdParam(ref myCommand, "schedule_id", svAdvSchedule.id);
  1823. AddCmdParam(ref myCommand, "percent", adv.percent);
  1824. AddCmdParam(ref myCommand, "sv_adv_id", adv.id);
  1825. //AddCmdParam(ref myCommand, "sv_code", adv.sv_code);
  1826. //AddCmdParam(ref myCommand, "msg_adv", adv.msg_adv);
  1827. //AddCmdParam(ref myCommand, "channel_adv", adv.channel_adv);
  1828. //AddCmdParam(ref myCommand, "message_type", adv.message_type);
  1829. //AddCmdParam(ref myCommand, "from_money", adv.from_money);
  1830. myCommand.ExecuteNonQuery();
  1831. }
  1832. transaction.Commit();
  1833. return true;
  1834. }
  1835. }
  1836. catch (Exception ex)
  1837. {
  1838. log.Error("Error InsertSvAdvSchedule", ex);
  1839. return false;
  1840. }
  1841. finally
  1842. {
  1843. try
  1844. {
  1845. if (myConnection != null)
  1846. {
  1847. myConnection.Close();
  1848. }
  1849. }
  1850. catch { }
  1851. }
  1852. }
  1853. public ErrResponse ProcessPrizeTop(long id)
  1854. {
  1855. try
  1856. {
  1857. using (OracleConnection objConn = new OracleConnection(SqlCommon.GetConnectionString(SqlConnString.GAMEPORTAL)))
  1858. {
  1859. OracleCommand objCmd = new OracleCommand();
  1860. objCmd.Connection = objConn;
  1861. objCmd.CommandText = "process_prize_top";
  1862. objCmd.CommandType = CommandType.StoredProcedure;
  1863. objCmd.Parameters.Add("id_", OracleDbType.Int32).Value = id;
  1864. objCmd.Parameters.Add("cur_employees", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
  1865. try
  1866. {
  1867. objConn.Open();
  1868. OracleDataReader objReader = objCmd.ExecuteReader();
  1869. ErrResponse res = new ErrResponse();
  1870. while (objReader.Read())
  1871. {
  1872. for (int i = 0; i < objReader.FieldCount; i++)
  1873. {
  1874. if (objReader.GetName(i).ToUpper() == "ERROR")
  1875. {
  1876. res.error = objReader[i].ToString();
  1877. }
  1878. else if (objReader.GetName(i).ToUpper() == "MESSAGE")
  1879. {
  1880. res.message = objReader[i].ToString();
  1881. }
  1882. }
  1883. return res;
  1884. }
  1885. res.error = "-1";
  1886. res.message = "Not found";
  1887. return res;
  1888. }
  1889. catch (Exception ex)
  1890. {
  1891. log.Error("Exception ProcessPrizeTop: ", ex);
  1892. return new ErrResponse("-1", "Error database");
  1893. }
  1894. finally
  1895. {
  1896. try
  1897. {
  1898. objConn.Close();
  1899. }
  1900. catch { }
  1901. }
  1902. }
  1903. }
  1904. catch (Exception ex)
  1905. {
  1906. log.Error("Error ProcessPrizeTop", ex);
  1907. return new ErrResponse("-1", "Error database");
  1908. }
  1909. }
  1910. }
  1911. }