12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Data;
- using System.Drawing;
- using System.Xml;
- using System.IO;
- namespace SysBaseLibs
- {
- public class rsQuery
- {
- public rsQuery()
- {
- this._backendTableName = "";
- this._QueryCriteria = "";
- //this._LastRecordId = 0;
- this._RecordsPerPage = 1;
- this._SortString = "";
- this._lFireRecordMoved = true;
- this._lColumnChanged = true;
- this._tableName = "TAble" + AppEnv.GetRandom();
- this.ClearEnvironment();
- }
- #region Events
- public event evDataOperationRequested AfterAddingNewRecord;
- public event evDataOperationRequested AfterSavingOfData;
- public event evDataOperationRequested BeforeAddingNewRecord;
- public event evDataOperationRequested BeforeRecordMoved;
- public event evDataOperationRequested BeforeSavingOfData;
- public event evFieldValueChanged FieldValueChanged;
- public event evRefreshRequested QueryOpened;
- public event evRefreshRequested RefreshRequested;
- #endregion
- #region Fields
- protected int _CurrentIndex;
- private string _CustomDefaultColumns;
- private string _CustomDefaultValues;
- //protected int _LastRecordId;
- private bool _lColumnChanged;
- private bool _lFireRecordMoved;
- protected DataTable _myDataTable;
- protected string _QueryCriteria;
- private int _RecordsPerPage;
- private string _SortString;
- protected string _sql;
- protected string _tableName;
- public evRecordMoved RecordMoved;
- protected string _backendTableName;
- protected DBConnSql _DBConn = null;
- private DataSet _DataSet = null;
- #endregion
- #region Properties
- public string AllFields
- {
- get
- {
- string text1 = "";
- foreach (DataColumn column1 in this.Columns)
- {
- text1 = UtilStr.AppendToStr(text1, column1.ColumnName);
- }
- return text1;
- }
- }
- public string DisplayColumns
- {
- get
- {
- string text1 = "";
- foreach (DataColumn column1 in this.Columns)
- {
- string lcStr = column1.ColumnName + ":" + column1.MaxLength;
- text1 = UtilStr.AppendToStr(text1, lcStr);
- }
- return text1;
- }
- }
- public string BackendTableName
- {
- get { return _backendTableName; }
- }
- public bool Changed
- {
- get
- {
- bool lbRetVal = false;
- if (this._myDataTable != null)
- {
- DataTable loTable = this._myDataTable.GetChanges();
- lbRetVal = loTable != null;
- }
- return lbRetVal;
- }
- }
- public DataColumnCollection Columns
- {
- get
- {
- return this._myDataTable.Columns;
- }
- }
- public DataRow CurrentRow
- {
- get
- {
- DataRow loRetVal = null;
- if (((this._CurrentIndex != -1) && (this._myDataTable != null)) && (this._CurrentIndex < this._myDataTable.DefaultView.Count))
- {
- loRetVal = this._myDataTable.DefaultView[this._CurrentIndex].Row;
- }
- return loRetVal;
- }
- }
- public DataTable CurrentTable
- {
- get
- {
- return this._myDataTable;
- }
- }
- public bool IsNewRow
- {
- get
- {
- bool lbRetVal = false;
- if (this.CurrentRow != null)
- {
- lbRetVal = this.CurrentRow.RowState == DataRowState.Added;
- }
- return lbRetVal;
- }
- }
- public bool IsOpened
- {
- get
- {
- return (this._myDataTable != null);
- }
- }
- public bool IsToFireColumnChanged
- {
- get
- {
- return this._lColumnChanged;
- }
- set
- {
- this._lColumnChanged = value;
- }
- }
- public bool IsToFireRecordMovedEvent
- {
- get
- {
- return this._lFireRecordMoved;
- }
- set
- {
- this._lFireRecordMoved = value;
- }
- }
- public object this[string pcColumnName]
- {
- get
- {
- object loRetVal = "";
- if (this._myDataTable.Columns.Contains(pcColumnName) && (this.CurrentRow != null))
- {
- loRetVal = this.CurrentRow[pcColumnName];
- }
- return loRetVal;
- }
- }
- public int PageCount
- {
- get
- {
- int liRetVal = this.RecCount / this.RecordsPerPage;
- if ((this.RecCount % this.RecordsPerPage) != 0)
- {
- liRetVal++;
- }
- return liRetVal;
- }
- }
- public int PageNo
- {
- get
- {
- int liRetVal = 1;
- if (this._RecordsPerPage > 0)
- liRetVal = (this.RecNo / this.RecordsPerPage) + 1;
- return liRetVal;
- }
- set
- {
- int num1 = 1;
- if (value > 0)
- {
- num1 = ((value - 1) * this.RecordsPerPage) + 1;
- if (num1 > this.RecCount)
- {
- num1 = this.RecCount;
- }
- int num2 = this.RecNo;
- this.Go(num1 - 1);
- if (this.RowIndexInPage(num2) != -1)
- {
- this.Go(num2);
- }
- }
- }
- }
- public string QueryCriteria
- {
- get
- {
- return this._QueryCriteria;
- }
- set
- {
- this._QueryCriteria = value;
- }
- }
- public int RecCount
- {
- get
- {
- if (this._myDataTable != null)
- {
- return this._myDataTable.DefaultView.Count;
- }
- return -1;
- }
- }
- public int RecNo
- {
- get
- {
- if ((this._CurrentIndex < 0) | (this._CurrentIndex >= this.RecCount))
- {
- return -1;
- }
- return this._CurrentIndex;
- }
- set
- {
- this.Go(value);
- }
- }
- public int RecordsPerPage
- {
- get
- {
- return this._RecordsPerPage;
- }
- set
- {
- this._RecordsPerPage = value;
- }
- }
- public DataRowCollection Rows
- {
- get
- {
- return this._myDataTable.Rows;
- }
- }
- public string SortString
- {
- get
- {
- return this._SortString;
- }
- }
- public DataSet MyDataSet
- {
- get
- {
- if (this._myDataTable != null)
- this._DataSet = this._myDataTable.DataSet;
- return this._DataSet;
- }
- set
- {
- this._DataSet = value;
- }
- }
- public DBConnSql DBConn
- {
- get { return _DBConn; }
- }
- #endregion
- #region methods
- // Methods
- public void AddPk(string pcFields)
- {
- if ((this._myDataTable != null) && !this._myDataTable.Constraints.Contains("PrimaryKey"))
- {
- Array loArr1 = UtilStr.StrToArray(pcFields);
- Array loArr2 = Array.CreateInstance(typeof(DataColumn), loArr1.Length);
- int num1 = 0;
- foreach (string text1 in loArr1)
- {
- loArr2.SetValue(this._myDataTable.Columns[text1], num1++);
- }
- this._myDataTable.Constraints.Add("PrimaryKey", (DataColumn[])loArr2, true);
- }
- }
- protected virtual void ClearEnvironment()
- {
- this._sql = "";
- this._CurrentIndex = -1;
- this._CustomDefaultColumns = "";
- this._CustomDefaultValues = "";
- }
- public virtual void CloneFrom(rsQuery poSource)
- {
- this._myDataTable = poSource.CurrentTable.Clone();
- poSource.CurrentTable.Constraints.Clear();
- this._myDataTable.TableName = AppEnv.GetNextDataTableName();//DBConn.GetNextDataTableName();
- this.QueryCriteria = poSource.QueryCriteria;
- }
- public void Close()
- {
- this.ClearEnvironment();
- if (this.CurrentTable != null)
- {
- //DBConn.CloseDataTable(this.CurrentTable.TableName);//songyf
- if (this.CurrentTable.DataSet != null)
- {
- _myDataTable.DataSet.Tables.Remove(_myDataTable);
- _myDataTable.Clear();
- _myDataTable.Constraints.Clear();
- _myDataTable.Columns.Clear();
- _myDataTable.Dispose();
- this._myDataTable = null;
- }
- }
- }
- protected void ColumnChanged(object sender, DataColumnChangeEventArgs e)
- {
- this.FireFieldValueChanged(e.Column.ColumnName);
- }
- public object Compute(string pcAggrFunction, string pcExpr, string pcCriteria)
- {
- object obj1 = null;
- try
- {
- this.Columns.Add("ABCDEFGHIJKLMNOPQRSTUVWXYZ", typeof(decimal), pcExpr);
- obj1 = this.CurrentTable.Compute(pcAggrFunction + "(ABCDEFGHIJKLMNOPQRSTUVWXYZ)", pcCriteria);
- this.Columns.Remove("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
- }
- catch (Exception exception1)
- {
- obj1 = exception1;
- }
- return obj1;
- }
- public virtual DataRow CopyRow()
- {
- DataRow row1 = this.CurrentRow;
- DataRow row2 = null;
- if (row1 != null)
- {
- row2 = this._myDataTable.NewRow();
- if (row2 == null)
- {
- return row2;
- }
- row2.BeginEdit();
- foreach (DataColumn column1 in this._myDataTable.Columns)
- {
- string text1 = column1.ColumnName;
- row2[text1] = row1[text1];
- }
- row2.EndEdit();
- this._myDataTable.Rows.Add(row2);
- //this.MarkNewRowRecordId(row2);
- }
- return row2;
- }
- public void CreateFrom(List<DataColumn> poDataColumns)
- {
- this._myDataTable = new DataTable(this._tableName);
- foreach (DataColumn column1 in poDataColumns)
- {
- this._myDataTable.Columns.Add(column1);
- }
- }
- public void DeleteAllRecord()
- {
- bool flag1 = this.IsToFireRecordMovedEvent;
- this.IsToFireRecordMovedEvent = false;
- while (this.RecCount > 0)
- {
- this.MoveFirst();
- this.DeleteCurrentRow();
- }
- this.IsToFireRecordMovedEvent = flag1;
- this.FireRecordMovedEvent();
- }
- public virtual DataRow DeleteCurrentRow()
- {
- DataRow row1 = this.CurrentRow;
- if (row1.RowState == DataRowState.Added)
- {
- this._myDataTable.Rows.Remove(row1);
- }
- else
- {
- row1.Delete();
- }
- row1 = this.CurrentRow;
- bool flag1 = this.IsToFireRecordMovedEvent;
- this.IsToFireRecordMovedEvent = false;
- if (row1 != null)
- {
- if (row1.RowState == DataRowState.Deleted)
- {
- row1 = this.MoveNext();
- }
- }
- else
- {
- row1 = this.MoveLast();
- }
- if (this._CurrentIndex >= this.RecCount)
- {
- this._CurrentIndex = -1;
- }
- this.IsToFireRecordMovedEvent = flag1;
- this.FireRecordMovedEvent();
- return row1;
- }
- public void FilterBy(string pcExpression)
- {
- this._myDataTable.DefaultView.RowFilter = pcExpression;
- }
- public bool FireAfterAddNewRecord()
- {
- bool flag1 = true;
- if (this.AfterAddingNewRecord != null)
- {
- flag1 = this.AfterAddingNewRecord(this);
- }
- return flag1;
- }
- public bool FireAfterSavingOfData()
- {
- bool flag1 = true;
- if (this.AfterSavingOfData != null)
- {
- flag1 = this.AfterSavingOfData(this);
- }
- return flag1;
- }
- public bool FireBeforeAddNewRecord()
- {
- bool flag1 = true;
- if (this.BeforeAddingNewRecord != null)
- {
- flag1 = this.BeforeAddingNewRecord(this);
- }
- return flag1;
- }
- public bool FireBeforeRecordMoved()
- {
- bool flag1 = true;
- if ((this.BeforeRecordMoved != null) && this._lFireRecordMoved)
- {
- flag1 = this.BeforeRecordMoved(this);
- }
- return flag1;
- }
- public bool FireBeforeSavingOfData()
- {
- bool flag1 = true;
- if (this.BeforeSavingOfData != null)
- {
- flag1 = this.BeforeSavingOfData(this);
- }
- return flag1;
- }
- public void FireFieldValueChanged(string pcColumnName)
- {
- if ((this.FieldValueChanged != null) && this.IsToFireColumnChanged)
- {
- this.FieldValueChanged(this, pcColumnName);
- }
- }
- protected void FireFieldValueChangedEx(rsQuery poQuery, string pcColumnName)
- {
- if ((this.FieldValueChanged != null) && this.IsToFireColumnChanged)
- {
- this.FieldValueChanged(poQuery, pcColumnName);
- }
- }
- public void FireQueryOpened()
- {
- if (this.QueryOpened != null)
- {
- this.QueryOpened(this);
- }
- }
- public void FireRecordMovedEvent()
- {
- if (this._lFireRecordMoved)
- {
- this.FireRefreshRequested();
- if (this.RecordMoved != null)
- {
- this.RecordMoved();
- }
- }
- }
- public void FireRefreshRequested()
- {
- if (this.RefreshRequested != null)
- {
- this.RefreshRequested(this);
- }
- }
- public byte[] GetBytes(string pcFieldName)
- {
- byte[] buffer1 = null;
- if (this.Columns.Contains(pcFieldName))
- {
- object obj1 = this.CurrentRow[pcFieldName];
- if ((obj1 != null) && !(obj1 is DBNull))
- {
- string text1 = this.GetString(pcFieldName);
- if (text1 != "")
- {
- buffer1 = Convert.FromBase64String(text1);
- }
- }
- }
- return buffer1;
- }
- public DateTime GetDateTime(string pcFieldName)
- {
- return UtilStr.StrToDt(this.GetString(pcFieldName, this.CurrentRow));
- }
- public decimal GetDecimal(string pcFieldName)
- {
- return Utils .ValD(this.GetString(pcFieldName));
- }
- public string GetFieldValues(string pcFieldNames)
- {
- return this.GetFieldValues(pcFieldNames, this.CurrentRow);
- }
- public string GetFieldValues(string pcFieldNames, DataRow poDataRow)
- {
- string text1 = "";
- Array array1 = UtilStr.StrToArray(pcFieldNames);
- foreach (string text2 in array1)
- {
- if (this.Columns.Contains(text2))
- {
- text1 = UtilStr.AddStr(text1, this.GetString(text2, poDataRow));
- }
- else
- {
- text1 = UtilStr.AddStr(text1, text2);
- }
- }
- return text1;
- }
- public object GetImage(string pcFieldName)
- {
- object obj1 = null;
- if (this.CurrentRow != null)
- {
- obj1 = Utils.BytesToImage(this.CurrentRow[pcFieldName]);
- }
- return obj1;
- }
- //public byte[] GetBytes(string pcFieldName)
- //{
- // byte[] obj1 = null;
- // if (this.CurrentRow != null)
- // {
- // obj1 = this.CurrentRow[pcFieldName];
- // }
- // return obj1;
- //}
- public int GetInt(string pcFieldName)
- {
- return Utils.ValI(this.GetString(pcFieldName));
- }
- public string GetString(string pcFieldName)
- {
- return this.GetString(pcFieldName, this.CurrentRow);
- }
- public bool GetBool(string pcFieldName)
- {
- return UtilStr.StrToBool(GetString(pcFieldName));
- }
- public string GetString(string pcFieldName, DataRow poDr)
- {
- string text1 = "";
- if (((this._myDataTable == null) || !this._myDataTable.Columns.Contains(pcFieldName)) || (poDr == null))
- {
- return text1;
- }
- if (poDr[pcFieldName] is DateTime)
- {
- try
- {
- DateTime time1 = (DateTime)poDr[pcFieldName];
- if (((time1.Year != 0x76c) || (time1.Month != 1)) || (time1.Day != 1))
- {
- return time1.ToString("G");
- }
- return "";
- }
- catch (Exception)
- {
- return "";
- }
- }
- return poDr[pcFieldName].ToString().Trim();
- }
- public string GetString(string pcFieldName, int piDecimalDigit)
- {
- string text1 = this.GetString(pcFieldName);
- decimal num1 = Utils.ValD(text1);
- if (UtilStr.UAndT(num1) != text1)
- {
- return text1;
- }
- string text2 = "0.";
- for (int num2 = 0; num2 < piDecimalDigit; num2++)
- {
- text2 = text2 + "0";
- }
- return num1.ToString(text2);
- }
- public DataRow Go(int recordNumber)
- {
- if ((recordNumber != this._CurrentIndex) && this.FireBeforeRecordMoved())
- {
- this._CurrentIndex = recordNumber;
- this.FireRecordMovedEvent();
- }
- return this.CurrentRow;
- }
- public void GoTo(DataRow dr)
- {
- if ((dr != null) && ((this.RecNo <= -1) || (this._myDataTable.DefaultView[this.RecNo].Row != dr)))
- {
- for (int num1 = 0; num1 < this.RecCount; num1++)
- {
- if (this._myDataTable.DefaultView[num1].Row == dr)
- {
- this.Go(num1);
- return;
- }
- }
- }
- }
- public void GoTo(DataRow podr, bool plFireEvent)
- {
- bool flag1 = this.IsToFireRecordMovedEvent;
- this.IsToFireRecordMovedEvent = plFireEvent;
- this.GoTo(podr);
- this.IsToFireRecordMovedEvent = flag1;
- }
- public bool GoToRecordByFieldsAndValues(string pcFields, string pcValues)
- {
- int num1 = this._CurrentIndex;
- //UtilStr.StrToArray(pcFields);
- //UtilStr.StrToArray(pcValues);
- bool flag1 = false;
- this._CurrentIndex = 0;
- while (this._CurrentIndex < this.RecCount)
- {
- if (DALibs.IsValuesMatch(this.CurrentRow, pcFields, pcValues))
- {
- flag1 = true;
- break;
- }
- this._CurrentIndex++;
- }
- if (flag1 && (this._CurrentIndex != num1))
- {
- this.FireRecordMovedEvent();
- return flag1;
- }
- this._CurrentIndex = num1;
- return flag1;
- }
- public DataRow GoToRecordByString(string pcStr, string pcColName)
- {
- int num1 = this._CurrentIndex;
- pcStr = UtilStr.UAndT(pcStr);
- int num2 = pcStr.Length;
- bool flag1 = false;
- if (this.Columns.Contains(pcColName))
- {
- this._CurrentIndex = 0;
- while (this._CurrentIndex < this.RecCount)
- {
- string text1 = UtilStr.UAndT(this.CurrentRow[pcColName]);
- if (text1.Length >= num2)
- {
- text1 = text1.Substring(0, num2);
- if (text1 == pcStr)
- {
- flag1 = true;
- break;
- }
- }
- this._CurrentIndex++;
- }
- }
- if (flag1)
- {
- this.FireRecordMovedEvent();
- }
- else
- {
- this._CurrentIndex = num1;
- }
- return this.CurrentRow;
- }
- public void GoToRecordInPage(int piRecordIndex)
- {
- if ((piRecordIndex >= 0) && (piRecordIndex < this.RecordsPerPage))
- {
- int num1 = ((this.PageNo - 1) * this.RecordsPerPage) + piRecordIndex;
- if (num1 < 0)
- {
- num1 = 0;
- }
- if (num1 >= this.RecCount)
- {
- num1 = this.RecCount - 1;
- }
- this.Go(num1);
- }
- }
-
- public DataRow Locate(object[] paValues)
- {
- DataRow row1 = this._myDataTable.Rows.Find(paValues);
- if (row1 != null)
- {
- this.GoTo(row1);
- }
- return row1;
- }
- public DataRow MoveFirst()
- {
- if ((this._CurrentIndex != 0) && this.FireBeforeRecordMoved())
- {
- this._CurrentIndex = 0;
- this.FireRecordMovedEvent();
- }
- return this.CurrentRow;
- }
- public DataRow MoveLast()
- {
- if ((this._CurrentIndex != (this._myDataTable.DefaultView.Count - 1)) && this.FireBeforeRecordMoved())
- {
- this._CurrentIndex = this._myDataTable.DefaultView.Count - 1;
- this.FireRecordMovedEvent();
- }
- return this.CurrentRow;
- }
- public DataRow MoveNext()
- {
- if ((this._CurrentIndex < (this._myDataTable.DefaultView.Count - 1)) && this.FireBeforeRecordMoved())
- {
- this._CurrentIndex++;
- this.FireRecordMovedEvent();
- }
- return this.CurrentRow;
- }
- public DataRow MovePrev()
- {
- if ((this._CurrentIndex > 0) && this.FireBeforeRecordMoved())
- {
- this._CurrentIndex--;
- this.FireRecordMovedEvent();
- }
- return this.CurrentRow;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public bool Next()
- {
- if (this._CurrentIndex < this.RecCount - 1 && this._CurrentIndex > -1)
- {
- this._CurrentIndex++;
- this.FireRecordMovedEvent();
- return true;
- }
- return false;
- }
- public DataRow NewRowFrom(DataRow poDr)
- {
- DataRow row1 = this._myDataTable.NewRow();
- if (row1 != null)
- {
- row1.BeginEdit();
- foreach (DataColumn column1 in this.Columns)
- {
- string text1 = column1.ColumnName.Trim().ToUpper();
- if (poDr.Table.Columns.Contains(text1))
- {
- row1[text1] = poDr[text1];
- }
- }
- row1.EndEdit();
- }
- this._myDataTable.Rows.Add(row1);
- this.GoTo(row1);
- return row1;
- }
- public virtual bool Open(string pcSQLCommand, DBConnSql poDBConn)
- {
- this._backendTableName = AppEnv.GetRandom(); ;
- this._CurrentIndex = -1;
- this._sql = pcSQLCommand;
- this._DBConn = poDBConn;
- this._myDataTable = poDBConn.OpenDataTable(pcSQLCommand);
- if (this._myDataTable != null)
- {
- if (this._myDataTable.Rows.Count > 0)
- {
- this._CurrentIndex = 0;
- }
- this.FireQueryOpened();
- this.FireRecordMovedEvent();
- }
- return (this._myDataTable != null);
- }
- public virtual bool Open(DataSet poDataSet, string pcTableName, string pcSQLCommand, DBConnSql poDBConn)
- {
- this._backendTableName = pcTableName;
- this._CurrentIndex = -1;
- this._sql = pcSQLCommand;
- this._DBConn = poDBConn;
- this._myDataTable = poDBConn.OpenDataTable(poDataSet, pcTableName, pcSQLCommand);
- if (this._myDataTable != null)
- {
- if (this._myDataTable.Rows.Count > 0)
- {
- this._CurrentIndex = 0;
- }
- this.FireQueryOpened();
- this.FireRecordMovedEvent();
- }
- return (this._myDataTable != null);
- }
- public void OpenFromDataTable(DataTable poDataTable)
- {
- if (this._myDataTable != null)
- {
- this.Close();
- }
- this._myDataTable = poDataTable;
- if (this._myDataTable != null)
- {
- if (this._myDataTable.Rows.Count > 0)
- {
- this._CurrentIndex = 0;
- }
- this.FireQueryOpened();
- }
- }
- public void PageFirst()
- {
- this.PageNo = 1;
- }
- public void PageLast()
- {
- this.PageNo = this.PageCount;
- }
- public void PageNext()
- {
- this.PageNo++;
- }
- public void PagePrev()
- {
- this.PageNo--;
- }
- public bool ReQuery()
- {
- bool lbRetVal = false;
- if (this._sql != "")
- {
- lbRetVal = this.Open(this.MyDataSet, this.BackendTableName, this._sql, this._DBConn);
- }
- return lbRetVal;
- }
- public void RestoreAllRows()
- {
- this._myDataTable.RejectChanges();
- this.MoveFirst();
- }
- public bool RestoreCurrentRow()
- {
- DataRow row1 = this.CurrentRow;
- if (row1 != null)
- {
- if (row1.RowState == DataRowState.Added)
- {
- this.DeleteCurrentRow();
- }
- else
- {
- row1.RejectChanges();
- }
- this.FireRecordMovedEvent();
- }
- return true;
- }
- public int RowIndexInPage()
- {
- return RowIndexInPage(this.RecNo);
- }
- public int RowIndexInPage(int piRecNo)
- {
- int num1 = -1;
- int num2 = (this.PageNo - 1) * this.RecordsPerPage;
- int num3 = (this.PageNo * this.RecordsPerPage) - 1;
- if (num3 >= this.RecCount)
- {
- num3 = this.RecCount - 1;
- }
- if ((piRecNo >= num2) && (piRecNo <= num3))
- {
- num1 = piRecNo - num2;
- }
- return num1;
- }
- public virtual void SetBytes(string pcColName, byte[] poBytes)
- {
- if (this.Columns.Contains(pcColName) && (this.CurrentRow != null))
- {
- this.CurrentRow.BeginEdit();
- if ((poBytes == null) || (0 != 0))
- {
- this.CurrentRow[pcColName] = DBNull.Value;
- }
- else
- {
- string text1 = Convert.ToBase64String(poBytes, 0, poBytes.Length);
- this.CurrentRow[pcColName] = text1;
- }
- this.CurrentRow.EndEdit();
- }
- }
- public virtual void SetField(string pcColName, string pcValue)
- {
- this.SetField(pcColName, pcValue, true);
- }
- public virtual void SetField(string pcColName, string pcValue, bool plFireFieldChangedEvent)
- {
- pcColName = UtilStr.UAndT(pcColName);
- DataRow row1 = this.CurrentRow;
- if (row1 != null)
- {
- string text1 = row1[pcColName].ToString().Trim();
- bool flag1 = false;
- if (!flag1 || (row1[pcColName] == DBNull.Value))
- {
- bool flag2 = this.IsToFireColumnChanged;
- this.IsToFireColumnChanged = plFireFieldChangedEvent;
- this.SetField(pcColName, pcValue, row1);
- if (this.CurrentRow != row1)
- {
- bool flag3 = this.IsToFireRecordMovedEvent;
- this.IsToFireRecordMovedEvent = false;
- this.GoTo(row1);
- this.IsToFireRecordMovedEvent = flag3;
- }
- this.FireFieldValueChanged(pcColName);
- this.IsToFireColumnChanged = flag2;
- }
- }
- }
- public virtual void SetField(string pcColName, string pcValue, DataRow poDataRow)
- {
- if (poDataRow.Table.Columns.Contains(pcColName))
- {
- DataColumn column1 = poDataRow.Table.Columns[pcColName];
- if ((column1.MaxLength >= 0) && (column1.MaxLength < pcValue.Length))
- {
- pcValue = pcValue.Substring(0, column1.MaxLength);
- }
- string text1 = this.GetString(pcColName, poDataRow);
- poDataRow.BeginEdit();
- poDataRow[pcColName] = pcValue;
- poDataRow.EndEdit();
- }
- }
- public void SetCustomDefault(string pcColumns, string pcValues)
- {
- this._CustomDefaultColumns = pcColumns;
- this._CustomDefaultValues = pcValues;
- }
- public void SortBy(string pcSort)
- {
- try
- {
- if (this._myDataTable != null)
- {
- int num1 = -1;
- this._SortString = pcSort;
- DataRow row1 = this.CurrentRow;
- this._myDataTable.DefaultView.Sort = pcSort;
- if (row1 != null)
- {
- this.GoTo(row1, false);
- num1 = this.RecNo;
- }
- DataTable table1 = this._myDataTable.Copy();
- this._myDataTable.Rows.Clear();
- this._myDataTable.DefaultView.Sort = "";
- DataView view1 = new DataView(table1, "", pcSort, DataViewRowState.CurrentRows);
- foreach (DataRowView view2 in view1)
- {
- this._myDataTable.ImportRow(view2.Row);
- }
- view1 = new DataView(table1, "", pcSort, DataViewRowState.Deleted);
- foreach (DataRowView view3 in view1)
- {
- this._myDataTable.ImportRow(view3.Row);
- }
- this._CurrentIndex = num1;
- this.FireRefreshRequested();
- }
- }
- catch (Exception)
- {
- }
- }
- public void SortBy(string pcColumnId, bool plAscending)
- {
- string text1 = pcColumnId + (plAscending ? " asc" : " desc");
- this.SortBy(text1);
- }
- public void ToXML()
- {
- ToXML(this.AllFields);
- }
- public void ToXML(string pcCols)
- {
- if (this.IsOpened)
- {
- Array array1 = UtilStr.StrToArray(pcCols);
- XmlTextWriter writer1 = new XmlTextWriter(@"c:\result.xml", Encoding.UTF8);
- writer1.WriteStartDocument(true);
- writer1.WriteStartElement("Data");
- this._CurrentIndex = 0;
- while (this._CurrentIndex < this.RecCount)
- {
- string text1 = "Record";
- writer1.WriteStartElement(text1);
- for (int num1 = 0; num1 < array1.Length; num1++)
- {
- string text2 = array1.GetValue(num1).ToString();
- writer1.WriteElementString(text2, this.GetString(text2));
- }
- writer1.WriteEndElement();
- this._CurrentIndex++;
- }
- writer1.WriteEndElement();
- writer1.WriteEndDocument();
- writer1.Flush();
- writer1.Close();
- }
- }
- #endregion
- }
- }
|