锐腾搅拌上料功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

5 months ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using ICSSoft.Frame.Data.Entity;
  6. using ICSSoft.Base.Config.AppConfig;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.Linq;
  10. using ICSSoft.Base.Config.DBHelper;
  11. namespace ICSSoft.Frame.Data.DAL
  12. {
  13. public class ICSUser2ResDAL
  14. {
  15. #region AddandEdit
  16. public static void AddandEdit(ICSUser2Res ItemLot, string Appconstr)
  17. {
  18. FramDataContext db = new FramDataContext(Appconstr);
  19. db.Connection.Open();
  20. db.Transaction = db.Connection.BeginTransaction();
  21. try
  22. {
  23. ICSUser2Res line = new ICSUser2Res();
  24. line.USERID = ItemLot.USERID;
  25. line.RESID = ItemLot.RESID;
  26. line.RESCODE = ItemLot.RESCODE;
  27. line.USERCODE = ItemLot.USERCODE;
  28. line.MUSER = ItemLot.MUSER;
  29. line.MUSERName = ItemLot.MUSERName;
  30. line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
  31. line.WorkPoint = AppConfig.WorkPointCode;
  32. db.ICSUser2Res.InsertOnSubmit(line);
  33. db.SubmitChanges();
  34. db.Transaction.Commit();
  35. }
  36. catch (Exception ex)
  37. {
  38. db.Transaction.Rollback();
  39. throw new Exception(ex.Message);
  40. }
  41. }
  42. #endregion
  43. #region 根据资源代码查询资源id
  44. public static DataTable SelectResID(string rescode)
  45. {
  46. string sql = @"select ID
  47. from dbo.ICSRES
  48. where RESCODE='" + rescode + "' and WorkPoint='" + AppConfig.WorkPointCode + "'";
  49. sql = string.Format(sql);
  50. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  51. return dt;
  52. }
  53. #endregion
  54. #region 根据人员代码查询人员id
  55. public static DataTable SelectUserID(string usercode)
  56. {
  57. string sql = @"select ID
  58. from dbo.Sys_User
  59. where UserCode='" + usercode + "' and WorkPointCode='" + AppConfig.WorkPointCode + "'";
  60. sql = string.Format(sql);
  61. DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
  62. return dt;
  63. }
  64. #endregion
  65. #region select
  66. public static ICSDCT select(String guid, String Appconstr)
  67. {
  68. FramDataContext db = new FramDataContext(Appconstr);
  69. db.Connection.Open();
  70. db.Transaction = db.Connection.BeginTransaction();
  71. ICSDCT entity = new ICSDCT();
  72. try
  73. {
  74. var line = db.ICSDCT.SingleOrDefault(a => a.ID == guid);
  75. return (ICSDCT)line;
  76. }
  77. catch (Exception ex)
  78. {
  79. throw new Exception(ex.Message);
  80. }
  81. }
  82. #endregion
  83. #region delete
  84. public static void delete(List<String> useridList,List<string> residList)
  85. {
  86. FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
  87. db.Connection.Open();
  88. db.Transaction = db.Connection.BeginTransaction();
  89. try
  90. {
  91. var lines = db.ICSUser2Res.Where(a => useridList.Contains(a.USERID) && residList.Contains(a.RESID));
  92. //var line = db.ICSRES.Where(a => codeList.Contains(a.DCTCODE));
  93. //if (line.Count() != 0)
  94. //{
  95. // throw new Exception("DCT指令在资源维护已经使用,无法删除!");
  96. //}
  97. db.ICSUser2Res.DeleteAllOnSubmit(lines);
  98. db.SubmitChanges();
  99. db.Transaction.Commit();
  100. }
  101. catch (Exception ex)
  102. {
  103. db.Transaction.Rollback();
  104. throw ex;
  105. }
  106. }
  107. #endregion
  108. }
  109. }