private async void DownloadSongs_Click(object sender, RoutedEventArgs e)
        {
            using (var client = new WebClient())
            {
                List <PandoraStation> stations = await pandoraService.GetPandoraStationsAsync(config, restfulService, pandoraState);

                PandoraStation station = stations.Where(s => s.Name == Station.Text).FirstOrDefault();
                if (station != null)
                {
                    int          songsLeft = int.Parse(NumberOfSongs.Text);
                    int          count     = 0;
                    StationCache cache     = new StationCache();
                    cache.Name = station.Name;
                    while (songsLeft > 0)
                    {
                        List <PandoraSong> playlist = await pandoraService.GetPandoraPlaylistAsync(restfulService, pandoraState, station);

                        foreach (PandoraSong song in playlist)
                        {
                            if (!IsInLibrary(song.Title, song.AlbumName, song.ArtistName) && songsLeft > 0)
                            {
                                string formattedTitle = song.Title;
                                client.DownloadFile(song.AudioUrl, PandoraDirectory.Text + "/" + SanitizeFilename(formattedTitle) + ".mp4");
                                if (song.AlbumArtUrl != null)
                                {
                                    client.DownloadFile(song.AlbumArtUrl, PandoraDirectory.Text + "/" + SanitizeFilename(song.AlbumName) + ".png");
                                }
                                TagLib.File mp3File = TagLib.File.Create(PandoraDirectory.Text + "/" + SanitizeFilename(formattedTitle) + ".mp4");
                                mp3File.Tag.Title        = song.Title;
                                mp3File.Tag.Album        = song.AlbumName;
                                mp3File.Tag.AlbumArtists = song.ArtistName.Split(',');
                                mp3File.Tag.Pictures     = new TagLib.IPicture[] {
                                    new TagLib.Picture(PandoraDirectory.Text + "/" + SanitizeFilename(song.AlbumName) + ".png")
                                };
                                mp3File.Save();
                                Log.AppendText("\n" + "Downloading (" + (count + 1) + "/" + NumberOfSongs.Text + "): " + song.Title + " by " + song.ArtistName);
                                Files.Items.Add(new Song()
                                {
                                    Title  = song.Title,
                                    Album  = song.AlbumName,
                                    Artist = song.ArtistName
                                });
                                cache.Songs.Add(song);
                                songsLeft--;
                                count++;
                            }
                        }
                    }
                    string serializedSongList = JsonConvert.SerializeObject(cache);
                    File.WriteAllText(PandoraDirectory.Text + "/Songs_" + Guid.NewGuid().ToString() + ".json", serializedSongList);
                    Files.Items.SortDescriptions.Add(new SortDescription(Files.Columns[0].SortMemberPath, ListSortDirection.Ascending));
                }
                else
                {
                    Log.Text = Log.Text + "\n" + "Station not found: " + Station.Text;
                }
            }
        }
 public WinCutPlanAddOrEdit(int?id, StationCache head)
 {
     InitializeComponent();
     this.Id    = id;
     this.Head  = head;
     this.Title = id == null ? "新增" : "编辑";
     Init();
     this.GridMain.DataContext = CurrentCutPlan;
 }
