using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Xml; using IwbZero.ToolCommon.FileHelpers; using IwbZero.ToolCommon.StringModel; namespace IwbZero.IwbDataQuery { public partial class IwbQuery { protected delegate void EvDictionaryChanged(Dictionary dictionary); public IwbQuery() { ClearEnvironment(); //DictionaryChanged += SaveToXml; } public IwbQuery(string id) : this() { Id = id; } public IwbQuery(string id,string filePath):this(id) { FilePath = filePath; } public string Id { get; } private string _filePath; public string FilePath { get => GetFilePath(Id); set => _filePath = value; } private string GetFilePath(string id) { return _filePath.IsEmpty() ? Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resource/Data/IwbQuery/{id}.iwbx") : _filePath; } protected string _backendTableName = ""; protected string TableName { get; set; } private DataTable _myDataTable; protected DataTable MyDataTable { get => _myDataTable ?? GetDataTable(FilePath); set=>_myDataTable=value; } private DataTable GetDataTable(string filePath) { return filePath.CXmlFileToDataTable(); } private Hashtable Columns { get; set; } protected int CurrentIndex { get; set; } private string CustomDefaultColumns { get; set; } private string CustomDefaultValues { get; set; } protected int LastRecordId { get; set; } public string SortString { get; set; } private readonly ArrayList LinkQueries = new ArrayList(); public DataRowCollection Rows => MyDataTable.Rows; public DataRow CurrentRow { get { if (((CurrentIndex != -1) && (MyDataTable != null)) && (CurrentIndex < MyDataTable.DefaultView.Count)) { return MyDataTable.DefaultView[CurrentIndex].Row; } return null; } } public DataTable CurrentTable => MyDataTable; public bool IsNewRow { get { bool flag = false; if (CurrentRow != null) { flag = CurrentRow.RowState == DataRowState.Added; } return flag; } } public bool IsOpened => (MyDataTable != null); public DataColumnCollection CurColumns => MyDataTable.Columns; public ArrayList IwbColumns { get { ArrayList list = new ArrayList(); for (int i = 0; i < MyDataTable.Columns.Count; i++) { string key = MyDataTable.Columns[i].ColumnName.UAndT(); if (IwbDataColumns.ContainsKey(key)) { list.Add(IwbDataColumns[key]); } } return list; } } public Hashtable IwbDataColumns { get { if ((MyDataTable != null) && (Columns == null)) { Columns = new Hashtable(); for (int i = 0; i < MyDataTable.Columns.Count; i++) { string columnName = MyDataTable.Columns[i].ColumnName; //IwbDataColumn dataColumn = AppEnv.GetDataColumn(IwbDataColumn.GetBaseColumn(columnName), null); var dataColumn= new IwbDataColumn(); if (dataColumn != null) { Columns.Add(columnName.ToUpper(), dataColumn); } } } return Columns; } } public int PageCount { get { int num = RecCount / RecordsPerPage; if ((RecCount % RecordsPerPage) != 0) { num++; } return num; } } public int PageNo { get { return ((RecNo / RecordsPerPage) + 1); } set { if (value > 0) { var recCount = ((value - 1) * RecordsPerPage) + 1; if (recCount > RecCount) { recCount = RecCount; } int recNo = RecNo; Go(recCount - 1); if (RowIndexInPage(recNo) != -1) { Go(recNo); } } } } public int RecCount { get { if (MyDataTable != null) { return MyDataTable.DefaultView.Count; } return -1; } } public int RecNo { get { if ((CurrentIndex < 0) | (CurrentIndex >= RecCount)) { return -1; } return CurrentIndex; } set => Go(value); } public int RecordId { get { int num = -1; DataRow currentRow = CurrentRow; if ((currentRow != null) && MyDataTable.Columns.Contains(IwbZeroConsts.RecordIdentityCol)) { object obj2 = currentRow[IwbZeroConsts.RecordIdentityCol]; if (!(obj2 is DBNull)) { num = (int)obj2; } } return num; } } public int RecordsPerPage { get; set; } public virtual DataRow AddCurrentRowFrom(IwbQuery poSource) { DataRow row = MyDataTable.NewRow(); MyDataTable.Rows.Add(row); GoTo(row); ReplaceCurrentRow(poSource.CurrentRow); return row; } public DataRow MoveFirst() { if ((CurrentIndex != 0) ) //if ((_CurrentIndex != 0) && FireBeforeRecordMoved()) { CurrentIndex = 0; //FireRecordMovedEvent(); } return CurrentRow; } public DataRow MoveLast() { if ((CurrentIndex != (MyDataTable.DefaultView.Count - 1)) ) //if ((_CurrentIndex != (_myDataTable.DefaultView.Count - 1)) && FireBeforeRecordMoved()) { CurrentIndex = MyDataTable.DefaultView.Count - 1; //FireRecordMovedEvent(); } return CurrentRow; } public DataRow MoveNext() { if ((CurrentIndex < (MyDataTable.DefaultView.Count - 1)) ) // if ((_CurrentIndex < (_myDataTable.DefaultView.Count - 1)) && FireBeforeRecordMoved()) { CurrentIndex++; //FireRecordMovedEvent(); } return CurrentRow; } public DataRow MovePrev() { if ((CurrentIndex > 0) ) //if ((_CurrentIndex > 0) && FireBeforeRecordMoved()) { CurrentIndex--; //FireRecordMovedEvent(); } return CurrentRow; } public virtual DataRow NewRow() { DataRow row; //if (FireBeforeAddNewRecord()) { row = MyDataTable.NewRow(); MyDataTable.Rows.Add(row); //MarkNewRowRecordId(row); CurrentIndex = -1; GoTo(row); //ApplyCustomDefaults(); } return row; } public DataRow NewRowFrom(DataRow poDr) { DataRow row = MyDataTable.NewRow(); row.BeginEdit(); foreach (DataColumn column in CurColumns) { string name = column.ColumnName.Trim().ToUpper(); if (poDr.Table.Columns.Contains(name)) { row[name] = poDr[name]; } } row.EndEdit(); MyDataTable.Rows.Add(row); GoTo(row); return row; } public byte[] GetBytes(string pcFieldName) { byte[] buffer = null; if (CurColumns.Contains(pcFieldName)) { object obj2 = CurrentRow[pcFieldName]; if ((obj2 != null) && !(obj2 is DBNull)) { string s = GetString(pcFieldName); if (s != "") { buffer = Convert.FromBase64String(s); } } } return buffer; } public DateTime GetDateTime(string pcFieldName) { return GetString(pcFieldName, CurrentRow).StrToDt(); } public decimal GetDecimal(string pcFieldName) { return GetString(pcFieldName).ValD(); } public string GetDisplayString(string pcFieldName) { string pcStandardValue = GetString(pcFieldName); string str2 = StringHelper.UAndT(pcFieldName); if (IwbDataColumns[str2] != null) { pcStandardValue = ((IwbDataColumn)IwbDataColumns[str2]).GetDisplayString(pcStandardValue); } return pcStandardValue; } public string GetFieldValues(string pcFieldNames) { return GetFieldValues(pcFieldNames, CurrentRow); } public string GetFieldValues(string pcFieldNames, DataRow poDataRow) { string pcSource = ""; foreach (string str2 in StringHelper.StrToArray(pcFieldNames)) { if (CurColumns.Contains(str2)) { pcSource = StringHelper.AddStr(pcSource, GetString(str2, poDataRow)); } else { pcSource = StringHelper.AddStr(pcSource, str2); } } return pcSource; } public int GetInt(string pcFieldName) => StringHelper.ValI(GetString(pcFieldName)); public IwbDataColumn GetDataColumn(string pcColumnName) { IwbDataColumn column = null; pcColumnName = pcColumnName.UAndT(); if (IwbDataColumns.ContainsKey(pcColumnName)) { column = (IwbDataColumn)IwbDataColumns[pcColumnName]; } return column; } public string GetString(string pcFieldName) { return GetString(pcFieldName, CurrentRow); } public string GetString(string pcFieldName, DataRow poDr) { string str = ""; if (((MyDataTable == null) || !MyDataTable.Columns.Contains(pcFieldName)) || (poDr == null)) { return str; } if (poDr[pcFieldName] is DateTime) { try { DateTime time = (DateTime)poDr[pcFieldName]; if (((time.Year != 0x76c) || (time.Month != 1)) || (time.Day != 1)) { return time.ToString("G"); } return ""; } catch (Exception) { return ""; } } return poDr[pcFieldName].ToString().Trim(); } public string GetString(string pcFieldName, int piDecimalDigit) { string str = GetString(pcFieldName); decimal poObject = str.ValD(); if (poObject.UAndT() != str) { return str; } string format = "0."; for (int i = 0; i < piDecimalDigit; i++) { format = format + "0"; } return poObject.ToString(format); } public Hashtable GetValuesByCols(string pcCols, DataRow poDr) { Hashtable hashtable = new Hashtable(); Array array = pcCols.StrToArray(); for (int i = 0; i < array.Length; i++) { string key = array.GetValue(i).ToString().ToUpper().Trim(); hashtable.Add(key, poDr[key]); } return hashtable; } public DataRow Go(int recordNumber) { //if ((recordNumber != _CurrentIndex) && FireBeforeRecordMoved()) if ((recordNumber != CurrentIndex)) { CurrentIndex = recordNumber; //FireRecordMovedEvent(); } return CurrentRow; } public bool GoByRecordId(int piRecordId, bool plFireRecordMoveEvent) { bool flag = false; if (MyDataTable.Columns.Contains(IwbZeroConsts.RecordIdentityCol)) { int num = CurrentIndex; CurrentIndex = 0; while (CurrentIndex < RecCount) { if (RecordId == piRecordId) { //if (plFireRecordMoveEvent) //{ // bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; // IsToFireRecordMovedEvent = true; // FireRecordMovedEvent(); // IsToFireRecordMovedEvent = isToFireRecordMovedEvent; //} flag = true; break; } CurrentIndex++; } if (!flag) { CurrentIndex = num; } } return flag; } public void GoTo(DataRow dr) { if ((dr != null) && ((RecNo <= -1) || (MyDataTable.DefaultView[RecNo].Row != dr))) { for (int i = 0; i < RecCount; i++) { if (MyDataTable.DefaultView[i].Row == dr) { Go(i); return; } } } } //public void GoTo(DataRow podr, bool plFireEvent) //{ // bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; // IsToFireRecordMovedEvent = plFireEvent; // GoTo(podr); // IsToFireRecordMovedEvent = isToFireRecordMovedEvent; //} public bool GoToRecordByFieldsAndValues(string pcFields, string pcValues) { int num = CurrentIndex; StringHelper.StrToArray(pcFields); StringHelper.StrToArray(pcValues); bool flag = false; CurrentIndex = 0; while (CurrentIndex < RecCount) { if (IsValuesMatch(CurrentRow, pcFields, pcValues)) { flag = true; break; } CurrentIndex++; } if (flag && (CurrentIndex != num)) { //FireRecordMovedEvent(); return true; } CurrentIndex = num; return flag; } public DataRow GoToRecordByString(string pcStr, string pcColName) { int num = CurrentIndex; pcStr = StringHelper.UAndT(pcStr); int length = pcStr.Length; bool flag = false; if (CurColumns.Contains(pcColName)) { CurrentIndex = 0; while (CurrentIndex < RecCount) { string str = StringHelper.UAndT(CurrentRow[pcColName]); if ((str.Length >= length) && (str.Substring(0, length) == pcStr)) { flag = true; break; } CurrentIndex++; } } if (flag) { //FireRecordMovedEvent(); } else { CurrentIndex = num; } return CurrentRow; } public void GoToRecordInPage(int piRecordIndex) { if ((piRecordIndex >= 0) && (piRecordIndex < RecordsPerPage)) { int recordNumber = ((PageNo - 1) * RecordsPerPage) + piRecordIndex; if (recordNumber < 0) { recordNumber = 0; } if (recordNumber >= RecCount) { recordNumber = RecCount - 1; } Go(recordNumber); } } public bool IsDataValid(string pcColName, string pcValue) { bool flag = true; string key = pcColName.UAndT(); if (IwbDataColumns.ContainsKey(key)) { IwbDataColumn column = (IwbDataColumn)IwbDataColumns[key]; if (column == null) { return true; } IwbDataType dataType = column.IwbDataType; try { dataType.TranslateValue(pcValue); } catch { flag = false; //string pcString = AppEnv.T(0x18733, pcValue, column.ColumnName, exception.Message); //AppEnv.InfoBox(pcString); //if (AppEnv.AppMode == npAppModes.Web) //{ // throw new Exception(pcString); //} } } return flag; } public bool IsValuesMatch(DataRow poDr, Hashtable poCriteria) { if (poCriteria != null) { Array array = new String[poCriteria.Count]; poCriteria.Keys.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { string str = StringHelper.UAndT(array.GetValue(i)); IwbDataColumn column = (IwbDataColumn)IwbDataColumns[str]; if ((column == null) || (column.IwbDataType.Compare(poDr[str], poCriteria[str]) != 0)) { return false; } } } return true; } public bool IsValuesMatch(DataRow poDr, string pcFields, string pcValues) { bool flag = true; Array array = pcFields.StrToArray(); Array array2 = pcValues.StrToArray(); Hashtable columns = IwbDataColumns; for (int i = 0; i < array.Length; i++) { string key = StringHelper.UAndT(array.GetValue(i)); string poDest = ""; if (i < array2.Length) { poDest = array2.GetValue(i).ToString(); } if (columns.ContainsKey(key)) { IwbDataColumn column = (IwbDataColumn)columns[key]; if (column.IwbDataType.Compare(poDr[key], poDest) != 0) { flag = false; } } else { flag = IwbDataType.CompareStatic(poDest, poDr[key]) == 0; } if (!flag) { return false; } } return true; } public void ReplaceCurrentRow(DataRow dr) { DataRow currentRow = CurrentRow; if (currentRow != null) { currentRow.BeginEdit(); foreach (DataColumn column in MyDataTable.Columns) { string columnName = column.ColumnName; if (dr.Table.Columns.Contains(columnName)) { try { currentRow[columnName] = dr[columnName]; } catch (Exception) { SetField(columnName, dr[columnName].ToString()); } } } currentRow.EndEdit(); //bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; //IsToFireRecordMovedEvent = false; GoTo(currentRow); //IsToFireRecordMovedEvent = isToFireRecordMovedEvent; } //FireRefreshRequested(); } public void ReplaceFieldValues(string pcFields, string pcValues) { Array array = pcFields.StrToArray(); Array array2 = pcValues.StrToArray(); DataRow currentRow = CurrentRow; if ((array.Length == array2.Length) && (currentRow != null)) { currentRow.BeginEdit(); for (int i = 0; i < array.Length; i++) { string pcColName = array.GetValue(i).ToString().Trim(); SetField(pcColName, array2.GetValue(i).ToString()); } currentRow.EndEdit(); //FireRefreshRequested(); } } public void RestoreAllRows() { MyDataTable.RejectChanges(); MoveFirst(); } public bool RestoreCurrentRow() { DataRow currentRow = CurrentRow; if (currentRow != null) { if (currentRow.RowState == DataRowState.Added) { DeleteCurrentRow(); } else { currentRow.RejectChanges(); } //FireRecordMovedEvent(); } return true; } public int RowIndexInPage(int piRecNo) { int num = -1; int num2 = (PageNo - 1) * RecordsPerPage; int num3 = (PageNo * RecordsPerPage) - 1; if (num3 >= RecCount) { num3 = RecCount - 1; } if ((piRecNo >= num2) && (piRecNo <= num3)) { num = piRecNo - num2; } return num; } public virtual void SetBytes(string pcColName, byte[] poBytes) { if (CurColumns.Contains(pcColName) && (CurrentRow != null)) { CurrentRow.BeginEdit(); if ((poBytes == null)) { CurrentRow[pcColName] = DBNull.Value; } else { string str = Convert.ToBase64String(poBytes, 0, poBytes.Length); CurrentRow[pcColName] = str; } CurrentRow.EndEdit(); } } public void SetCustomDefault(string pcColumns, string pcValues) { CustomDefaultColumns = pcColumns; CustomDefaultValues = pcValues; } public virtual void SetField(string pcColName, string pcValue) { SetField(pcColName, pcValue, true); } public virtual void SetField(string pcColName, string pcValue, bool plFireFieldChangedEvent) { pcColName = pcColName.UAndT(); DataRow currentRow = CurrentRow; if (currentRow != null) { string poDest = currentRow[pcColName].ToString().Trim(); bool flag; if (IwbDataColumns.ContainsKey(pcColName)) { flag = ((IwbDataColumn)IwbDataColumns[pcColName]).IwbDataType.Compare(pcValue, poDest) == 0; } else { flag = pcValue.Trim() == poDest; } if ((!flag || (currentRow[pcColName] == DBNull.Value)) && IsDataValid(pcColName, pcValue)) { //bool isToFireColumnChanged = IsToFireColumnChanged; //IsToFireColumnChanged = plFireFieldChangedEvent; SetField(pcColName, pcValue, currentRow); if (CurrentRow != currentRow) { //bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; //IsToFireRecordMovedEvent = false; GoTo(currentRow); //IsToFireRecordMovedEvent = isToFireRecordMovedEvent; } //FireFieldValueChanged(pcColName); //IsToFireColumnChanged = isToFireColumnChanged; } } } public virtual void SetField(string pcColName, string pcValue, DataRow poDataRow) { if (poDataRow.Table.Columns.Contains(pcColName)) { DataColumn column = poDataRow.Table.Columns[pcColName]; if ((column.MaxLength >= 0) && (column.MaxLength < pcValue.Length)) { pcValue = pcValue.Substring(0, column.MaxLength); } IwbDataType npDataTypeByType = IwbDataType.GetIwbDataTypeByType(CurColumns[pcColName].DataType); string pcOldValue = GetString(pcColName, poDataRow); CascadeValuesToChild(poDataRow, pcColName, pcValue, pcOldValue); poDataRow.BeginEdit(); poDataRow[pcColName] = npDataTypeByType.TranslateValue(pcValue); poDataRow.EndEdit(); } } private void SetNextLocalId() { object obj2 = MyDataTable.Compute("Max(" + IwbZeroConsts.IdenField + ")", ""); if (obj2 is DBNull) { obj2 = 0; } SetField(IwbZeroConsts.IdenField, (((int)obj2) + 1).ToString(), false); } public void SortBy(string pcSort) { try { if (MyDataTable != null) { int recNo = -1; SortString = pcSort; DataRow currentRow = CurrentRow; MyDataTable.DefaultView.Sort = pcSort; if (currentRow != null) { GoTo(currentRow); recNo = RecNo; } DataTable table = MyDataTable.Copy(); MyDataTable.Rows.Clear(); MyDataTable.DefaultView.Sort = ""; DataView view = new DataView(table, "", pcSort, DataViewRowState.CurrentRows); foreach (DataRowView view2 in view) { MyDataTable.ImportRow(view2.Row); } view = new DataView(table, "", pcSort, DataViewRowState.Deleted); foreach (DataRowView view3 in view) { MyDataTable.ImportRow(view3.Row); } CurrentIndex = recNo; //FireRefreshRequested(); } } catch { // } } public void SortBy(string pcColumnId, bool plAscending) { string pcSort = pcColumnId + (plAscending ? " asc" : " desc"); SortBy(pcSort); } public void PageFirst() { PageNo = 1; } public void PageLast() { PageNo = PageCount; } public void PageNext() { PageNo++; } public void PagePrev() { PageNo--; } public void AddLocalBal(string pcSourceQtyField) { AddLocalBal(pcSourceQtyField, IwbZeroConsts.IdenField); } public void AddLocalBal(string pcSourceQtyField, string pcTargetField) { if (IsOpened) { MyDataTable.Columns.Add(pcTargetField, typeof(decimal)).Caption = "Local Bal"; Columns = null; int num = CurrentIndex; CurrentIndex = 0; while (CurrentIndex < RecCount) { SetField(pcTargetField, GetString(pcSourceQtyField), false); CurrentIndex++; } CurrentIndex = num; } } public void AddLocalIdentity() { if (IsOpened) { MyDataTable.Columns.Add(IwbZeroConsts.IdenField, typeof(int)); Columns = null; int num = CurrentIndex; CurrentIndex = 0; while (CurrentIndex < RecCount) { SetNextLocalId(); CurrentIndex++; } CurrentIndex = num; } } public void AddPk(string pcFields) { if ((MyDataTable != null) && !MyDataTable.Constraints.Contains("PrimaryKey")) { Array array = pcFields.StrToArray(); Array array2 = Array.CreateInstance(typeof(DataColumn), array.Length); int num = 0; foreach (string str in array) { array2.SetValue(MyDataTable.Columns[str], num++); } MyDataTable.Constraints.Add("PrimaryKey", (DataColumn[])array2, true); } } protected virtual void ApplyCustomDefaults() { //FireAfterAddNewRecord(); ReplaceFieldValues(CustomDefaultColumns, CustomDefaultValues); } private void CascadeValuesToChild(DataRow poParentRow, string pcColumn, string pcNewValue, string pcOldValue) { foreach (IwbLinkQuery query in LinkQueries) { query.CascadeFieldValues(this, poParentRow, pcColumn, pcNewValue, pcOldValue); } } protected virtual void ClearEnvironment() { CurrentIndex = -1; CustomDefaultColumns = ""; CustomDefaultValues = ""; } public virtual void CloneFrom(IwbQuery poSource) { //ConnectionId = poSource.ConnectionId; MyDataTable = poSource.CurrentTable.Clone(); poSource.CurrentTable.Constraints.Clear(); MyDataTable.TableName = "T" + StringHelper.GetRandom(); //QueryCriteria = poSource.QueryCriteria; } public void Close() { ClearEnvironment(); if (CurrentTable != null) { MyDataTable = null; } } protected void ColumnChanged(object sender, DataColumnChangeEventArgs e) { //FireFieldValueChanged(e.Column.ColumnName); } public object Compute(string pcAggrFunction, string pcExpr, string pcCriteria) { object obj2 = null; try { CurColumns.Add("ABCDEFGHIJKLMNOPQRSTUVWXYZ", typeof(decimal), pcExpr); obj2 = CurrentTable.Compute(pcAggrFunction + "(ABCDEFGHIJKLMNOPQRSTUVWXYZ)", pcCriteria); CurColumns.Remove("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); } catch (Exception exception) { obj2 = exception; } return obj2; } public virtual DataRow CopyRow() { DataRow currentRow = CurrentRow; DataRow row = null; if (currentRow != null) { row = MyDataTable.NewRow(); row.BeginEdit(); foreach (DataColumn column in MyDataTable.Columns) { string columnName = column.ColumnName; row[columnName] = currentRow[columnName]; } row.EndEdit(); MyDataTable.Rows.Add(row); MarkNewRowRecordId(row); } return row; } protected void MarkNewRowRecordId(DataRow poRow) { if ((poRow != null) && MyDataTable.Columns.Contains(IwbZeroConsts.RecordIdentityCol)) { poRow[IwbZeroConsts.RecordIdentityCol] = ++LastRecordId; } } public void CreateFrom(ArrayList poDataColumns) { MyDataTable = new DataTable(TableName); foreach (DataColumn column in poDataColumns) { MyDataTable.Columns.Add(column); } } public void DeleteAllRecord() { //bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; //IsToFireRecordMovedEvent = false; while (RecCount > 0) { MoveFirst(); DeleteCurrentRow(); } //IsToFireRecordMovedEvent = isToFireRecordMovedEvent; //FireRecordMovedEvent(); } public virtual DataRow DeleteCurrentRow() { DataRow currentRow = CurrentRow; if (currentRow.RowState == DataRowState.Added) { MyDataTable.Rows.Remove(currentRow); } else { currentRow.Delete(); } currentRow = CurrentRow; //bool isToFireRecordMovedEvent = IsToFireRecordMovedEvent; //IsToFireRecordMovedEvent = false; if (currentRow != null) { if (currentRow.RowState == DataRowState.Deleted) { currentRow = MoveNext(); } } else { currentRow = MoveLast(); } if (CurrentIndex >= RecCount) { CurrentIndex = -1; } //IsToFireRecordMovedEvent = isToFireRecordMovedEvent; //FireRecordMovedEvent(); return currentRow; } public void FilterBy(string pcExpression) { MyDataTable.DefaultView.RowFilter = pcExpression; } public virtual void SaveToXml(DataTable dt) { dt.CDataToXmlFile(FilePath); } public virtual void SaveToXml() { MyDataTable.CDataToXmlFile(FilePath); } ~IwbQuery() { } //public static Dictionary Dictionary { get; set; } //protected event EvDictionaryChanged DictionaryChanged; //public void SetField(string name, object value) //{ // Dictionary = Dictionary ?? GetDictionary(); // if (Dictionary.ContainsKey(name)) // { // var oldValue = Dictionary[name]; // if (oldValue != value) // { // Dictionary[name] = value; // DictionaryChanged?.Invoke(Dictionary); // } // } // else // { // Dictionary.Add(name,value); // DictionaryChanged?.Invoke(Dictionary); // } //} //public string GetString(string name) //{ // //Dictionary = Dictionary ?? GetDictionary(); // //if (Dictionary.ContainsKey(name)) // //{ // // return Dictionary[name].ToString(); // //} // return ""; //} //public int GetInt(string name) //{ // return GetString(name).ValI(); //} //public decimal GetDecimal(string name) //{ // return GetString(name).ValD(); //} //public bool GetBool(string name) //{ // return GetString(name).ValB(); //} //public DateTime GetDate(string name) //{ // return GetString(name).StrToDt(); //} //public virtual void SaveToXml(Dictionary dictionary) //{ // if (dictionary.Count > 0) // { // var str = ""; // foreach (var o in dictionary) // { // str += $"<{o.Key}>{o.Value.ToString().FormatCode2Xml()}\r\n"; // } // XmlDocument xDoc = new XmlDocument {InnerText = str}; // xDoc.Save(FilePath); // } //} //public Dictionary GetDictionary() //{ // if (Dictionary != null) // { // return Dictionary; // } // var dic= new Dictionary(); // if (FilePath.IsNotEmpty()) // { // XmlDocument xDoc= new XmlDocument(); // try // { // xDoc.Load(FilePath); // var xmlNode = xDoc.LastChild; // if (xmlNode != null && xmlNode.HasChildNodes) // { // foreach (XmlNode node in xmlNode.ChildNodes) // { // dic.Add(node.Name, (node.FirstChild?.Value).FormatXml2Code() ?? ""); // } // } // } // catch(Exception ) // { // // // } // } // return dic; //} } }