DataAccess.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Common;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Configuration;
  9. using MySql.Data.MySqlClient;
  10. using System.Runtime.InteropServices.ComTypes;
  11. using static DataManager.UIConstants;
  12. using System.ComponentModel.Design;
  13. using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
  14. using System.Xml.Linq;
  15. using System.Windows;
  16. using System.Security.Policy;
  17. namespace DataManager
  18. {
  19. public class DataAccess
  20. {
  21. private static String connectionString = ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString;
  22. public const sbyte DM_NULL = -99;
  23. public static DataTable Get_cm_user_by_cellphone(string cellphone)
  24. {
  25. MySqlConnection connection = new MySqlConnection(connectionString);
  26. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_cm_user_by_cellphone", connection);
  27. MySqlParameter i_cellphone = new MySqlParameter("i_cellphone", cellphone);
  28. ad.SelectCommand.Parameters.Add(i_cellphone);
  29. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  30. DataTable dt = new DataTable();
  31. ad.Fill(dt);
  32. connection.Close();
  33. return dt;
  34. }
  35. public static DataTable Get_dm_user(int? userId, sbyte? role)
  36. {
  37. MySqlConnection connection = new MySqlConnection(connectionString);
  38. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_user", connection);
  39. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  40. MySqlParameter i_role = new MySqlParameter("i_role", role);
  41. ad.SelectCommand.Parameters.Add(i_userid);
  42. ad.SelectCommand.Parameters.Add(i_role);
  43. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  44. DataTable dt = new DataTable();
  45. ad.Fill(dt);
  46. connection.Close();
  47. return dt;
  48. }
  49. /// <summary>
  50. /// 取数据采集任务列表
  51. /// </summary>
  52. /// <param name="userId"></param>
  53. /// <param name="taskId"></param>
  54. /// <param name="companyId"></param>
  55. /// <param name="taskDate"></param>
  56. /// <param name="taskType"></param>
  57. /// <param name="isValid"></param>
  58. /// <returns></returns>
  59. public static DataTable Get_dm_collection_task(int? userId, int? taskId, string providerId, string providerKeyword,
  60. DateTime? taskDate, short? taskType, string entityId, string entityKeyword, sbyte? isValid)
  61. {
  62. MySqlConnection connection = new MySqlConnection(connectionString);
  63. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_collection_task", connection);
  64. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  65. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  66. MySqlParameter i_provider_id = new MySqlParameter("i_provider_id", providerId);
  67. MySqlParameter i_provider_keyword = new MySqlParameter("i_provider_keyword", providerKeyword);
  68. MySqlParameter i_task_date = new MySqlParameter("i_task_date", taskDate);
  69. MySqlParameter i_task_type = new MySqlParameter("i_task_type", taskType);
  70. MySqlParameter i_entity_id = new MySqlParameter("i_entity_id", entityId);
  71. MySqlParameter i_entity_keywordword = new MySqlParameter("i_entity_keyword", entityKeyword);
  72. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isValid);
  73. ad.SelectCommand.Parameters.Add(i_userid);
  74. ad.SelectCommand.Parameters.Add(i_task_id);
  75. ad.SelectCommand.Parameters.Add(i_provider_id);
  76. ad.SelectCommand.Parameters.Add(i_provider_keyword);
  77. ad.SelectCommand.Parameters.Add(i_task_date);
  78. ad.SelectCommand.Parameters.Add(i_task_type);
  79. ad.SelectCommand.Parameters.Add(i_entity_id);
  80. ad.SelectCommand.Parameters.Add(i_entity_keywordword);
  81. ad.SelectCommand.Parameters.Add(i_isvalid);
  82. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  83. DataTable dt = new DataTable();
  84. ad.Fill(dt);
  85. connection.Close();
  86. return dt;
  87. }
  88. public static void Set_dm_collection_task(int? taskId, string providerId, DateTime taskDate, Int16 taskType,
  89. string entityId, string errMessage,
  90. sbyte isvalid, int userId, out int task_id)
  91. {
  92. task_id = 0;
  93. using (MySqlConnection connection = new MySqlConnection(connectionString))
  94. {
  95. connection.Open();
  96. MySqlCommand cmd = new MySqlCommand("sp_set_dm_collection_task", connection);
  97. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  98. MySqlParameter i_provider_id = new MySqlParameter("i_provider_id", providerId);
  99. MySqlParameter i_task_date = new MySqlParameter("i_task_date", taskDate);
  100. MySqlParameter i_task_type = new MySqlParameter("i_task_type", taskType);
  101. MySqlParameter i_entity_id = new MySqlParameter("i_entity_id", entityId);
  102. MySqlParameter i_err_message = new MySqlParameter("i_err_message", errMessage);
  103. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isvalid);
  104. MySqlParameter i_user_id = new MySqlParameter("i_user_id", userId);
  105. MySqlParameter o_task_id = new MySqlParameter("o_task_id", DbType.Int32);
  106. o_task_id.Direction = ParameterDirection.Output;
  107. cmd.Parameters.Add(i_task_id);
  108. cmd.Parameters.Add(i_provider_id);
  109. cmd.Parameters.Add(i_task_date);
  110. cmd.Parameters.Add(i_task_type);
  111. cmd.Parameters.Add(i_isvalid);
  112. cmd.Parameters.Add(i_entity_id);
  113. cmd.Parameters.Add(i_err_message);
  114. cmd.Parameters.Add(i_user_id);
  115. cmd.Parameters.Add(o_task_id);
  116. cmd.CommandType = CommandType.StoredProcedure;
  117. cmd.Connection = connection;
  118. cmd.ExecuteNonQuery();
  119. task_id = int.Parse(cmd.Parameters["o_task_id"].Value.ToString());
  120. }
  121. }
  122. /// <summary>
  123. /// 取公司联系任务列表
  124. /// </summary>
  125. /// <param name="userId"></param>
  126. /// <param name="taskId"></param>
  127. /// <param name="companyId"></param>
  128. /// <param name="taskDate"></param>
  129. /// <param name="taskType"></param>
  130. /// <param name="isValid"></param>
  131. /// <param name="priority"></param>
  132. /// <param name="followUpDate"></param>
  133. /// <param name="companyAsset"></param>
  134. /// <returns></returns>
  135. public static DataTable Get_dm_contact_task(int? userId, int? taskId, string companyId, string companyKeyword,
  136. DateTime? taskDate, short? taskType, sbyte? isValid, sbyte? priority,
  137. DateTime? followUpDate, sbyte? companyAsset)
  138. {
  139. MySqlConnection connection = new MySqlConnection(connectionString);
  140. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_contact_task", connection);
  141. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  142. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  143. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  144. MySqlParameter i_company_keyword = new MySqlParameter("i_company_keyword", companyKeyword);
  145. MySqlParameter i_task_date = new MySqlParameter("i_task_date", taskDate);
  146. MySqlParameter i_task_type = new MySqlParameter("i_task_type", taskType);
  147. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isValid);
  148. MySqlParameter i_priority = new MySqlParameter("i_priority", priority);
  149. MySqlParameter i_follow_up_date = new MySqlParameter("i_follow_up_date", followUpDate);
  150. MySqlParameter i_company_asset_size = new MySqlParameter("i_company_asset_size", companyAsset);
  151. ad.SelectCommand.Parameters.Add(i_userid);
  152. ad.SelectCommand.Parameters.Add(i_task_id);
  153. ad.SelectCommand.Parameters.Add(i_company_id);
  154. ad.SelectCommand.Parameters.Add(i_company_keyword);
  155. ad.SelectCommand.Parameters.Add(i_task_date);
  156. ad.SelectCommand.Parameters.Add(i_task_type);
  157. ad.SelectCommand.Parameters.Add(i_isvalid);
  158. ad.SelectCommand.Parameters.Add(i_priority);
  159. ad.SelectCommand.Parameters.Add(i_follow_up_date);
  160. ad.SelectCommand.Parameters.Add(i_company_asset_size);
  161. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  162. DataTable dt = new DataTable();
  163. ad.Fill(dt);
  164. connection.Close();
  165. return dt;
  166. }
  167. /// <summary>
  168. /// 更新联系任务表
  169. /// </summary>
  170. /// <param name="taskId"></param>
  171. /// <param name="companyId"></param>
  172. /// <param name="taskDate"></param>
  173. /// <param name="taskType"></param>
  174. /// <param name="isvalid"></param>
  175. /// <param name="priority"></param>
  176. /// <param name="followUpDate"></param>
  177. /// <param name="userId"></param>
  178. public static void Set_dm_contact_task(int? taskId, string companyId, DateTime taskDate, Int16 taskType, sbyte isvalid,
  179. sbyte priority, DateTime? followUpDate, int userId, out int task_id)
  180. {
  181. task_id = 0;
  182. using (MySqlConnection connection = new MySqlConnection(connectionString))
  183. {
  184. connection.Open();
  185. MySqlCommand cmd = new MySqlCommand("sp_set_dm_contact_task", connection);
  186. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  187. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  188. MySqlParameter i_task_date = new MySqlParameter("i_task_date", taskDate);
  189. MySqlParameter i_task_type = new MySqlParameter("i_task_type", taskType);
  190. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isvalid);
  191. MySqlParameter i_priority = new MySqlParameter("i_priority", priority);
  192. MySqlParameter i_follow_up_date = new MySqlParameter("i_follow_up_date", followUpDate);
  193. MySqlParameter i_user_id = new MySqlParameter("i_user_id", userId);
  194. MySqlParameter o_task_id = new MySqlParameter("o_task_id", DbType.Int32);
  195. o_task_id.Direction = ParameterDirection.Output;
  196. cmd.Parameters.Add(i_task_id);
  197. cmd.Parameters.Add(i_company_id);
  198. cmd.Parameters.Add(i_task_date);
  199. cmd.Parameters.Add(i_task_type);
  200. cmd.Parameters.Add(i_isvalid);
  201. cmd.Parameters.Add(i_priority);
  202. cmd.Parameters.Add(i_follow_up_date);
  203. cmd.Parameters.Add(i_user_id);
  204. cmd.Parameters.Add(o_task_id);
  205. cmd.CommandType = CommandType.StoredProcedure;
  206. cmd.Connection = connection;
  207. cmd.ExecuteNonQuery();
  208. task_id = int.Parse(cmd.Parameters["o_task_id"].Value.ToString());
  209. }
  210. }
  211. /// <summary>
  212. /// 取基金基本信息
  213. /// </summary>
  214. /// <param name="fundId"></param>
  215. /// <returns></returns>
  216. public static DataTable Get_dm_fund_information(string fundId, string companyId)
  217. {
  218. MySqlConnection connection = new MySqlConnection(connectionString);
  219. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_fund_information", connection);
  220. MySqlParameter i_fundId = new MySqlParameter("i_fund_id", fundId);
  221. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  222. ad.SelectCommand.Parameters.Add(i_fundId);
  223. ad.SelectCommand.Parameters.Add(i_company_id);
  224. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  225. DataTable dt = new DataTable();
  226. ad.Fill(dt);
  227. connection.Close();
  228. return dt;
  229. }
  230. public static void Set_dm_fund_information(string fundId, string fundShortName, int? strategyId, int? substrategyId,
  231. string parentFundId, string navFrequency,
  232. sbyte isAuthorized, sbyte isRanking, sbyte isRating, int userId)
  233. {
  234. using (MySqlConnection connection = new MySqlConnection(connectionString))
  235. {
  236. connection.Open();
  237. MySqlCommand cmd = new MySqlCommand("sp_set_dm_fund_information", connection);
  238. MySqlParameter i_fund_id = new MySqlParameter("i_fund_id", fundId);
  239. MySqlParameter i_fund_short_name = new MySqlParameter("i_fund_short_name", fundShortName);
  240. MySqlParameter i_strategy_id = new MySqlParameter("i_strategy_id", strategyId);
  241. MySqlParameter i_substrategy_id = new MySqlParameter("i_substrategy_id", substrategyId);
  242. MySqlParameter i_p_fund_id = new MySqlParameter("i_p_fund_id", parentFundId);
  243. MySqlParameter i_nav_frequency = new MySqlParameter("i_nav_frequency", navFrequency);
  244. MySqlParameter i_is_authorized = new MySqlParameter("i_is_authorized", isAuthorized);
  245. MySqlParameter i_is_ranking = new MySqlParameter("i_is_ranking", isRanking);
  246. MySqlParameter i_is_rating = new MySqlParameter("i_is_rating", isRating);
  247. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  248. cmd.Parameters.Add(i_fund_id);
  249. cmd.Parameters.Add(i_fund_short_name);
  250. cmd.Parameters.Add(i_strategy_id);
  251. cmd.Parameters.Add(i_substrategy_id);
  252. cmd.Parameters.Add(i_p_fund_id);
  253. cmd.Parameters.Add(i_nav_frequency);
  254. cmd.Parameters.Add(i_is_authorized);
  255. cmd.Parameters.Add(i_is_ranking);
  256. cmd.Parameters.Add(i_is_rating);
  257. cmd.Parameters.Add(i_userid);
  258. cmd.CommandType = CommandType.StoredProcedure;
  259. cmd.Connection = connection;
  260. cmd.ExecuteNonQuery();
  261. }
  262. }
  263. public static DataTable Get_dm_company_information(string companyId)
  264. {
  265. MySqlConnection connection = new MySqlConnection(connectionString);
  266. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_company_information", connection);
  267. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  268. ad.SelectCommand.Parameters.Add(i_company_id);
  269. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  270. DataTable dt = new DataTable();
  271. ad.Fill(dt);
  272. connection.Close();
  273. return dt;
  274. }
  275. public static int Set_dm_company_information(string companyId, string shortName, int userId)
  276. {
  277. int ret = -1;
  278. using (MySqlConnection connection = new MySqlConnection(connectionString))
  279. {
  280. connection.Open();
  281. MySqlCommand cmd = new MySqlCommand("sp_set_dm_company_information", connection);
  282. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  283. MySqlParameter i_company_short_name = new MySqlParameter("i_company_short_name", shortName);
  284. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  285. cmd.Parameters.Add(i_company_id);
  286. cmd.Parameters.Add(i_company_short_name);
  287. cmd.Parameters.Add(i_userid);
  288. cmd.CommandType = CommandType.StoredProcedure;
  289. cmd.Connection = connection;
  290. cmd.ExecuteNonQuery();
  291. ret = 1;
  292. }
  293. return ret;
  294. }
  295. /// <summary>
  296. /// 搜索公司(目前仅支持对 company_short_name 的搜索)
  297. /// </summary>
  298. /// <param name="companyType"></param> 私募证券:1
  299. /// <param name="keyWord"></param>
  300. /// <returns></returns>
  301. public static DataTable Search_dm_company(int? companyType, string keyWord)
  302. {
  303. MySqlConnection connection = new MySqlConnection(connectionString);
  304. MySqlDataAdapter ad = new MySqlDataAdapter("sp_dm_search_company", connection);
  305. MySqlParameter i_companyType = new MySqlParameter("i_company_type", companyType);
  306. MySqlParameter i_keyWord = new MySqlParameter("i_key_word", keyWord);
  307. ad.SelectCommand.Parameters.Add(i_companyType);
  308. ad.SelectCommand.Parameters.Add(i_keyWord);
  309. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  310. DataTable dt = new DataTable();
  311. ad.Fill(dt);
  312. connection.Close();
  313. return dt;
  314. }
  315. /// <summary>
  316. /// 搜索基金(目前仅支持对 fund_short_name 的搜索)
  317. /// </summary>
  318. /// <param name="raiseType"></param> 私募:1、公募:2
  319. /// <param name="keyWord"></param>
  320. /// <returns></returns>
  321. public static DataTable Search_dm_fund(int? raiseType, string keyWord)
  322. {
  323. MySqlConnection connection = new MySqlConnection(connectionString);
  324. MySqlDataAdapter ad = new MySqlDataAdapter("sp_dm_search_fund", connection);
  325. MySqlParameter i_raise_type = new MySqlParameter("i_raise_type", raiseType);
  326. MySqlParameter i_keyWord = new MySqlParameter("i_key_word", keyWord);
  327. ad.SelectCommand.Parameters.Add(i_raise_type);
  328. ad.SelectCommand.Parameters.Add(i_keyWord);
  329. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  330. DataTable dt = new DataTable();
  331. ad.Fill(dt);
  332. connection.Close();
  333. return dt;
  334. }
  335. /// <summary>
  336. /// 从 mfdb 里取NAV
  337. /// </summary>
  338. /// <param name="fundId"></param>
  339. /// <param name="startDate"></param>
  340. /// <param name="endDate"></param>
  341. /// <returns></returns>
  342. public static DataTable Get_Nav(string fundId, DateTime? startDate, DateTime? endDate)
  343. {
  344. MySqlConnection connection = new MySqlConnection(connectionString);
  345. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_nav", connection);
  346. MySqlParameter i_fund_id = new MySqlParameter("i_fund_id", fundId);
  347. MySqlParameter i_start_date = new MySqlParameter("i_start_date", startDate);
  348. MySqlParameter i_end_date = new MySqlParameter("i_end_date", endDate);
  349. ad.SelectCommand.Parameters.Add(i_fund_id);
  350. ad.SelectCommand.Parameters.Add(i_start_date);
  351. ad.SelectCommand.Parameters.Add(i_end_date);
  352. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  353. DataTable dt = new DataTable();
  354. ad.Fill(dt);
  355. connection.Close();
  356. return dt;
  357. }
  358. /// <summary>
  359. /// 从 raw_db 里取原始NAV
  360. /// </summary>
  361. /// <param name="fundId"></param>
  362. /// <param name="startDate"></param>
  363. /// <param name="endDate"></param>
  364. /// <returns></returns>
  365. public static DataTable Get_dm_nav(string fundId, string providerId, string externalId, DateTime? startDate, DateTime? endDate)
  366. {
  367. MySqlConnection connection = new MySqlConnection(connectionString);
  368. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_nav", connection);
  369. MySqlParameter i_fund_id = new MySqlParameter("i_fund_id", fundId);
  370. MySqlParameter i_provider_id = new MySqlParameter("i_provider_id", providerId);
  371. MySqlParameter i_external_id = new MySqlParameter("i_external_id", externalId);
  372. MySqlParameter i_start_date = new MySqlParameter("i_start_date", startDate);
  373. MySqlParameter i_end_date = new MySqlParameter("i_end_date", endDate);
  374. ad.SelectCommand.Parameters.Add(i_fund_id);
  375. ad.SelectCommand.Parameters.Add(i_provider_id);
  376. ad.SelectCommand.Parameters.Add(i_external_id);
  377. ad.SelectCommand.Parameters.Add(i_start_date);
  378. ad.SelectCommand.Parameters.Add(i_end_date);
  379. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  380. DataTable dt = new DataTable();
  381. ad.Fill(dt);
  382. connection.Close();
  383. return dt;
  384. }
  385. public static DataTable Get_dm_memo(sbyte jobType, int taskId)
  386. {
  387. MySqlConnection connection = new MySqlConnection(connectionString);
  388. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_task_memo", connection);
  389. MySqlParameter i_job_type = new MySqlParameter("i_job_type", jobType);
  390. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  391. ad.SelectCommand.Parameters.Add(i_job_type);
  392. ad.SelectCommand.Parameters.Add(i_task_id);
  393. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  394. DataTable dt = new DataTable();
  395. ad.Fill(dt);
  396. connection.Close();
  397. return dt;
  398. }
  399. public static void Set_dm_memo(sbyte jobType, int taskId, string memo, int userId)
  400. {
  401. using (MySqlConnection connection = new MySqlConnection(connectionString))
  402. {
  403. connection.Open();
  404. MySqlCommand cmd = new MySqlCommand("sp_set_dm_task_memo", connection);
  405. MySqlParameter i_job_type = new MySqlParameter("i_job_type", jobType);
  406. MySqlParameter i_task_id = new MySqlParameter("i_task_id", taskId);
  407. MySqlParameter i_memo = new MySqlParameter("i_memo", memo);
  408. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  409. cmd.Parameters.Add(i_job_type);
  410. cmd.Parameters.Add(i_task_id);
  411. cmd.Parameters.Add(i_memo);
  412. cmd.Parameters.Add(i_userid);
  413. cmd.CommandType = CommandType.StoredProcedure;
  414. cmd.Connection = connection;
  415. cmd.ExecuteNonQuery();
  416. }
  417. }
  418. public static DataTable Get_dm_contacts(string companyId)
  419. {
  420. MySqlConnection connection = new MySqlConnection(connectionString);
  421. MySqlDataAdapter ad = new MySqlDataAdapter("sp_dm_get_contacts", connection);
  422. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  423. ad.SelectCommand.Parameters.Add(i_company_id);
  424. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  425. DataTable dt = new DataTable();
  426. ad.Fill(dt);
  427. connection.Close();
  428. return dt;
  429. }
  430. public static int Set_dm_contacts(DataTable dt, string companyId, int userId)
  431. {
  432. int ret = 0;
  433. if (dt == null || dt.Rows.Count <= 0) { return ret; }
  434. for (int i = 0; i < dt.Rows.Count; i++)
  435. {
  436. DataRow dataRow = dt.Rows[i];
  437. int o_id;
  438. if (dataRow.RowState == DataRowState.Deleted)
  439. {
  440. Set_dm_contacts(int.Parse(dataRow["id", DataRowVersion.Original].ToString()), dataRow["company_id", DataRowVersion.Original].ToString(),
  441. dataRow["name", DataRowVersion.Original].ToString(), dataRow["role", DataRowVersion.Original].ToString(),
  442. dataRow["phone", DataRowVersion.Original].ToString(), dataRow["wechat", DataRowVersion.Original].ToString(),
  443. dataRow["email", DataRowVersion.Original].ToString(),
  444. 0, userId, out o_id);
  445. ret++;
  446. }
  447. else if (dataRow.RowState == DataRowState.Added || dataRow.RowState == DataRowState.Modified)
  448. {
  449. int? id = null;
  450. if (string.IsNullOrEmpty(dataRow["id"].ToString()) == false)
  451. id = int.Parse(dataRow["id"].ToString());
  452. Set_dm_contacts(id, companyId, dataRow["name"].ToString(), dataRow["role"].ToString(), dataRow["phone"].ToString(),
  453. dataRow["wechat"].ToString(), dataRow["email"].ToString(),
  454. 1, userId, out o_id);
  455. if (dataRow.RowState == DataRowState.Added)
  456. {
  457. dataRow["id"] = o_id;
  458. dataRow["company_id"] = companyId;
  459. }
  460. ret++;
  461. }
  462. }
  463. return ret;
  464. }
  465. public static void Set_dm_contacts(int? id, string companyId, string name, string role, string phone,
  466. string wechat, string email, sbyte isvalid, int userId, out int out_id)
  467. {
  468. using (MySqlConnection connection = new MySqlConnection(connectionString))
  469. {
  470. connection.Open();
  471. MySqlCommand cmd = new MySqlCommand("sp_dm_set_contacts", connection);
  472. MySqlParameter i_id = new MySqlParameter("i_id", id);
  473. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  474. MySqlParameter i_name = new MySqlParameter("i_name", name);
  475. MySqlParameter i_role = new MySqlParameter("i_role", role);
  476. MySqlParameter i_phone = new MySqlParameter("i_phone", phone);
  477. MySqlParameter i_wechat = new MySqlParameter("i_wechat", wechat);
  478. MySqlParameter i_email = new MySqlParameter("i_email", email);
  479. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isvalid);
  480. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  481. MySqlParameter o_id = new MySqlParameter("o_id", DbType.Int32);
  482. o_id.Direction = ParameterDirection.Output;
  483. cmd.Parameters.Add(i_id);
  484. cmd.Parameters.Add(i_company_id);
  485. cmd.Parameters.Add(i_name);
  486. cmd.Parameters.Add(i_role);
  487. cmd.Parameters.Add(i_phone);
  488. cmd.Parameters.Add(i_wechat);
  489. cmd.Parameters.Add(i_email);
  490. cmd.Parameters.Add(i_isvalid);
  491. cmd.Parameters.Add(i_userid);
  492. cmd.Parameters.Add(o_id);
  493. cmd.CommandType = CommandType.StoredProcedure;
  494. cmd.Connection = connection;
  495. cmd.ExecuteNonQuery();
  496. out_id = int.Parse(cmd.Parameters["o_id"].Value.ToString());
  497. }
  498. }
  499. public static DataTable Get_dm_company_cover(string companyId, sbyte? coverType, int? userId)
  500. {
  501. MySqlConnection connection = new MySqlConnection(connectionString);
  502. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_company_cover", connection);
  503. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  504. MySqlParameter i_cover_type = new MySqlParameter("i_cover_type", coverType);
  505. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  506. ad.SelectCommand.Parameters.Add(i_company_id);
  507. ad.SelectCommand.Parameters.Add(i_cover_type);
  508. ad.SelectCommand.Parameters.Add(i_userid);
  509. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  510. DataTable dt = new DataTable();
  511. ad.Fill(dt);
  512. connection.Close();
  513. return dt;
  514. }
  515. /// <summary>
  516. /// 批量更新公司-对接人员关系
  517. /// </summary>
  518. /// <param name="updateQuery">Json字符串</param>
  519. /// <param name="userId"></param>
  520. /// <returns></returns>
  521. public static int Set_dm_company_cover(string updateQuery, int userId)
  522. {
  523. int ret = -1;
  524. using (MySqlConnection connection = new MySqlConnection(connectionString))
  525. {
  526. connection.Open();
  527. MySqlCommand cmd = new MySqlCommand("sp_set_dm_company_cover", connection);
  528. MySqlParameter i_update_query = new MySqlParameter("i_update_query", updateQuery);
  529. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  530. cmd.Parameters.Add(i_update_query);
  531. cmd.Parameters.Add(i_userid);
  532. cmd.CommandType = CommandType.StoredProcedure;
  533. cmd.Connection = connection;
  534. cmd.ExecuteNonQuery();
  535. ret = 1;
  536. }
  537. return ret;
  538. }
  539. /// <summary>
  540. /// 取基金指数,benchmark_type: 0-主基准、1-分类平均
  541. /// </summary>
  542. /// <param name="fundId"></param>
  543. /// <returns></returns>
  544. public static DataTable Get_dm_fund_benchmark(string fundId)
  545. {
  546. MySqlConnection connection = new MySqlConnection(connectionString);
  547. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_fund_benchmark", connection);
  548. MySqlParameter i_fund_id = new MySqlParameter("i_fund_id", fundId);
  549. ad.SelectCommand.Parameters.Add(i_fund_id);
  550. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  551. DataTable dt = new DataTable();
  552. ad.Fill(dt);
  553. connection.Close();
  554. return dt;
  555. }
  556. public static DataTable Get_dm_external_fund_mapping(sbyte? isOrphan, int? userId)
  557. {
  558. MySqlConnection connection = new MySqlConnection(connectionString);
  559. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_external_fund_mapping", connection);
  560. MySqlParameter i_is_orphan = new MySqlParameter("i_is_orphan", isOrphan);
  561. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  562. ad.SelectCommand.Parameters.Add(i_is_orphan);
  563. ad.SelectCommand.Parameters.Add(i_userid);
  564. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  565. DataTable dt = new DataTable();
  566. ad.Fill(dt);
  567. connection.Close();
  568. return dt;
  569. }
  570. public static void Set_dm_external_fund_mapping(string providerId, string externalId, string fundId, int userId)
  571. {
  572. using (MySqlConnection connection = new MySqlConnection(connectionString))
  573. {
  574. connection.Open();
  575. MySqlCommand cmd = new MySqlCommand("sp_set_dm_external_fund_mapping", connection);
  576. MySqlParameter i_provider_id = new MySqlParameter("i_provider_id", providerId);
  577. MySqlParameter i_external_id = new MySqlParameter("i_external_id", externalId);
  578. MySqlParameter i_fund_id = new MySqlParameter("i_fund_id", fundId);
  579. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  580. cmd.Parameters.Add(i_provider_id);
  581. cmd.Parameters.Add(i_external_id);
  582. cmd.Parameters.Add(i_fund_id);
  583. cmd.Parameters.Add(i_userid);
  584. cmd.CommandType = CommandType.StoredProcedure;
  585. cmd.Connection = connection;
  586. cmd.ExecuteNonQuery();
  587. }
  588. }
  589. public static DataTable Report_company_coverage(int? userId)
  590. {
  591. MySqlConnection connection = new MySqlConnection(connectionString);
  592. MySqlDataAdapter ad = new MySqlDataAdapter("sp_dm_report_company_coverage", connection);
  593. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  594. ad.SelectCommand.Parameters.Add(i_userid);
  595. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  596. DataTable dt = new DataTable();
  597. ad.Fill(dt);
  598. connection.Close();
  599. return dt;
  600. }
  601. public static DataTable Get_dm_company_authorization(string companyId, int? userId)
  602. {
  603. MySqlConnection connection = new MySqlConnection(connectionString);
  604. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_company_authorization", connection);
  605. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  606. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  607. ad.SelectCommand.Parameters.Add(i_company_id);
  608. ad.SelectCommand.Parameters.Add(i_userid);
  609. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  610. DataTable dt = new DataTable();
  611. ad.Fill(dt);
  612. connection.Close();
  613. return dt;
  614. }
  615. public static DataTable Report_fund_coverage(int? userId)
  616. {
  617. MySqlConnection connection = new MySqlConnection(connectionString);
  618. MySqlDataAdapter ad = new MySqlDataAdapter("sp_dm_report_fund_coverage", connection);
  619. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  620. ad.SelectCommand.Parameters.Add(i_userid);
  621. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  622. DataTable dt = new DataTable();
  623. ad.Fill(dt);
  624. connection.Close();
  625. return dt;
  626. }
  627. public static DataTable Get_dm_fund_authorization(int? userId)
  628. {
  629. MySqlConnection connection = new MySqlConnection(connectionString);
  630. MySqlDataAdapter ad = new MySqlDataAdapter("sp_get_dm_fund_authorization", connection);
  631. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  632. ad.SelectCommand.Parameters.Add(i_userid);
  633. ad.SelectCommand.CommandType = CommandType.StoredProcedure;
  634. DataTable dt = new DataTable();
  635. ad.Fill(dt);
  636. connection.Close();
  637. return dt;
  638. }
  639. public static int Set_dm_fund_authorization(string ids, int isValid, int userId)
  640. {
  641. int ret = -1;
  642. using (MySqlConnection connection = new MySqlConnection(connectionString))
  643. {
  644. connection.Open();
  645. MySqlCommand cmd = new MySqlCommand("sp_set_dm_fund_authorization", connection);
  646. MySqlParameter i_fund_ids = new MySqlParameter("i_fund_ids", ids);
  647. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isValid);
  648. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  649. cmd.Parameters.Add(i_fund_ids);
  650. cmd.Parameters.Add(i_isvalid);
  651. cmd.Parameters.Add(i_userid);
  652. cmd.CommandType = CommandType.StoredProcedure;
  653. cmd.Connection = connection;
  654. cmd.ExecuteNonQuery();
  655. ret = 1;
  656. }
  657. return ret;
  658. }
  659. public static int Set_dm_company_authorization(string companyId, int isAuthorized, int userId)
  660. {
  661. int ret = -1;
  662. using (MySqlConnection connection = new MySqlConnection(connectionString))
  663. {
  664. connection.Open();
  665. MySqlCommand cmd = new MySqlCommand("sp_set_dm_company_authorization", connection);
  666. MySqlParameter i_company_id = new MySqlParameter("i_company_id", companyId);
  667. MySqlParameter i_isvalid = new MySqlParameter("i_isvalid", isAuthorized);
  668. MySqlParameter i_userid = new MySqlParameter("i_userid", userId);
  669. cmd.Parameters.Add(i_company_id);
  670. cmd.Parameters.Add(i_isvalid);
  671. cmd.Parameters.Add(i_userid);
  672. cmd.CommandType = CommandType.StoredProcedure;
  673. cmd.Connection = connection;
  674. cmd.ExecuteNonQuery();
  675. ret = 1;
  676. }
  677. return ret;
  678. }
  679. }
  680. }