using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using BO.Utils;
|
|
|
|
namespace SegmentationWeight
|
|
{
|
|
|
|
|
|
public static class SegmentationWeightContext
|
|
{
|
|
private static string loginConfigPath = Application.StartupPath + "\\SegmentationWeightConfig.xml";
|
|
private static SegmentationWeightConfig _config;
|
|
public static SegmentationWeightConfig Config
|
|
{
|
|
get
|
|
{
|
|
if (_config == null)
|
|
_config = CreateConfig();
|
|
return _config;
|
|
}
|
|
}
|
|
static SegmentationWeightConfig CreateConfig()
|
|
{
|
|
var config = new SegmentationWeightConfig();
|
|
if (!File.Exists(loginConfigPath))
|
|
{
|
|
XmlUtil.SerializerObjToFile(config, loginConfigPath);
|
|
}
|
|
else
|
|
config = XmlUtil.DeserializeFromFile<SegmentationWeightConfig>(loginConfigPath);
|
|
return config;
|
|
}
|
|
|
|
public static void Save()
|
|
{
|
|
if (string.IsNullOrEmpty(_config.WeightSet))
|
|
throw new Exception("请选择称型号");
|
|
if (string.IsNullOrEmpty(_config.ComSet))
|
|
throw new Exception("请选择Com口");
|
|
if (_config.RateSet == null)
|
|
throw new Exception("请选择波特率");
|
|
if (_config.BitSet == null)
|
|
throw new Exception("请选择数据位");
|
|
if (string.IsNullOrEmpty(_config.Format))
|
|
throw new Exception("请填写显示格式");
|
|
try
|
|
{
|
|
string.Format("{0:" + _config.Format + "}", 1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("显示格式填写错误\n" + ex.Message);
|
|
}
|
|
XmlUtil.SerializerObjToFile(_config, loginConfigPath);
|
|
}
|
|
}
|
|
|
|
public class SegmentationWeightConfig
|
|
{
|
|
public string WeightSet { get; set; }
|
|
|
|
public string ComSet { get; set; }
|
|
|
|
public int? RateSet { get; set; }
|
|
|
|
public int? BitSet { get; set; }
|
|
|
|
public string Format { get; set; }
|
|
|
|
public decimal? Discont { get; set; }
|
|
|
|
public int WeightType { get; set; }
|
|
|
|
public decimal MinWeight { get; set; }
|
|
|
|
public decimal MaxWeight { get; set; }
|
|
}
|
|
}
|