frmCalibration.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using com.hnshituo.core.webapp.vo;
  2. using Common;
  3. using Infragistics.Win;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace StorageMeterSystem
  14. {
  15. public partial class frmCalibration : Form
  16. {
  17. public frmCalibration()
  18. {
  19. InitializeComponent();
  20. }
  21. Log lg = Log.GetInstance();
  22. //校秤主
  23. MeterWorkCalibrationMainService calibrationMainService = new MeterWorkCalibrationMainService();
  24. //校秤从
  25. MeterWorkCalibrationBranchService calibrationBranchService = new MeterWorkCalibrationBranchService();
  26. MeterBaseMutualDiffService mutualDiffService = new MeterBaseMutualDiffService();//互检差值
  27. ComBaseInfoService cis = new ComBaseInfoService();
  28. MeterWorkCalibrationBranch calibrationBranch { get; set; }
  29. public string userId = "", userName = "";
  30. private void timer1_Tick(object sender, EventArgs e)
  31. {
  32. txtWgt.Value = (decimal)Math.Round(PbStorageCache.collect.mainWgt, 1);
  33. }
  34. private void btnClose_Click(object sender, EventArgs e)
  35. {
  36. this.Close();
  37. }
  38. private void btnSave_Click(object sender, EventArgs e)
  39. {
  40. lbMsgInfo.Visible = false;
  41. if (cbCalibrationType.Value == null || cbCalibrationType.Text.Trim() == "")
  42. {
  43. MessageBox.Show("请选择校秤类型");
  44. return;
  45. }
  46. if (cbCalibrationType.Value != null && cbCalibrationType.Value.ToString() == "001005002")
  47. {
  48. if (cbWorkMonitor.Value == null || cbWorkMonitor.Text.Trim() == "")
  49. {
  50. MessageBox.Show("请选择对比计量点");
  51. return;
  52. }
  53. }
  54. DialogResult dr = MessageBox.Show("确认进行校秤吗?", "提示", MessageBoxButtons.OKCancel);
  55. if (dr == DialogResult.OK)
  56. {
  57. btnSave.Enabled = false;
  58. string baseContrastNo = PbStorageCache.sportInfo.baseSpotNo;
  59. string baseContrastName = PbStorageCache.sportInfo.baseSpotName;
  60. string dbWgt = PbStorageCache.collect.mainWgt + "";
  61. if (calibrationBranch != null)
  62. {
  63. baseContrastNo = calibrationBranch.baseSpotNo;
  64. baseContrastName = calibrationBranch.baseSpotName;
  65. dbWgt = calibrationBranch.calibrationWeight;
  66. }
  67. RESTfulResult<MeterWorkCalibrationBranch> rm = calibrationMainService.doSaveWf(
  68. new MeterWorkCalibrationMain
  69. {
  70. baseSpotNo = baseContrastNo,
  71. baseSpotName = baseContrastName,
  72. spotTypeNo = cbSpotType.Value == null ? "001002003" : cbSpotType.Value.ToString().Trim(),
  73. spotTypeName = cbSpotType.Text == "" ? "成品秤" : cbSpotType.Text.Trim(),
  74. calibrationTypeNo = cbCalibrationType.Value == null ? "" : cbCalibrationType.Value.ToString().Trim(),
  75. calibrationTypeName = cbCalibrationType.Text,
  76. baseContrastSpotNo = cbWorkMonitor.Value == null ? "" : cbWorkMonitor.Value.ToString().Trim(),
  77. baseContrastSpotName = cbWorkMonitor.Text.Trim()
  78. },
  79. new MeterWorkCalibrationBranch
  80. {
  81. baseSpotNo = baseContrastNo,
  82. baseSpotName = baseContrastName,
  83. calibrationWeight = dbWgt + "",
  84. spotTypeNo = cbSpotType.Value == null ? "001002003" : cbSpotType.Value.ToString().Trim(),
  85. spotTypeName = cbSpotType.Text == "" ? "成品秤" : cbSpotType.Text.Trim(),
  86. calibrationTypeNo = cbCalibrationType.Value == null ? "" : cbCalibrationType.Value.ToString().Trim(),
  87. calibrationTypeName = cbCalibrationType.Text,
  88. createManNo = userId,
  89. createManName = userName
  90. }
  91. );
  92. if (rm.Succeed)
  93. {
  94. #region 截取图片信息
  95. try
  96. {
  97. calibrationBranch = rm.Data;
  98. //*
  99. //截取屏幕信息
  100. Point screenPoint = this.PointToScreen(new Point());
  101. Rectangle rect = new Rectangle(screenPoint, this.Size);
  102. Image img = new Bitmap(rect.Width, rect.Height);
  103. Graphics g = Graphics.FromImage(img);
  104. g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
  105. img.Save(string.Format("{0}imgShort\\tempImg\\{1}_{2}_{3}.jpg",
  106. AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  107. PbStorageCache.sportInfo.baseSpotNo,
  108. "S" + rm.Message,
  109. (PbStorageCache.videoChild.Count + 1)), System.Drawing.Imaging.ImageFormat.Jpeg);
  110. //循环摄像头,然后根据摄像头有多少,则取硬盘录像机多少个通道数据
  111. for (uint i = 1; i <= CarCache.cameraShots.Count; i++)
  112. {
  113. cameraShotMain.CapPicFromVideo(i,
  114. string.Format("{0}\\imgShort\\formalImg\\{1}_{2}_{3}",
  115. AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  116. PbStorageCache.sportInfo.baseSpotNo,
  117. "S" + rm.Message, i)
  118. );
  119. }
  120. /*
  121. //最后进行截图操作
  122. CameraShotCls cameraShot = new CameraShotCls();
  123. cameraShot.CapMethod(rm.Message);
  124. //*/
  125. }
  126. catch (Exception ex)
  127. {
  128. lg.WriteLog(5, PbStorageCache.sportInfo.baseSpotName + "校秤截图失败");
  129. }
  130. #endregion
  131. if (rm.Data == null || string.IsNullOrEmpty(rm.Data.baseSpotNo))
  132. {
  133. this.DialogResult = DialogResult.OK;
  134. this.Close(); //校秤成功了,可能是单点通过,可能是同时通过
  135. }
  136. else //说明是单点校秤然后失败了,此时提醒选择下一个对比校秤点
  137. {
  138. cbWorkMonitor.Enabled = true;
  139. cbCalibrationType.Enabled = true;
  140. lbMsgInfo.Visible = true;
  141. btnSave.Enabled = true;
  142. }
  143. }
  144. else
  145. {
  146. MessageBox.Show("校秤异常:" + rm.Message);
  147. btnSave.Enabled = true;
  148. }
  149. }
  150. }
  151. public CameraShotCls cameraShotMain { get; set; }
  152. private void frmCalibration_FormClosing(object sender, FormClosingEventArgs e)
  153. {
  154. timer1.Stop();
  155. }
  156. private void frmCalibration_Load(object sender, EventArgs e)
  157. {
  158. timer1.Start();
  159. ValueList vlistSpot = new ValueList();
  160. vlistSpot.ValueListItems.Add("001002003", "成品秤");
  161. cbSpotType.ValueList = vlistSpot;
  162. cbSpotType.Value = "001002003";
  163. cbSpotType.Enabled = false;
  164. //校秤类型
  165. RESTfulResult<List<PbModelDb>> rm = cis.doQueryWf(new ComBaseInfo { pBaseCode = "001005" });
  166. ValueList vlistCalibration = new ValueList();
  167. foreach (PbModelDb pb in rm.Data)
  168. {
  169. vlistCalibration.ValueListItems.Add(pb.id, pb.text);
  170. }
  171. cbCalibrationType.ValueList = vlistCalibration;
  172. RESTfulResult<List<MeterWorkCalibrationBranch>> rmMwcb = calibrationBranchService.doQueryWf(new MeterWorkCalibrationBranch { baseSpotNo = PbStorageCache.sportInfo.baseSpotNo });
  173. if (rmMwcb.Succeed)
  174. {
  175. if (rmMwcb.Data != null && rmMwcb.Data.Count > 0)
  176. {
  177. cbCalibrationType.Value = rmMwcb.Data[0].calibrationTypeNo;
  178. cbWorkMonitor.Value = rmMwcb.Data[0].baseSpotNo;
  179. cbCalibrationType.Enabled = false;
  180. cbWorkMonitor.Enabled = false;
  181. }
  182. }
  183. }
  184. private void cbCalibrationType_SelectionChanged(object sender, EventArgs e)
  185. {
  186. //互检
  187. if (cbCalibrationType.Value != null && cbCalibrationType.Value.ToString() == "001005002")
  188. {
  189. label1.Visible = true;
  190. cbWorkMonitor.Visible = true;
  191. RESTfulResult<List<MeterBaseMutualDiff>> rm = mutualDiffService.doQueryWf(new MeterBaseMutualDiff { baseSpotOneNo = PbStorageCache.sportInfo.baseSpotNo });
  192. if (rm.Data == null || rm.Data.Count == 0)
  193. {
  194. MessageBox.Show("互检差值表未配置当前计量点对应的互检计量点数据");
  195. return;
  196. }
  197. ValueList vlist = new ValueList();
  198. foreach (MeterBaseMutualDiff diff in rm.Data)
  199. {
  200. vlist.ValueListItems.Add(diff.baseSpotOneNo, diff.baseSpotOneName);
  201. }
  202. cbWorkMonitor.ValueList = vlist;
  203. }
  204. else
  205. {
  206. cbWorkMonitor.SelectedIndex = -1;
  207. cbWorkMonitor.ValueList = null;
  208. label1.Visible = false;
  209. cbWorkMonitor.Visible = false;
  210. }
  211. }
  212. }
  213. }