查看: 360|回复: 0

[.NET开发] 接口学习

发表于 2017-12-5 08:00:01
  1. 1 using System;
  2. 2 using System.Collections.Generic;
  3. 3 using System.Web;
  4. 4 using System.Web.Services;
  5. 5 using System.Data;
  6. 6 using Topevery.EOffice.Logic;
  7. 7 using Topevery.EOffice.Entity;
  8. 8 using System.Data.SqlClient;
  9. 9
  10. 10 namespace Topevery.EOffice.Web.WebService
  11. 11 {
  12. 12 /// <summary>
  13. 13 /// AttendanceMachineImport 的摘要说明
  14. 14 /// </summary>
  15. 15 [WebService(Namespace = "http://tempuri.org/")]
  16. 16 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  17. 17 [System.ComponentModel.ToolboxItem(false)]
  18. 18 public class AttendanceMachineImport : System.Web.Services.WebService
  19. 19 {
  20. 20 /// <summary>
  21. 21 /// 两个列
  22. 22 /// [DIN,员工编号][CLOCK,打卡时间]
  23. 23 /// </summary>
  24. 24 /// <param name="data"></param>
  25. 25 /// <returns></returns>
  26. 26 [WebMethod]
  27. 27 public bool Import(DataTable data)
  28. 28 {
  29. 29
  30. 30 DataSet dsAttendanceData = new DataSet();
  31. 31 using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["efDatabase"].ConnectionString))
  32. 32 {
  33. 33 conn.Open();
  34. 34 using (SqlTransaction tran = conn.BeginTransaction())
  35. 35 {
  36. 36 foreach (DataRow dr in data.Rows)
  37. 37 {
  38. 38 string DIN = dr["DIN"].ToString();
  39. 39 DateTime Clock = (DateTime)dr["CLOCK"];
  40. 40 using (SqlCommand command = new SqlCommand("INSERT INTO T_EO_ATTENDANCE_MACHINE(C_DIN , C_CLOCK) VALUES (@DIN , @CLOCK);", conn, tran))
  41. 41 {
  42. 42 command.Parameters.Add(new SqlParameter("@DIN", DIN));
  43. 43 command.Parameters.Add(new SqlParameter("@CLOCK", Clock));
  44. 44 command.ExecuteNonQuery();
  45. 45 }
  46. 46 }
  47. 47 tran.Commit();
  48. 48 }
  49. 49
  50. 50 using (SqlDataAdapter command = new SqlDataAdapter("P_EO_PROCESS_ATTENDANCE_MACHINE", conn))
  51. 51 {
  52. 52 command.SelectCommand.CommandType = CommandType.StoredProcedure;
  53. 53 command.Fill(dsAttendanceData);
  54. 54 }
  55. 55 }
  56. 56
  57. 57 foreach (DataRow dr in dsAttendanceData.Tables[0].Rows)
  58. 58 {
  59. 59 /*
  60. 60 C_USER_ID , C_DATE , C_CHECK_IN_DATE , C_CHECK_OUT_DATE
  61. 61 */
  62. 62 DateTime? _SignInDate = null; DateTime? _SignOutDate = null;
  63. 63 if (dr["C_CHECK_IN_DATE"] != DBNull.Value) { _SignInDate = (DateTime)dr["C_CHECK_IN_DATE"]; }
  64. 64 if (dr["C_CHECK_OUT_DATE"] != DBNull.Value) { _SignOutDate = (DateTime)dr["C_CHECK_OUT_DATE"]; }
  65. 65 EOAttendanceLogic.InsertStaffAttenceEx(new EOStaffAttence()
  66. 66 {
  67. 67 UserID = (Guid)dr["C_USER_ID"],
  68. 68 CheckDate = (DateTime)dr["C_DATE"],
  69. 69 SignInDate = _SignInDate,
  70. 70 SignOutDate = _SignOutDate
  71. 71 });
  72. 72 EOAvoidCheckLogic.ProcessAttendanceData((Guid)dr["C_USER_ID"], (DateTime)dr["C_DATE"]);
  73. 73 }
  74. 74
  75. 75 using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["efDatabase"].ConnectionString))
  76. 76 {
  77. 77 conn.Open();
  78. 78 using (SqlTransaction tran = conn.BeginTransaction())
  79. 79 {
  80. 80 foreach (DataRow dr in data.Rows)
  81. 81 {
  82. 82 using (SqlCommand command = new SqlCommand("TRUNCATE TABLE T_EO_ATTENDANCE_MACHINE ;", conn, tran))
  83. 83 {
  84. 84 command.ExecuteNonQuery();
  85. 85 }
  86. 86 }
  87. 87 tran.Commit();
  88. 88 }
  89. 89 }
  90. 90 return true;
  91. 91 }
  92. 92
  93. 93 [WebMethod]
  94. 94 public DateTime GetLastTime()
  95. 95 {
  96. 96 DateTime lastTime = DateTime.Now.AddDays(-1);
  97. 97 string sql = @"
  98. 98 select max(d) from(
  99. 99 select max(a.c_sign_in_date) as d from t_eo_staff_attence_bak a
  100. 100 inner join syn_ty_pmi_user u on a.c_user_id = u.user_id
  101. 101 where a.c_attence_type = 1
  102. 102 union all
  103. 103 select max(a.c_sign_out_date) from t_eo_staff_attence_bak a
  104. 104 inner join syn_ty_pmi_user u on a.c_user_id = u.user_id
  105. 105 where a.c_attence_type = 1) a";
  106. 106
  107. 107 using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["efDatabase"].ConnectionString))
  108. 108 {
  109. 109 conn.Open();
  110. 110
  111. 111 using (SqlCommand command = new SqlCommand(sql, conn))
  112. 112 {
  113. 113 lastTime = (DateTime)command.ExecuteScalar();
  114. 114 }
  115. 115 }
  116. 116
  117. 117 return lastTime;
  118. 118 }
  119. 119
  120. 120 Dictionary<string, Guid> _EoUserExtBuffer = null;
  121. 121 Dictionary<string, Guid> EoUserExtBuffer
  122. 122 {
  123. 123 get
  124. 124 {
  125. 125 if (_EoUserExtBuffer == null)
  126. 126 {
  127. 127 _EoUserExtBuffer = new Dictionary<string, Guid>();
  128. 128 }
  129. 129 EOUserExtCollection eoUserExtColl = EOPersonalLogic.GetUserInfos();
  130. 130 foreach (EOUserExt ext in eoUserExtColl)
  131. 131 {
  132. 132
  133. 133 _EoUserExtBuffer.Add(ext.UserCode, ext.UserID);
  134. 134 }
  135. 135
  136. 136 return _EoUserExtBuffer;
  137. 137 }
  138. 138 }
  139. 139
  140. 140
  141. 141 Guid GetUserId(string DIN)
  142. 142 {
  143. 143 if (EoUserExtBuffer.ContainsKey(DIN))
  144. 144 {
  145. 145 return EoUserExtBuffer[DIN];
  146. 146 }
  147. 147 return Guid.Empty;
  148. 148 }
  149. 149 }
  150. 150 }
复制代码
View Code

调用方式

  1. 1 TYEO.AttendanceMachineImport ser = new AttendanceMachineTool.TYEO.AttendanceMachineImport();
  2. 2 dtStart.Value = ser.GetLastTime();
复制代码



回复

使用道具 举报

关闭

站长推荐上一条 /1 下一条