You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.7 KiB
94 lines
3.7 KiB
using IOTContainer.Common;
|
|
using IOTContainer.Communication;
|
|
using IOTContainer.MvvmBase;
|
|
using IOTContainer.View;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace IOTContainer.ViewModel
|
|
{
|
|
public class MainWindowViewModel : ViewModelBase
|
|
{
|
|
|
|
public MainWindowViewModel()
|
|
{
|
|
Startup();
|
|
}
|
|
|
|
private UserControl _mainUserControl;
|
|
/// <summary>
|
|
/// 主页显示的用户控件
|
|
/// </summary>
|
|
public UserControl MainUserControl
|
|
{
|
|
get { return _mainUserControl; }
|
|
set { base.SetProperty(ref _mainUserControl, value, "MainUserControl"); }
|
|
}
|
|
public void Startup()
|
|
{
|
|
try
|
|
{
|
|
LocalStorage.CheckDBFile();
|
|
Log.DeleteLog();
|
|
#region 基础字段获取
|
|
ComParameters.Parameters.SocketPort = ConfigurationManager.AppSettings["SocketPort"];
|
|
ComParameters.Parameters.CmdChrome = ConfigurationManager.AppSettings["cmdChrome"];
|
|
var propertyInfos = typeof(ComParameters).GetProperties();
|
|
var dt = LocalStorage.SelectPipTable("infos");
|
|
if (null != dt)
|
|
{
|
|
foreach (DataRow item in dt.Rows)
|
|
{
|
|
var property = propertyInfos.FirstOrDefault(p => p.Name == item["key"].ToString());
|
|
if (null != property)
|
|
{
|
|
var changedValue = Convert.ChangeType(item["value"], property.PropertyType);
|
|
property.SetValue(ComParameters.Parameters, changedValue, null);
|
|
}
|
|
}
|
|
}
|
|
//var keys = typeof(ConfigKey).GetFields();
|
|
//foreach (var key in keys)
|
|
//{
|
|
// var propertyInfo = typeof(ComParameters).GetProperty(key.Name);
|
|
// var value = LocalStorage.SelectPipTable("infos", key.Name);
|
|
// if (!string.IsNullOrEmpty(value))
|
|
// {
|
|
// var changedValue = Convert.ChangeType(value, propertyInfo.PropertyType);
|
|
// propertyInfo.SetValue(ComParameters.Parameters, changedValue, null);
|
|
// }
|
|
//}
|
|
#endregion
|
|
#region 字段判断与页面显示
|
|
ComParameters.Parameters.MainViewModel = this;
|
|
if (string.IsNullOrEmpty(ComParameters.Parameters.httpServer) || string.IsNullOrEmpty(ComParameters.Parameters.registerCode))
|
|
{
|
|
//邀请码、http配置页面
|
|
MainUserControl = new RegisterView();
|
|
}
|
|
else if (string.IsNullOrEmpty(ComParameters.Parameters.buildingName) || string.IsNullOrEmpty(ComParameters.Parameters.floorName) || string.IsNullOrEmpty(ComParameters.Parameters.devCode)
|
|
|| string.IsNullOrEmpty(ComParameters.Parameters.devType) || string.IsNullOrEmpty(ComParameters.Parameters.devAttr))
|
|
{
|
|
//楼栋楼层注册页面
|
|
MainUserControl = new ServiceInfoView();
|
|
}
|
|
else
|
|
{
|
|
//主页
|
|
MainUserControl = new InitialView(false);
|
|
}
|
|
#endregion
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.MyLog.WriteLogFile("主程序出错:" + e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|