WmsUI.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DbCommon.Enties.DbModels;
  11. using ProjectManagementSystem.Common.Function;
  12. using DbCommon.BusinessCore.BaseCore;
  13. using ProjectManagementSystem.Common.Config;
  14. using ProjectManagementSystem.Common.Models;
  15. using ProjectManagementSystem.Common.Logger;
  16. using ProjectManagementSystem.Common.WebApi;
  17. using ProjectManagementSystem.Common.Extenions;
  18. using Pms.DataLibrary.Order;
  19. namespace ProjectManagementSystem.UI
  20. {
  21. public partial class WmsUI : UserControl, IDisplayUI
  22. {
  23. private LocationPropertyManager locationManager;
  24. private WareHouseManager wareHouseManager;
  25. public WmsUI()
  26. {
  27. InitializeComponent();
  28. }
  29. public bool Init()
  30. {
  31. areaUI1.OnLocationSelected += AreaUI1_OnLocationSelected;
  32. if (!areaUI1.Init()
  33. || !InitTaskUI())
  34. {
  35. return false;
  36. }
  37. return true;
  38. }
  39. public void UpdateDisplay()
  40. {
  41. areaUI1.UpdateDisplay();
  42. }
  43. private void AreaUI1_OnLocationSelected(object arg1, LocationProperty arg2)
  44. {
  45. UpdateUpMaterial(arg2);
  46. }
  47. public bool InitTaskUI()
  48. {
  49. try
  50. {
  51. locationManager = new LocationPropertyManager();
  52. wareHouseManager = new WareHouseManager();
  53. string filter = AppSetting.TryGetValue<string>("WareHouseFilter1");
  54. DataTable dt = null;
  55. if (string.IsNullOrEmpty(filter))
  56. {
  57. dt = locationManager.QueryAreaDistinct();
  58. //dt = wareHouseManager.QueryWareHouse();
  59. }
  60. else if (filter.Contains("|"))
  61. {
  62. var filters = filter.Split(new char[] { '|' });
  63. dt = locationManager.QueryAreaDistinct(filters);
  64. //dt = wareHouseManager.QueryWareHouse(filters);
  65. }
  66. else
  67. {
  68. //没有分割符时,使用模糊查询
  69. dt = locationManager.QueryAreaDistinct(filter);
  70. //dt = wareHouseManager.QueryWareHouse(filter);
  71. }
  72. if (dt == null)
  73. {
  74. return false;
  75. }
  76. //this.comboBox1.ValueMember = "WareHouseCode";
  77. //this.comboBox1.DisplayMember = "WareHouseName";
  78. this.comboBox1.ValueMember = "Area";
  79. this.comboBox1.DisplayMember = "Area";
  80. this.comboBox1.DataSource = dt;
  81. }
  82. catch (Exception ex)
  83. {
  84. if (ex.Message.Contains("连接数据库"))
  85. {
  86. MessageBox.Show("连接数据库失败,请检查网络通讯!");
  87. }
  88. else
  89. {
  90. MessageBox.Show(ex.Message);
  91. }
  92. return false;
  93. }
  94. InitTaskButton();
  95. ClearLabText();
  96. return true;
  97. }
  98. private void InitTaskButton()
  99. {
  100. var taskButtonArray = AppSetting.TryGetValue<string>("TaskButton").ToValueArray<string>();
  101. foreach (var item in this.panel4.Controls)
  102. {
  103. var btn = item as Button;
  104. if (btn == null)
  105. {
  106. continue;
  107. }
  108. btn.Visible = taskButtonArray.Contains(btn.Text) ? true : false;
  109. }
  110. }
  111. private void ClearLabText()
  112. {
  113. labUpArea.Text = string.Empty;
  114. labUpWareHouse.Text = string.Empty;
  115. labUpLocation.Text = string.Empty;
  116. labUpMaterial.Text = string.Empty;
  117. //labFilled.Text = string.Empty;
  118. //labEmpty.Text = string.Empty;
  119. //labLocked.Text = string.Empty;
  120. //labLineCall.Text = string.Empty;
  121. //labFilled.AutoSize = false;
  122. //labEmpty.AutoSize = false;
  123. //labLocked.AutoSize = false;
  124. //labLineCall.AutoSize = false;
  125. //labFilled.BackColor = ColorSetting.Instance.GetColor(LocationStatus.Filled);
  126. //labEmpty.BackColor = ColorSetting.Instance.GetColor(LocationStatus.Empty);
  127. //labLocked.BackColor = ColorSetting.Instance.GetColor(LocationStatus.Locked);
  128. //labLineCall.BackColor = ColorSetting.Instance.GetColor(LocationStatus.LineCall);
  129. }
  130. public void UpdateUpMaterial(LocationProperty row)
  131. {
  132. labUpArea.Text = row.Area;
  133. labUpWareHouse.Text = row.WareHouseCode;
  134. labUpLocation.Text = row.LocationCode;
  135. labUpMaterial.Text = row.MaterialId;
  136. }
  137. private void ShowMsg(string text)
  138. {
  139. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  140. }
  141. private void ShowErrMsg(string text)
  142. {
  143. MessageBox.Show(text, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  144. }
  145. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  146. {
  147. areaUI1.CurrentWareHouseCode = comboBox1.SelectedValue.ToString();
  148. }
  149. private LocationProperty GetCheckLocation(bool checkLocked = true)
  150. {
  151. string location = labUpLocation.Text;
  152. if (string.IsNullOrEmpty(location))
  153. {
  154. ShowErrMsg("叫料点检查异常");
  155. return null;
  156. }
  157. var ulocationData = locationManager.GetById(location);
  158. if (ulocationData == null)
  159. {
  160. ShowErrMsg("查询叫料点库位数据失败");
  161. return null;
  162. }
  163. if (checkLocked
  164. && ulocationData.Status == LocationStatus.Locked)
  165. {
  166. ShowErrMsg("叫料点库位已锁定");
  167. return null;
  168. }
  169. return ulocationData;
  170. }
  171. private void button1_Click(object sender, EventArgs e)
  172. {
  173. var locationData = GetCheckLocation();
  174. if (locationData == null) return;
  175. var wData = wareHouseManager.GetById(locationData.WareHouseCode);
  176. if (string.IsNullOrEmpty(wData?.SourceWareHouseCode))
  177. {
  178. ShowErrMsg("该位置不能叫料");
  179. return;
  180. }
  181. using (Forms.FormPmsTaskInfo setting = new Forms.FormPmsTaskInfo())
  182. {
  183. setting.Init(sender, locationData);
  184. setting.ShowDialog();
  185. }
  186. }
  187. private void button2_Click(object sender, EventArgs e)
  188. {
  189. var locationData = GetCheckLocation();
  190. if (locationData == null) return;
  191. var wData = wareHouseManager.GetById(locationData.WareHouseCode);
  192. if (string.IsNullOrEmpty(wData?.TargetWareHouseCode))
  193. {
  194. ShowErrMsg("该位置不能转运");
  195. return;
  196. }
  197. using (Forms.FormPmsTaskInfo setting = new Forms.FormPmsTaskInfo())
  198. {
  199. setting.Init(sender, locationData);
  200. setting.ShowDialog();
  201. }
  202. }
  203. private void button3_Click(object sender, EventArgs e)
  204. {
  205. var locationData = GetCheckLocation(false);
  206. if (locationData == null) return;
  207. var wData = wareHouseManager.GetById(locationData.WareHouseCode);
  208. if (string.IsNullOrEmpty(wData?.SourceWareHouseCode))
  209. {
  210. ShowErrMsg("该位置不能叫料");
  211. return;
  212. }
  213. using (Forms.FormPmsTaskInfo setting = new Forms.FormPmsTaskInfo())
  214. {
  215. setting.Init(sender, locationData);
  216. setting.ShowDialog();
  217. }
  218. }
  219. private void button4_Click(object sender, EventArgs e)
  220. {
  221. var locationData = GetCheckLocation(false);
  222. if (locationData == null) return;
  223. var wData = wareHouseManager.GetById(locationData.WareHouseCode);
  224. if (string.IsNullOrEmpty(wData?.TargetWareHouseCode))
  225. {
  226. ShowErrMsg("该位置不能转运");
  227. return;
  228. }
  229. using (Forms.FormPmsTaskInfo setting = new Forms.FormPmsTaskInfo())
  230. {
  231. setting.Init(sender, locationData);
  232. setting.ShowDialog();
  233. }
  234. }
  235. private void button5_Click(object sender, EventArgs e)
  236. {
  237. var locationData = GetCheckLocation(false);
  238. if (locationData == null) return;
  239. try
  240. {
  241. string text = $"确定要手动放行AGV? 库位:{locationData.LocationCode}";
  242. var dialogResult = MessageBox.Show(text, "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  243. if (dialogResult != DialogResult.OK)
  244. {
  245. return;
  246. }
  247. var result = PmsApi.CustomApiPost("ReleaseAgv", null, new { LocationCode = locationData.LocationCode });
  248. if (result?.code == 20000)
  249. {
  250. ShowMsg($"操作成功,{result?.message}");
  251. }
  252. else
  253. {
  254. ShowErrMsg($"操作失败,{result?.message}");
  255. }
  256. }
  257. catch (Exception ex)
  258. {
  259. ShowErrMsg($"操作异常:{ex.Message}");
  260. }
  261. }
  262. }
  263. }