107 lines
4.5 KiB
C#
Raw Normal View History

2025-08-15 16:44:13 +08:00
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
2025-08-15 16:44:13 +08:00
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using IniParser;
using IniParser.Model;
2025-08-15 16:44:13 +08:00
using Newtonsoft.Json;
using Prism.Ioc;
using SWS.Commons;
using SWS.Model;
using SWS.Service;
using Unity;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace SWS.Electrical
{
public class GlobalObj
{
public static List<TreeModel> treeDrawings = new List<TreeModel>();
2025-08-15 16:44:13 +08:00
//public static IUnityContainer container;
//public static IContainerExtension _prismContainer;
public static FileIniDataParser configIni = new FileIniDataParser();
public enum dialogPar
{
info,
para1,
para2
}
public static string LocalWorkDir = string.Empty;//本地文件路径
/// <summary>
/// 检查是否登录
/// </summary>
public static async Task<bool> CheckLogin()
{
try
2025-10-09 17:50:08 +08:00
{
string token = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginToken");
string loginkey = IniHelper.ReadValueFromIniFile("LoginInfo", "LoginMark");
string curProjId = IniHelper.ReadValueFromIniFile("LoginInfo", "CurProjId");
LocalWorkDir = IniHelper.ReadValueFromIniFile("Profile", "strLocalWorkDir");
string address = IniHelper.ReadValueFromIniFile("Profile", "strIPAddress");
string port = IniHelper.ReadValueFromIniFile("Profile", "nPort");
string dbType = IniHelper.ReadValueFromIniFile("Profile", "nConType");
string domain = IniHelper.ReadValueFromIniFile("Profile", "strDomainName");
2025-08-15 16:44:13 +08:00
if (dbType == "1")
{
string strDomain = domain;
2025-08-15 16:44:13 +08:00
GlobalObject.client = new HttpClient()
{
BaseAddress = new Uri($"{strDomain}/api/"),
2025-10-09 17:50:08 +08:00
Timeout = TimeSpan.FromSeconds(600)
2025-08-15 16:44:13 +08:00
};
}
else if (dbType == "0")
{
GlobalObject.client = new HttpClient()
{
BaseAddress = new Uri($"http://{address}:{port}/api/"),
2025-10-09 17:50:08 +08:00
Timeout = TimeSpan.FromSeconds(600)
2025-08-15 16:44:13 +08:00
};
}
GlobalObject.client.DefaultRequestHeaders.Add("logintoken", token);
2025-08-15 16:44:13 +08:00
GlobalObject.client.DefaultRequestHeaders.Add("loginkey", loginkey);
var loginService = GlobalObject.container.Resolve<LoginService>();
var flag = await loginService.ValidateLogin(token, loginkey);
if (flag && GlobalObject.curProject == null && !string.IsNullOrEmpty(curProjId))
2025-08-15 16:44:13 +08:00
{
//第一次要在后台初始化一些数据
var projectService = GlobalObject.container.Resolve<ProjectService>();
GlobalObject.curProject = await projectService.GetEntity(curProjId);
if (GlobalObject.curProject == null)
{
Task.Factory.StartNew(async () =>
{
// var projectService = GlobalObject.container.Resolve<ProjectService>();
var listProjects = (await projectService.GetProjects(1, 1000)).Rows;
var p = listProjects.FirstOrDefault(a => a.ProjectId == curProjId);
GlobalObject.curProject = p;
//var obj = await projectService.InitProjInfo(curProjId, "");
//var treeData = obj.First(x => (string)x["Name"] == "图纸树(按目录)")["data"];
//treeDrawings = JsonConvert.DeserializeObject<List<TreeModel>>(treeData.ToString());
2025-08-15 16:44:13 +08:00
});
}
2025-08-15 16:44:13 +08:00
}
if (GlobalObject.curProject == null)
2025-10-09 17:50:08 +08:00
{ GlobalObject.curProject = new ec_project() { ProjectId = curProjId }; }
2025-08-15 16:44:13 +08:00
return flag;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
return false;
}
}
}
}