diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/ViewModel/EditMaterialNameViewModel.cs b/Correlator/ViewModel/EditMaterialNameViewModel.cs index 3565c41..4127a57 100644 --- a/Correlator/ViewModel/EditMaterialNameViewModel.cs +++ b/Correlator/ViewModel/EditMaterialNameViewModel.cs @@ -1,19 +1,18 @@ using System.Linq; -using System.Text.RegularExpressions; using System.Windows; using Correlator.Dialog; -using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class EditMaterialNameViewModel : ViewModelBase { + private readonly IMaterialNameDataService _dataService; private int _materialId; private string _materialNewName; @@ -30,55 +29,39 @@ public RelayCommand DetermineParamCommand { get; set; } - public EditMaterialNameViewModel() + public EditMaterialNameViewModel(IMaterialNameDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.EditMaterialName, it => { _materialId = it; }); - DetermineParamCommand = new RelayCommand(it => + DetermineParamCommand = new RelayCommand(DetermineParam); + } + + private void DetermineParam(EditMaterialNameDialog it) + { + if (string.IsNullOrEmpty(_materialNewName)) { - if (string.IsNullOrEmpty(_materialNewName)) - { - MessageBox.Show("名称不允许为空", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + MessageBox.Show("名称不允许为空", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - if (MaterialManager.InitPipeMaterial().Any( - material => _materialNewName.Equals(material.ChineseMaterial) || - _materialNewName.Equals(material.EnglishMaterial)) - ) - { - MessageBox.Show("该名称已存在,请重新输入", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + if (MaterialManager.InitPipeMaterial().Any( + material => _materialNewName.Equals(material.ChineseMaterial) || _materialNewName.Equals(material.EnglishMaterial)) + ) + { + MessageBox.Show("该名称已存在,请重新输入", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == _materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "EditMaterialNameViewModel"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(_materialNewName)) - { - material.EnglishMaterial = _materialNewName; - } - else - { - material.ChineseMaterial = _materialNewName; - } - - manager.Update(material); - } + _dataService.EditMaterialName(_materialId, _materialNewName); - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialName); + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialName); - //返回选择材质界面 - it.Close(); - }); + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/ViewModel/EditMaterialNameViewModel.cs b/Correlator/ViewModel/EditMaterialNameViewModel.cs index 3565c41..4127a57 100644 --- a/Correlator/ViewModel/EditMaterialNameViewModel.cs +++ b/Correlator/ViewModel/EditMaterialNameViewModel.cs @@ -1,19 +1,18 @@ using System.Linq; -using System.Text.RegularExpressions; using System.Windows; using Correlator.Dialog; -using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class EditMaterialNameViewModel : ViewModelBase { + private readonly IMaterialNameDataService _dataService; private int _materialId; private string _materialNewName; @@ -30,55 +29,39 @@ public RelayCommand DetermineParamCommand { get; set; } - public EditMaterialNameViewModel() + public EditMaterialNameViewModel(IMaterialNameDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.EditMaterialName, it => { _materialId = it; }); - DetermineParamCommand = new RelayCommand(it => + DetermineParamCommand = new RelayCommand(DetermineParam); + } + + private void DetermineParam(EditMaterialNameDialog it) + { + if (string.IsNullOrEmpty(_materialNewName)) { - if (string.IsNullOrEmpty(_materialNewName)) - { - MessageBox.Show("名称不允许为空", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + MessageBox.Show("名称不允许为空", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - if (MaterialManager.InitPipeMaterial().Any( - material => _materialNewName.Equals(material.ChineseMaterial) || - _materialNewName.Equals(material.EnglishMaterial)) - ) - { - MessageBox.Show("该名称已存在,请重新输入", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + if (MaterialManager.InitPipeMaterial().Any( + material => _materialNewName.Equals(material.ChineseMaterial) || _materialNewName.Equals(material.EnglishMaterial)) + ) + { + MessageBox.Show("该名称已存在,请重新输入", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == _materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "EditMaterialNameViewModel"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(_materialNewName)) - { - material.EnglishMaterial = _materialNewName; - } - else - { - material.ChineseMaterial = _materialNewName; - } - - manager.Update(material); - } + _dataService.EditMaterialName(_materialId, _materialNewName); - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialName); + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialName); - //返回选择材质界面 - it.Close(); - }); + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index 431a4e3..54067da 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -29,12 +29,10 @@ { #region RelayCommand - public RelayCommand FilterCommand { get; set; } - public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } + public RelayCommand SaveAudioCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } public RelayCommand StartCalculateCommand { get; set; } - public RelayCommand SaveAudioCommand { get; set; } #endregion @@ -475,36 +473,37 @@ RegisterMessage(); - FilterCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // FilterCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + // { + // MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var filterUserControl = new FilterUserControl(); + // UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; + // Messenger.Default.Send("", MessengerToken.AddFilter); + // }); + // NoiseCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var noiseUserControl = new NoiseUserControl(); + // UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + // Messenger.Default.Send("", MessengerToken.AddNoise); + // }); - if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) - { - MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var filterUserControl = new FilterUserControl(); - UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; - Messenger.Default.Send("", MessengerToken.AddFilter); - }); - NoiseCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var noiseUserControl = new NoiseUserControl(); - UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; - Messenger.Default.Send("", MessengerToken.AddNoise); - }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -517,7 +516,21 @@ UserControlManager.UserControlMap["auditionUserControl"] = auditionUserControl; Messenger.Default.Send("", MessengerToken.AddAudition); }); + + SaveAudioCommand = new RelayCommand(() => + { + if (FlowStatus.CorrelatorData != null) + { + SaveAudio(); + } + else + { + MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + } + }); + ResetParamCommand = new RelayCommand(ResetParam); + StartCalculateCommand = new RelayCommand(it => { if (SerialPort.GetPortNames().Length == 0) @@ -537,17 +550,6 @@ }; materialDialog.ShowDialog(); }); - SaveAudioCommand = new RelayCommand(() => - { - if (FlowStatus.CorrelatorData != null) - { - SaveAudio(); - } - else - { - MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - } - }); //计算时间Timer _runningTimer.Tick += delegate @@ -673,7 +675,7 @@ NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task - new Task(CollectData).Start(); + Task.Factory.StartNew(CollectData); //记录计算时间 _runningTimer.Start(); diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/ViewModel/EditMaterialNameViewModel.cs b/Correlator/ViewModel/EditMaterialNameViewModel.cs index 3565c41..4127a57 100644 --- a/Correlator/ViewModel/EditMaterialNameViewModel.cs +++ b/Correlator/ViewModel/EditMaterialNameViewModel.cs @@ -1,19 +1,18 @@ using System.Linq; -using System.Text.RegularExpressions; using System.Windows; using Correlator.Dialog; -using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class EditMaterialNameViewModel : ViewModelBase { + private readonly IMaterialNameDataService _dataService; private int _materialId; private string _materialNewName; @@ -30,55 +29,39 @@ public RelayCommand DetermineParamCommand { get; set; } - public EditMaterialNameViewModel() + public EditMaterialNameViewModel(IMaterialNameDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.EditMaterialName, it => { _materialId = it; }); - DetermineParamCommand = new RelayCommand(it => + DetermineParamCommand = new RelayCommand(DetermineParam); + } + + private void DetermineParam(EditMaterialNameDialog it) + { + if (string.IsNullOrEmpty(_materialNewName)) { - if (string.IsNullOrEmpty(_materialNewName)) - { - MessageBox.Show("名称不允许为空", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + MessageBox.Show("名称不允许为空", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - if (MaterialManager.InitPipeMaterial().Any( - material => _materialNewName.Equals(material.ChineseMaterial) || - _materialNewName.Equals(material.EnglishMaterial)) - ) - { - MessageBox.Show("该名称已存在,请重新输入", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + if (MaterialManager.InitPipeMaterial().Any( + material => _materialNewName.Equals(material.ChineseMaterial) || _materialNewName.Equals(material.EnglishMaterial)) + ) + { + MessageBox.Show("该名称已存在,请重新输入", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == _materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "EditMaterialNameViewModel"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(_materialNewName)) - { - material.EnglishMaterial = _materialNewName; - } - else - { - material.ChineseMaterial = _materialNewName; - } - - manager.Update(material); - } + _dataService.EditMaterialName(_materialId, _materialNewName); - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialName); + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialName); - //返回选择材质界面 - it.Close(); - }); + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index 431a4e3..54067da 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -29,12 +29,10 @@ { #region RelayCommand - public RelayCommand FilterCommand { get; set; } - public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } + public RelayCommand SaveAudioCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } public RelayCommand StartCalculateCommand { get; set; } - public RelayCommand SaveAudioCommand { get; set; } #endregion @@ -475,36 +473,37 @@ RegisterMessage(); - FilterCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // FilterCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + // { + // MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var filterUserControl = new FilterUserControl(); + // UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; + // Messenger.Default.Send("", MessengerToken.AddFilter); + // }); + // NoiseCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var noiseUserControl = new NoiseUserControl(); + // UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + // Messenger.Default.Send("", MessengerToken.AddNoise); + // }); - if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) - { - MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var filterUserControl = new FilterUserControl(); - UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; - Messenger.Default.Send("", MessengerToken.AddFilter); - }); - NoiseCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var noiseUserControl = new NoiseUserControl(); - UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; - Messenger.Default.Send("", MessengerToken.AddNoise); - }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -517,7 +516,21 @@ UserControlManager.UserControlMap["auditionUserControl"] = auditionUserControl; Messenger.Default.Send("", MessengerToken.AddAudition); }); + + SaveAudioCommand = new RelayCommand(() => + { + if (FlowStatus.CorrelatorData != null) + { + SaveAudio(); + } + else + { + MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + } + }); + ResetParamCommand = new RelayCommand(ResetParam); + StartCalculateCommand = new RelayCommand(it => { if (SerialPort.GetPortNames().Length == 0) @@ -537,17 +550,6 @@ }; materialDialog.ShowDialog(); }); - SaveAudioCommand = new RelayCommand(() => - { - if (FlowStatus.CorrelatorData != null) - { - SaveAudio(); - } - else - { - MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - } - }); //计算时间Timer _runningTimer.Tick += delegate @@ -673,7 +675,7 @@ NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task - new Task(CollectData).Start(); + Task.Factory.StartNew(CollectData); //记录计算时间 _runningTimer.Start(); diff --git a/Correlator/ViewModel/PipeMaterialViewModel.cs b/Correlator/ViewModel/PipeMaterialViewModel.cs index 3f88cda..a3898e5 100644 --- a/Correlator/ViewModel/PipeMaterialViewModel.cs +++ b/Correlator/ViewModel/PipeMaterialViewModel.cs @@ -3,11 +3,11 @@ using System.Windows.Controls; using Correlator.Dialog; using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel @@ -20,6 +20,7 @@ public RelayCommand ItemSelectedCommand { get; set; } public RelayCommand NextStepCommand { get; set; } + private readonly IPipeMaterialDataService _dataService; private PipeMaterialModel _materialData; private ObservableCollection _pipeMaterials; @@ -34,8 +35,9 @@ } } - public PipeMaterialViewModel() + public PipeMaterialViewModel(IPipeMaterialDataService dataService) { + _dataService = dataService; PipeMaterials = MaterialManager.InitPipeMaterial(); ResetDefaultValueCommand = new RelayCommand(ResetDefaultValue); @@ -117,15 +119,7 @@ return; } - using (var manager = new DataBaseManager()) - { - _materialData.SoundSpeed = 0; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(_materialData), - "PipeMaterialViewModel"); - - manager.Update(_materialData); - } + _dataService.ResetDefaultValue(_materialData); PipeMaterials = MaterialManager.InitPipeMaterial(); } diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/ViewModel/EditMaterialNameViewModel.cs b/Correlator/ViewModel/EditMaterialNameViewModel.cs index 3565c41..4127a57 100644 --- a/Correlator/ViewModel/EditMaterialNameViewModel.cs +++ b/Correlator/ViewModel/EditMaterialNameViewModel.cs @@ -1,19 +1,18 @@ using System.Linq; -using System.Text.RegularExpressions; using System.Windows; using Correlator.Dialog; -using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class EditMaterialNameViewModel : ViewModelBase { + private readonly IMaterialNameDataService _dataService; private int _materialId; private string _materialNewName; @@ -30,55 +29,39 @@ public RelayCommand DetermineParamCommand { get; set; } - public EditMaterialNameViewModel() + public EditMaterialNameViewModel(IMaterialNameDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.EditMaterialName, it => { _materialId = it; }); - DetermineParamCommand = new RelayCommand(it => + DetermineParamCommand = new RelayCommand(DetermineParam); + } + + private void DetermineParam(EditMaterialNameDialog it) + { + if (string.IsNullOrEmpty(_materialNewName)) { - if (string.IsNullOrEmpty(_materialNewName)) - { - MessageBox.Show("名称不允许为空", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + MessageBox.Show("名称不允许为空", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - if (MaterialManager.InitPipeMaterial().Any( - material => _materialNewName.Equals(material.ChineseMaterial) || - _materialNewName.Equals(material.EnglishMaterial)) - ) - { - MessageBox.Show("该名称已存在,请重新输入", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + if (MaterialManager.InitPipeMaterial().Any( + material => _materialNewName.Equals(material.ChineseMaterial) || _materialNewName.Equals(material.EnglishMaterial)) + ) + { + MessageBox.Show("该名称已存在,请重新输入", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == _materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "EditMaterialNameViewModel"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(_materialNewName)) - { - material.EnglishMaterial = _materialNewName; - } - else - { - material.ChineseMaterial = _materialNewName; - } - - manager.Update(material); - } + _dataService.EditMaterialName(_materialId, _materialNewName); - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialName); + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialName); - //返回选择材质界面 - it.Close(); - }); + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index 431a4e3..54067da 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -29,12 +29,10 @@ { #region RelayCommand - public RelayCommand FilterCommand { get; set; } - public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } + public RelayCommand SaveAudioCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } public RelayCommand StartCalculateCommand { get; set; } - public RelayCommand SaveAudioCommand { get; set; } #endregion @@ -475,36 +473,37 @@ RegisterMessage(); - FilterCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // FilterCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + // { + // MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var filterUserControl = new FilterUserControl(); + // UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; + // Messenger.Default.Send("", MessengerToken.AddFilter); + // }); + // NoiseCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var noiseUserControl = new NoiseUserControl(); + // UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + // Messenger.Default.Send("", MessengerToken.AddNoise); + // }); - if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) - { - MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var filterUserControl = new FilterUserControl(); - UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; - Messenger.Default.Send("", MessengerToken.AddFilter); - }); - NoiseCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var noiseUserControl = new NoiseUserControl(); - UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; - Messenger.Default.Send("", MessengerToken.AddNoise); - }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -517,7 +516,21 @@ UserControlManager.UserControlMap["auditionUserControl"] = auditionUserControl; Messenger.Default.Send("", MessengerToken.AddAudition); }); + + SaveAudioCommand = new RelayCommand(() => + { + if (FlowStatus.CorrelatorData != null) + { + SaveAudio(); + } + else + { + MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + } + }); + ResetParamCommand = new RelayCommand(ResetParam); + StartCalculateCommand = new RelayCommand(it => { if (SerialPort.GetPortNames().Length == 0) @@ -537,17 +550,6 @@ }; materialDialog.ShowDialog(); }); - SaveAudioCommand = new RelayCommand(() => - { - if (FlowStatus.CorrelatorData != null) - { - SaveAudio(); - } - else - { - MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - } - }); //计算时间Timer _runningTimer.Tick += delegate @@ -673,7 +675,7 @@ NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task - new Task(CollectData).Start(); + Task.Factory.StartNew(CollectData); //记录计算时间 _runningTimer.Start(); diff --git a/Correlator/ViewModel/PipeMaterialViewModel.cs b/Correlator/ViewModel/PipeMaterialViewModel.cs index 3f88cda..a3898e5 100644 --- a/Correlator/ViewModel/PipeMaterialViewModel.cs +++ b/Correlator/ViewModel/PipeMaterialViewModel.cs @@ -3,11 +3,11 @@ using System.Windows.Controls; using Correlator.Dialog; using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel @@ -20,6 +20,7 @@ public RelayCommand ItemSelectedCommand { get; set; } public RelayCommand NextStepCommand { get; set; } + private readonly IPipeMaterialDataService _dataService; private PipeMaterialModel _materialData; private ObservableCollection _pipeMaterials; @@ -34,8 +35,9 @@ } } - public PipeMaterialViewModel() + public PipeMaterialViewModel(IPipeMaterialDataService dataService) { + _dataService = dataService; PipeMaterials = MaterialManager.InitPipeMaterial(); ResetDefaultValueCommand = new RelayCommand(ResetDefaultValue); @@ -117,15 +119,7 @@ return; } - using (var manager = new DataBaseManager()) - { - _materialData.SoundSpeed = 0; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(_materialData), - "PipeMaterialViewModel"); - - manager.Update(_materialData); - } + _dataService.ResetDefaultValue(_materialData); PipeMaterials = MaterialManager.InitPipeMaterial(); } diff --git a/Correlator/ViewModel/SoundSpeedViewModel.cs b/Correlator/ViewModel/SoundSpeedViewModel.cs index 24ddbe9..63bdf84 100644 --- a/Correlator/ViewModel/SoundSpeedViewModel.cs +++ b/Correlator/ViewModel/SoundSpeedViewModel.cs @@ -3,17 +3,18 @@ using System.Windows.Controls; using Correlator.Dialog; using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class SoundSpeedViewModel : ViewModelBase { + private readonly ISoundSpeedDataService _dataService; private string _materialName; private MaterialVelocity _materialVelocity; @@ -35,82 +36,28 @@ public RelayCommand ItemSelectedCommand { get; set; } public RelayCommand NextStepCommand { get; set; } - public SoundSpeedViewModel() + public SoundSpeedViewModel(ISoundSpeedDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.SoundSpeed, it => { _materialName = it; //查询数据库 - VelocityCollection = GetVelocityCollection(_materialName); + VelocityCollection = _dataService.GetVelocityCollection(_materialName); }); Messenger.Default.Register(this, MessengerToken.UpdateSoundSpeed, - it => { VelocityCollection = GetVelocityCollection(_materialName); }); + it => { VelocityCollection = _dataService.GetVelocityCollection(_materialName); }); ItemSelectedCommand = new RelayCommand(ItemSelected); - - DeleteSpeedCommand = new RelayCommand(delegate - { - if (_materialVelocity == null) - { - MessageBox.Show("未选择任何项,无法删除", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - var result = MessageBox.Show("是否删除?删除后无法恢复", - "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); - if (result == MessageBoxResult.Cancel) - { - return; - } + DeleteSpeedCommand = new RelayCommand(DeleteSpeed); - DeleteVelocity(_materialVelocity); - VelocityCollection = GetVelocityCollection(_materialName); - }); + AddSpeedCommand = new RelayCommand(AddSpeed); - AddSpeedCommand = new RelayCommand(it => - { - var addSoundSpeedDialog = new AddSoundSpeedDialog(_materialName) - { - Owner = Window.GetWindow(it) - }; - addSoundSpeedDialog.ShowDialog(); - }); + EditSpeedCommand = new RelayCommand(EditSpeed); - EditSpeedCommand = new RelayCommand(it => - { - if (_materialVelocity == null) - { - MessageBox.Show("未选择任何项,无法编辑", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var editSoundSpeedDialog = new EditSoundSpeedDialog(_materialVelocity) - { - Owner = Window.GetWindow(it) - }; - editSoundSpeedDialog.ShowDialog(); - }); - - NextStepCommand = new RelayCommand(it => - { - if (_materialVelocity == null) - { - MessageBox.Show("还未选择任何材料,无法进行下一步操作", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - UpdatePipeMaterial(_materialName, _materialVelocity); - - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialSoundSpeed); - - //返回选择材质界面 - it.Close(); - }); + NextStepCommand = new RelayCommand(UpdatePipeMaterial); } private void ItemSelected(object sender) @@ -119,46 +66,67 @@ _materialVelocity = (MaterialVelocity)listView.SelectedItem; } - private ObservableCollection GetVelocityCollection(string materialName) + private void DeleteSpeed() { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) + if (_materialVelocity == null) { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } + MessageBox.Show("未选择任何项,无法删除", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - return velocityCollection; + var result = MessageBox.Show("是否删除?删除后无法恢复", + "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); + if (result == MessageBoxResult.Cancel) + { + return; + } + + _dataService.DeleteVelocity(_materialVelocity); + VelocityCollection = _dataService.GetVelocityCollection(_materialName); } - private void DeleteVelocity(MaterialVelocity velocity) + private void AddSpeed(SoundSpeedDialog it) { - using (var manager = new DataBaseManager()) + var addSoundSpeedDialog = new AddSoundSpeedDialog(_materialName) { - manager.Delete(velocity); - } + Owner = Window.GetWindow(it) + }; + addSoundSpeedDialog.ShowDialog(); } - private void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + private void EditSpeed(SoundSpeedDialog it) { - using (var manager = new DataBaseManager()) + if (_materialVelocity == null) { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedViewModel"); - - manager.Update(materialModel); + MessageBox.Show("未选择任何项,无法编辑", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; } + + var editSoundSpeedDialog = new EditSoundSpeedDialog(_materialVelocity) + { + Owner = Window.GetWindow(it) + }; + editSoundSpeedDialog.ShowDialog(); + } + + private void UpdatePipeMaterial(SoundSpeedDialog it) + { + if (_materialVelocity == null) + { + MessageBox.Show("还未选择任何材料,无法进行下一步操作", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + _dataService.UpdatePipeMaterial(_materialName, _materialVelocity); + + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialSoundSpeed); + + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/Correlator.csproj b/Correlator/Correlator.csproj index 496e854..1846fee 100644 --- a/Correlator/Correlator.csproj +++ b/Correlator/Correlator.csproj @@ -235,10 +235,12 @@ PictureFileUserControl.xaml + + + + - - diff --git a/Correlator/Service/IMaterialNameDataService.cs b/Correlator/Service/IMaterialNameDataService.cs index 8dd6b51..3115d4d 100644 --- a/Correlator/Service/IMaterialNameDataService.cs +++ b/Correlator/Service/IMaterialNameDataService.cs @@ -2,6 +2,6 @@ { public interface IMaterialNameDataService { - void UpdateMaterialName(int materialId, string materialNewName); + void EditMaterialName(int materialId, string materialNewName); } } \ No newline at end of file diff --git a/Correlator/Service/IPipeMaterialDataService.cs b/Correlator/Service/IPipeMaterialDataService.cs new file mode 100644 index 0000000..349f22d --- /dev/null +++ b/Correlator/Service/IPipeMaterialDataService.cs @@ -0,0 +1,9 @@ +using Correlator.Model; + +namespace Correlator.Service +{ + public interface IPipeMaterialDataService + { + void ResetDefaultValue(PipeMaterialModel materialData); + } +} \ No newline at end of file diff --git a/Correlator/Service/MaterialNameDataService.cs b/Correlator/Service/MaterialNameDataService.cs deleted file mode 100644 index bd37900..0000000 --- a/Correlator/Service/MaterialNameDataService.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class MaterialNameDataService : IMaterialNameDataService - { - public void UpdateMaterialName(int materialId, string materialNewName) - { - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "MaterialNameDataService"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(materialNewName)) - { - material.EnglishMaterial = materialNewName; - } - else - { - material.ChineseMaterial = materialNewName; - } - - manager.Update(material); - } - } - } -} \ No newline at end of file diff --git a/Correlator/Service/SoundSpeedDataService.cs b/Correlator/Service/SoundSpeedDataService.cs deleted file mode 100644 index fe2a03c..0000000 --- a/Correlator/Service/SoundSpeedDataService.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System.Collections.ObjectModel; -using Correlator.Model; -using Correlator.Util; -using Newtonsoft.Json; - -namespace Correlator.Service -{ - public class SoundSpeedDataService : ISoundSpeedDataService - { - public ObservableCollection GetVelocityCollection(string materialName) - { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) - { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } - } - - return velocityCollection; - } - - public void DeleteVelocity(MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - manager.Delete(velocity); - } - } - - public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) - { - using (var manager = new DataBaseManager()) - { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedDataService"); - - manager.Update(materialModel); - } - } - } -} \ No newline at end of file diff --git a/Correlator/ServiceImpl/MaterialNameDataService.cs b/Correlator/ServiceImpl/MaterialNameDataService.cs new file mode 100644 index 0000000..ad923c6 --- /dev/null +++ b/Correlator/ServiceImpl/MaterialNameDataService.cs @@ -0,0 +1,34 @@ +using System.Text.RegularExpressions; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class MaterialNameDataService : IMaterialNameDataService + { + public void EditMaterialName(int materialId, string materialNewName) + { + using (var manager = new DataBaseManager()) + { + var material = manager.Table().First(x => x.Id == materialId); + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), + "MaterialNameDataService"); + + //判断是否是英文 + var regEnglish = new Regex("^[a-zA-Z]"); + if (regEnglish.IsMatch(materialNewName)) + { + material.EnglishMaterial = materialNewName; + } + else + { + material.ChineseMaterial = materialNewName; + } + + manager.Update(material); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/PipeMaterialDataService.cs b/Correlator/ServiceImpl/PipeMaterialDataService.cs new file mode 100644 index 0000000..15f2598 --- /dev/null +++ b/Correlator/ServiceImpl/PipeMaterialDataService.cs @@ -0,0 +1,23 @@ +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + internal class PipeMaterialDataService : IPipeMaterialDataService + { + public void ResetDefaultValue(PipeMaterialModel materialData) + { + using (var manager = new DataBaseManager()) + { + materialData.SoundSpeed = 0; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialData), + "PipeMaterialDataService"); + + manager.Update(materialData); + } + } + } +} \ No newline at end of file diff --git a/Correlator/ServiceImpl/SoundSpeedDataService.cs b/Correlator/ServiceImpl/SoundSpeedDataService.cs new file mode 100644 index 0000000..671c2d9 --- /dev/null +++ b/Correlator/ServiceImpl/SoundSpeedDataService.cs @@ -0,0 +1,53 @@ +using System.Collections.ObjectModel; +using Correlator.Model; +using Correlator.Service; +using Correlator.Util; +using Newtonsoft.Json; + +namespace Correlator.ServiceImpl +{ + public class SoundSpeedDataService : ISoundSpeedDataService + { + public ObservableCollection GetVelocityCollection(string materialName) + { + var velocityCollection = new ObservableCollection(); + using (var manager = new DataBaseManager()) + { + var velocities = manager + .Table() + .Where(x => x.MaterialName == materialName) + .ToList(); + foreach (var model in velocities) + { + velocityCollection.Add(model); + } + } + + return velocityCollection; + } + + public void DeleteVelocity(MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + manager.Delete(velocity); + } + } + + public void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + { + using (var manager = new DataBaseManager()) + { + var materialModel = manager + .Table() + .FirstOrDefault(x => x.ChineseMaterial == materialName); + materialModel.SoundSpeed = velocity.Velocity; + + LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), + "SoundSpeedDataService"); + + manager.Update(materialModel); + } + } + } +} \ No newline at end of file diff --git a/Correlator/View/HomePageWindow.xaml b/Correlator/View/HomePageWindow.xaml index 26a6975..abb4526 100644 --- a/Correlator/View/HomePageWindow.xaml +++ b/Correlator/View/HomePageWindow.xaml @@ -156,9 +156,9 @@ - + - + @@ -392,7 +392,7 @@ Foreground="#545454" Text="{Binding TransmitterADistance, StringFormat=\{0\}}" /> @@ -434,7 +434,7 @@ Foreground="#545454" Text="{Binding TransmitterBDistance, StringFormat=\{0\}}" /> @@ -477,32 +477,6 @@ - - - + + + + - diff --git a/Correlator/ViewModel/EditMaterialNameViewModel.cs b/Correlator/ViewModel/EditMaterialNameViewModel.cs index 3565c41..4127a57 100644 --- a/Correlator/ViewModel/EditMaterialNameViewModel.cs +++ b/Correlator/ViewModel/EditMaterialNameViewModel.cs @@ -1,19 +1,18 @@ using System.Linq; -using System.Text.RegularExpressions; using System.Windows; using Correlator.Dialog; -using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class EditMaterialNameViewModel : ViewModelBase { + private readonly IMaterialNameDataService _dataService; private int _materialId; private string _materialNewName; @@ -30,55 +29,39 @@ public RelayCommand DetermineParamCommand { get; set; } - public EditMaterialNameViewModel() + public EditMaterialNameViewModel(IMaterialNameDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.EditMaterialName, it => { _materialId = it; }); - DetermineParamCommand = new RelayCommand(it => + DetermineParamCommand = new RelayCommand(DetermineParam); + } + + private void DetermineParam(EditMaterialNameDialog it) + { + if (string.IsNullOrEmpty(_materialNewName)) { - if (string.IsNullOrEmpty(_materialNewName)) - { - MessageBox.Show("名称不允许为空", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + MessageBox.Show("名称不允许为空", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - if (MaterialManager.InitPipeMaterial().Any( - material => _materialNewName.Equals(material.ChineseMaterial) || - _materialNewName.Equals(material.EnglishMaterial)) - ) - { - MessageBox.Show("该名称已存在,请重新输入", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + if (MaterialManager.InitPipeMaterial().Any( + material => _materialNewName.Equals(material.ChineseMaterial) || _materialNewName.Equals(material.EnglishMaterial)) + ) + { + MessageBox.Show("该名称已存在,请重新输入", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } - using (var manager = new DataBaseManager()) - { - var material = manager.Table().First(x => x.Id == _materialId); - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(material), - "EditMaterialNameViewModel"); - - //判断是否是英文 - var regEnglish = new Regex("^[a-zA-Z]"); - if (regEnglish.IsMatch(_materialNewName)) - { - material.EnglishMaterial = _materialNewName; - } - else - { - material.ChineseMaterial = _materialNewName; - } - - manager.Update(material); - } + _dataService.EditMaterialName(_materialId, _materialNewName); - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialName); + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialName); - //返回选择材质界面 - it.Close(); - }); + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/HomePageViewModel.cs b/Correlator/ViewModel/HomePageViewModel.cs index 431a4e3..54067da 100644 --- a/Correlator/ViewModel/HomePageViewModel.cs +++ b/Correlator/ViewModel/HomePageViewModel.cs @@ -29,12 +29,10 @@ { #region RelayCommand - public RelayCommand FilterCommand { get; set; } - public RelayCommand NoiseCommand { get; set; } public RelayCommand AudioCommand { get; set; } + public RelayCommand SaveAudioCommand { get; set; } public RelayCommand ResetParamCommand { get; set; } public RelayCommand StartCalculateCommand { get; set; } - public RelayCommand SaveAudioCommand { get; set; } #endregion @@ -475,36 +473,37 @@ RegisterMessage(); - FilterCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } + // FilterCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) + // { + // MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var filterUserControl = new FilterUserControl(); + // UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; + // Messenger.Default.Send("", MessengerToken.AddFilter); + // }); + // NoiseCommand = new RelayCommand(() => + // { + // if (!SerialPortManager.Instance.PortIsReady()) + // { + // MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + // return; + // } + // + // var noiseUserControl = new NoiseUserControl(); + // UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; + // Messenger.Default.Send("", MessengerToken.AddNoise); + // }); - if (FlowStatus.SelectedMaterialModel == null || FlowStatus.CorrelatorData == null) - { - MessageBox.Show("还未采集数据,无法进行频段筛选", "错误", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var filterUserControl = new FilterUserControl(); - UserControlManager.UserControlMap["filterUserControl"] = filterUserControl; - Messenger.Default.Send("", MessengerToken.AddFilter); - }); - NoiseCommand = new RelayCommand(() => - { - if (!SerialPortManager.Instance.PortIsReady()) - { - MessageBox.Show("串口状态异常,无法操作", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var noiseUserControl = new NoiseUserControl(); - UserControlManager.UserControlMap["noiseUserControl"] = noiseUserControl; - Messenger.Default.Send("", MessengerToken.AddNoise); - }); AudioCommand = new RelayCommand(() => { if (!SerialPortManager.Instance.PortIsReady()) @@ -517,7 +516,21 @@ UserControlManager.UserControlMap["auditionUserControl"] = auditionUserControl; Messenger.Default.Send("", MessengerToken.AddAudition); }); + + SaveAudioCommand = new RelayCommand(() => + { + if (FlowStatus.CorrelatorData != null) + { + SaveAudio(); + } + else + { + MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + } + }); + ResetParamCommand = new RelayCommand(ResetParam); + StartCalculateCommand = new RelayCommand(it => { if (SerialPort.GetPortNames().Length == 0) @@ -537,17 +550,6 @@ }; materialDialog.ShowDialog(); }); - SaveAudioCommand = new RelayCommand(() => - { - if (FlowStatus.CorrelatorData != null) - { - SaveAudio(); - } - else - { - MessageBox.Show("还未开始采集数据,无法保存音频", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - } - }); //计算时间Timer _runningTimer.Tick += delegate @@ -673,7 +675,7 @@ NoiseValue = it.LowFrequency + "-" + it.HighFrequency + "Hz"; //数据采集Task - new Task(CollectData).Start(); + Task.Factory.StartNew(CollectData); //记录计算时间 _runningTimer.Start(); diff --git a/Correlator/ViewModel/PipeMaterialViewModel.cs b/Correlator/ViewModel/PipeMaterialViewModel.cs index 3f88cda..a3898e5 100644 --- a/Correlator/ViewModel/PipeMaterialViewModel.cs +++ b/Correlator/ViewModel/PipeMaterialViewModel.cs @@ -3,11 +3,11 @@ using System.Windows.Controls; using Correlator.Dialog; using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel @@ -20,6 +20,7 @@ public RelayCommand ItemSelectedCommand { get; set; } public RelayCommand NextStepCommand { get; set; } + private readonly IPipeMaterialDataService _dataService; private PipeMaterialModel _materialData; private ObservableCollection _pipeMaterials; @@ -34,8 +35,9 @@ } } - public PipeMaterialViewModel() + public PipeMaterialViewModel(IPipeMaterialDataService dataService) { + _dataService = dataService; PipeMaterials = MaterialManager.InitPipeMaterial(); ResetDefaultValueCommand = new RelayCommand(ResetDefaultValue); @@ -117,15 +119,7 @@ return; } - using (var manager = new DataBaseManager()) - { - _materialData.SoundSpeed = 0; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(_materialData), - "PipeMaterialViewModel"); - - manager.Update(_materialData); - } + _dataService.ResetDefaultValue(_materialData); PipeMaterials = MaterialManager.InitPipeMaterial(); } diff --git a/Correlator/ViewModel/SoundSpeedViewModel.cs b/Correlator/ViewModel/SoundSpeedViewModel.cs index 24ddbe9..63bdf84 100644 --- a/Correlator/ViewModel/SoundSpeedViewModel.cs +++ b/Correlator/ViewModel/SoundSpeedViewModel.cs @@ -3,17 +3,18 @@ using System.Windows.Controls; using Correlator.Dialog; using Correlator.Model; +using Correlator.Service; using Correlator.Util; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; -using Newtonsoft.Json; using MessageBox = HandyControl.Controls.MessageBox; namespace Correlator.ViewModel { public class SoundSpeedViewModel : ViewModelBase { + private readonly ISoundSpeedDataService _dataService; private string _materialName; private MaterialVelocity _materialVelocity; @@ -35,82 +36,28 @@ public RelayCommand ItemSelectedCommand { get; set; } public RelayCommand NextStepCommand { get; set; } - public SoundSpeedViewModel() + public SoundSpeedViewModel(ISoundSpeedDataService dataService) { + _dataService = dataService; Messenger.Default.Register(this, MessengerToken.SoundSpeed, it => { _materialName = it; //查询数据库 - VelocityCollection = GetVelocityCollection(_materialName); + VelocityCollection = _dataService.GetVelocityCollection(_materialName); }); Messenger.Default.Register(this, MessengerToken.UpdateSoundSpeed, - it => { VelocityCollection = GetVelocityCollection(_materialName); }); + it => { VelocityCollection = _dataService.GetVelocityCollection(_materialName); }); ItemSelectedCommand = new RelayCommand(ItemSelected); - - DeleteSpeedCommand = new RelayCommand(delegate - { - if (_materialVelocity == null) - { - MessageBox.Show("未选择任何项,无法删除", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - var result = MessageBox.Show("是否删除?删除后无法恢复", - "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); - if (result == MessageBoxResult.Cancel) - { - return; - } + DeleteSpeedCommand = new RelayCommand(DeleteSpeed); - DeleteVelocity(_materialVelocity); - VelocityCollection = GetVelocityCollection(_materialName); - }); + AddSpeedCommand = new RelayCommand(AddSpeed); - AddSpeedCommand = new RelayCommand(it => - { - var addSoundSpeedDialog = new AddSoundSpeedDialog(_materialName) - { - Owner = Window.GetWindow(it) - }; - addSoundSpeedDialog.ShowDialog(); - }); + EditSpeedCommand = new RelayCommand(EditSpeed); - EditSpeedCommand = new RelayCommand(it => - { - if (_materialVelocity == null) - { - MessageBox.Show("未选择任何项,无法编辑", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - var editSoundSpeedDialog = new EditSoundSpeedDialog(_materialVelocity) - { - Owner = Window.GetWindow(it) - }; - editSoundSpeedDialog.ShowDialog(); - }); - - NextStepCommand = new RelayCommand(it => - { - if (_materialVelocity == null) - { - MessageBox.Show("还未选择任何材料,无法进行下一步操作", - "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); - return; - } - - UpdatePipeMaterial(_materialName, _materialVelocity); - - //更新界面数据 - Messenger.Default.Send("", MessengerToken.UpdateMaterialSoundSpeed); - - //返回选择材质界面 - it.Close(); - }); + NextStepCommand = new RelayCommand(UpdatePipeMaterial); } private void ItemSelected(object sender) @@ -119,46 +66,67 @@ _materialVelocity = (MaterialVelocity)listView.SelectedItem; } - private ObservableCollection GetVelocityCollection(string materialName) + private void DeleteSpeed() { - var velocityCollection = new ObservableCollection(); - using (var manager = new DataBaseManager()) + if (_materialVelocity == null) { - var velocities = manager - .Table() - .Where(x => x.MaterialName == materialName) - .ToList(); - foreach (var model in velocities) - { - velocityCollection.Add(model); - } + MessageBox.Show("未选择任何项,无法删除", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; } - return velocityCollection; + var result = MessageBox.Show("是否删除?删除后无法恢复", + "温馨提示", MessageBoxButton.OKCancel, MessageBoxImage.Question); + if (result == MessageBoxResult.Cancel) + { + return; + } + + _dataService.DeleteVelocity(_materialVelocity); + VelocityCollection = _dataService.GetVelocityCollection(_materialName); } - private void DeleteVelocity(MaterialVelocity velocity) + private void AddSpeed(SoundSpeedDialog it) { - using (var manager = new DataBaseManager()) + var addSoundSpeedDialog = new AddSoundSpeedDialog(_materialName) { - manager.Delete(velocity); - } + Owner = Window.GetWindow(it) + }; + addSoundSpeedDialog.ShowDialog(); } - private void UpdatePipeMaterial(string materialName, MaterialVelocity velocity) + private void EditSpeed(SoundSpeedDialog it) { - using (var manager = new DataBaseManager()) + if (_materialVelocity == null) { - var materialModel = manager - .Table() - .FirstOrDefault(x => x.ChineseMaterial == materialName); - materialModel.SoundSpeed = velocity.Velocity; - - LogWithConsole.WriteLine("正在修改的管材是:" + JsonConvert.SerializeObject(materialModel), - "SoundSpeedViewModel"); - - manager.Update(materialModel); + MessageBox.Show("未选择任何项,无法编辑", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; } + + var editSoundSpeedDialog = new EditSoundSpeedDialog(_materialVelocity) + { + Owner = Window.GetWindow(it) + }; + editSoundSpeedDialog.ShowDialog(); + } + + private void UpdatePipeMaterial(SoundSpeedDialog it) + { + if (_materialVelocity == null) + { + MessageBox.Show("还未选择任何材料,无法进行下一步操作", + "温馨提示", MessageBoxButton.OK, MessageBoxImage.Error); + return; + } + + _dataService.UpdatePipeMaterial(_materialName, _materialVelocity); + + //更新界面数据 + Messenger.Default.Send("", MessengerToken.UpdateMaterialSoundSpeed); + + //返回选择材质界面 + it.Close(); } } } \ No newline at end of file diff --git a/Correlator/ViewModel/ViewModelLocator.cs b/Correlator/ViewModel/ViewModelLocator.cs index cb9bc89..0d754a0 100644 --- a/Correlator/ViewModel/ViewModelLocator.cs +++ b/Correlator/ViewModel/ViewModelLocator.cs @@ -13,6 +13,8 @@ */ using CommonServiceLocator; +using Correlator.Service; +using Correlator.ServiceImpl; using GalaSoft.MvvmLight.Ioc; namespace Correlator.ViewModel @@ -32,8 +34,9 @@ #region DataService - // SimpleIoc.Default.Register(); - // SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); + SimpleIoc.Default.Register(); #endregion