Esempio n. 3
0
        private void Init()
        {
            stations.Add(new Station()
            {
                Id = 1135, Code = "LengthMeasuringCache", Name = "测长缓存"
            });
            stations.Add(new Station()
            {
                Id = 1131, Code = "AssembleCache1", Name = "组队区缓存1"
            });
            stations.Add(new Station()
            {
                Id = 1132, Code = "AssembleCache2", Name = "组队区缓存2"
            });
            CbxStation.ItemsSource       = stations;
            CbxStation.DisplayMemberPath = "Name";
            CbxStation.SelectedValuePath = "Code";

            //管材缓存状态列表
            var StationCacheStatusList = CommonHelper.EnumListDic <StationCacheStatus>("");

            CbxCacheMaterialStatus.ItemsSource       = StationCacheStatusList;
            CbxCacheMaterialStatus.DisplayMemberPath = "Value";
            CbxCacheMaterialStatus.SelectedValuePath = "Key";

            if (Id == null)
            {
                //新增
            }
            else
            {
                //编辑
                BllResult <List <StationCache> > result = AppSession.Dal.GetCommonModelByCondition <StationCache>($"where id ={Id}");
                if (result.Success)
                {
                    CurrentStationCache = result.Data[0];
                    //CbxCacheMaterialStatus.SelectedValue = StepTraceStatus.设备请求下料.GetIndexInt();
                    //CurrentEquipmentType.Id = temp.Id;
                    //CurrentEquipmentType.Code = temp.Code;
                    //CurrentEquipmentType.Name = temp.Name;
                    //CurrentEquipmentType.Description = temp.Description;
                    //CurrentEquipmentType.Created = temp.Created;
                    //CurrentEquipmentType.CreatedBy = temp.CreatedBy;
                    //TxtEquipmentTypeCode.IsReadOnly = true;
                }
                else
                {
                    MessageBox.Show($"查询设备类型详情失败:{result.Msg}");
                }
            }
        }
        private void QueryDetail(StationCache item)
        {
            //重新查询一遍主数据,防止同步删除
            BllResult <List <StationCache> > result = AppSession.Dal.GetCommonModelByCondition <StationCache>($"where id ={item.Id}");

            if (result.Success)
            {
                var temp = result.Data[0];
                CurrentStationCache.Id = temp.Id;
                //CurrentStationCache.Code = temp.Code;
                //CurrentStationCache.Name = temp.Name;
                //CurrentStationCache.Description = temp.Description;
                CurrentStationCache.CreateTime = temp.CreateTime;
                CurrentStationCache.CreateBy   = temp.CreateBy;
                CurrentStationCache.CreateTime = temp.CreateTime;
                CurrentStationCache.UpdateBy   = temp.UpdateBy;

                string sql = " ";
                if (!String.IsNullOrWhiteSpace(TxtMainCode.Text))
                {
                    sql += $" and WONumber like '%{TxtMainCode.Text}%'";
                }
                if (!String.IsNullOrWhiteSpace(TxtMainId.Text))
                {
                    sql += $" and stationCacheId like '%{TxtMainId.Text}%'";
                }

                //查询属性模板
                //var a = AppSession.Dal.GetCommonModelByCondition<CutPlan>(sql );
                var a = AppSession.Dal.GetCommonModelByCondition <CutPlan>($"where stationCacheId = {CurrentStationCache.Id}" + sql);
                if (a.Success)
                {
                    DGDetail.ItemsSource = a.Data;
                }
                else
                {
                    DGDetail.ItemsSource = null;
                    MessageBox.Show($"查询当前套料结果模板失败:{a.Msg}");
                }
                TIDetail.IsSelected = true;
            }
            else
            {
                MessageBox.Show("未能查询到主数据,请刷新");
                CacheMaterialPanl.IsSelected = true;
            }
        }
 private void BtnEdit_Click(object sender, RoutedEventArgs e)
 {
     if (DGMain.SelectedItem == null)
     {
         MessageBox.Show("请先选中一条数据!");
         return;
     }
     if (DGMain.SelectedItems.Count > 1)
     {
         MessageBox.Show("每次只能选择一条");
         return;
     }
     else
     {
         StationCache temp             = (StationCache)DGMain.SelectedItem;
         WinCacheMaterialAddOrEdit win = new WinCacheMaterialAddOrEdit(temp.Id);
         win.ShowDialog();
         Query();
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 执行下料请求
        /// 注意:allEquipments引用所有设备,此为共享应用
        /// </summary>
        /// <param name="lengthMeasuring"></param>
        /// <param name="allEquipments"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public override BllResult ExcuteRequest(Equipment lengthMeasuringMachine, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc)
        {
            try
            {
                //接收PLC传来的长度
                var pipeLength          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestLength.ToString());
                var lengthConvertResult = int.TryParse(pipeLength.Value, out int length);
                //接收PLC传来的材质
                var pipeMaterial          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestMaterial.ToString());
                var materialConvertResult = int.TryParse(pipeMaterial.Value, out int materialType);
                //接收PLC传来的壁厚
                var pipeThickness          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestThickness.ToString());
                var thicknessConvertResult = decimal.TryParse(pipeThickness.Value, out decimal thickness);
                //接收PLC传来的内径
                var pipeDiameter          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestDiameter.ToString());
                var diameterConvertResult = decimal.TryParse(pipeDiameter.Value, out decimal diameter);

                if (!lengthConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的长度[{pipeLength.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!materialConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的材质[{pipeMaterial.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!thicknessConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的壁厚[{pipeThickness.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!diameterConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的内径[{pipeDiameter.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }

                var nextEquipment = allEquipments.FirstOrDefault(t => t.SelfAddress == lengthMeasuringMachine.GoAddress.ToString());

                //对缓存表做判断,小于12条记录说明缓存区没满,可以下料
                var cacheInfo = AppSession.Dal.GetCommonModelByConditionWithZero <StationCache>($" where  stationCode = '{nextEquipment.StationCode}' and status < {StationCacheStatus.使用中.GetIndexInt()}");
                if (!cacheInfo.Success)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,查询缓存区失败,原因:[{cacheInfo.Msg}]", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (cacheInfo.Data.Count >= 11)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,缓存区已满,请等待缓存区腾出位置", LogLevel.Warning);
                    return(BllResultFactory.Error());
                }
                var requestNumber = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MachineProps.RequestNumber.ToString());

                //生成缓存记录并且插入数据库
                StationCache stationCache = new StationCache();
                stationCache.StationId      = lengthMeasuringMachine.StationId;
                stationCache.StationCode    = lengthMeasuringMachine.StationCode;
                stationCache.WcsProductType = materialType;
                stationCache.Thickness      = thickness / 10;
                stationCache.Diameter       = diameter / 10;
                stationCache.MaterialLength = length;
                stationCache.Status         = StationCacheStatus.初始.GetIndexInt();
                stationCache.CreateBy       = App.User.UserCode;
                stationCache.CreateTime     = DateTime.Now;
                var insertResult = AppSession.Dal.InsertCommonModel <StationCache>(stationCache);
                if (!insertResult.Success)
                {
                    Logger.Log($"处理工位[{lengthMeasuringMachine.StationCode}]的设备[{lengthMeasuringMachine.Name}] 下料请求的时候,插入管材信息到数据库失败,原因:{insertResult.Msg}", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                stationCache.Id = insertResult.Data;
                var sendResult = SendAddressReplyToPlc(lengthMeasuringMachine, plc, MachineMessageFlag.WCS回复允许下料, requestNumber.Value, stationCache.Id.ToString(), "", "0", stationCache.WcsProductType.ToString(), stationCache.MaterialLength.ToString(), stationCache.Diameter.ToString(), stationCache.Thickness.ToString(), lengthMeasuringMachine.GoAddress);
                if (sendResult.Success)
                {
                    Logger.Log($"处理工位[{lengthMeasuringMachine.StationCode}]的设备[{lengthMeasuringMachine.Name}] 下料请求 成功,管子缓存标识[{stationCache.Id}],管子材质[{stationCache.WcsProductType}],管子长度[{stationCache.MaterialLength}],管子直径[{stationCache.Diameter}],管子壁厚[{stationCache.Thickness}]", LogLevel.Success);
                    return(BllResultFactory.Sucess());
                }
                else
                {
                    AppSession.Dal.DeleteCommonModelByIds <StationCache>(new List <int>()
                    {
                        stationCache.Id.Value
                    });
                    Logger.Log($"处理工位[{lengthMeasuringMachine.StationCode}]的设备[{lengthMeasuringMachine.Name}] 下料请求的时候,管子缓存标识[{stationCache.Id}]对应的信息写入PLC失败,原因:{sendResult.Msg}", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
                return(BllResultFactory.Error());
            }
        }
        protected override BllResult ExcuteArrive(Equipment AssemblyCcache, List <Equipment> allEquipments, List <StepTrace> stepTraceList, IPLC plc)
        {
            try
            {
                var ArriveTaskId = AssemblyCcache.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PipeLineProps.ArriveTaskId.ToString());
                if (string.IsNullOrWhiteSpace(ArriveTaskId.Value))
                {
                    Logger.Log($"处理工位位[{AssemblyCcache.StationCode}]的设备[{AssemblyCcache.Name}] 位置到达失败,原因:有位置到达但是没有任务号信息", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                //var count = stepTraceList.Count(t => t.StationId == AssemblyCcache.StationId);
                //if (count > 1)
                //{
                //    Logger.Log($"处理工位[{AssemblyCcache.StationId}]设备[{AssemblyCcache.Name}]位置到达的时候,出现数据错误,站台有多个对应的任务", LogLevel.Error);
                //    return BllResultFactory.Error();
                //}
                var number    = AssemblyCcache.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == PipeLineProps.ArriveRealAddress.ToString());
                var stepTrace = stepTraceList.FirstOrDefault(t => t.Id == Convert.ToInt32(ArriveTaskId.Value));
                if (stepTrace == null)
                {
                    Logger.Log($"处理工位位[{AssemblyCcache.StationCode}]的设备[{AssemblyCcache.Name}]位置到达失败,找不到未完成的工序任务id[{ArriveTaskId.Value}]", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                //更新数据
                stepTrace.StationId     = stepTrace.NextStationId;
                stepTrace.NextStationId = 0;
                stepTrace.Status        = StepTraceStatus.设备开始生产.GetIndexInt();
                stepTrace.UpdateTime    = DateTime.Now;
                stepTrace.UpdateBy      = App.User.UserCode;

                //生成缓存记录并且插入数据库
                StationCache stationCache = new StationCache();
                stationCache.stepTraceId    = stepTrace.Id;
                stationCache.StationId      = AssemblyCcache.StationId;
                stationCache.StationCode    = AssemblyCcache.StationCode;
                stationCache.MaterialLength = stepTrace.PipeLength;
                stationCache.WcsProductType = stepTrace.PipeMaterial;
                stationCache.Thickness      = stepTrace.PipeThickness;
                stationCache.Diameter       = stepTrace.PipeDiameter;
                stationCache.Status         = StationCacheStatus.初始.GetIndexInt();
                stationCache.CreateBy       = App.User.UserCode;
                stationCache.CreateTime     = DateTime.Now;

                using (IDbConnection connection = AppSession.Dal.GetConnection())
                {
                    IDbTransaction tran = null;
                    try
                    {
                        connection.Open();
                        tran = connection.BeginTransaction();
                        connection.Update <StepTrace>(stepTrace, transaction: tran);
                        connection.Insert <StationCache>(stationCache, transaction: tran);
                        BllResult plcResult = SendAckToPlc(AssemblyCcache, plc, StationMessageFlag.WCSPLCACK, StationLoadStatus.回复到达, number.Value, stepTrace.Id.ToString(), "", stepTrace.WcsProductType.ToString(), stepTrace.PipeLength.ToString(), stepTrace.PipeDiameter.ToString(), stepTrace.PipeThickness.ToString(), stepTrace.WeldingNo);
                        if (plcResult.Success)
                        {
                            tran.Commit();
                            Logger.Log($"处理工位[{AssemblyCcache.StationCode}]的设备[{AssemblyCcache.Name}] 响应位置到达 成功,任务:{stepTrace.Id}", LogLevel.Success);
                            return(BllResultFactory.Sucess());
                        }
                        else
                        {
                            tran?.Rollback();
                            Logger.Log($"处理工位[{AssemblyCcache.StationCode}]的设备[{AssemblyCcache.Name}] 响应位置到达的时候,写入PLC失败,任务:{stepTrace.Id},原因:{plcResult.Msg}", LogLevel.Error);
                            return(BllResultFactory.Error());
                        }
                    }
                    catch (Exception ex)
                    {
                        tran?.Rollback();
                        Logger.Log($"处理工位[{AssemblyCcache.StationCode}]的设备[{AssemblyCcache.Name}] 响应位置到达的时候,发生异常,任务:{stepTrace.Id},原因:{ex.Message}", LogLevel.Exception, ex);
                        return(BllResultFactory.Error());
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"处理工位[{AssemblyCcache.StationId}]设备[{AssemblyCcache.Name}]位置到达时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
                return(BllResultFactory.Error());
            }
        }
        /// <summary>
        /// 执行下料请求
        /// 注意:allEquipments引用所有设备,此为共享应用
        /// </summary>
        /// <param name="lengthMeasuring"></param>
        /// <param name="allEquipments"></param>
        /// <param name="plc"></param>
        /// <returns></returns>
        public override BllResult ExcuteRequest(Equipment lengthMeasuringMachine, List <Equipment> allEquipments, List <Equipment> lthMeasuringCaches, IPLC plc)
        {
            try
            {
                //接收PLC传来的长度
                var pipeLength          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MeasuringMachineToECSProps.Length.ToString());
                var lengthConvertResult = int.TryParse(pipeLength.Value, out int length);
                //接收PLC传来的材质
                var pipeMaterial          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MeasuringMachineToECSProps.Material.ToString());
                var materialConvertResult = int.TryParse(pipeMaterial.Value, out int materialType);
                //接收PLC传来的壁厚
                var pipeThickness          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MeasuringMachineToECSProps.Thickness.ToString());
                var thicknessConvertResult = int.TryParse(pipeThickness.Value, out int thickness);
                //接收PLC传来的内径
                var pipeDiameter          = lengthMeasuringMachine.EquipmentProps.Find(t => t.EquipmentTypeTemplateCode == MeasuringMachineToECSProps.Diameter.ToString());
                var diameterConvertResult = int.TryParse(pipeDiameter.Value, out int diameter);

                if (!lengthConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的长度[{pipeLength.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!materialConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的材质[{pipeMaterial.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!thicknessConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的壁厚[{pipeThickness.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                if (!diameterConvertResult)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,原材料的内径[{pipeDiameter.Value}]转化为整数失败!", LogLevel.Error);
                    return(BllResultFactory.Error());
                }

                var bevelCcache = allEquipments.FirstOrDefault(t => t.SelfAddress == lengthMeasuringMachine.GoAddress.ToString());

                //对缓存表做判断,小于12条记录说明缓存区没满,可以下料
                var cacheInfo = AppSession.Dal.GetCommonModelByConditionWithZero <StationCache>($" where  stationCode = '{bevelCcache.StationCode}' ");
                if (!cacheInfo.Success)
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,查询缓存区失败,原因:[{cacheInfo.Msg}]", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
                //测长缓存区只能放11根管子
                if (cacheInfo.Data.Count <= 11)
                {
                    //生成缓存记录并且插入数据库
                    StationCache stationCache = new StationCache();
                    stationCache.StationId      = lengthMeasuringMachine.StationId;
                    stationCache.StationCode    = lengthMeasuringMachine.StationCode;
                    stationCache.WcsProductType = materialType;
                    stationCache.Thickness      = thickness;
                    stationCache.Diameter       = diameter;
                    stationCache.MaterialLength = length;
                    stationCache.Status         = 0;
                    AppSession.Dal.InsertCommonModel <StationCache>(stationCache);
                    SendRequestToPlc(plc, lengthMeasuringMachine, true);
                }
                else
                {
                    Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求失败,缓存区已满,请等待缓存区腾出位置", LogLevel.Error);
                    return(BllResultFactory.Error());
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"处理站台[{lengthMeasuringMachine.StationId}]的设备[{lengthMeasuringMachine.Name}]下料请求时候,发生异常:{ex.Message}", LogLevel.Exception, ex);
                return(BllResultFactory.Error());
            }
            return(BllResultFactory.Sucess());
        }