Common.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using Core.Mes.ServerFrameWork;
  5. using Core.Mes.IBaseInterface;
  6. namespace Core.XgMes.Server.JGKC.SteelPlateManager
  7. {
  8. public class Common : Core.Mes.ServerFrameWork.IComponent
  9. {
  10. public Common()
  11. {
  12. //
  13. // TODO: 在此处添加构造函数逻辑
  14. //
  15. }
  16. public override int maxValue
  17. {
  18. get
  19. {
  20. return 100;
  21. }
  22. }
  23. public override int minValue
  24. {
  25. get
  26. {
  27. return 50;
  28. }
  29. }
  30. public static string CheckNullStr(object obj)
  31. {
  32. if (obj == null || obj.GetType() == typeof(System.DBNull))
  33. {
  34. return "";
  35. }
  36. else
  37. {
  38. return Convert.ToString(obj);
  39. }
  40. }
  41. public static object[] FixValues(object[] values)
  42. {
  43. for (int i = 0; i < values.Length; i++)
  44. {
  45. if (values[i] == null)
  46. {
  47. values[i] = DBNull.Value;
  48. }
  49. else if (values[i].GetType().FullName == "System.String")
  50. {
  51. values[i] = ((string)values[i]).Length != 0 ? values[i] : DBNull.Value;
  52. }
  53. }
  54. return values;
  55. }
  56. /// <summary>
  57. /// 对目标对象进行字符串的转换
  58. /// </summary>
  59. /// <param name="obj"></param>
  60. /// <returns></returns>
  61. public static string ObjToStr(object obj)
  62. {
  63. if (obj == null || obj.GetType() == typeof(System.DBNull))
  64. {
  65. return "";
  66. }
  67. else
  68. {
  69. return Convert.ToString(obj);
  70. }
  71. }
  72. /// <summary>
  73. /// 对目标对象进行数字(小数)的转换
  74. /// </summary>
  75. /// <param name="obj"></param>
  76. /// <returns></returns>
  77. public static System.Decimal ObjToDecimal(object obj)
  78. {
  79. try
  80. {
  81. if (obj == null || obj.GetType() == typeof(System.DBNull) || ObjToStr(obj).Length == 0)
  82. {
  83. return 0;
  84. }
  85. else
  86. {
  87. return Convert.ToDecimal(obj);
  88. }
  89. }
  90. catch (System.Exception ex)
  91. {
  92. System.Diagnostics.Debug.WriteLine(ex.ToString());
  93. return 0;
  94. }
  95. }
  96. /// <summary>
  97. /// 初始化ComboBox,返回哈希表(针对scm_base_info表)
  98. /// </summary>
  99. /// <param name="_sortCode ">scm_base_info中sort_code字段</param>
  100. /// <returns></returns>
  101. public ReturnObject IniComboBox(string _sortCode)
  102. {
  103. string strSql;
  104. string strOut = "";
  105. DataSet ds;
  106. System.Collections.Hashtable ht = new Hashtable();
  107. try
  108. {
  109. strSql = "select name_ ,id_ from SELECT BUTTRESSCODE FROM KCJ_BUTTRESS_ZW WHERE BUTTRESSTYPE='0' AND ISVALID='1' where sort_code = '" + _sortCode + "'" + " and substr(id_,1,4) ='" + _sortCode + "'";
  110. ds = this.DBManager.ExecuteQuery(strSql, out strOut);
  111. if (ds != null && ds.Tables.Count == 1)
  112. {
  113. foreach (System.Data.DataRow row in ds.Tables[0].Rows)
  114. {
  115. ht.Add(row["id_"].ToString(), row["name_"].ToString());
  116. }
  117. return new ReturnObject(ht);
  118. }
  119. return new ReturnObject(strOut);
  120. }
  121. catch (Exception ex)
  122. {
  123. System.Diagnostics.Debug.WriteLine(ex.ToString());
  124. return new ReturnObject(ex.ToString());
  125. }
  126. }
  127. /// <summary>
  128. /// 初始化ComboBox,返回哈希表(针对所有表表)
  129. /// </summary>
  130. /// <param name="_sql ">SQL(Select语句)</param>
  131. /// <param name="_keyCol ">Key字段</param>
  132. /// <param name="_valuesCol ">Values字段</param>
  133. /// <returns></returns>
  134. public ReturnObject IniAllComboBox(string _sql, string _keyCol, string _valuesCol)
  135. {
  136. string strOut = "";
  137. DataSet ds;
  138. System.Collections.Hashtable ht = new Hashtable();
  139. try
  140. {
  141. ds = this.DBManager.ExecuteQuery(_sql, out strOut);
  142. if (ds != null && ds.Tables.Count == 1)
  143. {
  144. foreach (System.Data.DataRow row in ds.Tables[0].Rows)
  145. {
  146. ht.Add(row[_keyCol].ToString(), row[_valuesCol].ToString());
  147. }
  148. return new ReturnObject(ht);
  149. }
  150. return new ReturnObject(strOut);
  151. }
  152. catch (Exception ex)
  153. {
  154. System.Diagnostics.Debug.WriteLine(ex.ToString());
  155. return new ReturnObject(ex.ToString());
  156. }
  157. }
  158. //得到区域编码_AreaType=0原料,1成品
  159. public ReturnObject GetAreaCode(string _AreaType)
  160. {
  161. string strOut = "";
  162. ArrayList al = new ArrayList();
  163. string sql = "";
  164. try
  165. {
  166. sql = "select distinct(areacode) from KCJ_AREA_ZW where isvalid = '1'and areatype = '" + _AreaType + "' ";
  167. DataSet ds = this.DBManager.ExecuteQuery(sql, out strOut);
  168. if (strOut != "")
  169. {
  170. return new ReturnObject(strOut);
  171. }
  172. foreach (System.Data.DataRow row in ds.Tables[0].Rows)
  173. {
  174. al.Add(row["areacode"].ToString());
  175. }
  176. return new ReturnObject(al);
  177. }
  178. catch (Exception ex)
  179. {
  180. System.Diagnostics.Debug.WriteLine(ex.ToString());
  181. return new ReturnObject(ex.ToString());
  182. }
  183. }
  184. public ReturnObject ExecuteNone(string sql)
  185. {
  186. string outerr = "";
  187. this.DBManager.ExecuteNonQuery(sql, out outerr);
  188. if (outerr.Length == 0)
  189. {
  190. return new ReturnObject("1");//success
  191. }
  192. else
  193. {
  194. return new ReturnObject(outerr.ToString());//cuowu
  195. }
  196. }
  197. public ReturnObject GetDataSet(string _sqlstr)
  198. {
  199. string strOut = "";
  200. DataSet ds = this.DBManager.ExecuteQuery(_sqlstr, out strOut);
  201. //DataSet ds = ((STMes.DBManager)DBManagerList["ODPDB"]).ExecuteQuery(_sqlstr, out strOut);
  202. return new ReturnObject(ds, strOut);
  203. }
  204. }
  205. }