rsQuery.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Xml;
  7. using System.IO;
  8. namespace SysBaseLibs
  9. {
  10. public class rsQuery
  11. {
  12. public rsQuery()
  13. {
  14. this._backendTableName = "";
  15. this._QueryCriteria = "";
  16. //this._LastRecordId = 0;
  17. this._RecordsPerPage = 1;
  18. this._SortString = "";
  19. this._lFireRecordMoved = true;
  20. this._lColumnChanged = true;
  21. this._tableName = "TAble" + AppEnv.GetRandom();
  22. this.ClearEnvironment();
  23. }
  24. #region Events
  25. public event evDataOperationRequested AfterAddingNewRecord;
  26. public event evDataOperationRequested AfterSavingOfData;
  27. public event evDataOperationRequested BeforeAddingNewRecord;
  28. public event evDataOperationRequested BeforeRecordMoved;
  29. public event evDataOperationRequested BeforeSavingOfData;
  30. public event evFieldValueChanged FieldValueChanged;
  31. public event evRefreshRequested QueryOpened;
  32. public event evRefreshRequested RefreshRequested;
  33. #endregion
  34. #region Fields
  35. protected int _CurrentIndex;
  36. private string _CustomDefaultColumns;
  37. private string _CustomDefaultValues;
  38. //protected int _LastRecordId;
  39. private bool _lColumnChanged;
  40. private bool _lFireRecordMoved;
  41. protected DataTable _myDataTable;
  42. protected string _QueryCriteria;
  43. private int _RecordsPerPage;
  44. private string _SortString;
  45. protected string _sql;
  46. protected string _tableName;
  47. public evRecordMoved RecordMoved;
  48. protected string _backendTableName;
  49. protected DBConnSql _DBConn = null;
  50. private DataSet _DataSet = null;
  51. #endregion
  52. #region Properties
  53. public string AllFields
  54. {
  55. get
  56. {
  57. string text1 = "";
  58. foreach (DataColumn column1 in this.Columns)
  59. {
  60. text1 = UtilStr.AppendToStr(text1, column1.ColumnName);
  61. }
  62. return text1;
  63. }
  64. }
  65. public string DisplayColumns
  66. {
  67. get
  68. {
  69. string text1 = "";
  70. foreach (DataColumn column1 in this.Columns)
  71. {
  72. string lcStr = column1.ColumnName + ":" + column1.MaxLength;
  73. text1 = UtilStr.AppendToStr(text1, lcStr);
  74. }
  75. return text1;
  76. }
  77. }
  78. public string BackendTableName
  79. {
  80. get { return _backendTableName; }
  81. }
  82. public bool Changed
  83. {
  84. get
  85. {
  86. bool lbRetVal = false;
  87. if (this._myDataTable != null)
  88. {
  89. DataTable loTable = this._myDataTable.GetChanges();
  90. lbRetVal = loTable != null;
  91. }
  92. return lbRetVal;
  93. }
  94. }
  95. public DataColumnCollection Columns
  96. {
  97. get
  98. {
  99. return this._myDataTable.Columns;
  100. }
  101. }
  102. public DataRow CurrentRow
  103. {
  104. get
  105. {
  106. DataRow loRetVal = null;
  107. if (((this._CurrentIndex != -1) && (this._myDataTable != null)) && (this._CurrentIndex < this._myDataTable.DefaultView.Count))
  108. {
  109. loRetVal = this._myDataTable.DefaultView[this._CurrentIndex].Row;
  110. }
  111. return loRetVal;
  112. }
  113. }
  114. public DataTable CurrentTable
  115. {
  116. get
  117. {
  118. return this._myDataTable;
  119. }
  120. }
  121. public bool IsNewRow
  122. {
  123. get
  124. {
  125. bool lbRetVal = false;
  126. if (this.CurrentRow != null)
  127. {
  128. lbRetVal = this.CurrentRow.RowState == DataRowState.Added;
  129. }
  130. return lbRetVal;
  131. }
  132. }
  133. public bool IsOpened
  134. {
  135. get
  136. {
  137. return (this._myDataTable != null);
  138. }
  139. }
  140. public bool IsToFireColumnChanged
  141. {
  142. get
  143. {
  144. return this._lColumnChanged;
  145. }
  146. set
  147. {
  148. this._lColumnChanged = value;
  149. }
  150. }
  151. public bool IsToFireRecordMovedEvent
  152. {
  153. get
  154. {
  155. return this._lFireRecordMoved;
  156. }
  157. set
  158. {
  159. this._lFireRecordMoved = value;
  160. }
  161. }
  162. public object this[string pcColumnName]
  163. {
  164. get
  165. {
  166. object loRetVal = "";
  167. if (this._myDataTable.Columns.Contains(pcColumnName) && (this.CurrentRow != null))
  168. {
  169. loRetVal = this.CurrentRow[pcColumnName];
  170. }
  171. return loRetVal;
  172. }
  173. }
  174. public int PageCount
  175. {
  176. get
  177. {
  178. int liRetVal = this.RecCount / this.RecordsPerPage;
  179. if ((this.RecCount % this.RecordsPerPage) != 0)
  180. {
  181. liRetVal++;
  182. }
  183. return liRetVal;
  184. }
  185. }
  186. public int PageNo
  187. {
  188. get
  189. {
  190. int liRetVal = 1;
  191. if (this._RecordsPerPage > 0)
  192. liRetVal = (this.RecNo / this.RecordsPerPage) + 1;
  193. return liRetVal;
  194. }
  195. set
  196. {
  197. int num1 = 1;
  198. if (value > 0)
  199. {
  200. num1 = ((value - 1) * this.RecordsPerPage) + 1;
  201. if (num1 > this.RecCount)
  202. {
  203. num1 = this.RecCount;
  204. }
  205. int num2 = this.RecNo;
  206. this.Go(num1 - 1);
  207. if (this.RowIndexInPage(num2) != -1)
  208. {
  209. this.Go(num2);
  210. }
  211. }
  212. }
  213. }
  214. public string QueryCriteria
  215. {
  216. get
  217. {
  218. return this._QueryCriteria;
  219. }
  220. set
  221. {
  222. this._QueryCriteria = value;
  223. }
  224. }
  225. public int RecCount
  226. {
  227. get
  228. {
  229. if (this._myDataTable != null)
  230. {
  231. return this._myDataTable.DefaultView.Count;
  232. }
  233. return -1;
  234. }
  235. }
  236. public int RecNo
  237. {
  238. get
  239. {
  240. if ((this._CurrentIndex < 0) | (this._CurrentIndex >= this.RecCount))
  241. {
  242. return -1;
  243. }
  244. return this._CurrentIndex;
  245. }
  246. set
  247. {
  248. this.Go(value);
  249. }
  250. }
  251. public int RecordsPerPage
  252. {
  253. get
  254. {
  255. return this._RecordsPerPage;
  256. }
  257. set
  258. {
  259. this._RecordsPerPage = value;
  260. }
  261. }
  262. public DataRowCollection Rows
  263. {
  264. get
  265. {
  266. return this._myDataTable.Rows;
  267. }
  268. }
  269. public string SortString
  270. {
  271. get
  272. {
  273. return this._SortString;
  274. }
  275. }
  276. public DataSet MyDataSet
  277. {
  278. get
  279. {
  280. if (this._myDataTable != null)
  281. this._DataSet = this._myDataTable.DataSet;
  282. return this._DataSet;
  283. }
  284. set
  285. {
  286. this._DataSet = value;
  287. }
  288. }
  289. public DBConnSql DBConn
  290. {
  291. get { return _DBConn; }
  292. }
  293. #endregion
  294. #region methods
  295. // Methods
  296. public void AddPk(string pcFields)
  297. {
  298. if ((this._myDataTable != null) && !this._myDataTable.Constraints.Contains("PrimaryKey"))
  299. {
  300. Array loArr1 = UtilStr.StrToArray(pcFields);
  301. Array loArr2 = Array.CreateInstance(typeof(DataColumn), loArr1.Length);
  302. int num1 = 0;
  303. foreach (string text1 in loArr1)
  304. {
  305. loArr2.SetValue(this._myDataTable.Columns[text1], num1++);
  306. }
  307. this._myDataTable.Constraints.Add("PrimaryKey", (DataColumn[])loArr2, true);
  308. }
  309. }
  310. protected virtual void ClearEnvironment()
  311. {
  312. this._sql = "";
  313. this._CurrentIndex = -1;
  314. this._CustomDefaultColumns = "";
  315. this._CustomDefaultValues = "";
  316. }
  317. public virtual void CloneFrom(rsQuery poSource)
  318. {
  319. this._myDataTable = poSource.CurrentTable.Clone();
  320. poSource.CurrentTable.Constraints.Clear();
  321. this._myDataTable.TableName = AppEnv.GetNextDataTableName();//DBConn.GetNextDataTableName();
  322. this.QueryCriteria = poSource.QueryCriteria;
  323. }
  324. public void Close()
  325. {
  326. this.ClearEnvironment();
  327. if (this.CurrentTable != null)
  328. {
  329. //DBConn.CloseDataTable(this.CurrentTable.TableName);//songyf
  330. if (this.CurrentTable.DataSet != null)
  331. {
  332. _myDataTable.DataSet.Tables.Remove(_myDataTable);
  333. _myDataTable.Clear();
  334. _myDataTable.Constraints.Clear();
  335. _myDataTable.Columns.Clear();
  336. _myDataTable.Dispose();
  337. this._myDataTable = null;
  338. }
  339. }
  340. }
  341. protected void ColumnChanged(object sender, DataColumnChangeEventArgs e)
  342. {
  343. this.FireFieldValueChanged(e.Column.ColumnName);
  344. }
  345. public object Compute(string pcAggrFunction, string pcExpr, string pcCriteria)
  346. {
  347. object obj1 = null;
  348. try
  349. {
  350. this.Columns.Add("ABCDEFGHIJKLMNOPQRSTUVWXYZ", typeof(decimal), pcExpr);
  351. obj1 = this.CurrentTable.Compute(pcAggrFunction + "(ABCDEFGHIJKLMNOPQRSTUVWXYZ)", pcCriteria);
  352. this.Columns.Remove("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
  353. }
  354. catch (Exception exception1)
  355. {
  356. obj1 = exception1;
  357. }
  358. return obj1;
  359. }
  360. public virtual DataRow CopyRow()
  361. {
  362. DataRow row1 = this.CurrentRow;
  363. DataRow row2 = null;
  364. if (row1 != null)
  365. {
  366. row2 = this._myDataTable.NewRow();
  367. if (row2 == null)
  368. {
  369. return row2;
  370. }
  371. row2.BeginEdit();
  372. foreach (DataColumn column1 in this._myDataTable.Columns)
  373. {
  374. string text1 = column1.ColumnName;
  375. row2[text1] = row1[text1];
  376. }
  377. row2.EndEdit();
  378. this._myDataTable.Rows.Add(row2);
  379. //this.MarkNewRowRecordId(row2);
  380. }
  381. return row2;
  382. }
  383. public void CreateFrom(List<DataColumn> poDataColumns)
  384. {
  385. this._myDataTable = new DataTable(this._tableName);
  386. foreach (DataColumn column1 in poDataColumns)
  387. {
  388. this._myDataTable.Columns.Add(column1);
  389. }
  390. }
  391. public void DeleteAllRecord()
  392. {
  393. bool flag1 = this.IsToFireRecordMovedEvent;
  394. this.IsToFireRecordMovedEvent = false;
  395. while (this.RecCount > 0)
  396. {
  397. this.MoveFirst();
  398. this.DeleteCurrentRow();
  399. }
  400. this.IsToFireRecordMovedEvent = flag1;
  401. this.FireRecordMovedEvent();
  402. }
  403. public virtual DataRow DeleteCurrentRow()
  404. {
  405. DataRow row1 = this.CurrentRow;
  406. if (row1.RowState == DataRowState.Added)
  407. {
  408. this._myDataTable.Rows.Remove(row1);
  409. }
  410. else
  411. {
  412. row1.Delete();
  413. }
  414. row1 = this.CurrentRow;
  415. bool flag1 = this.IsToFireRecordMovedEvent;
  416. this.IsToFireRecordMovedEvent = false;
  417. if (row1 != null)
  418. {
  419. if (row1.RowState == DataRowState.Deleted)
  420. {
  421. row1 = this.MoveNext();
  422. }
  423. }
  424. else
  425. {
  426. row1 = this.MoveLast();
  427. }
  428. if (this._CurrentIndex >= this.RecCount)
  429. {
  430. this._CurrentIndex = -1;
  431. }
  432. this.IsToFireRecordMovedEvent = flag1;
  433. this.FireRecordMovedEvent();
  434. return row1;
  435. }
  436. public void FilterBy(string pcExpression)
  437. {
  438. this._myDataTable.DefaultView.RowFilter = pcExpression;
  439. }
  440. public bool FireAfterAddNewRecord()
  441. {
  442. bool flag1 = true;
  443. if (this.AfterAddingNewRecord != null)
  444. {
  445. flag1 = this.AfterAddingNewRecord(this);
  446. }
  447. return flag1;
  448. }
  449. public bool FireAfterSavingOfData()
  450. {
  451. bool flag1 = true;
  452. if (this.AfterSavingOfData != null)
  453. {
  454. flag1 = this.AfterSavingOfData(this);
  455. }
  456. return flag1;
  457. }
  458. public bool FireBeforeAddNewRecord()
  459. {
  460. bool flag1 = true;
  461. if (this.BeforeAddingNewRecord != null)
  462. {
  463. flag1 = this.BeforeAddingNewRecord(this);
  464. }
  465. return flag1;
  466. }
  467. public bool FireBeforeRecordMoved()
  468. {
  469. bool flag1 = true;
  470. if ((this.BeforeRecordMoved != null) && this._lFireRecordMoved)
  471. {
  472. flag1 = this.BeforeRecordMoved(this);
  473. }
  474. return flag1;
  475. }
  476. public bool FireBeforeSavingOfData()
  477. {
  478. bool flag1 = true;
  479. if (this.BeforeSavingOfData != null)
  480. {
  481. flag1 = this.BeforeSavingOfData(this);
  482. }
  483. return flag1;
  484. }
  485. public void FireFieldValueChanged(string pcColumnName)
  486. {
  487. if ((this.FieldValueChanged != null) && this.IsToFireColumnChanged)
  488. {
  489. this.FieldValueChanged(this, pcColumnName);
  490. }
  491. }
  492. protected void FireFieldValueChangedEx(rsQuery poQuery, string pcColumnName)
  493. {
  494. if ((this.FieldValueChanged != null) && this.IsToFireColumnChanged)
  495. {
  496. this.FieldValueChanged(poQuery, pcColumnName);
  497. }
  498. }
  499. public void FireQueryOpened()
  500. {
  501. if (this.QueryOpened != null)
  502. {
  503. this.QueryOpened(this);
  504. }
  505. }
  506. public void FireRecordMovedEvent()
  507. {
  508. if (this._lFireRecordMoved)
  509. {
  510. this.FireRefreshRequested();
  511. if (this.RecordMoved != null)
  512. {
  513. this.RecordMoved();
  514. }
  515. }
  516. }
  517. public void FireRefreshRequested()
  518. {
  519. if (this.RefreshRequested != null)
  520. {
  521. this.RefreshRequested(this);
  522. }
  523. }
  524. public byte[] GetBytes(string pcFieldName)
  525. {
  526. byte[] buffer1 = null;
  527. if (this.Columns.Contains(pcFieldName))
  528. {
  529. object obj1 = this.CurrentRow[pcFieldName];
  530. if ((obj1 != null) && !(obj1 is DBNull))
  531. {
  532. string text1 = this.GetString(pcFieldName);
  533. if (text1 != "")
  534. {
  535. buffer1 = Convert.FromBase64String(text1);
  536. }
  537. }
  538. }
  539. return buffer1;
  540. }
  541. public DateTime GetDateTime(string pcFieldName)
  542. {
  543. return UtilStr.StrToDt(this.GetString(pcFieldName, this.CurrentRow));
  544. }
  545. public decimal GetDecimal(string pcFieldName)
  546. {
  547. return Utils .ValD(this.GetString(pcFieldName));
  548. }
  549. public string GetFieldValues(string pcFieldNames)
  550. {
  551. return this.GetFieldValues(pcFieldNames, this.CurrentRow);
  552. }
  553. public string GetFieldValues(string pcFieldNames, DataRow poDataRow)
  554. {
  555. string text1 = "";
  556. Array array1 = UtilStr.StrToArray(pcFieldNames);
  557. foreach (string text2 in array1)
  558. {
  559. if (this.Columns.Contains(text2))
  560. {
  561. text1 = UtilStr.AddStr(text1, this.GetString(text2, poDataRow));
  562. }
  563. else
  564. {
  565. text1 = UtilStr.AddStr(text1, text2);
  566. }
  567. }
  568. return text1;
  569. }
  570. public object GetImage(string pcFieldName)
  571. {
  572. object obj1 = null;
  573. if (this.CurrentRow != null)
  574. {
  575. obj1 = Utils.BytesToImage(this.CurrentRow[pcFieldName]);
  576. }
  577. return obj1;
  578. }
  579. //public byte[] GetBytes(string pcFieldName)
  580. //{
  581. // byte[] obj1 = null;
  582. // if (this.CurrentRow != null)
  583. // {
  584. // obj1 = this.CurrentRow[pcFieldName];
  585. // }
  586. // return obj1;
  587. //}
  588. public int GetInt(string pcFieldName)
  589. {
  590. return Utils.ValI(this.GetString(pcFieldName));
  591. }
  592. public string GetString(string pcFieldName)
  593. {
  594. return this.GetString(pcFieldName, this.CurrentRow);
  595. }
  596. public bool GetBool(string pcFieldName)
  597. {
  598. return UtilStr.StrToBool(GetString(pcFieldName));
  599. }
  600. public string GetString(string pcFieldName, DataRow poDr)
  601. {
  602. string text1 = "";
  603. if (((this._myDataTable == null) || !this._myDataTable.Columns.Contains(pcFieldName)) || (poDr == null))
  604. {
  605. return text1;
  606. }
  607. if (poDr[pcFieldName] is DateTime)
  608. {
  609. try
  610. {
  611. DateTime time1 = (DateTime)poDr[pcFieldName];
  612. if (((time1.Year != 0x76c) || (time1.Month != 1)) || (time1.Day != 1))
  613. {
  614. return time1.ToString("G");
  615. }
  616. return "";
  617. }
  618. catch (Exception)
  619. {
  620. return "";
  621. }
  622. }
  623. return poDr[pcFieldName].ToString().Trim();
  624. }
  625. public string GetString(string pcFieldName, int piDecimalDigit)
  626. {
  627. string text1 = this.GetString(pcFieldName);
  628. decimal num1 = Utils.ValD(text1);
  629. if (UtilStr.UAndT(num1) != text1)
  630. {
  631. return text1;
  632. }
  633. string text2 = "0.";
  634. for (int num2 = 0; num2 < piDecimalDigit; num2++)
  635. {
  636. text2 = text2 + "0";
  637. }
  638. return num1.ToString(text2);
  639. }
  640. public DataRow Go(int recordNumber)
  641. {
  642. if ((recordNumber != this._CurrentIndex) && this.FireBeforeRecordMoved())
  643. {
  644. this._CurrentIndex = recordNumber;
  645. this.FireRecordMovedEvent();
  646. }
  647. return this.CurrentRow;
  648. }
  649. public void GoTo(DataRow dr)
  650. {
  651. if ((dr != null) && ((this.RecNo <= -1) || (this._myDataTable.DefaultView[this.RecNo].Row != dr)))
  652. {
  653. for (int num1 = 0; num1 < this.RecCount; num1++)
  654. {
  655. if (this._myDataTable.DefaultView[num1].Row == dr)
  656. {
  657. this.Go(num1);
  658. return;
  659. }
  660. }
  661. }
  662. }
  663. public void GoTo(DataRow podr, bool plFireEvent)
  664. {
  665. bool flag1 = this.IsToFireRecordMovedEvent;
  666. this.IsToFireRecordMovedEvent = plFireEvent;
  667. this.GoTo(podr);
  668. this.IsToFireRecordMovedEvent = flag1;
  669. }
  670. public bool GoToRecordByFieldsAndValues(string pcFields, string pcValues)
  671. {
  672. int num1 = this._CurrentIndex;
  673. //UtilStr.StrToArray(pcFields);
  674. //UtilStr.StrToArray(pcValues);
  675. bool flag1 = false;
  676. this._CurrentIndex = 0;
  677. while (this._CurrentIndex < this.RecCount)
  678. {
  679. if (DALibs.IsValuesMatch(this.CurrentRow, pcFields, pcValues))
  680. {
  681. flag1 = true;
  682. break;
  683. }
  684. this._CurrentIndex++;
  685. }
  686. if (flag1 && (this._CurrentIndex != num1))
  687. {
  688. this.FireRecordMovedEvent();
  689. return flag1;
  690. }
  691. this._CurrentIndex = num1;
  692. return flag1;
  693. }
  694. public DataRow GoToRecordByString(string pcStr, string pcColName)
  695. {
  696. int num1 = this._CurrentIndex;
  697. pcStr = UtilStr.UAndT(pcStr);
  698. int num2 = pcStr.Length;
  699. bool flag1 = false;
  700. if (this.Columns.Contains(pcColName))
  701. {
  702. this._CurrentIndex = 0;
  703. while (this._CurrentIndex < this.RecCount)
  704. {
  705. string text1 = UtilStr.UAndT(this.CurrentRow[pcColName]);
  706. if (text1.Length >= num2)
  707. {
  708. text1 = text1.Substring(0, num2);
  709. if (text1 == pcStr)
  710. {
  711. flag1 = true;
  712. break;
  713. }
  714. }
  715. this._CurrentIndex++;
  716. }
  717. }
  718. if (flag1)
  719. {
  720. this.FireRecordMovedEvent();
  721. }
  722. else
  723. {
  724. this._CurrentIndex = num1;
  725. }
  726. return this.CurrentRow;
  727. }
  728. public void GoToRecordInPage(int piRecordIndex)
  729. {
  730. if ((piRecordIndex >= 0) && (piRecordIndex < this.RecordsPerPage))
  731. {
  732. int num1 = ((this.PageNo - 1) * this.RecordsPerPage) + piRecordIndex;
  733. if (num1 < 0)
  734. {
  735. num1 = 0;
  736. }
  737. if (num1 >= this.RecCount)
  738. {
  739. num1 = this.RecCount - 1;
  740. }
  741. this.Go(num1);
  742. }
  743. }
  744. public DataRow Locate(object[] paValues)
  745. {
  746. DataRow row1 = this._myDataTable.Rows.Find(paValues);
  747. if (row1 != null)
  748. {
  749. this.GoTo(row1);
  750. }
  751. return row1;
  752. }
  753. public DataRow MoveFirst()
  754. {
  755. if ((this._CurrentIndex != 0) && this.FireBeforeRecordMoved())
  756. {
  757. this._CurrentIndex = 0;
  758. this.FireRecordMovedEvent();
  759. }
  760. return this.CurrentRow;
  761. }
  762. public DataRow MoveLast()
  763. {
  764. if ((this._CurrentIndex != (this._myDataTable.DefaultView.Count - 1)) && this.FireBeforeRecordMoved())
  765. {
  766. this._CurrentIndex = this._myDataTable.DefaultView.Count - 1;
  767. this.FireRecordMovedEvent();
  768. }
  769. return this.CurrentRow;
  770. }
  771. public DataRow MoveNext()
  772. {
  773. if ((this._CurrentIndex < (this._myDataTable.DefaultView.Count - 1)) && this.FireBeforeRecordMoved())
  774. {
  775. this._CurrentIndex++;
  776. this.FireRecordMovedEvent();
  777. }
  778. return this.CurrentRow;
  779. }
  780. public DataRow MovePrev()
  781. {
  782. if ((this._CurrentIndex > 0) && this.FireBeforeRecordMoved())
  783. {
  784. this._CurrentIndex--;
  785. this.FireRecordMovedEvent();
  786. }
  787. return this.CurrentRow;
  788. }
  789. /// <summary>
  790. ///
  791. /// </summary>
  792. /// <returns></returns>
  793. public bool Next()
  794. {
  795. if (this._CurrentIndex < this.RecCount - 1 && this._CurrentIndex > -1)
  796. {
  797. this._CurrentIndex++;
  798. this.FireRecordMovedEvent();
  799. return true;
  800. }
  801. return false;
  802. }
  803. public DataRow NewRowFrom(DataRow poDr)
  804. {
  805. DataRow row1 = this._myDataTable.NewRow();
  806. if (row1 != null)
  807. {
  808. row1.BeginEdit();
  809. foreach (DataColumn column1 in this.Columns)
  810. {
  811. string text1 = column1.ColumnName.Trim().ToUpper();
  812. if (poDr.Table.Columns.Contains(text1))
  813. {
  814. row1[text1] = poDr[text1];
  815. }
  816. }
  817. row1.EndEdit();
  818. }
  819. this._myDataTable.Rows.Add(row1);
  820. this.GoTo(row1);
  821. return row1;
  822. }
  823. public virtual bool Open(string pcSQLCommand, DBConnSql poDBConn)
  824. {
  825. this._backendTableName = AppEnv.GetRandom(); ;
  826. this._CurrentIndex = -1;
  827. this._sql = pcSQLCommand;
  828. this._DBConn = poDBConn;
  829. this._myDataTable = poDBConn.OpenDataTable(pcSQLCommand);
  830. if (this._myDataTable != null)
  831. {
  832. if (this._myDataTable.Rows.Count > 0)
  833. {
  834. this._CurrentIndex = 0;
  835. }
  836. this.FireQueryOpened();
  837. this.FireRecordMovedEvent();
  838. }
  839. return (this._myDataTable != null);
  840. }
  841. public virtual bool Open(DataSet poDataSet, string pcTableName, string pcSQLCommand, DBConnSql poDBConn)
  842. {
  843. this._backendTableName = pcTableName;
  844. this._CurrentIndex = -1;
  845. this._sql = pcSQLCommand;
  846. this._DBConn = poDBConn;
  847. this._myDataTable = poDBConn.OpenDataTable(poDataSet, pcTableName, pcSQLCommand);
  848. if (this._myDataTable != null)
  849. {
  850. if (this._myDataTable.Rows.Count > 0)
  851. {
  852. this._CurrentIndex = 0;
  853. }
  854. this.FireQueryOpened();
  855. this.FireRecordMovedEvent();
  856. }
  857. return (this._myDataTable != null);
  858. }
  859. public void OpenFromDataTable(DataTable poDataTable)
  860. {
  861. if (this._myDataTable != null)
  862. {
  863. this.Close();
  864. }
  865. this._myDataTable = poDataTable;
  866. if (this._myDataTable != null)
  867. {
  868. if (this._myDataTable.Rows.Count > 0)
  869. {
  870. this._CurrentIndex = 0;
  871. }
  872. this.FireQueryOpened();
  873. }
  874. }
  875. public void PageFirst()
  876. {
  877. this.PageNo = 1;
  878. }
  879. public void PageLast()
  880. {
  881. this.PageNo = this.PageCount;
  882. }
  883. public void PageNext()
  884. {
  885. this.PageNo++;
  886. }
  887. public void PagePrev()
  888. {
  889. this.PageNo--;
  890. }
  891. public bool ReQuery()
  892. {
  893. bool lbRetVal = false;
  894. if (this._sql != "")
  895. {
  896. lbRetVal = this.Open(this.MyDataSet, this.BackendTableName, this._sql, this._DBConn);
  897. }
  898. return lbRetVal;
  899. }
  900. public void RestoreAllRows()
  901. {
  902. this._myDataTable.RejectChanges();
  903. this.MoveFirst();
  904. }
  905. public bool RestoreCurrentRow()
  906. {
  907. DataRow row1 = this.CurrentRow;
  908. if (row1 != null)
  909. {
  910. if (row1.RowState == DataRowState.Added)
  911. {
  912. this.DeleteCurrentRow();
  913. }
  914. else
  915. {
  916. row1.RejectChanges();
  917. }
  918. this.FireRecordMovedEvent();
  919. }
  920. return true;
  921. }
  922. public int RowIndexInPage()
  923. {
  924. return RowIndexInPage(this.RecNo);
  925. }
  926. public int RowIndexInPage(int piRecNo)
  927. {
  928. int num1 = -1;
  929. int num2 = (this.PageNo - 1) * this.RecordsPerPage;
  930. int num3 = (this.PageNo * this.RecordsPerPage) - 1;
  931. if (num3 >= this.RecCount)
  932. {
  933. num3 = this.RecCount - 1;
  934. }
  935. if ((piRecNo >= num2) && (piRecNo <= num3))
  936. {
  937. num1 = piRecNo - num2;
  938. }
  939. return num1;
  940. }
  941. public virtual void SetBytes(string pcColName, byte[] poBytes)
  942. {
  943. if (this.Columns.Contains(pcColName) && (this.CurrentRow != null))
  944. {
  945. this.CurrentRow.BeginEdit();
  946. if ((poBytes == null) || (0 != 0))
  947. {
  948. this.CurrentRow[pcColName] = DBNull.Value;
  949. }
  950. else
  951. {
  952. string text1 = Convert.ToBase64String(poBytes, 0, poBytes.Length);
  953. this.CurrentRow[pcColName] = text1;
  954. }
  955. this.CurrentRow.EndEdit();
  956. }
  957. }
  958. public virtual void SetField(string pcColName, string pcValue)
  959. {
  960. this.SetField(pcColName, pcValue, true);
  961. }
  962. public virtual void SetField(string pcColName, string pcValue, bool plFireFieldChangedEvent)
  963. {
  964. pcColName = UtilStr.UAndT(pcColName);
  965. DataRow row1 = this.CurrentRow;
  966. if (row1 != null)
  967. {
  968. string text1 = row1[pcColName].ToString().Trim();
  969. bool flag1 = false;
  970. if (!flag1 || (row1[pcColName] == DBNull.Value))
  971. {
  972. bool flag2 = this.IsToFireColumnChanged;
  973. this.IsToFireColumnChanged = plFireFieldChangedEvent;
  974. this.SetField(pcColName, pcValue, row1);
  975. if (this.CurrentRow != row1)
  976. {
  977. bool flag3 = this.IsToFireRecordMovedEvent;
  978. this.IsToFireRecordMovedEvent = false;
  979. this.GoTo(row1);
  980. this.IsToFireRecordMovedEvent = flag3;
  981. }
  982. this.FireFieldValueChanged(pcColName);
  983. this.IsToFireColumnChanged = flag2;
  984. }
  985. }
  986. }
  987. public virtual void SetField(string pcColName, string pcValue, DataRow poDataRow)
  988. {
  989. if (poDataRow.Table.Columns.Contains(pcColName))
  990. {
  991. DataColumn column1 = poDataRow.Table.Columns[pcColName];
  992. if ((column1.MaxLength >= 0) && (column1.MaxLength < pcValue.Length))
  993. {
  994. pcValue = pcValue.Substring(0, column1.MaxLength);
  995. }
  996. string text1 = this.GetString(pcColName, poDataRow);
  997. poDataRow.BeginEdit();
  998. poDataRow[pcColName] = pcValue;
  999. poDataRow.EndEdit();
  1000. }
  1001. }
  1002. public void SetCustomDefault(string pcColumns, string pcValues)
  1003. {
  1004. this._CustomDefaultColumns = pcColumns;
  1005. this._CustomDefaultValues = pcValues;
  1006. }
  1007. public void SortBy(string pcSort)
  1008. {
  1009. try
  1010. {
  1011. if (this._myDataTable != null)
  1012. {
  1013. int num1 = -1;
  1014. this._SortString = pcSort;
  1015. DataRow row1 = this.CurrentRow;
  1016. this._myDataTable.DefaultView.Sort = pcSort;
  1017. if (row1 != null)
  1018. {
  1019. this.GoTo(row1, false);
  1020. num1 = this.RecNo;
  1021. }
  1022. DataTable table1 = this._myDataTable.Copy();
  1023. this._myDataTable.Rows.Clear();
  1024. this._myDataTable.DefaultView.Sort = "";
  1025. DataView view1 = new DataView(table1, "", pcSort, DataViewRowState.CurrentRows);
  1026. foreach (DataRowView view2 in view1)
  1027. {
  1028. this._myDataTable.ImportRow(view2.Row);
  1029. }
  1030. view1 = new DataView(table1, "", pcSort, DataViewRowState.Deleted);
  1031. foreach (DataRowView view3 in view1)
  1032. {
  1033. this._myDataTable.ImportRow(view3.Row);
  1034. }
  1035. this._CurrentIndex = num1;
  1036. this.FireRefreshRequested();
  1037. }
  1038. }
  1039. catch (Exception)
  1040. {
  1041. }
  1042. }
  1043. public void SortBy(string pcColumnId, bool plAscending)
  1044. {
  1045. string text1 = pcColumnId + (plAscending ? " asc" : " desc");
  1046. this.SortBy(text1);
  1047. }
  1048. public void ToXML()
  1049. {
  1050. ToXML(this.AllFields);
  1051. }
  1052. public void ToXML(string pcCols)
  1053. {
  1054. if (this.IsOpened)
  1055. {
  1056. Array array1 = UtilStr.StrToArray(pcCols);
  1057. XmlTextWriter writer1 = new XmlTextWriter(@"c:\result.xml", Encoding.UTF8);
  1058. writer1.WriteStartDocument(true);
  1059. writer1.WriteStartElement("Data");
  1060. this._CurrentIndex = 0;
  1061. while (this._CurrentIndex < this.RecCount)
  1062. {
  1063. string text1 = "Record";
  1064. writer1.WriteStartElement(text1);
  1065. for (int num1 = 0; num1 < array1.Length; num1++)
  1066. {
  1067. string text2 = array1.GetValue(num1).ToString();
  1068. writer1.WriteElementString(text2, this.GetString(text2));
  1069. }
  1070. writer1.WriteEndElement();
  1071. this._CurrentIndex++;
  1072. }
  1073. writer1.WriteEndElement();
  1074. writer1.WriteEndDocument();
  1075. writer1.Flush();
  1076. writer1.Close();
  1077. }
  1078. }
  1079. #endregion
  1080. }
  1081. }