SettingControl.cs 16.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
using ConfigHelper;
using CtuDeviceLib;
using CtuDeviceLib.manager;
using DeviceLibrary;
using DeviceLibrary.CtuDeviceLib;
using DeviceLibrary.CtuService;
using Mushiny;
using OnlineStore;
using OnlineStore.AssemblyLine;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TheMachine
{
    public partial class SettingControl : UserControl
    {

        List<CTU> allCtus;
        public SettingControl()
        {
            InitializeComponent();
            for (int i = 1; i < 7; i++)
            {
                comboBox3.Items.Add(i);
            }
            allCtus = CTUManager.GetCTUs();
            foreach (var ctu in allCtus)
            {
                var control = new ucCtuRunInfo(ctu);
                CtuRunInfos.Add(control);
                flowLayoutPanel1.Controls.Add(control);
            }
            allCtus?.ForEach(ctu =>
            {
                cmbCtus.Items.Add($"{ctu.Name}({ctu.IP})");
                comboBox1.Items.Add($"{ctu.Name}({ctu.IP})");
            }
            );

            comboBox2.Items.Add(Setting_Init.ChargeStation_01);
            comboBox2.Items.Add(Setting_Init.ChargeStation_02);
            comboBox2.Items.Add(Setting_Init.ChargeStation_03);
            comboBox2.Items.Add(Setting_Init.ChargeStation_04);
            RobotManager.LoadFinishEvent += RobotManage_LoadFinishEvent;
        }
        List<ucCtuRunInfo> CtuRunInfos = new List<ucCtuRunInfo>();
        private void RobotManage_LoadFinishEvent(bool state, string msg)
        {
            if (!File.Exists("说明.txt"))
            {
                return;
            }
            //var allTxt = File.ReadAllLines("说明.txt");
            //if (allTxt.Length > 0)
            //{
            //    foreach (var item in allTxt)
            //    {
            //        rtbDesc.AppendText(item + "\r\n");
            //    }
            //}
            if (!state)
                return;
        }


        private void SettingControl_Load(object sender, EventArgs e)
        {
            //Config.PropertyBind(Setting_Init.Device_Use_Fixpos.Key, cb_usefixpos, "Checked", "CheckedChanged");
            //Config.PropertyBind(Setting_Init.Device_AutoRun.Key, cb_autorun, "Checked", "CheckedChanged");
        }

        DateTime lastUpdateTime = DateTime.Now;
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (!Visible)
                return;
            if (Monitor.TryEnter(timer1, 300))
            {
                try
                {
                    //lstStandbys.Items.Clear();
                    //foreach (var item in CtuStandbys.ctuStandbies)
                    //{
                    //    lstStandbys.Items.Add($"{item.Name}");
                    //}
                    if ((DateTime.Now - lastUpdateTime).TotalSeconds > 10)
                    {
                        foreach (var item in CtuRunInfos)
                        {
                            item.UpdateInfo();
                        }
                        lastUpdateTime = DateTime.Now;
                    }
                    //var posinfos = PosInfos.GetAllPosInfos()?.FindAll(s => s.Name.StartsWith(Setting_Init.outLine) && s.Name.EndsWith(Setting_Init.dir_in));
                    //if (posinfos != null)
                    //{
                    //   // textBox1.Text = "";
                    //    StringBuilder sb = new StringBuilder();
                    //    //foreach (var item in posinfos)
                    //    //{
                    //    //    if (RobotManager.BoxListAtOutLetBuff.ContainsKey(item.Name))
                    //    //    {
                    //    //        var totalBoxCount = RobotManager.BoxListAtOutLetBuff[item.Name].TotalCnt;
                    //    //        var emptyBoxCount = RobotManager.BoxListAtOutLetBuff[item.Name].EmptyCnt;
                    //    //        var reelNumToOut = RobotManager.BoxListAtOutLetBuff[item.Name].WaitOutReelCnt;
                    //    //        sb.AppendLine($"【{RobotManager.BoxListAtOutLetBuff[item.Name].UpdateTime.ToString("HH:mm:ss")}】【{item.Name}】总料箱数【{totalBoxCount}】空料箱数【{emptyBoxCount}】满料箱数【{totalBoxCount - emptyBoxCount}】,待出库料盘数【{reelNumToOut}】");
                    //    //    }
                    //    //}
                    //    //textBox1.Text = sb.ToString();
                    //}
                    //var list = TaskUtil.AllEmptyBox?.ToList();
                    //var InletOutStoreBoxs = "";
                    //if (list != null && list.Count > 0)
                    //{
                    //    StringBuilder sb = new StringBuilder();
                    //    sb.AppendLine($"空箱总数:{list.Count}");
                    //    var size7 = list.FindAll(s => "7".Equals(s.size));
                    //    var size13 = list.FindAll(s => "13".Equals(s.size));
                    //    var size15 = list.FindAll(s => "15".Equals(s.size));
                    //    sb.AppendLine($"7寸总数:{size7?.Count}");
                    //    sb.AppendLine($"13寸总数:{size13?.Count}");
                    //    sb.AppendLine($"15寸总数:{size15?.Count}");
                    //    list.ForEach(s => sb.AppendLine($"【{s.box}】【{s.size}】【{s.posName}】【{s.remainNum}】【{s.warehouseCode}】"));
                    //    InletOutStoreBoxs = sb.ToString();
                    //}
                    //else
                    //{
                    //    InletOutStoreBoxs = "";
                    //}

                    //textBox2.Text = InletOutStoreBoxs;
                }
                finally
                {
                    Monitor.Exit(timer1);
                }
            }
        }

        private void flowLayoutPanel1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            try
            {
                this.Invoke(new Action(() =>
                {
                    foreach (var item in CtuRunInfos)
                    {
                        item.UpdateInfo();
                    }
                }));

            }
            catch (Exception ex)
            {

            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否屏蔽该背篓?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                CTUManager.EditBasket(allCtus[idx], (byte)numRow.Value, true);
                richTextBox1.AppendText($"【{allCtus[idx].Name}】屏蔽背篓:\r\n");
                allCtus[idx].GetAllBaskets().ForEach(s =>
                {
                    if (s.Shield)
                    {
                        richTextBox1.AppendText($"{s.Row}\r\n");
                    }

                });
            }
            LogUtil.info($"手动操作 屏蔽背篓");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否启用该背篓?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                CTUManager.EditBasket(allCtus[idx], (byte)numRow.Value, false);
                richTextBox1.AppendText($"【{allCtus[idx].Name}】屏蔽背篓:\r\n");
                allCtus[idx].GetAllBaskets().ForEach(s =>
                {
                    if (s.Shield)
                    {
                        richTextBox1.AppendText($"{s.Row}\r\n");
                    }

                });
            }
        }

        private void button7_Click(object sender, EventArgs e)
        {
            // FrmPwd fw = new FrmPwd(10);
            //DialogResult result = fw.ShowDialog();
            //if (!result.Equals(DialogResult.OK))
            //{
            //    LogUtil.info("清空当前背篓时,没有正确输入密码");
            //    return;
            //}
            if (MessageBox.Show($"是否清空该背篓?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                allCtus[idx]?.ClearBasket((byte)numRow.Value);
            }
            LogUtil.info($"手动操作 清空当前背篓");
        }

        private void button6_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                richTextBox1.AppendText($"【{CTUManager.GetCTUs()[idx].Name}】屏蔽背篓:\r\n");
                allCtus[idx].GetAllBaskets().ForEach(s =>
                {
                    if (s.Shield)
                    {
                        richTextBox1.AppendText($"{s.Row}\r\n");
                    }

                });
            }
        }

        private void lstOutstores_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否设置该背篓有料箱?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                CTUManager.EditBasketHasBox(allCtus[idx], (byte)numRow.Value, true);
                richTextBox1.AppendText($"【{allCtus[idx].Name}】屏蔽背篓:\r\n");
                allCtus[idx].GetAllBaskets().ForEach(s =>
                {
                    if (s.Shield)
                    {
                        richTextBox1.AppendText($"{s.Row}\r\n");
                    }

                });
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否设置该背篓无料箱?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            richTextBox1.Clear();
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                CTUManager.EditBasketHasBox(allCtus[idx], (byte)numRow.Value, false);
                richTextBox1.AppendText($"【{allCtus[idx].Name}】屏蔽背篓:\r\n");
                allCtus[idx].GetAllBaskets().ForEach(s =>
                {
                    if (s.Shield)
                    {
                        richTextBox1.AppendText($"{s.Row}\r\n");
                    }

                });
            }
        }

        private void lstOutstores_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var outs = TaskManager.GetAllTasks()?.FindAll(s => s.TaskType == RobotTaskType.Outstore);
            lstOutstores.Items.Clear();
            if (outs != null)
            {
                foreach (var item in outs)
                {
                    lstOutstores.Items.Add($"{item.BoxCode}\t{item.SrcPoint}\t{item.DestPoint}");
                }
            }
            groupBox1.Text = $"出库任务:[{lstOutstores.Items.Count}]";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1) return;
            if (comboBox2.SelectedIndex == -1) return;
            var curCtu = allCtus[comboBox1.SelectedIndex];
            var charge = comboBox2.SelectedItem.ToString();

            allCtus.ForEach(s =>
            {
                if (s.CtuTask != null && s.CtuTask is ChargeTask && s.CtuTask.DstName.Equals(charge))
                {
                    MessageBox.Show($"【{s.Name}】执行该充电桩任务,无法使用该充电桩!");
                    return;
                }
            });

            curCtu.CtuTask = new ChargeTask(curCtu, charge);
            LogUtil.info($"【{curCtu.Name}】手动发送到【{charge}】充电");
            MessageBox.Show($"【{curCtu.Name}】手动发送到【{charge}】充电成功");
        }

        private void lstInstores_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var outs = TaskManager.GetAllTasks()?.FindAll(s=>s.TaskType ==  RobotTaskType.Insotre);
            lstInstores.Items.Clear();
            if (outs != null)
            {
                foreach (var item in outs)
                {
                    lstInstores.Items.Add($"{item.BoxCode}\t{item.SrcPoint}\t{item.DestPoint}");
                }
            }
            groupBox2.Text = $"入库任务:[{lstInstores.Items.Count}]";
        }

        private void button9_Click(object sender, EventArgs e)
        {
            if (comboBox3.SelectedIndex == -1) return;
            if (comboBox1.SelectedIndex == -1) return;

            var curCtu = allCtus[comboBox1.SelectedIndex];
            if (byte.TryParse(comboBox3.SelectedItem.ToString(), out byte row))
            {
                if (MushinyManager.GenManualGetFromBunkerPathPoints(curCtu, row, out List<PathPoint> path))
                {
                    if (!curCtu.CreatePathPoint(path, curCtu.CurLandMark, ""))
                    {
                        MessageBox.Show("手动取箱失败");
                    }
                }
            }
        }

        private void button10_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否设置该背篓目的地为分拣机?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                var basket = allCtus[idx].GetBasket((byte)numRow.Value);
                if (basket != null)
                {
                    if (!string.IsNullOrEmpty(basket.BoxCode))
                    {
                        if (CTUManager.InletGroup.IsInGroup(allCtus[idx].Name))
                        {
                            basket.DstName = Setting_Init.In_FeedingInlet;
                        }
                        else
                        {
                            basket.DstName = Setting_Init.Out_FeedingInlet;
                        }
                        LogUtil.info($"手动设置料箱【{basket.BoxCode}】目的地为【{basket.DstName}】");
                    }
                }
            }
        }

        private void button11_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show($"是否设置该碑楼目的地从服务器获取?", "提示", MessageBoxButtons.YesNo).Equals(DialogResult.No))
            {
                return;
            }
            if (cmbCtus.SelectedIndex > -1)
            {
                int idx = cmbCtus.SelectedIndex;
                var basket = allCtus[idx].GetBasket((byte)numRow.Value);
                if (basket != null)
                {
                    if (!string.IsNullOrEmpty(basket.BoxCode))
                    {
                        if (SMFManager.GetBoxTarget(basket.BoxCode, out string dst))
                        {
                            basket.DstName = dst;
                            LogUtil.info($"手动设置料箱【{basket.BoxCode}】目的地为【{dst}】");
                        }

                    }
                }
            }
        }

        private void button12_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedIndex == -1) return;
            if (uint.TryParse(txtTarget.Text, out uint targetPoint)) return;
            var curCtu = allCtus[comboBox1.SelectedIndex];
            var posinfo = PosInfos.GetPosInfoByPtCode(targetPoint);
            if (posinfo != null)
            {
                curCtu.CtuTask = new ManualMoveTask(curCtu, posinfo.Name);
                LogUtil.info($"【{curCtu.Name}】手动发送到【{posinfo.Name}】");
                MessageBox.Show($"【{curCtu.Name}】手动发送到【{posinfo.Name}】成功");
            }
            else
            {
                MessageBox.Show($"该地码【{targetPoint}】不可用,请使用其他地码!");
            }
        }

        private void tabPage9_Click(object sender, EventArgs e)
        {
            label3.Text = "";
        }
    }
}