CommHelper.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. using Infragistics.Win.UltraWinGrid;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading;
  8. namespace Core.StlMes.Client.PlnSaleOrd.PlanStove
  9. {
  10. public class CommHelper
  11. {
  12. /// <summary>
  13. /// byWencheg设置列的顺序
  14. /// </summary>
  15. /// <param name="band"></param>
  16. /// <param name="key"></param>
  17. /// <param name="index"></param>
  18. public static void SetColumnPosition(Infragistics.Win.UltraWinGrid.UltraGridBand band, string key, int index)
  19. {
  20. if (band.Columns.Exists(key) && band.Columns.Count > index)
  21. {
  22. band.Columns[key].Swap(GetSpecPositionCol(band, index));
  23. //band.Columns[key].Swap(band.Columns[index]);
  24. }
  25. }
  26. /// <summary>
  27. /// 获取指定位置的列
  28. /// </summary>
  29. /// <param name="band"></param>
  30. /// <param name="position"></param>
  31. /// <returns></returns>
  32. public static UltraGridColumn GetSpecPositionCol(UltraGridBand band, int position)
  33. {
  34. foreach (UltraGridColumn col in band.Columns)
  35. {
  36. if (col.Header.VisiblePosition == position)
  37. {
  38. return col;
  39. }
  40. }
  41. return null;
  42. }
  43. /// <summary>
  44. //byWenCheng 设置grid的band的列名和描述(列名和描述来自数据库的列名和描述)
  45. /// </summary>
  46. /// <param name="band">需要设置的grid的band</param>
  47. /// <param name="tablename">与band对应的表名</param>
  48. /// <param name="ob">OpenBase对象</param>
  49. public static void SetColandCaption(Infragistics.Win.UltraWinGrid.UltraGridBand band, string tablename, CoreFS.CA06.OpeBase ob)
  50. {
  51. if (band == null)
  52. {
  53. return;
  54. }
  55. System.Data.DataTable dt = GetDataBySql(string.Format(@"select column_name,comments from user_col_comments where table_name = '{0}'", tablename), ob);
  56. if (dt.Rows.Count > 0)
  57. {
  58. foreach (DataRow row in dt.Rows)
  59. {
  60. if (band.Columns.IndexOf(row[0].ToString()) < 0)
  61. {
  62. band.Columns.Add(row[0].ToString(), row[1].ToString());
  63. }
  64. else
  65. {
  66. band.Columns[row[0].ToString()].Header.Caption = row[1].ToString();
  67. }
  68. }
  69. }
  70. }
  71. /// <summary>
  72. ///byWenCheng 执行sql语句
  73. /// </summary>
  74. /// <param name="sqlString"></param>
  75. /// <param name="_ob"></param>
  76. /// <returns></returns>
  77. public static System.Data.DataTable GetDataBySql(string sqlString, CoreFS.CA06.OpeBase _ob)
  78. {
  79. return Core.Mes.Client.Comm.Server.ServerHelper.GetData("com.steering.pss.plnsaleord.ordAmCal.OrderDemo.getDataBySql", new Object[] { sqlString }, _ob);
  80. }
  81. /// <summary>
  82. ///byWenCheng 设置某band的所有列不可编辑,除了ignoreColums里包含的列
  83. /// </summary>
  84. /// <param name="band">需要设置的band</param>
  85. /// <param name="ignoreColums">需要忽略的列</param>
  86. public static void SetGridColNoEdit(Infragistics.Win.UltraWinGrid.UltraGridBand band, string[] ignoreColums)
  87. {
  88. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in band.Columns)
  89. {
  90. if (ignoreColums.Length > 0 && !string.IsNullOrEmpty(ignoreColums.FirstOrDefault(c => c == col.Key)))
  91. {
  92. col.CellAppearance.BackColor = System.Drawing.Color.Yellow;
  93. continue;
  94. }
  95. col.CellActivation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  96. }
  97. }
  98. /// <summary>
  99. /// byWenCheng,复制数据到数据表,暂未测试速率,目前发现在查询数据时比较耗时,2000条数据2-3s
  100. /// </summary>
  101. /// <param name="srcDt"></param>
  102. /// <param name="desDt"></param>
  103. /// <param name="ClearExsit"></param>
  104. public static void CopyDatabyDatatable(System.Data.DataTable srcDt, System.Data.DataTable desDt, bool ClearExsit)
  105. {
  106. if (srcDt.Rows.Count <= 0)
  107. {
  108. return;
  109. }
  110. if (ClearExsit)
  111. {
  112. desDt.Rows.Clear();
  113. }
  114. foreach (DataRow row in srcDt.Rows)
  115. {
  116. desDt.LoadDataRow(row.ItemArray, false);
  117. }
  118. }
  119. /// <summary>
  120. ///byWenCheng 设置列宽根据内容自适应方法1
  121. /// </summary>
  122. /// <param name="band">需要设置的band</param>
  123. public static void SetColumnAutoFitSize1(UltraGridBand band)
  124. {
  125. if (band != null)
  126. {
  127. band.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand,true);
  128. }
  129. }
  130. /// <summary>
  131. ///byWenCheng 设置列宽根据内容自适应方法2
  132. /// </summary>
  133. /// <param name="band">需要设置的band</param>
  134. public static void SetColumnAutoFitSize2(UltraGridBand band)
  135. {
  136. if (band != null)
  137. {
  138. foreach (UltraGridColumn col in band.Columns)
  139. {
  140. col.PerformAutoResize(PerformAutoSizeType.AllRowsInBand,true);
  141. }
  142. }
  143. }
  144. /// <summary>
  145. ///byWenCheng 设置行高根据内容自适应
  146. /// </summary>
  147. /// <param name="grid"></param>
  148. public static void SetRowAutoFitSize(UltraGrid grid)
  149. {
  150. if (grid != null)
  151. {
  152. grid.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
  153. }
  154. }
  155. /// <summary>
  156. ///byWenCheng 获取grid的激活的行,如果该行有对应的父行,则取其父行。和selected选择的行有区别的是,selectedrow是可以有多行,activedrow只能是一行,而且一般是最后选择的那一行
  157. /// </summary>
  158. /// <param name="grid"></param>
  159. /// <returns></returns>
  160. public static UltraGridRow GetActiveRow(UltraGrid grid)
  161. {
  162. if (grid == null || grid.ActiveRow == null)
  163. {
  164. return null;
  165. }
  166. UltraGridRow ugr = grid.ActiveRow;
  167. if (ugr.HasParent())
  168. {
  169. ugr = ugr.ParentRow;
  170. }
  171. return ugr;
  172. }
  173. /// <summary>
  174. /// byWencheng,获取小数点后指定位数的double值
  175. /// </summary>
  176. /// <param name="dsrc">源double</param>
  177. /// <param name="nBit">指定小数点后的位数</param>
  178. /// <returns>结果值</returns>
  179. public static double GetSpecDecimalBit(double dsrc, int nBit)
  180. {
  181. return Convert.ToDouble(dsrc.ToString(string.Format("f{0}", nBit)));
  182. }
  183. /// <summary>
  184. /// 往指定位置插入一列,原来在这个位置上的列会被交换到末尾
  185. /// </summary>
  186. /// <param name="key"></param>
  187. /// <param name="caption"></param>
  188. /// <param name="band"></param>
  189. /// <param name="index"></param>
  190. /// <returns></returns>
  191. public static Infragistics.Win.UltraWinGrid.UltraGridColumn InsertColumn(string key, string caption, Infragistics.Win.UltraWinGrid.UltraGridBand band, int index)
  192. {
  193. Infragistics.Win.UltraWinGrid.UltraGridColumn col = band.Columns.Add(key, caption);
  194. band.Columns[index].Swap(col);
  195. //SetColumnPosition(band, key, index);
  196. return col;
  197. }
  198. /// <summary>
  199. /// 设置列隐藏
  200. /// </summary>
  201. /// <param name="band"></param>
  202. /// <param name="columnList"></param>
  203. public static void SetColumsHide(Infragistics.Win.UltraWinGrid.UltraGridBand band, List<string> columnList)
  204. {
  205. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in band.Columns)
  206. {
  207. if (columnList.Contains(col.Key))
  208. {
  209. col.Hidden = true;
  210. }
  211. }
  212. }
  213. public static bool IsNullOrEmptry(string srcString)
  214. {
  215. if ((srcString + "").Length == 0)
  216. {
  217. return true;
  218. }
  219. return false;
  220. }
  221. public static string getProcessCode(string CustomInfo)
  222. {
  223. string strResult = "";
  224. switch (CustomInfo)
  225. {
  226. case CustomInfoDef.DEFINE_CUSTOMER_DBK: strResult = "E"; break;
  227. case CustomInfoDef.DEFINE_CUSTOMER_JG: strResult = "G"; break;
  228. case CustomInfoDef.DEFINE_CUSTOMER_RCL: strResult = "F"; break;
  229. case CustomInfoDef.DEFINE_CUSTOMER_ZG: strResult = "D"; break;
  230. }
  231. return strResult;
  232. }
  233. public static string getProcessDesc(string CustomInfo)
  234. {
  235. string strResult = "";
  236. switch (CustomInfo)
  237. {
  238. case CustomInfoDef.DEFINE_CUSTOMER_DBK: strResult = "镦拔扩"; break;
  239. case CustomInfoDef.DEFINE_CUSTOMER_JG: strResult = "加工线"; break;
  240. case CustomInfoDef.DEFINE_CUSTOMER_RCL: strResult = "热处理"; break;
  241. case CustomInfoDef.DEFINE_CUSTOMER_ZG: strResult = "轧管"; break;
  242. }
  243. return strResult;
  244. }
  245. #region 私有的一些算法
  246. /// <summary>
  247. /// 求计划切后重量
  248. /// </summary>
  249. /// <param name="WALLTHICK">壁厚</param>
  250. /// <param name="OUTDIAMETER">外径</param>
  251. /// <param name="AIMLENGTH_CUT">切后目标长度</param>
  252. /// <param name="CUT_OUT_NUM">计划切后支数</param>
  253. /// <returns></returns>
  254. public static double GetCutOutWeight(Object WALLTHICK, Object OUTDIAMETER, Object AIMLENGTH_CUT, Object CUT_OUT_NUM)
  255. {
  256. double result = 0;
  257. try
  258. {
  259. double dWallThick = Convert.ToDouble(WALLTHICK);
  260. double dOutDiamEter = Convert.ToDouble(OUTDIAMETER);
  261. double dAimlenthCut = Convert.ToDouble(AIMLENGTH_CUT);
  262. double dCutOutNum = Convert.ToDouble(CUT_OUT_NUM);
  263. double WtPerMile = PlanComm.WeightOfMi(dOutDiamEter, dWallThick);
  264. //0.02466 * dWallThick * (dOutDiamEter - dWallThick);
  265. result = WtPerMile * dAimlenthCut * dCutOutNum;
  266. result = CommHelper.GetSpecDecimalBit(result, 3);
  267. }
  268. catch
  269. {
  270. }
  271. return result;
  272. }
  273. /// <summary>
  274. /// 获取作业计划表表名
  275. /// </summary>
  276. /// <returns></returns>
  277. public static string GetZYMtablename(string CustomInfo)
  278. {
  279. string tablename = "";
  280. switch (CustomInfo)
  281. {
  282. case CustomInfoDef.DEFINE_CUSTOMER_DBK: tablename = "PLN_ZY_DBK_M"; break;
  283. case CustomInfoDef.DEFINE_CUSTOMER_RCL: tablename = "PLN_ZY_RCL_M"; break;
  284. case CustomInfoDef.DEFINE_CUSTOMER_JG: tablename = "PLN_ZY_JGX_M"; break;
  285. case CustomInfoDef.DEFINE_CUSTOMER_ZG: tablename = "PLN_ZY_ZG_M"; break;
  286. }
  287. return tablename;
  288. }
  289. public static string GetOrdertableName(string CustomInfo)
  290. {
  291. string tablename = "";
  292. switch (CustomInfo)
  293. {
  294. case CustomInfoDef.DEFINE_CUSTOMER_DBK: tablename = "PLN_ORDER_DBK_S"; break;
  295. case CustomInfoDef.DEFINE_CUSTOMER_JG: tablename = "PLN_ORDER_JGX_S"; break;
  296. case CustomInfoDef.DEFINE_CUSTOMER_RCL: tablename = "PLN_ORDER_RCL_S"; break;
  297. case CustomInfoDef.DEFINE_CUSTOMER_ZG: tablename = "PLN_ORDER_ZG_S"; break;
  298. }
  299. return tablename;
  300. }
  301. public static void init_Zy_Col(UltraGridBand band)
  302. {
  303. CommHelper.SetColumnPosition(band, "PlineName", 1);
  304. CommHelper.SetColumnPosition(band, "OrderNo", 2);
  305. CommHelper.SetColumnPosition(band, "OrderSeq", 3);
  306. CommHelper.SetColumnPosition(band, "ProPlanId", 4);
  307. CommHelper.SetColumnPosition(band, "GxPlanNo", 5);
  308. CommHelper.SetColumnPosition(band, "HeatPlanNo", 6);
  309. CommHelper.SetColumnPosition(band, "HeatnoLast", 7);
  310. CommHelper.SetColumnPosition(band, "ZgBatchNo", 8);
  311. CommHelper.SetColumnPosition(band, "LastBatchNo", 8);
  312. CommHelper.SetColumnPosition(band, "BatchGroudNo", 9);
  313. CommHelper.SetColumnPosition(band, "OrderSource", 10);
  314. CommHelper.SetColumnPosition(band, "OutNum", 11);
  315. CommHelper.SetColumnPosition(band, "OutWt", 12);
  316. CommHelper.SetColumnPosition(band, "InNum", 13);
  317. CommHelper.SetColumnPosition(band, "InWt", 14);
  318. CommHelper.SetColumsHide(band, new List<string>() { "PlineCode", "InwlId" });
  319. band.Columns["OrderSource"].Header.Caption = "主合同来源";
  320. band.Columns["Planstatus"].Header.Caption = "执行状态";
  321. }
  322. /// <summary>
  323. /// 管坯米单重=(7.8*3.1415926/4*直径*直径)/1000/1000
  324. /// </summary>
  325. /// <param name="DIAMETER_GP">管坯直径</param>
  326. /// <returns></returns>
  327. public static double GetCutSingleWtPerMile(Object DIAMETER_GP)
  328. {
  329. double dRet = 0;
  330. try
  331. {
  332. double dEtergp = Convert.ToDouble(DIAMETER_GP);
  333. dRet = PlanComm.GpweightOfmi(dEtergp);
  334. dRet = CommHelper.GetSpecDecimalBit(dRet, 3);
  335. }
  336. catch
  337. {
  338. }
  339. return dRet;
  340. }
  341. /// <summary>
  342. /// 计划单倍坯支数=计划产出支数/分切数
  343. /// </summary>
  344. /// <param name="OUT_NUM">计划产出支数</param>
  345. /// <param name="OUTNUM_CUT">分切数</param>
  346. /// <returns></returns>
  347. public static int GetCutSingleNum(Object OUT_NUM, Object OUTNUM_CUT)
  348. {
  349. int nRet = 0;
  350. try
  351. {
  352. int dOutnum = Convert.ToInt32(OUT_NUM);
  353. int dOutnumCut = Convert.ToInt32(OUTNUM_CUT);
  354. nRet = dOutnum / dOutnumCut;
  355. }
  356. catch
  357. {
  358. }
  359. return nRet;
  360. }
  361. /// <summary>
  362. /// CUT_SINGLE_WT计划单倍坯重量 = 计划单倍坯支数*管坯单重
  363. /// </summary>
  364. /// <returns></returns>
  365. public static double GetCutSingleWt(Object CUT_SINGLE_NUM, double CutSingleWtPerMile)
  366. {
  367. double dRet = 0;
  368. try
  369. {
  370. int nCutSinleNum = Convert.ToInt32(CUT_SINGLE_NUM);
  371. dRet = nCutSinleNum * CutSingleWtPerMile;
  372. dRet = CommHelper.GetSpecDecimalBit(dRet, 3);
  373. }
  374. catch
  375. {
  376. }
  377. return dRet;
  378. }
  379. /// <summary>
  380. /// 倍尺数=管坯长度/单倍坯长(取整)
  381. /// </summary>
  382. /// <param name="LENGTH_GP">管坯长度(m)</param>
  383. /// <param name="LEN_GP_SINGLE">单倍坯长mm</param>
  384. /// <returns></returns>
  385. public static int GetMultipleNum(Object LENGTH_GP, Object LEN_GP_SINGLE)
  386. {
  387. int nRet = 0;
  388. try
  389. {
  390. double dlenthgp = Convert.ToDouble(LENGTH_GP);
  391. double dlengpsingle = Convert.ToDouble(LEN_GP_SINGLE)/1000;
  392. nRet = Convert.ToInt32(Math.Truncate(dlenthgp / dlengpsingle));
  393. }
  394. catch
  395. {
  396. }
  397. return nRet;
  398. }
  399. /// <summary>
  400. /// 获取轧管的计划投入重量=ACT_WEIGHT--重量/ ACT_COUNT,--支数 * 计划投入支数
  401. /// </summary>
  402. /// <param name="ACT_WEIGHT"></param>
  403. /// <param name="ACT_COUNT"></param>
  404. /// <param name="IN_GP_NUM"></param>
  405. /// <returns></returns>
  406. public static double GetIN_GP_WT(Object ACT_WEIGHT, Object ACT_COUNT, Object IN_GP_NUM)
  407. {
  408. double nRet = 0;
  409. try
  410. {
  411. double bActWt = Convert.ToDouble(ACT_WEIGHT);
  412. int nActCount = Convert.ToInt32(ACT_COUNT);
  413. int nInGpNum = Convert.ToInt32(IN_GP_NUM);
  414. nRet = CommHelper.GetSpecDecimalBit(nInGpNum * (bActWt / nActCount), 3);
  415. }
  416. catch
  417. {
  418. }
  419. return nRet;
  420. }
  421. /// <summary>
  422. /// OUT_WT 计划产出重量= 排产重量/排产支数*用户输入支数
  423. /// </summary>
  424. /// <param name="InNum">用户输入支数</param>
  425. /// <param name="WeigthS">排产重量</param>
  426. /// <param name="NumS">排产支数</param>
  427. /// <returns></returns>
  428. public static double GetOutWeight(Object InNum, Object WeigthS, Object NumS)
  429. {
  430. double result = 0;
  431. double SingleWeight = Convert.ToDouble(WeigthS) / Convert.ToDouble(NumS);
  432. result = Convert.ToDouble(InNum) * SingleWeight;
  433. result = CommHelper.GetSpecDecimalBit(result, 3);
  434. return result;
  435. }
  436. #endregion
  437. }
  438. }