コード例 #1
0
        public static Result Create(int packId)
        {
            var pack = GetObject.GetById <Pack>(packId);

            if (string.IsNullOrEmpty(pack.Code))
            {
                return(new Result("系统中不包含箱体,ID:" + packId));
            }
            var content = Common.PACK_DETAILS_WEB_SITE_URL.Replace("[pack_code]", pack.Code);

            var result = Arthur.Core.Coder.QRCoder.Create(content, 5, 4, AppDomain.CurrentDomain.BaseDirectory + "Images\\gmcc_logo_4_qrcode.png", 36);

            if (result.IsFailed)
            {
                return(result);
            }
            var bimg = (Bitmap)result.Data;

            var dirPath = GetSaveQRCodeDirPath(pack.SortResult);

            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            return(Arthur.Core.Coder.QRCoder.SaveQRCode(bimg, dirPath + string.Format("\\{0}.png", pack.Code)));
        }
コード例 #2
0
 private void Battery_code_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         var code = (sender as TextBox).Text.Trim();
         if (!string.IsNullOrEmpty(code))
         {
             var battery = GetObject.GetByCode <Battery>(code);
             if (battery.Id > 0)
             {
                 this.sortResult          = battery.SortResult;
                 this.sort_result.Content = this.sortResult;
                 packId = battery.PackId;
                 var pack = GetObject.GetById <Pack>(packId);
                 if (pack.Id > 0)
                 {
                     this.pack_code.Content          = pack.Code;
                     this.pack_battery_count.Content = PackManage.GetPackCount(packId);
                     tip.Visibility            = Visibility.Collapsed;
                     this.btnConfirm.IsEnabled = true;
                 }
                 else
                 {
                     tip.Background = new SolidColorBrush(Colors.Red);
                     tip.Text       = "该电池尚未绑定箱体!";
                     tip.Visibility = Visibility.Visible;
                 }
             }
             else
             {
                 tip.Background = new SolidColorBrush(Colors.Red);
                 tip.Text       = "系统中不存在该电池!";
                 tip.Visibility = Visibility.Visible;
             }
         }
     }
     else
     {
         tip.Visibility = Visibility.Collapsed;
     }
 }
コード例 #3
0
        public static Result Upload(Battery battery)
        {
            Result result;

            using (var db = new GMCCContext())
            {
                var sql = string.Format("INSERT INTO AutoSorting (CaseNumber, BarCode, CAP, ESR, TestDate, UserID, UserName) VALUES ('{0}', '{1}', {2}, {3}, '{4}', {5}, '{6}')",
                                        GetObject.GetById <Pack>(battery.PackId).Code, battery.Code, battery.CAP, battery.ESR, battery.TestTime, Current.User.Id, Current.User.Name);
                try
                {
                    if (db.Database.ExecuteSqlCommand(sql) > 0)
                    {
                        result = Result.Success;
                    }
                    else
                    {
                        return(new Result(""));
                    }
                }
                catch (Exception ex)
                {
                    return(new Result(ex));
                }
            }

            using (var db = new Data.AppContext())
            {
                try
                {
                    battery            = db.Batteries.Where(o => o.Id == battery.Id).FirstOrDefault();
                    battery.IsUploaded = true;
                    db.SaveChanges();
                    return(Result.Success);
                }
                catch (Exception ex)
                {
                    return(new Result(ex));
                }
            }
        }
コード例 #4
0
        public Edit(int id)
        {
            InitializeComponent();
            this.Battery     = ContextToViewModel.Convert(_AppContext.Batteries.Single(t => t.Id == id));
            this.DataContext = this.Battery;

            var trays = _AppContext.Trays.ToList();

            this.proctray.Items.Add("——未知——");
            trays.ForEach(o => this.proctray.Items.Add(o.Code));
            var proctray_index = -1;

            if (this.Battery.ProcTrayId < 1)
            {
                proctray_index = 0;
            }
            else
            {
                var procTray = GetObject.GetById <Model.ProcTray>(this.Battery.ProcTrayId);
                proctray_index = trays.IndexOf(trays.FirstOrDefault(o => o.Id == procTray.TrayId)) + 1;
            }
            this.proctray.SelectedIndex = proctray_index;
        }
