Adding.cshtml 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. @*
  2. For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
  3. *@
  4. @using SuperCms.Controllers;
  5. @using SuperCms.Models;
  6. @using System.Globalization;
  7. @model ConfigViewModel
  8. @{
  9. // set today date for all
  10. DateTime oDateFrom = DateTime.ParseExact(DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
  11. String date = oDateFrom.ToString("yyyy-MM-dd'T'HH:mm:ss.fff", CultureInfo.InvariantCulture);
  12. String ranStr = UtilsController.RandomString(10, true);
  13. }
  14. <script>
  15. $('#myInform').modal('hide');
  16. </script>
  17. <div class="modal-content">
  18. <div class="modal-header">
  19. <h4 class="modal-title" id="modalLabelService">@UtilsController.convertNameTable(Model.tableType)</h4>
  20. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  21. <span aria-hidden="true">×</span>
  22. </button>
  23. </div>
  24. <div class="modal-body">
  25. @{
  26. if (Model.tableType == UtilsController.Constant.BOTS || Model.tableType == UtilsController.Constant.GROUPS)
  27. {
  28. <div class="row">
  29. <div class="col-md-12">
  30. <div class="form-group">
  31. <label for="team1">Code</label>
  32. <input class="form-control" type="text" id="name" name="name" autocomplete="on" value="">
  33. </div>
  34. </div>
  35. <div class="col-md-12">
  36. <div class="form-group">
  37. <label for="fromDate">Name</label>
  38. <textarea class="form-control" id="description" name="description" autocomplete="off" rows="3" spellcheck="false"></textarea>
  39. </div>
  40. </div>
  41. <div class="col-md-4">
  42. <div class="form-group">
  43. <label for="serviceCode">Status</label>
  44. <select id="status" name="status" class="form-control">
  45. @{
  46. for (int i = 0; i <= UtilsController.Constant.MAX_BOT_STATUS; i++)
  47. {
  48. <option value="@i">@UtilsController.convertBotStatus(i)</option>
  49. }
  50. }
  51. </select>
  52. </div>
  53. </div>
  54. <div class="col-md-4">
  55. <div class="form-group">
  56. <label for="fromDate">From date</label>
  57. <input class="model-box-input" type="datetime-local" id="fromDate" name="fromDate" value="@date">
  58. </div>
  59. </div>
  60. <div class="col-md-4">
  61. <div class="form-group">
  62. <label for="toDate">To date</label>
  63. <input class="model-box-input" type="datetime-local" id="toDate" name="toDate" value="@date">
  64. </div>
  65. </div>
  66. </div>
  67. }
  68. else if (Model.tableType == UtilsController.Constant.CONFIGS)
  69. {
  70. <div class="row">
  71. <div class="col-md-6">
  72. <div class="form-group">
  73. <label for="team1">Key</label>
  74. <input class="form-control" type="text" id="key" name="key" autocomplete="on" value="">
  75. </div>
  76. </div>
  77. <div class="col-md-6">
  78. <div class="form-group">
  79. <label for="team1">Value</label>
  80. <input class="form-control" type="text" id="value" name="value" autocomplete="on" value="">
  81. </div>
  82. </div>
  83. </div>
  84. }
  85. else if (Model.tableType == UtilsController.Constant.SENDMAIL)
  86. {
  87. <input type="hidden" class="tableType" id="tableType" name="tableType" value="@Model.tableType" />
  88. <div class="row">
  89. <div class="col-md-4">
  90. <div class="form-group">
  91. <label for="serviceCode">Telcos</label>
  92. <select id="telcoId" name="telcoId" class="form-control" onchange="telcoSendMailClick(this.value)">
  93. <option value="@Model.telco.id">@Model.telco.telcoName</option>
  94. @{
  95. for (int i = 0; i < Model.telcos.data.Count; i++)
  96. {
  97. if (Model.telcos.data[i].id != Model.telco.id)
  98. {
  99. <option value="@Model.telcos.data[i].id">@Model.telcos.data[i].telcoName</option>
  100. }
  101. }
  102. }
  103. @*<option value="-1">ALL</option>*@
  104. </select>
  105. </div>
  106. </div>
  107. <div class="col-md-4 company-model-style">
  108. <div class="form-group">
  109. <label for="serviceCode">Companies</label>
  110. <select id="companyId" name="companyId" class="form-control" onchange="companySendMailClick(this.value)">
  111. @{
  112. if (Model.company != null)
  113. {
  114. <option value="@Model.company.id">@Model.company.name</option>
  115. for (int i = 0; i < Model.companies.data.Count; i++)
  116. {
  117. if (Model.companies.data[i].id != Model.company.id)
  118. {
  119. <option value="@Model.companies.data[i].id">@Model.companies.data[i].name</option>
  120. }
  121. }
  122. }
  123. }
  124. @*<option value="-1">ALL</option>*@
  125. </select>
  126. </div>
  127. </div>
  128. <div class="col-md-4 service-model-style">
  129. <div class="form-group">
  130. <label for="serviceCode">Services</label>
  131. <select id="serviceId" name="serviceId" class="form-control">
  132. @{
  133. for (int i = 0; i < Model.services.data.Count; i++)
  134. {
  135. <option value="@Model.services.data[i].id">@Model.services.data[i].serviceName</option>
  136. }
  137. }
  138. @*<option value="-1">ALL</option>*@
  139. </select>
  140. </div>
  141. </div>
  142. <div class="col-md-6">
  143. <div class="form-group">
  144. <label for="serviceCode">Status</label>
  145. <select id="status" name="status" class="form-control">
  146. @{
  147. if (Model.sendMail != null)
  148. {
  149. <option value="@Model.sendMail.status">@UtilsController.convertBotStatus(int.Parse(Model.sendMail.status))</option>
  150. for (int i = 0; i <= UtilsController.Constant.MAX_BOT_STATUS; i++)
  151. {
  152. if (i.ToString() != Model.sendMail.status)
  153. {
  154. <option value="@i">@UtilsController.convertBotStatus(i)</option>
  155. }
  156. }
  157. }
  158. else
  159. {
  160. for (int i = 0; i <= UtilsController.Constant.MAX_BOT_STATUS; i++)
  161. {
  162. <option value="@i">@UtilsController.convertBotStatus(i)</option>
  163. }
  164. }
  165. }
  166. </select>
  167. </div>
  168. </div>
  169. <div class="col-md-6">
  170. <div class="form-group">
  171. <label for="toDate">Time send</label>
  172. <input class="model-box-input" type="datetime-local" id="timeSend" name="timeSend" value="@date">
  173. </div>
  174. </div>
  175. <div class="col-md-6">
  176. <div class="form-group content-box">
  177. <label for="toDate">List emails</label>
  178. @{
  179. if (Model.sendMail != null)
  180. {
  181. <textarea class="form-control" id="listMail" name="listMail" autocomplete="off" rows="3" spellcheck="false">@Model.sendMail.listMail</textarea>
  182. }
  183. else
  184. {
  185. <textarea class="form-control" id="listMail" name="listMail" autocomplete="off" rows="3" spellcheck="false"></textarea>
  186. }
  187. }
  188. </div>
  189. </div>
  190. <div class="col-md-6">
  191. <div class="form-group content-box">
  192. <label for="toDate">Message (if have))</label>
  193. @{
  194. if (Model.sendMail != null)
  195. {
  196. <textarea class="form-control" id="message" name="message" autocomplete="off" rows="3" spellcheck="false">@Model.sendMail.message</textarea>
  197. }
  198. else
  199. {
  200. <textarea class="form-control" id="message" name="message" autocomplete="off" rows="3" spellcheck="false"></textarea>
  201. }
  202. }
  203. </div>
  204. </div>
  205. </div>
  206. }
  207. else if (Model.tableType == UtilsController.Constant.SERVICE_CONFIG)
  208. {
  209. <input type="hidden" class="tableType" id="tableType" name="tableType" value="@Model.tableType" />
  210. <div class="row">
  211. <div class="col-md-3">
  212. <div class="form-group">
  213. <label for="serviceCode">Thị trường</label>
  214. <select id="telcoId" name="telcoId" class="form-control" onchange="telcoServiceClick(this.value)">
  215. <option value="@Model.telco.id">@Model.telco.telcoName</option>
  216. @{
  217. for (int i = 0; i < Model.telcos.data.Count; i++)
  218. {
  219. if (Model.telcos.data[i].id != Model.telco.id)
  220. {
  221. <option value="@Model.telcos.data[i].id">@Model.telcos.data[i].telcoName</option>
  222. }
  223. }
  224. }
  225. @*<option value="-1">ALL</option>*@
  226. </select>
  227. </div>
  228. </div>
  229. <div class="col-md-3 company-model-style">
  230. <div class="form-group">
  231. <label for="serviceCode">Công ty</label>
  232. <select id="companyId" name="companyId" class="form-control" onchange="companyServiceClick(this.value)">
  233. @{
  234. if (Model.company != null)
  235. {
  236. <option value="@Model.company.id">@Model.company.name</option>
  237. for (int i = 0; i < Model.companies.data.Count; i++)
  238. {
  239. if (Model.companies.data[i].id != Model.company.id)
  240. {
  241. <option value="@Model.companies.data[i].id">@Model.companies.data[i].name</option>
  242. }
  243. }
  244. }
  245. }
  246. @*<option value="-1">ALL</option>*@
  247. </select>
  248. </div>
  249. </div>
  250. <div class="col-md-3">
  251. <div class="form-group">
  252. <label for="serviceCode">Trạng thái</label>
  253. <select id="status" name="status" class="form-control">
  254. @{
  255. for (int i = 0; i <= UtilsController.Constant.MAX_WARNING_STATUS; i++)
  256. {
  257. <option value="@i">@UtilsController.convertBotStatus(i)</option>
  258. }
  259. }
  260. </select>
  261. </div>
  262. </div>
  263. <div class="col-md-3">
  264. <div class="form-group">
  265. <label for="serviceCode">Có trả thưởng ?</label>
  266. <select id="state" name="state" class="form-control">
  267. @{
  268. for (int i = 0; i <= UtilsController.Constant.MAX_BOT_STATUS; i++)
  269. {
  270. <option value="@i">@UtilsController.convertServiceState(i)</option>
  271. }
  272. }
  273. </select>
  274. </div>
  275. </div>
  276. <div class="col-md-4 service-model-style">
  277. <div class="form-group">
  278. <label for="serviceCode">Tên dịch vụ</label>
  279. <input class="form-control" type="text" id="serviceName" name="serviceName" autocomplete="on" value="">
  280. </div>
  281. </div>
  282. <div class="col-md-4 service-model-style">
  283. <div class="form-group">
  284. <label for="toDate">Thời gian chạy</label>
  285. <input class="model-box-input" type="time" id="hourRun" name="hourRun" value="" required>
  286. </div>
  287. </div>
  288. <div class="col-md-4 service-model-style">
  289. <div class="form-group">
  290. <label for="serviceCode">Hạn mức tiền cảnh báo</label>
  291. <input class="form-control" type="number" id="money" name="money" autocomplete="on" value="">
  292. </div>
  293. </div>
  294. <div class="col-md-6 service-model-style">
  295. <div class="form-group">
  296. <label for="serviceCode">URL</label>
  297. @*<input class="form-control" type="text" id="url" name="url" autocomplete="on" value="">*@
  298. <textarea class="form-control" id="url" name="url" autocomplete="off" rows="3" spellcheck="false"></textarea>
  299. </div>
  300. </div>
  301. <div class="col-md-6">
  302. <div class="form-group content-box">
  303. <label for="toDate">V_SQL</label>
  304. <textarea class="form-control" id="vSql" name="vSql" autocomplete="off" rows="3" spellcheck="false"></textarea>
  305. </div>
  306. </div>
  307. <div class="col-md-12">
  308. <div class="form-group content-box">
  309. <label for="toDate">CONNECTION</label>
  310. <textarea class="form-control" id="connection" name="connection" autocomplete="off" rows="3" spellcheck="false"></textarea>
  311. </div>
  312. </div>
  313. </div>
  314. }
  315. else
  316. {
  317. // Schedules
  318. <div class="row">
  319. <div class="col-md-12">
  320. <div class="form-group">
  321. <label for="team1">Name</label>
  322. <input class="form-control" type="text" id="name" name="name" autocomplete="on" value="">
  323. </div>
  324. </div>
  325. <div class="col-md-12">
  326. <div class="form-group">
  327. <label for="fromDate">Description</label>
  328. <textarea class="form-control" id="description" name="description" autocomplete="off" rows="3" spellcheck="false"></textarea>
  329. </div>
  330. </div>
  331. <div class="col-md-6">
  332. <div class="form-group">
  333. <label for="serviceCode">Bot name</label>
  334. <select id="botID" name="botID" class="form-control">
  335. @{
  336. for (int i = 0; i < Model.bots.data.Count; i++)
  337. {
  338. <option value="@Model.bots.data[i].id">@Model.bots.data[i].description</option>
  339. }
  340. }
  341. </select>
  342. </div>
  343. </div>
  344. <div class="col-md-6">
  345. <div class="form-group">
  346. <label for="serviceCode">Group name</label>
  347. <select id="groupID" name="groupID" class="form-control">
  348. @{
  349. for (int i = 0; i < Model.groups.data.Count; i++)
  350. {
  351. <option value="@Model.groups.data[i].id">@Model.groups.data[i].description</option>
  352. }
  353. }
  354. </select>
  355. </div>
  356. </div>
  357. <div class="col-md-6">
  358. <div class="form-group">
  359. <label for="serviceCode">Status</label>
  360. <select id="status" name="status" class="form-control">
  361. @{
  362. for (int i = 0; i <= UtilsController.Constant.MAX_SCHEDULE_STATUS; i++)
  363. {
  364. <option value="@i">@UtilsController.convertScheduleStatus(i)</option>
  365. }
  366. }
  367. </select>
  368. </div>
  369. </div>
  370. <div class="col-md-6">
  371. <div class="form-group">
  372. <label for="fromDate">Time notification</label>
  373. <input class="model-box-input" type="datetime-local" id="timeRun" name="timeRun" value="@date">
  374. </div>
  375. </div>
  376. <div class="col-md-12">
  377. <div class="form-group">
  378. <label for="fromDate">Note</label>
  379. <input class="form-control" type="text" id="note" name="note" autocomplete="on" value="">
  380. </div>
  381. </div>
  382. <div class="col-md-12">
  383. <div class="form-group content-box">
  384. <label for="toDate">Content</label>
  385. <textarea class="form-control" id="content" name="content" autocomplete="off" rows="3" spellcheck="false"></textarea>
  386. </div>
  387. </div>
  388. </div>
  389. }
  390. }
  391. </div>
  392. <div class="modal-footer">
  393. <button type="button" class="btn grey btn-outline-secondary" data-dismiss="modal">Close</button>
  394. <button type="button" id="btnUpdateInfo" class="btn btn-outline-primary" onclick="saveAdding()">Create</button>
  395. </div>
  396. </div>
  397. <script>
  398. function saveAdding() {
  399. console.log("saveAdding");
  400. var check = 1;
  401. var formData = new FormData();
  402. var name = "";
  403. var description = "";
  404. var status = "";
  405. var botID = "";
  406. var groupID = "";
  407. var timeRun = "";
  408. var note = "";
  409. var content = "";
  410. var note = "";
  411. var fromDate = "";
  412. var toDate = "";
  413. var timeRun = "";
  414. var hourRun = "";
  415. var money = "";
  416. var serviceName = "";
  417. var url = "";
  418. var vSql = "";
  419. var state = "";
  420. var connection = "";
  421. var key = "";
  422. var value = "";
  423. // for send mail
  424. var telcoId = "", companyId = "", serviceId = "", timeSend = "", listMail = "", message = "";
  425. if (@Model.tableType == @UtilsController.Constant.SENDMAIL) {
  426. telcoId = $("#telcoId").val();
  427. companyId = $("#companyId").val();
  428. status = $("#status").val();
  429. serviceId = $("#serviceId").val();
  430. timeSend = $("#timeSend").val();
  431. listMail = $("#listMail").val();
  432. message = $("#message").val();
  433. console.log("telcoId", telcoId);
  434. console.log("companyId", companyId);
  435. console.log("status", status);
  436. console.log("serviceId", serviceId);
  437. console.log("timeSend", timeSend);
  438. console.log("listMail", listMail);
  439. console.log("message", message);
  440. if (listMail == null || listMail == "") {
  441. $("#listMail").addClass("note-input");
  442. check *= 0;
  443. } else {
  444. $("#listMail").removeClass("note-input");
  445. }
  446. } else if (@Model.tableType == @UtilsController.Constant.SCHEDULES) {
  447. name = $("#name").val();
  448. description = $("#description").val();
  449. status = $("#status").val();
  450. botID = $("#botID").val();
  451. groupID = $("#groupID").val();
  452. timeRun = $("#timeRun").val();
  453. note = $("#note").val();
  454. content = $("#content").val();
  455. if (name == null || name == "") {
  456. $("#name").addClass("note-input");
  457. check *= 0;
  458. } else {
  459. $("#name").removeClass("note-input");
  460. }
  461. if (content == null || content == "") {
  462. $(".content").addClass("note-input");
  463. check *= 0;
  464. } else {
  465. $(".content").removeClass("note-input");
  466. }
  467. } else if (@Model.tableType == @UtilsController.Constant.CONFIGS) {
  468. key = $("#key").val();
  469. value = $("#value").val();
  470. if (key == null || key == "") {
  471. $("#key").addClass("note-input");
  472. check *= 0;
  473. } else {
  474. $("#key").removeClass("note-input");
  475. }
  476. if (value == null || value == "") {
  477. $("#value").addClass("note-input");
  478. check *= 0;
  479. } else {
  480. $("#value").removeClass("note-input");
  481. }
  482. } else if (@Model.tableType == @UtilsController.Constant.SERVICE_CONFIG) {
  483. telcoId = $("#telcoId").val();
  484. companyId = $("#companyId").val();
  485. status = $("#status").val();
  486. serviceName = $("#serviceName").val();
  487. url = $("#url").val();
  488. vSql = $("#vSql").val();
  489. state = $("#state").val();
  490. connection = $("#connection").val();
  491. hourRun = $("#hourRun").val();
  492. money = $("#money").val();
  493. if (serviceName == null || serviceName == "") {
  494. $("#serviceName").addClass("note-input");
  495. check *= 0;
  496. } else {
  497. $("#serviceName").removeClass("note-input");
  498. }
  499. if (url == null || url == "") {
  500. $("#url").addClass("note-input");
  501. check *= 0;
  502. } else {
  503. $("#url").removeClass("note-input");
  504. }
  505. if (vSql == null || vSql == "") {
  506. $("#vSql").addClass("note-input");
  507. check *= 0;
  508. } else {
  509. $("#vSql").removeClass("note-input");
  510. }
  511. if (connection == null || connection == "") {
  512. $("#connection").addClass("note-input");
  513. check *= 0;
  514. } else {
  515. $("#connection").removeClass("note-input");
  516. }
  517. if (hourRun == null || hourRun == "") {
  518. $("#hourRun").addClass("note-input");
  519. check *= 0;
  520. } else {
  521. $("#hourRun").removeClass("note-input");
  522. }
  523. if (money == null || money == "") {
  524. $("#money").addClass("note-input");
  525. check *= 0;
  526. } else {
  527. $("#money").removeClass("note-input");
  528. }
  529. }
  530. else {
  531. name = $("#name").val();
  532. description = $("#description").val();
  533. status = $("#status").val();
  534. fromDate = $("#fromDate").val();
  535. toDate = $("#toDate").val();
  536. if (name == null || name == "") {
  537. $("#name").addClass("note-input");
  538. check *= 0;
  539. } else {
  540. $("#name").removeClass("note-input");
  541. }
  542. }
  543. if (check == 1) {
  544. formData.append('__RequestVerificationToken', $('input[name=__RequestVerificationToken]').val());
  545. formData.append('name', name);
  546. formData.append('description', description);
  547. formData.append('status', status);
  548. formData.append('startDate', fromDate);
  549. formData.append('endDate', toDate);
  550. formData.append('botID', botID);
  551. formData.append('groupID', groupID);
  552. formData.append('timeRun', timeRun);
  553. formData.append('note', note);
  554. formData.append('content', content);
  555. formData.append('value', value);
  556. formData.append('key', key);
  557. // send mail
  558. formData.append('telcoId', telcoId);
  559. formData.append('companyId', companyId);
  560. formData.append('serviceId', serviceId);
  561. formData.append('timeSend', timeSend);
  562. formData.append('listMail', listMail);
  563. formData.append('message', message);
  564. // conn config
  565. formData.append('serviceName', serviceName);
  566. formData.append('url', url);
  567. formData.append('vSql', vSql);
  568. formData.append('state', state);
  569. formData.append('connection', connection);
  570. formData.append('hourRun', hourRun);
  571. formData.append('money', money);
  572. $.ajax({
  573. type: "POST",
  574. url: "@(Model.tableType == UtilsController.Constant.BOTS ? "/Config/AddingBotAction" :
  575. Model.tableType == UtilsController.Constant.SENDMAIL ? "/Config/AddingSendMailAction" :
  576. Model.tableType == UtilsController.Constant.GROUPS ? "/Config/AddingGroupAction" :
  577. Model.tableType == UtilsController.Constant.SCHEDULES ? "/Config/AddingScheduleAction" :
  578. Model.tableType == UtilsController.Constant.SERVICE_CONFIG ? "/Config/AddingServiceAction" :
  579. "/Config/AddingConfigAction")",
  580. headers: { 'RequestVerificationToken': $('input[name=__RequestVerificationToken]').val() },
  581. data: formData,
  582. processData: false,
  583. contentType: false,
  584. success: function (data) {
  585. if (data.code == @UtilsController.Constant.SUCCESS) {
  586. window.location.href = data.href;
  587. } else {
  588. $.ajax({
  589. type: "POST",
  590. url: "/Partial/Response",
  591. data: {
  592. "message": "An error was happened"
  593. },
  594. success: function (data) {
  595. $('#informModel').html(data);
  596. $('#myInform').modal({ "backdrop": "static", keyboard: true });
  597. $('#myInform').modal('show');
  598. },
  599. failure: function (data) {
  600. console.log(data);
  601. alert(data);
  602. },
  603. error: function (data) {
  604. console.log(data);
  605. alert(data);
  606. }
  607. });
  608. }
  609. },
  610. failure: function (data) {
  611. console.log(data);
  612. alert(data);
  613. },
  614. error: function (data) {
  615. console.log(data);
  616. alert(data);
  617. }
  618. });
  619. }
  620. }
  621. </script>