DAL_AMResult.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using MOKA_Factory_Tools.Database;
  2. using MOKA_Factory_Tools.Models;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MOKA_Factory_Tools.DAL
  10. {
  11. public class DAL_AMResult : BaseDAL
  12. {
  13. public DAL_AMResult()
  14. {
  15. this.TableFieldNameString = "";
  16. }
  17. #region 属性和字段
  18. string _tableName = "AMResult";
  19. /// <summary>
  20. /// 获取数据表名
  21. /// </summary>
  22. public override string TableName
  23. {
  24. get { return _tableName; }
  25. set { this._tableName = value; }
  26. }
  27. /// <summary>
  28. /// 获取当前新的数据表模型对象
  29. /// </summary>
  30. public override object ObjModel
  31. {
  32. get
  33. {
  34. return this.CurrentModel;
  35. }
  36. }
  37. /// <summary>
  38. /// 获取当前新的MOdel
  39. /// </summary>
  40. public AMResult CurrentModel
  41. {
  42. get { return new AMResult(); }
  43. }
  44. string _tableFieldNameString = "";
  45. /// <summary>
  46. /// 数据表字段名数组
  47. /// </summary>
  48. public override string TableFieldNameString
  49. {
  50. get { return this._tableFieldNameString; }
  51. set { this._tableFieldNameString = value; }
  52. }
  53. #endregion
  54. #region 检查记录
  55. //基类已经实现
  56. #endregion
  57. #region 增加数据
  58. /// <summary>
  59. /// 增加一条数据
  60. /// </summary>
  61. /// <param name="model">Model对象</param>
  62. /// <returns></returns>
  63. public bool Add(AMResult model)
  64. {
  65. return base.Add(model);
  66. }
  67. /// <summary>
  68. /// 增加一条数据
  69. /// </summary>
  70. /// <param name="model">Model对象</param>
  71. /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
  72. /// <returns></returns>
  73. public bool Add(AMResult model, string overlookFieldList = "ID")
  74. {
  75. return base.Add(model, overlookFieldList);
  76. }
  77. #endregion
  78. #region 删除数据
  79. /// <summary>
  80. /// 删除数据
  81. /// </summary>
  82. /// <param name="model"></param>
  83. /// <returns></returns>
  84. public bool Delete(AMResult model)
  85. {
  86. return base.Delete(string.Format("Station = '{0}' and SN = '{1}' and ReDo = '{2}'", model.Station, model.SN, model.ReDo));
  87. }
  88. #endregion
  89. #region 更新数据
  90. /// <summary>
  91. /// 更新一条数据
  92. /// </summary>
  93. public bool Update(AMResult model)
  94. {
  95. return base.Update(model);
  96. }
  97. /// <summary>
  98. /// 根据筛选字段和SQL筛选运算符号更新数据
  99. /// </summary>
  100. /// <param name="model">Model对象</param>
  101. /// <param name="filterFieldName">筛选字段名称</param>
  102. /// <param name="operators">SQL筛选运算符号</param>
  103. /// <param name="overlookFieldList">忽略字段名列表 字段名之间用“,”号分隔</param>
  104. /// <returns></returns>
  105. public bool Update(AMResult model, string strWhere, string IgnoreUpdateFields = "Station,SN,ODF,DSN,Line,Model,Dimension")
  106. {
  107. return base.UpdateAMResult(model, strWhere, IgnoreUpdateFields);
  108. }
  109. #endregion
  110. #region 查询数据
  111. /// <summary>
  112. ///
  113. /// </summary>
  114. /// <param name="strWhere"></param>
  115. /// <returns></returns>
  116. public AMResult GetModel(string strWhere)
  117. {
  118. return DataRowToModel(GetDataRow(strWhere));
  119. }
  120. /// <summary>
  121. /// 得到一个对象实体
  122. /// </summary>
  123. public AMResult GetModel(string strStation, string strSN)
  124. {
  125. return DataRowToModel(GetDataRow(string.Format("Station = '{0}' and SN = '{1}'", strStation, strSN)));
  126. }
  127. public HourlyResultData GetHourlyResultData(string Line, string Station, string ODF, DateTime TestDate, int TestHour)
  128. {
  129. DataRow row = GetHourlyDataRow(string.Format("Line='{0}' and Station='{1}' and ODF='{2}' and TestDate='{3}' and TestHour='{4}'", Line, Station, ODF, TestDate, TestHour));
  130. if ( row != null )
  131. {
  132. HourlyResultData model = new HourlyResultData();
  133. model.TotalCount = row["Total"].ToString();
  134. model.RealTotalCount = row["RealTotal"].ToString();
  135. model.OncePassCount = row["OncePass"].ToString();
  136. model.OnceFailCount = row["OnceFail"].ToString();
  137. model.NTFCount = row["NTF"].ToString();
  138. model.TwiceFailCount = row["TwiceFail"].ToString();
  139. model.FinalFailCount = row["FinalFail"].ToString();
  140. model.FinalPassCount = row["FinalPass"].ToString();
  141. model.RealFailCount = row["RealFail"].ToString();
  142. model.RealPassCount = row["RealPass"].ToString();
  143. model.NTFSN = row["NTFSN"].ToString();
  144. model.FailDSN = row["FailDSN"].ToString();
  145. return model;
  146. }
  147. return null;
  148. }
  149. public DataRow GetHourlyDataRow(string whereString)
  150. {
  151. if (whereString.Trim().Length > 0)
  152. {
  153. StringBuilder strSql = new StringBuilder();
  154. strSql.Append("select ");
  155. strSql.Append("count(1) as 'Total',");
  156. strSql.Append("count(case when ReDo = '0' then 1 else null end) as 'RealTotal',");
  157. strSql.Append("count(case when ResultType = 'OncePass' then 1 else null end) as 'OncePass',");
  158. strSql.Append("count(case when ResultType = 'OnceFail' then 1 else null end) as 'OnceFail',");
  159. strSql.Append("count(case when ResultType = 'NTF' then 1 else null end) as 'NTF',");
  160. strSql.Append("count(case when ResultType = 'TwiceFail' then 1 else null end) as 'TwiceFail',");
  161. strSql.Append("count(case when ResultType = 'FinalFail' then 1 else null end) as 'FinalFail',");
  162. strSql.Append("count(case when ResultType = 'FinalPass' then 1 else null end) as 'FinalPass',");
  163. strSql.Append("count(case when FinalTest = 'PASS' and ReDo = '0' then 1 else null end) as 'RealPass',");
  164. strSql.Append("count(case when FinalTest = 'FAIL' and ReDo = '0' then 1 else null end) as 'RealFail',");
  165. strSql.Append(string.Format("stuff((select ',' + SN from {0} where {1} and ResultType='NTF' for XML PATH('')),1,1,'') as 'NTFSN',", this.TableName, whereString));
  166. strSql.Append(string.Format("stuff((select ',' + DSN from {0} where {1} and FinalTest='FAIL' for XML PATH('')),1,1,'') as 'FailDSN' ", this.TableName, whereString));
  167. strSql.Append("from " + this.TableName);
  168. strSql.Append(" where " + whereString);
  169. DataSet ds = DbHelper.Query(cps.ConnectionString, strSql.ToString());
  170. if (ds.Tables[0].Rows.Count > 0)
  171. {
  172. return ds.Tables[0].Rows[0];
  173. }
  174. }
  175. return null;
  176. }
  177. /// <summary>
  178. /// 得到一个对象实体
  179. /// </summary>
  180. /// <param name="row"></param>
  181. /// <returns></returns>
  182. public AMResult DataRowToModel(DataRow row)
  183. {
  184. return DataRowToModelObject(row) as AMResult;
  185. }
  186. /// <summary>
  187. /// 获得数据Model列表
  188. /// </summary>
  189. /// <param name="strWhere">条件 不包含 where 关键字</param>
  190. public List<AMResult> GetModelList(string strWhere)
  191. {
  192. DataSet ds = base.GetList(strWhere);
  193. return DataTableToList(ds.Tables[0]);
  194. }
  195. /// <summary>
  196. ///
  197. /// </summary>
  198. /// <param name="strLine"></param>
  199. /// <param name="strStation"></param>
  200. /// <param name="ODF"></param>
  201. /// <param name="TestDate"></param>
  202. /// <param name="TestHour"></param>
  203. /// <returns></returns>
  204. public List<AMResult> GetModelList(string strLine, string strStation, string ODF, DateTime TestDate, int TestHour)
  205. {
  206. DataSet ds = base.GetList(string.Format("Line = '{0}' and Station = '{1}' and ODF='{2}' and TestDate='{3}' and TestHour='{4}'", strLine, strStation, ODF, TestDate, TestHour));
  207. return DataTableToList(ds.Tables[0]);
  208. }
  209. /// <summary>
  210. /// 获得数据列表
  211. /// </summary>
  212. /// <param name="dt">DataTable</param>
  213. public List<AMResult> DataTableToList(DataTable dt)
  214. {
  215. List<AMResult> modelList = new List<AMResult>();
  216. List<object> ObjList = base.GetDataTableToOblList(dt);
  217. foreach (object obj in ObjList)
  218. {
  219. modelList.Add((AMResult)obj);
  220. }
  221. return modelList;
  222. }
  223. #endregion
  224. }
  225. }