GetData.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. using System.Text;
  9. using System.Text.RegularExpressions;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. using SysBaseLibs;
  13. using SysDataLibs;
  14. using SysDataLibs.TableClass;
  15. namespace GSMarketSys.Controllers
  16. {
  17. //获取数据
  18. public class GetData
  19. {
  20. public static GetData Instance { get; } = new GetData();
  21. #region 为dg_Table(EasyUi)获取数据
  22. /// <summary>
  23. /// 根据SQL查询数据(dg_Table)
  24. /// </summary>
  25. /// <param name="pcSql"></param>
  26. /// <param name="dbConn"></param>
  27. /// <returns></returns>
  28. public string GetResult(string pcSql, DBConnSql dbConn)
  29. {
  30. rsQuery loQuery = dbConn.OpenQuery(pcSql);
  31. StringBuilder sb = new StringBuilder();
  32. sb.Append("{\"total\":" + loQuery.RecCount + ",\"rows\":");
  33. if (loQuery.IsOpened && loQuery.RecCount > 0)
  34. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  35. else
  36. sb.Append("[]");
  37. sb.Append("}");
  38. return sb.ToString();
  39. }
  40. /// <summary>
  41. /// 根据SQL查询数据(dg_Table)
  42. /// </summary>
  43. /// <param name="pcSql"></param>
  44. /// <param name="dbConn"></param>
  45. /// <returns></returns>
  46. public string GetJsonResult(string pcSql, DBConnSql dbConn)
  47. {
  48. rsQuery loQuery = dbConn.OpenQuery(pcSql);
  49. StringBuilder sb = new StringBuilder();
  50. if (loQuery.IsOpened && loQuery.RecCount > 0)
  51. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  52. else
  53. sb.Append("[]");
  54. return sb.ToString();
  55. }
  56. /// <summary>
  57. /// 真实分页查询(dg_Table)
  58. /// </summary>
  59. /// <param name="pcTableName"></param>
  60. /// <param name="pcSelectFieldNames"></param>
  61. /// <param name="pcStrWhere"></param>
  62. /// <param name="pcOrderBy"></param>
  63. /// <param name="piPageIndex"></param>
  64. /// <param name="piPageSize"></param>
  65. /// <param name="dbConn"></param>
  66. /// <returns></returns>
  67. public string GetResult(string pcTableName, string pcSelectFieldNames, string pcStrWhere, string pcOrderBy, int piPageIndex, int piPageSize, DBConnSql dbConn)
  68. {
  69. int piRowCount, piPageCount;
  70. DataSet loDataset = dbConn.GetPageRecords_RowNum(pcTableName, pcSelectFieldNames, pcStrWhere, pcOrderBy, piPageIndex, piPageSize, out piRowCount, out piPageCount);
  71. DataTable dt = loDataset.Tables[0];
  72. StringBuilder sb = new StringBuilder();
  73. sb.Append("{\"total\":" + piRowCount + ",\"rows\":");
  74. if (dt != null && dt.Rows.Count > 0)
  75. sb.Append(dt.ToJson("yyyy-MM-dd"));
  76. else
  77. sb.Append("[]");
  78. sb.Append("}");
  79. return sb.ToString();
  80. }
  81. /// <summary>
  82. /// 根据SQL查询数据,翻译IsLock(dg_Table)
  83. /// </summary>
  84. /// <param name="pcSql"></param>
  85. /// <param name="dbConn"></param>
  86. /// <returns></returns>
  87. public string GetResultLockTran(string pcSql, DBConnSql dbConn)
  88. {
  89. rsQuery loQuery = dbConn.OpenQuery(pcSql);
  90. StringBuilder sb = new StringBuilder();
  91. sb.Append("{\"total\":" + loQuery.RecCount + ",\"rows\":");
  92. if (loQuery.IsOpened && loQuery.RecCount > 0)
  93. {
  94. DataTable dt = loQuery.CurrentTable;
  95. dt.Columns.Add("LockState", typeof(string));
  96. for (int i = 0; i < dt.Rows.Count; i++)
  97. {
  98. dt.Rows[i]["LockState"] = dt.Rows[i]["IsLock"].ToString() == "0" ? "在用" : "删除";
  99. }
  100. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  101. }
  102. else
  103. sb.Append("[]");
  104. sb.Append("}");
  105. return sb.ToString();
  106. }
  107. /// <summary>
  108. /// 真实分页查询,翻译IsLock(dg_Table)
  109. /// </summary>
  110. /// <param name="pcTableName"></param>
  111. /// <param name="pcSelectFieldNames"></param>
  112. /// <param name="pcStrWhere"></param>
  113. /// <param name="pcOrderBy"></param>
  114. /// <param name="piPageIndex"></param>
  115. /// <param name="piPageSize"></param>
  116. /// <param name="dbConn"></param>
  117. /// <returns></returns>
  118. public string GetResultLockTran(string pcTableName, string pcSelectFieldNames, string pcStrWhere, string pcOrderBy, int piPageIndex, int piPageSize, DBConnSql dbConn)
  119. {
  120. int piRowCount, piPageCount;
  121. DataSet loDataset = dbConn.GetPageRecords_RowNum(pcTableName, pcSelectFieldNames, pcStrWhere, pcOrderBy, piPageIndex, piPageSize, out piRowCount, out piPageCount);
  122. DataTable dt = loDataset.Tables[0];
  123. StringBuilder sb = new StringBuilder();
  124. sb.Append("{\"total\":" + piRowCount + ",\"rows\":");
  125. if (dt != null && dt.Rows.Count > 0)
  126. {
  127. dt.Columns.Add("LockState", typeof(string));
  128. for (int i = 0; i < dt.Rows.Count; i++)
  129. {
  130. dt.Rows[i]["LockState"] = dt.Rows[i]["IsLock"].ToString() == "0" ? "在用" : "删除";
  131. }
  132. sb.Append(dt.ToJson("yyyy-MM-dd"));
  133. }
  134. else
  135. sb.Append("[]");
  136. sb.Append("}");
  137. return sb.ToString();
  138. }
  139. /// <summary>
  140. /// SQL语句查询经过系统字典翻译
  141. /// </summary>
  142. /// <param name="tableName"></param>
  143. /// <param name="colName"></param>
  144. /// <param name="dbConn"></param>
  145. /// <param name="pcSql"></param>
  146. /// <returns></returns>
  147. public string GetResultSysStatesTran(string tableName, string colName, string pcSql, DBConnSql dbConn)
  148. {
  149. string lcRetval = GetResult(pcSql, dbConn);
  150. rsQuery loQuery = dbConn.OpenQuery(
  151. "SELECT CodeValue,DisplayValue FROM Sys_Status WHERE TableName='" + tableName + "' AND ColName='" + colName +
  152. "'");
  153. if (loQuery.IsOpened && loQuery.RecCount > 0)
  154. {
  155. loQuery.MoveFirst();
  156. for (int i = 0; i < loQuery.RecCount; i++)
  157. {
  158. string codevalue = loQuery.GetString("CodeValue");
  159. string code = '"' + colName + '"' + ':' + '"' + codevalue + '"';
  160. string displayValue = loQuery.GetString("DisplayValue");
  161. string display = '"' + colName + '"' + ':' + '"' + displayValue + '"';
  162. if (lcRetval.Contains(code))
  163. lcRetval = Regex.Replace(lcRetval, code, display);
  164. loQuery.MoveNext();
  165. }
  166. }
  167. return lcRetval;
  168. }
  169. /// <summary>
  170. /// 真实分页SQL语句查询经过系统字典翻译
  171. /// </summary>
  172. /// <param name="pcTableName"></param>
  173. /// <param name="pcSelectFieldNames"></param>
  174. /// <param name="pcStrWhere"></param>
  175. /// <param name="pcOrderBy"></param>
  176. /// <param name="piPageIndex"></param>
  177. /// <param name="piPageSize"></param>
  178. /// <param name="tableName"></param>
  179. /// <param name="colName"></param>
  180. /// <param name="dbConn"></param>
  181. /// <param name="isString">需要翻译的值是否为字符串(false为int类型),默认true,</param>
  182. /// <returns></returns>
  183. public string GetResultSysStatesTran(string pcTableName, string pcSelectFieldNames, string pcStrWhere, string pcOrderBy, int piPageIndex, int piPageSize, string tableName, string colName, DBConnSql dbConn,bool isString=true)
  184. {
  185. string lcRetval = GetResult(pcTableName,pcSelectFieldNames,pcStrWhere,pcOrderBy,piPageIndex,piPageSize,dbConn);
  186. rsQuery loQuery = dbConn.OpenQuery(
  187. "SELECT CodeValue,DisplayValue FROM Sys_Status WHERE TableName='" + tableName + "' AND ColName='" + colName +
  188. "'");
  189. if (loQuery.IsOpened && loQuery.RecCount > 0)
  190. {
  191. loQuery.MoveFirst();
  192. for (int i = 0; i < loQuery.RecCount; i++)
  193. {
  194. string codevalue = loQuery.GetString("CodeValue");
  195. string code = '"' + colName + '"' + ':' + (isString?'"'+ codevalue + '"':codevalue) ;
  196. string displayValue = loQuery.GetString("DisplayValue");
  197. string display = '"' + colName + '"' + ':' + '"' + displayValue + '"';
  198. if (lcRetval.Contains(code))
  199. lcRetval = Regex.Replace(lcRetval, code, display);
  200. loQuery.MoveNext();
  201. }
  202. }
  203. return lcRetval;
  204. }
  205. /// <summary>
  206. /// 查询数据翻译(dg_Table)
  207. /// </summary>
  208. /// <param name="pcSql">SQL语句</param>
  209. /// <param name="oldColNames">原列名(多列用"|"分隔,并保证下面类似字段"|"分隔数量相同)</param>
  210. /// <param name="newColNames">新增列名</param>
  211. /// <param name="tableNames">要去查询翻译的表名</param>
  212. /// <param name="colNames">要去查询翻译的列名</param>
  213. /// <param name="dbConn">数据连接</param>
  214. /// <param name="whereSqls">查询翻译条件,没有查询条件的填""(可不填,如填需要以"|"分隔""补全【例:""|"1=1"|""】)</param>
  215. /// <returns></returns>
  216. public string GetResultTran(string pcSql, string oldColNames, string newColNames, string tableNames, string colNames, DBConnSql dbConn, string whereSqls = "")
  217. {
  218. string[] oldColNameArr = oldColNames.Split('|');
  219. string[] newColNameArr = newColNames.Split('|');
  220. string[] tableNameArr = tableNames.Split('|');
  221. string[] colNameArr = colNames.Split('|');
  222. string[] whereSqlArr = new string[newColNameArr.Length];
  223. if (string.IsNullOrEmpty(whereSqls))
  224. {
  225. for (int i = 0; i < newColNameArr.Length; i++)
  226. {
  227. whereSqlArr[i] = "";
  228. }
  229. }
  230. else
  231. whereSqlArr = whereSqls.Split('|');
  232. if (newColNameArr.Length != oldColNameArr.Length && newColNameArr.Length != tableNameArr.Length && newColNameArr.Length != colNameArr.Length)
  233. return "";
  234. rsQuery loQuery = dbConn.OpenQuery(pcSql);
  235. StringBuilder sb = new StringBuilder();
  236. List<string[]> colList = new List<string[]>();
  237. for (int i = 0; i < newColNameArr.Length; i++)
  238. {
  239. colList.Add(new[] { oldColNameArr[i], newColNameArr[i], tableNameArr[i], colNameArr[i], whereSqlArr[i] == "" ? "1=1" : whereSqlArr[i] });
  240. }
  241. sb.Append("{\"total\":" + loQuery.RecCount + ",\"rows\":");
  242. if (loQuery.IsOpened && loQuery.RecCount > 0)
  243. {
  244. DataTable dt = loQuery.CurrentTable;
  245. foreach (string col in newColNameArr)
  246. {
  247. dt.Columns.Add(col, typeof(string));
  248. }
  249. for (int i = 0; i < dt.Rows.Count; i++)
  250. {
  251. foreach (string[] col in colList)
  252. {
  253. var r = dt.Rows[i][col[0]];
  254. if (!(r is int))
  255. {
  256. r = "'" + r + "'";
  257. }
  258. string lcSql = "SELECT " + col[3] + " FROM " + col[2] + " WHERE " + col[0] + "=" + r + " AND " + col[4];
  259. rsQuery loQueryTm = dbConn.OpenQuery(lcSql);
  260. loQueryTm.MoveFirst();
  261. dt.Rows[i][col[1]] = loQueryTm.CurrentTable.Rows[0][col[3]];
  262. }
  263. //dt.Rows[i]["LockState"] = dt.Rows[i]["IsLock"].ToString() == "0" ? "在用" : "删除";
  264. }
  265. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  266. }
  267. else
  268. sb.Append("[]");
  269. sb.Append("}");
  270. return sb.ToString();
  271. }
  272. /// <summary>
  273. /// 真实分页查询数据翻译(dg_Table)
  274. /// </summary>
  275. /// <param name="tableName">查询表面</param>
  276. /// <param name="selectFieldNames">查询字段</param>
  277. /// <param name="strWhere">查询WHERE条件</param>
  278. /// <param name="orderBy">查询排序条件</param>
  279. /// <param name="piPageSize">每页显示条数</param>
  280. /// <param name="piPageIndex">页码</param>
  281. /// <param name="oldColNames">原列名(多列用"|"分隔,并保证下面类似字段"|"分隔数量相同)</param>
  282. /// <param name="newColNames">新增列名</param>
  283. /// <param name="tableNames">要去查询翻译的表名</param>
  284. /// <param name="colNames">要去查询翻译的列名</param>
  285. /// <param name="dbConn">数据连接</param>
  286. /// <param name="whereSqls">查询翻译条件,没有查询条件的填""(可不填,如填需要以"|"分隔""补全【例:""|"1=1"|""】)</param>
  287. /// <returns></returns>
  288. public string GetResultTran(string tableName, string selectFieldNames, string strWhere, string orderBy, int piPageIndex, int piPageSize, string oldColNames, string newColNames, string tableNames, string colNames,DBConnSql dbConn, string whereSqls="")
  289. {
  290. string[] oldColNameArr = oldColNames.Split('|');
  291. string[] newColNameArr = newColNames.Split('|');
  292. string[] tableNameArr = tableNames.Split('|');
  293. string[] colNameArr = colNames.Split('|');
  294. string[] whereSqlArr = new string[newColNameArr.Length];
  295. if (string.IsNullOrEmpty(whereSqls))
  296. {
  297. for (int i = 0; i < newColNameArr.Length; i++)
  298. {
  299. whereSqlArr[i] = "";
  300. }
  301. }
  302. else
  303. whereSqlArr = whereSqls.Split('|');
  304. if (newColNameArr.Length != oldColNameArr.Length&& newColNameArr.Length != tableNameArr.Length && newColNameArr.Length != colNameArr.Length)
  305. return "";
  306. int piRowCount, piPageCount;
  307. DataSet loDataset = dbConn.GetPageRecords_RowNum(tableName, selectFieldNames, strWhere, orderBy, piPageIndex, piPageSize, out piRowCount, out piPageCount);
  308. DataTable dt = loDataset.Tables[0];
  309. StringBuilder sb = new StringBuilder();
  310. List<string[]> colList = new List<string[]>();
  311. for (int i = 0; i < newColNameArr.Length; i++)
  312. {
  313. colList.Add(new[] { oldColNameArr[i], newColNameArr[i], tableNameArr[i], colNameArr[i], whereSqlArr[i]==""?"1=1": whereSqlArr[i] });
  314. }
  315. sb.Append("{\"total\":" + piRowCount + ",\"rows\":");
  316. if (dt != null && dt.Rows.Count > 0)
  317. {
  318. foreach (string col in newColNameArr)
  319. {
  320. dt.Columns.Add(col, typeof(string));
  321. }
  322. for (int i = 0; i < dt.Rows.Count; i++)
  323. {
  324. foreach (string[] col in colList)
  325. {
  326. var r = dt.Rows[i][col[0]];
  327. if (!(r is int))
  328. {
  329. r = "'" + r + "'";
  330. }
  331. string lcSql = "SELECT " + col[3] + " FROM " + col[2] + " WHERE " + col[0] + "=" + r + " AND " + col[4];
  332. rsQuery loQueryTm = dbConn.OpenQuery(lcSql);
  333. loQueryTm.MoveFirst();
  334. dt.Rows[i][col[1]] = loQueryTm.CurrentTable.Rows[0][col[3]];
  335. }
  336. //dt.Rows[i]["LockState"] = dt.Rows[i]["IsLock"].ToString() == "0" ? "在用" : "删除";
  337. }
  338. sb.Append(dt.ToJson("yyyy-MM-dd"));
  339. }
  340. else
  341. sb.Append("[]");
  342. sb.Append("}");
  343. return sb.ToString();
  344. }
  345. /// <summary>
  346. /// 已查询的数据通过系统字典里翻译
  347. /// </summary>
  348. /// <param name="tableName">表名</param>
  349. /// <param name="colName">列名</param>
  350. /// <param name="pcStr">需要翻译的数据</param>
  351. /// <param name="dbConn"></param>
  352. /// <returns></returns>
  353. public string TranFromSysStates(string tableName, string colName, string pcStr, DBConnSql dbConn)
  354. {
  355. rsQuery loQuery = dbConn.OpenQuery(
  356. "SELECT CodeValue,DisplayValue FROM Sys_Status WHERE TableName='" + tableName + "' AND ColName='" + colName +
  357. "'");
  358. string lcRetval = pcStr;
  359. if (loQuery.IsOpened && loQuery.RecCount > 0)
  360. {
  361. loQuery.MoveFirst();
  362. for (int i = 0; i < loQuery.RecCount; i++)
  363. {
  364. string codevalue = loQuery.GetString("CodeValue");
  365. string code = '"' + colName + '"' + ':' + '"' + codevalue + '"';
  366. string displayValue = loQuery.GetString("DisplayValue");
  367. string display = '"' + colName + '"' + ':' + '"' + displayValue + '"';
  368. if (lcRetval.Contains(code))
  369. lcRetval = Regex.Replace(pcStr, code, display);
  370. loQuery.MoveNext();
  371. }
  372. }
  373. return lcRetval;
  374. }
  375. #endregion
  376. #region 拼装【SELECT】 里的【option】
  377. /// <summary>
  378. /// 拼组【SELECT】 里的【option】
  379. /// </summary>
  380. /// <param name="selValueColName"></param>
  381. /// <param name="selNameColName"></param>
  382. /// <param name="tabelName"></param>
  383. /// <param name="dbConn"></param>
  384. /// <param name="isLock"></param>
  385. /// <returns></returns>
  386. public string GetSelStr(string selValueColName, string selNameColName, string tabelName, DBConnSql dbConn, bool isLock = true)
  387. {
  388. string lcSql = "SELECT " + selValueColName + "," + selNameColName + " FROM " + tabelName +
  389. " WHERE 1 = 1";
  390. if (isLock)
  391. lcSql += " AND IsLock = 0";
  392. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  393. StringBuilder sb = new StringBuilder();
  394. if (loQuery.IsOpened && loQuery.RecCount > 0)
  395. {
  396. DataTable dt = loQuery.CurrentTable;
  397. DataRowCollection drc = dt.Rows;
  398. for (var i = 0; i < drc.Count; i++)
  399. {
  400. sb.Append("<option value=\"" + drc[i][selValueColName] + "\" >" + drc[i][selNameColName] + " </option>");
  401. }
  402. }
  403. return sb.ToString();
  404. }/// <summary>
  405. /// 拼组 Region【SELECT】 里的【option】
  406. /// </summary>
  407. /// <param name="selValueColName"></param>
  408. /// <param name="selNameColName"></param>
  409. /// <param name="tabelName"></param>
  410. /// <param name="dbConn"></param>
  411. /// <param name="isLock"></param>
  412. /// <returns></returns>
  413. public string GetRegionSelStr(string selValueColName, string selNameColName, string tabelName, DBConnSql dbConn, bool isLock = true)
  414. {
  415. string lcSql = "SELECT RegionID ,Names ,Depth FROM Regions WHERE RegionID!='861111 ' AND IsLock = 0 ORDER BY Depth";
  416. //if (isLock)
  417. // lcSql += " AND IsLock = 0";
  418. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  419. StringBuilder sb = new StringBuilder();
  420. if (loQuery.IsOpened && loQuery.RecCount > 0)
  421. {
  422. DataTable dt = loQuery.CurrentTable;
  423. DataRowCollection drc = dt.Rows;
  424. for (var i = 0; i < drc.Count; i++)
  425. {
  426. var prev = "";
  427. for (int j = 0; j < (int)drc[i]["Depth"]; j++)
  428. {
  429. prev += "--";
  430. }
  431. sb.Append("<option value=\"" + drc[i]["RegionID"] + "\" >"+ prev + drc[i]["Names"] + " </option>");
  432. }
  433. }
  434. return sb.ToString();
  435. }
  436. /// <summary>
  437. /// 带 WHERE 条件拼组【SELECT】 里的【option】
  438. /// </summary>
  439. /// <param name="selValueColName"></param>
  440. /// <param name="selNameColName"></param>
  441. /// <param name="tabelName"></param>
  442. /// <param name="whereStr"></param>
  443. /// <param name="dbConn"></param>
  444. /// <returns></returns>
  445. public string GetSelStr(string selValueColName, string selNameColName, string tabelName,
  446. string whereStr, DBConnSql dbConn)
  447. {
  448. string lcSql = "SELECT " + selValueColName + "," + selNameColName + " FROM " + tabelName;
  449. if (!string.IsNullOrEmpty(whereStr))
  450. lcSql += " WHERE " + whereStr;
  451. //if (isLock)
  452. // lcSql += " AND IsLock = 0";
  453. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  454. StringBuilder sb = new StringBuilder();
  455. if (loQuery.IsOpened && loQuery.RecCount > 0)
  456. {
  457. DataTable dt = loQuery.CurrentTable;
  458. DataRowCollection drc = dt.Rows;
  459. for (var i = 0; i < drc.Count; i++)
  460. {
  461. sb.Append("<option value=\"" + drc[i][selValueColName] + "\" >" + drc[i][selNameColName] + " </option>");
  462. }
  463. }
  464. return sb.ToString();
  465. }
  466. /// <summary>
  467. /// 带 WHERE 条件拼组【SELECT】 里的【option】
  468. /// </summary>
  469. /// <param name="selValueColName"></param>
  470. /// <param name="selNameColName"></param>
  471. /// <param name="tabelName"></param>
  472. /// <param name="whereStr"></param>
  473. /// <param name="dbConn"></param>
  474. /// <returns></returns>
  475. public string GetSelStrLi(string selValueColName, string selNameColName, string tabelName,
  476. string whereStr, DBConnSql dbConn)
  477. {
  478. string lcSql = "SELECT " + selValueColName + "," + selNameColName + " FROM " + tabelName;
  479. if (!string.IsNullOrEmpty(whereStr))
  480. lcSql += " WHERE " + whereStr;
  481. //if (isLock)
  482. // lcSql += " AND IsLock = 0";
  483. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  484. StringBuilder sb = new StringBuilder();
  485. if (loQuery.IsOpened && loQuery.RecCount > 0)
  486. {
  487. DataTable dt = loQuery.CurrentTable;
  488. DataRowCollection drc = dt.Rows;
  489. for (var i = 0; i < drc.Count; i++)
  490. {
  491. sb.Append("<li value=\"" + drc[i][selValueColName] + "\" >" + drc[i][selNameColName] + " </li>");
  492. }
  493. }
  494. return sb.ToString();
  495. }
  496. /// <summary>
  497. /// 带 WHERE 条件拼组【SELECT】 里的【option】
  498. /// </summary>
  499. /// <param name="selValueColName"></param>
  500. /// <param name="selNameColName"></param>
  501. /// <param name="tabelName"></param>
  502. /// <param name="whereStr"></param>
  503. /// <param name="dbConn"></param>
  504. /// <returns></returns>
  505. public string GetSelStrDistinct(string selValueColName, string selNameColName, string tabelName,
  506. string whereStr, DBConnSql dbConn)
  507. {
  508. string lcSql = "SELECT distinct " + selValueColName + "," + selNameColName + " FROM " + tabelName;
  509. if (!string.IsNullOrEmpty(whereStr))
  510. lcSql += " WHERE " + whereStr;
  511. //if (isLock)
  512. // lcSql += " AND IsLock = 0";
  513. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  514. StringBuilder sb = new StringBuilder();
  515. if (loQuery.IsOpened && loQuery.RecCount > 0)
  516. {
  517. DataTable dt = loQuery.CurrentTable;
  518. DataRowCollection drc = dt.Rows;
  519. for (var i = 0; i < drc.Count; i++)
  520. {
  521. sb.Append("<option value=\"" + drc[i][selValueColName] + "\" >" + drc[i][selNameColName] + " </option>");
  522. }
  523. }
  524. return sb.ToString();
  525. }
  526. /// <summary>
  527. /// 从系统字典中翻译拼组【SELECT】 里的【option】
  528. /// </summary>
  529. /// <param name="colName"></param>
  530. /// <param name="tabelName"></param>
  531. /// <param name="dbConn"></param>
  532. /// <returns></returns>
  533. public string GetSelStr(string colName, string tabelName, DBConnSql dbConn)
  534. {
  535. string lcSql = "SELECT CodeValue,DisplayValue FROM Sys_Status WHERE TableName='" + tabelName + "' AND ColName='" +
  536. colName + "'";
  537. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  538. StringBuilder sb = new StringBuilder();
  539. if (loQuery.IsOpened && loQuery.RecCount > 0)
  540. {
  541. DataTable dt = loQuery.CurrentTable;
  542. DataRowCollection drc = dt.Rows;
  543. for (var i = 0; i < drc.Count; i++)
  544. {
  545. sb.Append("<option value=\"" + drc[i]["CodeValue"] + "\" >" + drc[i]["DisplayValue"] + " </option>");
  546. }
  547. }
  548. return sb.ToString();
  549. }
  550. private string TranRegionName(int poDepth, string poName)
  551. {
  552. string exReg = "";
  553. for (int i = 0; i < poDepth; i++)
  554. {
  555. exReg += "---";
  556. }
  557. exReg += poName;
  558. return exReg;
  559. }
  560. public string GetRegionsTreeList(DBConnSql poDbConn,bool isContainRoot = true)
  561. {
  562. string lcSql = " select * from Regions where IsLock='0'" + (isContainRoot?"": " and RegionID<>'861111'") +" ORDER BY Sort ";
  563. rsQuery loQuery = poDbConn.OpenQuery(lcSql);//
  564. StringBuilder sb = new StringBuilder();
  565. if (loQuery.IsOpened && loQuery.RecCount > 0)
  566. {
  567. DataTable dt = loQuery.CurrentTable;
  568. DataRowCollection drc = dt.Rows;
  569. for (var i = 0; i < drc.Count; i++)
  570. {
  571. sb.Append("<option value=\"" + drc[i]["RegionID"] + "\" >" + TranRegionName(Utils.ValI(UtilStr.StrFromObj(drc[i]["Depth"])), loQuery.GetString("Names")) + " </option>");
  572. loQuery.MoveNext();
  573. }
  574. }
  575. else
  576. sb.Append("");
  577. return sb.ToString();
  578. }
  579. #endregion
  580. public List<SelectItem> GetSelectList(string selValueColName, string selNameColName, string tabelName,
  581. string whereStr, DBConnSql dbConn)
  582. {
  583. List<SelectItem> selectList =new List<SelectItem>();
  584. string lcSql = "SELECT " + selValueColName + "," + selNameColName + " FROM " + tabelName;
  585. if (!string.IsNullOrEmpty(whereStr))
  586. lcSql += " WHERE " + whereStr;
  587. //if (isLock)
  588. // lcSql += " AND IsLock = 0";
  589. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  590. StringBuilder sb = new StringBuilder();
  591. if (loQuery.IsOpened && loQuery.RecCount > 0)
  592. {
  593. DataTable dt = loQuery.CurrentTable;
  594. DataRowCollection drc = dt.Rows;
  595. for (var i = 0; i < drc.Count; i++)
  596. {
  597. selectList.Add(new SelectItem()
  598. {
  599. id = drc[i][selNameColName] + "",
  600. text = drc[i][selValueColName] + ""
  601. });
  602. }
  603. }
  604. return selectList;
  605. }
  606. /// <summary>
  607. /// 空字符串转为 int 类型时设置为 0
  608. /// </summary>
  609. /// <param name="pcStr"></param>
  610. /// <returns></returns>
  611. public string SetIntDefault(string pcStr)
  612. {
  613. return string.IsNullOrEmpty(pcStr) ? "0" : pcStr;
  614. }
  615. /// <summary>
  616. /// 传入表名及表的ID名 返回最后一个ID值
  617. /// </summary>
  618. /// <param name="idName"></param>
  619. /// <param name="tbName"></param>
  620. /// <param name="dbConn"></param>
  621. /// <returns></returns>
  622. public string GetLastRecId(string idName, string tbName, DBConnSql dbConn)
  623. {
  624. string lcRetval = "", lsql = "SELECT " + idName + " FROM " + tbName;
  625. rsQuery loQuery = dbConn.OpenQuery(lsql);
  626. if (loQuery.IsOpened && loQuery.RecCount > 0)
  627. lcRetval = loQuery.RecCount.ToString();
  628. return lcRetval;
  629. }
  630. /// <summary>
  631. /// 检测数据库是否存在一条记录信息
  632. /// </summary>
  633. /// <param name="pcColumn"></param>
  634. /// <param name="pcColumnValue"></param>
  635. /// <param name="pcTableName"></param>
  636. /// <param name="dbConn"></param>
  637. /// <returns></returns>
  638. public bool isCheckExistObj(string pcColumn, string pcColumnValue, string pcTableName, DBConnSql dbConn)
  639. {
  640. bool lbRetval = false;
  641. string lcSql = "SELECT top 1 * FROM " + pcTableName + " where " + pcColumn + " = '" + pcColumnValue + "'";
  642. rsQuery loQuery = dbConn.OpenQuery(lcSql);
  643. if (loQuery.IsOpened && loQuery.RecCount > 0)
  644. {
  645. lbRetval = true;
  646. }
  647. return lbRetval;
  648. }
  649. /// <summary>
  650. /// 附件操作
  651. /// </summary>
  652. /// <param name="type">操作类型</param>
  653. /// <param name="pcAttacthFileInfo">附件实体</param>
  654. /// <param name="userSessionInfo">UserSession</param>
  655. /// <param name="msg">回传信息</param>
  656. /// <returns></returns>
  657. public bool AttachFileUpdate(string type, Sys_AttachFiles_info pcAttacthFileInfo,UserSession userSessionInfo, ref string msg)
  658. {
  659. if (msg == null) throw new ArgumentNullException(nameof(msg));
  660. msg = "操作失败";
  661. Sys_AttachFiles_info t;
  662. string oldPath;
  663. bool ltRetval = false;
  664. HttpFileCollection attachFile = HttpContext.Current.Request.Files;
  665. switch (type)
  666. {
  667. case "Add":
  668. pcAttacthFileInfo.TimeCreated = DateTime.Now.ToShortDateString();
  669. if (pcAttacthFileInfo.UpdateFile(attachFile, userSessionInfo))
  670. {
  671. ltRetval = true;
  672. msg = "附件上传成功";
  673. }
  674. break;
  675. case "Edit":
  676. t = new Sys_AttachFiles_info(pcAttacthFileInfo.TableId, pcAttacthFileInfo.ColumnId,
  677. pcAttacthFileInfo.SourceKey, userSessionInfo.DBConn);
  678. if (pcAttacthFileInfo.UpdateFile(attachFile, userSessionInfo, false))
  679. {
  680. try
  681. {
  682. oldPath = HttpContext.Current.Request.PhysicalApplicationPath;
  683. oldPath += t.FilePath + "/" + t.FileName;
  684. if (!string.IsNullOrEmpty(oldPath))
  685. System.IO.File.Delete(oldPath);
  686. }
  687. catch
  688. {
  689. // ignored
  690. }
  691. ltRetval = true;
  692. msg = "附件修改成功";
  693. }
  694. break;
  695. case "Del":
  696. t = new Sys_AttachFiles_info(pcAttacthFileInfo.TableId, pcAttacthFileInfo.ColumnId,
  697. pcAttacthFileInfo.SourceKey, userSessionInfo.DBConn);
  698. oldPath = HttpContext.Current.Request.PhysicalApplicationPath;
  699. oldPath += t.FilePath + "/" + t.FileName;
  700. if (userSessionInfo.DBConn.ExcuteSqlTran(pcAttacthFileInfo.DeleteSql()))
  701. {
  702. try
  703. {
  704. if (!string.IsNullOrEmpty(oldPath))
  705. System.IO.File.Delete(oldPath);
  706. }
  707. catch
  708. {
  709. // ignored
  710. }
  711. ltRetval = true;
  712. msg = "附件删除成功";
  713. }
  714. else
  715. msg = "附件删除失败!";
  716. break;
  717. }
  718. return ltRetval;
  719. }
  720. /// <summary>
  721. /// 附件操作
  722. /// </summary>
  723. /// <param name="type">操作类型</param>
  724. /// <param name="pcAttacthFileInfo">附件实体</param>
  725. /// <param name="userSessionInfo">UserSession</param>
  726. /// <param name="msg">回传信息</param>
  727. /// <returns></returns>
  728. public bool AttachFileUpdate2(string type, string base64Str,Sys_AttachFiles_info pcAttacthFileInfo, UserSession userSessionInfo, ref string msg)
  729. {
  730. if (msg == null) throw new ArgumentNullException(nameof(msg));
  731. msg = "操作失败";
  732. Sys_AttachFiles_info t;
  733. string oldPath;
  734. bool ltRetval = false;
  735. HttpFileCollection attachFile = HttpContext.Current.Request.Files;
  736. switch (type)
  737. {
  738. case "Add":
  739. pcAttacthFileInfo.TimeCreated = DateTime.Now.ToShortDateString();
  740. if (pcAttacthFileInfo.UpdateFileBase64(base64Str, userSessionInfo))
  741. {
  742. ltRetval = true;
  743. msg = "附件上传成功";
  744. }
  745. break;
  746. case "Edit":
  747. t = new Sys_AttachFiles_info(pcAttacthFileInfo.TableId, pcAttacthFileInfo.ColumnId,
  748. pcAttacthFileInfo.SourceKey, userSessionInfo.DBConn);
  749. if (pcAttacthFileInfo.UpdateFileBase64(base64Str, userSessionInfo, false))
  750. {
  751. try
  752. {
  753. oldPath = HttpContext.Current.Request.PhysicalApplicationPath;
  754. oldPath += t.FilePath + "/" + t.FileName;
  755. if (!string.IsNullOrEmpty(oldPath))
  756. System.IO.File.Delete(oldPath);
  757. }
  758. catch
  759. {
  760. // ignored
  761. }
  762. ltRetval = true;
  763. msg = "附件修改成功";
  764. }
  765. break;
  766. case "Del":
  767. t = new Sys_AttachFiles_info(pcAttacthFileInfo.TableId, pcAttacthFileInfo.ColumnId,
  768. pcAttacthFileInfo.SourceKey, userSessionInfo.DBConn);
  769. oldPath = HttpContext.Current.Request.PhysicalApplicationPath;
  770. oldPath += t.FilePath + "/" + t.FileName;
  771. if (userSessionInfo.DBConn.ExcuteSqlTran(pcAttacthFileInfo.DeleteSql()))
  772. {
  773. try
  774. {
  775. if (!string.IsNullOrEmpty(oldPath))
  776. System.IO.File.Delete(oldPath);
  777. }
  778. catch
  779. {
  780. // ignored
  781. }
  782. ltRetval = true;
  783. msg = "附件删除成功";
  784. }
  785. else
  786. msg = "附件删除失败!";
  787. break;
  788. }
  789. return ltRetval;
  790. }
  791. /// <summary>
  792. /// 返回
  793. /// </summary>
  794. /// <param name="pcErrorCode"></param>
  795. /// <returns></returns>
  796. public string GetBackInfo(string pcErrorCode)
  797. {
  798. return SysRebackDisplayInfo.Instance.GetDisplayValue(pcErrorCode);
  799. }
  800. /// <summary>
  801. /// 根据主键查询表对象
  802. /// </summary>
  803. /// <param name="pcId">主键值</param>
  804. /// <param name="pcTableName">表名</param>
  805. /// <param name="pcColumnName">字段名</param>
  806. /// <returns></returns>
  807. public string GetResultById(string pcId, string pcTableName, string pcColumnName)
  808. {
  809. string lcResult = "";
  810. DBConnSql loDbConn = new DBConnSql();
  811. loDbConn.Open();
  812. try
  813. {
  814. string lcSql = " SELECT * FROM " + pcTableName + " WHERE " + pcColumnName + " = '" + pcId + "'";
  815. rsQuery loQuery = loDbConn.OpenQuery(lcSql);
  816. StringBuilder sb = new StringBuilder();
  817. if (loQuery.IsOpened && loQuery.RecCount > 0)
  818. sb.Append(loQuery.CurrentTable.ToJson("yyyy-MM-dd"));
  819. else
  820. sb.Append("[]");
  821. lcResult = sb.ToString();
  822. }
  823. catch
  824. {
  825. // ignored
  826. }
  827. finally
  828. {
  829. loDbConn.Close();
  830. // ReSharper disable once RedundantAssignment
  831. loDbConn = null;
  832. }
  833. return lcResult;
  834. }
  835. /// <summary>
  836. ///
  837. /// </summary>
  838. /// <param name="poNumberType"></param>
  839. /// <param name="dbConn"></param>
  840. /// <returns></returns>
  841. public int GetRandomNextNum(NumberType poNumberType, DBConnSql dbConn)
  842. {
  843. int liResult = 0;
  844. try
  845. {
  846. IdCollection loSpPars = new IdCollection();
  847. SqlSPPar loSpPar = new SqlSPPar("idtype", SqlDbType.SmallInt);
  848. loSpPar.ParameterValue = (int)poNumberType;
  849. loSpPars.Add(loSpPar);
  850. loSpPar = new SqlSPPar("nextid", SqlDbType.Int);
  851. loSpPar.IsOutput = true;
  852. loSpPars.Add(loSpPar);
  853. loSpPar = new SqlSPPar("maxid", SqlDbType.Int);
  854. loSpPar.IsOutput = true;
  855. loSpPars.Add(loSpPar);
  856. if (dbConn.ExecuteStoredProc("sp_ss_reserveuid", loSpPars))
  857. {
  858. if (loSpPars["maxid"] != null)
  859. {
  860. liResult = Convert.ToInt16(((SqlSPPar)loSpPars["maxid"]).ParameterValue);
  861. }
  862. }
  863. else
  864. {
  865. string ss = dbConn.ErrorMsg;
  866. }
  867. }
  868. catch (Exception err)
  869. {
  870. ThreadLog.LogException(err);
  871. }
  872. return liResult;
  873. }
  874. public ComboTree GetComboTreeNode(rsQuery poQuery, string pcId, string pcParentId, string pcName, string pcRootFilter,
  875. string pcDepth = "Depth", string pcDepthVal = "1")
  876. {
  877. ComboTree tree = new ComboTree();
  878. //rsQuery loQuery = dbConn.OpenQuery("SELECT CheckItemId,CheckItemName From CheckItem WHERE IsLock='N'");
  879. //rsQuery loQuery = poQuery;
  880. poQuery?.FilterBy(pcRootFilter);
  881. if (poQuery?.RecCount == 1)
  882. {
  883. poQuery.MoveFirst();
  884. string lcParentId = poQuery.GetInt(pcId) + "";
  885. if (string.IsNullOrEmpty(lcParentId))
  886. {
  887. lcParentId = poQuery.GetString(pcId);
  888. }
  889. if (string.IsNullOrEmpty(lcParentId))
  890. {
  891. return null;
  892. }
  893. tree.id = poQuery.GetString(pcId);
  894. tree.text = poQuery.GetString(pcName);
  895. DataTable loTable = poQuery.CurrentTable;
  896. tree.children = GetComboTrees(loTable, pcId, pcParentId, pcName, lcParentId, pcDepth, pcDepthVal);
  897. }
  898. return tree;
  899. }
  900. public List<ComboTree> GetComboTree(rsQuery poQuery,string pcId,string pcParentId ,string pcName,string pcRootFilter,string pcDepth= "Depth",string pcDepthVal="1")
  901. {
  902. ComboTree tree = new ComboTree();
  903. //rsQuery loQuery = dbConn.OpenQuery("SELECT CheckItemId,CheckItemName From CheckItem WHERE IsLock='N'");
  904. //rsQuery loQuery = poQuery;
  905. poQuery?.FilterBy(pcRootFilter);
  906. if (poQuery?.RecCount == 1)
  907. {
  908. poQuery.MoveFirst();
  909. string lcParentId = poQuery.GetInt(pcId)+"";
  910. if (string.IsNullOrEmpty(lcParentId))
  911. {
  912. lcParentId = poQuery.GetString(pcId);
  913. }
  914. if (string.IsNullOrEmpty(lcParentId))
  915. {
  916. return null;
  917. }
  918. tree.id = poQuery.GetString(pcId);
  919. tree.text = poQuery.GetString(pcName);
  920. DataTable loTable = poQuery.CurrentTable;
  921. tree.children = GetComboTrees(loTable, pcId, pcParentId, pcName, lcParentId,pcDepth, pcDepthVal);
  922. }
  923. return tree.children;
  924. }
  925. private List<ComboTree> GetComboTrees(DataTable poTable, string pcId, string pcParentId, string pcName,
  926. string pcParentIdVal, string pcDepth, string pcDepthVal)
  927. {
  928. List<ComboTree> trees=new List<ComboTree>();
  929. try
  930. {
  931. var dRows = poTable.Select(pcParentId + "='" + pcParentIdVal.Trim()+"'");
  932. if (dRows.Length > 0)
  933. {
  934. foreach (DataRow row in dRows)
  935. {
  936. var lcId = row[pcId].ToString();
  937. var tree = new ComboTree
  938. {
  939. id = lcId,
  940. text = row[pcName].ToString(),
  941. children = GetComboTrees(poTable, pcId, pcParentId, pcName, lcId, pcDepth, pcDepthVal)
  942. };
  943. string[] closes = pcDepthVal.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  944. if (closes.Length > 0)
  945. {
  946. if (closes.Contains(row[pcDepth] + ""))
  947. {
  948. tree.state = "closed";
  949. }
  950. }
  951. trees.Add(tree);
  952. }
  953. }
  954. }
  955. catch (Exception e)
  956. {
  957. Console.WriteLine(e);
  958. throw;
  959. }
  960. return trees;
  961. }
  962. #region 图表相关方法
  963. // 为饼图生成返回的Json格式数据(和其他各种图表有所区别)
  964. public string GenOutputDataForPie(int nCount, List<Array> listData)
  965. {
  966. string strData = string.Empty;
  967. if ((listData != null) && (listData.Count == 2))
  968. {
  969. Array arrayRet = new string[nCount];
  970. for (int i = 0; i < nCount; i++)
  971. {
  972. string strKey = listData[0].GetValue(i).ToString();
  973. string strVal = listData[1].GetValue(i).ToString();
  974. double dVal = Convert.ToDouble(strVal);
  975. // name 和 y 为HighCharts对象属性
  976. string strRow = "{\"name\":\"" + strKey + "\", \"y\":" + dVal + "}";
  977. arrayRet.SetValue(strRow, i);
  978. }
  979. strData = ArrayToString(arrayRet);
  980. }
  981. strData = UtilStr.GetDelimitedStr(strData);
  982. // 格式为 {"__totalcount":2,"__data":[{"name":"2012/03", "y":554},{"name":"2012/04", "y":5}]}
  983. string strRet = "{\"__totalcount\":" + nCount + ",\"__data\":" + strData + "}";
  984. return strRet;
  985. }
  986. // 生成返回的Json格式数据,注意此数据格式尽量和图表类型无关,给予前台页面更大自由度
  987. public string GenOutputData(int nCount, List<Array> listData)
  988. {
  989. string strRet = string.Empty;
  990. if ((listData != null) && (listData.Count > 1))
  991. {
  992. // x轴的Categories,注意各项都有双引号,用逗号相隔开
  993. string strCategories = ArrayToStringEx(listData[0]);
  994. strCategories = UtilStr.GetDelimitedStr(strCategories);
  995. // y轴数据列表
  996. Array arraySeries = new string[listData.Count - 1];
  997. for (int i = 0; i < listData.Count - 1; i++)
  998. {
  999. string strData = ArrayToString(listData[i + 1]);
  1000. strData = UtilStr.GetDelimitedStr(strData);
  1001. arraySeries.SetValue(strData, i);
  1002. }
  1003. // y轴数据列表转换成string
  1004. string strSeries = ArrayToString(arraySeries);
  1005. strSeries = UtilStr.GetDelimitedStr(strSeries);
  1006. // 返回结果
  1007. strRet = "{\"__totalcount\":" + nCount + ",\"__categories\":" +
  1008. strCategories + ",\"__series\":" + strSeries + "}";
  1009. }
  1010. //strRet = "{\"__totalcount\":3,\"__categories\":[\"2012/02\",\"2012/03\",\"2012/04\"],\"__series\":[[533,924,554],[1,0.99,0.98]]}";
  1011. return strRet;
  1012. }
  1013. // 将一个Array各项用逗号隔开,拼成一个string
  1014. private string ArrayToString(Array paArray)
  1015. {
  1016. string lcStr = "";
  1017. foreach (string lcStr2 in paArray)
  1018. {
  1019. lcStr = lcStr + ((lcStr == "") ? "" : ",") + lcStr2;
  1020. }
  1021. return lcStr;
  1022. }
  1023. // 将一个Array各项左右加双引号,再用逗号隔开,拼成一个string
  1024. private string ArrayToStringEx(Array paArray)
  1025. {
  1026. string lcStr = "";
  1027. foreach (string lcStr2 in paArray)
  1028. {
  1029. lcStr = lcStr + ((lcStr == "") ? "" : ",") + "\"" + lcStr2 + "\"";
  1030. }
  1031. return lcStr;
  1032. }
  1033. #endregion
  1034. public static T DeepCopyByReflect<T>(T obj)
  1035. {
  1036. //如果是字符串或值类型则直接返回
  1037. if (obj is string || obj.GetType().IsValueType) return obj;
  1038. object retval = Activator.CreateInstance(obj.GetType());
  1039. FieldInfo[] fields = obj.GetType()
  1040. .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
  1041. foreach (FieldInfo field in fields)
  1042. {
  1043. try
  1044. {
  1045. field.SetValue(retval, DeepCopyByReflect(field.GetValue(obj)));
  1046. }
  1047. catch
  1048. {
  1049. //
  1050. }
  1051. }
  1052. return (T) retval;
  1053. }
  1054. }
  1055. public enum NumberType
  1056. {
  1057. VarietyCategoryNo = 1, //产品类别编号
  1058. CheckProjectTypeNo = 2,
  1059. CheckItemNo = 3
  1060. }
  1061. }