DALibs.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. namespace SysBaseLibs
  6. {
  7. public class DALibs
  8. {
  9. public static bool IsValuesMatch(DataRow poDr, string pcFields, string pcValues)
  10. {
  11. bool lbRetVal = false;
  12. Dictionary<string, object> loht = UtilStr .StrToDictionary(pcFields, pcValues);
  13. lbRetVal = IsValuesMatch(poDr, loht);
  14. return lbRetVal;
  15. }
  16. public static bool IsValuesMatch(DataRow poDr, Dictionary<string, object> poCriteria)
  17. {
  18. bool lbRetVal = false;
  19. if (poDr != null && poCriteria != null)
  20. {
  21. foreach (string lcColName in poCriteria.Keys)
  22. {
  23. object loValue = poCriteria[lcColName];
  24. if (poDr[lcColName] != null)
  25. {
  26. lbRetVal = CompareStatic(poDr[lcColName].ToString(), loValue);
  27. }
  28. else
  29. lbRetVal = false;
  30. if (!lbRetVal)
  31. return lbRetVal;
  32. }
  33. }
  34. return lbRetVal;
  35. }
  36. public static bool CompareStatic(string pcValue1, object poObject2)
  37. {
  38. bool lbRetVal = false;
  39. if (poObject2 == null)
  40. return lbRetVal;
  41. if (poObject2 is string)
  42. lbRetVal = (string.Compare(pcValue1.Trim(), poObject2.ToString().Trim(), true) == 0);
  43. if (poObject2 is DateTime)
  44. lbRetVal = (DateTime.Compare(UtilStr.StrToDt(pcValue1), (DateTime)poObject2) == 0);
  45. if (poObject2 is decimal)
  46. lbRetVal = (decimal.Compare(Utils.ValD(pcValue1), Utils.ValD(poObject2.ToString())) == 0);
  47. return lbRetVal;
  48. }
  49. public static string GetColumnId(string pcTableAndColumn)
  50. {
  51. string lcRetVal = pcTableAndColumn;
  52. Array loArr = UtilStr.StrToArrayEx(pcTableAndColumn, ".");
  53. if (loArr != null && loArr.Length == 2)
  54. lcRetVal = loArr.GetValue(1).ToString();
  55. return lcRetVal;
  56. }
  57. public static string GetTableId(string pcTableAndColumn)
  58. {
  59. string lcRetVal = pcTableAndColumn;
  60. Array loArr = UtilStr.StrToArrayEx(pcTableAndColumn, ".");
  61. if (loArr != null && loArr.Length == 2)
  62. lcRetVal = loArr.GetValue(0).ToString();
  63. return lcRetVal;
  64. }
  65. // Properties
  66. private static string _ConnectionStr = "";
  67. public static string CenterConnectionStr
  68. {
  69. get
  70. {
  71. if (_ConnectionStr.Trim().Length == 0)
  72. _ConnectionStr = AppEnv.DBConnectString;
  73. return _ConnectionStr;
  74. }
  75. }
  76. }
  77. public delegate bool evDataOperationRequested(rsQuery poQuery);
  78. public delegate void evFieldValueChanged(rsQuery poQuery, string pcFieldName);
  79. public delegate void evRefreshRequested(rsQuery poQuery);
  80. public delegate void evRecordMoved();
  81. //public delegate void evDeleteRecordLocally(rsTable poNpTable, DataRow poDataRow, int piIndex);
  82. public delegate void evDBOperationError(string pcErrorMsgs, string ErrorFields);
  83. }