DataHelper.cs 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. using Oracle.ManagedDataAccess.Client;
  2. using System;
  3. using System.Data;
  4. using System.Text;
  5. using System.Collections;
  6. using UAS_LabelMachine.PublicMethod;
  7. using System.Collections.Generic;
  8. namespace UAS_LabelMachine
  9. {
  10. public class DataHelper
  11. {
  12. //泽天外网地址
  13. private readonly string ConnectionStrings = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=ZT;Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=183.47.41.2)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  14. //泽天ERP地址
  15. public static readonly string ERPAddesss = "http://183.47.41.2:8099/ERP/";
  16. //泽天FTP外网
  17. //public static readonly string FTPAdress = "ftp://183.47.41.3:21|uas|Zt2018";
  18. //泽天FTP内网
  19. public static readonly string FTPAdress = "ftp://10.2.10.241|uas|Lz201478c";
  20. //Oracle端口
  21. public static readonly string OraclePort = "1521";
  22. //需要显示的账套
  23. public static readonly string Masters = "ZT_TEST,ZT";
  24. //用户选择的数据库的连接字符串
  25. public static string DBConnectionString;
  26. static OracleConnection connection = null;
  27. static OracleCommand command = null;
  28. /// <summary>
  29. /// 执行构造函数的时候打开数据库的链接
  30. /// </summary>
  31. public DataHelper()
  32. {
  33. try
  34. {
  35. //如果选择的是默认数据则直接用配置文件的信息连接,否则选择数据库的账套信息
  36. if (DBConnectionString == null || DBConnectionString == ConnectionStrings)
  37. {
  38. DBConnectionString = ConnectionStrings;
  39. connection = new OracleConnection(ConnectionStrings);
  40. }
  41. else
  42. {
  43. connection = new OracleConnection(DBConnectionString);
  44. }
  45. connection.Open();
  46. }
  47. catch (Exception e) { LogManager.DoLog(e.Message); }
  48. }
  49. /// <summary>
  50. ///
  51. /// </summary>
  52. public void Dispose()
  53. {
  54. connection.Dispose();
  55. }
  56. /// <summary>
  57. /// 根据表名获取该表字段数据类型
  58. /// </summary>
  59. public DataTable GetColumnDataType(string TableName)
  60. {
  61. DataTable dt = new DataTable();
  62. command = new OracleCommand("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", connection);
  63. OracleDataAdapter ad = new OracleDataAdapter(command);
  64. ad.Fill(dt);
  65. ad.Dispose();
  66. return dt;
  67. }
  68. public object GetLabelParam(string sql)
  69. {
  70. DataTable dt = new DataTable();
  71. command = new OracleCommand(sql, connection);
  72. OracleDataAdapter ad = new OracleDataAdapter();
  73. ad.SelectCommand = command;
  74. ad.Fill(dt);
  75. if (dt.Rows.Count > 0)
  76. {
  77. ad.Dispose();
  78. return dt.Rows[0][0];
  79. }
  80. else { return ""; }
  81. }
  82. /// <summary>
  83. /// 获取第一行第一列的信息
  84. /// </summary>
  85. public object getFieldDataByCondition(string TableName, string Field, string Condition)
  86. {
  87. DataTable dt = new DataTable();
  88. string sql = "select " + Field + " from " + TableName + " where " + Condition;
  89. command = new OracleCommand(sql, connection);
  90. Reconnect(command);
  91. OracleDataAdapter ad = new OracleDataAdapter();
  92. ad.SelectCommand = command;
  93. try
  94. {
  95. ad.Fill(dt);
  96. }
  97. catch (Exception)
  98. {
  99. connection = new OracleConnection(DBConnectionString);
  100. connection.Open();
  101. command = new OracleCommand(sql, connection);
  102. ad = new OracleDataAdapter();
  103. ad.SelectCommand = command;
  104. ad.Fill(dt);
  105. }
  106. ad.Dispose();
  107. if (dt.Rows.Count > 0)
  108. {
  109. return dt.Rows[0][0];
  110. }
  111. else
  112. {
  113. return "";
  114. }
  115. }
  116. /// <summary>
  117. /// 获取第一行第一列的信息
  118. /// </summary>
  119. public object getFieldDataByConditionForUpdate(string TableName, string Field, string Condition ,string Wait)
  120. {
  121. DataTable dt = new DataTable();
  122. string sql = "select " + Field + " from " + TableName + " where " + Condition + " for "+ Wait;
  123. command = new OracleCommand(sql, connection);
  124. Reconnect(command);
  125. OracleDataAdapter ad = new OracleDataAdapter();
  126. ad.SelectCommand = command;
  127. try
  128. {
  129. ad.Fill(dt);
  130. }
  131. catch (Exception)
  132. {
  133. connection = new OracleConnection(DBConnectionString);
  134. connection.Open();
  135. command = new OracleCommand(sql, connection);
  136. ad = new OracleDataAdapter();
  137. ad.SelectCommand = command;
  138. ad.Fill(dt);
  139. }
  140. ad.Dispose();
  141. if (dt.Rows.Count > 0)
  142. {
  143. return dt.Rows[0][0];
  144. }
  145. else
  146. {
  147. return "";
  148. }
  149. }
  150. /// <summary>
  151. /// 执行打印的SQL
  152. /// </summary>
  153. /// <param name="SQL">SQL语句</param>
  154. /// <param name="Parameters">动态添加的参数,主要根据条码枪扫描获取</param>
  155. /// <returns></returns>
  156. public object ExecutePrintSQL(string SQL, params string[] Parameters)
  157. {
  158. //按照?拆分数据,然后以:Param替换问号,同时添加参数
  159. string[] Param = SQL.Split('?');
  160. int ParamNum = Param.Length - 1;
  161. //条码打印必然存在需要维护的参数
  162. if (ParamNum > 0)
  163. {
  164. StringBuilder sb = new StringBuilder();
  165. for (int i = 0; i < ParamNum; i++)
  166. {
  167. sb.Append(Param[i] + ":Param" + i);
  168. }
  169. command = new OracleCommand(sb.ToString(), connection);
  170. for (int i = 0; i < ParamNum; i++)
  171. {
  172. command.Parameters.Add("Param" + i, OracleDbType.Varchar2, Parameters[i], ParameterDirection.Input);
  173. }
  174. OracleDataAdapter ad = new OracleDataAdapter(command);
  175. DataTable dt = new DataTable();
  176. ad.Fill(dt);
  177. ad.Dispose();
  178. return dt;
  179. }
  180. return "参数错误,请检查SQL语句";
  181. }
  182. /// <summary>
  183. /// 获取指定表的记录的条数 ,带条件
  184. /// </summary>
  185. /// <returns></returns>
  186. public int getRowCount(string TableName, string Condition)
  187. {
  188. DataTable dt = new DataTable();
  189. string sql = "select count(1) from " + TableName + " where " + Condition;
  190. command = new OracleCommand(sql, connection);
  191. OracleDataAdapter ad = new OracleDataAdapter(command);
  192. ad.Fill(dt);
  193. int count = int.Parse(dt.Rows[0][0].ToString());
  194. return count;
  195. }
  196. /// <summary>
  197. /// 获取指定表的记录的条数 ,不带条件
  198. /// </summary>
  199. /// <param name="TableName"></param>
  200. /// <returns></returns>
  201. public int getRowCount(string TableName)
  202. {
  203. DataTable dt = new DataTable();
  204. string sql = "select count(1) from " + TableName;
  205. command = new OracleCommand(sql, connection);
  206. OracleDataAdapter ad = new OracleDataAdapter(command);
  207. ad.Fill(dt);
  208. int count = int.Parse(dt.Rows[0][0].ToString());
  209. return count;
  210. }
  211. /// <summary>
  212. /// 通过表名和获取单行的记录
  213. /// </summary>
  214. public DataTable getFieldsDataByCondition(string TableName, string[] Fields, string Condition)
  215. {
  216. DataTable dt = new DataTable();
  217. string sql = "select ";
  218. sql += AddField(Fields);
  219. sql += " from " + TableName + " where " + Condition + " and rownum=1";
  220. command = new OracleCommand(sql, connection);
  221. OracleDataAdapter ad = new OracleDataAdapter(command);
  222. ad.Fill(dt);
  223. return dt;
  224. }
  225. /// <summary>
  226. /// 通过表名和获取单行的记录
  227. /// </summary>
  228. public DataTable getFieldsDatasByCondition(string sql)
  229. {
  230. DataTable dt = new DataTable();
  231. command = new OracleCommand(sql, connection);
  232. OracleDataAdapter ad = new OracleDataAdapter(command);
  233. ad.Fill(dt);
  234. return dt;
  235. }
  236. /// <summary>
  237. /// 将DataTable导入到指定的表中
  238. /// </summary>
  239. /// <param name="DataTable"></param>
  240. /// <param name="TableName"></param>
  241. public void InsertDataTable(DataTable DataTable, string TableName)
  242. {
  243. for (int i = 0; i < DataTable.Rows.Count; i++)
  244. {
  245. for (int j = 0; j < DataTable.Columns.Count; j++)
  246. {
  247. }
  248. }
  249. }
  250. /// <summary>
  251. /// 按分页获取数据
  252. /// </summary>
  253. /// <param name="TableName">表名</param>
  254. /// <param name="Fields">查询字段</param>
  255. /// <param name="CurrentPage">当前页面</param>
  256. /// <param name="PageSize">页面展示条数</param>
  257. /// <param name="Caller"></param>
  258. /// <returns></returns>
  259. // SELECT * FROM (SELECT A.* FROM (SELECT* FROM datalist) A WHERE ROWNUM <= 50) WHERE ROWNUM >= 21
  260. public DataTable getFieldsDatasByPageing(string TableName, string Fields, int CurrentPage, int PageSize, string Caller, params string[] condition)
  261. {
  262. DataTable dt = new DataTable();
  263. StringBuilder sql = new StringBuilder();
  264. //先查询出配置出去的列
  265. //获取查询的列
  266. string[] caption = GetCaptionFromField(Fields);
  267. //获取对应列的描述
  268. string[] field = GetField(Fields);
  269. sql.Append(" select * from (select RowNum RN, A.* from (select ");
  270. sql.Append(AddField(caption));
  271. if (condition.Length > 0)
  272. {
  273. if (condition[0].Trim() != "")
  274. {
  275. sql.Append(" from " + TableName + " where " + condition[0] + " ) A where ROWNUM <=" + CurrentPage * PageSize + ") where RN>" + (CurrentPage - 1) * PageSize);
  276. }
  277. else
  278. {
  279. sql.Append(" from " + TableName + ") A where ROWNUM <= " + CurrentPage * PageSize + ") where RN> " + (CurrentPage - 1) * PageSize);
  280. }
  281. }
  282. command = new OracleCommand(sql.ToString(), connection);
  283. OracleDataAdapter ad = new OracleDataAdapter(command);
  284. ad.Fill(dt);
  285. dt.Columns.RemoveAt(0);
  286. foreach (DataColumn dc in dt.Columns)
  287. {
  288. dc.ColumnName = field[dt.Columns.IndexOf(dc)];
  289. dc.Caption = caption[dt.Columns.IndexOf(dc)];
  290. }
  291. return dt;
  292. }
  293. /// <summary>
  294. /// 通过表名,字段和条件获取DataTable类型的数据
  295. /// </summary>
  296. public DataTable getFieldsDatasByCondition(string TableName, string[] Fields, string Condition)
  297. {
  298. DataTable dt = new DataTable();
  299. string sql = "select ";
  300. sql += AddField(Fields);
  301. sql += " from " + TableName + " where " + Condition;
  302. command = new OracleCommand(sql, connection);
  303. OracleDataAdapter ad = new OracleDataAdapter(command);
  304. ad.Fill(dt);
  305. return dt;
  306. }
  307. /// <summary>
  308. /// 通过表名,字段获取DataTable类型的数据
  309. /// </summary>
  310. public string[] getFieldsDatas(string TableName, string Fields)
  311. {
  312. ArrayList arr = new ArrayList();
  313. DataTable dt = new DataTable();
  314. string sql = "select ";
  315. sql += Fields;
  316. sql += " from " + TableName;
  317. command = new OracleCommand(sql, connection);
  318. OracleDataAdapter ad = new OracleDataAdapter(command);
  319. ad.SelectCommand = command;
  320. ad.Fill(dt);
  321. foreach (DataRow dc in dt.Rows)
  322. {
  323. arr.Add(dc[Fields]);
  324. }
  325. ad.Dispose();
  326. return (string[])arr.ToArray(typeof(string));
  327. }
  328. /// <summary>
  329. /// 通过表名,字段获取DataTable类型的数据
  330. /// </summary>
  331. public string[] getFieldsDatas(string TableName, string Fields, string Condition)
  332. {
  333. ArrayList arr = new ArrayList();
  334. DataTable dt = new DataTable();
  335. string sql = "select ";
  336. sql += Fields;
  337. sql += " from " + TableName + " where " + Condition;
  338. command = new OracleCommand(sql, connection);
  339. OracleDataAdapter ad = new OracleDataAdapter(command);
  340. ad.SelectCommand = command;
  341. ad.Fill(dt);
  342. foreach (DataRow dc in dt.Rows)
  343. {
  344. arr.Add(dc[Fields]);
  345. }
  346. ad.Dispose();
  347. return (string[])arr.ToArray(typeof(string));
  348. }
  349. /// <summary>
  350. /// 根据DataTable和指定的表名更新数据,如果需要保存新增的数据则需要传递一条Insert的SQL
  351. /// </summary>
  352. /// <param name="DataTable"></param>
  353. /// <param name="TableName"></param>
  354. /// <param name="Condition"></param>
  355. public void UpDateTableByCondition(DataTable DataTable, string TableName, string PrimaryKey, params string[] sql)
  356. {
  357. if (DataTable == null)
  358. {
  359. return;
  360. }
  361. StringBuilder sb = new StringBuilder();
  362. //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
  363. DataTable data = (DataTable)ExecuteSql("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", "select");
  364. //将所有的字段拼接起来
  365. for (int i = 0; i < data.Rows.Count; i++)
  366. {
  367. sb.Append("#" + data.Rows[i]["Column_Name"].ToString());
  368. }
  369. //移除掉所有不属于该表的列
  370. for (int i = DataTable.Columns.Count - 1; i >= 0; i--)
  371. {
  372. if (!sb.ToString().Contains(DataTable.Columns[i].ColumnName.ToUpper()))
  373. {
  374. DataTable.Columns.RemoveAt(i);
  375. }
  376. }
  377. sb.Clear();
  378. //计算有多少个是新加的行,根据主键为空来进行判断
  379. int NewRowCount = 0;
  380. for (int i = 0; i < DataTable.Rows.Count; i++)
  381. {
  382. if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
  383. {
  384. NewRowCount = NewRowCount + 1;
  385. }
  386. }
  387. if (sql.Length > 0)
  388. {
  389. if (NewRowCount > 0)
  390. {
  391. //获取参数的个数
  392. int paramsNum = sql[0].Split(':').Length - 1;
  393. //解析参数的数据
  394. string[] param = GetParamFromSQL(sql[0]);
  395. //新建一个二维数组去
  396. string[][] param_array = new string[paramsNum][];
  397. //实例化每个一维数组
  398. for (int i = 0; i < paramsNum; i++)
  399. {
  400. param_array[i] = new string[NewRowCount];
  401. }
  402. //设置每列参数的索引
  403. int num = 0;
  404. //变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
  405. for (int i = DataTable.Rows.Count - 1; i >= 0; i--)
  406. {
  407. if (DataTable.Rows[i][PrimaryKey] == null || DataTable.Rows[i][PrimaryKey].ToString() == "")
  408. {
  409. //当为新添加行的时候才去设置参数,设置过后索引+1
  410. for (int j = 0; j < paramsNum; j++)
  411. {
  412. param_array[j][num] = DataTable.Rows[i][param[j]].ToString();
  413. }
  414. DataTable.Rows.RemoveAt(i);
  415. num++;
  416. }
  417. }
  418. BatchInsertDataTable(sql[0], param, param_array);
  419. }
  420. }
  421. //不是新增行的启用更新的方法
  422. sb.Append("update " + TableName + " set ");
  423. //拼接语句,特殊处理日期
  424. foreach (DataColumn dc in DataTable.Columns)
  425. {
  426. if (!dc.DataType.ToString().Equals("System.DateTime"))
  427. {
  428. sb.Append(dc.Caption + "=:" + dc.Caption + ",");
  429. }
  430. else
  431. {
  432. sb.Append(dc.Caption + "=:" + dc.Caption + ",");
  433. }
  434. }
  435. sb.Remove(sb.Length - 1, 1);
  436. sb.Append(" where " + PrimaryKey + "=:" + PrimaryKey);
  437. command = new OracleCommand(sb.ToString(), connection);
  438. OracleDataAdapter ad = new OracleDataAdapter(command);
  439. // 参数的长度是DataTable的行数决定的
  440. command.ArrayBindCount = DataTable.Rows.Count;
  441. //默认全部是Varchar2类型的
  442. OracleDbType ob = OracleDbType.Varchar2;
  443. for (int i = 0; i < DataTable.Columns.Count; i++)
  444. {
  445. object[] param = new object[DataTable.Rows.Count];
  446. for (int j = 0; j < DataTable.Rows.Count; j++)
  447. {
  448. DateTime dt = DateTime.Now;
  449. //if (DateTime.TryParse(DataTable.Rows[j][i].ToString(), out dt))
  450. //{
  451. // param[j] = dt;
  452. // ob = OracleDbType.Date;
  453. //}
  454. //else
  455. //{
  456. ob = OracleDbType.Varchar2;
  457. param[j] = DataTable.Rows[j][i];
  458. //}
  459. }
  460. //添加批量更新的参数
  461. command.Parameters.Add(new OracleParameter(DataTable.Columns[i].Caption, ob, param, ParameterDirection.Input));
  462. }
  463. ad.UpdateCommand = command;
  464. ad.Update(DataTable);
  465. ad.Dispose();
  466. }
  467. public void SaveDataTable(DataTable dt, string TableName, string ID, params string[] sql)
  468. {
  469. if (dt == null)
  470. {
  471. return;
  472. }
  473. StringBuilder sb = new StringBuilder();
  474. //预防插入的DataTable中存在不属于该表的列,在进行下一步操作之前全部剔除
  475. DataTable data = (DataTable)ExecuteSql("select Column_Name,Data_Type from cols where TABLE_name=upper('" + TableName + "')", "select");
  476. //将所有的字段拼接起来
  477. for (int i = 0; i < data.Rows.Count; i++)
  478. {
  479. sb.Append("#" + data.Rows[i]["Column_Name"].ToString());
  480. }
  481. //移除掉所有不属于该表的列
  482. for (int i = dt.Columns.Count - 1; i >= 0; i--)
  483. {
  484. if (!sb.ToString().Contains(dt.Columns[i].ColumnName.ToUpper()))
  485. {
  486. dt.Columns.RemoveAt(i);
  487. }
  488. }
  489. sb.Clear();
  490. //计算有多少个是新加的行,根据主键为空来进行判断
  491. int NewRowCount = 0;
  492. for (int i = 0; i < dt.Rows.Count; i++)
  493. {
  494. if (dt.Rows[i][ID] == null || dt.Rows[i][ID].ToString() == "")
  495. {
  496. NewRowCount = NewRowCount + 1;
  497. }
  498. }
  499. if (sql.Length > 0)
  500. {
  501. if (NewRowCount > 0)
  502. {
  503. //获取参数的个数
  504. int paramsNum = sql[0].Split(':').Length - 1;
  505. //解析参数的数据
  506. string[] param = GetParamFromSQL(sql[0]);
  507. //新建一个二维数组去
  508. string[][] param_array = new string[paramsNum][];
  509. //实例化每个一维数组
  510. for (int i = 0; i < paramsNum; i++)
  511. {
  512. param_array[i] = new string[NewRowCount];
  513. }
  514. //设置每列参数的索引
  515. int num = 0;
  516. //变量所有的行,如果有主键为空的则移除,不为空的进行参数的拼接
  517. for (int i = dt.Rows.Count - 1; i >= 0; i--)
  518. {
  519. if (dt.Rows[i][ID] == null || dt.Rows[i][ID].ToString() == "")
  520. {
  521. //当为新添加行的时候才去设置参数,设置过后索引+1
  522. for (int j = 0; j < paramsNum; j++)
  523. {
  524. param_array[j][num] = dt.Rows[i][param[j]].ToString();
  525. }
  526. //dt.Rows.RemoveAt(i);
  527. num++;
  528. }
  529. }
  530. BatchInsertDataTable(sql[0], param, param_array);
  531. }
  532. }
  533. //sb.Clear();
  534. //sb.Append("update " + TableName + " set ");
  535. //int ColumnCount = dt.Columns.Count;
  536. //int RowCount = dt.Rows.Count;
  537. ////存数据的参数
  538. //List<string[]> Parameter = new List<string[]>();
  539. ////存参数名的参数
  540. //string[] ParName = new string[ColumnCount];
  541. //for (int i = 0; i < ColumnCount; i++)
  542. //{
  543. // ParName[i] = dt.Columns[i].ColumnName;
  544. // if (i == dt.Columns.Count - 1)
  545. // sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName);
  546. // else
  547. // sb.Append(dt.Columns[i].ColumnName + "=:" + dt.Columns[i].ColumnName + ",");
  548. //}
  549. //sb.Append(" where " + ID + " =:" + ID);
  550. ////先添加参数
  551. //Parameter.Add(ParName);
  552. ////添加参数的具体内容
  553. //for (int i = 0; i < ColumnCount; i++)
  554. //{
  555. // string[] par = new string[RowCount];
  556. // for (int j = 0; j < RowCount; j++)
  557. // {
  558. // par[j] = dt.Rows[j][i].ToString();
  559. // }
  560. // Parameter.Add(par);
  561. //}
  562. //BatchInsert(sb.ToString(), Parameter.ToArray());
  563. }
  564. /// <summary>
  565. /// 获取DbFind的数据的DataTable的结构
  566. /// </summary>
  567. /// <param name="field"></param>
  568. /// <param name="caller"></param>
  569. /// <returns></returns>
  570. public DataTable GetDbFindDataTable(string field, string caller)
  571. {
  572. string sql = "select * from dbfindsetui where ds_caller='" + caller + "' and ds_whichui='" + field + "'";
  573. DataTable dt = (DataTable)ExecuteSql(sql, "select");
  574. if (dt.Rows.Count != 0)
  575. {
  576. //通过#号分割字段
  577. string[] dbfield = dt.Rows[0]["ds_findtoui"].ToString().Split('#');
  578. string[] cnfield = dt.Rows[0]["ds_dbcaption"].ToString().Split('#');
  579. //获取查询要查询的Table
  580. string dbtable = dt.Rows[0]["ds_tables"].ToString();
  581. //拼接查询的字段
  582. for (int i = 0; i < dbfield.Length; i++)
  583. {
  584. dbfield[i] = dbfield[i].Split(',')[0];
  585. }
  586. //新建一个空的DataTable
  587. DataTable dt1 = new DataTable();
  588. //往空的DataTable添加结构,ColumnName是中文,Caption是实际的字段名称
  589. for (int i = 0; i < cnfield.Length; i++)
  590. {
  591. dt1.Columns.Add(cnfield[i]);
  592. dt1.Columns[i].Caption = dbfield[i];
  593. }
  594. //返回一个带有结构的空的DataTable
  595. // DbFind.BindTable1 = dbtable;
  596. return dt1;
  597. }
  598. else
  599. {
  600. return null;
  601. }
  602. }
  603. /// <summary>
  604. /// 获取配置列表中的数据,支持DaatList,Form,DetailGrid
  605. /// </summary>
  606. /// <param name="Caller"></param>
  607. /// <param name="Type"></param>
  608. /// <param name="condition"></param>
  609. /// <returns></returns>
  610. public DataTable GetConfigureData(string Caller, string Type, string condition)
  611. {
  612. DataTable dt = new DataTable();
  613. //用于拼接SQL语句
  614. StringBuilder Sql = new StringBuilder();
  615. //用于设置不同Type时设置对应表的字段
  616. string getField = "";
  617. string getCaption = "";
  618. string getTable = "";
  619. switch (Type.ToUpper())
  620. {
  621. case "DATALIST":
  622. getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
  623. Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
  624. break;
  625. case "FORM":
  626. getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
  627. Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
  628. break;
  629. case "DETAILGRID":
  630. getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
  631. Sql.Append("select * from detailgrid where dg_caller='" + Caller + "'");
  632. break;
  633. }
  634. command = new OracleCommand(Sql.ToString(), connection);
  635. OracleDataAdapter ad = new OracleDataAdapter(command);
  636. ad.Fill(dt);
  637. //清除掉之前的内容重新拼接
  638. Sql.Clear();
  639. Sql.Append("select ");
  640. string[] field = new string[dt.Rows.Count];
  641. string[] caption = new string[dt.Rows.Count];
  642. DataTable dt1 = new DataTable();
  643. //记录描述和字段名称
  644. foreach (DataRow dr in dt.Rows)
  645. {
  646. field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
  647. caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
  648. Sql.Append(dr[getField] + ",");
  649. }
  650. //调用substring是为了去除之前拼接多出来的一个逗号
  651. string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable] + " where " + condition;
  652. //调用一个新的构造DataTable用来存放返回的数据
  653. dt1 = (DataTable)ExecuteSql(sql, "select");
  654. //给DataTable加上列名和描述,列名是中文字段,描述是数据库实际的字段名称
  655. for (int i = 0; i < field.Length; i++)
  656. {
  657. dt1.Columns[i].ColumnName = field[i];
  658. dt1.Columns[i].Caption = caption[i];
  659. }
  660. //返回的第一条数据是SQL,后面的是实际的列名
  661. return dt1;
  662. }
  663. /// <summary>
  664. /// 查询配置的字段,Type是查询DataList,Form还是DetailGrid
  665. /// </summary>
  666. /// <param name="Caller"></param>
  667. /// <param name="Type"></param>
  668. /// <returns></returns>
  669. public DataTable GetConfigureData(string Caller, string Type)
  670. {
  671. DataTable dt = new DataTable();
  672. //用于拼接SQL语句
  673. StringBuilder Sql = new StringBuilder();
  674. //用于设置不同Type时设置对应表的字段
  675. string getField = "";
  676. string getCaption = "";
  677. string getTable = "";
  678. switch (Type.ToUpper())
  679. {
  680. case "DATALIST":
  681. getField = "dld_field"; getCaption = "dld_caption"; getTable = "dld_table";
  682. Sql.Append("select * from datalistdetail where dld_caller='" + Caller + "'");
  683. break;
  684. case "FORM":
  685. getField = "fd_field"; getCaption = "fd_caption"; getTable = "fd_table";
  686. Sql.Append("select * from formdetail where fd_foid=( select fo_id from form where fo_caller='" + Caller + "')");
  687. break;
  688. case "DETAILGRID":
  689. getField = "dg_field"; getCaption = "dg_caption"; getTable = "dg_table";
  690. Sql.Append("select * from detailgrid where dg_caller='" + Caller + "'");
  691. break;
  692. }
  693. command = new OracleCommand(Sql.ToString(), connection);
  694. OracleDataAdapter ad = new OracleDataAdapter(command);
  695. ad.Fill(dt);
  696. //清除掉之前的内容重新拼接
  697. Sql.Clear();
  698. Sql.Append("select ");
  699. //用于记录实际的列名,+1的目的是为了存放SQL
  700. string[] field = new string[dt.Rows.Count];
  701. string[] caption = new string[dt.Rows.Count];
  702. DataTable dt1 = new DataTable();
  703. foreach (DataRow dr in dt.Rows)
  704. {
  705. field[dt.Rows.IndexOf(dr)] = dr[getCaption].ToString();
  706. caption[dt.Rows.IndexOf(dr)] = dr[getField].ToString();
  707. Sql.Append(dr[getField] + ",");
  708. }
  709. string sql = Sql.Remove(Sql.Length - 1, 1).ToString() + " from " + dt.Rows[0][getTable];
  710. dt1 = (DataTable)ExecuteSql(sql, "select");
  711. //设置DataTable的列名和描述
  712. for (int i = 0; i < field.Length; i++)
  713. {
  714. dt1.Columns[i].ColumnName = field[i];
  715. dt1.Columns[i].Caption = caption[i];
  716. }
  717. ad.Dispose();
  718. return dt1;
  719. }
  720. /// <summary>
  721. /// 检测内容是否存在
  722. /// </summary>
  723. /// <param name="TableName"></param>
  724. /// <param name="Condition"></param>
  725. /// <returns></returns>
  726. public bool CheckExist(string TableName, string Condition)
  727. {
  728. string sql = "select count(1) from " + TableName + " where " + Condition;
  729. command = new OracleCommand(sql, connection);
  730. OracleDataAdapter ad = new OracleDataAdapter(command);
  731. DataTable dt = new DataTable();
  732. ad.Fill(dt);
  733. if (int.Parse(dt.Rows[0][0].ToString()) > 0)
  734. {
  735. ad.Dispose();
  736. return true;
  737. }
  738. else
  739. {
  740. ad.Dispose();
  741. return false;
  742. }
  743. }
  744. /// <summary>
  745. /// 直接执行SQL,同时传入SQL的类型
  746. /// </summary>
  747. /// <param name="SQL"></param>
  748. /// <param name="Type"></param>
  749. /// <returns></returns>
  750. public object ExecuteSql(string SQL, string Type, params object[] names)
  751. {
  752. object result = null;
  753. Console.WriteLine( SQL);
  754. command = new OracleCommand(SQL, connection);
  755. Reconnect(command);
  756. //用来拼接参数的
  757. if (names.Length > 0)
  758. {
  759. string[] par = SQL.Split(':');
  760. //用来存参数的数组
  761. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  762. for (int i = 0; i < par.Length - 1; i++)
  763. {
  764. //新建一个char类型的数组用来存储每个字节的变量
  765. char[] c = par[i + 1].ToCharArray();
  766. addpar[i] = new StringBuilder();
  767. for (int j = 0; j < c.Length; j++)
  768. {
  769. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  770. {
  771. addpar[i].Append(c[j]);
  772. }
  773. else
  774. {
  775. break;
  776. }
  777. }
  778. }
  779. for (int i = 0; i < addpar.Length; i++)
  780. command.Parameters.Add(new OracleParameter(addpar[i].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
  781. }
  782. switch (Type.ToUpper())
  783. {
  784. case "SELECT":
  785. OracleDataAdapter ad = new OracleDataAdapter(command);
  786. result = new DataTable();
  787. try
  788. {
  789. ad.Fill((DataTable)result);
  790. }
  791. catch (Exception)
  792. {
  793. connection = new OracleConnection(DBConnectionString);
  794. connection.Open();
  795. command = new OracleCommand(SQL, connection);
  796. ad = new OracleDataAdapter();
  797. ad.SelectCommand = command;
  798. ad.Fill((DataTable)result);
  799. }
  800. break;
  801. case "DELETE":
  802. try
  803. {
  804. result = command.ExecuteNonQuery();
  805. }
  806. catch (Exception)
  807. {
  808. command.Connection = new OracleConnection(DBConnectionString);
  809. command.Connection.Open();
  810. result = command.ExecuteNonQuery();
  811. }
  812. break;
  813. case "UPDATE":
  814. try
  815. {
  816. result = command.ExecuteNonQuery();
  817. }
  818. catch (Exception)
  819. {
  820. command.Connection = new OracleConnection(DBConnectionString);
  821. command.Connection.Open();
  822. result = command.ExecuteNonQuery();
  823. }
  824. break;
  825. case "INSERT":
  826. try
  827. {
  828. result = command.ExecuteNonQuery();
  829. }
  830. catch (Exception)
  831. {
  832. command.Connection = new OracleConnection(DBConnectionString);
  833. command.Connection.Open();
  834. result = command.ExecuteNonQuery();
  835. }
  836. break;
  837. }
  838. //
  839. return result;
  840. }
  841. /// <summary>
  842. /// 为了同步BS端的条码维护,检测时允许问号的存在,在检测时默认将问号换成:Param参数
  843. /// </summary>
  844. /// <param name="SQL"></param>
  845. public bool CheckSQL(string SQL, out string ErrorMessage)
  846. {
  847. ErrorMessage = "";
  848. try
  849. {
  850. SQL = SQL.Replace("?", ":Param");
  851. command = new OracleCommand(SQL, connection);
  852. command.ExecuteNonQuery();
  853. return true;
  854. }
  855. catch (Exception e)
  856. {
  857. ErrorMessage = e.Message;
  858. return false;
  859. }
  860. }
  861. public int GetDistinctRowCount(string TableName, string Field)
  862. {
  863. DataTable dt = new DataTable();
  864. string sql = "select distinct count('" + Field + "') from " + TableName;
  865. OracleDataAdapter ad = new OracleDataAdapter(new OracleCommand(sql, connection));
  866. ad.Fill(dt);
  867. return int.Parse(dt.Rows[0][0].ToString());
  868. }
  869. /// <summary>
  870. /// 根据Caller获取流水号
  871. /// </summary>
  872. /// <param name="Caller"></param>
  873. /// <returns></returns>
  874. public string GetSerialNumberByCaller(string Caller)
  875. {
  876. string SerialNumber = getFieldDataByCondition("MaxNumbers", "mn_number", "mn_tablename='" + Caller + "'").ToString();
  877. UpdateByCondition("MaxNumbers", "mn_number=mn_number+1", "mn_tablename='" + Caller + "'");
  878. return SerialNumber;
  879. }
  880. /// <summary>
  881. /// 根据主键ID删除表的数据
  882. /// </summary>
  883. /// <param name="TableName">表名</param>
  884. /// <param name="ID">主键</param>
  885. /// <param name="DeleteID">需要删除主键ID的数组</param>
  886. public void DeleteDataByID(string TableName, string ID, string[] DeleteID)
  887. {
  888. string sql = "delete from " + TableName + " where " + ID + " =:DeleteID";
  889. command = new OracleCommand(sql, connection);
  890. command.ArrayBindCount = DeleteID.Length;
  891. command.Parameters.Add(new OracleParameter("DeleteID", OracleDbType.Long, DeleteID, ParameterDirection.Input));
  892. command.ExecuteNonQuery();
  893. }
  894. /// <summary>
  895. /// 通过序列的名称获取序列
  896. /// </summary>
  897. /// <param name="SeqName"></param>
  898. /// <returns></returns>
  899. public string GetSEQ(string SeqName)
  900. {
  901. DataTable dt = new DataTable();
  902. dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".NEXTVAL FROM DUAL", "select");
  903. return dt.Rows[0][0].ToString();
  904. }
  905. /// <summary>
  906. /// 通过序列的名称获取序列
  907. /// </summary>
  908. /// <param name="SeqName"></param>
  909. /// <returns></returns>
  910. public string[] GetSEQ(string SeqName, int Num)
  911. {
  912. DataTable dt = new DataTable();
  913. dt = (DataTable)ExecuteSql("SELECT " + SeqName + ".nextval FROM DUAL CONNECT BY LEVEL<=" + Num, "select");
  914. string[] SerialNum = new string[dt.Rows.Count];
  915. for (int i = 0; i < dt.Rows.Count; i++)
  916. {
  917. SerialNum[i] = dt.Rows[i][0].ToString();
  918. }
  919. return SerialNum;
  920. }
  921. /// <summary>
  922. /// 批量通过SQL来执行插入操作 ,参数的第一个数一个string[]数组,用来传递需要添加的参数的名称
  923. /// 之后的是名称参数数组对应的 ,所有的插入参数数据长度必须是一致的
  924. /// </summary>
  925. /// <param name="sql"></param>
  926. /// <param name="names"></param>
  927. public int BatchInsert(string sql, params object[][] names)
  928. {
  929. command = new OracleCommand(sql, connection);
  930. command.ArrayBindCount = names[1].Length;
  931. //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
  932. //将第一个数组的下标固定为0作为循环添加的参数的名称
  933. for (int i = 1; i <= names[0].Length; i++)
  934. {
  935. command.Parameters.Add(new OracleParameter(names[0][i - 1].ToString(), OracleDbType.Varchar2, names[i], ParameterDirection.Input));
  936. }
  937. int rowsnum = (command.ExecuteNonQuery());
  938. return rowsnum;
  939. }
  940. public void BatchInsertDataTable(string sql, string[] param, params object[][] param1)
  941. {
  942. command = new OracleCommand(sql, connection);
  943. command.ArrayBindCount = param1[0].Length;
  944. //因为第一个数组保存的是参数的名称,所以循环从1而不是0开始
  945. //将第一个数组的下标固定为0作为循环添加的参数的名称
  946. for (int i = 0; i < param.Length; i++)
  947. {
  948. command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, param1[i], ParameterDirection.Input));
  949. }
  950. command.ExecuteNonQuery();
  951. }
  952. /// <summary>
  953. /// 查询DataList配置的字段
  954. /// </summary>
  955. /// <param name="TableName"></param>
  956. /// <param name="Caller"></param>
  957. /// <returns></returns>
  958. public string GetDataList(string TableName, string Caller)
  959. {
  960. DataTable dt = new DataTable();
  961. string SQL = " select listagg(dld_field,',') within group (order by dld_id) from datalistdetail where dld_caller='" + Caller + "'";
  962. command = new OracleCommand(SQL, connection);
  963. OracleDataAdapter ad = new OracleDataAdapter(command);
  964. ad.Fill(dt);
  965. return dt.Rows[0][0].ToString();
  966. }
  967. /// <summary>
  968. /// 取Configs表中的配置,进行该客户是否执行某个操作
  969. /// </summary>
  970. /// <param name="Code"></param>
  971. /// <param name="Caller"></param>
  972. /// <returns></returns>
  973. public object GetConfig(string Code, string Caller)
  974. {
  975. DataTable dt = new DataTable();
  976. string sql = "select * from configs where code='" + Code + "' and caller='" + Caller + "'";
  977. dt = (DataTable)ExecuteSql(sql, "select");
  978. if (dt.Rows.Count == 0)
  979. {
  980. return "";
  981. }
  982. else
  983. {
  984. return dt.Rows[0]["Data"];
  985. }
  986. }
  987. //将数据类型的列类型转换为DataTable
  988. public DataTable DataTypeColumnToDataTable(DataTable dt)
  989. {
  990. DataTable dt1 = new DataTable();
  991. dt1.Rows.Add();
  992. foreach (DataRow dr in dt.Rows)
  993. {
  994. dt1.Columns.Add(dr[0].ToString());
  995. int index = dt.Rows.IndexOf(dr);
  996. if (dr[1].ToString() == "NUMBER")
  997. {
  998. dt1.Rows[0][index] = 0;
  999. }
  1000. if (dr[1].ToString() == "VARCHAR2")
  1001. {
  1002. dt1.Rows[0][index] = "这是一段文字";
  1003. }
  1004. if (dr[1].ToString() == "DATE")
  1005. {
  1006. dt1.Rows[0][index] = DateTime.Now.ToString("yyyy-MM-dd");
  1007. }
  1008. if (dr[1].ToString() == "FLOAT")
  1009. {
  1010. dt1.Rows[0][index] = 1.0;
  1011. }
  1012. if (dr[1].ToString() == "CLOB")
  1013. {
  1014. dt1.Rows[0][index] = "一段长文字";
  1015. }
  1016. }
  1017. return dt1;
  1018. }
  1019. /// <summary>
  1020. /// 通过条件更新
  1021. /// </summary>
  1022. /// <param name="TableName"></param>
  1023. /// <param name="update"></param>
  1024. /// <param name="condition"></param>
  1025. public void UpdateByCondition(string TableName, string update, string condition)
  1026. {
  1027. string sql = "update " + TableName + " set " + update + " where " + condition;
  1028. command = new OracleCommand(sql, connection);
  1029. command.ExecuteNonQuery();
  1030. //
  1031. }
  1032. /// <summary>
  1033. /// 调用存储过程
  1034. /// </summary>
  1035. /// <param name="ProcedureName"></param>
  1036. /// <param name="param"></param>
  1037. public void CallProcedure(string ProcedureName, params string[] param)
  1038. {
  1039. command = new OracleCommand(ProcedureName);
  1040. command.Connection = connection;
  1041. command.CommandText = ProcedureName;
  1042. command.CommandType = CommandType.StoredProcedure;
  1043. for (int i = 0; i < param.Length; i++)
  1044. command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 200, param[i], ParameterDirection.InputOutput));
  1045. try
  1046. {
  1047. command.ExecuteNonQuery();
  1048. }
  1049. catch (Exception)
  1050. {
  1051. command.Connection = new OracleConnection(DBConnectionString);
  1052. command.Connection.Open();
  1053. command.ExecuteNonQuery();
  1054. }
  1055. for (int i = 0; i < command.Parameters.Count; i++)
  1056. param[i] = command.Parameters[i].Value.ToString();
  1057. }
  1058. /// <summary>
  1059. /// 调用存储过程
  1060. /// </summary>
  1061. /// <param name="ProcedureName"></param>
  1062. /// <param name="param"></param>
  1063. public void CallProcedure(string ProcedureName, ref string[] param)
  1064. {
  1065. command = new OracleCommand(ProcedureName);
  1066. command.Connection = connection;
  1067. command.CommandText = ProcedureName;
  1068. command.CommandType = CommandType.StoredProcedure;
  1069. for (int i = 0; i < param.Length; i++)
  1070. command.Parameters.Add(new OracleParameter(param[i].ToString(), OracleDbType.Varchar2, 4000, param[i], ParameterDirection.InputOutput));
  1071. try
  1072. {
  1073. command.ExecuteNonQuery();
  1074. }
  1075. catch (Exception)
  1076. {
  1077. command.Connection = new OracleConnection(DBConnectionString);
  1078. command.Connection.Open();
  1079. command.ExecuteNonQuery();
  1080. }
  1081. for (int i = 0; i < command.Parameters.Count; i++)
  1082. param[i] = command.Parameters[i].Value.ToString();
  1083. }
  1084. /// <summary>
  1085. /// 出现异常进行回滚的执行方法
  1086. /// </summary>
  1087. /// <param name="SQL"></param>
  1088. public void ExecuteSQLTran(params string[] SQL)
  1089. {
  1090. OracleTransaction tx = connection.BeginTransaction();
  1091. command = new OracleCommand();
  1092. command.Connection = connection;
  1093. command.Transaction = tx;
  1094. try
  1095. {
  1096. foreach (string sql in SQL)
  1097. {
  1098. if (!String.IsNullOrEmpty(sql))
  1099. {
  1100. command.CommandText = sql;
  1101. command.ExecuteNonQuery();
  1102. }
  1103. }
  1104. tx.Commit();
  1105. }
  1106. catch (OracleException E)
  1107. {
  1108. tx.Rollback();
  1109. throw new Exception(E.Message);
  1110. }
  1111. }
  1112. /// <summary>
  1113. /// 用于将string 的数组转换成SQL的查询内容
  1114. /// </summary>
  1115. /// <param name="Fields"></param>
  1116. /// <returns></returns>
  1117. private string AddField(string[] Fields)
  1118. {
  1119. string sql = " ";
  1120. foreach (string field in Fields)
  1121. {
  1122. sql += field + ",";
  1123. }
  1124. return sql.Substring(0, sql.Length - 1);
  1125. }
  1126. /// <summary>
  1127. /// 通过查询的内容获取到字段的描述
  1128. /// </summary>
  1129. /// <param name="field"></param>
  1130. /// <returns></returns>
  1131. private static string[] GetCaptionFromField(string field)
  1132. {
  1133. string[] caption = field.Split(',');
  1134. for (int i = 0; i < caption.Length; i++)
  1135. {
  1136. caption[i] = caption[i].Substring(0, caption[i].LastIndexOf("as")).Trim();
  1137. }
  1138. return caption;
  1139. }
  1140. /// <summary>
  1141. /// 通过查询的语句获取查询的字段
  1142. /// </summary>
  1143. /// <param name="field"></param>
  1144. /// <returns></returns>
  1145. private static string[] GetField(string field)
  1146. {
  1147. string[] fields = field.Split(',');
  1148. for (int i = 0; i < fields.Length; i++)
  1149. {
  1150. fields[i] = fields[i].Substring(fields[i].LastIndexOf("as") + 2, fields[i].Length - fields[i].LastIndexOf("as") - 2).Trim();
  1151. }
  1152. return fields;
  1153. }
  1154. public static string[] GetParamFromSQL(string SQL)
  1155. {
  1156. string[] par = SQL.Split(':');
  1157. //用来存参数的数组
  1158. StringBuilder[] addpar = new StringBuilder[par.Length - 1];
  1159. string[] param = new string[par.Length - 1];
  1160. for (int i = 0; i < par.Length - 1; i++)
  1161. {
  1162. //新建一个char类型的数组用来存储每个字节的变量
  1163. char[] c = par[i + 1].ToCharArray();
  1164. addpar[i] = new StringBuilder();
  1165. for (int j = 0; j < c.Length; j++)
  1166. {
  1167. if (c[j] != ' ' && c[j] != ',' && c[j] != ')')
  1168. {
  1169. addpar[i].Append(c[j]);
  1170. }
  1171. else
  1172. {
  1173. break;
  1174. }
  1175. }
  1176. }
  1177. for (int i = 0; i < par.Length - 1; i++)
  1178. {
  1179. param[i] = addpar[i].ToString();
  1180. }
  1181. return param;
  1182. }
  1183. private void Reconnect(OracleCommand cmd)
  1184. {
  1185. if (cmd.Connection.State == ConnectionState.Closed)
  1186. {
  1187. cmd.Connection.Open();
  1188. LogManager.DoLog("超时重连");
  1189. }
  1190. }
  1191. }
  1192. }