using AUCMA.STORE.Business.Implements; using AUCMA.STORE.Business.Interface; using AUCMA.STORE.Common; using AUCMA.STORE.Entity.DAO; using AUCMA.STORE.Entity.DTO; using AUCMA.STORE.Entity.Enums; using AUCMA.STORE.SqlSugar.serviceImpl; using AutoMapper; using HslCommunication; using HslCommunication.Core; using HslCommunication.Profinet.Siemens; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using System.Web.UI.WebControls; using System.Windows.Forms; using Button = System.Windows.Forms.Button; using Label = System.Windows.Forms.Label; namespace AUCMA.STORE { public partial class UnLockStoreLocationInfo : Form { SiemensS7Net s7; SiemensS7Net RGV_s7; private static PLCAddressTypeDTO[] WriteOnePilerPlcAddress = new PLCAddressTypeDTO[20]; private static PLCAddressTypeDTO[] ReadOnePilerPlcAddress = new PLCAddressTypeDTO[20]; private static PLCAddressTypeDTO[] WriteRGVPlcAddress = new PLCAddressTypeDTO[6]; //private static PLCAddressTypeDTO[] WriteSouthRGVPlcAddress = new PLCAddressTypeDTO[6]; private static PLCAddressTypeDTO[] ReadRGVPlcAddress = new PLCAddressTypeDTO[5]; //private static PLCAddressTypeDTO[] ReadSouthRGVPlcAddress = new PLCAddressTypeDTO[5]; private static PLCAddressTypeDTO[] UpLoadPilerPlcSignal = new PLCAddressTypeDTO[2]; private static PLCAddressTypeDTO[] UpLoadRGVPlcSignal = new PLCAddressTypeDTO[2]; private static PLCAddressTypeDTO[] UpLoadBarCodeSignal = new PLCAddressTypeDTO[2]; private static PLCAddressTypeDTO[] PLCHeartSendPackSignal = new PLCAddressTypeDTO[3]; private static PLCAlarmInfoDTO[] PilerPlcAlarmSignal = new PLCAlarmInfoDTO[32]; private static INIFile iNIFile = new INIFile(System.Environment.CurrentDirectory + "/PlcAddress/PlcAddress.InI"); public static string m_StoreCode = ConfigHelper.GetConfig("storeCode"); public String PilerInfo = ""; private string PlcCode = ""; public TaskType TaskType = TaskType.InStore; private System.Net.IPAddress address; public InStoreForm inStoreForm = null; private static IInStoreBusiness inStoreBusiness = new InStoreBusinessImpl(); private static IOutStoreBusiness outStoreBusiness = new OutStoreBusinessImpl(); private static IBaseTaskQueueBusiness baseTaskQueueBusiness = new BaseTaskQueueBusiness(); LocationArea locationArea = LocationArea.Location_NoCare; private string Area = ""; private IByteTransform byteTransform = new RegularByteTransform(); public UnLockStoreLocationInfo() { InitializeComponent(); tabControl1.Font = new Font("宋体", 18); this.StartPosition = FormStartPosition.CenterScreen; this.WindowState = FormWindowState.Maximized; //最大化窗体 } private void OutStore_Load(object sender, EventArgs e) { this.MaximizeBox = false; this.MinimizeBox = false; //inStoreForm.iFlag = true; if (m_StoreCode != "A" && m_StoreCode != "B") { m_StoreCode = "A"; } flowLayoutPanel1.AutoScroll = true; flowLayoutPanel2.AutoScroll = true; flowLayoutPanel1.BackColor = Color.FromArgb(3, 27, 61); flowLayoutPanel2.BackColor = Color.FromArgb(3, 27, 61); LoadPilerInfo(); LoadStoreInfo(); } private void LoadPilerInfo() { try { if (PilerInfo == "1") { locationArea = LocationArea.Location_Left; Area = "左"; } else { locationArea = LocationArea.Location_Right; Area = "右"; } } catch (Exception ex) { } } /// /// 库位展示 /// private async void LoadStoreInfo() { try { Expression> exp = s1 => true; Expression> order = (x) => x.Ordernum; exp = exp.And(s1 => s1.locationArea == locationArea && s1.storeCode == ConfigHelper.GetConfig("storeCode")); List locations = await new BaseServices().Query(exp, order, true); //var info = locations.OrderBy(x => x.remark).ToList(); locations.Add(new BaseLocationInfo("1-1-1", 1, 1, 1)); locations.Add(new BaseLocationInfo("1-1-2", 1, 1, 2)); locations.Add(new BaseLocationInfo("2-1-1", 2, 1, 1)); locations.Add(new BaseLocationInfo("2-1-2", 2, 1, 2)); //将list中的每列数据进行反转倒序 List baseLocationsDesc1 = new List(); List baseLocationsDesc2 = new List(); List locationLine = new List(); var info = locations.GroupBy(x => x.locationLine).ToList(); foreach (var item in info) { locationLine.Add(item.Key); } locationLine.ForEach(x => { var list = locations.Where(y => y.locationLine == x && y.locationRow == 1).ToList(); baseLocationsDesc1.AddRange(list.OrderByDescending(z => z.Ordernum).ToList()); var list2 = locations.Where(y => y.locationLine == x && y.locationRow == 2).ToList(); baseLocationsDesc2.AddRange(list2.OrderByDescending(z => z.Ordernum).ToList()); }); baseLocationsDesc1.ForEach(x => { System.Windows.Forms.Button button = new System.Windows.Forms.Button(); if (x.locationLine == 2 || x.locationLine == 3 || x.locationLine == 4 || x.locationLine == 5) { if (x.locationTier == 16) { this.flowLayoutPanel1.SetFlowBreak(button, true); } } button = buttonStyle(x.locationCode, x.Ordernum, x.materialType, x.locationStatus); flowLayoutPanel1.Controls.Add(button); }); baseLocationsDesc2.ForEach(x => { System.Windows.Forms.Button button = new System.Windows.Forms.Button(); if (x.locationLine == 2 || x.locationLine == 3 || x.locationLine == 4 || x.locationLine == 5) { if (x.locationTier == 16) { this.flowLayoutPanel2.SetFlowBreak(button, true); } } button = buttonStyle(x.locationCode, x.Ordernum, x.materialType, x.locationStatus); flowLayoutPanel2.Controls.Add(button); }); } catch (Exception ex) { MessageBox.Show("未查询到库位!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } } /// /// 利用button按钮实现仓库库位样式 /// /// /// /// /// /// private Button buttonStyle(string locationCode, int ordernum, string materialType, LocationStatus locationStatus) { Label label = new Label(); Label label2 = new Label(); Rectangle workingArea = Screen.GetWorkingArea(this); int num = workingArea.Width / 5 - 30; int num2 = workingArea.Height / 20; Button button = new Button(); button.Margin = new Padding(5); button.FlatStyle = FlatStyle.Flat; button.ImageAlign = ContentAlignment.TopCenter; button.Location = new Point(3, 0); button.Name = locationCode; button.Size = new Size(num, num2); button.TabIndex = 0; button.Font = new Font("宋体", 15f, FontStyle.Bold); button.BackColor = Color.FromArgb(3, 27, 61); button.ForeColor = Color.FromArgb(106, 203, 254); button.TextAlign = ContentAlignment.MiddleCenter; button.BackgroundImageLayout = ImageLayout.Stretch; Label label3 = new Label(); label3.Font = new Font("宋体", 9f, FontStyle.Regular); label3.Size = new Size(130, 23); label3.Name = "materialType"; if (ordernum > 2) { button.Text = locationCode; if (materialType.Length > 15) { label3.Text = "物料型号:\r\n" + materialType; } else { label3.Text = "物料型号:" + materialType; } button.Text = locationCode; if ((int)locationStatus == 1) { label2 = new Label(); label2.Font = new Font("宋体", 10f, FontStyle.Regular); label2.Size = new Size(40, 15); label2.Name = "locationStatus"; label2.BackColor = Color.Red; label2.Text = "占用"; label2.Location = new Point(num - 100, 15); } else if ((int)locationStatus == 2) { label2 = new Label(); label2.Font = new Font("宋体", 10f, FontStyle.Regular); label2.Size = new Size(40, 15); label2.Name = "locationStatus"; label2.BackColor = Color.Green; label2.Text = "空闲"; label2.Location = new Point(num - 100, 15); } else if ((int)locationStatus == 0) { label2 = new Label(); label2.Font = new Font("宋体", 10f, FontStyle.Regular); label2.Size = new Size(40, 15); label2.Name = "locationStatus"; label2.BackColor = Color.Red; label2.Text = "锁库"; label2.Location = new Point(num - 100, 15); } else if ((int)locationStatus == 4) { label2 = new Label(); label2.Font = new Font("宋体", 10f, FontStyle.Regular); label2.Size = new Size(40, 15); label2.Name = "locationStatus"; label2.BackColor = Color.Red; label2.Text = "异常"; label2.Location = new Point(num - 100, 15); } label3.Location = new Point(12, 10); label3.BringToFront(); label2.BringToFront(); button.Click += numberButton_Click; button.Controls.Add(label3); button.Controls.Add(label2); } return button; } private async void numberButton_Click(object sender, EventArgs e) { try { Button btn = sender as Button; if (btn == null) { return; } foreach (Control a in btn.Controls) { if (a is Label) { if (a.Name.Equals("locationStatus")) { _ = a.Text; } if (a.Name.Equals("materialType")) { a.Text.Substring(5); } } } Expression> exp2 = (BaseLocationInfo s1) => true; exp2 = ExpressionExtensions.And>(exp2, (Expression>)((BaseLocationInfo s1) => (int)s1.locationArea == (int)locationArea && s1.storeCode == ConfigHelper.GetConfig("storeCode") && s1.locationCode == btn.Text)); BaseLocationInfo baseLocationInfo = await new BaseServices().QuerySingle(exp2); StoreLocationInfo storeLocationInfo = new StoreLocationInfo(); storeLocationInfo.baseLocationInfo = baseLocationInfo; storeLocationInfo.ShowDialog(this); if (storeLocationInfo.DialogResult == DialogResult.OK) { MessageBox.Show("修改成功!"); btn_Cancle_Click(null, null); } else { storeLocationInfo.Dispose(); } } catch (Exception) { } } private void btn_Cancle_Click(object sender, EventArgs e) { Close(); } } }