コード例 #5
0
ファイル: TimerExec.cs プロジェクト: jtzhang163/Arthur
        public static void TaskExec(object obj)
        {
            if (!IsRunning)
            {
                return;
            }

            if (Arthur.App.Current.Option.RemainingMinutes <= 0)
            {
                return;
            }

            try
            {
                if (Current.Task.Status == Model.TaskStatus.完成)
                {
                    if (Current.App.TaskMode == ViewModel.TaskMode.自动任务)
                    {
                        foreach (var type in Factory.TaskFactory.TaskTypes)
                        {
                            if (type == TaskType.料 && Current.Option.Tray13_Id < 1)
                            {
                                continue;
                            }
                            else if (type == TaskType.料 && Current.Option.Tray21_Id > 0)
                            {
                                continue;
                            }

                            if (Current.Option.IsTaskReady)
                            {
                                var storages = Factory.TaskFactory.CanGetOrPutStorages(type);
                                if (storages.Count > 0)
                                {
                                    StorageViewModel storage = storages.OrderBy(o => o.GetPriority(type, Current.Option.TaskPriorityType)).First();

                                    Current.Task.StorageId  = storage.Id;
                                    Current.Task.Type       = type;
                                    Current.Task.StartTime  = DateTime.Now;
                                    Current.Task.ProcTrayId = type == Model.TaskType.料 ? Current.Option.Tray13_Id : storage.ProcTrayId;
                                    Current.Task.Status     = Model.TaskStatus.就绪;

                                    LogHelper.WriteInfo(string.Format("=== 生成自动任务 类型:{0},料仓:{1},流程托盘ID:{2},托盘条码:{3} ===",
                                                                      Current.Task.Type, storage.Name, Current.Task.ProcTrayId, GetObject.GetById <ProcTray>(Current.Task.ProcTrayId).Code));

                                    break;
                                }
                            }
                        }
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.就绪)
                {
                    var storage    = GetObject.GetById <StorageViewModel>(Current.Task.StorageId);
                    var toMoveInfo = JawMoveInfo.Create(Current.Task.Type, storage);

                    //若指令已经发给PLC
                    if (Current.Option.JawMoveInfo.Equals(toMoveInfo))
                    {
                        Current.Option.JawProcTrayId = Current.Task.ProcTrayId;
                        Current.Task.Status          = Model.TaskStatus.准备搬;
                        return;
                    }

                    Current.MainMachine.SendCommand(toMoveInfo);
                }
                else if (Current.Task.Status == Model.TaskStatus.准备搬)
                {
                    //若指令已经发给PLC
                    if (Current.Option.IsJawHasTray)
                    {
                        Current.Task.Status = Model.TaskStatus.搬运中;
                        return;
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.搬运中)
                {
                    if (Current.Option.IsTaskFinished)
                    {
                        var storage = GetObject.GetById <StorageViewModel>(Current.Task.StorageId);
                        if (Current.Task.Type == Model.TaskType.料)
                        {
                            storage.ProcTrayId = Current.Task.ProcTrayId;
                            storage.ProcTray.StartStillTime = DateTime.Now;
                        }
                        else
                        {
                            Current.Option.Tray21_Id = Current.Task.ProcTrayId;
                            if (storage.ProcTrayId > 0)
                            {
                                storage.ProcTray.StillTimeSpan = Convert.ToInt32((DateTime.Now - storage.ProcTray.StartStillTime).TotalMinutes);
                                storage.ProcTrayId             = 0;
                            }
                        }
                        Current.Option.JawProcTrayId = 0;
                        Current.Task.Status          = Model.TaskStatus.回位中;
                    }
                }
                else if (Current.Task.Status == Model.TaskStatus.回位中)
                {
                    if (Current.Option.IsTaskReady)
                    {
                        Current.Task.PreType = Current.Task.Type;
                        if (Current.Task.Type == Model.TaskType.料)
                        {
                            Current.Option.LastFeedTaskStorageColumn = GetObject.GetById <StorageViewModel>(Current.Task.StorageId).Column;
                        }
                        Current.Task.Status = Model.TaskStatus.完成;
                        new TaskManage().AddTaskLog();
                    }
                }
            }
            catch (Exception ex)
            {
                Running.StopRunAndShowMsg("执行任务出现异常:" + ex.Message);
                LogHelper.WriteError(ex);
            }
        }
コード例 #6
0
ファイル: TimerExec.cs プロジェクト: jtzhang163/Arthur
        public static void GetShareDataExec(object obj)
        {
            if (!IsRunning)
            {
                return;
            }

            if (Arthur.App.Current.Option.RemainingMinutes <= 0)
            {
                return;
            }

            if (!Current.Option.IsGetShareDataExecting)
            {
                Current.Option.IsGetShareDataExecting = true;

                if (Current.ShareDatas.Count > 0)
                {
                    if (Current.Option.Tray12_Id > 0)
                    {
                        var chargeData = Current.ShareDatas.First(o => o.Key == "chargeCodes");
                        var bindCode   = JsonHelper.DeserializeJsonToObject <BindCode>(chargeData.Value);
                        var procTray   = GetObject.GetById <ProcTray>(Current.Option.Tray12_Id);

                        if (procTray.Id > 0 && chargeData.Status == 2)
                        {
                            if (procTray.Id == chargeData.ProcTrayId)
                            {
                            }
                            else
                            {
                                //充电位条码绑定信息传给BTS客户端
                                var batteries = procTray.GetBatteries();
                                var codes     = new List <string>();
                                for (var i = 1; i <= Common.TRAY_BATTERY_COUNT; i++)
                                {
                                    var code    = "";
                                    var battery = batteries.FirstOrDefault(o => o.GetChargeOrder() == i);
                                    if (battery != null)
                                    {
                                        code = battery.Code;
                                    }
                                    codes.Add(code);
                                }

                                var value = new BindCode {
                                    TrayCode = procTray.Code, BatteryCodes = string.Join(",", codes.ToArray())
                                };
                                chargeData.Value      = JsonHelper.SerializeObject(value);
                                chargeData.Status     = 1;
                                chargeData.ProcTrayId = procTray.Id;
                                chargeData.UpdateTime = DateTime.Now;
                                LogHelper.WriteInfo(string.Format("--------成功发送充电位条码绑定信息给BTS【流程托盘ID:{0},条码:{1}】---------", procTray.Id, procTray.Code));
                            }
                        }
                    }

                    if (Current.Option.Tray22_Id > 0)
                    {
                        var dischargeData = Current.ShareDatas.First(o => o.Key == "dischargeCodes");
                        var bindCode      = JsonHelper.DeserializeJsonToObject <BindCode>(dischargeData.Value);
                        var procTray      = GetObject.GetById <ProcTray>(Current.Option.Tray22_Id);

                        if (procTray.Id > 0 && dischargeData.Status == 2)
                        {
                            if (procTray.Id == dischargeData.ProcTrayId)
                            {
                            }
                            else
                            {
                                //放电位条码绑定信息传给BTS客户端
                                var batteries = procTray.GetBatteries();
                                var codes     = new List <string>();
                                for (var i = 1; i <= Common.TRAY_BATTERY_COUNT; i++)
                                {
                                    var code    = "";
                                    var battery = batteries.FirstOrDefault(o => o.GetChargeOrder() == i);
                                    if (battery != null)
                                    {
                                        code = battery.Code;
                                    }
                                    codes.Add(code);
                                }

                                var value = new BindCode {
                                    TrayCode = procTray.Code, BatteryCodes = string.Join(",", codes.ToArray())
                                };
                                dischargeData.Value      = JsonHelper.SerializeObject(value);
                                dischargeData.Status     = 1;
                                dischargeData.ProcTrayId = procTray.Id;
                                dischargeData.UpdateTime = DateTime.Now;
                                LogHelper.WriteInfo(string.Format("--------成功发送放电位条码绑定信息给BTS【流程托盘ID:{0},条码:{1}】---------", procTray.Id, procTray.Code));
                            }
                        }
                    }

                    if (Current.Option.Tray23_Id > 0)
                    {
                        var procTray = GetObject.GetById <ProcTray>(Current.Option.Tray23_Id);

                        var sortingResults = Current.ShareDatas.First(o => o.Key == "sortingResults");
                        var capResults     = Current.ShareDatas.First(o => o.Key == "capResults");
                        var esrResults     = Current.ShareDatas.First(o => o.Key == "esrResults");

                        if (sortingResults.Status == 1 && capResults.Status == 1 && esrResults.Status == 1)
                        {
                            var sortingResult_sort = JsonHelper.DeserializeJsonToObject <SortingResult>(sortingResults.Value);
                            var sortingResult_cap  = JsonHelper.DeserializeJsonToObject <SortingResult>(capResults.Value);
                            var sortingResult_esr  = JsonHelper.DeserializeJsonToObject <SortingResult>(esrResults.Value);

                            if (sortingResult_sort.TrayCode == procTray.Code)
                            {
                                try
                                {
                                    var sortList = sortingResult_sort.Results.Split(',');
                                    var capList  = sortingResult_cap.Results.Split(',');
                                    var esrList  = sortingResult_esr.Results.Split(',');

                                    for (int i = 0; i < sortList.Length; i++)
                                    {
                                        //i:绑盘序号
                                        Current.MainMachine.Commor.Write(string.Format("D{0:D3}", 401 + i), ushort.Parse(sortList[OrderManage.GetChargeOrderBySortOrder(i + 1) - 1]));
                                    }
                                    LogHelper.WriteInfo(string.Format("--------成功发送分选结果数据给PLC【流程托盘ID:{0},条码:{1}】---------", procTray.Id, procTray.Code));

                                    var batteries         = procTray.GetBatteries();
                                    var batteryViewModels = ContextToViewModel.Convert(batteries);

                                    for (int i = 0; i < sortList.Length; i++)
                                    {
                                        //i:通道序号
                                        var sort = int.Parse(sortList[i]);
                                        var cap  = decimal.Parse(capList[i]);
                                        var esr  = decimal.Parse(esrList[i]);

                                        if (sort > 0)
                                        {
                                            var battery = batteryViewModels.FirstOrDefault(o => o.Pos == OrderManage.GetBindOrderByChargeOrder(i + 1));
                                            if (battery != null)
                                            {
                                                battery.SortResult = (SortResult)sort;
                                                battery.CAP        = cap;
                                                battery.ESR        = esr;
                                            }
                                        }
                                    }

                                    sortingResults.Status     = 2;
                                    sortingResults.ProcTrayId = procTray.Id;
                                    sortingResults.UpdateTime = DateTime.Now;

                                    capResults.Status     = 2;
                                    capResults.ProcTrayId = procTray.Id;
                                    capResults.UpdateTime = DateTime.Now;


                                    esrResults.Status     = 2;
                                    esrResults.ProcTrayId = procTray.Id;
                                    esrResults.UpdateTime = DateTime.Now;
                                }
                                catch (Exception ex)
                                {
                                    Running.StopRunAndShowMsg(ex);
                                }
                            }
                        }
                    }
                }
                Current.Option.IsGetShareDataExecting = false;
            }
        }
コード例 #7
0
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            var header = (sender as MenuItem).Header.ToString();

            if (header == "手动【上料】" || header == "手动【下料】")
            {
                if (Current.Task.Status != Model.TaskStatus.完成)
                {
                    MessageBox.Show("当前任务尚未完成!", "提示");
                    return;
                }

                if (!Current.Option.IsTaskReady)
                {
                    MessageBox.Show("PLC接收任务状态未就绪!", "提示");
                    return;
                }


                var type = header == "手动【上料】" ? Model.TaskType.料 : Model.TaskType.料;

                var fromProcTrayId = type == Model.TaskType.料 ? Current.Option.Tray13_Id : this.Storage.ProcTrayId;
                if (fromProcTrayId < 1)
                {
                    MessageBox.Show("取盘位置无托盘!", "提示");
                    return;
                }


                var toProcTrayId = type == Model.TaskType.料 ? this.Storage.ProcTrayId : Current.Option.Tray21_Id;
                if (toProcTrayId > 0)
                {
                    MessageBox.Show("放盘位置有托盘!", "提示");
                    return;
                }

                if (type == TaskType.料)
                {
                    var lowerStorage = Current.Storages.FirstOrDefault(o => o.Floor == this.Floor + 1 && o.Column == this.Col);
                    if (lowerStorage != null && lowerStorage.ProcTrayId < 1)
                    {
                        MessageBox.Show("该位置无法上料,下层料仓无托盘!", "提示");
                        return;
                    }
                }

                if (type == TaskType.料)
                {
                    var lowerStorage = Current.Storages.FirstOrDefault(o => o.Floor == this.Floor - 1 && o.Column == this.Col);
                    if (lowerStorage != null && lowerStorage.ProcTrayId > 1)
                    {
                        MessageBox.Show("该位置无法下料,上层料仓有托盘!", "提示");
                        return;
                    }
                }

                Current.Task.StorageId  = this.Storage.Id;
                Current.Task.Type       = type;
                Current.Task.StartTime  = DateTime.Now;
                Current.Task.ProcTrayId = type == TaskType.料 ? Current.Option.Tray13_Id : this.Storage.ProcTrayId;
                Current.Task.Status     = Model.TaskStatus.就绪;

                LogHelper.WriteInfo(string.Format("=== 手动生成任务 类型:{0},料仓:{1},流程托盘ID:{2},托盘条码:{3} ===",
                                                  Current.Task.Type, this.Storage.Name, Current.Task.ProcTrayId, GetObject.GetById <ProcTray>(Current.Task.ProcTrayId).Code));
            }
        }