initial version with inspection edition
This commit is contained in:
commit
6a5629fc3b
7
.gitignore
vendored
Normal file
7
.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
.vs/
|
||||
bin/
|
||||
obj/
|
||||
packages/
|
||||
.DS_Store
|
||||
Icon?
|
||||
*.user
|
14
ConsoleApplication1/App.config
Normal file
14
ConsoleApplication1/App.config
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
<add key="DbConntionString" value="Data Source=192.168.25.215\IRONINTEL;Initial Catalog=IRONINTEL_IRONDEV;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="JRE_IronIntelDb" value="Data Source=192.168.25.215\IRONINTEL;Initial Catalog=JRE_IRONINTEL;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="MasterDb" value="Data Source=192.168.25.215\IRONINTEL;Initial Catalog=IRONINTEL;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="AdminDb" value="Data Source=192.168.25.215\IRONINTEL;Initial Catalog=IRONINTEL_ADMIN;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="AppVersion" value="1.16.12.15"/>
|
||||
<add key="LastUpdateTime" value="10/17/2016 10:36:26.229"/>
|
||||
</appSettings>
|
||||
</configuration>
|
91
ConsoleApplication1/ConsoleApplication1.csproj
Normal file
91
ConsoleApplication1/ConsoleApplication1.csproj
Normal file
@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{62910ED6-A98B-422A-A938-1FC729771F54}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ConsoleApplication1</RootNamespace>
|
||||
<AssemblyName>ConsoleApplication1</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FICore">
|
||||
<HintPath>..\Reflib\FICore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FIWinLib">
|
||||
<HintPath>..\Reflib\FIWinLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ForesightServicesClient">
|
||||
<HintPath>..\Reflib\ForesightServicesClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisitebase">
|
||||
<HintPath>..\Reflib\iisitebase.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisyslib">
|
||||
<HintPath>..\Reflib\iisyslib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\Reflib\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="IronIntelDebugHost.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\IronIntelContractorBusiness\IronIntelContractorBusiness.csproj">
|
||||
<Project>{515fb61f-f032-4a48-8f32-93b59b9d37f8}</Project>
|
||||
<Name>IronIntelContractorBusiness</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\IronIntelContractorSiteLib\IronIntelContractorSiteLib.csproj">
|
||||
<Project>{9d398985-9424-4fc7-a637-6b5b204d8f7c}</Project>
|
||||
<Name>IronIntelContractorSiteLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
61
ConsoleApplication1/IronIntelDebugHost.cs
Normal file
61
ConsoleApplication1/IronIntelDebugHost.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Configuration;
|
||||
using System.Net.Mail;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.DataModel.Admin.Customers;
|
||||
using IronIntel.DataModel.Admin.Users;
|
||||
using Foresight.Services.Log;
|
||||
|
||||
namespace ConsoleApplication1
|
||||
{
|
||||
class IronIntelDebugHost : IIronIntelHost
|
||||
{
|
||||
public CustomerInfo GetCustomerInfo(string custid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public CustomerManager GetCustomerManager()
|
||||
{
|
||||
return new CustomerManager(ConfigurationManager.AppSettings["MasterDb"]);
|
||||
}
|
||||
|
||||
public string GetIronIntelDbConnectionString(string custid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public LoginManager GetLoginManager()
|
||||
{
|
||||
return new LoginManager(ConfigurationManager.AppSettings["MasterDb"]);
|
||||
}
|
||||
|
||||
public int SendEmail(string customerid, MailMessage msg)
|
||||
{
|
||||
var mail = new Foresight.Services.Mail.MailSender(@"net.tcp://192.168.25.210:20100/fisvcs/systemsvc");
|
||||
mail.AppName = "fleet_dev";
|
||||
return (int)mail.SendMail("fleet_dev", customerid, "", msg);
|
||||
}
|
||||
|
||||
public void WriteLog(string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
LogWriter log = new LogWriter(@"net.tcp://192.168.25.210:20100/fisvcs/systemsvc");
|
||||
log.WriteLog("fleet_dev", "Foresight", "hq-pc", "SystemService", logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
public void WriteLog(string customerid, string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
LogWriter log = new LogWriter(@"net.tcp://192.168.25.210:20100/fisvcs/systemsvc");
|
||||
log.WriteLog("fleet_dev", customerid, "hq-pc", "SystemService", logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
long IIronIntelHost.SendEmail(string customerid, MailMessage msg)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
57
ConsoleApplication1/Program.cs
Normal file
57
ConsoleApplication1/Program.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using IronIntel.Contractor.MapView;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Contractor;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.DataModel.Admin.Customers;
|
||||
|
||||
namespace ConsoleApplication1
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// IronIntelHostEnvironment.InitHost(new IronIntelDebugHost());
|
||||
|
||||
// Test1();
|
||||
|
||||
Guid gd = new Guid("10000000-0000-0000-0000-100000000001");
|
||||
|
||||
ContractorHost.Init();
|
||||
|
||||
testdemo();
|
||||
Console.ReadLine();
|
||||
}
|
||||
|
||||
private static void Test1()
|
||||
{
|
||||
var cm = IronIntelHostEnvironment.GetCustomerManager();
|
||||
var db= cm.GetCustomerDatabaseInfo("Foresight", "IRONINTEL_ADMINDB");
|
||||
Console.WriteLine(db.ToString());
|
||||
//var loc = cm.GetLocationManager("IRONDEV");
|
||||
|
||||
//var locs = loc.GetCustomerLocations();
|
||||
//Console.WriteLine(locs.ToString());
|
||||
}
|
||||
|
||||
private static void testlogin()
|
||||
{
|
||||
var lm = IronIntelHostEnvironment.GetLoginManager();
|
||||
|
||||
lm.DeleteUser("6D3A02C7-FC25-47C0-A7A4-97D470EA4CC5", true);
|
||||
|
||||
// Console.WriteLine(r.ToString());
|
||||
}
|
||||
|
||||
private static void testdemo()
|
||||
{
|
||||
var usermanager = ContractorHost.Instance.GetContractorManager<IronIntel.DataModel.Contractor.Users.UserManager>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
36
ConsoleApplication1/Properties/AssemblyInfo.cs
Normal file
36
ConsoleApplication1/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ConsoleApplication1")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ConsoleApplication1")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("62910ed6-a98b-422a-a938-1fc729771f54")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
70
Contractor.sln
Normal file
70
Contractor.sln
Normal file
@ -0,0 +1,70 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2003
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Site", "Site\", "{C2BC3E5B-B059-4B6C-8563-07FEAE54AF6B}"
|
||||
ProjectSection(WebsiteProperties) = preProject
|
||||
TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.7.2"
|
||||
Debug.AspNetCompiler.VirtualPath = "/localhost_5246"
|
||||
Debug.AspNetCompiler.PhysicalPath = "Site\"
|
||||
Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_5246\"
|
||||
Debug.AspNetCompiler.Updateable = "true"
|
||||
Debug.AspNetCompiler.ForceOverwrite = "true"
|
||||
Debug.AspNetCompiler.FixedNames = "false"
|
||||
Debug.AspNetCompiler.Debug = "True"
|
||||
Release.AspNetCompiler.VirtualPath = "/localhost_5246"
|
||||
Release.AspNetCompiler.PhysicalPath = "Site\"
|
||||
Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_5246\"
|
||||
Release.AspNetCompiler.Updateable = "true"
|
||||
Release.AspNetCompiler.ForceOverwrite = "true"
|
||||
Release.AspNetCompiler.FixedNames = "false"
|
||||
Release.AspNetCompiler.Debug = "False"
|
||||
VWDPort = "5246"
|
||||
SlnRelativePath = "Site\"
|
||||
DefaultWebSiteLanguage = "Visual C#"
|
||||
StartServerOnDebug = "false"
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronIntelContractorBusiness", "IronIntelContractorBusiness\IronIntelContractorBusiness.csproj", "{515FB61F-F032-4A48-8F32-93B59B9D37F8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronIntelContractorSiteLib", "IronIntelContractorSiteLib\IronIntelContractorSiteLib.csproj", "{9D398985-9424-4FC7-A637-6B5B204D8F7C}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{62910ED6-A98B-422A-A938-1FC729771F54}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IronIntelSiteServiceHost", "IronIntelSiteServiceHost\IronIntelSiteServiceHost.csproj", "{B5E29343-DF46-47DE-A8E8-69BCF58C0697}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C2BC3E5B-B059-4B6C-8563-07FEAE54AF6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2BC3E5B-B059-4B6C-8563-07FEAE54AF6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2BC3E5B-B059-4B6C-8563-07FEAE54AF6B}.Release|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2BC3E5B-B059-4B6C-8563-07FEAE54AF6B}.Release|Any CPU.Build.0 = Debug|Any CPU
|
||||
{515FB61F-F032-4A48-8F32-93B59B9D37F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{515FB61F-F032-4A48-8F32-93B59B9D37F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{515FB61F-F032-4A48-8F32-93B59B9D37F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{515FB61F-F032-4A48-8F32-93B59B9D37F8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9D398985-9424-4FC7-A637-6B5B204D8F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9D398985-9424-4FC7-A637-6B5B204D8F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9D398985-9424-4FC7-A637-6B5B204D8F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9D398985-9424-4FC7-A637-6B5B204D8F7C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{62910ED6-A98B-422A-A938-1FC729771F54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{62910ED6-A98B-422A-A938-1FC729771F54}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{62910ED6-A98B-422A-A938-1FC729771F54}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{62910ED6-A98B-422A-A938-1FC729771F54}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B5E29343-DF46-47DE-A8E8-69BCF58C0697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B5E29343-DF46-47DE-A8E8-69BCF58C0697}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B5E29343-DF46-47DE-A8E8-69BCF58C0697}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B5E29343-DF46-47DE-A8E8-69BCF58C0697}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {BAE453CC-00EC-4D9C-902A-AF8F249C8653}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
18
FICMigrator/App.config
Normal file
18
FICMigrator/App.config
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<configSections>
|
||||
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
|
||||
<section name="FICMigrator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||
</sectionGroup>
|
||||
</configSections>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
<applicationSettings>
|
||||
<FICMigrator.Properties.Settings>
|
||||
<setting name="ExcludeTables" serializeAs="String">
|
||||
<value>EXPORTLOG</value>
|
||||
</setting>
|
||||
</FICMigrator.Properties.Settings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
161
FICMigrator/Definitions.cs
Normal file
161
FICMigrator/Definitions.cs
Normal file
@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FICMigrator
|
||||
{
|
||||
class Definitions
|
||||
{
|
||||
public static readonly string[] TABLES = new[]
|
||||
{
|
||||
"AUTHORIZE",
|
||||
"BOARD",
|
||||
"BOARDCHARTPIVOT",
|
||||
"BOARDLANGUAGE",
|
||||
"BOARDPIVOT",
|
||||
"BOARDPIVOTLANGUAGE",
|
||||
"CATEGORY",
|
||||
"CHART",
|
||||
"CHARTAGGREGATELANGUAGE",
|
||||
"CHARTCLASS",
|
||||
"CHARTCONTAINER",
|
||||
"CHARTCONTAINERPOSITION",
|
||||
"CHARTDYNAMICYCOLOR",
|
||||
"CHARTDYNAMICYDATA",
|
||||
"CHARTDYNAMICYDATACOMPOSITION",
|
||||
"CHARTDYNAMICYPROPORTION",
|
||||
"CHARTEXTENSIONCOLUMN",
|
||||
"CHARTEXTENSIONCOLUMNLANGUAGE",
|
||||
"CHARTEXTENSIONCOLUMNPARAMVALUE",
|
||||
"CHARTEXTENSIONDETAIL",
|
||||
"CHARTEXTENSIONFILTER",
|
||||
"CHARTEXTENSIONY",
|
||||
"CHARTFILTER",
|
||||
"CHARTGAUGEDYNAMICDATA",
|
||||
"CHARTGAUGEDYNAMICY",
|
||||
"CHARTLANGUAGE",
|
||||
"CHARTPARAMVALUE",
|
||||
"CHARTPIVOT",
|
||||
"CHARTPIVOTDATA",
|
||||
"CHARTPIVOTLANGUAGE",
|
||||
"CHARTPROPERTYVALUE",
|
||||
"CHARTSORT",
|
||||
"CHARTTOTALROW",
|
||||
"CHARTTOTALROWCOLUMN",
|
||||
"CHARTTOTALROWCOLUMNOBJECT",
|
||||
"CHARTXYLANGUAGE",
|
||||
"CHARTXYZ",
|
||||
"COLORSCHEME",
|
||||
"CONSTRUCTOROBJECT",
|
||||
"DATACONNECTION",
|
||||
"DATARIGHT",
|
||||
"DATATABLE",
|
||||
"DATATABLECLASS",
|
||||
"DATATABLECLASSRELATION",
|
||||
"DRILLDOWN",
|
||||
"DRILLDOWNDETAIL",
|
||||
"DRILLDOWNFILTER",
|
||||
"DRILLDOWNFORURL",
|
||||
"DRILLDOWNURLPARAMVALUES",
|
||||
"DRILLDOWNY",
|
||||
"DTPERFLOG",
|
||||
"EMBEDEXTENDEDDATACONNECTION",
|
||||
"EMBEDEXTENDEDDATATABLE",
|
||||
"ENUMERATION",
|
||||
"EXPORTLOG",
|
||||
"EXTENDEDDC",
|
||||
"EXTENDEDDCLOGIN",
|
||||
"FAVORITECONTENT",
|
||||
"FAVORITEITEM",
|
||||
"FREECHARTCELL",
|
||||
"FREECHARTCELLCOLORFILTER",
|
||||
"FREECHARTCELLDATAFILTER",
|
||||
"FREECHARTCELLLANGUAGE",
|
||||
"FREECHARTCOLUMN",
|
||||
"FREECHARTROW",
|
||||
"FUNCTIONTYPE",
|
||||
"GLOBALFILTER",
|
||||
"GLOBALVARIABLE",
|
||||
"GRIDWIDTH",
|
||||
"GROUPS",
|
||||
"HIDDENBOARDS",
|
||||
"INNERINFORMATION",
|
||||
"JOBLOG",
|
||||
"JOBSCHEDULE",
|
||||
"LEVELS",
|
||||
"LICENSEINFO",
|
||||
"LICENSEPACKAGE",
|
||||
"LOOKUPDATA",
|
||||
"MANAGEMENTTREE",
|
||||
"MESSAGEDATA",
|
||||
"MESSAGEKEY",
|
||||
"MESSAGEPARAMS",
|
||||
"MESSAGEPOOL",
|
||||
"MESSAGETYPE",
|
||||
"MODULESINFOFILES",
|
||||
"MSG",
|
||||
"MULTILEVELFIELD",
|
||||
"MUTEX",
|
||||
"MYFAVCHARTS",
|
||||
"OBJSTATISTICS",
|
||||
"OPERATIONRIGHT",
|
||||
"OPERATIONS",
|
||||
"PACKAGECONTENT",
|
||||
"PACKAGEDCMAPPING",
|
||||
"PACKAGEINFO",
|
||||
"PACKAGELIST",
|
||||
"PLUGIN",
|
||||
"PLUGINCAPTION",
|
||||
"PLUGINDATAIMPORT",
|
||||
"PLUGINDATATABLE",
|
||||
"RESOURCEDATA",
|
||||
"RESOURCEFILEVERSION",
|
||||
"SCATTERPLOTFILTER",
|
||||
"SCATTERPLOTSTYLE",
|
||||
"SCATTERTARGETSTRUCTURE",
|
||||
"SCHEDULEDSNAPSHOT",
|
||||
"SERVICEAGENT",
|
||||
"SNAPSHOTS",
|
||||
"SNAPSHOTTOFRS",
|
||||
"STYLECATALOG",
|
||||
"STYLEOBJECT",
|
||||
"STYLEVALUE",
|
||||
"SUBSCRIBEMESSAGE",
|
||||
"SYS_USERLOGINERROR",
|
||||
"SYSTEMFAVORITE",
|
||||
"SYSTEMPARAMS",
|
||||
"TABLEFIELD",
|
||||
"TABLEFILTER",
|
||||
"TABLEPARAMS",
|
||||
"TABLERELATION",
|
||||
"TRANSFORMATIONCOLUMN",
|
||||
"TRANSFORMATIONROWVALUE",
|
||||
"TRANSFORMATIONTABLE",
|
||||
"URLGENERATOR",
|
||||
"URLGENERATORFILE",
|
||||
"USERCHARTINFO",
|
||||
"USERDEFAULTINFO",
|
||||
"USEREMAIL",
|
||||
"USERFIRSTLOGIN",
|
||||
"USERGROUPRELATION",
|
||||
"USERMESSAGE",
|
||||
"USERMESSAGEEMAIL",
|
||||
"USEROBJECT",
|
||||
"USEROBJECTXML",
|
||||
"USERS",
|
||||
"USERTEXTMESSAGE",
|
||||
"VALS",
|
||||
"VIRTUALDC",
|
||||
"VIRTUALROLE",
|
||||
"WORKSPACE",
|
||||
"WORKSPACELANGUAGE",
|
||||
"WORKSPACEPIVOT",
|
||||
"WORKSPACEPIVOTLANGUAGE",
|
||||
"WORKSPACEPIVOTRELATION",
|
||||
"WSPBOARD",
|
||||
"WSPHIDENCHARTS"
|
||||
};
|
||||
}
|
||||
}
|
94
FICMigrator/FICMigrator.csproj
Normal file
94
FICMigrator/FICMigrator.csproj
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{6FA9CAE8-F5E8-4536-B141-4A7A9F2ADE05}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>FICMigrator</RootNamespace>
|
||||
<AssemblyName>FICMigrator</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Definitions.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainForm.Designer.cs">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<EmbeddedResource Include="MainForm.resx">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Resources\Create.sql" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
437
FICMigrator/MainForm.Designer.cs
generated
Normal file
437
FICMigrator/MainForm.Designer.cs
generated
Normal file
@ -0,0 +1,437 @@
|
||||
namespace FICMigrator
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonTestTo = new System.Windows.Forms.Button();
|
||||
this.buttonTestFrom = new System.Windows.Forms.Button();
|
||||
this.textPassTo = new System.Windows.Forms.TextBox();
|
||||
this.label8 = new System.Windows.Forms.Label();
|
||||
this.textUserTo = new System.Windows.Forms.TextBox();
|
||||
this.label7 = new System.Windows.Forms.Label();
|
||||
this.textDBTo = new System.Windows.Forms.TextBox();
|
||||
this.label6 = new System.Windows.Forms.Label();
|
||||
this.textServerTo = new System.Windows.Forms.TextBox();
|
||||
this.label5 = new System.Windows.Forms.Label();
|
||||
this.textPassFrom = new System.Windows.Forms.TextBox();
|
||||
this.label4 = new System.Windows.Forms.Label();
|
||||
this.textUserFrom = new System.Windows.Forms.TextBox();
|
||||
this.label3 = new System.Windows.Forms.Label();
|
||||
this.textDBFrom = new System.Windows.Forms.TextBox();
|
||||
this.label2 = new System.Windows.Forms.Label();
|
||||
this.textServerFrom = new System.Windows.Forms.TextBox();
|
||||
this.label1 = new System.Windows.Forms.Label();
|
||||
this.groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
this.listView1 = new System.Windows.Forms.ListView();
|
||||
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
|
||||
this.buttonReloadTables = new System.Windows.Forms.Button();
|
||||
this.buttonMigrator = new System.Windows.Forms.Button();
|
||||
this.textMessage = new System.Windows.Forms.TextBox();
|
||||
this.progressBar1 = new System.Windows.Forms.ProgressBar();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.groupBox1.SuspendLayout();
|
||||
this.groupBox2.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.groupBox1.Controls.Add(this.buttonTestTo);
|
||||
this.groupBox1.Controls.Add(this.buttonTestFrom);
|
||||
this.groupBox1.Controls.Add(this.textPassTo);
|
||||
this.groupBox1.Controls.Add(this.label8);
|
||||
this.groupBox1.Controls.Add(this.textUserTo);
|
||||
this.groupBox1.Controls.Add(this.label7);
|
||||
this.groupBox1.Controls.Add(this.textDBTo);
|
||||
this.groupBox1.Controls.Add(this.label6);
|
||||
this.groupBox1.Controls.Add(this.textServerTo);
|
||||
this.groupBox1.Controls.Add(this.label5);
|
||||
this.groupBox1.Controls.Add(this.textPassFrom);
|
||||
this.groupBox1.Controls.Add(this.label4);
|
||||
this.groupBox1.Controls.Add(this.textUserFrom);
|
||||
this.groupBox1.Controls.Add(this.label3);
|
||||
this.groupBox1.Controls.Add(this.textDBFrom);
|
||||
this.groupBox1.Controls.Add(this.label2);
|
||||
this.groupBox1.Controls.Add(this.textServerFrom);
|
||||
this.groupBox1.Controls.Add(this.label1);
|
||||
this.groupBox1.Location = new System.Drawing.Point(12, 12);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(909, 91);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Connections";
|
||||
//
|
||||
// buttonTestTo
|
||||
//
|
||||
this.buttonTestTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonTestTo.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.buttonTestTo.Location = new System.Drawing.Point(844, 51);
|
||||
this.buttonTestTo.Name = "buttonTestTo";
|
||||
this.buttonTestTo.Size = new System.Drawing.Size(59, 23);
|
||||
this.buttonTestTo.TabIndex = 17;
|
||||
this.buttonTestTo.Text = "Test";
|
||||
this.buttonTestTo.UseVisualStyleBackColor = true;
|
||||
this.buttonTestTo.Click += new System.EventHandler(this.buttonTestTo_Click);
|
||||
//
|
||||
// buttonTestFrom
|
||||
//
|
||||
this.buttonTestFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonTestFrom.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.buttonTestFrom.Location = new System.Drawing.Point(844, 22);
|
||||
this.buttonTestFrom.Name = "buttonTestFrom";
|
||||
this.buttonTestFrom.Size = new System.Drawing.Size(59, 23);
|
||||
this.buttonTestFrom.TabIndex = 8;
|
||||
this.buttonTestFrom.Text = "Test";
|
||||
this.buttonTestFrom.UseVisualStyleBackColor = true;
|
||||
this.buttonTestFrom.Click += new System.EventHandler(this.buttonTestFrom_Click);
|
||||
//
|
||||
// textPassTo
|
||||
//
|
||||
this.textPassTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textPassTo.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textPassTo.Location = new System.Drawing.Point(762, 51);
|
||||
this.textPassTo.Name = "textPassTo";
|
||||
this.textPassTo.PasswordChar = '*';
|
||||
this.textPassTo.Size = new System.Drawing.Size(76, 21);
|
||||
this.textPassTo.TabIndex = 16;
|
||||
this.textPassTo.Text = "database";
|
||||
this.textPassTo.TextChanged += new System.EventHandler(this.textboxTo_TextChanged);
|
||||
//
|
||||
// label8
|
||||
//
|
||||
this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label8.AutoSize = true;
|
||||
this.label8.Location = new System.Drawing.Point(686, 54);
|
||||
this.label8.Name = "label8";
|
||||
this.label8.Size = new System.Drawing.Size(67, 17);
|
||||
this.label8.TabIndex = 15;
|
||||
this.label8.Text = "Password:";
|
||||
//
|
||||
// textUserTo
|
||||
//
|
||||
this.textUserTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textUserTo.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textUserTo.Location = new System.Drawing.Point(606, 51);
|
||||
this.textUserTo.Name = "textUserTo";
|
||||
this.textUserTo.Size = new System.Drawing.Size(74, 21);
|
||||
this.textUserTo.TabIndex = 14;
|
||||
this.textUserTo.Text = "fi";
|
||||
this.textUserTo.TextChanged += new System.EventHandler(this.textboxTo_TextChanged);
|
||||
//
|
||||
// label7
|
||||
//
|
||||
this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label7.AutoSize = true;
|
||||
this.label7.Location = new System.Drawing.Point(560, 54);
|
||||
this.label7.Name = "label7";
|
||||
this.label7.Size = new System.Drawing.Size(38, 17);
|
||||
this.label7.TabIndex = 13;
|
||||
this.label7.Text = "User:";
|
||||
//
|
||||
// textDBTo
|
||||
//
|
||||
this.textDBTo.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textDBTo.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textDBTo.Location = new System.Drawing.Point(459, 51);
|
||||
this.textDBTo.Name = "textDBTo";
|
||||
this.textDBTo.Size = new System.Drawing.Size(95, 21);
|
||||
this.textDBTo.TabIndex = 12;
|
||||
this.textDBTo.Text = "IRONINTEL_IRONDEV_FIC";
|
||||
this.textDBTo.TextChanged += new System.EventHandler(this.textboxTo_TextChanged);
|
||||
//
|
||||
// label6
|
||||
//
|
||||
this.label6.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label6.AutoSize = true;
|
||||
this.label6.Location = new System.Drawing.Point(422, 54);
|
||||
this.label6.Name = "label6";
|
||||
this.label6.Size = new System.Drawing.Size(28, 17);
|
||||
this.label6.TabIndex = 11;
|
||||
this.label6.Text = "DB:";
|
||||
//
|
||||
// textServerTo
|
||||
//
|
||||
this.textServerTo.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textServerTo.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textServerTo.Location = new System.Drawing.Point(105, 51);
|
||||
this.textServerTo.Name = "textServerTo";
|
||||
this.textServerTo.Size = new System.Drawing.Size(311, 21);
|
||||
this.textServerTo.TabIndex = 10;
|
||||
this.textServerTo.Text = "192.168.25.212";
|
||||
this.textServerTo.TextChanged += new System.EventHandler(this.textboxTo_TextChanged);
|
||||
//
|
||||
// label5
|
||||
//
|
||||
this.label5.Location = new System.Drawing.Point(6, 54);
|
||||
this.label5.Name = "label5";
|
||||
this.label5.Size = new System.Drawing.Size(90, 17);
|
||||
this.label5.TabIndex = 9;
|
||||
this.label5.Text = "To:";
|
||||
this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
//
|
||||
// textPassFrom
|
||||
//
|
||||
this.textPassFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textPassFrom.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textPassFrom.Location = new System.Drawing.Point(762, 22);
|
||||
this.textPassFrom.Name = "textPassFrom";
|
||||
this.textPassFrom.PasswordChar = '*';
|
||||
this.textPassFrom.Size = new System.Drawing.Size(76, 21);
|
||||
this.textPassFrom.TabIndex = 7;
|
||||
this.textPassFrom.Text = "demo";
|
||||
this.textPassFrom.TextChanged += new System.EventHandler(this.textbox_TextChanged);
|
||||
//
|
||||
// label4
|
||||
//
|
||||
this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label4.AutoSize = true;
|
||||
this.label4.Location = new System.Drawing.Point(686, 25);
|
||||
this.label4.Name = "label4";
|
||||
this.label4.Size = new System.Drawing.Size(67, 17);
|
||||
this.label4.TabIndex = 6;
|
||||
this.label4.Text = "Password:";
|
||||
//
|
||||
// textUserFrom
|
||||
//
|
||||
this.textUserFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textUserFrom.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textUserFrom.Location = new System.Drawing.Point(606, 22);
|
||||
this.textUserFrom.Name = "textUserFrom";
|
||||
this.textUserFrom.Size = new System.Drawing.Size(74, 21);
|
||||
this.textUserFrom.TabIndex = 5;
|
||||
this.textUserFrom.Text = "demo";
|
||||
this.textUserFrom.TextChanged += new System.EventHandler(this.textbox_TextChanged);
|
||||
//
|
||||
// label3
|
||||
//
|
||||
this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label3.AutoSize = true;
|
||||
this.label3.Location = new System.Drawing.Point(560, 25);
|
||||
this.label3.Name = "label3";
|
||||
this.label3.Size = new System.Drawing.Size(38, 17);
|
||||
this.label3.TabIndex = 4;
|
||||
this.label3.Text = "User:";
|
||||
//
|
||||
// textDBFrom
|
||||
//
|
||||
this.textDBFrom.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textDBFrom.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textDBFrom.Location = new System.Drawing.Point(459, 22);
|
||||
this.textDBFrom.Name = "textDBFrom";
|
||||
this.textDBFrom.Size = new System.Drawing.Size(95, 21);
|
||||
this.textDBFrom.TabIndex = 3;
|
||||
this.textDBFrom.Text = "T02_0630_FIC";
|
||||
this.textDBFrom.TextChanged += new System.EventHandler(this.textbox_TextChanged);
|
||||
//
|
||||
// label2
|
||||
//
|
||||
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.label2.AutoSize = true;
|
||||
this.label2.Location = new System.Drawing.Point(422, 25);
|
||||
this.label2.Name = "label2";
|
||||
this.label2.Size = new System.Drawing.Size(28, 17);
|
||||
this.label2.TabIndex = 2;
|
||||
this.label2.Text = "DB:";
|
||||
//
|
||||
// textServerFrom
|
||||
//
|
||||
this.textServerFrom.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textServerFrom.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.textServerFrom.Location = new System.Drawing.Point(105, 22);
|
||||
this.textServerFrom.Name = "textServerFrom";
|
||||
this.textServerFrom.Size = new System.Drawing.Size(311, 21);
|
||||
this.textServerFrom.TabIndex = 1;
|
||||
this.textServerFrom.Text = "192.168.25.106";
|
||||
this.textServerFrom.TextChanged += new System.EventHandler(this.textbox_TextChanged);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
this.label1.Location = new System.Drawing.Point(6, 25);
|
||||
this.label1.Name = "label1";
|
||||
this.label1.Size = new System.Drawing.Size(90, 17);
|
||||
this.label1.TabIndex = 0;
|
||||
this.label1.Text = "Connect from:";
|
||||
this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.groupBox2.Controls.Add(this.listView1);
|
||||
this.groupBox2.Controls.Add(this.buttonReloadTables);
|
||||
this.groupBox2.Location = new System.Drawing.Point(12, 109);
|
||||
this.groupBox2.Name = "groupBox2";
|
||||
this.groupBox2.Size = new System.Drawing.Size(295, 402);
|
||||
this.groupBox2.TabIndex = 1;
|
||||
this.groupBox2.TabStop = false;
|
||||
this.groupBox2.Text = "Check Tables";
|
||||
//
|
||||
// listView1
|
||||
//
|
||||
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.columnHeader1,
|
||||
this.columnHeader2});
|
||||
this.listView1.Location = new System.Drawing.Point(6, 29);
|
||||
this.listView1.Name = "listView1";
|
||||
this.listView1.Size = new System.Drawing.Size(283, 364);
|
||||
this.listView1.TabIndex = 1;
|
||||
this.listView1.UseCompatibleStateImageBehavior = false;
|
||||
this.listView1.View = System.Windows.Forms.View.Details;
|
||||
//
|
||||
// columnHeader1
|
||||
//
|
||||
this.columnHeader1.Text = "Table";
|
||||
this.columnHeader1.Width = 200;
|
||||
//
|
||||
// columnHeader2
|
||||
//
|
||||
this.columnHeader2.Text = "";
|
||||
//
|
||||
// buttonReloadTables
|
||||
//
|
||||
this.buttonReloadTables.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonReloadTables.Font = new System.Drawing.Font("Microsoft YaHei UI", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.buttonReloadTables.Location = new System.Drawing.Point(228, 0);
|
||||
this.buttonReloadTables.Name = "buttonReloadTables";
|
||||
this.buttonReloadTables.Size = new System.Drawing.Size(55, 23);
|
||||
this.buttonReloadTables.TabIndex = 0;
|
||||
this.buttonReloadTables.Text = "Load";
|
||||
this.buttonReloadTables.UseVisualStyleBackColor = true;
|
||||
this.buttonReloadTables.Click += new System.EventHandler(this.buttonReloadTables_Click);
|
||||
//
|
||||
// buttonMigrator
|
||||
//
|
||||
this.buttonMigrator.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonMigrator.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.buttonMigrator.Location = new System.Drawing.Point(316, 481);
|
||||
this.buttonMigrator.Name = "buttonMigrator";
|
||||
this.buttonMigrator.Size = new System.Drawing.Size(605, 30);
|
||||
this.buttonMigrator.TabIndex = 3;
|
||||
this.buttonMigrator.Text = "Copy tables";
|
||||
this.buttonMigrator.UseVisualStyleBackColor = true;
|
||||
this.buttonMigrator.Click += new System.EventHandler(this.buttonMigrator_Click);
|
||||
//
|
||||
// textMessage
|
||||
//
|
||||
this.textMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.textMessage.Location = new System.Drawing.Point(316, 109);
|
||||
this.textMessage.Multiline = true;
|
||||
this.textMessage.Name = "textMessage";
|
||||
this.textMessage.ReadOnly = true;
|
||||
this.textMessage.ScrollBars = System.Windows.Forms.ScrollBars.Both;
|
||||
this.textMessage.Size = new System.Drawing.Size(605, 366);
|
||||
this.textMessage.TabIndex = 2;
|
||||
//
|
||||
// progressBar1
|
||||
//
|
||||
this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.progressBar1.Location = new System.Drawing.Point(316, 455);
|
||||
this.progressBar1.Name = "progressBar1";
|
||||
this.progressBar1.Size = new System.Drawing.Size(605, 20);
|
||||
this.progressBar1.TabIndex = 4;
|
||||
this.progressBar1.Visible = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.progressBar1);
|
||||
this.panel1.Controls.Add(this.groupBox1);
|
||||
this.panel1.Controls.Add(this.textMessage);
|
||||
this.panel1.Controls.Add(this.groupBox2);
|
||||
this.panel1.Controls.Add(this.buttonMigrator);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(933, 523);
|
||||
this.panel1.TabIndex = 5;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
|
||||
this.ClientSize = new System.Drawing.Size(933, 523);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.DoubleBuffered = true;
|
||||
this.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.MinimumSize = new System.Drawing.Size(690, 270);
|
||||
this.Name = "MainForm";
|
||||
this.Text = "Migrator - Foresight Intelligence Center";
|
||||
this.groupBox1.ResumeLayout(false);
|
||||
this.groupBox1.PerformLayout();
|
||||
this.groupBox2.ResumeLayout(false);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.GroupBox groupBox1;
|
||||
public System.Windows.Forms.TextBox textDBFrom;
|
||||
private System.Windows.Forms.Label label2;
|
||||
public System.Windows.Forms.TextBox textServerFrom;
|
||||
private System.Windows.Forms.Label label1;
|
||||
public System.Windows.Forms.TextBox textUserFrom;
|
||||
private System.Windows.Forms.Label label3;
|
||||
public System.Windows.Forms.TextBox textPassFrom;
|
||||
private System.Windows.Forms.Label label4;
|
||||
public System.Windows.Forms.TextBox textServerTo;
|
||||
private System.Windows.Forms.Label label5;
|
||||
private System.Windows.Forms.Label label6;
|
||||
public System.Windows.Forms.TextBox textDBTo;
|
||||
public System.Windows.Forms.TextBox textUserTo;
|
||||
private System.Windows.Forms.Label label7;
|
||||
private System.Windows.Forms.Label label8;
|
||||
public System.Windows.Forms.TextBox textPassTo;
|
||||
private System.Windows.Forms.Button buttonTestFrom;
|
||||
private System.Windows.Forms.Button buttonTestTo;
|
||||
private System.Windows.Forms.GroupBox groupBox2;
|
||||
private System.Windows.Forms.Button buttonReloadTables;
|
||||
private System.Windows.Forms.Button buttonMigrator;
|
||||
private System.Windows.Forms.TextBox textMessage;
|
||||
private System.Windows.Forms.ListView listView1;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader1;
|
||||
private System.Windows.Forms.ColumnHeader columnHeader2;
|
||||
private System.Windows.Forms.ProgressBar progressBar1;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
}
|
||||
}
|
||||
|
432
FICMigrator/MainForm.cs
Normal file
432
FICMigrator/MainForm.cs
Normal file
@ -0,0 +1,432 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FICMigrator
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private string _connFromString;
|
||||
private string _connToString;
|
||||
private bool _isFromTested;
|
||||
private bool _isToTested;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void textbox_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_isFromTested = false;
|
||||
}
|
||||
private void textboxTo_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
_isToTested = false;
|
||||
}
|
||||
|
||||
private string SafeString(string str)
|
||||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return str;
|
||||
return str.Replace(';', '_');
|
||||
}
|
||||
|
||||
private void GetConnFromString()
|
||||
{
|
||||
_connFromString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=false;User ID={2};Password={3}",
|
||||
SafeString(textServerFrom.Text),
|
||||
SafeString(textDBFrom.Text),
|
||||
SafeString(textUserFrom.Text),
|
||||
SafeString(textPassFrom.Text));
|
||||
}
|
||||
|
||||
private void GetConnToString()
|
||||
{
|
||||
_connToString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=false;User ID={2};Password={3}",
|
||||
SafeString(textServerTo.Text),
|
||||
SafeString(textDBTo.Text),
|
||||
SafeString(textUserTo.Text),
|
||||
SafeString(textPassTo.Text));
|
||||
}
|
||||
|
||||
private void EnableUI(bool flag)
|
||||
{
|
||||
this.panel1.Enabled = flag;
|
||||
this.Cursor = flag ? Cursors.Default : Cursors.AppStarting;
|
||||
this.progressBar1.Visible = false;
|
||||
}
|
||||
|
||||
private void buttonTestFrom_Click(object sender, EventArgs e)
|
||||
{
|
||||
EnableUI(false);
|
||||
new Thread(new ThreadStart(async delegate
|
||||
{
|
||||
var result = await Task.Run(new Func<bool>(TestFromConnection));
|
||||
if (result)
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
MessageBox.Show(this, "Test successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}));
|
||||
}
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
EnableUI(true);
|
||||
}));
|
||||
})).Start();
|
||||
}
|
||||
|
||||
private void buttonTestTo_Click(object sender, EventArgs e)
|
||||
{
|
||||
EnableUI(false);
|
||||
new Thread(new ThreadStart(async delegate
|
||||
{
|
||||
var result = await Task.Run(new Func<bool>(TestToConnection));
|
||||
if (result)
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
MessageBox.Show(this, "Test successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}));
|
||||
}
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
EnableUI(true);
|
||||
}));
|
||||
})).Start();
|
||||
}
|
||||
|
||||
private void buttonReloadTables_Click(object sender, EventArgs e)
|
||||
{
|
||||
listView1.Items.Clear();
|
||||
EnableUI(false);
|
||||
new Thread(LoadTables).Start();
|
||||
}
|
||||
|
||||
private void buttonMigrator_Click(object sender, EventArgs e)
|
||||
{
|
||||
EnableUI(false);
|
||||
textMessage.Text = "";
|
||||
progressBar1.Visible = true;
|
||||
progressBar1.Value = 0;
|
||||
progressBar1.Maximum = Definitions.TABLES.Length;
|
||||
|
||||
new Thread(MigrateTables).Start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private bool TestFromConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetConnFromString();
|
||||
|
||||
using (var conn = new SqlConnection(_connFromString))
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
_isFromTested = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
MessageBox.Show(this, "Error occurs:\n" + o, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}), ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool TestToConnection()
|
||||
{
|
||||
try
|
||||
{
|
||||
GetConnToString();
|
||||
|
||||
using (var conn = new SqlConnection(_connToString))
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
_isToTested = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
MessageBox.Show(this, "Error occurs:\n" + o, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}), ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void LoadTables()
|
||||
{
|
||||
if (!_isFromTested)
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
MessageBox.Show(this, "Please test connection first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
EnableUI(true);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var list = new List<ListViewItem>();
|
||||
|
||||
using (var conn = new SqlConnection(_connFromString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
foreach (var tb in Definitions.TABLES)
|
||||
{
|
||||
var cmd = conn.CreateCommand();
|
||||
cmd.CommandText = "select 1 from sys.objects where object_id=object_id(@tb) and type='U'";
|
||||
cmd.Parameters.AddWithValue("@tb", tb);
|
||||
|
||||
var o = cmd.ExecuteScalar();
|
||||
var notexist = (o == null || o == DBNull.Value);
|
||||
|
||||
list.Add(new ListViewItem(new[] { tb, notexist ? "×" : "" }));
|
||||
}
|
||||
}
|
||||
|
||||
var arr = list.ToArray();
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
this.listView1.Items.AddRange(arr);
|
||||
}));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
MessageBox.Show(this, "Error occurs:\n" + o, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
EnableUI(true);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
private void MigrateTables()
|
||||
{
|
||||
var result = TestFromConnection();
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
result = TestToConnection();
|
||||
if (!result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_isFromTested || !_isToTested)
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
MessageBox.Show(this, "Please test all connections first.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
EnableUI(true);
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var exclude_tables = Properties.Settings.Default.ExcludeTables.Split(',');
|
||||
|
||||
// init structure
|
||||
var fieldsDict = new Dictionary<string, string[]>();
|
||||
using (var conn = new SqlConnection(_connToString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
//using (var cmd = conn.CreateCommand())
|
||||
//{
|
||||
// cmd.CommandText = Properties.Resources.Create;
|
||||
// cmd.CommandType = CommandType.Text;
|
||||
// cmd.ExecuteNonQuery();
|
||||
//}
|
||||
|
||||
var truncate = new StringBuilder();
|
||||
foreach (var tb in Definitions.TABLES)
|
||||
{
|
||||
if (exclude_tables.Any(s => string.Compare(s, tb, true) == 0))
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
textMessage.Text += string.Format("[{0:HH:mm:ss}] - {1}\r\n\r\n", DateTime.Now, o);
|
||||
}), string.Format("Exclude truncate table \"{0}\"", tb));
|
||||
continue;
|
||||
}
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.columns WHERE TABLE_NAME=@pn";
|
||||
cmd.Parameters.AddWithValue("@pn", tb);
|
||||
|
||||
using (var reader = cmd.ExecuteReader())
|
||||
{
|
||||
var fields = new List<string>();
|
||||
while (reader.Read())
|
||||
{
|
||||
fields.Add(reader["COLUMN_NAME"].ToString());
|
||||
}
|
||||
|
||||
fieldsDict[tb] = fields.ToArray();
|
||||
}
|
||||
}
|
||||
truncate.AppendLine("truncate table " + tb);
|
||||
}
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = truncate.ToString();
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
// copy data
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
progressBar1.Style = ProgressBarStyle.Blocks;
|
||||
}));
|
||||
|
||||
var bulk = new SqlBulkCopy(_connToString);
|
||||
bulk.BatchSize = 1000;
|
||||
bulk.BulkCopyTimeout = 600;
|
||||
|
||||
var i = 0;
|
||||
foreach (var tb in Definitions.TABLES)
|
||||
{
|
||||
if (exclude_tables.Any(s => string.Compare(s, tb, true) == 0))
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
textMessage.Text += string.Format("[{0:HH:mm:ss}] - {1}\r\n\r\n", DateTime.Now, o);
|
||||
}), string.Format("Exclude table \"{0}\"", tb));
|
||||
continue;
|
||||
}
|
||||
|
||||
using (var conn = new SqlConnection(_connFromString))
|
||||
{
|
||||
conn.Open();
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
var fields = fieldsDict[tb];
|
||||
|
||||
cmd.CommandText = string.Format("select [{0}] from [{1}]", string.Join("],[", fields), tb);
|
||||
|
||||
try
|
||||
{
|
||||
#if READER
|
||||
var reader = cmd.ExecuteReader();
|
||||
bulk.DestinationTableName = tb;
|
||||
bulk.WriteToServer(reader);
|
||||
#else
|
||||
var ds = new DataSet();
|
||||
using (var adapter = new SqlDataAdapter(cmd))
|
||||
{
|
||||
adapter.Fill(ds);
|
||||
}
|
||||
bulk.DestinationTableName = tb;
|
||||
var table = ds.Tables[0];
|
||||
bulk.ColumnMappings.Clear();
|
||||
//foreach (DataColumn col in table.Columns)
|
||||
foreach (var field in fields)
|
||||
{
|
||||
//bulk.ColumnMappings.Add(col.ColumnName, col.ColumnName.ToUpper());
|
||||
bulk.ColumnMappings.Add(field, field);
|
||||
}
|
||||
bulk.WriteToServer(table);
|
||||
#endif
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
textMessage.Text += string.Format("[{0:HH:mm:ss}] table \"{1}\" copied.\r\n\r\n", DateTime.Now, o);
|
||||
}), tb);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BeginInvoke(new Action<object, object>((o1, o2) =>
|
||||
{
|
||||
textMessage.Text += string.Format("[{0:HH:mm:ss}] table \"{1}\" - {2}\r\n\r\n", DateTime.Now, o2, o1);
|
||||
}), ex, tb);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.BeginInvoke(new Action<int>(o =>
|
||||
{
|
||||
progressBar1.Value = o;
|
||||
}), ++i);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bulk.Close();
|
||||
|
||||
// change the system params
|
||||
using (var conn = new SqlConnection(_connToString))
|
||||
{
|
||||
conn.Open();
|
||||
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "update SYSTEMPARAMS set PARAMVALUE=@v where PARAMNAME='ExtDBName'";
|
||||
cmd.Parameters.AddWithValue("@v", textDBTo.Text + "EXT"); //Properties.Settings.Default.ExtDBName
|
||||
cmd.CommandType = CommandType.Text;
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
MessageBox.Show(this, "All done.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.BeginInvoke(new Action<object>(o =>
|
||||
{
|
||||
textMessage.Text = "Error occurs:\r\n" + o;
|
||||
MessageBox.Show(this, "Error occurs, please see the detail.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.BeginInvoke(new Action(delegate
|
||||
{
|
||||
EnableUI(true);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
120
FICMigrator/MainForm.resx
Normal file
120
FICMigrator/MainForm.resx
Normal file
@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
59
FICMigrator/Program.cs
Normal file
59
FICMigrator/Program.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace FICMigrator
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
#if TEST
|
||||
//var path = @"C:\Users\cl\Documents\Tencent Files\272001610\FileRecv\";
|
||||
//var bs = System.IO.File.ReadAllBytes(path + "HttpHandler.lua.dream");
|
||||
//var result = DecryptAES(bs);
|
||||
//System.IO.File.WriteAllText(path + "HttpHandler.lua", result);
|
||||
#endif
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
var frm = new MainForm();
|
||||
|
||||
frm.textServerFrom.Text = @"FIIRONSQL01\IRONINTEL";
|
||||
frm.textDBFrom.Text = "IronIntel001_FIC";
|
||||
frm.textUserFrom.Text = "cc";
|
||||
frm.textPassFrom.Text = "$hortPuma96";
|
||||
|
||||
frm.textServerTo.Text = @"FIIRONSQL01\IRONINTEL";
|
||||
frm.textDBTo.Text = "IRONINTEL_09302016_TEST1_FIC";
|
||||
frm.textUserTo.Text = "cc";
|
||||
frm.textPassTo.Text = "$hortPuma96";
|
||||
Application.Run(frm);
|
||||
}
|
||||
|
||||
#if TEST
|
||||
static string DecryptAES(byte[] to)
|
||||
{
|
||||
var keys = Encoding.UTF8.GetBytes("HAO_HAO_JIA=+=MI");
|
||||
var r = new System.Security.Cryptography.RijndaelManaged
|
||||
{
|
||||
Key = keys,
|
||||
Mode = System.Security.Cryptography.CipherMode.ECB,
|
||||
Padding = System.Security.Cryptography.PaddingMode.None
|
||||
};
|
||||
var trans = r.CreateDecryptor();
|
||||
var result = trans.TransformFinalBlock(to, 0, to.Length);
|
||||
return Encoding.UTF8.GetString(result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
36
FICMigrator/Properties/AssemblyInfo.cs
Normal file
36
FICMigrator/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("FICMigrator")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("FICMigrator")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("6fa9cae8-f5e8-4536-b141-4a7a9f2ade05")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
77
FICMigrator/Properties/Resources.Designer.cs
generated
Normal file
77
FICMigrator/Properties/Resources.Designer.cs
generated
Normal file
@ -0,0 +1,77 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FICMigrator.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FICMigrator.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to /****** Object: UserDefinedDataType [dbo].[Description] Script Date: 2017/1/5 15:14:17 ******/
|
||||
///IF NOT EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N'Description' AND ss.name = N'dbo')
|
||||
///CREATE TYPE [dbo].[Description] FROM [nvarchar](200) NULL
|
||||
///
|
||||
////****** Object: UserDefinedDataType [dbo].[GUID] Script Date: 2017/1/5 15:14:17 ******/
|
||||
///IF NOT EXISTS (SELECT * FROM sys.types st JOIN sys.schemas ss ON st.schema_id = ss.schema_id WHERE st.name = N' [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string Create {
|
||||
get {
|
||||
return ResourceManager.GetString("Create", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
124
FICMigrator/Properties/Resources.resx
Normal file
124
FICMigrator/Properties/Resources.resx
Normal file
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="Create" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Resources\Create.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16</value>
|
||||
</data>
|
||||
</root>
|
35
FICMigrator/Properties/Settings.Designer.cs
generated
Normal file
35
FICMigrator/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,35 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace FICMigrator.Properties {
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default {
|
||||
get {
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
|
||||
[global::System.Configuration.ApplicationScopedSettingAttribute()]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Configuration.DefaultSettingValueAttribute("EXPORTLOG")]
|
||||
public string ExcludeTables {
|
||||
get {
|
||||
return ((string)(this["ExcludeTables"]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
FICMigrator/Properties/Settings.settings
Normal file
9
FICMigrator/Properties/Settings.settings
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="FICMigrator.Properties" GeneratedClassName="Settings">
|
||||
<Profiles />
|
||||
<Settings>
|
||||
<Setting Name="ExcludeTables" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)">EXPORTLOG</Value>
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
BIN
FICMigrator/Resources/Create.sql
Normal file
BIN
FICMigrator/Resources/Create.sql
Normal file
Binary file not shown.
160
IronIntelContractor/CacheManager.cs
Normal file
160
IronIntelContractor/CacheManager.cs
Normal file
@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Foresight.Cache;
|
||||
using Foresight.Cache.AspNet;
|
||||
using Foresight.Cache.Redis;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public static class CacheManager
|
||||
{
|
||||
public static void Dispose()
|
||||
{
|
||||
if (_Client != null)
|
||||
{
|
||||
_Client.Dispose();
|
||||
_Client = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient _Client = null;
|
||||
private static object _sycobj = new object();
|
||||
|
||||
private static FIRedisCacheClient CreateRedisClient(string[] servers)
|
||||
{
|
||||
if ((servers == null) || (servers.Length == 0))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<RedisNode> ls = new List<RedisNode>();
|
||||
foreach (string srv in servers)
|
||||
{
|
||||
try
|
||||
{
|
||||
RedisNode node = CreateRedisNode(srv);
|
||||
ls.Add(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", typeof(CacheManager).FullName + ".CreateRedisClient", "Create RedisNode failed: " + srv, ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
if (ls.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FIRedisCacheClient("IRONINTEL_" + ContractorHost.Instance.CustomerID.ToUpper(), ls);
|
||||
}
|
||||
}
|
||||
|
||||
private static RedisNode CreateRedisNode(string server)
|
||||
{
|
||||
string[] address = server.Split(new char[] { ':' });
|
||||
int port = -1;
|
||||
if (!int.TryParse(address[1], out port))
|
||||
{
|
||||
port = -1;
|
||||
}
|
||||
int weight = 100;
|
||||
if (!int.TryParse(address[2], out weight))
|
||||
{
|
||||
weight = 100;
|
||||
}
|
||||
RedisNode node = new RedisNode(address[0], port, weight);
|
||||
return node;
|
||||
}
|
||||
|
||||
private static void InitCacheClient()
|
||||
{
|
||||
FIRedisCacheClient fc = null;
|
||||
try
|
||||
{
|
||||
fc = CreateRedisClient(ContractorHost.Instance.RedisServersAddress);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", typeof(CacheManager).FullName + ".InitCacheClient", "Create Redis client failed", ex.ToString(),string.Empty);
|
||||
}
|
||||
if (fc != null)
|
||||
{
|
||||
_Client = fc;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Client = new AspNetCacheManager("IRONINTEL_" + ContractorHost.Instance.CustomerID.ToUpper());
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
lock (_sycobj)
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
InitCacheClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _Client;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Remove(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.Remove(key);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(string key, byte[] buffer, TimeSpan expire)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
Remove(key);
|
||||
}
|
||||
else if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.SetValue(key, buffer, expire);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetValue(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.GetValue(key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
269
IronIntelContractor/ContractorHost.cs
Normal file
269
IronIntelContractor/ContractorHost.cs
Normal file
@ -0,0 +1,269 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Configuration;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using Foresight.Data;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.DataModel.Admin.Customers;
|
||||
using IronIntel.DataModel.Admin.Users;
|
||||
using IronIntel.Services;
|
||||
using Foresight.Services.Log;
|
||||
using Foresight.Services.Mail;
|
||||
using IronIntel.DataModel.Admin;
|
||||
using IronIntel.DataModel.Admin.Machines;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
/// <summary>
|
||||
/// Ironintel contractor站点宿主。目前contractor站点仍然是每个公司一个站点
|
||||
/// </summary>
|
||||
public class ContractorHost : IIronIntelHost
|
||||
{
|
||||
public static ContractorHost Instance { get; private set; }
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Instance = new ContractorHost();
|
||||
IronIntelHostEnvironment.InitHost(Instance);
|
||||
}
|
||||
|
||||
private const string APPNAME = "IronIntelCustomerSite";
|
||||
|
||||
private CustomerManager _CustomerManager = null;
|
||||
private LoginManager _LoginManager = null;
|
||||
private LogWriter _LogWriter = null;
|
||||
private SystemParamProvider _MasterSystemParams = null;
|
||||
private MachineClassManager _MachineClassManager = null;
|
||||
private MachineManager _MachineManager = null;
|
||||
|
||||
public string DataDbConnectionString { get; private set; }
|
||||
public string FICDbConnectionString { get; private set; }
|
||||
public CustomerInfo Customer { get; private set; }
|
||||
|
||||
public DataModel.Contractor.ContractorSystemParams ContractorSystemParams { get; private set; }
|
||||
private string AdminDbConnectionString = string.Empty;
|
||||
private string MasterDbConnectionString = string.Empty;
|
||||
private string MasterDbConnectionString2 = string.Empty;//指向新的数据库服务器
|
||||
|
||||
public string CustomerID { get; private set; }
|
||||
private string MasterServiceAddress = string.Empty;
|
||||
private string FICSysDbName = string.Empty;
|
||||
|
||||
private string ForesightServiceAppName = string.Empty;
|
||||
private string ForesightServiceAddress = string.Empty;
|
||||
public string[] RedisServersAddress { get; private set; }
|
||||
|
||||
private ContractorHost()
|
||||
{
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(ConfigurationManager.AppSettings["DbConntionString"]);
|
||||
try
|
||||
{
|
||||
sb.Password = SystemUtility.DecryptString(sb.Password);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
DataDbConnectionString = sb.ToString();
|
||||
LoadLocalParams();
|
||||
InitMasterManager();
|
||||
CreateDbObjects();
|
||||
|
||||
_MachineManager = new MachineManager(AdminDbConnectionString);
|
||||
_MachineClassManager = new MachineClassManager(AdminDbConnectionString);
|
||||
|
||||
Customer = GetCustomerInfo(CustomerID);
|
||||
ContractorSystemParams = new DataModel.Contractor.ContractorSystemParams();
|
||||
ContractorSystemParams.Init(Customer, DataDbConnectionString, FICDbConnectionString);
|
||||
MasterDbConnectionString2 = _CustomerManager.GetCustomerIronIntelDbConnectionString2(CustomerID);
|
||||
}
|
||||
|
||||
private void LoadLocalParams()
|
||||
{
|
||||
const string PARAM_MASTER_SERVICE_ADDRESS = "MasterServiceAddress";
|
||||
const string PARAM_COMPANYID = "CompanyID";
|
||||
const string PARAM_FICSYSDB = "FICSysDBName";
|
||||
|
||||
|
||||
FISqlConnection db = new FISqlConnection(DataDbConnectionString);
|
||||
DataTable tb = db.GetDataTableBySQL("select PARAMNAME,PARAMVALUE from SYSPARAMS");
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
string pname = dr["PARAMNAME"].ToString();
|
||||
string pvalue = FIDbAccess.GetFieldString(dr["PARAMVALUE"], string.Empty);
|
||||
if (string.Compare(pname, PARAM_COMPANYID, true) == 0)
|
||||
{
|
||||
CustomerID = pvalue;
|
||||
}
|
||||
else if (string.Compare(pname, PARAM_MASTER_SERVICE_ADDRESS, true) == 0)
|
||||
{
|
||||
string[] uris = pvalue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
MasterServiceAddress = uris[0];
|
||||
}
|
||||
else if (string.Compare(pname, PARAM_FICSYSDB, true) == 0)
|
||||
{
|
||||
FICSysDbName = pvalue;
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(DataDbConnectionString);
|
||||
sb.InitialCatalog = FICSysDbName;
|
||||
FICDbConnectionString = sb.ConnectionString;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDbObjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
IronIntel.Services.Database.Contractor.ContractorDbCreator cd = new Services.Database.Contractor.ContractorDbCreator(DataDbConnectionString);
|
||||
cd.Create();
|
||||
|
||||
FI.FIC.Database.FIC.FICDbInitializer ficdb = new FI.FIC.Database.FIC.FICDbInitializer(FICDbConnectionString);
|
||||
ficdb.RunIronIntel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog(CustomerID, GetType().FullName + ".CreateDbObjects()", "Init db objects failed: " + ex.Message, ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
private void InitMasterManager()
|
||||
{
|
||||
IronSysServiceClient client = new IronSysServiceClient(MasterServiceAddress);
|
||||
client.AppName = APPNAME;
|
||||
AdminDbConnectionString = client.GetAdminDbConnectionString();
|
||||
|
||||
FISqlConnection db = new FISqlConnection(AdminDbConnectionString);
|
||||
string masterdb = FIDbAccess.GetFieldString(db.GetRC1BySQL("select PARAMVALUE from SYSPARAMS where PARAMNAME='MASTER_DB_NAME'"), string.Empty);
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(AdminDbConnectionString);
|
||||
sb.InitialCatalog = masterdb;
|
||||
MasterDbConnectionString = sb.ConnectionString;
|
||||
|
||||
_CustomerManager = new CustomerManager(MasterDbConnectionString);
|
||||
_LoginManager = new LoginManager(MasterDbConnectionString);
|
||||
|
||||
_MasterSystemParams = new SystemParamProvider(MasterDbConnectionString);
|
||||
|
||||
ForesightServiceAppName = _MasterSystemParams.ForesightServiceAppName;
|
||||
ForesightServiceAddress = _MasterSystemParams.ForesightServiceAddress;
|
||||
|
||||
string str = _MasterSystemParams.RedisServersAddress;
|
||||
if(string.IsNullOrWhiteSpace(str))
|
||||
{
|
||||
RedisServersAddress = new string[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
RedisServersAddress = str.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
_LogWriter = new LogWriter(ForesightServiceAddress);
|
||||
_LogWriter.AppName = ForesightServiceAppName;
|
||||
}
|
||||
|
||||
public CustomerManager GetCustomerManager()
|
||||
{
|
||||
return _CustomerManager;
|
||||
}
|
||||
|
||||
public LoginManager GetLoginManager()
|
||||
{
|
||||
return _LoginManager;
|
||||
}
|
||||
|
||||
public long SendEmail(string customerid, MailMessage msg)
|
||||
{
|
||||
return SendEmail(customerid, APPNAME, msg);
|
||||
}
|
||||
|
||||
public long SendEmail(string customerid,string mailtype, MailMessage msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
MailSender mail = new MailSender(ForesightServiceAddress);
|
||||
mail.AppName = ForesightServiceAppName;
|
||||
return mail.SendMail(ForesightServiceAppName, customerid, mailtype, msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteLog(customerid, "Error", GetType().FullName + ".SendEmail", "Add mail to mailservice failed: " + ex.Message, ex.ToString(), string.Empty);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public void WriteLog(string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
_LogWriter.WriteLog(ForesightServiceAppName, CustomerInfo.FORESIGHT, SystemUtility.HostName, APPNAME, logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
public void WriteLog(string customerid, string logtype, string source, string message, string detail, string extmsg)
|
||||
{
|
||||
_LogWriter.WriteLog(ForesightServiceAppName, customerid, SystemUtility.HostName, APPNAME, logtype, source, message, detail, extmsg);
|
||||
}
|
||||
|
||||
public string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
return _LogWriter.GetResourceLock(ForesightServiceAppName, resourceid, locksecond);
|
||||
}
|
||||
|
||||
public void ReleaseLock(string lockid)
|
||||
{
|
||||
_LogWriter.ReleaseLock(ForesightServiceAppName, lockid);
|
||||
}
|
||||
|
||||
public CustomerInfo GetCustomerInfo(string custid)
|
||||
{
|
||||
if (Customer != null)
|
||||
{
|
||||
if (string.Compare(custid, Customer.ID, true) == 0)
|
||||
{
|
||||
return Customer;
|
||||
}
|
||||
}
|
||||
return _CustomerManager.GetCustomerByID(custid);
|
||||
}
|
||||
|
||||
public DataModel.LicenseInfo GetLicense()
|
||||
{
|
||||
return _CustomerManager.GetLicense(CustomerID);
|
||||
}
|
||||
|
||||
public string GetIronIntelDbConnectionString(string custid)
|
||||
{
|
||||
if (string.Compare(custid, CustomerID, true) == 0)
|
||||
{
|
||||
return DataDbConnectionString;
|
||||
}
|
||||
return _CustomerManager.GetCustomerIronIntelDbConnectionString(custid);
|
||||
}
|
||||
|
||||
public T GetContractorManager<T>() where T : DataModel.Contractor.ContractorBusinessBase, new()
|
||||
{
|
||||
T rst = new T();
|
||||
rst.Init(Customer, DataDbConnectionString, FICDbConnectionString);
|
||||
return rst;
|
||||
}
|
||||
|
||||
public IronIntel.DataModel.Contractor.Users.UserManager GetUserManager()
|
||||
{
|
||||
return GetContractorManager<IronIntel.DataModel.Contractor.Users.UserManager>();
|
||||
}
|
||||
|
||||
public SystemParamProvider GetSystemParamsProvider()
|
||||
{
|
||||
return _MasterSystemParams;
|
||||
}
|
||||
|
||||
public MachineClassManager GetMachineClassManager()
|
||||
{
|
||||
return _MachineClassManager;
|
||||
}
|
||||
|
||||
public MachineManager GetMachineManager()
|
||||
{
|
||||
return _MachineManager;
|
||||
}
|
||||
}
|
||||
}
|
528
IronIntelContractor/FIC/FICHost.cs
Normal file
528
IronIntelContractor/FIC/FICHost.cs
Normal file
@ -0,0 +1,528 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using System.Net.Mail;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using Foresight.Data;
|
||||
using Foresight.Security.License;
|
||||
using System.Web;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using FI.FIC;
|
||||
using IronIntel.DataModel.Contractor.Users;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using IronIntel.DataModel;
|
||||
using IronIntel.Contractor.Site;
|
||||
|
||||
namespace IronIntel.Contractor.FIC
|
||||
{
|
||||
public class FICHost : IFICHost
|
||||
{
|
||||
static readonly Guid FIC_MODULE_ID = new Guid("1c6dfe25-347d-4889-ab75-73ade9190d27");
|
||||
const string FIC_MODULE_NAME = "Foresight Intelligence Center";
|
||||
const string FIC_MODULE_VERSION = "3.0";
|
||||
|
||||
public string FICDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return ContractorHost.Instance.FICDbConnectionString;
|
||||
}
|
||||
}
|
||||
|
||||
public string FrsDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
public bool FICInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool FRSInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
FICHostEnvironment.SetHost(new FICHost());
|
||||
}
|
||||
|
||||
public byte[] GetCacheData(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = CacheManager.GetValue(key);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Decompress(buffer);
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.FromBuffer(tmp);
|
||||
createTime = fc.CreateTime;
|
||||
return fc.Data;
|
||||
}
|
||||
|
||||
public DataTable GetCacheDataTable(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = GetCacheData(key, ignoreExpired, ref createTime);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//FIDataTable tb = new FIDataTable();
|
||||
//tb.FillFromBuffer(buffer);
|
||||
//return FIDbAccess.ConvertDataTable(tb);
|
||||
return Deserialize(buffer) as DataTable;
|
||||
}
|
||||
|
||||
public FICCompanyInfo GetCompanyInfo()
|
||||
{
|
||||
var cp = ContractorHost.Instance.Customer;
|
||||
FICCompanyInfo ficcp = new FICCompanyInfo();
|
||||
ficcp.ID = cp.ID;
|
||||
ficcp.Name = cp.Name;
|
||||
|
||||
return ficcp;
|
||||
}
|
||||
|
||||
public CompanyLic GetLicense()
|
||||
{
|
||||
var lic = ContractorHost.Instance.GetLicense();
|
||||
if (lic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CompanyLic ci = new CompanyLic();
|
||||
ci.CompanyID = ContractorHost.Instance.Customer.ID;
|
||||
ci.CompanyName = ContractorHost.Instance.Customer.Name;
|
||||
|
||||
Foresight.Security.License.LicenseInfo li = new Foresight.Security.License.LicenseInfo();
|
||||
ci.Licenses.Add(li);
|
||||
li.CompanyID = ci.CompanyID;
|
||||
li.CompanyName = ci.CompanyName;
|
||||
li.Expiration = lic.ExpireDate;
|
||||
li.ID = Guid.Empty;
|
||||
li.StartDate = lic.StartDate;
|
||||
li.ModuleID = FIC_MODULE_ID;
|
||||
li.ModuleName = FIC_MODULE_NAME;
|
||||
li.Version = FIC_MODULE_VERSION;
|
||||
|
||||
foreach (var item in lic.Items)
|
||||
{
|
||||
var prop = ConvertLicenseItem(item);
|
||||
if (prop != null)
|
||||
{
|
||||
li.AddtionalPropertes.Add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
return ci;
|
||||
}
|
||||
|
||||
private LicenseAddtionalPropertyObj ConvertLicenseItem(DataModel.LicenseItem item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
switch (item.Key)
|
||||
{
|
||||
case "ColumnLineCombChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ColumnLineCombChart", Value = item.Value, Description = item.Description };
|
||||
case "ExportChartToXPS":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ExportChartToXPS", Value = item.Value, Description = item.Description };
|
||||
case "FreeChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "FreeChart", Value = item.Value, Description = item.Description };
|
||||
case "DrilldownToURL":
|
||||
return new LicenseAddtionalPropertyObj { Key = "DrilldownToURL", Value = item.Value, Description = item.Description };
|
||||
case "MaxCharts":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxCharts", Value = item.Value, Description = item.Description };
|
||||
case "MaxDataTables":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxDataTables", Value = item.Value, Description = item.Description };
|
||||
case "PrintChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "PrintChart", Value = item.Value, Description = item.Description };
|
||||
case "ScatterChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ScatterChart", Value = item.Value, Description = item.Description };
|
||||
case "Snapshot":
|
||||
return new LicenseAddtionalPropertyObj { Key = "Snapshot", Value = item.Value, Description = item.Description };
|
||||
case "SQLGenerator":
|
||||
return new LicenseAddtionalPropertyObj { Key = "SQLGenerator", Value = item.Value, Description = item.Description };
|
||||
//case "MainStyle":
|
||||
//case "MaxAdminCount":
|
||||
//case "MaxLogins":
|
||||
//case "MaxNormalUerCount":
|
||||
//case "MaxReadOnlyUserCount":
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
return ContractorHost.Instance.GetResourceLock(resourceid, locksecond);
|
||||
}
|
||||
|
||||
private static FICUserInfo ConvertToFICUserInfo(IronIntel.DataModel.Contractor.Users.UserInfo ui)
|
||||
{
|
||||
var user = new FICUserInfo
|
||||
{
|
||||
ID = ui.ID,
|
||||
IID = ui.UID,
|
||||
Enabled = ui.Active,
|
||||
DisplayName = ui.Name,
|
||||
Mobile = ui.Mobile,
|
||||
BusinessPhone = ui.BusinessPhone,
|
||||
};
|
||||
switch (ui.UserType)
|
||||
{
|
||||
case UserTypes.Common:
|
||||
user.UserType = FICUserTypes.Common;
|
||||
break;
|
||||
case UserTypes.Admin:
|
||||
user.UserType = FICUserTypes.Admin;
|
||||
break;
|
||||
case UserTypes.Readonly:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
case UserTypes.SupperAdmin:
|
||||
user.UserType = FICUserTypes.SuperAdmin;
|
||||
break;
|
||||
default:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByIID(string useriid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
var ui = um.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByLoginSessionID(string sessionid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo ui = um.GetUserByLoginSessionID(sessionid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByUserID(string userId)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo ui = um.GetUserByID(userId);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers()
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
UserInfo[] users = um.GetSelfUsers();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public string GetUserEmail(string useriid)
|
||||
{
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
UserInfo ui = um.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ui.ID;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostMessage(int category, string msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void ReleaseResourceLock(string lockid)
|
||||
{
|
||||
ContractorHost.Instance.ReleaseLock(lockid);
|
||||
}
|
||||
|
||||
public void RemoveCache(string key)
|
||||
{
|
||||
CacheManager.Remove(key);
|
||||
}
|
||||
|
||||
public void SendMail(MailMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
ContractorHost.Instance.SendEmail(ContractorHost.Instance.CustomerID, "FIC", message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog("Error", this.GetType().FullName + ".SendMail(MailMessage)", "Add fic mail to mail service failed", ex.ToString(), string.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCacheData(string key, byte[] buffer, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
return;
|
||||
}
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.Data = buffer;
|
||||
fc.CreateTime = createTime;
|
||||
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Compress(fc.ToBuffer());
|
||||
CacheManager.SetValue(key, tmp, TimeSpan.FromSeconds(expirationsecond));
|
||||
}
|
||||
|
||||
public void SetCacheDataTable(string key, DataTable dt, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (dt == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] buffer = Serialize(dt, createTime);
|
||||
SetCacheData(key, buffer, expirationsecond, slidingExpiration, createTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void SubscribeMessage(int category, Action<IEnumerable<MessageInformation>> action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void WriteLog(string logType, string category, string source, string message, string detail)
|
||||
{
|
||||
ContractorHost.Instance.WriteLog(logType, source, message, detail,category);
|
||||
}
|
||||
|
||||
public List<string> GetUserGroupIDByUserIID(string userIID)
|
||||
{
|
||||
var grps = ContractorHost.Instance.GetUserManager().GetGroupsByUserIID(userIID);
|
||||
List<string> ls = new List<string>(grps.Length);
|
||||
foreach(var grp in grps)
|
||||
{
|
||||
ls.Add(grp.ID);
|
||||
}
|
||||
return ls;
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers(bool hasAdmin)
|
||||
{
|
||||
if (!hasAdmin)
|
||||
{
|
||||
return GetUsers();
|
||||
}
|
||||
|
||||
var um = ContractorHost.Instance.GetUserManager();
|
||||
|
||||
UserInfo[] localusers = um.GetSelfUsers();
|
||||
UserInfo[] foresightusers = um.GetForesightUsers();
|
||||
UserInfo[] users = localusers.Union(foresightusers).ToArray();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public LoginContext GetCurrentLoginContext(HttpContext context)
|
||||
{
|
||||
string session = Site.IronIntelBasePage.GetLoginSessionID(context.Request);
|
||||
if (string.IsNullOrWhiteSpace(session))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
LoginContext lc = new LoginContext();
|
||||
lc.SessionID = session;
|
||||
lc.User = GetUserByLoginSessionID(session);
|
||||
lc.LanguageID = GetLgID(context);
|
||||
return lc;
|
||||
}
|
||||
|
||||
private string GetLgID(HttpContext context)
|
||||
{
|
||||
var language = context.Request.Cookies[IronIntelBasePage.LANGUAGECOOKIENAME];
|
||||
if (language != null)
|
||||
{
|
||||
return language.Value;
|
||||
}
|
||||
return ResLanguage.ClientCurrentLanguage;
|
||||
}
|
||||
|
||||
public string ProductEdition
|
||||
{
|
||||
get
|
||||
{
|
||||
return "General";
|
||||
}
|
||||
}
|
||||
|
||||
public string FIExternalDBConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public SpecialDatabaseConnectionInfo[] GetSpecialDatabaseConnections()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string GetStyleDefines(string useriid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
//StringBuilder s = new StringBuilder();
|
||||
//s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
//s.Append("<root>");
|
||||
//s.Append("<Workspace><Title><Background>#ff00ff</Background><Foreground>#222222</Foreground></Title></Workspace>");
|
||||
//s.Append("<Chart><Title><Background>#333333</Background><Foreground>#444444</Foreground></Title><Board>#555555</Board></Chart>");
|
||||
//s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
//s.Append("</root>");
|
||||
//return s.ToString();
|
||||
//// Services.CustUIStyle uistyle = SystemParams.GetUIStyle(useriid);
|
||||
|
||||
// StringBuilder s = new StringBuilder();
|
||||
// s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
// s.Append("<root>");
|
||||
// s.Append("<Workspace><Title><Background></Background><Foreground>#000000</Foreground></Title></Workspace>");
|
||||
// s.Append("<Chart><Title><Background>" + uistyle.ChartTitleBackgroundColor + "</Background><Foreground></Foreground></Title><Board>" + uistyle.ChartBorderColor + "</Board></Chart>");
|
||||
// //s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
// s.Append("</root>");
|
||||
// return s.ToString();
|
||||
}
|
||||
public Dictionary<string, string> GetAdditionalParameter()
|
||||
{
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic.Add("ConnectorToken", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("ConnectorToken"));
|
||||
dic.Add("ConnectorServer", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("ConnectorServer"));
|
||||
dic.Add("LdapAgentID", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("LdapAgentID"));
|
||||
dic.Add("LdapAgentToken", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("LdapAgentToken"));
|
||||
dic.Add("CanUseConnectorLDAP", ContractorHost.Instance.ContractorSystemParams.GetFICStringParam("CanUseConnectorLDAP"));
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetSimpleUsers(bool hasAdmin)
|
||||
{
|
||||
var users = GetUsers(hasAdmin);
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
var us = new FICUserInfo();
|
||||
us.IID = user.IID;
|
||||
us.ID = user.ID;
|
||||
us.DisplayName = user.DisplayName;
|
||||
ls.Add(us);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
class FICCacheObject
|
||||
{
|
||||
public byte[] Data = null;
|
||||
public DateTime CreateTime = DateTime.Now;
|
||||
|
||||
public byte[] ToBuffer()
|
||||
{
|
||||
byte[] rst = new byte[Data.Length + 8];
|
||||
byte[] bf1 = BitConverter.GetBytes(CreateTime.Ticks);
|
||||
Buffer.BlockCopy(bf1, 0, rst, 0, 8);
|
||||
Buffer.BlockCopy(Data, 0, rst, 8, Data.Length);
|
||||
|
||||
return rst;
|
||||
}
|
||||
|
||||
public void FromBuffer(byte[] buffer)
|
||||
{
|
||||
long l = BitConverter.ToInt64(buffer, 0);
|
||||
CreateTime = new DateTime(l);
|
||||
Data = new byte[buffer.Length - 8];
|
||||
Buffer.BlockCopy(buffer, 8, Data, 0, buffer.Length - 8);
|
||||
}
|
||||
}
|
||||
|
||||
#region - (De)Serialize -
|
||||
|
||||
private static byte[] Serialize(object obj, DateTime createtime)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var cacheObj = new RedisCacheObject
|
||||
{
|
||||
CreateTime = createtime,
|
||||
Data = obj
|
||||
};
|
||||
byte[] data;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(ms, cacheObj);
|
||||
data = ms.ToArray();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static object Deserialize(byte[] buffer)
|
||||
{
|
||||
using (var ms = new MemoryStream(buffer, false))
|
||||
{
|
||||
return new BinaryFormatter().Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[Serializable]
|
||||
class RedisCacheObject
|
||||
{
|
||||
public DateTime CreateTime { get; set; }
|
||||
public object Data { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
118
IronIntelContractor/IronIntelContractor.csproj
Normal file
118
IronIntelContractor/IronIntelContractor.csproj
Normal file
@ -0,0 +1,118 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{66F769E6-9708-4924-A9D8-BA8AE92B94D5}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IronIntel.Contractor</RootNamespace>
|
||||
<AssemblyName>IronIntelContractor</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>LHBIS.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FIASPNETCache">
|
||||
<HintPath>..\Reflib\FIASPNETCache.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICacheManager.Redis">
|
||||
<HintPath>..\Reflib\FICacheManager.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICachManager">
|
||||
<HintPath>..\Reflib\FICachManager.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICBLC">
|
||||
<HintPath>..\Reflib\FIC\FICBLC.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntf">
|
||||
<HintPath>..\Reflib\FIC\FICIntf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntfAdv">
|
||||
<HintPath>..\Reflib\FIC\FICIntfAdv.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICModels">
|
||||
<HintPath>..\Reflib\FIC\FICModels.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICore">
|
||||
<HintPath>..\Reflib\FICore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICoreDbCreator">
|
||||
<HintPath>..\Reflib\FICoreDbCreator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FIWinLib">
|
||||
<HintPath>..\Reflib\FIWinLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ForesightServicesClient">
|
||||
<HintPath>..\Reflib\ForesightServicesClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisyslib">
|
||||
<HintPath>..\Reflib\iisyslib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="irondbobjlib">
|
||||
<HintPath>..\Reflib\irondbobjlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Reflib\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="StackExchange.Redis.StrongName">
|
||||
<HintPath>..\Reflib\StackExchange.Redis.StrongName.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CacheManager.cs" />
|
||||
<Compile Include="ContractorHost.cs" />
|
||||
<Compile Include="FIC\FICHost.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Site\IronIntelBasePage.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Site\IronIntelHttpHandlerBase.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DataModel\DataModel.csproj">
|
||||
<Project>{b0d49bbd-b287-44f0-aaaf-33833532ce4c}</Project>
|
||||
<Name>DataModel</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="LHBIS.snk" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
BIN
IronIntelContractor/LHBIS.snk
Normal file
BIN
IronIntelContractor/LHBIS.snk
Normal file
Binary file not shown.
36
IronIntelContractor/Properties/AssemblyInfo.cs
Normal file
36
IronIntelContractor/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("IronIntelContractor")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Foresight Intelligence")]
|
||||
[assembly: AssemblyProduct("IronIntelContractor")]
|
||||
[assembly: AssemblyCopyright("Copyright © Foresight Intelligence 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("66f769e6-9708-4924-a9d8-ba8ae92b94d5")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("3.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("3.18.1011.0")]
|
436
IronIntelContractor/Site/IronIntelBasePage.cs
Normal file
436
IronIntelContractor/Site/IronIntelBasePage.cs
Normal file
@ -0,0 +1,436 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using Foresight.ServiceModel;
|
||||
using Foresight.Security;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Users;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.Site
|
||||
{
|
||||
public class IronIntelBasePage : System.Web.UI.Page
|
||||
{
|
||||
public const string LOGINSESSION_COOKIENAME = "iiabc_";
|
||||
public const string LANGUAGECOOKIENAME = LOGINSESSION_COOKIENAME + "language";
|
||||
public const string APPNAME = "iron-desktop";
|
||||
public const string CLIENT_TIMEOFFSET_COOKIENAME = "clienttimeoffset";
|
||||
|
||||
private static int _LOCAL_TIMEOFFSET = 10000;
|
||||
|
||||
private static string _HostName = null;
|
||||
|
||||
private static string _Branch = string.Empty;
|
||||
private static string _AboutUrl = string.Empty;
|
||||
private static string _Copyrights = string.Empty;
|
||||
private static string _PageTitle = string.Empty;
|
||||
private static string _ShowTermofuse = string.Empty;
|
||||
|
||||
public static string LocalHostName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_HostName == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_HostName = Dns.GetHostName();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_HostName = string.Empty;
|
||||
}
|
||||
}
|
||||
return _HostName;
|
||||
}
|
||||
}
|
||||
|
||||
public static int LocalTimeOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_LOCAL_TIMEOFFSET == 10000)
|
||||
{
|
||||
DateTime dt = DateTime.Now;
|
||||
DateTime dt1 = dt.ToUniversalTime();
|
||||
TimeSpan sp = dt1 - dt;
|
||||
_LOCAL_TIMEOFFSET = Convert.ToInt32(sp.TotalMinutes);
|
||||
}
|
||||
return _LOCAL_TIMEOFFSET;
|
||||
}
|
||||
}
|
||||
|
||||
private static readonly byte[] KEY = new byte[] { 219, 239, 201, 20, 173, 133, 64, 29, 33, 71, 49, 117, 208, 115, 79, 169, 1, 126, 201, 229, 115, 35, 62, 102, 71, 16, 71, 220, 44, 95, 186, 223 };
|
||||
private static readonly byte[] IV = new byte[] { 255, 180, 99, 244, 147, 37, 175, 243, 193, 52, 167, 82, 143, 199, 242, 171 };
|
||||
|
||||
public static string EncryptString(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
byte[] buf = Encoding.UTF8.GetBytes(s);
|
||||
byte[] tmp = SecurityHelper.AesEncrypt(buf, KEY, IV);
|
||||
return Convert.ToBase64String(tmp);
|
||||
}
|
||||
|
||||
public static string DecryptString(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
byte[] tmp = Convert.FromBase64String(s);
|
||||
byte[] buf = SecurityHelper.AesDecrypt(tmp, KEY, IV);
|
||||
return Encoding.UTF8.GetString(buf);
|
||||
}
|
||||
|
||||
public virtual string GetIronSystemServiceAddress()
|
||||
{
|
||||
return ConfigurationManager.AppSettings["syssvcaddress"];
|
||||
}
|
||||
|
||||
public virtual IronSysServiceClient GetSystemServiceClient()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual CustomerProvider GetCustomerProvider()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
CustomerProvider ic = new CustomerProvider(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual LoginProvider GetLoginProvider()
|
||||
{
|
||||
LoginSession session = null;
|
||||
try
|
||||
{
|
||||
session = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
if (session != null)
|
||||
{
|
||||
ic.AppName = session.AppName;
|
||||
ic.LoginSessionID = session.SessionID;
|
||||
ic.CurrentUserIID = session.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
private string GetServerParam(string key)
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
StringKeyValue[] kvs = ic.GetServerParams();
|
||||
foreach (StringKeyValue kv in kvs)
|
||||
{
|
||||
if (string.Compare(kv.Key, key, true) == 0)
|
||||
{
|
||||
return kv.Value;
|
||||
}
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public string Branch
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_Branch))
|
||||
{
|
||||
_Branch = GetServerParam("Branch");
|
||||
}
|
||||
return _Branch;
|
||||
}
|
||||
}
|
||||
|
||||
public string AboutUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_AboutUrl))
|
||||
{
|
||||
_AboutUrl = GetServerParam("AboutUrl");
|
||||
}
|
||||
return _AboutUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public string Copyrights
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_Copyrights))
|
||||
{
|
||||
_Copyrights = GetServerParam("Copyrights");
|
||||
}
|
||||
return _Copyrights;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public string PageTitle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_PageTitle))
|
||||
{
|
||||
_PageTitle = GetServerParam("PageTitle");
|
||||
}
|
||||
return _PageTitle;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowTermofuse
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(_ShowTermofuse))
|
||||
{
|
||||
_ShowTermofuse = GetServerParam("ShowTermofuse");
|
||||
}
|
||||
return string.Compare(_ShowTermofuse, "True", true) == 0 || string.Compare(_ShowTermofuse, "Yes", true) == 0 || string.Compare(_ShowTermofuse, "1", true) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetLoginSessionID(HttpRequest request)
|
||||
{
|
||||
HttpCookie cookie = request.Cookies[LOGINSESSION_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return DecryptString(cookie.Value);
|
||||
}
|
||||
|
||||
public LoginSession GetCurrentLoginSession()
|
||||
{
|
||||
string sessionid = GetLoginSessionID(Request);
|
||||
if (string.IsNullOrWhiteSpace(sessionid))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
return ic.GetLoginSession(sessionid);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void RedirectToLoginPage()
|
||||
{
|
||||
Response.Redirect(LoginPageUrl);
|
||||
}
|
||||
|
||||
protected string LoginPageUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
return ic.GetPortalLoginUrl();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 当用户登录成功后,跳转到用户的默认主界面, 也即是各公司的主界面
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
protected void RedirectToUsersDefaultEntryPage(UserInfo user)
|
||||
{
|
||||
Response.Redirect(GetUserDefaultEntryPageUrl(user), true);
|
||||
}
|
||||
|
||||
protected string GetUserDefaultEntryPageUrl(UserInfo user)
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
return ic.GetCompanyPortalEntryUrl(user.CompanyID);
|
||||
}
|
||||
|
||||
protected void ClearLoginSessionCookie()
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(LOGINSESSION_COOKIENAME);
|
||||
cookie.Value = string.Empty;
|
||||
cookie.Expires = DateTime.Now.AddDays(-3);
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected void SetLoginSessionCookie(string sessionid)
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(LOGINSESSION_COOKIENAME);
|
||||
cookie.Value = EncryptString(sessionid);
|
||||
|
||||
string path = ConfigurationManager.AppSettings["sessioncookiepath"];
|
||||
if (!string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
cookie.Path = path;
|
||||
}
|
||||
string domain = ConfigurationManager.AppSettings["sessioncookiedomain"];
|
||||
if (!string.IsNullOrWhiteSpace(domain))
|
||||
{
|
||||
cookie.Domain = domain;
|
||||
}
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected void SetClientTimeOffset(int offset)
|
||||
{
|
||||
HttpCookie cookie = new HttpCookie(CLIENT_TIMEOFFSET_COOKIENAME);
|
||||
cookie.Value = offset.ToString();
|
||||
cookie.Expires = DateTime.Now.AddYears(1);
|
||||
Response.Cookies.Add(cookie);
|
||||
}
|
||||
|
||||
protected int GetClientTimeOffset()
|
||||
{
|
||||
HttpCookie cookie = Request.Cookies[CLIENT_TIMEOFFSET_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
int n = 0;
|
||||
if (int.TryParse(cookie.Value, out n))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return LocalTimeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public static DateTime UtcTimeToClientTime(DateTime dt, int clienttimeoffset)
|
||||
{
|
||||
return dt.AddMinutes(-1 * clienttimeoffset);
|
||||
}
|
||||
|
||||
public static Int64 GetSiteFileDateTime(string url)
|
||||
{
|
||||
string fn = HttpContext.Current.Server.MapPath(url);
|
||||
if (System.IO.File.Exists(fn))
|
||||
{
|
||||
try
|
||||
{
|
||||
return System.IO.File.GetLastWriteTimeUtc(fn).Ticks;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于构造js/css或图片文件的url,在其最后加上版本标识,解决浏览器缓存问题
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetFileUrlWithVersion(string url)
|
||||
{
|
||||
string fn = HttpContext.Current.Server.MapPath(url);
|
||||
if (System.IO.File.Exists(fn))
|
||||
{
|
||||
try
|
||||
{
|
||||
Int64 n = System.IO.File.GetLastWriteTimeUtc(fn).Ticks;
|
||||
return url + "?sn=" + n.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadTextFromStream(System.IO.Stream stream)
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetUserHostAddress(HttpRequest request)
|
||||
{
|
||||
const string CLIENT_IP = "client-ip";
|
||||
if (request == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
string rst = request.Headers[CLIENT_IP];
|
||||
if (string.IsNullOrWhiteSpace(rst))
|
||||
{
|
||||
rst = request.UserHostAddress;
|
||||
}
|
||||
if (rst == null)
|
||||
{
|
||||
rst = string.Empty;
|
||||
}
|
||||
return rst;
|
||||
}
|
||||
|
||||
protected string UserHostAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetUserHostAddress(Request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
151
IronIntelContractor/Site/IronIntelHttpHandlerBase.cs
Normal file
151
IronIntelContractor/Site/IronIntelHttpHandlerBase.cs
Normal file
@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using System.Web;
|
||||
using Foresight.Security;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Users;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.Site
|
||||
{
|
||||
public class IronIntelHttpHandlerBase : IDisposable
|
||||
{
|
||||
public static string LocalHostName
|
||||
{
|
||||
get { return IronIntelBasePage.LocalHostName; }
|
||||
}
|
||||
|
||||
public HttpContext Context { get; private set; }
|
||||
protected LoginSession LoginSession { get; private set; }
|
||||
|
||||
protected int ClientTimeOffset { get; private set; }
|
||||
|
||||
public IronIntelHttpHandlerBase(HttpContext context)
|
||||
{
|
||||
Context = context;
|
||||
try
|
||||
{
|
||||
LoginSession = GetCurrentLoginSession();
|
||||
}
|
||||
catch
|
||||
{
|
||||
LoginSession = null;
|
||||
}
|
||||
ClientTimeOffset = GetClientTimeOffset();
|
||||
}
|
||||
|
||||
public virtual string GetIronSystemServiceAddress()
|
||||
{
|
||||
return ConfigurationManager.AppSettings["syssvcaddress"];
|
||||
}
|
||||
|
||||
public virtual IronSysServiceClient GetSystemServiceClient()
|
||||
{
|
||||
IronSysServiceClient ic = new IronSysServiceClient(GetIronSystemServiceAddress());
|
||||
if (LoginSession != null)
|
||||
{
|
||||
ic.AppName = LoginSession.AppName;
|
||||
ic.LoginSessionID = LoginSession.SessionID;
|
||||
ic.CurrentUserIID = LoginSession.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public virtual CustomerProvider GetCustomerProvider()
|
||||
{
|
||||
CustomerProvider ic = new CustomerProvider(GetIronSystemServiceAddress());
|
||||
if (LoginSession != null)
|
||||
{
|
||||
ic.AppName = LoginSession.AppName;
|
||||
ic.LoginSessionID = LoginSession.SessionID;
|
||||
ic.CurrentUserIID = LoginSession.User.UID;
|
||||
}
|
||||
return ic;
|
||||
}
|
||||
|
||||
public LoginSession GetCurrentLoginSession()
|
||||
{
|
||||
HttpCookie cookie = Context.Request.Cookies[IronIntelBasePage.LOGINSESSION_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string sessionid = IronIntelBasePage.DecryptString(cookie.Value);
|
||||
try
|
||||
{
|
||||
LoginProvider ic = new LoginProvider(GetIronSystemServiceAddress());
|
||||
return ic.GetLoginSession(sessionid);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int GetClientTimeOffset()
|
||||
{
|
||||
HttpCookie cookie = Context.Request.Cookies[IronIntelBasePage.CLIENT_TIMEOFFSET_COOKIENAME];
|
||||
if (cookie == null)
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(cookie.Value))
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
int n = 0;
|
||||
if (int.TryParse(cookie.Value, out n))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return IronIntelBasePage.LocalTimeOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ReadTextFromStream(System.IO.Stream stream)
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(stream))
|
||||
{
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ProcessRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
protected void Dispose(bool disposed)
|
||||
{
|
||||
Context = null;
|
||||
LoginSession = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
Dispose(true);
|
||||
disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public string UserHostAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
return IronIntelBasePage.GetUserHostAddress(Context.Request);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
IronIntelContractorBusiness/App.config
Normal file
23
IronIntelContractorBusiness/App.config
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="DbConntionString" value="Data Source=192.168.25.215\ironintel;Initial Catalog=IRONINTEL_IRONDEV;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="JRE_IronIntelDb" value="Data Source=192.168.25.215\ironintel;Initial Catalog=JRE_IRONINTEL;Integrated Security=false;User ID=fi;Password=database"/>
|
||||
<add key="ClientSettingsProvider.ServiceUri" value=""/>
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
||||
</startup>
|
||||
<system.web>
|
||||
<membership defaultProvider="ClientAuthenticationMembershipProvider">
|
||||
<providers>
|
||||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/>
|
||||
</providers>
|
||||
</membership>
|
||||
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
|
||||
<providers>
|
||||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/>
|
||||
</providers>
|
||||
</roleManager>
|
||||
</system.web>
|
||||
</configuration>
|
23
IronIntelContractorBusiness/Attachment/AttachmentItem.cs
Normal file
23
IronIntelContractorBusiness/Attachment/AttachmentItem.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Attachment
|
||||
{
|
||||
public class AttachmentItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string StringID { get; set; }//为了兼容旧数据库中的ATTACHES.ATTACHID字段,旧数据库中的表由Workorder和MaintanceLog在使用
|
||||
public string FileName { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string SourceID { get; set; }
|
||||
public string AddedByUserIID { get; set; }
|
||||
public string AddedByUserName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime AddedOn { get; set; }
|
||||
public string AddedOnStr { get { return AddedOn.ToString(); } }
|
||||
public byte[] FileData { get; set; }
|
||||
}
|
||||
}
|
181
IronIntelContractorBusiness/AttachmentsManagement.cs
Normal file
181
IronIntelContractorBusiness/AttachmentsManagement.cs
Normal file
@ -0,0 +1,181 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight.ServiceModel;
|
||||
using Newtonsoft.Json;
|
||||
using Foresight.Data;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Contractor.Attachment;
|
||||
using Foresight.Fleet.Services.Attachment;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class AttachmentsManagement
|
||||
{
|
||||
public static StringKeyValue[] GetAttachList(string refID, string source)
|
||||
{
|
||||
string SQL = @"SELECT ATTACHID,FILENAME,ADDEDBY,ADDEDON_UTC
|
||||
FROM ATTACHES WHERE REFID={0} and SOURCE={1}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, refID, source);
|
||||
|
||||
var users = Users.UserManagement.GetAllAvailableUsers();
|
||||
return ConvertToSKarray(dt, users);
|
||||
}
|
||||
|
||||
public static StringKeyValue GetAttachByAttachID(string attachID)
|
||||
{
|
||||
string SQL = @"SELECT ATTACHID,FILENAME,ADDEDBY,ADDEDON_UTC
|
||||
FROM ATTACHES WHERE ATTACHID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, attachID);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
var user = Users.UserManagement.GetUserByIID(FIDbAccess.GetFieldString(dt.Rows[0]["ADDEDBY"], string.Empty));
|
||||
StringKeyValue[] skarray = ConvertToSKarray(dt, new UserInfo[] { user });
|
||||
if (skarray.Length > 0)
|
||||
return skarray[0];
|
||||
}
|
||||
return new StringKeyValue();
|
||||
}
|
||||
|
||||
public static byte[] GetAttachFileData(string attachID, out string fileName)
|
||||
{
|
||||
string SQL = "select FILENAME,ATTACHDATA from ATTACHES where ATTACHID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, attachID);
|
||||
byte[] fileData = Foresight.Data.FIDbAccess.GetFieldBytes(dt.Rows[0]["ATTACHDATA"]);
|
||||
fileName = Foresight.Data.FIDbAccess.GetFieldString(dt.Rows[0]["FILENAME"], "");
|
||||
return fileData;
|
||||
}
|
||||
|
||||
public static void SaveAttach(string refid, string username, string[] attachids, string source)
|
||||
{
|
||||
if (attachids != null)
|
||||
{
|
||||
foreach (string attaid in attachids)
|
||||
{
|
||||
string sql = "update ATTACHES set REFID={1},ADDEDBY={2},SOURCE={3} where ATTACHID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(sql, attaid, refid, username, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string AddAttachment(string fileName, byte[] fileData)
|
||||
{
|
||||
string attachID = Guid.NewGuid().ToString().ToUpper();
|
||||
string sql = "insert into ATTACHES (ATTACHID,FILENAME,ATTACHDATA,ADDEDON_UTC) values({0},{1},{2},getutcdate())";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(sql, attachID, fileName, fileData);
|
||||
|
||||
DeleteTimeoutTempAttach();
|
||||
return attachID;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据附件ID删除附件,主要用于页面上单独删除某一附件
|
||||
/// </summary>
|
||||
/// <param name="attachid"></param>
|
||||
public static void DeleteAttachment(string attachid)
|
||||
{
|
||||
string sql = "DELETE FROM ATTACHES WHERE ATTACHID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
|
||||
DeleteTimeoutTempAttach();
|
||||
db.ExecSQL(sql, attachid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="refids"></param>
|
||||
public void DeleteAttachments(string[] refids)
|
||||
{
|
||||
if (refids.Length > 0)
|
||||
{
|
||||
string publicsolutionIDs = string.Empty;
|
||||
foreach (string s in refids)
|
||||
{
|
||||
publicsolutionIDs += "'" + s + "',";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(publicsolutionIDs))
|
||||
{
|
||||
publicsolutionIDs = publicsolutionIDs.Substring(0, publicsolutionIDs.Length - 1);
|
||||
}
|
||||
string deletepublic = string.Format("delete from ATTACHES where REFID in ({0})", publicsolutionIDs);
|
||||
var db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(deletepublic);
|
||||
}
|
||||
}
|
||||
|
||||
private static StringKeyValue[] ConvertToSKarray(DataTable dt, IEnumerable<Contractor.Users.UserInfo> users)
|
||||
{
|
||||
List<StringKeyValue> sklist = new List<StringKeyValue>();
|
||||
StringKeyValue sk = null;
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
sk = new StringKeyValue();
|
||||
sk.Key = FIDbAccess.GetFieldString(row["ATTACHID"], string.Empty);
|
||||
sk.Tag1 = FIDbAccess.GetFieldString(row["FILENAME"], string.Empty);
|
||||
|
||||
string addBy = FIDbAccess.GetFieldString(row["ADDEDBY"], string.Empty);
|
||||
if (users != null)
|
||||
{
|
||||
Guid uiid;
|
||||
if (Guid.TryParse(addBy, out uiid))
|
||||
{
|
||||
var user = users.FirstOrDefault((u) => string.Compare(u.IID, addBy, true) == 0);
|
||||
if (user != null)
|
||||
addBy = user.DisplayName;
|
||||
else
|
||||
addBy = "";
|
||||
}
|
||||
}
|
||||
string createInfo = " Add by " + addBy;
|
||||
sk.Tag2 = createInfo;
|
||||
DateTime time = FIDbAccess.GetFieldDateTime(row["ADDEDON_UTC"], DateTime.MinValue);
|
||||
time = time.ToLocalTime();
|
||||
sk.Tag3 = time.ToString();
|
||||
sklist.Add(sk);
|
||||
}
|
||||
return sklist.OrderBy(s => s.Tag3).ToArray();
|
||||
}
|
||||
|
||||
private static void DeleteTimeoutTempAttach()
|
||||
{
|
||||
string sql = "DELETE from ATTACHES where REFID IS NULL AND DATEDIFF(HOUR,ADDEDON_UTC,GETUTCDATE())>23";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(sql);
|
||||
}
|
||||
|
||||
public static AttachmentItem GetAttachment(string sessionid, string custid, long attid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(custid))
|
||||
custid = SystemParams.CompanyID;
|
||||
Foresight.Fleet.Services.Attachment.AttachmentInfo att = FleetServiceClientHelper.CreateClient<AttachmentClient>(custid, sessionid).GetAttachment(custid, attid);
|
||||
AttachmentItem item = new AttachmentItem();
|
||||
Helper.CloneProperty(item, att);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static AttachmentItem GetAttachmentLegacy(string sessionid, string custid, string attid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(custid))
|
||||
custid = SystemParams.CompanyID;
|
||||
Foresight.Fleet.Services.Attachment.AttachmentInfo att = FleetServiceClientHelper.CreateClient<AttachmentClient>(custid, sessionid).GetAttachmentLegacy(custid, attid);
|
||||
AttachmentItem item = new AttachmentItem();
|
||||
Helper.CloneProperty(item, att);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
public class AttachmentType
|
||||
{
|
||||
public const string MaintenanceLog = "MaintenanceLog";
|
||||
public const string WorkOrder = "WorkOrder";
|
||||
}
|
||||
}
|
108
IronIntelContractorBusiness/BusinessBase.cs
Normal file
108
IronIntelContractorBusiness/BusinessBase.cs
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BusinessBase
|
||||
{
|
||||
public static string NewID()
|
||||
{
|
||||
return Guid.NewGuid().ToString().ToUpper();
|
||||
}
|
||||
|
||||
public static decimal? NegativeToNull(decimal v)
|
||||
{
|
||||
if (v < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static double? NegativeToNull(double v)
|
||||
{
|
||||
if (v < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public static int? NegativeToNull(int v)
|
||||
{
|
||||
if (v < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public string DbConnectionString { get; private set; }
|
||||
public BusinessBase(string dbstr)
|
||||
{
|
||||
DbConnectionString = dbstr;
|
||||
}
|
||||
|
||||
public static void ExecSQL(FIDbAccess db,int retrytimes,string sql, params object[] values)
|
||||
{
|
||||
int n = 0;
|
||||
while (true)
|
||||
{
|
||||
n++;
|
||||
try
|
||||
{
|
||||
db.ExecSQL(sql, values);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (n >= retrytimes)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ExecSQL(string sql, params object[] values)
|
||||
{
|
||||
FISqlConnection db = new FISqlConnection(DbConnectionString);
|
||||
db.ExecSQL(sql, values);
|
||||
}
|
||||
|
||||
protected DataTable GetDataTableBySQL(string sql, params object[] values)
|
||||
{
|
||||
FISqlConnection db = new FISqlConnection(DbConnectionString);
|
||||
db.CommandTimeout = 120;
|
||||
return db.GetDataTableBySQL(sql, values);
|
||||
}
|
||||
|
||||
protected object GetRC1BySQL(string sql, params object[] values)
|
||||
{
|
||||
FISqlConnection db = new FISqlConnection(DbConnectionString);
|
||||
return db.GetRC1BySQL(sql, values);
|
||||
}
|
||||
|
||||
protected FISqlTransaction BeginTransaction()
|
||||
{
|
||||
return new FISqlTransaction(DbConnectionString);
|
||||
}
|
||||
}
|
||||
}
|
161
IronIntelContractorBusiness/CacheManager.cs
Normal file
161
IronIntelContractorBusiness/CacheManager.cs
Normal file
@ -0,0 +1,161 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Foresight.Cache;
|
||||
using Foresight.Cache.AspNet;
|
||||
using Foresight.Cache.Redis;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public static class CacheManager
|
||||
{
|
||||
public static void Dispose()
|
||||
{
|
||||
if (_Client != null)
|
||||
{
|
||||
_Client.Dispose();
|
||||
_Client = null;
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient _Client = null;
|
||||
private static object _sycobj = new object();
|
||||
|
||||
private static FIRedisCacheClient CreateRedisClient()
|
||||
{
|
||||
string[] servers = FleetServiceClientHelper.CreateClient<Foresight.Fleet.Services.SystemUtil>().GetRedisServers();
|
||||
if ((servers == null) || (servers.Length == 0))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<RedisNode> ls = new List<RedisNode>();
|
||||
foreach (string srv in servers)
|
||||
{
|
||||
try
|
||||
{
|
||||
RedisNode node = CreateRedisNode(srv);
|
||||
ls.Add(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SystemParams.WriteLog("Error", typeof(CacheManager).FullName + ".CreateRedisClient", "Create RedisNode failed: " + srv, ex.ToString());
|
||||
}
|
||||
}
|
||||
if (ls.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FIRedisCacheClient("IRONINTEL_" + SystemParams.CompanyID.ToUpper(), ls);
|
||||
}
|
||||
}
|
||||
|
||||
private static RedisNode CreateRedisNode(string server)
|
||||
{
|
||||
string[] address = server.Split(new char[] { ':' });
|
||||
int port = -1;
|
||||
if (!int.TryParse(address[1], out port))
|
||||
{
|
||||
port = -1;
|
||||
}
|
||||
int weight = 100;
|
||||
if (!int.TryParse(address[2], out weight))
|
||||
{
|
||||
weight = 100;
|
||||
}
|
||||
RedisNode node = new RedisNode(address[0], port, weight);
|
||||
return node;
|
||||
}
|
||||
|
||||
private static void InitCacheClient()
|
||||
{
|
||||
FIRedisCacheClient fc = null;
|
||||
try
|
||||
{
|
||||
fc = CreateRedisClient();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SystemParams.WriteLog("Error", typeof(CacheManager).FullName + ".InitCacheClient", "Create Redis client failed", ex.ToString());
|
||||
}
|
||||
if (fc != null)
|
||||
{
|
||||
_Client = fc;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Client = new AspNetCacheManager("IRONINTEL_" + SystemParams.CompanyID.ToUpper());
|
||||
}
|
||||
}
|
||||
|
||||
private static CacheClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
lock (_sycobj)
|
||||
{
|
||||
if (_Client == null)
|
||||
{
|
||||
InitCacheClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
return _Client;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Remove(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.Remove(key);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetValue(string key, byte[] buffer, TimeSpan expire)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
Remove(key);
|
||||
}
|
||||
else if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
Client.SetValue(key, buffer, expire);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetValue(string key)
|
||||
{
|
||||
if (Client != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Client.GetValue(key);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
23
IronIntelContractorBusiness/Contact/ContactInfo.cs
Normal file
23
IronIntelContractorBusiness/Contact/ContactInfo.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Contact
|
||||
{
|
||||
public class ContactInfo
|
||||
{
|
||||
public string ContactID { get; set; }
|
||||
public string ContactName { get; set; }
|
||||
public string UserIID { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string ContactType { get; set; }
|
||||
public string EmailAddress { get; set; }
|
||||
public string TextAddress { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public bool Text { get; set; }
|
||||
public bool Email { get; set; }
|
||||
}
|
||||
|
||||
}
|
292
IronIntelContractorBusiness/Contact/ContactManagement.cs
Normal file
292
IronIntelContractorBusiness/Contact/ContactManagement.cs
Normal file
@ -0,0 +1,292 @@
|
||||
using Foresight.Data;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Contractor.Maintenance;
|
||||
using IronIntel.Contractor.MapView;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using IronIntel.Services.Customers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Contact
|
||||
{
|
||||
public class ContactManagement
|
||||
{
|
||||
public static ContactInfo[] GetContacts(string sessionid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = "select CONTACTID,CONTACTNAME,USERIID,NOTES,CONTACTTYPE,EMAILADDRESS,TEXTADDRESS from CONTACT";
|
||||
|
||||
List<ContactInfo> list = new List<ContactInfo>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
UserInfo[] users = UserManagement.GetUsers();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
ContactInfo ci = ConvertToContactInfo(dr);
|
||||
if (!string.IsNullOrWhiteSpace(ci.UserIID))
|
||||
{
|
||||
UserInfo ui = users.FirstOrDefault(m => m.IID == ci.UserIID);
|
||||
if (ui != null)
|
||||
ci.UserName = ui.DisplayName;
|
||||
}
|
||||
list.Add(ci);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public static void SaveContact(ContactInfo ci, string useriid)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from CONTACT where CONTACTID={0}) update CONTACT set CONTACTNAME={1},USERIID={2},NOTES={3},LASTUPDATEDBY={4},
|
||||
LASTUPDATEDON = GETUTCDATE(),RECVER = ISNULL(RECVER,0) + 1,CONTACTTYPE={5},EMAILADDRESS={6},TEXTADDRESS={7} where CONTACTID={0} else insert CONTACT(CONTACTID,CONTACTNAME,USERIID, NOTES, ADDEDBY,
|
||||
ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,RECVER,CONTACTTYPE,EMAILADDRESS,TEXTADDRESS) values({0},{1},{2},{3},{4},GETUTCDATE(),{4},GETUTCDATE(),1,{5},{6},{7})";
|
||||
|
||||
const string SQL_C = "select COUNT(1) from CONTACT where CONTACTID!={0} and CONTACTNAME={1}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL_C, ci.ContactID, ci.ContactName);
|
||||
if (Convert.ToInt32(obj) > 0)
|
||||
{
|
||||
throw new Exception("The contact name must be unique.");
|
||||
}
|
||||
|
||||
db.ExecSQL(SQL, ci.ContactID, ci.ContactName, ci.UserIID, ci.Notes, useriid, ci.ContactType, ci.EmailAddress, ci.TextAddress);
|
||||
|
||||
}
|
||||
|
||||
public static void DeleteContact(string contactid)
|
||||
{
|
||||
const string SQL = @"delete from CONTACT where CONTACTID={0}
|
||||
delete from RELATIONSHIP where PRIMARYID = {0} and (RELATIONSHIPTYPEID='MachineContact' or RELATIONSHIPTYPEID='ContactJobsite') ";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, contactid);
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetContactMachinesByID(string contactid)
|
||||
{
|
||||
const string SQL = @"select a.RELATEDID as MACHINEID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,b.HIDE,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(b.ODOMETER,0) as ODOMETER,ISNULL(b.ODOMETERUOM,'Mile') AS ODOMETERUOM from RELATIONSHIP a,MACHINES b
|
||||
where a.RELATEDID=b.MACHINEID and a.RELATIONSHIPTYPEID='MachineContact' and a.REMOVED<>1 and a.PRIMARYID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, contactid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MaintenanceMachineInfo mi = MaintenanceManagement.ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public static void SaveContactMachines(string contactid, string contractorid, string[] machineids)
|
||||
{
|
||||
const string SQL_R = "update RELATIONSHIP set REMOVEDON=GETUTCDATE(),REMOVED=1 where RELATIONSHIPTYPEID='MachineContact' and REMOVED<>1 and PRIMARYID={0}";
|
||||
const string SQL = @"if exists(select 1 from RELATIONSHIP where RELATIONSHIPTYPEID='MachineContact' and PRIMARYID={0} and RELATEDID={1}) update RELATIONSHIP
|
||||
set REMOVEDON=null,REMOVED=0 where RELATIONSHIPTYPEID='MachineContact' and PRIMARYID={0} and RELATEDID={1} else insert into RELATIONSHIP
|
||||
(RELATIONSHIPID,RELATIONSHIPTYPEID,CONTRACTORID,PRIMARYID,RELATEDID,ADDEDON) values({3},'MachineContact',{2},{0},{1},GETUTCDATE())";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_R, contactid);
|
||||
|
||||
foreach (var mid in machineids)
|
||||
{
|
||||
db.ExecSQL(SQL, contactid, mid, contractorid, Guid.NewGuid().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveMachineContacts(FISqlConnection db, string machineid, string contractorid, string[] contactids)
|
||||
{
|
||||
const string SQL_R = "update RELATIONSHIP set REMOVEDON=GETUTCDATE(),REMOVED=1 where RELATIONSHIPTYPEID='MachineContact' and REMOVED<>1 and RELATEDID={0}";
|
||||
const string SQL = @"if exists(select 1 from RELATIONSHIP where RELATIONSHIPTYPEID='MachineContact' and RELATEDID={0} and PRIMARYID={1}) update RELATIONSHIP
|
||||
set REMOVEDON=null,REMOVED=0 where RELATIONSHIPTYPEID='MachineContact' and RELATEDID={0} and PRIMARYID={1} else insert into RELATIONSHIP
|
||||
(RELATIONSHIPID,RELATIONSHIPTYPEID,CONTRACTORID,RELATEDID,PRIMARYID,ADDEDON) values({3},'MachineContact',{2},{0},{1},GETUTCDATE())";
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_R, machineid);
|
||||
|
||||
foreach (var cid in contactids)
|
||||
{
|
||||
db.ExecSQL(SQL, machineid, cid, contractorid, Guid.NewGuid().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ContactInfo ConvertToContactInfo(DataRow dr)
|
||||
{
|
||||
ContactInfo ci = new ContactInfo();
|
||||
ci.ContactID = FIDbAccess.GetFieldString(dr["CONTACTID"], string.Empty);
|
||||
ci.ContactName = FIDbAccess.GetFieldString(dr["CONTACTNAME"], string.Empty);
|
||||
ci.UserIID = FIDbAccess.GetFieldString(dr["USERIID"], string.Empty);
|
||||
ci.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
ci.ContactType = FIDbAccess.GetFieldString(dr["CONTACTTYPE"], string.Empty);
|
||||
ci.EmailAddress = FIDbAccess.GetFieldString(dr["EMAILADDRESS"], string.Empty);
|
||||
ci.TextAddress = FIDbAccess.GetFieldString(dr["TEXTADDRESS"], string.Empty);
|
||||
return ci;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JobSiteViewItem[] GetContactJobsitesByID(string contactid)
|
||||
{
|
||||
const string SQL = @"select a.RELATEDID as JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE,RADIUS,RADUIS_UOM,b.CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON,BASEONMACHINEID from RELATIONSHIP a,JOBSITES b
|
||||
where a.RELATIONSHIPTYPEID='ContactJobsite' and a.REMOVED<>1 and a.RELATEDID=b.JOBSITEID and a.PRIMARYID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, contactid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new JobSiteViewItem[0];
|
||||
}
|
||||
List<JobSiteViewItem> ls = new List<JobSiteViewItem>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
JobSiteViewItem js = ConvertToJobSiteViewItem(dr);
|
||||
ls.Add(js);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public static void SaveContactJobsites(string contactid, string contractorid, string[] jobsiteids)
|
||||
{
|
||||
const string SQL_R = "update RELATIONSHIP set REMOVEDON=GETUTCDATE(),REMOVED=1 where RELATIONSHIPTYPEID='ContactJobsite' and REMOVED<>1 and PRIMARYID={0}";
|
||||
const string SQL = @"if exists(select 1 from RELATIONSHIP where RELATIONSHIPTYPEID='ContactJobsite' and PRIMARYID={0} and RELATEDID={1}) update RELATIONSHIP
|
||||
set REMOVEDON=null,REMOVED=0 where RELATIONSHIPTYPEID='ContactJobsite' and PRIMARYID={0} and RELATEDID={1} else insert into RELATIONSHIP
|
||||
(RELATIONSHIPID,RELATIONSHIPTYPEID,CONTRACTORID,PRIMARYID,RELATEDID,ADDEDON) values({3},'ContactJobsite',{2},{0},{1},GETUTCDATE())";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_R, contactid);
|
||||
|
||||
foreach (var mid in jobsiteids)
|
||||
{
|
||||
db.ExecSQL(SQL, contactid, mid, contractorid, Guid.NewGuid().ToString());
|
||||
}
|
||||
}
|
||||
private static JobSiteViewItem ConvertToJobSiteViewItem(DataRow dr)
|
||||
{
|
||||
JobSiteViewItem js = new JobSiteViewItem();
|
||||
long JobSiteId = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.ID = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.Name = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
js.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
js.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
js.Radius = FIDbAccess.GetFieldDouble(dr["RADIUS"], 0);
|
||||
js.Radius_UOM = FIDbAccess.GetFieldString(dr["RADUIS_UOM"], string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(js.Radius_UOM))
|
||||
js.Radius_UOM = "Mile";
|
||||
js.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
//js.ColorString = FIDbAccess.GetFieldString(dr["COLOR"], string.Empty);
|
||||
//System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
//try
|
||||
//{
|
||||
// color = System.Drawing.ColorTranslator.FromHtml(js.ColorString);
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
//}
|
||||
//js.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
|
||||
js.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
js.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
js.EndDate = FIDbAccess.GetFieldDateTime(dr["ENDDATE"], DateTime.MinValue);
|
||||
js.BaseOnMachineID = FIDbAccess.GetFieldInt(dr["BASEONMACHINEID"], 0);
|
||||
return js;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器Contact和机器的对应关系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<int, List<string>> GetContactMachines(FISqlConnection db)
|
||||
{
|
||||
const string SQL_C = "select PRIMARYID,RELATEDID from RELATIONSHIP where RELATIONSHIPTYPEID='MachineContact' and REMOVED<>1";
|
||||
|
||||
Dictionary<int, List<string>> result = new Dictionary<int, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C);
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["RELATEDID"], 0);
|
||||
string contactid = FIDbAccess.GetFieldString(dr["PRIMARYID"], "");
|
||||
if (!result.ContainsKey(machineid))
|
||||
result[machineid] = new List<string>();
|
||||
result[machineid].Add(contactid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器对应的ContactID
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string[] GetContactByMachineID(FISqlConnection db, long machineid)
|
||||
{
|
||||
const string SQL_C = "select PRIMARYID from RELATIONSHIP where RELATIONSHIPTYPEID='MachineContact' and REMOVED<>1 and RELATEDID={0}";
|
||||
|
||||
Dictionary<int, List<string>> result = new Dictionary<int, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C, machineid);
|
||||
if (tb.Rows.Count <= 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
string contactid = FIDbAccess.GetFieldString(dr["PRIMARYID"], "");
|
||||
list.Add(contactid);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public static ContactInfo[] GetContactByAssetID(long assetid, string companyid)
|
||||
{
|
||||
const string SQL = @"select CONTACTID,CONTACTNAME,USERIID,NOTES,CONTACTTYPE,EMAILADDRESS,TEXTADDRESS from CONTACT where
|
||||
CONTACTID in(select PRIMARYID from RELATIONSHIP where RELATIONSHIPTYPEID='MachineContact' and REMOVED<>1 and RELATEDID={0} union all
|
||||
select rs.PRIMARYID from RELATIONSHIP rs left join JOBSITEMACHINES jm on rs.RELATEDID=jm.JOBSITEID where rs.RELATIONSHIPTYPEID='ContactJobsite' and rs.REMOVED<>1 and jm.MACHINEID={0})";
|
||||
|
||||
FISqlConnection db = null;
|
||||
if (string.IsNullOrWhiteSpace(companyid))
|
||||
db = SystemParams.GetDbInstance();
|
||||
else
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
|
||||
List<ContactInfo> list = new List<ContactInfo>();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, assetid);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
ContactInfo ci = ConvertToContactInfo(dr);
|
||||
list.Add(ci);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
29
IronIntelContractorBusiness/Device/GpsDeviceItem.cs
Normal file
29
IronIntelContractorBusiness/Device/GpsDeviceItem.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Device
|
||||
{
|
||||
public class GpsDeviceItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string SN { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string SourceName { get; set; }
|
||||
public string DeviceType { get; set; }
|
||||
public int Status { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public string ContractorID { get; set; }
|
||||
public string Contractor { get; set; }
|
||||
public string InvoiceNumber { get; set; }
|
||||
public DateTime AddDate { get; set; }
|
||||
public string AddDateStr { get { return AddDate == DateTime.MinValue ? "" : AddDate.ToShortDateString(); } }
|
||||
public DateTime? InvoiceDate { get; set; }
|
||||
public string InvoiceDateStr { get { return InvoiceDate == null ? "" : InvoiceDate.Value.ToShortDateString(); } }
|
||||
public DateTime? ServiceStartDate { get; set; }
|
||||
public string ServiceStartDateStr { get { return ServiceStartDate == null ? "" : ServiceStartDate.Value.ToShortDateString(); } }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
220
IronIntelContractorBusiness/ExportExcel/ConvertFormat.cs
Normal file
220
IronIntelContractorBusiness/ExportExcel/ConvertFormat.cs
Normal file
@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class ConvertFormat
|
||||
{
|
||||
/// <summary>
|
||||
/// 本函数将c#格式转换为excel格式,在转换时只允许一个格式中出现{0}或{0:xxx}之类的一次,多余的抛弃。
|
||||
/// </summary>
|
||||
/// <param name="csharpFormat"></param>
|
||||
/// <returns></returns>
|
||||
public static string ConvertFormatFromCSharpToExcel(string csharpFormat, CellDataType DataType)
|
||||
{
|
||||
if (string.IsNullOrEmpty(csharpFormat)) return "";
|
||||
|
||||
#region 验证格式是否合格。
|
||||
switch (DataType)
|
||||
{
|
||||
case CellDataType.Bool:
|
||||
if (!string.IsNullOrEmpty(csharpFormat))
|
||||
{
|
||||
string[] fors = csharpFormat.Split(';');
|
||||
csharpFormat = "\"" + string.Join("\";\"", fors.ToArray()) + "\"";
|
||||
if (fors.Length == 2)
|
||||
{
|
||||
csharpFormat = csharpFormat + ";" + "\"" + fors[1] + "\"";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CellDataType.Date:
|
||||
try
|
||||
{
|
||||
string.Format(csharpFormat, DateTime.Now);
|
||||
}
|
||||
catch
|
||||
{
|
||||
csharpFormat = "";
|
||||
}
|
||||
break;
|
||||
case CellDataType.Guid:
|
||||
break;
|
||||
case CellDataType.Integer:
|
||||
try
|
||||
{
|
||||
string.Format(csharpFormat, 1234);
|
||||
}
|
||||
catch
|
||||
{
|
||||
csharpFormat = "";
|
||||
}
|
||||
break;
|
||||
case CellDataType.Float:
|
||||
try
|
||||
{
|
||||
string.Format(csharpFormat, 1234.567890);
|
||||
}
|
||||
catch
|
||||
{
|
||||
csharpFormat = "";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endregion
|
||||
|
||||
string cshxp = csharpFormat;
|
||||
string excelFormat = "";
|
||||
string pattern = @"\{0\}|\{0:[^\}]+\}";
|
||||
Regex reg = new Regex(pattern);
|
||||
MatchCollection mc = reg.Matches(csharpFormat);
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
//将多余的格式串去掉。
|
||||
for (int i = 1; i < mc.Count; i++)
|
||||
{
|
||||
cshxp = cshxp.Replace(mc[i].Value, "");
|
||||
}
|
||||
|
||||
if (string.Equals(mc[0].Value, "{0}", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
int first = cshxp.IndexOf(mc[0].Value);
|
||||
|
||||
//当格式为{0}时,设置FIC需要的默认格式。
|
||||
string ft = "General";
|
||||
if (DataType == CellDataType.Float)
|
||||
{
|
||||
ft = "0.00";
|
||||
}
|
||||
else if (DataType == CellDataType.Integer)
|
||||
{
|
||||
ft = "0";
|
||||
}
|
||||
else if (DataType == CellDataType.Date)
|
||||
{
|
||||
ft = "MM-dd-yyyy";
|
||||
}
|
||||
else if (DataType == CellDataType.Bool)
|
||||
{
|
||||
ft = "True\";\"False\";\"False";
|
||||
}
|
||||
|
||||
excelFormat = "\"" + cshxp.Substring(0, first) + "\"" + ft + "\"" + cshxp.Substring(first + 3) + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
int first = cshxp.IndexOf(mc[0].Value);
|
||||
string format = mc[0].Value.Replace("{0:", "");
|
||||
format = format.Replace("}", "");
|
||||
|
||||
string[] strs = format.Split(';');
|
||||
string preText = cshxp.Substring(0, first);
|
||||
string postText = cshxp.Substring(first + mc[0].Value.Length);
|
||||
|
||||
string str2 = "";
|
||||
foreach (string str in strs)
|
||||
{
|
||||
str2 = str;
|
||||
if (DataType == CellDataType.Date)
|
||||
{
|
||||
str2 = ConvertSpecialDateFormat(str);
|
||||
}
|
||||
if (string.IsNullOrEmpty(excelFormat))
|
||||
{
|
||||
excelFormat = "\"" + preText + "\"" + str2 + "\"" + postText + "\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
string tmpFormat = "\"" + preText + "\"" + str2 + "\"" + postText + "\"";
|
||||
excelFormat = excelFormat + ";" + tmpFormat;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
excelFormat = cshxp;
|
||||
}
|
||||
|
||||
return excelFormat;
|
||||
}
|
||||
|
||||
private static string ConvertSpecialDateFormat(string format)
|
||||
{
|
||||
string result = format;
|
||||
//AM/PM:tt
|
||||
result = result.Replace("tt", "AM/PM");
|
||||
|
||||
//fff:
|
||||
string pattern = @"\.f+";
|
||||
Regex reg = new Regex(pattern);
|
||||
MatchCollection mc = reg.Matches(result);
|
||||
foreach (Match mt in mc)
|
||||
{
|
||||
if (mt.Value == null) continue;
|
||||
|
||||
string x0 = "";
|
||||
int num = mt.Value.Substring(1).Length;
|
||||
while (num > 0)
|
||||
{
|
||||
x0 += "0";
|
||||
num--;
|
||||
}
|
||||
result = result.Replace(mt.Value, "." + x0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool CheckIfCSharpFormatIsValid(string format)
|
||||
{
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
FormatDouble(format);
|
||||
return true; ;
|
||||
}
|
||||
catch { }
|
||||
|
||||
try
|
||||
{
|
||||
FormatDateTime(format);
|
||||
return true; ;
|
||||
}
|
||||
catch { }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void FormatDouble(string format)
|
||||
{
|
||||
double x = 12345.7890;
|
||||
try
|
||||
{
|
||||
string.Format(format, x);
|
||||
}
|
||||
catch
|
||||
{
|
||||
x.ToString(format);
|
||||
}
|
||||
}
|
||||
|
||||
private static void FormatDateTime(string format)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
try
|
||||
{
|
||||
string.Format(format, now);
|
||||
}
|
||||
catch
|
||||
{
|
||||
now.ToString(format);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
844
IronIntelContractorBusiness/ExportExcel/ExcelXlsx.cs
Normal file
844
IronIntelContractorBusiness/ExportExcel/ExcelXlsx.cs
Normal file
@ -0,0 +1,844 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using Ap = DocumentFormat.OpenXml.ExtendedProperties;
|
||||
using Vt = DocumentFormat.OpenXml.VariantTypes;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using A = DocumentFormat.OpenXml.Drawing;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
internal class ExcelXlsx
|
||||
{
|
||||
public ExcelXlsx() { }
|
||||
|
||||
private Dictionary<string, UInt32Value> _fontIndexCache = new Dictionary<string, UInt32Value>();
|
||||
private Dictionary<string, UInt32Value> _fillIndexCache = new Dictionary<string, UInt32Value>();
|
||||
private Dictionary<string, UInt32Value> _borderIndexCache = new Dictionary<string, UInt32Value>();
|
||||
private Dictionary<string, UInt32Value> _formatIndexCache = new Dictionary<string, UInt32Value>();
|
||||
|
||||
// Creates a SpreadsheetDocument.
|
||||
public void CreatePackage(MemoryStream ms, COpenXmlExcelSheet edata)
|
||||
{
|
||||
using (SpreadsheetDocument package = SpreadsheetDocument.Create(ms, SpreadsheetDocumentType.Workbook))
|
||||
{
|
||||
CExcelSheet excelSheetData = ConvertData(edata);
|
||||
CreateParts(package, excelSheetData);
|
||||
}
|
||||
}
|
||||
|
||||
private CExcelSheet ConvertData(COpenXmlExcelSheet openXmlData)
|
||||
{
|
||||
CExcelSheet excelSheetData = new CExcelSheet();
|
||||
|
||||
//保存每列宽度。
|
||||
foreach (double width in openXmlData.WidthList)
|
||||
{
|
||||
excelSheetData.WidthList.Add(width);
|
||||
}
|
||||
|
||||
//保存每行高度。
|
||||
foreach (KeyValuePair<int, double> kvp in openXmlData.RowHeightList)
|
||||
{
|
||||
excelSheetData.RowHeightList.Add(kvp.Key, kvp.Value);
|
||||
}
|
||||
|
||||
CExcelCellData excellData = null;
|
||||
|
||||
//生成特定样式数据,并生成shared strings列表,合并单元格列表。
|
||||
int orderIndex = 0;
|
||||
foreach (List<IOpenXmlExcelStyleAndData> rowData in openXmlData.DataMatrix)
|
||||
{
|
||||
List<CExcelCellData> excelRowData = new List<CExcelCellData>();
|
||||
foreach (IOpenXmlExcelStyleAndData cellData in rowData)
|
||||
{
|
||||
excellData = new CExcelCellData();
|
||||
excelRowData.Add(excellData);
|
||||
|
||||
excellData.ApplyNumberFormat = DocumentFormat.OpenXml.BooleanValue.FromBoolean(true);
|
||||
excellData.CAlignment = cellData.CAlignment;
|
||||
excellData.CBorder = cellData.CBorder;
|
||||
excellData.CFill = cellData.CFill;
|
||||
excellData.CFont = cellData.CFont;
|
||||
|
||||
if (cellData.FormatType == CellFormatType.CSharp)
|
||||
{
|
||||
bool b = false;
|
||||
if (cellData.FormatCode != null && cellData.FormatCode.Contains("{0:MMM-yyyy}"))
|
||||
{
|
||||
b = true;
|
||||
}
|
||||
excellData.FormatCode = ConvertFormat.ConvertFormatFromCSharpToExcel(cellData.FormatCode, cellData.DataType);
|
||||
if (cellData.DataType == CellDataType.String || cellData.DataType == CellDataType.Integer)
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
if (cellData.Value != null && cellData.Value.ToString().Length != 6)
|
||||
{
|
||||
excellData.FormatCode = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(excellData.FormatCode))
|
||||
{
|
||||
excellData.Value = orderIndex;
|
||||
orderIndex++;
|
||||
excelSheetData.SharedStrings.Add(cellData.Value == null ? "" : cellData.Value.ToString());
|
||||
excellData.DataType = CellValues.SharedString;
|
||||
excellData.FormatCode = "";
|
||||
excellData.NumberFormatId = 49U;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (cellData.DataType)
|
||||
{
|
||||
case CellDataType.Bool:
|
||||
try
|
||||
{
|
||||
|
||||
int v = 0;// Convert.ToInt16(cellData.Value);
|
||||
if (cellData.Value == null || cellData.Value.ToString() == "0" ||
|
||||
string.Equals(cellData.Value.ToString(), "false", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
v = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = 1;
|
||||
}
|
||||
|
||||
excellData.Value = v;
|
||||
excellData.DataType = CellValues.Number;
|
||||
}
|
||||
catch { }
|
||||
break;
|
||||
case CellDataType.Date:
|
||||
try
|
||||
{
|
||||
excellData.Value = Convert.ToDateTime(cellData.Value).ToOADate();
|
||||
excellData.DataType = CellValues.Number;
|
||||
}
|
||||
catch { }
|
||||
break;
|
||||
case CellDataType.Float:
|
||||
case CellDataType.Integer:
|
||||
excellData.Value = cellData.Value;
|
||||
excellData.DataType = CellValues.Number;
|
||||
break;
|
||||
default:
|
||||
//excellData.Value = orderIndex;
|
||||
//orderIndex++;
|
||||
//excelSheetData.SharedStrings.Add(cellData.Value == null ? "" : cellData.Value.ToString());
|
||||
//excellData.DataType = CellValues.SharedString;
|
||||
excellData.Value = (cellData.Value == null ? "" : cellData.Value.ToString());
|
||||
excellData.DataType = CellValues.String;
|
||||
excellData.FormatCode = "";
|
||||
excellData.NumberFormatId = 49U;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region 合并单元格还没处理好。
|
||||
if (!string.IsNullOrEmpty(cellData.MergedCellsPosition))
|
||||
{
|
||||
excelSheetData.MergeCellReferenceList.Add(cellData.MergedCellsPosition);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
excelSheetData.DataMatrix.Add(excelRowData);
|
||||
}
|
||||
|
||||
return excelSheetData;
|
||||
}
|
||||
|
||||
// Adds child parts and generates content of the specified part.
|
||||
private void CreateParts(SpreadsheetDocument document, CExcelSheet excelSheetData)
|
||||
{
|
||||
WorkbookPart workbookPart = document.AddWorkbookPart();
|
||||
GenerateWorkbookPart1Content(workbookPart);
|
||||
|
||||
WorkbookStylesPart workbookStylesPart = workbookPart.AddNewPart<WorkbookStylesPart>("rId3");
|
||||
GenerateWorkbookStylesPart1Content(workbookStylesPart);
|
||||
|
||||
WorksheetPart worksheetPart = workbookPart.AddNewPart<WorksheetPart>("rId1");
|
||||
GenerateWorksheetPart1Content(worksheetPart);
|
||||
|
||||
#region columns
|
||||
Columns columns = GenerateColumns(excelSheetData.WidthList);
|
||||
worksheetPart.Worksheet.Append(columns);
|
||||
#endregion
|
||||
|
||||
#region sheet data
|
||||
SheetData sheetData = GenerateSheetData(workbookStylesPart.Stylesheet, excelSheetData);
|
||||
worksheetPart.Worksheet.Append(sheetData);
|
||||
#endregion
|
||||
|
||||
#region sheet merge cells
|
||||
if (excelSheetData.MergeCellReferenceList.Count > 0)
|
||||
{
|
||||
MergeCells mergeCells = GenerateMergeCell(excelSheetData.MergeCellReferenceList);
|
||||
worksheetPart.Worksheet.Append(mergeCells);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region sheet shared strings
|
||||
if (excelSheetData.SharedStrings.Count > 0)
|
||||
{
|
||||
SharedStringTablePart sharedStringTablePart = workbookPart.AddNewPart<SharedStringTablePart>("rId4");
|
||||
GenerateSharedStringTablePart1Content(sharedStringTablePart, excelSheetData.SharedStrings);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
// Generates content of workbookPart1.
|
||||
private void GenerateWorkbookPart1Content(WorkbookPart workbookPart1)
|
||||
{
|
||||
Workbook workbook1 = new Workbook();
|
||||
workbook1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
|
||||
FileVersion fileVersion1 = new FileVersion() { ApplicationName = "xl", LastEdited = "4", LowestEdited = "4", BuildVersion = "4505" };
|
||||
WorkbookProperties workbookProperties1 = new WorkbookProperties() { DefaultThemeVersion = (UInt32Value)124226U };
|
||||
|
||||
BookViews bookViews1 = new BookViews();
|
||||
WorkbookView workbookView1 = new WorkbookView() { XWindow = 120, YWindow = 120, WindowWidth = (UInt32Value)21495U, WindowHeight = (UInt32Value)9570U };
|
||||
|
||||
bookViews1.Append(workbookView1);
|
||||
|
||||
Sheets sheets1 = new Sheets();
|
||||
Sheet sheet1 = new Sheet() { Name = "Sheet1", SheetId = (UInt32Value)1U, Id = "rId1" };
|
||||
|
||||
sheets1.Append(sheet1);
|
||||
CalculationProperties calculationProperties1 = new CalculationProperties() { CalculationId = (UInt32Value)125725U };
|
||||
FileRecoveryProperties fileRecoveryProperties1 = new FileRecoveryProperties() { RepairLoad = true };
|
||||
|
||||
workbook1.Append(fileVersion1);
|
||||
workbook1.Append(workbookProperties1);
|
||||
workbook1.Append(bookViews1);
|
||||
workbook1.Append(sheets1);
|
||||
workbook1.Append(calculationProperties1);
|
||||
workbook1.Append(fileRecoveryProperties1);
|
||||
|
||||
workbookPart1.Workbook = workbook1;
|
||||
}
|
||||
|
||||
// Generates content of worksheetPart1.
|
||||
private void GenerateWorksheetPart1Content(WorksheetPart worksheetPart1)
|
||||
{
|
||||
Worksheet worksheet1 = new Worksheet();
|
||||
worksheet1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
|
||||
|
||||
#region sheet dimension
|
||||
//SheetDimension sheetDimension1 = new SheetDimension();// { Reference = "A1:H3" };
|
||||
//worksheet1.Append(sheetDimension1);
|
||||
#endregion
|
||||
|
||||
#region sheet views
|
||||
SheetViews sheetViews1 = new SheetViews();
|
||||
|
||||
SheetView sheetView1 = new SheetView() { TabSelected = true, WorkbookViewId = (UInt32Value)0U };
|
||||
Selection selection1 = new Selection() { ActiveCell = "A1", SequenceOfReferences = new ListValue<StringValue>() { InnerText = "A1" } };
|
||||
|
||||
sheetView1.Append(selection1);
|
||||
sheetViews1.Append(sheetView1);
|
||||
worksheet1.Append(sheetViews1);
|
||||
#endregion
|
||||
|
||||
#region sheet format properties
|
||||
SheetFormatProperties sheetFormatProperties1 = new SheetFormatProperties() { DefaultRowHeight = 18D, CustomHeight = true };
|
||||
worksheet1.Append(sheetFormatProperties1);
|
||||
#endregion
|
||||
|
||||
#region columns 外部加入。
|
||||
//Columns columns = GenerateColumns(widthList);
|
||||
//worksheet1.Append(columns);
|
||||
#endregion
|
||||
|
||||
#region sheet data 外部加入。
|
||||
//SheetData sheetData = GenerateSheetData();
|
||||
//worksheet1.Append(sheetData);
|
||||
#endregion
|
||||
|
||||
#region merge cells
|
||||
#endregion
|
||||
|
||||
//PhoneticProperties phoneticProperties1 = new PhoneticProperties() { FontId = (UInt32Value)1U, Type = PhoneticValues.NoConversion };
|
||||
//PageMargins pageMargins1 = new PageMargins() { Left = 0.7D, Right = 0.7D, Top = 0.75D, Bottom = 0.75D, Header = 0.3D, Footer = 0.3D };
|
||||
//PageSetup pageSetup1 = new PageSetup() { PaperSize = (UInt32Value)9U, Orientation = OrientationValues.Portrait, HorizontalDpi = (UInt32Value)200U, VerticalDpi = (UInt32Value)200U };
|
||||
|
||||
//worksheet1.Append(phoneticProperties1);
|
||||
//worksheet1.Append(pageMargins1);
|
||||
//worksheet1.Append(pageSetup1);
|
||||
|
||||
worksheetPart1.Worksheet = worksheet1;
|
||||
}
|
||||
|
||||
private Columns GenerateColumns(List<DoubleValue> columnProperties)
|
||||
{
|
||||
Columns columns = new Columns();
|
||||
Column column = null;
|
||||
UInt32Value col = 0;
|
||||
double gain = 127.0 / 750.0;
|
||||
foreach (DoubleValue dv in columnProperties)
|
||||
{
|
||||
col++;
|
||||
column = new Column() { Min = col, Max = col, Width = dv * gain, CustomWidth = true, BestFit = true };
|
||||
columns.Append(column);
|
||||
}
|
||||
|
||||
return columns;
|
||||
}
|
||||
|
||||
private Row GenerateRow(int rowIndex, List<Cell> cellsInRow, int styleIndex)
|
||||
{
|
||||
if (rowIndex < 0) return null;
|
||||
|
||||
Row row = new Row() { RowIndex = (UInt32)rowIndex };
|
||||
|
||||
if (styleIndex >= 0)
|
||||
{
|
||||
row.StyleIndex = (UInt32)styleIndex;
|
||||
}
|
||||
|
||||
if (cellsInRow.Count > 0)
|
||||
{
|
||||
row.Spans = new ListValue<StringValue>() { InnerText = "1:" + cellsInRow.Count };
|
||||
}
|
||||
|
||||
foreach (Cell cell in cellsInRow)
|
||||
{
|
||||
row.Append(cell);
|
||||
}
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
private Cell GenerateCell(Stylesheet styleSheet, CExcelCellData cellData)
|
||||
{
|
||||
Cell cell = new Cell();
|
||||
CellValue cellValue = new CellValue();
|
||||
if (styleSheet == null)
|
||||
{
|
||||
cell.DataType = CellValues.String;
|
||||
cellValue.Text = cellData.Value == null ? "" : cellData.Value.ToString();
|
||||
cell.Append(cellValue);
|
||||
return cell;
|
||||
}
|
||||
|
||||
UInt32Value fontId = CreateFonts(styleSheet, cellData.CFont);
|
||||
UInt32Value fillId = CreateFills(styleSheet, cellData.CFill);
|
||||
UInt32Value borderId = CreateBorders(styleSheet, cellData.CBorder);
|
||||
|
||||
cell.StyleIndex = CreateCellFormat(styleSheet, fontId, fillId, borderId, cellData);
|
||||
|
||||
if (cellData.DataType != null && cellData.DataType.HasValue)
|
||||
{
|
||||
cell.DataType = cellData.DataType;
|
||||
}
|
||||
|
||||
cellValue.Text = cellData.Value == null ? "" : cellData.Value.ToString();
|
||||
cell.Append(cellValue);
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
private string GetFontsHashString(CellFont cellFont)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (cellFont != null)
|
||||
{
|
||||
sb.AppendLine(string.IsNullOrEmpty(cellFont.FontName) ? "" : cellFont.FontName);
|
||||
if (cellFont.FontSize != null && cellFont.FontSize.HasValue)
|
||||
{
|
||||
sb.AppendLine(cellFont.FontSize.Value.ToString());
|
||||
}
|
||||
if (cellFont.ForeColor != null)
|
||||
{
|
||||
sb.AppendLine(cellFont.ForeColor.ToArgb().ToString());
|
||||
}
|
||||
if (cellFont.IsBold != null && cellFont.IsBold.HasValue)
|
||||
{
|
||||
sb.AppendLine(cellFont.IsBold.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
string result = GetHashString(sb.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetFillHashString(CellFill fill)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (fill != null)
|
||||
{
|
||||
if (fill.FillColor != null)
|
||||
{
|
||||
sb.AppendLine(fill.FillColor.ToArgb().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
string result = GetHashString(sb.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetBorderHashString(CellBorder border)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (border != null)
|
||||
{
|
||||
if (border.LeftBorder != null)
|
||||
sb.AppendLine("left");
|
||||
if (border.RightBorder != null)
|
||||
sb.AppendLine("right");
|
||||
if (border.TopBorder != null)
|
||||
sb.AppendLine("top");
|
||||
if (border.BottomBorder != null)
|
||||
sb.AppendLine("bottom");
|
||||
if (border.DialogalBorder != null)
|
||||
sb.AppendLine("dialogal");
|
||||
}
|
||||
|
||||
string result = GetHashString(sb.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetFormatHashString(CellFormat cellFormat, string formateCode)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (cellFormat != null)
|
||||
{
|
||||
if (cellFormat.FontId != null && cellFormat.FontId.HasValue)
|
||||
sb.AppendLine(cellFormat.FontId.Value.ToString());
|
||||
if (cellFormat.ApplyFont != null && cellFormat.ApplyFont.HasValue)
|
||||
sb.AppendLine(cellFormat.ApplyFont.Value.ToString());
|
||||
|
||||
if (cellFormat.FillId != null && cellFormat.FillId.HasValue)
|
||||
sb.AppendLine(cellFormat.FillId.Value.ToString());
|
||||
if (cellFormat.ApplyFill != null && cellFormat.ApplyFill.HasValue)
|
||||
sb.AppendLine(cellFormat.ApplyFill.Value.ToString());
|
||||
|
||||
if (cellFormat.BorderId != null && cellFormat.BorderId.HasValue)
|
||||
sb.AppendLine(cellFormat.BorderId.Value.ToString());
|
||||
if (cellFormat.ApplyBorder != null && cellFormat.ApplyBorder.HasValue)
|
||||
sb.AppendLine(cellFormat.ApplyBorder.Value.ToString());
|
||||
|
||||
if (cellFormat.ApplyNumberFormat != null && cellFormat.ApplyNumberFormat.HasValue)
|
||||
sb.AppendLine(cellFormat.ApplyNumberFormat.Value.ToString());
|
||||
if (cellFormat.NumberFormatId != null && cellFormat.NumberFormatId.HasValue)
|
||||
sb.AppendLine(cellFormat.NumberFormatId.Value.ToString());
|
||||
|
||||
if (cellFormat.Alignment != null)
|
||||
{
|
||||
if (cellFormat.Alignment.Horizontal != null && cellFormat.Alignment.Horizontal.HasValue)
|
||||
sb.AppendLine(cellFormat.Alignment.Horizontal.Value.ToString());
|
||||
if (cellFormat.Alignment.Vertical != null && cellFormat.Alignment.Vertical.HasValue)
|
||||
sb.AppendLine(cellFormat.Alignment.Vertical.Value.ToString());
|
||||
if (cellFormat.ApplyAlignment != null && cellFormat.ApplyAlignment.HasValue)
|
||||
sb.AppendLine(cellFormat.ApplyAlignment.Value.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
sb.AppendLine(formateCode);
|
||||
|
||||
string result = GetHashString(sb.ToString());
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetHashString(string str)
|
||||
{
|
||||
return str;
|
||||
byte[] b1 = Encoding.UTF8.GetBytes(str);
|
||||
//Cryptography.HashCode hc = new LHBIS.Security.Cryptography.HashCode(LHBIS.Security.Cryptography.HashType.htSHA256);
|
||||
//byte[] b2 = hc.ComputeHash(b1);
|
||||
//string result = LHBIS.Security.Cryptography.CommonConvert.ToHex(b2);
|
||||
//return result;
|
||||
|
||||
HashAlgorithm ha = new SHA256Managed();
|
||||
byte[] b2 = ha.ComputeHash(b1);
|
||||
string result = ToHex(b2);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string ToHex(byte[] buffer)
|
||||
{
|
||||
if (buffer == null)
|
||||
return "";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
{
|
||||
sb.Append(string.Format("{0:X2}", buffer[i]));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private SheetData GenerateSheetData(Stylesheet styleSheet, CExcelSheet data)
|
||||
{
|
||||
SheetData sheetData = new SheetData();
|
||||
Row row = null;
|
||||
Cell cell = null;
|
||||
List<Cell> cellList = null;
|
||||
int rowIndex = 0;
|
||||
|
||||
foreach (List<CExcelCellData> rowData in data.DataMatrix)
|
||||
{
|
||||
rowIndex += 1;
|
||||
cellList = new List<Cell>();
|
||||
foreach (CExcelCellData cellData in rowData)
|
||||
{
|
||||
//no style while stylesheet is null
|
||||
cell = GenerateCell(styleSheet, cellData);
|
||||
cellList.Add(cell);
|
||||
}
|
||||
//初始化行的样式为-1,表示使用缺省样式。
|
||||
row = GenerateRow(rowIndex, cellList, -1);
|
||||
if (data.RowHeightList.ContainsKey(rowIndex))
|
||||
{
|
||||
row.CustomHeight = new BooleanValue(true);
|
||||
row.Height = new DoubleValue(data.RowHeightList[rowIndex]);
|
||||
}
|
||||
|
||||
sheetData.Append(row);
|
||||
}
|
||||
return sheetData;
|
||||
}
|
||||
|
||||
private UInt32Value CreateFonts(Stylesheet styleSheet, CellFont cellFont)
|
||||
{
|
||||
if (styleSheet == null || cellFont == null) return 0U;
|
||||
|
||||
string key = GetFontsHashString(cellFont);
|
||||
UInt32Value ui32 = 0;
|
||||
if (_fontIndexCache.TryGetValue(key, out ui32))
|
||||
{
|
||||
return ui32;
|
||||
}
|
||||
|
||||
Font font = new Font();
|
||||
if (!string.IsNullOrEmpty(cellFont.FontName))
|
||||
{
|
||||
FontName name = new FontName() { Val = cellFont.FontName };
|
||||
font.Append(name);
|
||||
}
|
||||
if (cellFont.FontSize != null && cellFont.FontSize.HasValue)
|
||||
{
|
||||
FontSize size = new FontSize() { Val = cellFont.FontSize.Value };
|
||||
font.Append(size);
|
||||
}
|
||||
if (cellFont.IsBold != null && cellFont.IsBold.Value)
|
||||
{
|
||||
Bold bold = new Bold();
|
||||
font.Append(bold);
|
||||
}
|
||||
if (cellFont.ForeColor != null)
|
||||
{
|
||||
Color color = new Color();
|
||||
color.Rgb = new HexBinaryValue();
|
||||
color.Rgb.Value = System.Drawing.ColorTranslator.ToHtml(
|
||||
System.Drawing.Color.FromArgb(cellFont.ForeColor.A, cellFont.ForeColor.R, cellFont.ForeColor.G, cellFont.ForeColor.B)).Replace("#", "");
|
||||
font.Append(color);
|
||||
}
|
||||
|
||||
FontFamilyNumbering fontFamilyNumbering = new FontFamilyNumbering() { Val = 2 };
|
||||
font.Append(fontFamilyNumbering);
|
||||
FontCharSet fontCharSet = new FontCharSet() { Val = 134 };
|
||||
font.Append(fontCharSet);
|
||||
FontScheme fontScheme = new FontScheme() { Val = FontSchemeValues.Minor };
|
||||
font.Append(fontScheme);
|
||||
|
||||
if (styleSheet.Fonts == null)
|
||||
{
|
||||
styleSheet.Fonts = new Fonts();
|
||||
}
|
||||
styleSheet.Fonts.Append(font);
|
||||
UInt32Value fontID = styleSheet.Fonts.Count;
|
||||
_fontIndexCache.Add(key, fontID);
|
||||
|
||||
styleSheet.Fonts.Count++;
|
||||
return fontID;
|
||||
}
|
||||
|
||||
private UInt32Value CreateFills(Stylesheet styleSheet, CellFill cellFill)
|
||||
{
|
||||
if (styleSheet == null || cellFill == null) return 0U;
|
||||
|
||||
string key = GetFillHashString(cellFill);
|
||||
UInt32Value ui32 = 0;
|
||||
if (_fillIndexCache.TryGetValue(key, out ui32))
|
||||
{
|
||||
return ui32;
|
||||
}
|
||||
|
||||
PatternFill patternFill = new PatternFill();
|
||||
if (cellFill != null)
|
||||
{
|
||||
patternFill.Append(new ForegroundColor()
|
||||
{
|
||||
Rgb = new HexBinaryValue()
|
||||
{
|
||||
Value = System.Drawing.ColorTranslator.ToHtml(
|
||||
System.Drawing.Color.FromArgb(cellFill.FillColor.A, cellFill.FillColor.R, cellFill.FillColor.G, cellFill.FillColor.B)).Replace("#", "")
|
||||
}
|
||||
});
|
||||
patternFill.PatternType = PatternValues.Solid;
|
||||
}
|
||||
else
|
||||
{
|
||||
patternFill.PatternType = PatternValues.None;
|
||||
}
|
||||
if (styleSheet.Fills == null)
|
||||
{
|
||||
styleSheet.Fills = new Fills();
|
||||
}
|
||||
|
||||
styleSheet.Fills.Append(new Fill(patternFill));
|
||||
UInt32Value fillId = styleSheet.Fills.Count;
|
||||
_fillIndexCache.Add(key, fillId);
|
||||
styleSheet.Fills.Count++;
|
||||
return fillId;
|
||||
}
|
||||
|
||||
private UInt32Value CreateBorders(Stylesheet styleSheet, CellBorder cellBorder)
|
||||
{
|
||||
if (styleSheet == null || cellBorder == null) return 0U;
|
||||
|
||||
string key = GetBorderHashString(cellBorder);
|
||||
UInt32Value ui32 = 0;
|
||||
if (_borderIndexCache.TryGetValue(key, out ui32))
|
||||
{
|
||||
return ui32;
|
||||
}
|
||||
|
||||
Border border = new Border();
|
||||
if (cellBorder == null) return 0;
|
||||
if (cellBorder.LeftBorder != null)
|
||||
border.Append(cellBorder.LeftBorder);
|
||||
if (cellBorder.RightBorder != null)
|
||||
border.Append(cellBorder.RightBorder);
|
||||
if (cellBorder.TopBorder != null)
|
||||
border.Append(cellBorder.TopBorder);
|
||||
if (cellBorder.BottomBorder != null)
|
||||
border.Append(cellBorder.BottomBorder);
|
||||
if (cellBorder.DialogalBorder != null)
|
||||
border.Append(cellBorder.DialogalBorder);
|
||||
|
||||
if (styleSheet.Borders == null)
|
||||
{
|
||||
styleSheet.Borders = new Borders();
|
||||
}
|
||||
styleSheet.Borders.Append(border);
|
||||
UInt32Value borderId = styleSheet.Borders.Count;
|
||||
_borderIndexCache.Add(key, borderId);
|
||||
styleSheet.Borders.Count++;
|
||||
return borderId;
|
||||
}
|
||||
|
||||
private UInt32Value CreateCellFormat(Stylesheet styleSheet, UInt32Value fontIndex, UInt32Value fillIndex,
|
||||
UInt32Value borderIndex, CExcelCellData cellData)
|
||||
{
|
||||
if (styleSheet == null) return 0U;
|
||||
|
||||
CellFormat cellFormat = new CellFormat();
|
||||
if (fontIndex == null) fontIndex = 0;
|
||||
cellFormat.FontId = fontIndex;
|
||||
cellFormat.ApplyFont = BooleanValue.FromBoolean(true);
|
||||
|
||||
if (fillIndex == null) fillIndex = 0;
|
||||
cellFormat.FillId = fillIndex;
|
||||
cellFormat.ApplyFill = BooleanValue.FromBoolean(true);
|
||||
|
||||
if (borderIndex == null) borderIndex = 0;
|
||||
cellFormat.BorderId = borderIndex;
|
||||
cellFormat.ApplyBorder = BooleanValue.FromBoolean(true);
|
||||
|
||||
cellFormat.ApplyNumberFormat = cellData.ApplyNumberFormat;
|
||||
cellFormat.NumberFormatId = cellData.NumberFormatId;
|
||||
|
||||
if (cellData.CAlignment != null)
|
||||
{
|
||||
cellFormat.Append(cellData.CAlignment.Align);
|
||||
cellFormat.ApplyAlignment = BooleanValue.FromBoolean(true);
|
||||
}
|
||||
|
||||
string key = GetFormatHashString(cellFormat, cellData.FormatCode);
|
||||
UInt32Value ui32 = 0;
|
||||
if (_formatIndexCache.TryGetValue(key, out ui32))
|
||||
{
|
||||
return ui32;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(cellData.FormatCode) && cellData.FormatCode.HasValue)
|
||||
{
|
||||
cellFormat.NumberFormatId = CreateFormatId(cellData.FormatCode, styleSheet.NumberingFormats);
|
||||
}
|
||||
|
||||
styleSheet.CellFormats.Append(cellFormat);
|
||||
UInt32Value cellFormatId = styleSheet.CellFormats.Count;
|
||||
_formatIndexCache.Add(key, cellFormatId);
|
||||
styleSheet.CellFormats.Count++;
|
||||
return cellFormatId;
|
||||
}
|
||||
|
||||
private UInt32Value CreateFormatId(string formatCode, NumberingFormats numberingFormats)
|
||||
{
|
||||
NumberingFormat nf = numberingFormats.AppendChild(new NumberingFormat());
|
||||
numberingFormats.Count++;
|
||||
nf.FormatCode = formatCode;
|
||||
nf.NumberFormatId = GetMaxFormatId(numberingFormats);
|
||||
if (nf.NumberFormatId == 0)
|
||||
{
|
||||
nf.NumberFormatId = 176U;
|
||||
}
|
||||
else
|
||||
{
|
||||
nf.NumberFormatId += 1;
|
||||
}
|
||||
return nf.NumberFormatId;
|
||||
}
|
||||
|
||||
private UInt32Value GetMaxFormatId(NumberingFormats numberingFormats)
|
||||
{
|
||||
UInt32Value maxFormatId = 0U;
|
||||
foreach (NumberingFormat nf in numberingFormats.ChildElements)
|
||||
{
|
||||
if (nf.NumberFormatId != null && nf.NumberFormatId.HasValue && nf.NumberFormatId > maxFormatId)
|
||||
maxFormatId = nf.NumberFormatId;
|
||||
}
|
||||
return maxFormatId;
|
||||
}
|
||||
|
||||
// Generates content of workbookStylesPart1.
|
||||
private void GenerateWorkbookStylesPart1Content(WorkbookStylesPart workbookStylesPart1)
|
||||
{
|
||||
Stylesheet stylesheet = new Stylesheet();
|
||||
|
||||
#region default fonts
|
||||
Font font = new Font();
|
||||
FontSize fontSize = new FontSize() { Val = 11D };
|
||||
Color color = new Color() { Theme = (UInt32Value)1U };
|
||||
FontName fontName = new FontName() { Val = "宋体" };
|
||||
FontFamilyNumbering fontFamilyNumbering = new FontFamilyNumbering() { Val = 2 };
|
||||
FontCharSet fontCharSet = new FontCharSet() { Val = 134 };
|
||||
FontScheme fontScheme = new FontScheme() { Val = FontSchemeValues.Minor };
|
||||
|
||||
font.Append(fontSize);
|
||||
font.Append(color);
|
||||
font.Append(fontName);
|
||||
font.Append(fontFamilyNumbering);
|
||||
font.Append(fontCharSet);
|
||||
font.Append(fontScheme);
|
||||
|
||||
if (stylesheet.Fonts == null) stylesheet.Fonts = new Fonts() { Count = 2 };
|
||||
stylesheet.Fonts.Append(font);
|
||||
|
||||
Font font2 = new Font();
|
||||
FontSize fontSize2 = new FontSize() { Val = 9D };
|
||||
FontName fontName2 = new FontName() { Val = "宋体" };
|
||||
FontFamilyNumbering fontFamilyNumbering2 = new FontFamilyNumbering() { Val = 2 };
|
||||
FontCharSet fontCharSet2 = new FontCharSet() { Val = 134 };
|
||||
FontScheme fontScheme2 = new FontScheme() { Val = FontSchemeValues.Minor };
|
||||
|
||||
font2.Append(fontSize2);
|
||||
font2.Append(fontName2);
|
||||
font2.Append(fontFamilyNumbering2);
|
||||
font2.Append(fontCharSet2);
|
||||
font2.Append(fontScheme2);
|
||||
stylesheet.Fonts.Append(font2);
|
||||
#endregion
|
||||
|
||||
#region default fills
|
||||
Fill fill = new Fill();
|
||||
PatternFill patternFill = new PatternFill() { PatternType = PatternValues.None };
|
||||
|
||||
fill.Append(patternFill);
|
||||
|
||||
if (stylesheet.Fills == null) stylesheet.Fills = new Fills() { Count = 2 };
|
||||
stylesheet.Fills.Append(fill);
|
||||
|
||||
Fill fill2 = new Fill();
|
||||
PatternFill patternFill2 = new PatternFill() { PatternType = PatternValues.Gray125 };
|
||||
|
||||
fill2.Append(patternFill2);
|
||||
stylesheet.Fills.Append(fill2);
|
||||
#endregion
|
||||
|
||||
#region default border
|
||||
Border border = new Border();
|
||||
LeftBorder leftBorder = new LeftBorder();
|
||||
RightBorder rightBorder = new RightBorder();
|
||||
TopBorder topBorder = new TopBorder();
|
||||
BottomBorder bottomBorder = new BottomBorder();
|
||||
DiagonalBorder diagonalBorder = new DiagonalBorder();
|
||||
|
||||
border.Append(leftBorder);
|
||||
border.Append(rightBorder);
|
||||
border.Append(topBorder);
|
||||
border.Append(bottomBorder);
|
||||
border.Append(diagonalBorder);
|
||||
|
||||
if (stylesheet.Borders == null) stylesheet.Borders = new Borders() { Count = 1 };
|
||||
stylesheet.Borders.Append(border);
|
||||
#endregion
|
||||
|
||||
#region cell style format
|
||||
#endregion
|
||||
|
||||
#region cell numberingformats
|
||||
stylesheet.NumberingFormats = new NumberingFormats() { Count = (UInt32Value)0U };
|
||||
#endregion
|
||||
|
||||
#region cell format 初始化一个cell format,因为cellXfs的索引须从1开始。
|
||||
stylesheet.CellFormats = new CellFormats() { Count = 1U };
|
||||
CellFormat cf0 = stylesheet.CellFormats.AppendChild(new CellFormat());
|
||||
cf0.NumberFormatId = 0;
|
||||
cf0.FontId = 0;
|
||||
cf0.BorderId = 0;
|
||||
cf0.FillId = 0;
|
||||
#endregion
|
||||
|
||||
#region cell style
|
||||
#endregion
|
||||
workbookStylesPart1.Stylesheet = stylesheet;
|
||||
}
|
||||
|
||||
// Generates content of sharedStringTablePart1.
|
||||
private void GenerateSharedStringTablePart1Content(SharedStringTablePart sharedStringTablePart1, List<string> cellValues)
|
||||
{
|
||||
SharedStringTable sharedStringTable = new SharedStringTable() { Count = UInt32Value.FromUInt32((uint)cellValues.Count), UniqueCount = UInt32Value.FromUInt32((uint)cellValues.Count) };
|
||||
|
||||
SharedStringItem sharedStringItem = null;// new SharedStringItem();
|
||||
Text text = null;// new Text();
|
||||
foreach (string str in cellValues)
|
||||
{
|
||||
sharedStringItem = new SharedStringItem();
|
||||
text = new Text();
|
||||
|
||||
text.Text = str;
|
||||
sharedStringItem.Append(text);
|
||||
sharedStringTable.Append(sharedStringItem);
|
||||
}
|
||||
|
||||
sharedStringTablePart1.SharedStringTable = sharedStringTable;
|
||||
}
|
||||
|
||||
private MergeCells GenerateMergeCell(List<string> mergeCellReferenceList)
|
||||
{
|
||||
MergeCells mcells = new MergeCells() { Count = UInt32Value.FromUInt32((uint)mergeCellReferenceList.Count) };
|
||||
if (mcells == null || mergeCellReferenceList == null || mergeCellReferenceList.Count <= 0) return mcells;
|
||||
var mergeCells = mergeCellReferenceList.Select((s) =>
|
||||
{
|
||||
return new MergeCell() { Reference = s };
|
||||
});
|
||||
|
||||
foreach (var o in mergeCells)
|
||||
{
|
||||
mcells.Append(o);
|
||||
}
|
||||
return mcells;
|
||||
}
|
||||
}
|
||||
}
|
483
IronIntelContractorBusiness/ExportExcel/ExportToExcel.cs
Normal file
483
IronIntelContractorBusiness/ExportExcel/ExportToExcel.cs
Normal file
@ -0,0 +1,483 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using DocumentFormat.OpenXml;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Data;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
internal class ChartFormatedData : IOpenXmlExcelStyleAndData
|
||||
{
|
||||
public ChartFormatedData()
|
||||
{
|
||||
FormatType = CellFormatType.CSharp;
|
||||
}
|
||||
|
||||
#region IOpenXmlExcelStyleAndData Members
|
||||
|
||||
public CellAlignment CAlignment { get; set; }
|
||||
|
||||
public CellBorder CBorder { get; set; }
|
||||
|
||||
public CellFill CFill { get; set; }
|
||||
|
||||
public CellFont CFont { get; set; }
|
||||
|
||||
public CellDataType DataType { get; set; }
|
||||
|
||||
public string FormatCode { get; set; }
|
||||
|
||||
public CellFormatType FormatType { get; set; }
|
||||
|
||||
public object Value { get; set; }
|
||||
|
||||
public String MergedCellsPosition { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class ExportToExcel
|
||||
{
|
||||
/// <summary>
|
||||
/// 将DataTable的数据导出到Excel
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public byte[] CreateExcel(DataTable data, string caption, double[] columnWidths, string[] MergeTitles)
|
||||
{
|
||||
COpenXmlExcelSheet osheet = ConvertToOpenXmlObject(data, caption, columnWidths, MergeTitles);
|
||||
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
ExcelXlsx xls = new ExcelXlsx();
|
||||
xls.CreatePackage(ms, osheet);
|
||||
ms.Position = 0;
|
||||
|
||||
byte[] bts = new byte[ms.Length];
|
||||
int offset = 0;
|
||||
while (offset < bts.Length)
|
||||
{
|
||||
offset += ms.Read(bts, offset, bts.Length - offset);
|
||||
}
|
||||
|
||||
return bts;
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
if (ms != null)
|
||||
ms.Close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private object ConvertIvalidChars(object s)
|
||||
{
|
||||
if (s == null) return null;
|
||||
if (s.GetType() != typeof(string)) return s;
|
||||
const string invalidCharsMatch =
|
||||
"(?ims)[\x0\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf" +
|
||||
"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x7f]";
|
||||
|
||||
//取代其中無效字元, 通通換成空字串
|
||||
s = Regex.Replace(
|
||||
s.ToString(),
|
||||
invalidCharsMatch, "");
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private COpenXmlExcelSheet ConvertToOpenXmlObject(DataTable data, string caption, double[] columnWidths, string[] MergeTitles)
|
||||
{
|
||||
try
|
||||
{
|
||||
COpenXmlExcelSheet osheet = new COpenXmlExcelSheet();
|
||||
|
||||
// 设置数据和格式。
|
||||
|
||||
//所有数据和格式存放在此结构中。
|
||||
List<List<IOpenXmlExcelStyleAndData>> dataMatrix = new List<List<IOpenXmlExcelStyleAndData>>();
|
||||
osheet.DataMatrix = dataMatrix;
|
||||
|
||||
//行数据临时对象。
|
||||
List<IOpenXmlExcelStyleAndData> rowData = null;
|
||||
//单元格数据临时对象。
|
||||
ChartFormatedData cellData = null;
|
||||
|
||||
DataRow rdr = null;
|
||||
DataColumn rdc = null;
|
||||
|
||||
#region 设置宽度。
|
||||
|
||||
foreach (var w in columnWidths)
|
||||
{
|
||||
osheet.WidthList.Add(w);
|
||||
}
|
||||
//for (int k = 0; k < dataFromClient.Columns.Count; k++)
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// rdc = dataFromClient.Columns[k];
|
||||
// if (rdc.Attributes == null || !rdc.Attributes.ContainsKey("Width"))
|
||||
// {
|
||||
// osheet.WidthList.Add(100);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// osheet.WidthList.Add(Convert.ToDouble(rdc.Attributes["Width"]));
|
||||
// }
|
||||
// }
|
||||
// catch
|
||||
// {
|
||||
// }
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
int rowIndex = 0;
|
||||
|
||||
#region caption
|
||||
|
||||
if (!string.IsNullOrEmpty(caption))
|
||||
{
|
||||
rowData = new List<IOpenXmlExcelStyleAndData>();
|
||||
cellData = new ChartFormatedData();
|
||||
cellData.CAlignment = new CellAlignment();
|
||||
cellData.CAlignment.Align = GetAlignment("center");
|
||||
cellData.DataType = CellDataType.String;
|
||||
cellData.FormatCode = "";
|
||||
|
||||
cellData.CFont = new CellFont();
|
||||
cellData.CFont.FontSize = 14;
|
||||
|
||||
cellData.Value = caption;
|
||||
cellData.MergedCellsPosition = "A1:" + ConvertColNumber(data.Columns.Count) + "1";
|
||||
|
||||
rowData.Add(cellData);
|
||||
rowIndex += 1;
|
||||
dataMatrix.Add(rowData);
|
||||
|
||||
//设置第一行的高度。
|
||||
osheet.RowHeightList.Add(rowIndex, 23);
|
||||
|
||||
//添加一个空行。
|
||||
rowData = new List<IOpenXmlExcelStyleAndData>();
|
||||
cellData = new ChartFormatedData();
|
||||
cellData.MergedCellsPosition = "A2:" + ConvertColNumber(data.Columns.Count) + "2";
|
||||
rowData.Add(cellData);
|
||||
rowIndex += 1;
|
||||
dataMatrix.Add(rowData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region MergeTitles
|
||||
|
||||
if (MergeTitles != null && MergeTitles.Length % 2 == 0)
|
||||
{
|
||||
rowData = new List<IOpenXmlExcelStyleAndData>();
|
||||
|
||||
for (int q = 0; q < data.Columns.Count; q++)
|
||||
{
|
||||
cellData = new ChartFormatedData();
|
||||
cellData.CAlignment = new CellAlignment();
|
||||
cellData.CAlignment.Align = GetAlignment("center");
|
||||
cellData.DataType = CellDataType.String;
|
||||
cellData.FormatCode = "";
|
||||
|
||||
cellData.CFont = new CellFont();
|
||||
cellData.CFont.FontSize = 14;
|
||||
|
||||
rowData.Add(cellData);
|
||||
}
|
||||
|
||||
for (int i = 0; i < MergeTitles.Length; i += 2)
|
||||
{
|
||||
string[] tmp = MergeTitles[i + 1].Split('-');
|
||||
if (tmp.Length == 1) continue;
|
||||
|
||||
cellData = (ChartFormatedData)rowData[(Convert.ToInt32(tmp[0]) - 1)];
|
||||
cellData.Value = MergeTitles[i];
|
||||
cellData.MergedCellsPosition = ConvertColNumber(Convert.ToInt32(tmp[0])) + "3:" + ConvertColNumber(Convert.ToInt32(tmp[1])) + "3";
|
||||
}
|
||||
|
||||
rowIndex += 1;
|
||||
dataMatrix.Add(rowData);
|
||||
//设置第一行的高度。
|
||||
osheet.RowHeightList.Add(rowIndex, 15);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region header。
|
||||
|
||||
rowData = new List<IOpenXmlExcelStyleAndData>();
|
||||
|
||||
for (int q = 0; q < data.Columns.Count; q++)
|
||||
{
|
||||
rdc = data.Columns[q];
|
||||
cellData = new ChartFormatedData();
|
||||
|
||||
string alignment = "";
|
||||
if (rdc != null)
|
||||
{
|
||||
//if (rdc.Attributes != null && rdc.Attributes.ContainsKey("Alignment"))
|
||||
//{
|
||||
// alignment = rdc.Attributes["Alignment"];
|
||||
//}
|
||||
|
||||
cellData.CAlignment = new CellAlignment();
|
||||
cellData.CAlignment.Align = GetAlignment(alignment);
|
||||
|
||||
cellData.CFont = new CellFont();
|
||||
cellData.CFont.IsBold = true;
|
||||
|
||||
cellData.CFill = new CellFill();
|
||||
cellData.CFill.FillColor = System.Drawing.Color.Gray;
|
||||
|
||||
cellData.DataType = CellDataType.String;
|
||||
cellData.FormatCode = "";
|
||||
}
|
||||
|
||||
cellData.Value = rdc.ColumnName;
|
||||
|
||||
rowData.Add(cellData);
|
||||
}
|
||||
rowIndex += 1;
|
||||
osheet.RowHeightList.Add(rowIndex, 18);
|
||||
dataMatrix.Add(rowData);
|
||||
|
||||
#endregion
|
||||
|
||||
#region real data 。
|
||||
|
||||
for (int k = 0; k <= data.Rows.Count - 1; k++)
|
||||
{
|
||||
rdr = data.Rows[k];
|
||||
rowData = new List<IOpenXmlExcelStyleAndData>();
|
||||
|
||||
for (int q = 0; q < data.Columns.Count; q++)
|
||||
{
|
||||
rdc = data.Columns[q];
|
||||
|
||||
string format = "";
|
||||
//if (rdc != null)
|
||||
//{
|
||||
//if (rdc.Attributes != null && rdc.Attributes.ContainsKey("DataFormat"))
|
||||
//{
|
||||
// format = (rdc.Attributes["DataFormat"] == null
|
||||
// ? ""
|
||||
// : rdc.Attributes["DataFormat"].ToString());
|
||||
//}
|
||||
//}
|
||||
|
||||
cellData = new ChartFormatedData();
|
||||
|
||||
//将特殊格式值处理成字符串显示。
|
||||
if (rdr != null)
|
||||
{
|
||||
bool isProcessed = false;
|
||||
cellData.Value =
|
||||
ConvertIvalidChars(
|
||||
ProcessSpecialFormat(rdr[q], format, ref isProcessed));
|
||||
if (isProcessed) format = "";
|
||||
}
|
||||
cellData.FormatCode = ProcessFormat(format);
|
||||
cellData.DataType =
|
||||
GetDataType((cellData.Value == null ? typeof(string) : cellData.Value.GetType()));
|
||||
|
||||
string alignment = "";
|
||||
if (rdc != null)
|
||||
{
|
||||
//if (rdc.Attributes != null && rdc.Attributes.ContainsKey("Alignment"))
|
||||
//{
|
||||
// alignment = rdc.Attributes["Alignment"];
|
||||
//}
|
||||
cellData.CAlignment = new CellAlignment();
|
||||
cellData.CAlignment.Align = GetAlignment(alignment);
|
||||
}
|
||||
|
||||
//如果是合计行则以浅灰色显示。
|
||||
//if (hasTotalRow && k == dataFromClient.Rows.Count - 1)
|
||||
//{
|
||||
// cellData.CFill = new CellFill();
|
||||
// cellData.CFill.FillColor = System.Drawing.Color.LightGray;
|
||||
//}
|
||||
|
||||
//如果是合计列则以浅灰色显示。
|
||||
//if (hasTotalColumn && q == dataFromClient.Columns.Count - 1)
|
||||
//{
|
||||
// cellData.CFill = new CellFill();
|
||||
// cellData.CFill.FillColor = System.Drawing.Color.LightGray;
|
||||
//}
|
||||
|
||||
rowData.Add(cellData);
|
||||
}
|
||||
|
||||
//rowIndex += 1;
|
||||
//if (hasTotalRow && k == dataFromClient.Rows.Count - 1)
|
||||
//{
|
||||
// osheet.RowHeightList.Add(rowIndex, totalRowHeight);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// osheet.RowHeightList.Add(rowIndex, 18);
|
||||
//}
|
||||
|
||||
dataMatrix.Add(rowData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
return osheet;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
private string ConvertColNumber(int colnum)
|
||||
{
|
||||
string zzz = "Z+";
|
||||
Regex reg = new Regex(zzz);
|
||||
string result = "";
|
||||
MatchCollection mc = null;
|
||||
for (int k = 0; k < colnum; k++)
|
||||
{
|
||||
mc = reg.Matches(result);
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
//是zzz格式。
|
||||
string first = result.Substring(0, mc[0].Index);
|
||||
if (string.IsNullOrEmpty(first))
|
||||
{
|
||||
result = result.Replace("Z", "A") + "A";
|
||||
}
|
||||
else
|
||||
{
|
||||
char c = first[first.Length - 1];
|
||||
c = Convert.ToChar(c + 1);
|
||||
result = c.ToString() + result.Substring(mc[0].Index).Replace("Z", "A");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
result = "A";
|
||||
}
|
||||
else
|
||||
{
|
||||
char c = result[result.Length - 1];
|
||||
c = Convert.ToChar(c + 1);
|
||||
result = result.Substring(0, result.Length - 1) + c.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Alignment GetAlignment(string align)
|
||||
{
|
||||
Alignment horizon = new Alignment() { Horizontal = HorizontalAlignmentValues.Left, WrapText = true };
|
||||
|
||||
if (string.Equals(align, "center", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
horizon = new Alignment() { Horizontal = HorizontalAlignmentValues.Center, WrapText = true };
|
||||
}
|
||||
else if (string.Equals(align, "right", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
horizon = new Alignment() { Horizontal = HorizontalAlignmentValues.Right, WrapText = true };
|
||||
}
|
||||
|
||||
return horizon;
|
||||
}
|
||||
|
||||
private CellDataType GetDataType(Type typ)
|
||||
{
|
||||
CellDataType result = CellDataType.String;
|
||||
|
||||
switch (Type.GetTypeCode(typ))
|
||||
{
|
||||
case TypeCode.Int16:
|
||||
case TypeCode.Int32:
|
||||
case TypeCode.Int64:
|
||||
case TypeCode.UInt16:
|
||||
case TypeCode.UInt32:
|
||||
case TypeCode.UInt64:
|
||||
result = CellDataType.Integer;
|
||||
break;
|
||||
case TypeCode.Decimal:
|
||||
case TypeCode.Double:
|
||||
case TypeCode.Single:
|
||||
result = CellDataType.Float;
|
||||
break;
|
||||
case TypeCode.DateTime:
|
||||
result = CellDataType.Date;
|
||||
break;
|
||||
case TypeCode.Boolean:
|
||||
result = CellDataType.Bool;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private object ProcessSpecialFormat(object val, string format, ref bool isProcessed)
|
||||
{
|
||||
object result = val;
|
||||
isProcessed = false;
|
||||
if (val == null || string.IsNullOrEmpty(format.Trim())) return result;
|
||||
|
||||
CellDataType typ = GetDataType(result.GetType());
|
||||
|
||||
//第一个特殊格式:如果值是6位字符串,格式是"MMM-yyyy",则按日期处理。
|
||||
if (typ == CellDataType.String && string.Equals(format.Replace(" ", ""), "{0:MMM-yyyy}"))
|
||||
{
|
||||
string str = result.ToString();
|
||||
if (str.Length == 6)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = new DateTime(Convert.ToInt32(str.Substring(0, 4)), Convert.ToInt32(str.Substring(4)), 1);
|
||||
result = string.Format(format, result);
|
||||
isProcessed = true;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/// <summary>
|
||||
/// 处理Format格式,使一些特殊符号(如:*、@)可以直接在Excel中看到,而不是解释成Excel中对这些符号的定义
|
||||
/// </summary>
|
||||
/// <param name="format">格式字符串</param>
|
||||
/// <returns></returns>
|
||||
private string ProcessFormat(string format)
|
||||
{
|
||||
string resultFormat = format;
|
||||
if (string.IsNullOrEmpty(resultFormat)) return resultFormat;
|
||||
if (format.IndexOf("*") >= 0)
|
||||
{
|
||||
resultFormat = resultFormat.Replace("*", "\"*\"");
|
||||
}
|
||||
if (format.IndexOf("@") >= 0)
|
||||
{
|
||||
resultFormat = resultFormat.Replace("@", "\"@\"");
|
||||
}
|
||||
return resultFormat;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
/// <summary>
|
||||
/// 单元格数据类型
|
||||
/// </summary>
|
||||
public enum CellDataType
|
||||
{
|
||||
String, Bool, Date, Guid, Float, Integer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单元格格式类型
|
||||
/// </summary>
|
||||
public enum CellFormatType
|
||||
{
|
||||
CSharp, Excel
|
||||
}
|
||||
|
||||
#region 单元格边界样式 Cell Border
|
||||
public enum EBorder
|
||||
{
|
||||
None, Single, Double
|
||||
}
|
||||
public class CellBorder
|
||||
{
|
||||
public LeftBorder LeftBorder { get; set; }
|
||||
public RightBorder RightBorder { get; set; }
|
||||
public TopBorder TopBorder { get; set; }
|
||||
public BottomBorder BottomBorder { get; set; }
|
||||
public DiagonalBorder DialogalBorder { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 单元格对齐方式
|
||||
/// </summary>
|
||||
#region cell alignment
|
||||
public class CellAlignment
|
||||
{
|
||||
public Alignment Align { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 单元格填充颜色
|
||||
/// </summary>
|
||||
#region cell fill
|
||||
public class CellFill
|
||||
{
|
||||
public System.Drawing.Color FillColor { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 单元格字体
|
||||
/// </summary>
|
||||
#region cell font
|
||||
public class CellFont
|
||||
{
|
||||
public string FontName { get; set; }
|
||||
public DoubleValue FontSize { get; set; }
|
||||
public BooleanValue IsBold { get; set; }
|
||||
public System.Drawing.Color ForeColor { get; set; }
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 单元格样式和数据。
|
||||
/// </summary>
|
||||
public interface IOpenXmlExcelStyleAndData
|
||||
{
|
||||
//单元格数据值
|
||||
object Value { get; set; }
|
||||
|
||||
//单元格数据类型
|
||||
CellDataType DataType { get; set; }
|
||||
|
||||
//单元格数据颜色
|
||||
CellFont CFont { get; set; }
|
||||
|
||||
//单元格数据格式
|
||||
CellFormatType FormatType { get; set; }
|
||||
String FormatCode { get; set; }
|
||||
|
||||
//单元格边界样式
|
||||
CellBorder CBorder { get; set; }
|
||||
|
||||
//单元格对齐方式
|
||||
CellAlignment CAlignment { get; set; }
|
||||
|
||||
//填充颜色
|
||||
CellFill CFill { get; set; }
|
||||
|
||||
//合并单元格需要合并的
|
||||
String MergedCellsPosition { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// excel sheet 数据和样式集合。
|
||||
/// </summary>
|
||||
public class COpenXmlExcelSheet
|
||||
{
|
||||
public List<List<IOpenXmlExcelStyleAndData>> DataMatrix
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
private List<double> _WidthList = new List<double>();
|
||||
public List<double> WidthList
|
||||
{
|
||||
get { return _WidthList; }
|
||||
}
|
||||
|
||||
Dictionary<int, double> _RowHeightList = new Dictionary<int, double>();
|
||||
public Dictionary<int, double> RowHeightList
|
||||
{
|
||||
get { return _RowHeightList; }
|
||||
}
|
||||
}
|
||||
}
|
73
IronIntelContractorBusiness/ExportExcel/XlsxObj.cs
Normal file
73
IronIntelContractorBusiness/ExportExcel/XlsxObj.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using Ap = DocumentFormat.OpenXml.ExtendedProperties;
|
||||
using Vt = DocumentFormat.OpenXml.VariantTypes;
|
||||
using DocumentFormat.OpenXml;
|
||||
using DocumentFormat.OpenXml.Spreadsheet;
|
||||
using A = DocumentFormat.OpenXml.Drawing;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
internal class CExcelCellData
|
||||
{
|
||||
//单元格数据值
|
||||
public object Value { get; set; }
|
||||
|
||||
//单元格数据类型
|
||||
public EnumValue<CellValues> DataType { get; set; }
|
||||
|
||||
//单元格数据颜色
|
||||
public CellFont CFont { get; set; }
|
||||
|
||||
//单元格数据格式
|
||||
public UInt32Value NumberFormatId { get; set; }
|
||||
public BooleanValue ApplyNumberFormat { get; set; }
|
||||
public StringValue FormatCode { get; set; }
|
||||
|
||||
//单元格边界样式
|
||||
public CellBorder CBorder { get; set; }
|
||||
|
||||
//单元格对齐方式
|
||||
public CellAlignment CAlignment { get; set; }
|
||||
|
||||
//填充颜色
|
||||
public CellFill CFill { get; set; }
|
||||
}
|
||||
|
||||
internal class CExcelSheet
|
||||
{
|
||||
private List<List<CExcelCellData>> _DataMatrix = new List<List<CExcelCellData>>();
|
||||
public List<List<CExcelCellData>> DataMatrix
|
||||
{
|
||||
get { return _DataMatrix; }
|
||||
}
|
||||
|
||||
private List<string> _SharedStrings = new List<string>();
|
||||
public List<string> SharedStrings
|
||||
{
|
||||
get { return _SharedStrings; }
|
||||
}
|
||||
|
||||
List<string> _MergeCellReferenceList = new List<string>();
|
||||
public List<string> MergeCellReferenceList
|
||||
{
|
||||
get { return _MergeCellReferenceList; }
|
||||
}
|
||||
|
||||
List<DoubleValue> _WidthList = new List<DoubleValue>();
|
||||
public List<DoubleValue> WidthList
|
||||
{
|
||||
get { return _WidthList; }
|
||||
}
|
||||
|
||||
Dictionary<int, DoubleValue> _RowHeightList = new Dictionary<int, DoubleValue>();
|
||||
public Dictionary<int, DoubleValue> RowHeightList
|
||||
{
|
||||
get { return _RowHeightList; }
|
||||
}
|
||||
}
|
||||
}
|
292
IronIntelContractorBusiness/ExportExcelManager.cs
Normal file
292
IronIntelContractorBusiness/ExportExcelManager.cs
Normal file
@ -0,0 +1,292 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Services.Customers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class ExportExcelManager
|
||||
{
|
||||
public static byte[] ExportRentals(string sessionid, string companyid, long machineid, DateTime from, DateTime to, string searchtext, string useriid, string sortPath, bool desc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
AssetRentalInfo[] rentalinfos = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAssetRentals(companyid, searchtext, useriid);
|
||||
|
||||
List<MachineRentalInfo> ls = new List<MachineRentalInfo>();
|
||||
foreach (AssetRentalInfo ri in rentalinfos)
|
||||
{
|
||||
MachineRentalInfo mi = new MachineRentalInfo();
|
||||
Helper.CloneProperty(mi, ri);
|
||||
mi.RentalRate = (decimal)ri.RentalRate;
|
||||
ls.Add(mi);
|
||||
}
|
||||
|
||||
var rentals = ls.ToArray();
|
||||
if (machineid > 0)
|
||||
rentals = rentals.Where(m => m.MachineID == machineid).ToArray();
|
||||
|
||||
rentals = rentals.Where(m => m.RentalDate >= from && m.RentalDate <= to).ToArray();
|
||||
|
||||
if (!string.IsNullOrEmpty(sortPath))
|
||||
{
|
||||
if (desc)
|
||||
{
|
||||
rentals = rentals.OrderByDescending(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
rentals = rentals.OrderBy(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
ExportToExcel ete = new ExportToExcel();
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "VIN/SN" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Asset Name" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Outside/Internal" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Vendor" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Rate" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Term" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Term Unit" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Date On" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Project Return Date" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Return Date" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Purchase Order #" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Comments" });
|
||||
|
||||
foreach (var r in rentals)
|
||||
{
|
||||
var dr = dt.NewRow();
|
||||
dr[0] = r.VIN;
|
||||
dr[1] = r.ShowName;
|
||||
dr[2] = r.Outside;
|
||||
dr[3] = r.Vendor;
|
||||
dr[4] = r.RentalRate;
|
||||
dr[5] = r.Term;
|
||||
dr[6] = r.TermUnit;
|
||||
dr[7] = r.RentalDateStr;
|
||||
dr[8] = r.ProjectReturnDateStr;
|
||||
dr[9] = r.ReturnDateStr;
|
||||
dr[10] = r.PONumber;
|
||||
dr[11] = r.Comments;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
double[] widths = new double[] { 180d, 180d, 180d, 150d, 150d, 150d, 150d, 150d, 150d, 150d, 150d, 200d };
|
||||
byte[] data = ete.CreateExcel(dt, null, widths, null);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] ExportRentalChanges(string sessionid, string companyid, long machineid, long rentalid, DateTime from, DateTime to, string searchtext, string useriid, string sortPath, bool desc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
AssetRentalChangeHistoryInfo[] assetrentals = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAssetRentalChangeHistory(companyid, Convert.ToInt64(rentalid));
|
||||
List<RentalChangeHistoryInfo> rentalHistory = new List<RentalChangeHistoryInfo>();
|
||||
foreach (AssetRentalChangeHistoryInfo ari in assetrentals)
|
||||
{
|
||||
RentalChangeHistoryInfo mri = new RentalChangeHistoryInfo();
|
||||
Helper.CloneProperty(mri, ari);
|
||||
mri.RentalRate = (decimal)ari.RentalRate;
|
||||
rentalHistory.Add(mri);
|
||||
}
|
||||
|
||||
if (machineid > 0)
|
||||
rentalHistory = rentalHistory.Where(m => m.MachineID == machineid).ToList();
|
||||
|
||||
if (rentalid > 0)
|
||||
rentalHistory = rentalHistory.Where(m => m.RentalID == rentalid).ToList();
|
||||
|
||||
rentalHistory = rentalHistory.Where(m => m.RentalDate >= from && m.RentalDate <= to).ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(sortPath))
|
||||
{
|
||||
if (desc)
|
||||
{
|
||||
rentalHistory = rentalHistory.OrderByDescending(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
rentalHistory = rentalHistory.OrderBy(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
ExportToExcel ete = new ExportToExcel();
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental ID" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "User Name" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Last Update Date" });
|
||||
//dt.Columns.Add(new DataColumn() { ColumnName = "Operate Type" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "VIN/SN" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Asset Name" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Outside/Internal" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Vendor" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Rate" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Term" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Term Unit" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Rental Date On" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Project Return Date" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Return Date" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Purchase Order #" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Comments" });
|
||||
|
||||
foreach (var r in rentalHistory)
|
||||
{
|
||||
var dr = dt.NewRow();
|
||||
dr[0] = r.RentalID;
|
||||
dr[1] = r.LastUpdateUserName;
|
||||
dr[2] = r.LastUpdateDateStr;
|
||||
//dr[3] = r.OperateType;
|
||||
dr[3] = r.VIN;
|
||||
dr[4] = r.ShowName;
|
||||
dr[5] = r.Outside;
|
||||
dr[6] = r.Vendor;
|
||||
dr[7] = r.RentalRate;
|
||||
dr[8] = r.Term;
|
||||
dr[9] = r.TermUnit;
|
||||
dr[10] = r.RentalDateStr;
|
||||
dr[11] = r.ProjectReturnDateStr;
|
||||
dr[12] = r.ReturnDateStr;
|
||||
dr[13] = r.PONumber;
|
||||
dr[14] = r.Comments;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
double[] widths = new double[] { 120d, 150d, 150d, 180d, 180d, 180d, 150d, 150d, 150d, 150d, 150d, 150d, 150d, 150d, 200d };
|
||||
byte[] data = ete.CreateExcel(dt, null, widths, null);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] ExportOdometerAdjustHistory(string sessionid, string companyid, long machineid, DateTime from, DateTime to, string sortPath, bool desc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
AssetOdometerAdjustInfo[] odoHistory = FleetServiceClientHelper.CreateClient<AssetDataAdjustClient>(companyid, sessionid).GetOdometerAdjustmentHistory(companyid, machineid, from, to);
|
||||
if (!string.IsNullOrEmpty(sortPath))
|
||||
{
|
||||
if (desc)
|
||||
{
|
||||
odoHistory = odoHistory.OrderByDescending(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
odoHistory = odoHistory.OrderBy(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
ExportToExcel ete = new ExportToExcel();
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "User Name" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Adjustment Time" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Odometer Entered" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Odometer UOM" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Odometer Time" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Notes" });
|
||||
|
||||
foreach (var r in odoHistory)
|
||||
{
|
||||
var dr = dt.NewRow();
|
||||
dr[0] = r.UserName;
|
||||
dr[1] = r.AdjustmentLocalTime.ToString("MM/dd/yyyy HH:mm");
|
||||
dr[2] = r.Odometer;
|
||||
dr[3] = r.UOM;
|
||||
dr[4] = r.OdometerLocalTime.ToString("MM/dd/yyyy HH:mm");
|
||||
dr[5] = r.Notes;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
double[] widths = new double[] { 200d, 150d, 150d, 150d, 150d, 300d };
|
||||
byte[] data = ete.CreateExcel(dt, null, widths, null);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] ExportEngineHoursAdjustHistory(string sessionid, string companyid, long machineid, DateTime from, DateTime to, string sortPath, bool desc)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
AssetEngineHoursAdjustInfo[] ehHistory = FleetServiceClientHelper.CreateClient<AssetDataAdjustClient>(companyid, sessionid).GetEngineHoursAdjustmentHistory(companyid, machineid, from, to);
|
||||
if (!string.IsNullOrEmpty(sortPath))
|
||||
{
|
||||
if (desc)
|
||||
{
|
||||
ehHistory = ehHistory.OrderByDescending(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
ehHistory = ehHistory.OrderBy(m =>
|
||||
{
|
||||
return OrderHandler(m, sortPath);
|
||||
}).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
ExportToExcel ete = new ExportToExcel();
|
||||
|
||||
DataTable dt = new DataTable();
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "User Name" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Adjustment Time" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Engine Hours Entered" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Engine Hours Time" });
|
||||
dt.Columns.Add(new DataColumn() { ColumnName = "Notes" });
|
||||
|
||||
foreach (var r in ehHistory)
|
||||
{
|
||||
var dr = dt.NewRow();
|
||||
dr[0] = r.UserName;
|
||||
dr[1] = r.AdjustmentLocalTime.ToString("MM/dd/yyyy HH:mm");
|
||||
dr[2] = r.EngineHours;
|
||||
dr[3] = r.EngineHoursLocalTime.ToString("MM/dd/yyyy HH:mm");
|
||||
dr[4] = r.Notes;
|
||||
dt.Rows.Add(dr);
|
||||
}
|
||||
double[] widths = new double[] { 200d, 150d, 150d, 150d, 300d };
|
||||
byte[] data = ete.CreateExcel(dt, null, widths, null);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
private static object OrderHandler(object obj, string sortPath)
|
||||
{
|
||||
Type type = obj.GetType();
|
||||
System.Reflection.PropertyInfo propertyInfo = type.GetProperty(sortPath);
|
||||
if (propertyInfo != null)
|
||||
return propertyInfo.GetValue(obj, null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
31
IronIntelContractorBusiness/FITracker/FITrackerManagement.cs
Normal file
31
IronIntelContractorBusiness/FITracker/FITrackerManagement.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Foresight;
|
||||
using Foresight.Data;
|
||||
using Foresight.Fleet.Services.FITracker;
|
||||
|
||||
namespace IronIntel.Contractor.FITracker
|
||||
{
|
||||
public class FITrackerManagement
|
||||
{
|
||||
public static MobileDeviceInfo[] GetTrackerDevices(string sessionid, string searchtext)
|
||||
{
|
||||
TrackerClient client = FleetServiceClientHelper.CreateClient<TrackerClient>(sessionid);
|
||||
return client.GetMobileDevices(SystemParams.CompanyID);
|
||||
}
|
||||
|
||||
public static ChatMessageInfo[] GetMessages(string sessionid, string deviceid, long lastmsgid)
|
||||
{
|
||||
TrackerClient client = FleetServiceClientHelper.CreateClient<TrackerClient>(sessionid);
|
||||
return client.GetChatMessages(deviceid, SystemParams.CompanyID, lastmsgid);
|
||||
}
|
||||
public static ChatMessageInfo PostMessage(string sessionid, string deviceid, string senderiid, string sendername, string msg, int type)
|
||||
{
|
||||
TrackerClient client = FleetServiceClientHelper.CreateClient<TrackerClient>(sessionid);
|
||||
return client.PostChatMessage(deviceid, senderiid, sendername, msg, type);
|
||||
}
|
||||
public static void ChangeAcceptableAccuracy(string sessionid, string deviceid, double accuracy, string note, string userid)
|
||||
{
|
||||
TrackerClient client = FleetServiceClientHelper.CreateClient<TrackerClient>(sessionid);
|
||||
client.ChangeAcceptableAccuracy(deviceid, accuracy, note, userid);
|
||||
}
|
||||
}
|
||||
}
|
236
IronIntelContractorBusiness/FilterQ/FilterQManagememt.cs
Normal file
236
IronIntelContractorBusiness/FilterQ/FilterQManagememt.cs
Normal file
@ -0,0 +1,236 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.FilterQ
|
||||
{
|
||||
public class FilterQManagememt
|
||||
{
|
||||
private static readonly string CLASSNAME = typeof(FilterQManagememt).FullName;
|
||||
|
||||
private static string IronIntelDbString
|
||||
{
|
||||
get { return ConfigurationManager.AppSettings["JRE_IronIntelDb"]; }
|
||||
}
|
||||
|
||||
private static void ChangeViewToTable()
|
||||
{
|
||||
const string SQL = @"insert into MACHINETASKS(TaskId,MACHINEID,TASKDESCRIPTION,TASKCOMPLETE,CUSTOMERPO,PRIORITY,SHIPNOTES,CURRENT_JOB,JOBCONTACT,JOBCONTACTNUMBER,
|
||||
JOBMAILSHIPADDRESS1,JOBMAILSHIPADDRESS2,JOBMAILSHIPADDRESSCITY,JOBMAILSHIPADDRESSSTATE,JOBMAILSHIPADDRESSZIP,ORGANIZATIONMACHINECODE,MANUFACTURERMAKE,
|
||||
MODEL,SN,CUMULATIVE_HOURS,MACHINETASKHOURCHECK,DIFFTOSERVICE,ESTSERVICENEEDEDBY,ESTSHIPDATE,ORGID,ORGANIZATIONNAME,MACHINETASKTYPEID)
|
||||
select v.TaskId,v.MACHINEID,v.TASKDESCRIPTION,v.TASKCOMPLETE,v.CUSTOMERPO,v.PRIORITY,v.ShipNotes,v.CURRENT_JOB,v.JOBCONTACT,
|
||||
v.JobContactNumber,v.JobMailShipAddress1,v.JobMailShipAddress2,v.JobMailShipAddressCity,v.JobMailShipAddressState,v.JobMailShipAddressZip,
|
||||
v.ORGANIZATIONMACHINECODE,v.MANUFACTURERMAKE,v.MODEL,v.SN,v.Cumulative_Hours,v.MachineTaskHourCheck,v.DIFFTOSERVICE,v.ESTSERVICENEEDEDBY,
|
||||
v.ESTSHIPDATE,v.ORGID,v.ORGANIZATIONNAME,m.MACHINETASKTYPEID from vwMACHINETASKSNOTIFICATION as v, vwMACHINETASKS as m
|
||||
where v.taskid=m.TaskId and v.TaskId not in(select TaskId from MACHINETASKS)";
|
||||
const string SQL_V = @"update a set MACHINEID=b.MACHINEID,CURRENT_JOB=b.CURRENT_JOB,JOBCONTACT=b.JOBCONTACT,JOBCONTACTNUMBER=b.JOBCONTACTNUMBER,JOBMAILSHIPADDRESS1=b.JOBMAILSHIPADDRESS1,
|
||||
JOBMAILSHIPADDRESS2=b.JOBMAILSHIPADDRESS2,JOBMAILSHIPADDRESSCITY=b.JOBMAILSHIPADDRESSCITY,JOBMAILSHIPADDRESSSTATE=b.JOBMAILSHIPADDRESSSTATE,JOBMAILSHIPADDRESSZIP=b.JOBMAILSHIPADDRESSZIP,
|
||||
ORGANIZATIONMACHINECODE=b.ORGANIZATIONMACHINECODE,MANUFACTURERMAKE=b.MANUFACTURERMAKE,MODEL=b.MODEL,SN=b.SN,CUMULATIVE_HOURS=b.CUMULATIVE_HOURS,
|
||||
MACHINETASKHOURCHECK=b.MACHINETASKHOURCHECK,DIFFTOSERVICE=b.DIFFTOSERVICE,ESTSERVICENEEDEDBY=b.ESTSERVICENEEDEDBY,ESTSHIPDATE=b.ESTSHIPDATE,
|
||||
ORGID=b.ORGID,ORGANIZATIONNAME=b.ORGANIZATIONNAME,DATALOADEDFROMVIEW=1
|
||||
from MACHINETASKS a,vwMACHINETASKSNOTIFICATION b where a.TaskId = b.TaskId and isnull(a.DATALOADEDFROMVIEW,0)=0";
|
||||
FISqlConnection db = new FISqlConnection(IronIntelDbString);
|
||||
db.ExecSQL(SQL);
|
||||
db.ExecSQL(SQL_V);
|
||||
}
|
||||
|
||||
public static MachineTasksNotificationInfo[] GetTasksNotofications()
|
||||
{
|
||||
const string SQL_1 = @"select TASKID,MACHINEID,CURRENT_JOB,JOBCONTACT,JOBCONTACTNUMBER,JOBMAILSHIPADDRESS1,JOBMAILSHIPADDRESS2,JOBMAILSHIPADDRESSCITY,JOBMAILSHIPADDRESSSTATE,JOBMAILSHIPADDRESSZIP,
|
||||
ORGANIZATIONMACHINECODE,MANUFACTURERMAKE,MODEL,SN,CUMULATIVE_HOURS,MACHINETASKHOURCHECK,DIFFTOSERVICE,ESTSERVICENEEDEDBY,ESTSHIPDATE,UPSTRACKINGNUMBER,REQUESTJRETOSERVICE,
|
||||
APPROVEDBY,PRIORITY,CUSTOMERPO,CUSTOMERWO,ALTERNATEMAILSHIPADDRESS1,ALTERNATEMAILSHIPADDRESS2,ALTERNATEMAILSHIPADDRESSCITY,ALTERNATEMAILSHIPADDRESSSTATE,ALTERNATEMAILSHIPADDRESSZIP,
|
||||
SHIPNOTES,ORGANIZATIONNAME,TASKCOMPLETE, TASKCOMPLETEDHOURS,ALTJOB,ALTJOBSITECONTACT from MACHINETASKS where ESTSHIPDATE is not null";
|
||||
const string SQL_2 = SQL_1 + " and ORGID in(select ORGID from ORGANIZATION o where o.CONTRACTORSITEID={0})";
|
||||
|
||||
ChangeViewToTable();
|
||||
var company = SystemParams.CustomerDetail;
|
||||
FISqlConnection db = new FISqlConnection(IronIntelDbString);
|
||||
DataTable dt = null;
|
||||
if (company.IsDealer)
|
||||
{
|
||||
dt = db.GetDataTableBySQL(SQL_1 + " order by CURRENT_JOB,JOBCONTACT");
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = db.GetDataTableBySQL(SQL_2 + " order by CURRENT_JOB,JOBCONTACT", company.ID);
|
||||
}
|
||||
|
||||
List<MachineTasksNotificationInfo> list = new List<MachineTasksNotificationInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineTasksNotificationInfo tt = new MachineTasksNotificationInfo();
|
||||
tt.TaskID = FIDbAccess.GetFieldString(dr["TASKID"], string.Empty);
|
||||
tt.MachineID = FIDbAccess.GetFieldString(dr["MACHINEID"], string.Empty);
|
||||
tt.CurrentJob = FIDbAccess.GetFieldString(dr["CURRENT_JOB"], string.Empty);
|
||||
tt.JobContact = FIDbAccess.GetFieldString(dr["JOBCONTACT"], string.Empty);
|
||||
tt.JobContactNumber = FIDbAccess.GetFieldString(dr["JOBCONTACTNUMBER"], string.Empty);
|
||||
tt.JobAddress1 = FIDbAccess.GetFieldString(dr["JOBMAILSHIPADDRESS1"], string.Empty);
|
||||
tt.JobAddress2 = FIDbAccess.GetFieldString(dr["JOBMAILSHIPADDRESS2"], string.Empty);
|
||||
tt.JobAddressCity = FIDbAccess.GetFieldString(dr["JOBMAILSHIPADDRESSCITY"], string.Empty);
|
||||
tt.JobAddressState = FIDbAccess.GetFieldString(dr["JOBMAILSHIPADDRESSSTATE"], string.Empty);
|
||||
tt.JobAddressZip = FIDbAccess.GetFieldString(dr["JOBMAILSHIPADDRESSZIP"], string.Empty);
|
||||
tt.OrgMachineCode = FIDbAccess.GetFieldString(dr["ORGANIZATIONMACHINECODE"], string.Empty);
|
||||
tt.ManufactuerMake = FIDbAccess.GetFieldString(dr["MANUFACTURERMAKE"], string.Empty);
|
||||
tt.Model = FIDbAccess.GetFieldString(dr["MODEL"], string.Empty);
|
||||
tt.SN = FIDbAccess.GetFieldString(dr["SN"], string.Empty);
|
||||
tt.CumulativeHours = FIDbAccess.GetFieldDouble(dr["CUMULATIVE_HOURS"], 0);
|
||||
tt.MachineTaskHourCheck = FIDbAccess.GetFieldInt(dr["MACHINETASKHOURCHECK"], 0);
|
||||
tt.DiffToService = FIDbAccess.GetFieldDouble(dr["DIFFTOSERVICE"], 0);
|
||||
tt.ESTServiceNeededBy = FIDbAccess.GetFieldDateTime(dr["ESTSERVICENEEDEDBY"], DateTime.MinValue);
|
||||
tt.ESTShopDate = FIDbAccess.GetFieldDateTime(dr["ESTSHIPDATE"], DateTime.MinValue);
|
||||
tt.UPSTrackingNumber = FIDbAccess.GetFieldString(dr["UPSTRACKINGNUMBER"], string.Empty);
|
||||
tt.RequestJREToService = FIDbAccess.GetFieldInt(dr["REQUESTJRETOSERVICE"], 0) == 1;
|
||||
string by = FIDbAccess.GetFieldString(dr["APPROVEDBY"], string.Empty);
|
||||
tt.Approved = (!string.IsNullOrWhiteSpace(by) && by != Guid.Empty.ToString() ? true : false);
|
||||
tt.Priority = FIDbAccess.GetFieldString(dr["PRIORITY"], string.Empty);
|
||||
tt.CustomerPO = FIDbAccess.GetFieldString(dr["CUSTOMERPO"], string.Empty);
|
||||
tt.CustomerWO = FIDbAccess.GetFieldString(dr["CUSTOMERWO"], string.Empty);
|
||||
tt.AlternateAddress1 = FIDbAccess.GetFieldString(dr["ALTERNATEMAILSHIPADDRESS1"], string.Empty);
|
||||
tt.AlternateAddress2 = FIDbAccess.GetFieldString(dr["ALTERNATEMAILSHIPADDRESS2"], string.Empty);
|
||||
tt.AlternateAddressCity = FIDbAccess.GetFieldString(dr["ALTERNATEMAILSHIPADDRESSCITY"], string.Empty);
|
||||
tt.AlternateAddressState = FIDbAccess.GetFieldString(dr["ALTERNATEMAILSHIPADDRESSSTATE"], string.Empty);
|
||||
tt.AlternateAddressZip = FIDbAccess.GetFieldString(dr["ALTERNATEMAILSHIPADDRESSZIP"], string.Empty);
|
||||
tt.ShipNotes = FIDbAccess.GetFieldString(dr["SHIPNOTES"], string.Empty);
|
||||
tt.OrganizationName = FIDbAccess.GetFieldString(dr["ORGANIZATIONNAME"], string.Empty);
|
||||
tt.TaskComplete = FIDbAccess.GetFieldInt(dr["TASKCOMPLETE"], 0) == 1;
|
||||
tt.TaskCompletedHours = FIDbAccess.GetFieldDouble(dr["TASKCOMPLETEDHOURS"], 0);
|
||||
tt.AltJob = FIDbAccess.GetFieldString(dr["ALTJOB"], string.Empty);
|
||||
tt.AltJobSiteContact = FIDbAccess.GetFieldString(dr["ALTJOBSITECONTACT"], string.Empty);
|
||||
list.Add(tt);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static void SaveMachineTasks(MachineTasksNotificationInfo[] tasks, string useriid)
|
||||
{
|
||||
var company = SystemParams.CustomerDetail;
|
||||
if (company.IsContractor)
|
||||
{
|
||||
SaveByContractor(tasks, useriid);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveByDealer(tasks, useriid);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveTaskHistory(FIDbTransaction tran, string taskid)
|
||||
{
|
||||
const string SQL_H = @"insert into MACHINETASKS_HISTORY(TaskId,MACHINEID,MACHINETASKTYPEID,TASKDESCRIPTION,TASKDATE,TASKCOMPLETE,NOTIFICATIONSENT,TASKCOMPLETEDATE
|
||||
,LASTUPDATEDATE,CUSTOMERPO,PRIORITY,SHIPDATE,SHIPNOTES,ALTERNATIVESHIPCONTACT,OVERRIDEJOBID,ALTERNATEMAILSHIPADDRESS1
|
||||
,ALTERNATEMAILSHIPADDRESS2 ,ALTERNATEMAILSHIPADDRESSSTATE,ALTERNATEMAILSHIPADDRESSZIP,ALTERNATEMAILSHIPADDRESSCITY,APPROVEDBY
|
||||
,CUSTOMERWO ,ALTERNATESHIPCONTACTNUMBER ,REQUESTDEALERTOSERVICE ,SHIPTRACKINGNO,SHIPTRACKINGSTATUS,UPSTRACKINGNUMBER ,REQUESTJRETOSERVICE
|
||||
,CURRENT_JOB ,JOBCONTACT,JOBCONTACTNUMBER,JOBMAILSHIPADDRESS1 ,JOBMAILSHIPADDRESS2,JOBMAILSHIPADDRESSCITY,JOBMAILSHIPADDRESSSTATE
|
||||
,JOBMAILSHIPADDRESSZIP,ORGANIZATIONMACHINECODE ,MANUFACTURERMAKE,MODEL,SN,CUMULATIVE_HOURS ,MACHINETASKHOURCHECK ,DIFFTOSERVICE
|
||||
,ESTSERVICENEEDEDBY,ESTSHIPDATE,LASTUPDATEDON ,LASTUPDATEDBY,RECVER,APPROVEDDATETIME,INSERTDATE,TASKCOMPLETEDHOURS,ORGID,ORGANIZATIONNAME,DATALOADEDFROMVIEW
|
||||
,ALTJOB,ALTJOBSITECONTACT)
|
||||
select TaskId,MACHINEID,MACHINETASKTYPEID,TASKDESCRIPTION,TASKDATE,TASKCOMPLETE,NOTIFICATIONSENT,TASKCOMPLETEDATE
|
||||
,LASTUPDATEDATE,CUSTOMERPO,PRIORITY,SHIPDATE,SHIPNOTES,ALTERNATIVESHIPCONTACT,OVERRIDEJOBID,ALTERNATEMAILSHIPADDRESS1
|
||||
,ALTERNATEMAILSHIPADDRESS2 ,ALTERNATEMAILSHIPADDRESSSTATE,ALTERNATEMAILSHIPADDRESSZIP,ALTERNATEMAILSHIPADDRESSCITY,APPROVEDBY
|
||||
,CUSTOMERWO ,ALTERNATESHIPCONTACTNUMBER ,REQUESTDEALERTOSERVICE ,SHIPTRACKINGNO,SHIPTRACKINGSTATUS,UPSTRACKINGNUMBER ,REQUESTJRETOSERVICE
|
||||
,CURRENT_JOB ,JOBCONTACT,JOBCONTACTNUMBER,JOBMAILSHIPADDRESS1 ,JOBMAILSHIPADDRESS2,JOBMAILSHIPADDRESSCITY,JOBMAILSHIPADDRESSSTATE
|
||||
,JOBMAILSHIPADDRESSZIP,ORGANIZATIONMACHINECODE ,MANUFACTURERMAKE,MODEL,SN,CUMULATIVE_HOURS ,MACHINETASKHOURCHECK ,DIFFTOSERVICE
|
||||
,ESTSERVICENEEDEDBY,ESTSHIPDATE,LASTUPDATEDON ,LASTUPDATEDBY,RECVER,APPROVEDDATETIME,GETUTCDATE(),TASKCOMPLETEDHOURS,ORGID,ORGANIZATIONNAME,DATALOADEDFROMVIEW
|
||||
,ALTJOB,ALTJOBSITECONTACT
|
||||
from MACHINETASKS where TaskId={0}";
|
||||
tran.ExecSQL(SQL_H, taskid);
|
||||
}
|
||||
|
||||
|
||||
private static void SaveByDealer(MachineTasksNotificationInfo[] tasks, string useriid)
|
||||
{
|
||||
const string SQL_D = @"update MACHINETASKS set REQUESTJRETOSERVICE={0},LASTUPDATEDBY={1},PRIORITY={2},CUSTOMERPO={3},CUSTOMERWO={4},ALTERNATEMAILSHIPADDRESS1={5},
|
||||
ALTERNATEMAILSHIPADDRESS2 ={6},ALTERNATEMAILSHIPADDRESSCITY ={7},ALTERNATEMAILSHIPADDRESSSTATE ={8},ALTERNATEMAILSHIPADDRESSZIP ={9},SHIPNOTES ={10}, LASTUPDATEDON = GETUTCDATE(),
|
||||
RECVER = isnull(RECVER, 0) + 1,UPSTRACKINGNUMBER ={11},TASKCOMPLETE ={12},TASKCOMPLETEDHOURS ={13},JOBMAILSHIPADDRESS1 ={14},JOBMAILSHIPADDRESS2 ={15},
|
||||
JOBMAILSHIPADDRESSCITY ={16},JOBMAILSHIPADDRESSSTATE ={17},JOBMAILSHIPADDRESSZIP ={18},ORGANIZATIONMACHINECODE ={19},MANUFACTURERMAKE ={20},MODEL ={21},
|
||||
CUMULATIVE_HOURS ={22},MACHINETASKHOURCHECK ={23},DIFFTOSERVICE ={24},ESTSERVICENEEDEDBY ={25},ESTSHIPDATE ={26},JOBCONTACTNUMBER ={27},JOBCONTACT={28},ORGANIZATIONNAME={29},
|
||||
ALTJOB={31},ALTJOBSITECONTACT={32},APPROVEDBY={33} where TaskId = {30}";
|
||||
foreach (MachineTasksNotificationInfo ts in tasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (FISqlTransaction tran = new FISqlTransaction(IronIntelDbString))
|
||||
{
|
||||
SaveTaskHistory(tran, ts.TaskID);
|
||||
tran.ExecSQL(SQL_D, ts.RequestJREToService, useriid, ts.Priority, ts.CustomerPO, ts.CustomerWO, ts.AlternateAddress1, ts.AlternateAddress2, ts.AlternateAddressCity, ts.AlternateAddressState,
|
||||
ts.AlternateAddressZip, ts.ShipNotes, ts.UPSTrackingNumber, ts.TaskComplete, ts.TaskCompletedHours, ts.JobAddress1, ts.JobAddress2, ts.JobAddressCity, ts.JobAddressState, ts.JobAddressZip,
|
||||
ts.OrgMachineCode, ts.ManufactuerMake, ts.Model, ts.CumulativeHours, ts.MachineTaskHourCheck, ts.DiffToService, ts.ESTServiceNeededBy, ts.ESTShopDate, ts.JobContactNumber, ts.JobContact,
|
||||
ts.OrganizationName, ts.TaskID, ts.AltJob, ts.AltJobSiteContact, ts.Approved ? useriid : Guid.Empty.ToString());
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(ts.ToString());
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(ex.ToString());
|
||||
SystemParams.WriteLog("Error", CLASSNAME + ".SaveByDealer", ex.Message, sb.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private static void SaveByContractor(MachineTasksNotificationInfo[] tasks, string useriid)
|
||||
{
|
||||
const string SQL_C1 = @"update MACHINETASKS set REQUESTJRETOSERVICE ={0},LASTUPDATEDBY ={1},PRIORITY ={2},CUSTOMERPO={3},CUSTOMERWO={4},ALTERNATEMAILSHIPADDRESS1={5},
|
||||
ALTERNATEMAILSHIPADDRESS2={6},ALTERNATEMAILSHIPADDRESSCITY={7},ALTERNATEMAILSHIPADDRESSSTATE ={8}, ALTERNATEMAILSHIPADDRESSZIP ={9},SHIPNOTES ={10},LASTUPDATEDON=GETUTCDATE(),
|
||||
RECVER=isnull(RECVER,0)+1,APPROVEDBY=NULL,APPROVEDDATETIME=NULL,ALTJOB={12},ALTJOBSITECONTACT={13},TASKCOMPLETEDHOURS={14} where TaskId={11}";
|
||||
const string SQL_C2 = @"update MACHINETASKS set REQUESTJRETOSERVICE={0},LASTUPDATEDBY={1},PRIORITY={2},CUSTOMERPO={3},CUSTOMERWO={4},ALTERNATEMAILSHIPADDRESS1={5},ALTERNATEMAILSHIPADDRESS2={6},
|
||||
ALTERNATEMAILSHIPADDRESSCITY={7},ALTERNATEMAILSHIPADDRESSSTATE={8},ALTERNATEMAILSHIPADDRESSZIP={9},SHIPNOTES={10}, LASTUPDATEDON=GETUTCDATE(), RECVER=isnull(RECVER,0)+1,APPROVEDBY={1},
|
||||
APPROVEDDATETIME=GETUTCDATE() ,ALTJOB={12},ALTJOBSITECONTACT={13},TASKCOMPLETEDHOURS={14} where TaskId={11}";
|
||||
const string SQL_C3 = @"update MACHINETASKS set REQUESTJRETOSERVICE={0},LASTUPDATEDBY={1},PRIORITY={2},CUSTOMERPO={3},CUSTOMERWO={4},ALTERNATEMAILSHIPADDRESS1={5},
|
||||
ALTERNATEMAILSHIPADDRESS2={6},ALTERNATEMAILSHIPADDRESSCITY={7},ALTERNATEMAILSHIPADDRESSSTATE={8},ALTERNATEMAILSHIPADDRESSZIP={9},SHIPNOTES={10}, LASTUPDATEDON=GETUTCDATE(),
|
||||
RECVER=isnull(RECVER,0)+1,ALTJOB={12},ALTJOBSITECONTACT={13},TASKCOMPLETEDHOURS={14} where TaskId={11}";
|
||||
const string SQL_sel = "select APPROVEDBY from MACHINETASKS where TaskId={0}";
|
||||
|
||||
FISqlConnection db = new FISqlConnection(IronIntelDbString);
|
||||
foreach (MachineTasksNotificationInfo ts in tasks)
|
||||
{
|
||||
try
|
||||
{
|
||||
string approvedby = FIDbAccess.GetFieldString(db.GetRC1BySQL(SQL_sel, ts.TaskID), string.Empty);
|
||||
using (FISqlTransaction tran = new FISqlTransaction(IronIntelDbString))
|
||||
{
|
||||
SaveTaskHistory(tran, ts.TaskID);
|
||||
if (ts.Approved)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(approvedby))
|
||||
{
|
||||
tran.ExecSQL(SQL_C2, ts.RequestJREToService, useriid, ts.Priority, ts.CustomerPO, ts.CustomerWO, ts.AlternateAddress1, ts.AlternateAddress2, ts.AlternateAddressCity, ts.AlternateAddressState,
|
||||
ts.AlternateAddressZip, ts.ShipNotes, ts.TaskID, ts.AltJob, ts.AltJobSiteContact, ts.TaskCompletedHours);
|
||||
}
|
||||
else
|
||||
{
|
||||
tran.ExecSQL(SQL_C3, ts.RequestJREToService, useriid, ts.Priority, ts.CustomerPO, ts.CustomerWO, ts.AlternateAddress1, ts.AlternateAddress2, ts.AlternateAddressCity, ts.AlternateAddressState,
|
||||
ts.AlternateAddressZip, ts.ShipNotes, ts.TaskID, ts.AltJob, ts.AltJobSiteContact, ts.TaskCompletedHours);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tran.ExecSQL(SQL_C1, ts.RequestJREToService, useriid, ts.Priority, ts.CustomerPO, ts.CustomerWO, ts.AlternateAddress1, ts.AlternateAddress2, ts.AlternateAddressCity, ts.AlternateAddressState,
|
||||
ts.AlternateAddressZip, ts.ShipNotes, ts.TaskID, ts.AltJob, ts.AltJobSiteContact, ts.TaskCompletedHours);
|
||||
}
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(ts.ToString());
|
||||
sb.AppendLine();
|
||||
sb.AppendLine(ex.ToString());
|
||||
SystemParams.WriteLog("Error", CLASSNAME + ".SaveByContractor", ex.Message, sb.ToString());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight;
|
||||
|
||||
namespace IronIntel.Contractor.FilterQ
|
||||
{
|
||||
public class MachineTasksNotificationInfo
|
||||
{
|
||||
public string TaskID { get; set; }
|
||||
public string MachineID { get; set; }
|
||||
public string CurrentJob { get; set; }
|
||||
public string JobContact { get; set; }
|
||||
public string JobContactNumber { get; set; }
|
||||
public string JobAddress1 { get; set; }
|
||||
public string JobAddress2 { get; set; }
|
||||
public string JobAddressCity { get; set; }
|
||||
public string JobAddressState { get; set; }
|
||||
public string JobAddressZip { get; set; }
|
||||
public string OrgMachineCode { get; set; }
|
||||
public string ManufactuerMake { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string SN { get; set; }
|
||||
public double CumulativeHours { get; set; }
|
||||
public int MachineTaskHourCheck { get; set; }
|
||||
public double DiffToService { get; set; }
|
||||
public DateTime ESTServiceNeededBy { get; set; }
|
||||
public DateTime ESTShopDate { get; set; }
|
||||
public string UPSTrackingNumber { get; set; }
|
||||
public bool RequestJREToService { get; set; }
|
||||
public bool Approved { get; set; }
|
||||
public string Priority { get; set; }
|
||||
public string CustomerPO { get; set; }
|
||||
public string CustomerWO { get; set; }
|
||||
public string AlternateAddress1 { get; set; }
|
||||
public string AlternateAddress2 { get; set; }
|
||||
public string AlternateAddressCity { get; set; }
|
||||
public string AlternateAddressState { get; set; }
|
||||
public string AlternateAddressZip { get; set; }
|
||||
public string ShipNotes { get; set; }
|
||||
public string OrganizationName { get; set; }
|
||||
|
||||
public bool TaskComplete { get; set; }
|
||||
public double TaskCompletedHours { get; set; }
|
||||
|
||||
public string AltJob { get; set; }
|
||||
public string AltJobSiteContact { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
XmlDocument doc = XmlHelper.CreateXmlDocument();
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "TaskID", TaskID);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "MachineID", MachineID);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "CurrentJob", CurrentJob);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobContact", JobContact);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobContactNumber", JobContactNumber);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobAddress1", JobAddress1);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobAddress2", JobAddress2);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobAddressCity", JobAddressCity);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobAddressState", JobAddressState);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "JobAddressZip", JobAddressZip);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "OrgMachineCode", OrgMachineCode);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "ManufactuerMake", ManufactuerMake);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "Model", Model);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "SN", SN);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "CumulativeHours", CumulativeHours.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "MachineTaskHourCheck", MachineTaskHourCheck.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "DiffToService", DiffToService.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "ESTServiceNeededBy", ESTServiceNeededBy.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "ESTShopDate", ESTShopDate.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "UPSTrackingNumber", UPSTrackingNumber);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "RequestJREToService", RequestJREToService ? "True" : "False");
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "Approved", Approved ? "True" : "False");
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "Priority", Priority);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "CustomerPO", CustomerPO);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "CustomerWO", CustomerWO);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AlternateAddress1", AlternateAddress1);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AlternateAddress2", AlternateAddress2);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AlternateAddressCity", AlternateAddressCity);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AlternateAddressState", AlternateAddressState);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AlternateAddressZip", AlternateAddressZip);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "ShipNotes", ShipNotes);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "OrganizationName", OrganizationName);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "TaskComplete", TaskComplete ? "True" : "False");
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "TaskCompletedHours", TaskCompletedHours.ToString());
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AltJob", AltJob);
|
||||
XmlHelper.AppendChildNode(doc.DocumentElement, "AltJobSiteContact", AltJobSiteContact);
|
||||
return doc.InnerXml;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
50
IronIntelContractorBusiness/FleetServiceClientHelper.cs
Normal file
50
IronIntelContractorBusiness/FleetServiceClientHelper.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Configuration;
|
||||
using Foresight.Fleet.Services;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public static class FleetServiceClientHelper
|
||||
{
|
||||
private static string[] FleetAssetServiceAddresses = null;
|
||||
|
||||
static FleetServiceClientHelper()
|
||||
{
|
||||
string addresses = ConfigurationManager.AppSettings["FleetAssetServiceAddress"];
|
||||
if (!string.IsNullOrWhiteSpace(addresses))
|
||||
{
|
||||
FleetAssetServiceAddresses = addresses.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
else
|
||||
{
|
||||
FleetAssetServiceAddresses = new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static T CreateClient<T>(string workingcompanyid, string sessionid) where T : RemoteClientBase
|
||||
{
|
||||
object[] args = new object[1];
|
||||
args[0] = FleetAssetServiceAddresses;
|
||||
|
||||
T client = (T)Activator.CreateInstance(typeof(T), args);
|
||||
client.AppName = SystemParams.APPNAME;
|
||||
client.WorkingCompanyID = string.IsNullOrWhiteSpace(workingcompanyid) ? SystemParams.CompanyID : workingcompanyid;
|
||||
client.SessionID = sessionid;
|
||||
return client;
|
||||
}
|
||||
|
||||
public static T CreateClient<T>(string sessionid) where T : RemoteClientBase
|
||||
{
|
||||
return CreateClient<T>(string.Empty, sessionid);
|
||||
}
|
||||
|
||||
public static T CreateClient<T>() where T : RemoteClientBase
|
||||
{
|
||||
return CreateClient<T>(string.Empty, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
92
IronIntelContractorBusiness/Helper.cs
Normal file
92
IronIntelContractorBusiness/Helper.cs
Normal file
@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class Helper
|
||||
{
|
||||
public static readonly DateTime DBMinDateTime = new DateTime(1900, 01, 01);
|
||||
|
||||
public static bool IsTrue(string s)
|
||||
{
|
||||
const string YES = "Yes";
|
||||
const string TRUE = "True";
|
||||
const string ONE = "1";
|
||||
|
||||
return (string.Compare(s, YES, true) == 0) || (string.Compare(s, TRUE, true) == 0) || (string.Compare(s, ONE) == 0);
|
||||
}
|
||||
|
||||
public static bool Contains(string text, string val)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return text.IndexOf(val, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CloneProperty(object objDes, object objSrc)
|
||||
{
|
||||
if (objDes == null || objSrc == null)
|
||||
return;
|
||||
PropertyInfo[] pisDes = objDes.GetType().GetProperties();
|
||||
Type tSrc = objSrc.GetType();
|
||||
foreach (PropertyInfo piDes in pisDes)
|
||||
{
|
||||
if (!piDes.CanWrite)
|
||||
continue;
|
||||
PropertyInfo piSrc = tSrc.GetProperty(piDes.Name, piDes.PropertyType);
|
||||
if (piSrc == null || !piSrc.CanRead)
|
||||
continue;
|
||||
try
|
||||
{
|
||||
piDes.SetValue(objDes, piSrc.GetValue(objSrc, null), null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static object DateValueToNull(DateTime date)
|
||||
{
|
||||
if (date <= DBMinDateTime)
|
||||
return null;
|
||||
else
|
||||
return date;
|
||||
}
|
||||
|
||||
public static object DateValueToNullOrBigHour(DateTime date)
|
||||
{
|
||||
if (date <= DBMinDateTime)
|
||||
return null;
|
||||
else
|
||||
return date.AddDays(1).AddSeconds(-1);
|
||||
}
|
||||
|
||||
public static object NumberValueToNull(int value)
|
||||
{
|
||||
if (value < 0)
|
||||
return null;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
public static object NumberValueToNull(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return null;
|
||||
else
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
69
IronIntelContractorBusiness/Host/ClientModels.cs
Normal file
69
IronIntelContractorBusiness/Host/ClientModels.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using FI.FIC;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
#region - Client Models -
|
||||
|
||||
public class UserInfoItem : FICUserInfo
|
||||
{
|
||||
public string Source { get; set; }
|
||||
public int IsTempPassword { get; set; }
|
||||
public DateTime PWDExpiration { get; set; }
|
||||
public int UserMode { get; set; }
|
||||
public int UserCatalog { get; set; }
|
||||
public static UserInfoItem From(FICUserInfo user)
|
||||
{
|
||||
return new UserInfoItem
|
||||
{
|
||||
IID = user.IID,
|
||||
ID = user.ID,
|
||||
DisplayName = user.DisplayName,
|
||||
Email = user.Email,
|
||||
Enabled = user.Enabled,
|
||||
Mobile = user.Mobile,
|
||||
UserType = user.UserType,
|
||||
BusinessPhone = user.BusinessPhone,
|
||||
DefaultMobileWspIID = user.DefaultMobileWspIID,
|
||||
DefaultWspIID = user.DefaultWspIID,
|
||||
Notes = user.Notes
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public class UserManagementItem
|
||||
{
|
||||
public string IID { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string Password { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Mobile { get; set; }
|
||||
public string BusinessPhone { get; set; }
|
||||
public FICUserTypes UserType { get; set; }
|
||||
public string UserLevel { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public string Active { get; set; }
|
||||
public int UserMode { get; set; }
|
||||
public string Groups { get; set; }
|
||||
public string DefaultWspIID { get; set; }
|
||||
public string DefaultMobileWspIID { get; set; }
|
||||
|
||||
public string[] GroupIIDs { get; set; }
|
||||
}
|
||||
|
||||
public class UserGroupManagementItem
|
||||
{
|
||||
public string IID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string[] UserIIDs { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
116
IronIntelContractorBusiness/Host/Common.cs
Normal file
116
IronIntelContractorBusiness/Host/Common.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class Common
|
||||
{
|
||||
public Common()
|
||||
{
|
||||
}
|
||||
|
||||
private static string _LoginSessionCookieName;
|
||||
public static string LoginSessionCookieName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_LoginSessionCookieName == null)
|
||||
{
|
||||
_LoginSessionCookieName = Site.IronIntelBasePage.LOGINSESSION_COOKIENAME;
|
||||
}
|
||||
return _LoginSessionCookieName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _LanguageCookieName;
|
||||
public static string LanguageCookieName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_LanguageCookieName == null)
|
||||
{
|
||||
_LanguageCookieName = LoginSessionCookieName + "language";
|
||||
}
|
||||
return _LanguageCookieName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _RememberCookieName;
|
||||
public static string RememberCookieName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_RememberCookieName == null)
|
||||
{
|
||||
_RememberCookieName = LoginSessionCookieName + "RemberUser";
|
||||
}
|
||||
return _RememberCookieName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _FrsPeriodCookieName;
|
||||
public static string FrsPeriodCookieName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_FrsPeriodCookieName == null)
|
||||
{
|
||||
_FrsPeriodCookieName = LoginSessionCookieName + "Period";
|
||||
}
|
||||
return _FrsPeriodCookieName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _FrsThemeCookieName;
|
||||
public static string FrsThemeCookieName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_FrsThemeCookieName == null)
|
||||
{
|
||||
_FrsThemeCookieName = LoginSessionCookieName + "FrsTheme";
|
||||
}
|
||||
return _FrsThemeCookieName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 此方法只有FIC的的页面,其他页面也是会出错
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string GenerateUrl(string file)
|
||||
{
|
||||
string url;
|
||||
System.Web.UI.Page page = HttpContext.Current.Handler as System.Web.UI.Page;
|
||||
if (page != null)
|
||||
{
|
||||
// Use page instance.
|
||||
url = page.ResolveUrl("~/") + "fic/" + file;
|
||||
}
|
||||
else
|
||||
{
|
||||
// avoid duplicate operation
|
||||
url = HttpContext.Current.Request.ApplicationPath + "/fic/" + file;
|
||||
}
|
||||
try
|
||||
{
|
||||
var path = System.IO.Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, "fic/" + file);
|
||||
if (System.IO.File.Exists(path))
|
||||
{
|
||||
url += "?t=" + System.IO.File.GetLastWriteTimeUtc(path).Ticks;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// cant read file
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
69
IronIntelContractorBusiness/Host/HostRequesEntry.cs
Normal file
69
IronIntelContractorBusiness/Host/HostRequesEntry.cs
Normal file
@ -0,0 +1,69 @@
|
||||
using FI.FIC;
|
||||
using FI.FIC.Contracts;
|
||||
using FI.FIC.Contracts.DataObjects;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using FI.FIC.DataProviders.HelpClass;
|
||||
using FI.FIC.Models;
|
||||
using Foresight;
|
||||
using IronIntel.Contractor.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class HostRequesEntry
|
||||
{
|
||||
public static object ProcessNetRequest(FICNetRequestObject netQuery, HttpContext context)
|
||||
{
|
||||
switch (netQuery.MethodName)
|
||||
{
|
||||
case "ChangePassword":
|
||||
var lc = FICHostEnvironment.GetCurrentLoginContext(context);
|
||||
if (!UserManagement.ChangePassword(netQuery.LoginIID, netQuery.Parameters[0].ToString(), netQuery.Parameters[1].ToString(), lc.SessionID, context.Request.UserHostName))
|
||||
{
|
||||
throw new FIException(0X65026303, "", null);
|
||||
}
|
||||
break;
|
||||
case "LoginFIC"://跳转到G4,IronIntel没有G4版本
|
||||
return "";
|
||||
case "GetVersion":
|
||||
return SystemParams.GetFICVersion();
|
||||
default:
|
||||
//rsp.Result = something
|
||||
var service = new HostService();
|
||||
service.Request = netQuery;
|
||||
var method = typeof(HostService).GetMethod(netQuery.MethodName);
|
||||
try
|
||||
{
|
||||
return method.Invoke(service, netQuery.Parameters);
|
||||
}
|
||||
catch (TargetInvocationException ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
throw ex.InnerException;
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class LoginModel
|
||||
{
|
||||
public int ErrorCode { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string Cookie { get; set; }
|
||||
}
|
||||
}
|
558
IronIntelContractorBusiness/Host/HostService.cs
Normal file
558
IronIntelContractorBusiness/Host/HostService.cs
Normal file
@ -0,0 +1,558 @@
|
||||
using FI.FIC;
|
||||
using FI.FIC.Contracts;
|
||||
using FI.FIC.Contracts.DataObjects;
|
||||
using FI.FIC.Contracts.DataObjects.BaseObject;
|
||||
using FI.FIC.Contracts.DataObjects.BLObject;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using FI.FIC.Models;
|
||||
using IronIntel.Contractor.Users;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class HostService
|
||||
{
|
||||
private FICUserInfo _User;
|
||||
private FICNetRequestObject _Request;
|
||||
public FICNetRequestObject Request
|
||||
{
|
||||
get { return _Request; }
|
||||
set
|
||||
{
|
||||
_Request = value;
|
||||
if (value == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_User = FICHostEnvironment.GetUserByLoginSessionID(value.SessionID);
|
||||
}
|
||||
}
|
||||
|
||||
public static UserInfoItem[] GetAllUsers(bool hasAdmin = false)
|
||||
{
|
||||
//UserInfoItem[] users = UserManagement.GetAllUsers(hasAdmin);
|
||||
//List<UserInfoItem> ls = new List<UserInfoItem>();
|
||||
//foreach (UserInfoItem ui in users)
|
||||
//{
|
||||
// ui.UserType = UserManagement.GetUserTypeByIID(ui.IID);
|
||||
// ls.Add(ui);
|
||||
//}
|
||||
//return ls.ToArray();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string CurrentUserIID
|
||||
{
|
||||
get { return _User == null ? null : _User.IID; }
|
||||
}
|
||||
|
||||
public string CurrentUserName
|
||||
{
|
||||
get { return _User == null ? null : _User.DisplayName; }
|
||||
}
|
||||
|
||||
public string ClientLanguage
|
||||
{
|
||||
get { return _Request == null ? ResManager.DefaultLanguage : _Request.LanguageID; }
|
||||
}
|
||||
|
||||
public string DeleteUserGroup(string iid)
|
||||
{
|
||||
try
|
||||
{
|
||||
UserManagement.DeleteGroup(iid);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SystemParams.WriteLog("ERROR", "DeleteUserGroup", ex.Message, ex.ToString());
|
||||
throw new Exception(ResManager.GetLanguage("LHBIS_EXCEPTION_E0X6502704C")); // "Failed to delete the user group."
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserManagementItem[] GetUsers()
|
||||
{
|
||||
//var users = GetAllUsers();
|
||||
//var items = new List<UserManagementItem>();
|
||||
|
||||
//var groups = UserManagement.GetUserGroupMapping().Rows.Cast<DataRow>();
|
||||
|
||||
//for (int i = 0; i < users.Length; i++)
|
||||
//{
|
||||
// if (string.Compare(users[i].ID, "admin", true) == 0)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
// var item = ConvertFromFICUser(users[i]);
|
||||
// // fill default param
|
||||
// item.DefaultWspIID = UserParametersInfo.GetUserSystemParameter(EMUserDefaultInfoType.DefaultWorkSpace, users[i].IID);
|
||||
// item.DefaultMobileWspIID = UserParametersInfo.GetUserSystemParameter(EMUserDefaultInfoType.DefaultWorkSpace4Mobile, users[i].IID);
|
||||
// // fill groups
|
||||
// var gs = groups
|
||||
// .Where(g => g["USERID"].ToString().ToUpper() == users[i].IID.ToUpper())
|
||||
// .Select(g => g["GROUPNAME"]);
|
||||
// item.Groups = string.Join("; ", gs);
|
||||
|
||||
// items.Add(item);
|
||||
//}
|
||||
//return items.ToArray();
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private UserManagementItem ConvertFromFICUser(UserInfoItem user)
|
||||
{
|
||||
var item = new UserManagementItem
|
||||
{
|
||||
IID = user.IID,
|
||||
ID = user.ID,
|
||||
DisplayName = user.DisplayName,
|
||||
Email = user.Email,
|
||||
Mobile = user.Mobile,
|
||||
BusinessPhone = user.BusinessPhone,
|
||||
UserType = user.UserType,
|
||||
Enabled = user.Enabled,
|
||||
Active = user.Enabled ? "Yes" : "No",
|
||||
UserMode = user.UserMode
|
||||
};
|
||||
switch (user.UserType)
|
||||
{
|
||||
case FICUserTypes.Admin:
|
||||
case FICUserTypes.SuperAdmin:
|
||||
item.UserLevel = "Admin";
|
||||
break;
|
||||
case FICUserTypes.Common:
|
||||
item.UserLevel = "User";
|
||||
break;
|
||||
default:
|
||||
item.UserLevel = "Read Only User";
|
||||
break;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private static Regex reg_userid = new Regex("^[a-zA-Z0-9_-]+$");
|
||||
private static Regex reg_email = new Regex(@"^([a-zA-Z0-9]+[-_.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9-_]+\.)*[a-zA-Z]{2,4}$");
|
||||
|
||||
private bool IsAdminOrSuper(FICUserTypes type)
|
||||
{
|
||||
return type == FICUserTypes.Admin || type == FICUserTypes.SuperAdmin;
|
||||
}
|
||||
private string VerifyPermission(string iid)
|
||||
{
|
||||
return VerifyPermission(new UserManagementItem
|
||||
{
|
||||
IID = iid,
|
||||
UserType = FICUserTypes.Readonly
|
||||
});
|
||||
}
|
||||
private string VerifyPermission(UserManagementItem user)
|
||||
{
|
||||
var currentUser = FICHostEnvironment.GetUserByIID(CurrentUserIID);
|
||||
var flag = false;
|
||||
if (string.IsNullOrEmpty(user.IID))
|
||||
{
|
||||
if (!IsAdminOrSuper(currentUser.UserType) &&
|
||||
user.UserType == FICUserTypes.Admin)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var olduser = FICHostEnvironment.GetUserByIID(user.IID);
|
||||
//if (olduser.UserType == FICUserTypes.Admin)
|
||||
if (currentUser.UserType < user.UserType)
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
if (flag)
|
||||
{
|
||||
SystemParams.WriteLog("ERROR", "SaveUser", "user try to edit user with illegal permission.", string.Format("current user: {0}, {1}", CurrentUserIID, CurrentUserName));
|
||||
return ResManager.GetLanguage("ERROR_LHBIS_FIC_BLC_BLWORKSPACE_A0034"); // "The user does not have the required access rights.";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string SaveUser(FICUserInfo user, string password, string[] groups)
|
||||
{
|
||||
var item = new UserManagementItem
|
||||
{
|
||||
IID = user.IID,
|
||||
ID = user.ID,
|
||||
DisplayName = user.DisplayName,
|
||||
Mobile = user.Mobile,
|
||||
BusinessPhone = user.BusinessPhone,
|
||||
Email = user.Email,
|
||||
UserType = user.UserType,
|
||||
DefaultWspIID = user.DefaultWspIID,
|
||||
DefaultMobileWspIID = user.DefaultMobileWspIID,
|
||||
Enabled = user.Enabled,
|
||||
Password = password,
|
||||
GroupIIDs = groups
|
||||
};
|
||||
return SaveUser(item, null);
|
||||
}
|
||||
|
||||
private string SaveUser(UserManagementItem user, string subject)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
return "User param is invalid.";
|
||||
}
|
||||
|
||||
// 权限验证
|
||||
var r = VerifyPermission(user);
|
||||
if (r != null)
|
||||
{
|
||||
return r;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(user.ID))
|
||||
{
|
||||
return ResManager.GetLanguage("LHBIS_FIC_CLIENT_MODULES_USERMANAGERCTRL_A023"); // "User ID cannot be empty.";
|
||||
}
|
||||
if (!reg_email.Match(user.ID).Success && !reg_userid.Match(user.ID).Success)
|
||||
{
|
||||
return ResManager.GetLanguage("LHBIS_FIC_CLIENT_MODULES_USERMANAGERCTRL_A056"); // "The user ID must contain only letters, numbers, underlines, minus signs or an email address.";
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(user.DisplayName))
|
||||
{
|
||||
return ResManager.GetLanguage("LHBIS_FIC_CLIENT_MODULES_USERMANAGERCTRL_A024"); // "User name cannot be empty.";
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(user.Email) && !reg_email.Match(user.Email).Success)
|
||||
{
|
||||
return ResManager.GetLanguage("LHBIS_FIC_CLIENT_MODULES_USERMANAGERCTRL_A066"); // "Email address is invalid.";
|
||||
}
|
||||
user.ID = user.ID.Trim();
|
||||
if (user.ID.Length > 100)
|
||||
{
|
||||
user.ID = user.ID.Substring(0, 100);
|
||||
}
|
||||
if (user.DisplayName != null && user.DisplayName.Length > 100)
|
||||
{
|
||||
user.DisplayName = user.DisplayName.Substring(0, 100);
|
||||
}
|
||||
if (user.Password != null && user.Password.Length > 300)
|
||||
{
|
||||
user.Password = user.Password.Substring(0, 300);
|
||||
}
|
||||
if (user.Mobile != null && user.Mobile.Length > 50)
|
||||
{
|
||||
user.Mobile = user.Mobile.Substring(0, 50);
|
||||
}
|
||||
if (user.BusinessPhone != null && user.BusinessPhone.Length > 50)
|
||||
{
|
||||
user.BusinessPhone = user.BusinessPhone.Substring(0, 50);
|
||||
}
|
||||
|
||||
// groups
|
||||
|
||||
|
||||
string result = SaveUser(new UserInfoItem
|
||||
{
|
||||
IID = user.IID,
|
||||
ID = user.ID,
|
||||
DisplayName = user.DisplayName,
|
||||
Enabled = user.Enabled,
|
||||
Mobile = user.Mobile,
|
||||
BusinessPhone = user.BusinessPhone,
|
||||
Email = user.Email,
|
||||
UserType = user.UserType,
|
||||
DefaultWspIID = user.DefaultWspIID,
|
||||
DefaultMobileWspIID = user.DefaultMobileWspIID
|
||||
}, user.Password, user.GroupIIDs, subject);
|
||||
if (result == null)
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string SaveUser(UserInfoItem user, string password, string[] groups, string subject)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// if (string.IsNullOrEmpty(user.IID))
|
||||
// {
|
||||
// UserManagement.AddUser(user, password, groups);
|
||||
|
||||
// //UserManagement.AddUser(user, password, groups, subject, ClientLanguage);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// UserManagement.EditUser(user, groups);
|
||||
// }
|
||||
// return null;
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// return ex.Message;
|
||||
//}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ResetPassword(string iid, string password)
|
||||
{
|
||||
// 权限验证
|
||||
//var r = VerifyPermission(iid);
|
||||
//if (r != null)
|
||||
//{
|
||||
// return r;
|
||||
//}
|
||||
|
||||
////if (!string.IsNullOrEmpty(password))
|
||||
////{
|
||||
//// password = HttpUtility.HtmlDecode(password);
|
||||
////}
|
||||
//UserManagement.ResetPassword(iid, string.IsNullOrEmpty(password), password);
|
||||
|
||||
//return null;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string DeleteUser(string iid)
|
||||
{
|
||||
// 权限验证
|
||||
//var r = VerifyPermission(iid);
|
||||
//if (r != null)
|
||||
//{
|
||||
// return r;
|
||||
//}
|
||||
|
||||
//try
|
||||
//{
|
||||
// UserManagement.DeleteUser(iid);
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// FICHostEnvironment.WriteLog("ERROR", "", "DeleteUser", ex.Message, ex.ToString());
|
||||
// throw new Exception(ResManager.GetLanguage("LHBIS_EXCEPTION_E0X65027021")); // "Failed to delete the user."
|
||||
//}
|
||||
//return null;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public UserGroupSimple[] GetUserGroups(string iid)
|
||||
{
|
||||
UserGroupSimple[] groups = SearchLocalGroups(null);
|
||||
var selected = FICHostEnvironment.GetUserGroupIDByUserIID(iid);
|
||||
|
||||
foreach (var g in groups)
|
||||
{
|
||||
if (selected.Contains(g.UserGroupID))
|
||||
{
|
||||
g.IsSelected = true;
|
||||
}
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public UserGroupSimple[] GetAllGroups()
|
||||
{
|
||||
var groups = SearchLocalGroups(null);
|
||||
return groups;
|
||||
}
|
||||
|
||||
public List<UserSimple> GetGroupMembers(string iid)
|
||||
{
|
||||
var users = FICHostEnvironment.GetUsers();
|
||||
if (string.IsNullOrEmpty(iid))
|
||||
{
|
||||
iid = Guid.Empty.ToString();
|
||||
}
|
||||
var selected = UserManagement.GetUserInfoByGoupid(iid);
|
||||
|
||||
var list = new List<UserSimple>();
|
||||
foreach (var u in users)
|
||||
{
|
||||
var item = new UserSimple
|
||||
{
|
||||
IID = u.IID,
|
||||
UserID = u.ID,
|
||||
UserName = u.DisplayName
|
||||
};
|
||||
var su = selected.FirstOrDefault((t) => t.IID.Equals(u.IID, StringComparison.OrdinalIgnoreCase));
|
||||
if (su != null)
|
||||
{
|
||||
item.IsSelected = true;
|
||||
}
|
||||
list.Add(item);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public string SaveGroup(string gs)
|
||||
{
|
||||
//gs = HttpUtility.HtmlDecode(gs);
|
||||
var group = JsonConvert.DeserializeObject<UserGroupManagementItem>(gs);
|
||||
|
||||
if (group == null)
|
||||
{
|
||||
return "Group param is invalid.";
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(group.Name))
|
||||
{
|
||||
return ResManager.GetLanguage("LHBIS_FIC_CLIENT_MODULES_USERADDDIALOG_A004"); // "Group name cannot be empty.";
|
||||
}
|
||||
|
||||
// users
|
||||
if (group.Name.Length > 100)
|
||||
{
|
||||
group.Name = group.Name.Substring(0, 100);
|
||||
}
|
||||
if (group.Description != null && group.Description.Length > 200)
|
||||
{
|
||||
group.Description = group.Description.Substring(0, 200);
|
||||
}
|
||||
|
||||
string result = SaveGroup(new UserGroupSimple
|
||||
{
|
||||
UserGroupID = group.IID,
|
||||
UserGroupName = group.Name,
|
||||
Description = group.Description,
|
||||
}, group.UserIIDs);
|
||||
if (result == null)
|
||||
{
|
||||
return "OK";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string SaveGroup(UserGroupSimple group, string[] users)
|
||||
{
|
||||
try
|
||||
{
|
||||
var add = string.IsNullOrEmpty(group.UserGroupID);
|
||||
bool isimport;
|
||||
if (!add)
|
||||
{
|
||||
// import domain group
|
||||
add = users == null && group.GroupMode == 1;
|
||||
isimport = add;
|
||||
}
|
||||
else
|
||||
{
|
||||
isimport = false;
|
||||
}
|
||||
UserGroupInfo ug = new UserGroupInfo();
|
||||
ug.ID = group.UserGroupID;
|
||||
ug.Name = group.UserGroupName;
|
||||
ug.Notes = group.Description;
|
||||
|
||||
List<UserInfo> userList = new List<UserInfo>();
|
||||
if (users != null)
|
||||
{
|
||||
foreach (string u in users)
|
||||
{
|
||||
userList.Add(new UserInfo() { IID = u });
|
||||
}
|
||||
}
|
||||
ug.Users = userList.ToArray();
|
||||
|
||||
if (add)
|
||||
{
|
||||
UserManagement.AddGroup(ug);
|
||||
}
|
||||
else
|
||||
{
|
||||
UserManagement.UpdateGroup(ug);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
public object[] GetUsersAndGroups()
|
||||
{
|
||||
// get users
|
||||
var users = FICHostEnvironment.GetUsers().Where(u => u.UserType < FICUserTypes.Admin);
|
||||
var groups = SearchLocalGroups("");
|
||||
|
||||
return new object[]
|
||||
{
|
||||
users,
|
||||
groups
|
||||
};
|
||||
}
|
||||
|
||||
public UserGroupSimple[] SearchLocalGroups(string prefix)
|
||||
{
|
||||
return UserManagement.SearchLocalGroups(prefix).OrderBy(m => m.UserGroupName).ToArray();
|
||||
}
|
||||
|
||||
public UserSimple[] GetPermissionUsers()
|
||||
{
|
||||
List<UserSimple> userSimples = new List<UserSimple>();
|
||||
|
||||
UserInfoItem[] userInfos = UserManagement.GetPermissionUsers();
|
||||
|
||||
foreach (var userInfo in userInfos)
|
||||
{
|
||||
UserSimple user = new UserSimple();
|
||||
user.IID = userInfo.IID;
|
||||
user.UserID = userInfo.ID;
|
||||
user.UserName = userInfo.DisplayName;
|
||||
userSimples.Add(user);
|
||||
}
|
||||
|
||||
return userSimples.OrderBy(m => m.UserID).ToArray();
|
||||
}
|
||||
|
||||
public UserPermissionData[] GetUserOrGroupPermission(string UserOrGroup, string objIID)
|
||||
{
|
||||
return UserManagement.GetUserOrGroupPermission(UserOrGroup, objIID, CurrentUserIID);
|
||||
}
|
||||
|
||||
#region - System Options -
|
||||
|
||||
public void SaveConnectorConfigs(string[] configs)
|
||||
{
|
||||
if (configs != null)
|
||||
{
|
||||
SystemParams.SetFICStringParameter("ConnectorServer", configs[0] ?? "");
|
||||
SystemParams.SetFICStringParameter("ConnectorToken", configs[1] ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveLDAPConnector(string[] configs)
|
||||
{
|
||||
if (configs != null)
|
||||
{
|
||||
SystemParams.SetFICStringParameter("LdapAgentID", configs[0] ?? "");
|
||||
SystemParams.SetFICStringParameter("LdapAgentToken", configs[1] ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveRedisConfigs(bool enabled, string token)
|
||||
{
|
||||
if (token != null)
|
||||
{
|
||||
token = token.Replace('\n', ';');
|
||||
}
|
||||
SystemParams.SetFICStringParameter("RedisEnabled", enabled ? "Yes" : "No");
|
||||
SystemParams.SetFICStringParameter("RedisToken", token);
|
||||
}
|
||||
|
||||
public object GetRedisConfigs()
|
||||
{
|
||||
return new
|
||||
{
|
||||
Enabled = SystemParams.RedisEnabled,
|
||||
RedisToken = SystemParams.RedisToken
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
16
IronIntelContractorBusiness/IIColor.cs
Normal file
16
IronIntelContractorBusiness/IIColor.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class IIColor
|
||||
{
|
||||
public byte Alpha { get; set; }
|
||||
public byte Red { get; set; }
|
||||
public byte Green { get; set; }
|
||||
public byte Blue { get; set; }
|
||||
}
|
||||
}
|
223
IronIntelContractorBusiness/IronIntelContractorBusiness.csproj
Normal file
223
IronIntelContractorBusiness/IronIntelContractorBusiness.csproj
Normal file
@ -0,0 +1,223 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{515FB61F-F032-4A48-8F32-93B59B9D37F8}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>IronIntel.Contractor</RootNamespace>
|
||||
<AssemblyName>iicontractorbl</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>LHBIS.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="DocumentFormat.OpenXml">
|
||||
<HintPath>..\Reflib\DocumentFormat.OpenXml.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FIASPNETCache">
|
||||
<HintPath>..\Reflib\FIASPNETCache.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICacheManager.Redis">
|
||||
<HintPath>..\Reflib\FICacheManager.Redis.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICachManager">
|
||||
<HintPath>..\Reflib\FICachManager.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICBLC">
|
||||
<HintPath>..\Reflib\FIC\FICBLC.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntf">
|
||||
<HintPath>..\Reflib\FIC\FICIntf.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICIntfAdv, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b006d6021b5c4397, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Reflib\FIC\FICIntfAdv.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICModels">
|
||||
<HintPath>..\Reflib\FIC\FICModels.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICore">
|
||||
<HintPath>..\Reflib\FICore.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICore.std, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1c0ebbbf33888075, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Reflib\FICore.std.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FICoreDbCreator">
|
||||
<HintPath>..\Reflib\FICoreDbCreator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FIWinLib">
|
||||
<HintPath>..\Reflib\FIWinLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FleetClientBase">
|
||||
<HintPath>..\Reflib\FleetClientBase.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FleetServiceClient">
|
||||
<HintPath>..\Reflib\FleetServiceClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Foresight.ServiceModel">
|
||||
<HintPath>..\Reflib\Foresight.ServiceModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisitebase">
|
||||
<HintPath>..\Reflib\iisitebase.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="iisyslib">
|
||||
<HintPath>..\Reflib\iisyslib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ironcontractorwinlib">
|
||||
<HintPath>..\Site\Bin\ironcontractorwinlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="irondbobjlib">
|
||||
<HintPath>..\Reflib\irondbobjlib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronIntel.ServiceModel.Client">
|
||||
<HintPath>..\Reflib\IronIntel.ServiceModel.Client.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronIntel.Services.Contractor">
|
||||
<HintPath>..\Site\Bin\IronIntel.Services.Contractor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronIntelServiceModel">
|
||||
<HintPath>..\Reflib\IronIntelServiceModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="IronIntelSysClient">
|
||||
<HintPath>..\Reflib\IronIntelSysClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\Reflib\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SqlClient, Version=4.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Data.SqlClient.4.6.0\lib\net461\System.Data.SqlClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AttachmentsManagement.cs" />
|
||||
<Compile Include="Attachment\AttachmentItem.cs" />
|
||||
<Compile Include="BusinessBase.cs" />
|
||||
<Compile Include="CacheManager.cs" />
|
||||
<Compile Include="Device\GpsDeviceItem.cs" />
|
||||
<Compile Include="ExportExcelManager.cs" />
|
||||
<Compile Include="ExportExcel\ConvertFormat.cs" />
|
||||
<Compile Include="ExportExcel\ExcelXlsx.cs" />
|
||||
<Compile Include="ExportExcel\ExportToExcel.cs" />
|
||||
<Compile Include="ExportExcel\IOpenXmlExcelStyleAndData.cs" />
|
||||
<Compile Include="ExportExcel\XlsxObj.cs" />
|
||||
<Compile Include="FITracker\FITrackerManagement.cs" />
|
||||
<Compile Include="FleetServiceClientHelper.cs" />
|
||||
<Compile Include="Host\ClientModels.cs" />
|
||||
<Compile Include="Host\Common.cs" />
|
||||
<Compile Include="Contact\ContactInfo.cs" />
|
||||
<Compile Include="Contact\ContactManagement.cs" />
|
||||
<Compile Include="Helper.cs" />
|
||||
<Compile Include="Host\HostRequesEntry.cs" />
|
||||
<Compile Include="Host\HostService.cs" />
|
||||
<Compile Include="MachineDetailWorkspace.cs" />
|
||||
<Compile Include="Machines\FuelusedInfo.cs" />
|
||||
<Compile Include="Machines\IdlehoursInfo.cs" />
|
||||
<Compile Include="Machines\LocationInfo.cs" />
|
||||
<Compile Include="Machines\MachineItem.cs" />
|
||||
<Compile Include="Machines\MachineManagement.cs" />
|
||||
<Compile Include="Machines\MachineRentalInfo.cs" />
|
||||
<Compile Include="Machines\EngineHoursInfo.cs" />
|
||||
<Compile Include="Machines\OdometerInfo.cs" />
|
||||
<Compile Include="Maintenance\AlertInfo.cs" />
|
||||
<Compile Include="Maintenance\AlertManager.cs" />
|
||||
<Compile Include="Maintenance\FuelRecordInfo.cs" />
|
||||
<Compile Include="Maintenance\IATCAlertsSyncService.cs" />
|
||||
<Compile Include="Maintenance\MaintenanceInfo.cs" />
|
||||
<Compile Include="Maintenance\MaintenanceManagement.cs" />
|
||||
<Compile Include="Maintenance\SegmentInfo.cs" />
|
||||
<Compile Include="Maintenance\WorkOrderInfo.cs" />
|
||||
<Compile Include="Maintenance\WorkOrderManager.cs" />
|
||||
<Compile Include="MapView\AssetMapViewManagement.cs" />
|
||||
<Compile Include="MapView\AssetViewItems.cs" />
|
||||
<Compile Include="OTRConfig\HarshDrivingItem.cs" />
|
||||
<Compile Include="OTRConfig\HarshDrivingManagement.cs" />
|
||||
<Compile Include="OTRConfig\SpeedingItem.cs" />
|
||||
<Compile Include="Security\CurfewInfo.cs" />
|
||||
<Compile Include="Security\CurfewManagement.cs" />
|
||||
<Compile Include="Security\CurfewMovementToleranceInfo.cs" />
|
||||
<Compile Include="Security\JobsiteLimitInfo.cs" />
|
||||
<Compile Include="Security\JobsiteLimitManagement.cs" />
|
||||
<Compile Include="Shape\MapPoint.cs" />
|
||||
<Compile Include="Shape\ShapeFileParser.cs" />
|
||||
<Compile Include="Users\AppModuleInfo.cs" />
|
||||
<Compile Include="Users\AppModulesManagement.cs" />
|
||||
<Compile Include="FilterQ\FilterQManagememt.cs" />
|
||||
<Compile Include="FilterQ\MachineTasksNotificationInfo.cs" />
|
||||
<Compile Include="IIColor.cs" />
|
||||
<Compile Include="IronintelHost.cs" />
|
||||
<Compile Include="JobSites\JobSitesManagement.cs" />
|
||||
<Compile Include="MapView\JobManagement.cs" />
|
||||
<Compile Include="MapView\LocationManagement.cs" />
|
||||
<Compile Include="MapView\MachineStateInfo.cs" />
|
||||
<Compile Include="MapView\MachinesMapViewerManagement.cs" />
|
||||
<Compile Include="MapView\MapViewer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SystemParams.cs" />
|
||||
<Compile Include="Users\Acl.cs" />
|
||||
<Compile Include="Users\UserGroupInfo.cs" />
|
||||
<Compile Include="Users\UserInfo.cs" />
|
||||
<Compile Include="Users\UserManagement.cs" />
|
||||
<Compile Include="Users\UserParams.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="LHBIS.snk" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy "$(TargetFileName)" "$(ProjectDir)\..\Site\Bin\$(TargetFileName)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
559
IronIntelContractorBusiness/IronintelHost.cs
Normal file
559
IronIntelContractorBusiness/IronintelHost.cs
Normal file
@ -0,0 +1,559 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using System.Net.Mail;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using Newtonsoft.Json;
|
||||
using Foresight.Data;
|
||||
using Foresight.Security.License;
|
||||
using FI.FIC;
|
||||
using IronIntel.Contractor.Users;
|
||||
using FI.FIC.Contracts.DataObjects.Enumeration;
|
||||
using System.Web;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class IronIntelHost : IFICHost
|
||||
{
|
||||
static readonly Guid FIC_MODULE_ID = new Guid("1c6dfe25-347d-4889-ab75-73ade9190d27");
|
||||
const string FIC_MODULE_NAME = "Foresight Intelligence Center";
|
||||
const string FIC_MODULE_VERSION = "3.0";
|
||||
|
||||
public string FICDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemParams.FICDbConnectionString;
|
||||
}
|
||||
}
|
||||
|
||||
public string FrsDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
public bool FICInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool FRSInstalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
FICHostEnvironment.SetHost(new IronIntelHost());
|
||||
}
|
||||
|
||||
public byte[] GetCacheData(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = CacheManager.GetValue(key);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Decompress(buffer);
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.FromBuffer(tmp);
|
||||
createTime = fc.CreateTime;
|
||||
return fc.Data;
|
||||
}
|
||||
|
||||
public DataTable GetCacheDataTable(string key, bool ignoreExpired, ref DateTime createTime)
|
||||
{
|
||||
byte[] buffer = GetCacheData(key, ignoreExpired, ref createTime);
|
||||
if (buffer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
//FIDataTable tb = new FIDataTable();
|
||||
//tb.FillFromBuffer(buffer);
|
||||
//return FIDbAccess.ConvertDataTable(tb);
|
||||
return Deserialize(buffer) as DataTable;
|
||||
}
|
||||
|
||||
public FICCompanyInfo GetCompanyInfo()
|
||||
{
|
||||
var cp = SystemParams.CustomerDetail;
|
||||
FICCompanyInfo ficcp = new FICCompanyInfo();
|
||||
ficcp.ID = cp.ID;
|
||||
ficcp.Name = cp.Name;
|
||||
|
||||
return ficcp;
|
||||
}
|
||||
|
||||
public CompanyLic GetLicense()
|
||||
{
|
||||
IronIntel.Services.LicenseInfo lic = SystemParams.GetLicense();
|
||||
if (lic == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CompanyLic ci = new CompanyLic();
|
||||
ci.CompanyID = SystemParams.CompanyID;
|
||||
ci.CompanyName = SystemParams.CustomerDetail.Name;
|
||||
|
||||
Foresight.Security.License.LicenseInfo li = new LicenseInfo();
|
||||
ci.Licenses.Add(li);
|
||||
li.CompanyID = ci.CompanyID;
|
||||
li.CompanyName = ci.CompanyName;
|
||||
li.Expiration = lic.ExpireDate;
|
||||
li.ID = Guid.Empty;
|
||||
li.StartDate = lic.StartDate;
|
||||
li.ModuleID = FIC_MODULE_ID;
|
||||
li.ModuleName = FIC_MODULE_NAME;
|
||||
li.Version = FIC_MODULE_VERSION;
|
||||
|
||||
foreach (var item in lic.Items)
|
||||
{
|
||||
var prop = ConvertLicenseItem(item);
|
||||
if (prop != null)
|
||||
{
|
||||
li.AddtionalPropertes.Add(prop);
|
||||
}
|
||||
}
|
||||
|
||||
return ci;
|
||||
}
|
||||
|
||||
private LicenseAddtionalPropertyObj ConvertLicenseItem(Services.LicenseItem item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
switch (item.Key)
|
||||
{
|
||||
case "ColumnLineCombChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ColumnLineCombChart", Value = item.Value, Description = item.Description };
|
||||
case "ExportChartToXPS":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ExportChartToXPS", Value = item.Value, Description = item.Description };
|
||||
case "FreeChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "FreeChart", Value = item.Value, Description = item.Description };
|
||||
case "DrilldownToURL":
|
||||
return new LicenseAddtionalPropertyObj { Key = "DrilldownToURL", Value = item.Value, Description = item.Description };
|
||||
case "MaxCharts":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxCharts", Value = item.Value, Description = item.Description };
|
||||
case "MaxDataTables":
|
||||
return new LicenseAddtionalPropertyObj { Key = "MaxDataTables", Value = item.Value, Description = item.Description };
|
||||
case "PrintChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "PrintChart", Value = item.Value, Description = item.Description };
|
||||
case "ScatterChart":
|
||||
return new LicenseAddtionalPropertyObj { Key = "ScatterChart", Value = item.Value, Description = item.Description };
|
||||
case "Snapshot":
|
||||
return new LicenseAddtionalPropertyObj { Key = "Snapshot", Value = item.Value, Description = item.Description };
|
||||
case "SQLGenerator":
|
||||
return new LicenseAddtionalPropertyObj { Key = "SQLGenerator", Value = item.Value, Description = item.Description };
|
||||
case "EmailSubscribe":
|
||||
return new LicenseAddtionalPropertyObj { Key = "EmailSubscribe", Value = item.Value, Description = item.Description };
|
||||
//case "MainStyle":
|
||||
//case "MaxAdminCount":
|
||||
//case "MaxLogins":
|
||||
//case "MaxNormalUerCount":
|
||||
//case "MaxReadOnlyUserCount":
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
return SystemParams.GetResourceLock(resourceid, locksecond);
|
||||
}
|
||||
|
||||
private static FICUserInfo ConvertToFICUserInfo(IronIntel.Contractor.Users.UserInfo ui)
|
||||
{
|
||||
var user = new FICUserInfo
|
||||
{
|
||||
ID = ui.ID,
|
||||
IID = ui.IID,
|
||||
Enabled = ui.Active,
|
||||
DisplayName = ui.DisplayName,
|
||||
//Mobile = ui.Mobile,
|
||||
Mobile = ui.TextAddress,
|
||||
BusinessPhone = ui.BusinessPhone,
|
||||
};
|
||||
switch (ui.UserType)
|
||||
{
|
||||
case UserTypes.Common:
|
||||
user.UserType = FICUserTypes.Common;
|
||||
break;
|
||||
case UserTypes.Admin:
|
||||
user.UserType = FICUserTypes.Admin;
|
||||
break;
|
||||
case UserTypes.Readonly:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
case UserTypes.SupperAdmin:
|
||||
user.UserType = FICUserTypes.SuperAdmin;
|
||||
break;
|
||||
default:
|
||||
user.UserType = FICUserTypes.Readonly;
|
||||
break;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByIID(string useriid)
|
||||
{
|
||||
UserInfo ui = UserManagement.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByLoginSessionID(string sessionid)
|
||||
{
|
||||
UserInfo ui = UserManagement.GetUserBySessionID(sessionid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo GetUserByUserID(string userId)
|
||||
{
|
||||
UserInfo ui = UserManagement.GetUserByID(userId);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return ConvertToFICUserInfo(ui);
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers()
|
||||
{
|
||||
UserInfo[] users = UserManagement.GetUsers();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public string GetUserEmail(string useriid)
|
||||
{
|
||||
UserInfo ui = UserManagement.GetUserByIID(useriid);
|
||||
if (ui == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ui.ID;
|
||||
}
|
||||
}
|
||||
|
||||
public void PostMessage(int category, string msg)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void ReleaseResourceLock(string lockid)
|
||||
{
|
||||
SystemParams.ReleaseResourceLock(lockid);
|
||||
}
|
||||
|
||||
public void RemoveCache(string key)
|
||||
{
|
||||
CacheManager.Remove(key);
|
||||
}
|
||||
|
||||
public void SendMail(MailMessage message)
|
||||
{
|
||||
try
|
||||
{
|
||||
SystemParams.SendMail("FIC", message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SystemParams.WriteLog("Error", this.GetType().FullName + ".SendMail(MailMessage)", "Add fic mail to mail service failed", ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCacheData(string key, byte[] buffer, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (buffer == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
return;
|
||||
}
|
||||
FICCacheObject fc = new FICCacheObject();
|
||||
fc.Data = buffer;
|
||||
fc.CreateTime = createTime;
|
||||
|
||||
byte[] tmp = Foresight.Security.SecurityHelper.Compress(fc.ToBuffer());
|
||||
CacheManager.SetValue(key, tmp, TimeSpan.FromSeconds(expirationsecond));
|
||||
}
|
||||
|
||||
public void SetCacheDataTable(string key, DataTable dt, int expirationsecond, bool slidingExpiration, DateTime createTime)
|
||||
{
|
||||
if (dt == null)
|
||||
{
|
||||
RemoveCache(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
//FIDataTable tb = FIDbAccess.ConvertDataTable(dt, -1);
|
||||
byte[] buffer = Serialize(dt, createTime);
|
||||
SetCacheData(key, buffer, expirationsecond, slidingExpiration, createTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void SubscribeMessage(int category, Action<IEnumerable<MessageInformation>> action)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void WriteLog(string logType, string category, string source, string message, string detail)
|
||||
{
|
||||
SystemParams.WriteLog(logType, category, source, message, detail);
|
||||
}
|
||||
|
||||
public List<string> GetUserGroupIDByUserIID(string userIID)
|
||||
{
|
||||
return UserManagement.GetUserGroupIDByUserIID(userIID);
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetUsers(bool hasAdmin)
|
||||
{
|
||||
if (!hasAdmin)
|
||||
{
|
||||
return GetUsers();
|
||||
}
|
||||
|
||||
UserInfo[] localusers = UserManagement.GetUsers();
|
||||
UserInfo[] foresightusers = UserManagement.GetForesightUsers();
|
||||
UserInfo[] users = localusers.Union(foresightusers).ToArray();
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>(users.Length);
|
||||
foreach (UserInfo ui in users)
|
||||
{
|
||||
//if (ui.UserType == UserTypes.Admin)
|
||||
//{
|
||||
ls.Add(ConvertToFICUserInfo(ui));
|
||||
//}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public LoginContext GetCurrentLoginContext(HttpContext context)
|
||||
{
|
||||
string session = Site.IronIntelBasePage.GetLoginSessionID(context.Request);
|
||||
if (string.IsNullOrWhiteSpace(session))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
LoginContext lc = new LoginContext();
|
||||
lc.SessionID = session;
|
||||
lc.User = GetUserByLoginSessionID(session);
|
||||
lc.LanguageID = GetLgID(context);
|
||||
return lc;
|
||||
}
|
||||
|
||||
private string GetLgID(HttpContext context)
|
||||
{
|
||||
var language = context.Request.Cookies[Common.LanguageCookieName];
|
||||
if (language != null)
|
||||
{
|
||||
return language.Value;
|
||||
}
|
||||
return ResLanguage.ClientCurrentLanguage;
|
||||
}
|
||||
|
||||
public string ProductEdition
|
||||
{
|
||||
get
|
||||
{
|
||||
return "General";
|
||||
}
|
||||
}
|
||||
|
||||
public string FIExternalDBConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeSpan BaseUtcOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
var timezone = CustomerTimeZoneInfo;
|
||||
return timezone.BaseUtcOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public TimeZoneInfo CustomerTimeZoneInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemParams.CustomerDetail.TimeZone;
|
||||
}
|
||||
}
|
||||
|
||||
public string FICommonDbConnectionString
|
||||
{
|
||||
get { return string.Empty; }
|
||||
}
|
||||
|
||||
public string GetStyleDefines(string useriid)
|
||||
{
|
||||
//StringBuilder s = new StringBuilder();
|
||||
//s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
//s.Append("<root>");
|
||||
//s.Append("<Workspace><Title><Background>#ff00ff</Background><Foreground>#222222</Foreground></Title></Workspace>");
|
||||
//s.Append("<Chart><Title><Background>#333333</Background><Foreground>#444444</Foreground></Title><Board>#555555</Board></Chart>");
|
||||
//s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
//s.Append("</root>");
|
||||
//return s.ToString();
|
||||
Services.CustUIStyle uistyle = SystemParams.GetUIStyle(useriid);
|
||||
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.Append(@"<?xml version=""1.0"" encoding=""UTF-8""?>");
|
||||
s.Append("<root>");
|
||||
s.Append("<Workspace><Title><Background></Background><Foreground>#000000</Foreground></Title></Workspace>");
|
||||
s.Append("<Chart><Title><Background>" + uistyle.ChartTitleBackgroundColor + "</Background><Foreground></Foreground></Title><Board>" + uistyle.ChartBorderColor + "</Board></Chart>");
|
||||
//s.Append("<Board><Title><Background>#666666</Background><Foreground>#777777</Foreground></Title></Board>");
|
||||
s.Append("</root>");
|
||||
return s.ToString();
|
||||
}
|
||||
public Dictionary<string, string> GetAdditionalParameter()
|
||||
{
|
||||
return SystemParams.GetAdditionalParameter();
|
||||
}
|
||||
|
||||
public FICUserInfo[] GetSimpleUsers(bool hasAdmin)
|
||||
{
|
||||
var users = GetUsers(hasAdmin);
|
||||
List<FICUserInfo> ls = new List<FICUserInfo>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
var us = new FICUserInfo();
|
||||
us.IID = user.IID;
|
||||
us.ID = user.ID;
|
||||
us.DisplayName = user.DisplayName;
|
||||
ls.Add(us);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public SpecialDatabaseConnectionInfo[] GetSpecialDatabaseConnections()
|
||||
{
|
||||
const string IRONINTELMASTERDB = "10000000-0000-0000-0000-100000000000";
|
||||
const string REPORTDB = "10000000-0000-0000-0000-100000000001";
|
||||
// const string IATC = "10000000-0000-0000-0000-100000000002";
|
||||
|
||||
List<SpecialDatabaseConnectionInfo> ls = new List<SpecialDatabaseConnectionInfo>();
|
||||
SpecialDatabaseConnectionInfo mast = new SpecialDatabaseConnectionInfo();
|
||||
mast.ID = IRONINTELMASTERDB;
|
||||
mast.DisplayName = "FleetView";
|
||||
mast.DatabaseType = "MSSQL";
|
||||
mast.ConnectionString = SystemParams.DataDbConnectionString;
|
||||
ls.Add(mast);
|
||||
|
||||
string rptstr = SystemParams.GetIronIntelReportDataDbString();
|
||||
if (!string.IsNullOrWhiteSpace(rptstr))
|
||||
{
|
||||
SpecialDatabaseConnectionInfo rptdb = new SpecialDatabaseConnectionInfo();
|
||||
rptdb.ID = REPORTDB;
|
||||
rptdb.DisplayName = "FleetView Report";
|
||||
rptdb.DatabaseType = "MSSQL";
|
||||
rptdb.ConnectionString = rptstr;
|
||||
ls.Add(rptdb);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
class FICCacheObject
|
||||
{
|
||||
public byte[] Data = null;
|
||||
public DateTime CreateTime = DateTime.Now;
|
||||
|
||||
public byte[] ToBuffer()
|
||||
{
|
||||
byte[] rst = new byte[Data.Length + 8];
|
||||
byte[] bf1 = BitConverter.GetBytes(CreateTime.Ticks);
|
||||
Buffer.BlockCopy(bf1, 0, rst, 0, 8);
|
||||
Buffer.BlockCopy(Data, 0, rst, 8, Data.Length);
|
||||
|
||||
return rst;
|
||||
}
|
||||
|
||||
public void FromBuffer(byte[] buffer)
|
||||
{
|
||||
long l = BitConverter.ToInt64(buffer, 0);
|
||||
CreateTime = new DateTime(l);
|
||||
Data = new byte[buffer.Length - 8];
|
||||
Buffer.BlockCopy(buffer, 8, Data, 0, buffer.Length - 8);
|
||||
}
|
||||
}
|
||||
|
||||
#region - (De)Serialize -
|
||||
|
||||
private static byte[] Serialize(object obj, DateTime createtime)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var cacheObj = new RedisCacheObject
|
||||
{
|
||||
CreateTime = createtime,
|
||||
Data = obj
|
||||
};
|
||||
byte[] data;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
new BinaryFormatter().Serialize(ms, cacheObj);
|
||||
data = ms.ToArray();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static object Deserialize(byte[] buffer)
|
||||
{
|
||||
using (var ms = new MemoryStream(buffer, false))
|
||||
{
|
||||
return new BinaryFormatter().Deserialize(ms);
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] GetCompanyLogo()
|
||||
{
|
||||
return SystemParams.GetCompanyLOGO(SystemParams.CompanyID);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
[Serializable]
|
||||
public class RedisCacheObject
|
||||
{
|
||||
public DateTime CreateTime { get; set; }
|
||||
public object Data { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
621
IronIntelContractorBusiness/JobSites/JobSitesManagement.cs
Normal file
621
IronIntelContractorBusiness/JobSites/JobSitesManagement.cs
Normal file
@ -0,0 +1,621 @@
|
||||
using Foresight;
|
||||
using Foresight.Data;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.JobSite;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Contractor.MapView;
|
||||
using IronIntel.Contractor.Shape;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.JobSites
|
||||
{
|
||||
public class JobSitesManagement
|
||||
{
|
||||
private const string MachineFields = "{0}MACHINEID,{0}MACHINENAME,{0}MAKEID,{0}MODELID,{0}TYPEID,{0}MACHINEICONID,{0}DEVICEID,{0}VIN,{0}MAKEYEAR,{0}NOTES,{0}STATUS,{0}CONTRACTORID,{0}DEALERID,{0}UID,{0}ADDEDON,{0}CUR_LONGITUDE,{0}CUR_LATITUDE,{0}LOCDATE_UTC,{0}ENGINEHOURS,{0}HOURSDATE_UTC,{0}DATASOURCE,{0}HIDE,{0}FUEL_CONSUMED,{0}FUEL_UNITS,{0}FUEL_DATE,{0}ODOMETER,{0}ODODATE_UTC,{0}ODOMETERUOM,{0}FUELCOST,{0}FUELCOSTUOM,{0}MACHINERATE,{0}WORKTYPE,{0}RETIREMENTHOURS,{0}RETIREMENTODO,{0}ALTITUDE,{0}ALTITUDEUNITS,{0}IDLEHOURSUTC,{0}IDLEHOURS,{0}LOADCOUNTUTC,{0}LOADCOUNT,{0}PAYLOADTOTALUTC,{0}PAYLOADTOTAL,{0}PAYLOADTOTALUNITS,{0}DEFREMAININGUTC,{0}DEFREMAINING,{0}FUELREMAININGUTC,{0}FUELREMAININGPERCENT,{0}MACHINENAME2,{0}ONROAD,{0}LEASESTART,{0}LEASEEND,{0}LEASEHOURS,{0}UNDERCARRIAGEHOURS,{0}ODOSTART2,{0}ISDELETED,{0}DELETEDDATE,{0}ODOSTART2DATASOURCE,{0}LOCDATASOURCE,{0}HOURSDATASOURCE,{0}FUELDATASOURCE,{0}AQUISITIONTYPE,{0}ICONFILENAME,{0}STARTINGENGINEHOURS,{0}DISTANCECALCBY,{0}TELEMATICSENABLED,{0}COSTCENTER,{0}EQCLASS,{0}DESCRIPTION";
|
||||
|
||||
|
||||
public static JobSiteViewItem GetJobSiteByID(string jobsiteid)
|
||||
{
|
||||
const string sql = @"select JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE,RADIUS,RADUIS_UOM,CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON,BASEONMACHINEID,ISDELETED from JOBSITES where JOBSITEID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(sql, jobsiteid);
|
||||
|
||||
JobSiteViewItem result = null;
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
result = ConvertToJobSiteViewItem(dt.Rows[0]);
|
||||
MachineViewItem[] msiary = GetJobSiteMachines(Convert.ToInt64(jobsiteid));
|
||||
if (msiary.Count() > 0)
|
||||
{
|
||||
result.Machines = msiary.OrderBy((m) => m.VIN).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Machines = null;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void RefreshJobsiteAssets(string sessionid, long jobsiteid)
|
||||
{
|
||||
System.Threading.ThreadPool.QueueUserWorkItem((object state) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
FleetServiceClientHelper.CreateClient<JobSiteProvider>(sessionid).RefreshAllJobSites(SystemParams.CompanyID, jobsiteid);
|
||||
}
|
||||
catch { }
|
||||
}, null);
|
||||
}
|
||||
|
||||
public static void DeleteJobSites(long jobsiteid)
|
||||
{
|
||||
const string SQL = "delete from JOBSITES where JOBSITEID={0}"
|
||||
+ " delete from JOBSITETYPE where JOBSITEID={0}"
|
||||
+ " delete from JOBSITEMACHINES where JOBSITEID={0}"
|
||||
+ " delete from RELATIONSHIP where RELATIONSHIPTYPEID='ContactJobsite' and RELATEDID={0}";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, jobsiteid);
|
||||
}
|
||||
|
||||
|
||||
public static void AddMachinesToJobSite(JobSiteViewItem jobsite)
|
||||
{
|
||||
if (jobsite != null)
|
||||
{
|
||||
const string SQL_t = @"if exists(select 1 from JOBSITEMACHINES where JOBSITEID={0} and MACHINEID={1}) update JOBSITEMACHINES set ONSITE={3} where JOBSITEID={0} and MACHINEID = {1} else insert into JOBSITEMACHINES(JOBSITEID,MACHINEID,VIN,ADDEDON,ONSITE) values({0},{1},{2},getutcdate(),{3})";
|
||||
const string SQL_upt = "update JOBSITEMACHINES set ONSITE=0 where JOBSITEID!={0} and MACHINEID={1}";
|
||||
const string SQL_del = "select MACHINEID from JOBSITEMACHINES where JOBSITEID={0} ";
|
||||
const string SQL_OUT = "exec pro_removejobsitemachines {0},{1},{2},{3},{4},{5},{6},{7}";
|
||||
|
||||
string ad = string.Empty;
|
||||
if (jobsite.Machines != null && jobsite.Machines.Length > 0)
|
||||
{
|
||||
string machineids = string.Join(",", jobsite.Machines.Select(m => m.ID));
|
||||
ad = " and MACHINEID not in(" + machineids + ")";
|
||||
}
|
||||
|
||||
using (FISqlTransaction tran = new FISqlTransaction(SystemParams.DataDbConnectionString))
|
||||
{
|
||||
DataTable dt = tran.GetDataTableBySQL(SQL_del + ad, jobsite.ID);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string mid = FIDbAccess.GetFieldString(dr["MACHINEID"], "");
|
||||
tran.ExecSQL(SQL_OUT, mid, jobsite.ID, DateTime.Now.ToUniversalTime(), null, null, null, null, "ManualRemove");
|
||||
}
|
||||
|
||||
if (jobsite.Machines != null && jobsite.Machines.Length > 0)
|
||||
{
|
||||
foreach (MachineViewItem mac in jobsite.Machines)
|
||||
{
|
||||
if (mac.OnSite)
|
||||
{
|
||||
tran.ExecSQL(SQL_upt, jobsite.ID, mac.ID);
|
||||
}
|
||||
|
||||
tran.ExecSQL(SQL_t, jobsite.ID, mac.ID, mac.VIN, mac.OnSite ? 1 : 0);
|
||||
}
|
||||
}
|
||||
tran.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void AddMachineOnSiteToJobSite(FISqlConnection db, long machineid, string vin, int jobsiteid)
|
||||
{
|
||||
const string SQL_t = @"if exists(select 1 from JOBSITEMACHINES where JOBSITEID={0} and MACHINEID={1}) update JOBSITEMACHINES set ONSITE={3}
|
||||
where JOBSITEID={0} and MACHINEID = {1} else insert into JOBSITEMACHINES(JOBSITEID,MACHINEID,VIN,ADDEDON,ONSITE) values({0},{1},{2},getutcdate(),{3})";
|
||||
const string SQL_upt = "update JOBSITEMACHINES set ONSITE=0 where JOBSITEID!={0} and MACHINEID={1}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
|
||||
db.ExecSQL(SQL_upt, jobsiteid, machineid);
|
||||
if (jobsiteid > 0)
|
||||
db.ExecSQL(SQL_t, jobsiteid, machineid, vin, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static JobSiteViewItem ConvertToJobSiteViewItem(DataRow dr)
|
||||
{
|
||||
JobSiteViewItem js = new JobSiteViewItem();
|
||||
long JobSiteId = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.ID = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.Name = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
js.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
js.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
js.Radius = FIDbAccess.GetFieldDouble(dr["RADIUS"], 0);
|
||||
js.Radius_UOM = FIDbAccess.GetFieldString(dr["RADUIS_UOM"], string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(js.Radius_UOM))
|
||||
js.Radius_UOM = "Mile";
|
||||
js.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
js.ColorString = FIDbAccess.GetFieldString(dr["COLOR"], string.Empty);
|
||||
System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
try
|
||||
{
|
||||
color = System.Drawing.ColorTranslator.FromHtml(js.ColorString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
js.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
|
||||
js.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
js.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
js.EndDate = FIDbAccess.GetFieldDateTime(dr["ENDDATE"], DateTime.MinValue);
|
||||
string polygon = FIDbAccess.GetFieldString(dr["POLYGON"], string.Empty);
|
||||
js.Polygon = ConvertPolygonToPointItem(polygon);
|
||||
js.BaseOnMachineID = FIDbAccess.GetFieldInt(dr["BASEONMACHINEID"], 0);
|
||||
js.IsDeleted = FIDbAccess.GetFieldInt(dr["ISDELETED"], 0) == 1;
|
||||
if (js.IsDeleted)
|
||||
js.Name = js.Name + " - Deleted";
|
||||
return js;
|
||||
}
|
||||
|
||||
private static PostionItem[] ConvertPolygonToPointItem(string polygon)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(polygon))
|
||||
return null;
|
||||
|
||||
List<PostionItem> list = new List<PostionItem>();
|
||||
var polygons = polygon.Split(';');
|
||||
foreach (var py in polygons)
|
||||
{
|
||||
PostionItem pi = new PostionItem();
|
||||
var sap = py.Split(',');
|
||||
pi.Latitude = Convert.ToDouble(sap[0]);
|
||||
pi.Longitude = Convert.ToDouble(sap[1]);
|
||||
list.Add(pi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static string ConvertPointItemToPolygon(PostionItem[] points)
|
||||
{
|
||||
string polygon = string.Empty;
|
||||
if (points == null || points.Length < 0)
|
||||
{
|
||||
return polygon;
|
||||
}
|
||||
foreach (var pi in points)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(polygon))
|
||||
polygon += pi.Latitude + "," + pi.Longitude;
|
||||
else
|
||||
polygon += ";" + pi.Latitude + "," + pi.Longitude;
|
||||
}
|
||||
return polygon;
|
||||
}
|
||||
|
||||
|
||||
private static MachineViewItem[] GetJobSiteMachines(long JobSiteId)
|
||||
{
|
||||
const string sql_j = @"select jm.MACHINEID,ISNULL(ONSITE,0) ONSITE,m.VIN,m.MACHINENAME,m.MACHINENAME2,m.TYPEID from JOBSITEMACHINES jm left join machines m on jm.MACHINEID=m.MACHINEID where JOBSITEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = null;
|
||||
dt = db.GetDataTableBySQL(sql_j, JobSiteId);
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MachineViewItem[0];
|
||||
}
|
||||
List<MachineViewItem> list = new List<MachineViewItem>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.OnSite = FIDbAccess.GetFieldInt(dr["ONSITE"], 0) == 1;
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty); ;
|
||||
mi.TypeID = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
list.Add(mi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器OnSite状态的JobSite
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<int, int> GetOnSiteMahcines(FISqlConnection db)
|
||||
{
|
||||
const string SQL_J = "select JOBSITEID,MACHINEID from JOBSITEMACHINES where ONSITE=1";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_J);
|
||||
Dictionary<int, int> result = new Dictionary<int, int>();
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
int jobsiteid = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
result[machineid] = jobsiteid;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器OnSite状态的JobSite
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="machineid"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetOnSiteByMachineID(FISqlConnection db, long machineid)
|
||||
{
|
||||
const string SQL_J = "select JOBSITEID from JOBSITEMACHINES where ONSITE=1 and MACHINEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_J, machineid);
|
||||
int jobsiteid = 0;
|
||||
if (tb.Rows.Count > 0)
|
||||
jobsiteid = FIDbAccess.GetFieldInt(tb.Rows[0]["JOBSITEID"], 0);
|
||||
|
||||
return jobsiteid;
|
||||
}
|
||||
|
||||
#region Machines
|
||||
|
||||
public static AvailableMachines GetMachineViewItemByType(string sessionid, string jobsiteid, string typeid, string searchText, string useriid)
|
||||
{
|
||||
AvailableMachines result = new AvailableMachines();
|
||||
string SQL_J = @"select m.*,js.JOBSITEID,js.JOBSITENAME,js.LATITUDE,js.LONGITUDE,jsm.ADDEDON as JSMADDEDON,ONSITE from MACHINES m
|
||||
left join JOBSITEMACHINES as jsm on m.MACHINEID = jsm.MACHINEID and jsm.ONSITE=1
|
||||
left join JOBSITES as js on js.JOBSITEID= jsm.JOBSITEID";
|
||||
|
||||
const string SQL_L = @"select AssetId as MACHINEID,LATITUDE,LONGITUDE,AsofTime as ASOFTIME_UTC,MOVESTATUS,HEADING, Speed,SpeedUnits,PostedSpeedLimit,SpeedLimitUnits,Street from AssetLocation where IsPrimary=1";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(typeid))
|
||||
{
|
||||
Regex r = new Regex(@"[a-zA-Z]");
|
||||
if (r.IsMatch(typeid))
|
||||
return result;
|
||||
SQL_J += " and m.TYPEID=" + typeid + "";
|
||||
}
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_J);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
result.Assigned = new MachineViewItem[0];
|
||||
result.Unassigned = new MachineViewItem[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
DataTable tbl = null;
|
||||
string dbString2 = SystemParams.GetIronIntelReportDataDbString();
|
||||
if (!string.IsNullOrWhiteSpace(dbString2))
|
||||
{
|
||||
var db2 = new FISqlConnection(dbString2);
|
||||
tbl = db2.GetDataTableBySQL(SQL_L);
|
||||
}
|
||||
|
||||
Dictionary<long, LocationViewItem> machineLocations = new Dictionary<long, LocationViewItem>();
|
||||
if (tbl != null && tbl.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tbl.Rows)
|
||||
{
|
||||
long mID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
var l = new LocationViewItem();
|
||||
l.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
l.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
l.LocationTime = FIDbAccess.GetFieldDateTime(dr["ASOFTIME_UTC"], DateTime.MinValue);
|
||||
if (l.LocationTime != DateTime.MinValue)
|
||||
l.LocationTime = l.LocationTime.AddHours(timeadjust);
|
||||
|
||||
machineLocations[mID] = l;
|
||||
}
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MachineViewItem> assigned = new List<MachineViewItem>();
|
||||
List<MachineViewItem> unassigned = new List<MachineViewItem>();
|
||||
JobSiteViewItem jobsite = GetJobSiteByID(jobsiteid);
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = Convert.ToInt64(dr["MACHINEID"]);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
MachineViewItem mi = ConvertToMachineViewItem(dr, makes, models, types, timeadjust);
|
||||
if (machineLocations.ContainsKey(mi.ID))
|
||||
mi.Location = machineLocations[mi.ID];
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchText))
|
||||
{
|
||||
if (!Helper.Contains(mi.VIN, searchText)
|
||||
&& !Helper.Contains(mi.ID.ToString(), searchText)
|
||||
&& !Helper.Contains(mi.Name, searchText)
|
||||
&& !Helper.Contains(mi.Name2, searchText)
|
||||
&& !Helper.Contains(mi.Make, searchText)
|
||||
&& !Helper.Contains(mi.MachineType, searchText)
|
||||
&& !Helper.Contains(mi.Model, searchText))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
mi.JobSiteName = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
Postion mPoint = new Postion(mi.Location.Latitude, mi.Location.Longitude);
|
||||
Postion jsPoint = new Postion(jobsite.Latitude, jobsite.Longitude);
|
||||
mi.DistanceFromSite = Foresight.Haversine.GetDistanceKilometers(mPoint, jsPoint);
|
||||
|
||||
if (jobsite.Polygon != null && jobsite.Polygon.Length > 3)//多边形,计算机器是否在Jobsite内
|
||||
mi.WithinSite = Haversine.IsInSide(new Postion(mi.Location.Latitude, mi.Location.Longitude), ConvertToPosition(jobsite.Polygon));//由于FICore.dll中Postion的Longtitude存在拼写错误,在前端容易引起混淆,使用加了PostionItem
|
||||
|
||||
|
||||
if (string.Compare(jobsite.Radius_UOM, "Kilometre", true) != 0)//转换
|
||||
mi.DistanceFromSite = mi.DistanceFromSite * 0.6213712;
|
||||
mi.DistanceFromSite = Math.Round(mi.DistanceFromSite, 2);
|
||||
|
||||
bool hide = FIDbAccess.GetFieldInt(dr["HIDE"], 0) == 1;
|
||||
if (!hide && (dr["JOBSITEID"] is DBNull || string.IsNullOrWhiteSpace(dr["JOBSITEID"].ToString())))
|
||||
unassigned.Add(mi);
|
||||
else
|
||||
assigned.Add(mi);
|
||||
}
|
||||
}
|
||||
if (jobsite.Radius > 0)
|
||||
{
|
||||
result.Assigned = assigned.OrderBy((m) => m.DistanceFromSite).ToArray();
|
||||
result.Unassigned = unassigned.OrderBy((m) => m.DistanceFromSite).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Assigned = assigned.OrderBy((m) => !m.WithinSite).ThenBy((m) => m.DistanceFromSite).ToArray();
|
||||
result.Unassigned = unassigned.OrderBy((m) => !m.WithinSite).ThenBy((m) => m.DistanceFromSite).ToArray();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可用于Jobsite 绑定的机器,Calamp和FI Tracker
|
||||
/// </summary>
|
||||
/// <param name="useriid"></param>
|
||||
/// <returns></returns>
|
||||
public static MachineViewItem[] GetBindingMachines(string sessionid, string useriid)
|
||||
{
|
||||
List<MachineViewItem> result = new List<MachineViewItem>();
|
||||
string SQL = @"select " + string.Format(MachineFields, "m.") + @" from MACHINES m order by m.MACHINENAME";
|
||||
|
||||
const string SQL_L = @"select AssetId as MACHINEID,LATITUDE,LONGITUDE,AsofTime as ASOFTIME_UTC,MOVESTATUS,HEADING,Speed,SpeedUnits,PostedSpeedLimit,SpeedLimitUnits,Street from AssetLocation where IsPrimary=1 and Datasource in ('Calamp','FITRACKER')";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, useriid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MachineViewItem[0];
|
||||
}
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
DataTable tbl = null;
|
||||
string dbString2 = SystemParams.GetIronIntelReportDataDbString();
|
||||
if (!string.IsNullOrWhiteSpace(dbString2))
|
||||
{
|
||||
var db2 = new FISqlConnection(dbString2);
|
||||
tbl = db2.GetDataTableBySQL(SQL_L);
|
||||
}
|
||||
|
||||
Dictionary<long, LocationViewItem> machineLocations = new Dictionary<long, LocationViewItem>();
|
||||
if (tbl != null && tbl.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tbl.Rows)
|
||||
{
|
||||
long mID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
var l = new LocationViewItem();
|
||||
l.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
l.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
l.LocationTime = FIDbAccess.GetFieldDateTime(dr["ASOFTIME_UTC"], DateTime.MinValue);
|
||||
if (l.LocationTime != DateTime.MinValue)
|
||||
l.LocationTime = l.LocationTime.AddHours(timeadjust);
|
||||
|
||||
machineLocations[mID] = l;
|
||||
}
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
MachineViewItem mi = ConvertToMachineViewItem(dr, makes, models, types, timeadjust);
|
||||
if (machineLocations.ContainsKey(mi.ID))
|
||||
{
|
||||
mi.Location = machineLocations[mi.ID];
|
||||
result.Add(mi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
private static MachineViewItem ConvertToMachineViewItem(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types, double timeadjust)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
mi.MakeYear = FIDbAccess.GetFieldInt(dr["MAKEYEAR"], 0);
|
||||
mi.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
mi.EngineHoursDate = FIDbAccess.GetFieldDateTime(dr["HOURSDATE_UTC"], DateTime.MinValue);
|
||||
if (mi.EngineHoursDate != DateTime.MinValue)
|
||||
mi.EngineHoursDate = mi.EngineHoursDate.AddHours(timeadjust);
|
||||
|
||||
mi.Location = new LocationViewItem();
|
||||
mi.Location.Latitude = FIDbAccess.GetFieldDouble(dr["CUR_LATITUDE"], 0);
|
||||
mi.Location.Longitude = FIDbAccess.GetFieldDouble(dr["CUR_LONGITUDE"], 0);
|
||||
mi.Location.LocationTime = FIDbAccess.GetFieldDateTime(dr["LOCDATE_UTC"], DateTime.MinValue);
|
||||
if (mi.Location.LocationTime != DateTime.MinValue)
|
||||
mi.Location.LocationTime = mi.Location.LocationTime.AddHours(timeadjust);
|
||||
|
||||
mi.Odometer = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
mi.OdometerUOM = FIDbAccess.GetFieldString(dr["ODOMETERUOM"], string.Empty);
|
||||
|
||||
int makeid = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
mi.Make = make == null ? string.Empty : make.Name;
|
||||
|
||||
int modelid = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
mi.Model = model == null ? string.Empty : model.Name;
|
||||
|
||||
int typeid = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
mi.TypeID = typeid;
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
if (mtype != null)
|
||||
{
|
||||
mi.MachineType = mtype.Name;
|
||||
mi.IconUrl = mtype.IconUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
mi.MachineType = string.Empty;
|
||||
mi.IconUrl = MachineManagement.DefaultMachineTypeIconUrl;
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
private static Foresight.Postion[] ConvertToPosition(PostionItem[] polygon)
|
||||
{
|
||||
if ((polygon == null) || (polygon.Length == 0))
|
||||
{
|
||||
return new Foresight.Postion[0];
|
||||
}
|
||||
List<Foresight.Postion> ls = new List<Postion>(polygon.Length);
|
||||
foreach (var p in polygon)
|
||||
{
|
||||
ls.Add(new Postion(p.Latitude, p.Longitude));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static MachineTypeItem[] GetMachineTypes()
|
||||
{
|
||||
List<MachineTypeItem> mTypes = new List<MachineTypeItem>();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
if (types != null)
|
||||
{
|
||||
foreach (var t in types)
|
||||
{
|
||||
mTypes.Add(new MachineTypeItem() { ID = t.ID, Name = t.Name });
|
||||
}
|
||||
}
|
||||
return mTypes.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<long, List<string>> GetJobSiteTypes(FISqlConnection db)
|
||||
{
|
||||
|
||||
const string SQL = "select JOBSITEID,JOBSITETYPE from JOBSITETYPE";
|
||||
|
||||
Dictionary<long, List<string>> result = new Dictionary<long, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long jobsiteid = FIDbAccess.GetFieldInt64(dr["JOBSITEID"], 0);
|
||||
string type = FIDbAccess.GetFieldString(dr["JOBSITETYPE"], string.Empty);
|
||||
if (!result.ContainsKey(jobsiteid))
|
||||
result[jobsiteid] = new List<string>();
|
||||
result[jobsiteid].Add(type);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SaveJobSiteTypes(FIDbAccess db, long jobsiteid, string[] types)
|
||||
{
|
||||
const string SQL = "insert into JOBSITETYPE(JOBSITEID,JOBSITETYPE) values({0},{1})";
|
||||
const string SQL_DEL = "delete from JOBSITETYPE where JOBSITEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
|
||||
db.ExecSQL(SQL_DEL, jobsiteid);
|
||||
if (types != null)
|
||||
{
|
||||
foreach (string type in types)
|
||||
{
|
||||
db.ExecSQL(SQL, jobsiteid, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static JobSiteViewItem[] GetUserJobsites(string uid)
|
||||
{
|
||||
const string SQL = @"select a.JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE,RADIUS,RADUIS_UOM,b.CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON, BASEONMACHINEID,ISDELETED from USERJOBSITEMAP a,JOBSITES b where a.JOBSITEID=b.JOBSITEID and a.USERIID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, uid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new JobSiteViewItem[0];
|
||||
}
|
||||
List<JobSiteViewItem> ls = new List<JobSiteViewItem>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
JobSiteViewItem js = ConvertToJobSiteViewItem(dr);
|
||||
ls.Add(js);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从Shape文件导入Jobsite范围
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="buffer"></param>
|
||||
/// <returns></returns>
|
||||
public static MapPoint[] ImportJobsitePolygon(string filename, byte[] buffer)
|
||||
{
|
||||
Shape.Shape shape = new Shape.Shape();
|
||||
ShapeFileParser.ParseFromShapeFile(buffer, shape);
|
||||
if (shape.Polygons.Count > 0 && shape.Polygons[0].Rings.Count > 0)
|
||||
{
|
||||
return shape.Polygons[0].Rings[0].Points.ToArray();
|
||||
}
|
||||
return new MapPoint[0];
|
||||
}
|
||||
}
|
||||
}
|
BIN
IronIntelContractorBusiness/LHBIS.snk
Normal file
BIN
IronIntelContractorBusiness/LHBIS.snk
Normal file
Binary file not shown.
95
IronIntelContractorBusiness/MachineDetailWorkspace.cs
Normal file
95
IronIntelContractorBusiness/MachineDetailWorkspace.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using Foresight.ServiceModel;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public class MachineDetailWorkspace
|
||||
{
|
||||
private const string MachineDetailWSP = "MachineDetailWSP";
|
||||
private const string Path = "fic/FIC.aspx?IID={0}&wspivots={1}";
|
||||
|
||||
public static string GenerateMachineDetailWSPURL(string machineid, string vin, out int openMode)
|
||||
{
|
||||
var config = GetConfig();
|
||||
openMode = config.OpenMode;
|
||||
List<WorkspacePivotItem> pvs = new List<WorkspacePivotItem>();
|
||||
if (!string.IsNullOrEmpty(config.MachineIDPivotIID))
|
||||
{
|
||||
WorkspacePivotItem pv = new WorkspacePivotItem();
|
||||
pv.iid = config.MachineIDPivotIID;
|
||||
pv.vals = new string[] { machineid };
|
||||
pvs.Add(pv);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(config.VINPivotIID))
|
||||
{
|
||||
WorkspacePivotItem pv = new WorkspacePivotItem();
|
||||
pv.iid = config.VINPivotIID;
|
||||
pv.vals = new string[] { vin };
|
||||
pvs.Add(pv);
|
||||
}
|
||||
|
||||
string pivotString = JsonConvert.SerializeObject(pvs);
|
||||
pivotString = System.Web.HttpUtility.UrlEncode(pivotString);
|
||||
string url = string.Format(Path, config.WorkspaceIID, pivotString);
|
||||
return url;
|
||||
}
|
||||
|
||||
public static MachineDetailWorkspaceConfig GetConfig()
|
||||
{
|
||||
MachineDetailWorkspaceConfig config = new MachineDetailWorkspaceConfig();
|
||||
string value = SystemParams.GetStringParam(MachineDetailWSP, false);
|
||||
//wspid=00000000-0000-0000-0000-000000000000&pivotid=00000000-0000-0000-0000-000000000000&openmode=0
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
string[] temps = value.Split('&');
|
||||
foreach (string temp in temps)
|
||||
{
|
||||
string[] kv = temp.Split('=');
|
||||
if (kv.Length == 2)
|
||||
{
|
||||
if (string.Equals("wspid", kv[0], StringComparison.OrdinalIgnoreCase))
|
||||
config.WorkspaceIID = kv[1];
|
||||
else if (string.Equals("midpivotid", kv[0], StringComparison.OrdinalIgnoreCase))
|
||||
config.MachineIDPivotIID = kv[1];
|
||||
else if (string.Equals("vinpivotid", kv[0], StringComparison.OrdinalIgnoreCase))
|
||||
config.VINPivotIID = kv[1];
|
||||
else if (string.Equals("openmode", kv[0], StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
int v = 0;
|
||||
if (int.TryParse(kv[1], out v))
|
||||
config.OpenMode = v;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
private static void SetConfig(MachineDetailWorkspaceConfig config)
|
||||
{
|
||||
config.OpenMode = GetConfig().OpenMode;//OpenMode暂不修改
|
||||
string value = string.Format("wspid={0}&midpivotid={1}&vinpivotid={2}&openmode={3}", config.WorkspaceIID, config.MachineIDPivotIID, config.VINPivotIID, config.OpenMode);
|
||||
SystemParams.SetStringParam(MachineDetailWSP, value);
|
||||
}
|
||||
}
|
||||
|
||||
public class MachineDetailWorkspaceConfig
|
||||
{
|
||||
public string WorkspaceIID { get; set; }
|
||||
public int OpenMode { get; set; }
|
||||
public string MachineIDPivotIID { get; set; }
|
||||
public string VINPivotIID { get; set; }
|
||||
}
|
||||
|
||||
public class WorkspacePivotItem
|
||||
{
|
||||
public string iid { get; set; }
|
||||
public string[] vals { get; set; }
|
||||
}
|
||||
}
|
155
IronIntelContractorBusiness/Machines/EngineHoursInfo.cs
Normal file
155
IronIntelContractorBusiness/Machines/EngineHoursInfo.cs
Normal file
@ -0,0 +1,155 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class EngineHoursInfo
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string DataSourceName { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
public double Hours { get; set; }
|
||||
public string UOM { get; set; }
|
||||
|
||||
private double _Corrected;
|
||||
public double Corrected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Corrected;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Corrected = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string ReceivedDateStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTimeLocal.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AdjustEngineHoursInfo
|
||||
{
|
||||
public string CustomerID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string Notes { get; set; }
|
||||
/// <summary>
|
||||
/// 前端选择的时区的分钟偏移
|
||||
/// </summary>
|
||||
public int OffsetMinute { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class CalampEngineHoursInfo
|
||||
{
|
||||
public long AssetId { get; set; }
|
||||
public string DeviceAirId { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public double Gps { get; set; }
|
||||
public double Gps_Calc { get; set; }
|
||||
public double VBUS { get; set; }
|
||||
public double VBUS_Calc { get; set; }
|
||||
public string EventTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
public DateTime AsofTime_Local { get; set; }
|
||||
public string EventTimeLocalText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime_Local.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PedigreeEngineHoursInfo
|
||||
{
|
||||
public long AssetId { get; set; }
|
||||
public string DeviceSN { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public double VBUS { get; set; }
|
||||
public double VBUS_Calc { get; set; }
|
||||
public string EventTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
public DateTime AsofTime_Local { get; set; }
|
||||
public string EventTimeLocalText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime_Local.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetEngineHoursAdjustItem
|
||||
{
|
||||
public long LogId { get; set; }
|
||||
public long AssetId { get; set; }
|
||||
public DateTime AdjustmentTime { get; set; }
|
||||
public string AdjustmentTimeText { get { return AdjustmentTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime EngineHoursTime { get; set; }
|
||||
public string EngineHoursTimeText { get { return EngineHoursTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime AdjustmentLocalTime { get; set; }
|
||||
public string AdjustmentLocalTimeText { get { return AdjustmentLocalTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime EngineHoursLocalTime { get; set; }
|
||||
public string EngineHoursLocalTimeText { get { return EngineHoursLocalTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public string Notes { get; set; }
|
||||
public string UserName { get; set; }
|
||||
|
||||
}
|
||||
}
|
31
IronIntelContractorBusiness/Machines/FuelusedInfo.cs
Normal file
31
IronIntelContractorBusiness/Machines/FuelusedInfo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class FuelusedInfo
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string DataSourceName { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
public double Amount { get; set; }
|
||||
public double Percent { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public string ReceivedDateStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTimeLocal.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
IronIntelContractorBusiness/Machines/IdlehoursInfo.cs
Normal file
30
IronIntelContractorBusiness/Machines/IdlehoursInfo.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class IdlehoursInfo
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string DataSourceName { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
public double Hours { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public string ReceivedDateStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTimeLocal.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
43
IronIntelContractorBusiness/Machines/LocationInfo.cs
Normal file
43
IronIntelContractorBusiness/Machines/LocationInfo.cs
Normal file
@ -0,0 +1,43 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class LocationInfo
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string DataSourceName { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
public string SpeedUnits { get; set; }
|
||||
public double AccelerationMagnitude { get; set; }
|
||||
public double Duration { get; set; }
|
||||
public SpeedingBehaviors SpeedingBehavior { get; set; }
|
||||
public HarshDrivingEvents HarshDringEvent { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string SpeedLimitUnits { get; set; }
|
||||
public double PostedSpeedLimit { get; set; }
|
||||
public double Speed { get; set; }
|
||||
public AssetMoveStatus MoveStatus { get; set; }
|
||||
public string EventType { get; set; }
|
||||
public int Heading { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
|
||||
public string ReceivedDateStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTimeLocal.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
412
IronIntelContractorBusiness/Machines/MachineItem.cs
Normal file
412
IronIntelContractorBusiness/Machines/MachineItem.cs
Normal file
@ -0,0 +1,412 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class AssetBasicItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public string CalampDeviceAirID { get; set; }
|
||||
public bool TelematicsEnabled { get; set; }
|
||||
public bool Hide { get; set; }
|
||||
public bool OnRoad { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
public string DealerID { get; set; }
|
||||
public string Dealer { get; set; }
|
||||
public string ContractorID { get; set; }
|
||||
public string Contractor { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public int MakeID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public DateTime? EngineHoursDate { get; set; }
|
||||
public string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
//DisplayName取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = ID.ToString();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
public string EngineHoursDateStr { get { return EngineHoursDate == null ? "" : EngineHoursDate.Value.ToShortDateString(); } }
|
||||
public string EngineHoursDateTimeStr { get { return EngineHoursDate == null ? "" : EngineHoursDate.Value.ToString(); } }
|
||||
}
|
||||
|
||||
|
||||
public class AssetDetailItem2
|
||||
{
|
||||
public bool IgnoreDuplicate { get; set; }//忽略重复
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public int MakeID { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
|
||||
private double? _EngineHours;
|
||||
public double? EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
_EngineHours = Math.Round(value.Value, 2);
|
||||
else
|
||||
_EngineHours = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? EngineHoursLocalTime { get; set; }
|
||||
|
||||
private double? _Odometer;
|
||||
public double? Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value != null)
|
||||
_Odometer = Math.Round(value.Value, 2);
|
||||
else
|
||||
_Odometer = value;
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime? OdometerLocalTime { get; set; }
|
||||
public string OdometerUnits { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string PairedDeviceSN { get; set; }
|
||||
public double? UnderCarriageHours { get; set; }
|
||||
public bool TelematicsEnabled { get; set; }
|
||||
public bool Hidden { get; set; }
|
||||
public bool OnRoad { get; set; }
|
||||
public string EQClass { get; set; }
|
||||
public string CostCenter { get; set; }
|
||||
public string AquisitionType { get; set; }
|
||||
public DateTime? AddedLocalTime { get; set; }
|
||||
public DateTime? AddedTime { get; set; }
|
||||
public string AddedByUserName { get; set; }
|
||||
public string IconFileName { get; set; }
|
||||
|
||||
public string ContractorID { get; set; }
|
||||
|
||||
public long OnSiteJobsiteID { get; set; }
|
||||
public string[] ContactIDs { get; set; }
|
||||
public string[] MachineGroupIDs { get; set; }
|
||||
public MachineRentalInfo MachineRental { get; set; }
|
||||
public MachineAttributeClient[] MachineAttributes { get; set; }
|
||||
public StringKeyValue[] VisibleOnWorkOrders { get; set; }
|
||||
|
||||
|
||||
public string AddedOnStr
|
||||
{
|
||||
get { return AddedLocalTime == null ? "" : AddedLocalTime.Value.ToString("MM/dd/yyyy"); }
|
||||
}
|
||||
public string EngineHoursDateTimeStr
|
||||
{
|
||||
get { return EngineHoursLocalTime == null ? "" : EngineHoursLocalTime.Value.ToString("MM/dd/yyyy"); }
|
||||
}
|
||||
public string OdometerDateTimeStr
|
||||
{
|
||||
get { return OdometerLocalTime == null ? "" : OdometerLocalTime.Value.ToString("MM/dd/yyyy"); }
|
||||
}
|
||||
}
|
||||
|
||||
public class MachineItem
|
||||
{
|
||||
public Int64 MachineID { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string MachineType { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int MakeID { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string MakeIconColor { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string ContractorID { get; set; }
|
||||
public string Contractor { get; set; }
|
||||
public string DealerID { get; set; }
|
||||
public string Dealer { get; set; }
|
||||
public int Status { get; set; }
|
||||
public Int64 GpsDeviceID { get; set; } //空 -1
|
||||
public string GpsDeviceSN { get; set; } = string.Empty; //空 -1
|
||||
|
||||
public double StartingEngineHours { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
public string EngineHoursDateStr { get { return EngineHoursDate == DateTime.MinValue ? "" : EngineHoursDate.ToShortDateString(); } }
|
||||
public string EngineHoursDateTimeStr { get { return EngineHoursDate == DateTime.MinValue ? "" : EngineHoursDate.ToString(); } }
|
||||
public bool Hide { get; set; }
|
||||
public double ODOStart2 { get; set; }
|
||||
|
||||
private double _ODOMeter;
|
||||
public double ODOMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ODOMeter;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_ODOMeter = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime ODOMeterDate { get; set; }
|
||||
public string ODOMeterDateStr { get { return ODOMeterDate == DateTime.MinValue ? "" : ODOMeterDate.ToShortDateString(); } }
|
||||
public string ODOMeterDateTimeStr { get { return ODOMeterDate == DateTime.MinValue ? "" : ODOMeterDate.ToString(); } }
|
||||
public string ODOMeterUom { get; set; }
|
||||
public double FuelCost { get; set; }
|
||||
public string FuelCostUom { get; set; }
|
||||
public double MachineRate { get; set; }
|
||||
public string WorkType { get; set; }
|
||||
public double RetirementHours { get; set; }
|
||||
public double RetirementOdo { get; set; }
|
||||
public bool OnRoad { get; set; }
|
||||
public DateTime LeaseStart { get; set; }
|
||||
public string LeaseStartStr { get { return LeaseStart == DateTime.MinValue ? "" : LeaseStart.ToShortDateString(); } }
|
||||
public DateTime LeaseEnd { get; set; }
|
||||
public string LeaseEndStr { get { return LeaseEnd == DateTime.MinValue ? "" : LeaseEnd.ToShortDateString(); } }
|
||||
public double LeaseTerm { get; set; }
|
||||
public double UndercarriageHours { get; set; }
|
||||
public string AquisitionType { get; set; }
|
||||
|
||||
public int OnSiteJobsiteID { get; set; }
|
||||
public string[] ContactIDs { get; set; }
|
||||
public MachineAttributeClient[] MachineAttributes { get; set; }
|
||||
public string MachineIconFileName { get; set; }
|
||||
public string DistanceCalcBy { get; set; }
|
||||
public bool TelematicsEnabled { get; set; }
|
||||
public string CostCenter { get; set; }
|
||||
public string EqClass { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string[] MachineGroupIDs { get; set; }
|
||||
public MachineRentalInfo MachineRental { get; set; }
|
||||
public StringKeyValue[] VisibleOnWorkOrders { get; set; }
|
||||
public DateTime AddedOn { get; set; }
|
||||
public string AddedOnStr { get { return AddedOn == DateTime.MinValue ? "" : AddedOn.ToShortDateString(); } }
|
||||
public string AddedBy { get; set; }
|
||||
public string AddedByName { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineID.ToString();
|
||||
return name;
|
||||
}
|
||||
}//由于地图显示及排序的名称
|
||||
}
|
||||
|
||||
public class MachineOffsetItem
|
||||
{
|
||||
public Int64 MachineID { get; set; }
|
||||
public double Value { get; set; }
|
||||
public double Offset { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public OffsetTypes Type { get; set; }
|
||||
}
|
||||
|
||||
public class DeviceItem
|
||||
{
|
||||
public string ContractorID { get; set; }
|
||||
|
||||
public string DeviceType { get; set; }
|
||||
public int Status { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime? ServiceStartDate { get; set; }
|
||||
public DateTime? InvoiceDate { get; set; }
|
||||
public DateTime? AddLocalDate { get; set; }
|
||||
public DateTime? AddDate { get; set; }
|
||||
public string InvoiceNumber { get; set; }
|
||||
public PairedAssetItem PairedAsset { get; set; }
|
||||
public string SourceName { get; set; }
|
||||
public string Source { get; set; }
|
||||
public string SourceDeviceId { get; set; }
|
||||
public string AlternativeSerialNumber { get; set; }
|
||||
public string SerialNumber { get; set; }
|
||||
public long Id { get; set; }
|
||||
public bool Active { get; }
|
||||
public long DeviceID { get; set; }
|
||||
public string AddDateStr { get { return AddLocalDate == null ? "" : AddLocalDate.Value.ToShortDateString(); } }
|
||||
public string InvoiceDateStr { get { return InvoiceDate == null ? "" : InvoiceDate.Value.ToShortDateString(); } }
|
||||
public string ServiceStartDateStr { get { return ServiceStartDate == null ? "" : ServiceStartDate.Value.ToShortDateString(); } }
|
||||
}
|
||||
|
||||
public class PairedAssetItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name { get; set; }
|
||||
public int Year { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public double? EngineHours { get; set; }
|
||||
public DateTime? EngineHoursDate { get; set; }
|
||||
public DateTime? EngineHoursLocalDate { get; set; }
|
||||
public string EngineHoursDateStr { get { return EngineHoursLocalDate == null ? "" : EngineHoursLocalDate.Value.ToShortDateString(); } }
|
||||
}
|
||||
public class CommentItem
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public DateTime SubmitLocalDate { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public string Comment { get; set; }
|
||||
public string SubmitDateStr { get { return SubmitLocalDate == DateTime.MinValue ? "" : SubmitLocalDate.ToString(); } }
|
||||
}
|
||||
|
||||
public class MachineGroup
|
||||
{
|
||||
public string GroupID { get; set; }
|
||||
public string GroupName { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Code { get; set; }
|
||||
|
||||
public long[] MachineIDs { get; set; }
|
||||
}
|
||||
|
||||
public class AssetMakeItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string IconColor { get; set; }
|
||||
public string AlterActiveName { get; set; }
|
||||
public string AddedBy { get; set; }//companyid
|
||||
public DateTime AddedDate { get; set; }
|
||||
public string Synonyms { get; set; }
|
||||
public bool CanEdit
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemParams.CompanyID.Equals(AddedBy, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetModelItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string AddedBy { get; set; }//companyid
|
||||
public int MakeID { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public string Synonyms { get; set; }
|
||||
|
||||
public bool CanEdit
|
||||
{
|
||||
get
|
||||
{
|
||||
return SystemParams.CompanyID.Equals(AddedBy, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MachineAttributeCategoryClient
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string DisplayText { get; set; }
|
||||
public int TabID { get; set; }
|
||||
public string TabName { get; set; }
|
||||
public int OrderIndex { get; set; }
|
||||
public List<MachineAttributeClient> MachineAttributes { get; set; }
|
||||
}
|
||||
|
||||
public class MachineAttributeClient
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string DisplayText { get; set; }
|
||||
public string Format { get; set; }
|
||||
public string Description { get; set; }
|
||||
public MachineAttributeDataTypes DataType { get; set; }
|
||||
public bool Multiline { get; set; }
|
||||
public int Length { get; set; }
|
||||
public int Precision { get; set; }
|
||||
public string Value { get; set; }
|
||||
public bool Dropdown { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class AssetAttachmentItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public long AssetId { get; set; }
|
||||
public string FileName { get; set; }
|
||||
public string AddedByUserIID { get; set; }
|
||||
public string AddedByUserName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public bool VisibleOnWorkOrder { get; set; }
|
||||
public DateTime AddedOn { get; set; }
|
||||
public string AddedOnStr { get { return AddedOn.ToString(); } }
|
||||
public byte[] FileData { get; set; }
|
||||
}
|
||||
}
|
866
IronIntelContractorBusiness/Machines/MachineManagement.cs
Normal file
866
IronIntelContractorBusiness/Machines/MachineManagement.cs
Normal file
@ -0,0 +1,866 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using IronIntel.Services.MapView;
|
||||
using IronIntel.Services.Customers;
|
||||
using IronIntel.Contractor.Maintenance;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class MachineManagement
|
||||
{
|
||||
private static List<MachineMake> _Makes = new List<MachineMake>();
|
||||
private static object _sycmakes = new object();
|
||||
|
||||
private static List<MachineType> _MachineTypes = new List<MachineType>();
|
||||
private static object _syctypes = new object();
|
||||
|
||||
private static List<MachineModel> _MachineModels = new List<MachineModel>();
|
||||
private static object _sycmodels = new object();
|
||||
|
||||
private const string MachineFields = "{0}MACHINEID,{0}MACHINENAME,{0}MAKEID,{0}MODELID,{0}TYPEID,{0}MACHINEICONID,{0}DEVICEID,{0}VIN,{0}MAKEYEAR,{0}NOTES,{0}STATUS,{0}CONTRACTORID,{0}DEALERID,{0}UID,{0}ADDEDON,{0}CUR_LONGITUDE,{0}CUR_LATITUDE,{0}LOCDATE_UTC,{0}ENGINEHOURS,{0}HOURSDATE_UTC,{0}DATASOURCE,{0}HIDE,{0}FUEL_CONSUMED,{0}FUEL_UNITS,{0}FUEL_DATE,{0}ODOMETER,{0}ODODATE_UTC,{0}ODOMETERUOM,{0}FUELCOST,{0}FUELCOSTUOM,{0}MACHINERATE,{0}WORKTYPE,{0}RETIREMENTHOURS,{0}RETIREMENTODO,{0}ALTITUDE,{0}ALTITUDEUNITS,{0}IDLEHOURSUTC,{0}IDLEHOURS,{0}LOADCOUNTUTC,{0}LOADCOUNT,{0}PAYLOADTOTALUTC,{0}PAYLOADTOTAL,{0}PAYLOADTOTALUNITS,{0}DEFREMAININGUTC,{0}DEFREMAINING,{0}FUELREMAININGUTC,{0}FUELREMAININGPERCENT,{0}MACHINENAME2,{0}ONROAD,{0}LEASESTART,{0}LEASEEND,{0}LEASEHOURS,{0}UNDERCARRIAGEHOURS,{0}ODOSTART2,{0}ISDELETED,{0}DELETEDDATE,{0}ODOSTART2DATASOURCE,{0}LOCDATASOURCE,{0}HOURSDATASOURCE,{0}FUELDATASOURCE,{0}AQUISITIONTYPE,{0}ICONFILENAME,{0}STARTINGENGINEHOURS,{0}DISTANCECALCBY,{0}TELEMATICSENABLED,{0}COSTCENTER,{0}EQCLASS,{0}DESCRIPTION,{0}ADDEDBY";
|
||||
|
||||
static MachineManagement()
|
||||
{
|
||||
RefreshBaseData();
|
||||
}
|
||||
|
||||
public static void RefreshBaseData()
|
||||
{
|
||||
RefreshMakes();
|
||||
RefreshModels();
|
||||
RefreshMachineTypes();
|
||||
}
|
||||
|
||||
public static void RefreshMakes()
|
||||
{
|
||||
MachineMake[] mks = null;
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
try
|
||||
{
|
||||
mks = mc.GetMachineMakes();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (mks != null)
|
||||
{
|
||||
lock (_sycmakes)
|
||||
{
|
||||
_Makes.Clear();
|
||||
_Makes.AddRange(mks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RefreshMachineTypes()
|
||||
{
|
||||
MachineType[] mks = null;
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
try
|
||||
{
|
||||
mks = mc.GetMachineTypes();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (mks != null)
|
||||
{
|
||||
lock (_syctypes)
|
||||
{
|
||||
_MachineTypes.Clear();
|
||||
_MachineTypes.AddRange(mks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void RefreshModels()
|
||||
{
|
||||
MachineModel[] mks = null;
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
try
|
||||
{
|
||||
mks = mc.GetMachineModels();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (mks != null)
|
||||
{
|
||||
lock (_sycmodels)
|
||||
{
|
||||
_MachineModels.Clear();
|
||||
_MachineModels.AddRange(mks);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineMake[] GetMachineMakes()
|
||||
{
|
||||
lock (_sycmakes)
|
||||
{
|
||||
return _Makes.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineType[] GetMachineTypes()
|
||||
{
|
||||
lock (_syctypes)
|
||||
{
|
||||
return _MachineTypes.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineModel[] GetMachineModels()
|
||||
{
|
||||
lock (_sycmodels)
|
||||
{
|
||||
return _MachineModels.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineMake GetMachineMake(int makeid)
|
||||
{
|
||||
var makes = GetMachineMakes();
|
||||
foreach (var make in makes)
|
||||
{
|
||||
if (makeid == make.ID)
|
||||
{
|
||||
return make;
|
||||
}
|
||||
}
|
||||
RefreshMakes();
|
||||
var makes2 = GetMachineMakes();
|
||||
foreach (var make in makes2)
|
||||
{
|
||||
if (makeid == make.ID)
|
||||
{
|
||||
return make;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetMachineMakeName(int makeid)
|
||||
{
|
||||
var make = GetMachineMake(makeid);
|
||||
return make == null ? string.Empty : make.Name;
|
||||
}
|
||||
|
||||
public static MachineModel GetMachineModel(int modelid)
|
||||
{
|
||||
var models = GetMachineModels();
|
||||
foreach (var model in models)
|
||||
{
|
||||
if (model.ID == modelid)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
}
|
||||
RefreshModels();
|
||||
var models2 = GetMachineModels();
|
||||
foreach (var model in models2)
|
||||
{
|
||||
if (model.ID == modelid)
|
||||
{
|
||||
return model;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetMachineModelName(int modelid)
|
||||
{
|
||||
var model = GetMachineModel(modelid);
|
||||
return model == null ? string.Empty : model.Name;
|
||||
}
|
||||
|
||||
public static MachineType GetMachineType(int typeid)
|
||||
{
|
||||
var types = GetMachineTypes();
|
||||
foreach (var mtype in types)
|
||||
{
|
||||
if (mtype.ID == typeid)
|
||||
{
|
||||
return mtype;
|
||||
}
|
||||
}
|
||||
RefreshMachineTypes();
|
||||
var types2 = GetMachineTypes();
|
||||
foreach (var mtype in types2)
|
||||
{
|
||||
if (mtype.ID == typeid)
|
||||
{
|
||||
return mtype;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetMachineTypeName(int typeid)
|
||||
{
|
||||
var mtype = GetMachineType(typeid);
|
||||
return mtype == null ? string.Empty : mtype.Name;
|
||||
}
|
||||
|
||||
public static MachineMake GetMachineMake(IEnumerable<MachineMake> makes, int id)
|
||||
{
|
||||
foreach (MachineMake mk in makes)
|
||||
{
|
||||
if (id == mk.ID)
|
||||
{
|
||||
return mk;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MachineType GetMachineType(IEnumerable<MachineType> types, int id)
|
||||
{
|
||||
foreach (MachineType mk in types)
|
||||
{
|
||||
if (id == mk.ID)
|
||||
{
|
||||
return mk;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static MachineModel GetMachineModel(IEnumerable<MachineModel> models, int id)
|
||||
{
|
||||
foreach (MachineModel mk in models)
|
||||
{
|
||||
if (id == mk.ID)
|
||||
{
|
||||
return mk;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static string _DefaultMachineTypeIconUrl = string.Empty;
|
||||
|
||||
public static string DefaultMachineTypeIconUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_DefaultMachineTypeIconUrl))
|
||||
{
|
||||
try
|
||||
{
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
_DefaultMachineTypeIconUrl = mc.GetDefaultMachineTypeIconUrl();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
return _DefaultMachineTypeIconUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineAlertViewClient GetMachineAlertViewClient()
|
||||
{
|
||||
string[] address = SystemParams.SystemServiceAddresses;
|
||||
MachineAlertViewClient ic = new MachineAlertViewClient(address[0]);
|
||||
return ic;
|
||||
}
|
||||
|
||||
public static bool Contains(string text, string val)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
return text.IndexOf(val, StringComparison.OrdinalIgnoreCase) >= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdateMachineHideStatus(IEnumerable<Tuple<long, bool>> machines)
|
||||
{
|
||||
const string SQL = "update MACHINES set HIDE={1} where MACHINEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
foreach (Tuple<long, bool> mac in machines)
|
||||
{
|
||||
db.ExecSQL(SQL, mac.Item1, mac.Item2 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static MachineItem GetMachineByID(string sessionid, long machineid, FIDbAccess db = null)
|
||||
{
|
||||
string SQL = "select " + string.Format(MachineFields, "") + " from MACHINES where MACHINEID={0}";
|
||||
|
||||
if (db == null)
|
||||
{
|
||||
db = SystemParams.GetDbInstance();
|
||||
}
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, machineid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
MachineItem mi = null;
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
mi = ConvertToMachineItem(tb.Rows[0], makes, models, types);
|
||||
mi.AddedOn = FIDbAccess.GetFieldDateTime(tb.Rows[0]["ADDEDON"], DateTime.MinValue).AddHours(SystemParams.GetHoursOffset());
|
||||
mi.AddedBy = FIDbAccess.GetFieldString(tb.Rows[0]["ADDEDBY"], string.Empty);
|
||||
if (!string.IsNullOrEmpty(mi.AddedBy))
|
||||
{
|
||||
var user = Users.UserManagement.GetUserByIID(mi.AddedBy);
|
||||
mi.AddedByName = user == null ? mi.AddedBy : user.DisplayName;
|
||||
}
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static MachineItem[] GetMachines(string sessionid, string useriid, string searchtxt, string companyid = null)
|
||||
{
|
||||
string SQL = "select " + string.Format(MachineFields, "") + " from MACHINES order by MACHINENAME";
|
||||
|
||||
FIDbAccess db = null;
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
{
|
||||
companyid = SystemParams.CompanyID;
|
||||
db = SystemParams.GetDbInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MachineItem[0];
|
||||
}
|
||||
long[] availableAssetsids = null;
|
||||
IronIntel.Contractor.Users.UserInfo user = null;
|
||||
if (!string.IsNullOrWhiteSpace(useriid))
|
||||
{
|
||||
user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAvailableAssetsForUsers(companyid, useriid);
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MachineItem> ls = new List<MachineItem>();
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (!string.IsNullOrWhiteSpace(useriid) && user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
|
||||
MachineItem mi = ConvertToMachineItem(dr, makes, models, types);
|
||||
if (!string.IsNullOrWhiteSpace(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(mi.VIN, searchtxt)
|
||||
|| Helper.Contains(mi.MachineID.ToString(), searchtxt)
|
||||
|| Helper.Contains(mi.Name, searchtxt)
|
||||
|| Helper.Contains(mi.Name2, searchtxt)
|
||||
|| Helper.Contains(mi.Make, searchtxt)
|
||||
|| Helper.Contains(mi.MachineType, searchtxt)
|
||||
|| Helper.Contains(mi.Model, searchtxt))
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public static MachineItem[] GetSelectMachinesByRental(string sessionid, string useriid, string searchtxt, string companyid = null)
|
||||
{
|
||||
string SQL = "select " + string.Format(MachineFields, "") + " from MACHINES where AQUISITIONTYPE in ('Rental','Rerent','RPO') order by MACHINENAME";
|
||||
|
||||
FIDbAccess db = null;
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
{
|
||||
companyid = SystemParams.CompanyID;
|
||||
db = SystemParams.GetDbInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MachineItem[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAvailableAssetsForUsers(companyid, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MachineItem> ls = new List<MachineItem>();
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
MachineItem mi = ConvertToMachineItem(dr, makes, models, types);
|
||||
if (!string.IsNullOrWhiteSpace(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(mi.VIN, searchtxt)
|
||||
|| Helper.Contains(mi.MachineID.ToString(), searchtxt)
|
||||
|| Helper.Contains(mi.Name, searchtxt)
|
||||
|| Helper.Contains(mi.Name2, searchtxt)
|
||||
|| Helper.Contains(mi.Make, searchtxt)
|
||||
|| Helper.Contains(mi.MachineType, searchtxt)
|
||||
|| Helper.Contains(mi.Model, searchtxt))
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
private static MachineItem ConvertToMachineItem(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types)
|
||||
{
|
||||
MachineItem mi = new MachineItem();
|
||||
mi.MachineID = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
mi.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
mi.MakeYear = FIDbAccess.GetFieldInt(dr["MAKEYEAR"], 0);
|
||||
mi.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
mi.DealerID = FIDbAccess.GetFieldString(dr["DEALERID"], string.Empty);
|
||||
mi.Status = FIDbAccess.GetFieldInt(dr["STATUS"], 0);
|
||||
mi.StartingEngineHours = FIDbAccess.GetFieldDouble(dr["STARTINGENGINEHOURS"], 0);
|
||||
mi.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
mi.EngineHoursDate = FIDbAccess.GetFieldDateTime(dr["HOURSDATE_UTC"], DateTime.MinValue);
|
||||
mi.Hide = FIDbAccess.GetFieldInt(dr["HIDE"], 0) == 1;
|
||||
mi.ODOStart2 = FIDbAccess.GetFieldDouble(dr["ODOSTART2"], 0);
|
||||
mi.ODOMeter = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
mi.ODOMeterDate = FIDbAccess.GetFieldDateTime(dr["ODODATE_UTC"], DateTime.MinValue);
|
||||
mi.ODOMeterUom = FIDbAccess.GetFieldString(dr["ODOMETERUOM"], string.Empty);
|
||||
mi.FuelCost = FIDbAccess.GetFieldDouble(dr["FUELCOST"], 0);
|
||||
mi.FuelCostUom = FIDbAccess.GetFieldString(dr["FUELCOSTUOM"], string.Empty);
|
||||
mi.MachineRate = FIDbAccess.GetFieldDouble(dr["MACHINERATE"], 0);
|
||||
mi.WorkType = FIDbAccess.GetFieldString(dr["WORKTYPE"], string.Empty);
|
||||
mi.RetirementHours = FIDbAccess.GetFieldDouble(dr["RETIREMENTHOURS"], 0);
|
||||
mi.RetirementOdo = FIDbAccess.GetFieldDouble(dr["RETIREMENTODO"], 0);
|
||||
|
||||
mi.MakeID = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, mi.MakeID);
|
||||
mi.Make = make == null ? string.Empty : make.Name;
|
||||
|
||||
mi.ModelID = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, mi.ModelID);
|
||||
mi.Model = model == null ? string.Empty : model.Name;
|
||||
|
||||
mi.TypeID = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, mi.TypeID);
|
||||
mi.MachineType = mtype == null ? string.Empty : mtype.Name;
|
||||
mi.OnRoad = FIDbAccess.GetFieldInt(dr["ONROAD"], 0) == 1;
|
||||
mi.LeaseStart = FIDbAccess.GetFieldDateTime(dr["LEASESTART"], DateTime.MinValue);
|
||||
mi.LeaseEnd = FIDbAccess.GetFieldDateTime(dr["LEASEEND"], DateTime.MinValue);
|
||||
mi.LeaseTerm = FIDbAccess.GetFieldDouble(dr["LEASEHOURS"], 0);
|
||||
mi.UndercarriageHours = FIDbAccess.GetFieldDouble(dr["UNDERCARRIAGEHOURS"], 0);
|
||||
mi.AquisitionType = FIDbAccess.GetFieldString(dr["AQUISITIONTYPE"], "");
|
||||
|
||||
mi.GpsDeviceID = FIDbAccess.GetFieldInt(dr["DEVICEID"], -1);
|
||||
mi.MachineIconFileName = FIDbAccess.GetFieldString(dr["ICONFILENAME"], "");
|
||||
mi.DistanceCalcBy = FIDbAccess.GetFieldString(dr["DISTANCECALCBY"], "");
|
||||
|
||||
mi.TelematicsEnabled = FIDbAccess.GetFieldInt(dr["TELEMATICSENABLED"], 0) == 1;
|
||||
mi.CostCenter = FIDbAccess.GetFieldString(dr["COSTCENTER"], "");
|
||||
mi.EqClass = FIDbAccess.GetFieldString(dr["EQCLASS"], "");
|
||||
mi.Description = FIDbAccess.GetFieldString(dr["DESCRIPTION"], "");
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static int SaveMachineGroup(MachineGroup mg)
|
||||
{
|
||||
const string SQL_Insert = "insert into MACHINEGROUPS (GROUPID,GROUPNAME,DESCRIPTION,CODE) values ({0},{1},{2},{3})";
|
||||
const string SQL_Update = "update MACHINEGROUPS set GROUPNAME={1},DESCRIPTION={2},CODE={3} where GROUPID={0} ";
|
||||
const string SQL_Exists = "select Count(1) from MACHINEGROUPS where GROUPNAME={0} and GROUPID<>{1}";
|
||||
const string SQL_DeleteDetail = "delete MACHINEGROUPMAP where GROUPID={0}";
|
||||
const string SQL_InsertDetail = "insert MACHINEGROUPMAP(MACHINEID,GROUPID) values({0},{1})";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
|
||||
int count = FIDbAccess.GetFieldInt(db.GetRC1BySQL(SQL_Exists, mg.GroupName, mg.GroupID ?? ""), 0);
|
||||
if (count > 0)
|
||||
return -1;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(mg.GroupID))
|
||||
{
|
||||
mg.GroupID = Guid.NewGuid().ToString();
|
||||
db.ExecSQL(SQL_Insert, mg.GroupID, mg.GroupName, mg.Description, mg.Code);
|
||||
if (mg.MachineIDs != null && mg.MachineIDs.Length > 0)
|
||||
{
|
||||
foreach (long mid in mg.MachineIDs)
|
||||
db.ExecSQL(SQL_InsertDetail, mid, mg.GroupID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
db.ExecSQL(SQL_Update, mg.GroupID, mg.GroupName, mg.Description, mg.Code);
|
||||
db.ExecSQL(SQL_DeleteDetail, mg.GroupID);
|
||||
if (mg.MachineIDs != null && mg.MachineIDs.Length > 0)
|
||||
{
|
||||
foreach (long mid in mg.MachineIDs)
|
||||
db.ExecSQL(SQL_InsertDetail, mid, mg.GroupID);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void SaveMachineToMachineGroups(FISqlConnection db, long machineid, string[] groupids)
|
||||
{
|
||||
const string SQL = "insert into MACHINEGROUPMAP(MACHINEID,GROUPID) values({0},{1})";
|
||||
const string SQL_DEL = "delete from MACHINEGROUPMAP where MACHINEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_DEL, machineid);
|
||||
if (groupids != null && groupids.Length > 0)
|
||||
{
|
||||
foreach (var groupid in groupids)
|
||||
{
|
||||
db.ExecSQL(SQL, machineid, groupid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static int DeleteMachineGroup(string groupID)
|
||||
{
|
||||
const string SQL_Delete = "delete from MACHINEGROUPS where GROUPID={0} delete from MACHINEGROUPMAP where GROUPID={0} ";
|
||||
const string SQL_Exists = "select Count(1) from USERMACHINEGROUPMAP where GROUPID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
int count = FIDbAccess.GetFieldInt(db.GetRC1BySQL(SQL_Exists, groupID ?? ""), 0);
|
||||
if (count > 0)
|
||||
return -1;
|
||||
|
||||
db.ExecSQL(SQL_Delete, groupID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static MachineGroup[] GetMachineGroups(string searchtext, FISqlConnection db = null)
|
||||
{
|
||||
string SQL = "select GROUPID,GROUPNAME,DESCRIPTION,CODE from MACHINEGROUPS ";
|
||||
if (!string.IsNullOrEmpty(searchtext))
|
||||
SQL += " where GROUPNAME like {0} or DESCRIPTION like {0} or CODE like {0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, "%" + searchtext + "%");
|
||||
|
||||
List<MachineGroup> result = new List<MachineGroup>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineGroup mg = new MachineGroup();
|
||||
mg.GroupID = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
mg.GroupName = FIDbAccess.GetFieldString(dr["GROUPNAME"], "");
|
||||
mg.Description = FIDbAccess.GetFieldString(dr["DESCRIPTION"], "");
|
||||
mg.Code = FIDbAccess.GetFieldString(dr["CODE"], "");
|
||||
result.Add(mg);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static MachineGroup[] GetMachineGroupsByUser(string useriid, FISqlConnection db = null)
|
||||
{
|
||||
string SQL = @"select GROUPID,GROUPNAME,DESCRIPTION from MACHINEGROUPS mg where (select case when not exists(select 1 from USERMACHINEGROUPMAP where USERIID={0}) then 1
|
||||
when exists(select 1 from USERMACHINEGROUPMAP g where USERIID={0} and mg.GROUPID=g.GROUPID) then 1 else 0 end) = 1";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, useriid);
|
||||
|
||||
List<MachineGroup> result = new List<MachineGroup>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineGroup mg = new MachineGroup();
|
||||
mg.GroupID = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
mg.GroupName = FIDbAccess.GetFieldString(dr["GROUPNAME"], "");
|
||||
mg.Description = FIDbAccess.GetFieldString(dr["DESCRIPTION"], "");
|
||||
result.Add(mg);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static MachineItem[] GetMachineByGroup(string groupid)
|
||||
{
|
||||
string SQL = "select " + string.Format(MachineFields, "b.") + " from MACHINEGROUPMAP a left join MACHINES b on a.MACHINEID=b.MACHINEID where a.GROUPID={0} order by MACHINENAME";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
if (db == null)
|
||||
{
|
||||
return new MachineItem[0];
|
||||
}
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, groupid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MachineItem[0];
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MachineItem> ls = new List<MachineItem>();
|
||||
if (tb.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MachineItem mi = ConvertToMachineItem(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public static MachineGroup[] GetMachineGroupByUser(string useriid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = "select b.* from USERMACHINEGROUPMAP a left join MACHINEGROUPS b on a.GROUPID=b.GROUPID where a.USERIID={0} order by GROUPNAME";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, useriid);
|
||||
|
||||
List<MachineGroup> result = new List<MachineGroup>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineGroup mg = new MachineGroup();
|
||||
mg.GroupID = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
mg.GroupName = FIDbAccess.GetFieldString(dr["GROUPNAME"], "");
|
||||
mg.Description = FIDbAccess.GetFieldString(dr["DESCRIPTION"], "");
|
||||
result.Add(mg);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static void SaveUserMachineGroup(string useriid, string[] groupids)
|
||||
{
|
||||
const string SQL_DeleteDetail = "delete USERMACHINEGROUPMAP where USERIID={0}";
|
||||
const string SQL_InsertDetail = "insert USERMACHINEGROUPMAP(USERIID,GROUPID) values({0},{1})";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
|
||||
db.ExecSQL(SQL_DeleteDetail, useriid);
|
||||
if (groupids != null && groupids.Length > 0)
|
||||
{
|
||||
foreach (string gid in groupids)
|
||||
db.ExecSQL(SQL_InsertDetail, useriid, gid);
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<int, List<StringKeyValue>> GetGroupsAssets(FISqlConnection db = null)
|
||||
{
|
||||
const string SQL_C = "select mgm.MACHINEID,mgm.GROUPID,mg.GROUPNAME from MACHINEGROUPMAP mgm left join MACHINEGROUPS mg on mgm.GROUPID=mg.GROUPID";
|
||||
|
||||
Dictionary<int, List<StringKeyValue>> result = new Dictionary<int, List<StringKeyValue>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C);
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], -1);
|
||||
StringKeyValue kv = new StringKeyValue();
|
||||
kv.Key = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
kv.Value = FIDbAccess.GetFieldString(dr["GROUPNAME"], ""); ;
|
||||
if (!result.ContainsKey(machineid))
|
||||
result[machineid] = new List<StringKeyValue>();
|
||||
result[machineid].Add(kv);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器组和机器的对应关系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<int, List<string>> GetGroupMachines(FISqlConnection db = null)
|
||||
{
|
||||
const string SQL_C = "select MACHINEID,GROUPID from MACHINEGROUPMAP";
|
||||
|
||||
Dictionary<int, List<string>> result = new Dictionary<int, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C);
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], -1);
|
||||
string groupid = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
if (!result.ContainsKey(machineid))
|
||||
result[machineid] = new List<string>();
|
||||
result[machineid].Add(groupid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器组和机器的对应关系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static long[] GetGroupMachines(string[] groupids, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL_C = "select distinct MACHINEID from MACHINEGROUPMAP where GROUPID in ({0})";
|
||||
|
||||
List<long> result = new List<long>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(string.Format(SQL_C, "'" + string.Join("','", groupids) + "'"));
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], -1);
|
||||
result.Add(machineid);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器组
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static string[] GetGroupByMachineID(FISqlConnection db, long machineid)
|
||||
{
|
||||
const string SQL_C = "select GROUPID from MACHINEGROUPMAP where MACHINEID={0}";
|
||||
|
||||
Dictionary<int, List<string>> result = new Dictionary<int, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C, machineid);
|
||||
if (tb.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
string groupid = FIDbAccess.GetFieldString(dr["GROUPID"], "");
|
||||
list.Add(groupid);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static void ChangeMachineIconFile(long machineid, string filename, byte[] filebyte, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL_NULL = "update MACHINES set ICONFILENAME=null,ICONDATA=null where MACHINEID={0}";
|
||||
const string SQL_ICON = "update MACHINES set ICONFILENAME={1},ICONDATA={2} where MACHINEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
if (filebyte == null)
|
||||
db.ExecSQL(SQL_NULL, machineid);
|
||||
else
|
||||
db.ExecSQL(SQL_ICON, machineid, filename, filebyte);
|
||||
}
|
||||
|
||||
public static byte[] GetMachineIconFile(string companyid, long machineid)
|
||||
{
|
||||
const string SQL = "select ICONDATA from MACHINES where MACHINEID={0}";
|
||||
FISqlConnection db = null;
|
||||
if (SystemParams.IsDealer)
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
else
|
||||
db = SystemParams.GetDbInstance();
|
||||
|
||||
object obj = db.GetRC1BySQL(SQL, machineid);
|
||||
return FIDbAccess.GetFieldBytes(obj);
|
||||
}
|
||||
|
||||
public static MachineInfo2 GetMachineByVIN(string vin)
|
||||
{
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
return mc.GetMachineInfoByVIN(vin);
|
||||
}
|
||||
|
||||
public static MachineInfo2 GetMachineByID(long machineid)
|
||||
{
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
return mc.GetMachineInfoByMachineID(machineid);
|
||||
}
|
||||
|
||||
public static string GetMachineIDByVIN(string vin)
|
||||
{
|
||||
const string SQL = "select MACHINEID from MACHINES where VIN={0} and isnull(HIDE,0)=0";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
|
||||
object obj = db.GetRC1BySQL(SQL, vin);
|
||||
return FIDbAccess.GetFieldString(obj, string.Empty);
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetContactMachinesByID(string contactid)
|
||||
{
|
||||
const string SQL = @"select a.MACHINEID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,b.HIDE,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(b.ODOMETER,0) as ODOMETER,ISNULL(b.ODOMETERUOM,'Mile') AS ODOMETERUOM from USERMACHINEMAP a,MACHINES b
|
||||
where a.MACHINEID=b.MACHINEID and a.USERIID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, contactid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MaintenanceMachineInfo mi = MaintenanceManagement.ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
89
IronIntelContractorBusiness/Machines/MachineRentalInfo.cs
Normal file
89
IronIntelContractorBusiness/Machines/MachineRentalInfo.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class MachineRentalInfo
|
||||
{
|
||||
public long RentalID { get; set; }
|
||||
public long MachineID { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string AquisitionType { get; set; }
|
||||
public string AssetID { get; set; }
|
||||
public string Division { get; set; }
|
||||
public string EQClass { get; set; }
|
||||
public string Outside { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Vendor { get; set; }
|
||||
public int Term { get; set; }
|
||||
public string TermUnit { get; set; }
|
||||
public decimal RentalRate { get; set; }
|
||||
public DateTime? RentalDate { get; set; }
|
||||
public string RentalDateStr { get { return RentalDate == null ? "" : RentalDate.Value.ToShortDateString(); } }
|
||||
public DateTime? ProjectReturnDate { get; set; }
|
||||
public string ProjectReturnDateStr { get { return ProjectReturnDate == null ? "" : ProjectReturnDate.Value.ToShortDateString(); } }
|
||||
public DateTime? ReturnDate { get; set; }
|
||||
public string ReturnDateStr { get { return ReturnDate == null ? "" : ReturnDate.Value.ToShortDateString(); } }
|
||||
public string PONumber { get; set; }
|
||||
public string Comments { get; set; }
|
||||
|
||||
public DateTime? RentalTermBillingDate { get; set; }
|
||||
public string RentalTermBillingDateStr { get { return RentalTermBillingDate == null ? "" : RentalTermBillingDate.Value.ToShortDateString(); } }
|
||||
public int BillingCycleDays { get; set; }
|
||||
|
||||
public bool Selected { get; set; }
|
||||
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = MachineName;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineID.ToString();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public string RentalStatus
|
||||
{
|
||||
get
|
||||
{
|
||||
//5.Can we add a rental status to Rental Information section:
|
||||
//a.Rental Information: ON RENT(if we are past the Start Date and the return date is blank or a future date and the Proj Return Date is blank or today or greater)
|
||||
//b.Rental Information: OVERDUE(if we are past the Start Date and the Proj Return Date is past and Return Date is Blank)
|
||||
//c.Rental Information: RETURNED(if Return Date is populated today or less).
|
||||
|
||||
DateTime today = DateTime.Now.Date;
|
||||
if (RentalDate < today
|
||||
&& (ReturnDate == null || ReturnDate > today)
|
||||
&& (ProjectReturnDate == null || ProjectReturnDate >= today))
|
||||
return "ON RENT";
|
||||
if (RentalDate < today
|
||||
&& (ProjectReturnDate != null && ProjectReturnDate < today)
|
||||
&& ReturnDate == null)
|
||||
return "OVERDUE";
|
||||
if (ReturnDate <= today)
|
||||
return "RETURNED";
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class RentalChangeHistoryInfo : MachineRentalInfo
|
||||
{
|
||||
public string OperateType { get; set; }
|
||||
public string LastUpdateUserName { get; set; }
|
||||
public string LastUpdatedBy { get; set; }
|
||||
public DateTime? LastUpdateDate { get; set; }
|
||||
public string LastUpdateDateStr { get { return LastUpdateDate == null ? "" : LastUpdateDate.Value.ToShortDateString(); } }
|
||||
|
||||
}
|
||||
}
|
179
IronIntelContractorBusiness/Machines/OdometerInfo.cs
Normal file
179
IronIntelContractorBusiness/Machines/OdometerInfo.cs
Normal file
@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Machines
|
||||
{
|
||||
public class OdometerInfo
|
||||
{
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string DataSourceName { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public bool IsPrimary { get; set; }
|
||||
|
||||
public string UOM { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private double _Corrected;
|
||||
public double Corrected
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Corrected;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Corrected = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string ReceivedDateStr
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTimeLocal.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AdjustOdometerInfo
|
||||
{
|
||||
public string CustomerID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public DateTime OdometerDate { get; set; }
|
||||
public string UOM { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string Notes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 前端选择的时区的分钟偏移
|
||||
/// </summary>
|
||||
public int OffsetMinute { get; set; }
|
||||
}
|
||||
public class CalampOdometerInfo
|
||||
{
|
||||
public long AssetId { get; set; }
|
||||
public string DeviceAirId { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public double Gps { get; set; }
|
||||
public double Gps_Calc { get; set; }
|
||||
public double VBUS { get; set; }
|
||||
public double VBUS_Calc { get; set; }
|
||||
public string EventTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
public DateTime AsofTime_Local { get; set; }
|
||||
public string EventTimeLocalText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime_Local.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PedigreeOdometerInfo
|
||||
{
|
||||
public long AssetId { get; set; }
|
||||
public string DeviceSN { get; set; }
|
||||
public DateTime AsofTime { get; set; }
|
||||
public string UOM { get; set; }
|
||||
public double Gps { get; set; }
|
||||
public double Gps_Calc { get; set; }
|
||||
public double VBUS { get; set; }
|
||||
public double VBUS_Calc { get; set; }
|
||||
public string EventTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
public DateTime AsofTime_Local { get; set; }
|
||||
public string EventTimeLocalText
|
||||
{
|
||||
get
|
||||
{
|
||||
return AsofTime_Local.ToString("MM/dd/yyyy HH:mm");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PrimaryDataSourceInfo
|
||||
{
|
||||
public int Type { get; set; } //Odometer:0,EngineHours:1
|
||||
public string CustomerID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string SubSource { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
|
||||
public class AssetOdometerAdjustItem
|
||||
{
|
||||
public long LogId { get; set; }
|
||||
public long AssetId { get; set; }
|
||||
public DateTime AdjustmentTime { get; set; }
|
||||
public string AdjustmentTimeText { get { return AdjustmentTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime OdometerTime { get; set; }
|
||||
public string OdometerTimeText { get { return OdometerTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime AdjustmentLocalTime { get; set; }
|
||||
public string AdjustmentLocalTimeText { get { return AdjustmentLocalTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public DateTime OdometerLocalTime { get; set; }
|
||||
public string OdometerLocalTimeText { get { return OdometerLocalTime.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string UOM { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string UserName { get; set; }
|
||||
}
|
||||
}
|
131
IronIntelContractorBusiness/Maintenance/AlertInfo.cs
Normal file
131
IronIntelContractorBusiness/Maintenance/AlertInfo.cs
Normal file
@ -0,0 +1,131 @@
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class AlertInfo
|
||||
{
|
||||
public long AlertID { get; set; }
|
||||
public long WorkOrderID { get; set; }
|
||||
public string WorkOrderStatus { get; set; }
|
||||
public string AlertType { get; set; }
|
||||
public DateTime AlertTime_UTC { get; set; }
|
||||
public string AlertTime_UTCStr { get { return AlertTime_UTC == DateTime.MinValue ? "" : AlertTime_UTC.ToString(); } }
|
||||
public bool Completed { get; set; }
|
||||
public long MachineID { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int MakeID { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
private double _CurrentHours;
|
||||
public double CurrentHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _CurrentHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_CurrentHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string Description { get; set; }
|
||||
public string ServiceDescription { get; set; }
|
||||
public int AlertCount { get; set; }
|
||||
public List<long> RepeatedAlerts { get; set; }
|
||||
public int OpenWorkOrderCount { get; set; }//针对Alert对应的机器
|
||||
public string PMType { get; set; }
|
||||
public string AcknowledgedBy { get; set; }
|
||||
public string AcknowledgedByName { get; set; }
|
||||
public DateTime AcknowledgedTime_UTC { get; set; }
|
||||
public string AcknowledgedTime_UTCStr { get { return AcknowledgedTime_UTC == DateTime.MinValue ? "" : AcknowledgedTime_UTC.ToString(); } }
|
||||
public string AcknowledgedComment { get; set; }
|
||||
}
|
||||
|
||||
public class MachineInfoForAlert
|
||||
{
|
||||
public long MachineID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public int DTCAlertCount { get; set; }
|
||||
public int PMAlertCount { get; set; }
|
||||
public int InspectAlertCount { get; set; }
|
||||
public int OpenWorkOrders { get; set; }
|
||||
public DateTime LatestAlertDateTime { get; set; }
|
||||
public string LatestAlertDateTimeStr { get { return LatestAlertDateTime == DateTime.MinValue ? "" : LatestAlertDateTime.ToString(); } }
|
||||
|
||||
public List<AlertInfo> Alerts { get; } = new List<AlertInfo>();
|
||||
}
|
||||
|
||||
public class AssetAlertInfo
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public DateTime AlertTime { get; set; }
|
||||
public string AlertTimeStr { get { return AlertTime == DateTime.MinValue ? "" : AlertTime.ToString(); } }
|
||||
public string AlertType { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public string AssetTypeName { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public bool Completed { get; set; }
|
||||
public DateTime? CompletedDate { get; set; }
|
||||
public string CompletedDateStr { get { return CompletedDate == null ? "" : CompletedDate.ToString(); } }
|
||||
|
||||
public AssetAlertCategory Category { get; set; }
|
||||
}
|
||||
}
|
566
IronIntelContractorBusiness/Maintenance/AlertManager.cs
Normal file
566
IronIntelContractorBusiness/Maintenance/AlertManager.cs
Normal file
@ -0,0 +1,566 @@
|
||||
using Foresight.Data;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static IronIntel.Contractor.MapView.MachinesMapViewerManagement;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class AlertManager : BusinessBase
|
||||
{
|
||||
public AlertManager(string dbstr) : base(dbstr)
|
||||
{
|
||||
}
|
||||
|
||||
const string SEL_ALERT = "select ALERTID,ALERTTYPE,ALERTTIME_UTC,COMPLETED,MACHINEID,VIN,MACHINENAME,ENGINGHOURS,ALERTDESC,PMTYPE from ALERTS";
|
||||
|
||||
public MachineInfoForAlert[] SearchMachineAlerts(string sessionid, string filtertext, string[] alertstatus, string[] alerttypes, string[] assetgroups, DateTime beginDate, DateTime endDate, string useriid)
|
||||
{
|
||||
string SQL = @"select a.ALERTID,w.WORKORDERID,wo.STATUS,ALERTTYPE,a.ALERTTIME_UTC,ISNULL(COMPLETED,0) COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME,a.ENGINGHOURS,m.ENGINEHOURS as CENGINGHOURS,ALERTDESC,m.MACHINENAME2
|
||||
,a.MAKEID,a.MODELID,pit.SERVICEDESCRIPTION
|
||||
,(select count(1) from WORKORDER wo1 where wo1.MACHINEID=a.MACHINEID and wo1.STATUS<>'Completed') as OpenWorkOrderCount,m.ONROAD,a.PMTYPE from ALERTS a with (nolock)
|
||||
left join WORKORDER_ALERTS w with (nolock) on a.ALERTID=w.ALERTID
|
||||
left join WORKORDER wo with (nolock) on w.WORKORDERID=wo.WORKORDERID
|
||||
left join MACHINES m with (nolock) on a.MACHINEID=m.MACHINEID
|
||||
left join PM_ALERTS pa with (nolock) on a.ALERTID=pa.ALERTID
|
||||
left join PM_INTERAVLS pit with (nolock) on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
where m.MACHINEID is not null and (m.HIDE=0 or m.HIDE is null) and ISNULL(ACKNOWLEDGED,0)<>1 and a.ALERTTIME_UTC>={0} and a.ALERTTIME_UTC<={1} ";
|
||||
|
||||
if (Array.IndexOf(alertstatus, "Completed") >= 0 && Array.IndexOf(alertstatus, "Uncompleted") < 0)
|
||||
SQL = SQL + " and ISNULL(COMPLETED,0)=1 ";
|
||||
if (Array.IndexOf(alertstatus, "Completed") < 0 && Array.IndexOf(alertstatus, "Uncompleted") >= 0)
|
||||
SQL = SQL + " and ISNULL(COMPLETED,0)=0 ";
|
||||
if (Array.IndexOf(alertstatus, "Assigned") >= 0 && Array.IndexOf(alertstatus, "Unassigned") < 0)
|
||||
SQL = SQL + " and w.WORKORDERID is not null ";
|
||||
else if (Array.IndexOf(alertstatus, "Assigned") < 0 && Array.IndexOf(alertstatus, "Unassigned") >= 0)
|
||||
SQL = SQL + " and w.WORKORDERID is null ";
|
||||
|
||||
if (assetgroups.Length > 0)//asset group
|
||||
{
|
||||
SQL = SQL + string.Format(" and exists(select 1 from MACHINEGROUPMAP mg where mg.MACHINEID=m.MACHINEID and GROUPID in ('{0}'))", string.Join("','", assetgroups));
|
||||
}
|
||||
|
||||
string SQL_FILTER = SQL + " and (ALERTTYPE like {0} or a.MACHINEID like {0} or a.VIN like {0} or a.MACHINENAME like {0} or m.MACHINENAME2 like {0} or ALERTDESC like {0} or SERVICEDESCRIPTION like {0})";
|
||||
|
||||
string ORDER_BY = " order by ALERTID";
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
if (beginDate != Helper.DBMinDateTime)
|
||||
beginDate = beginDate.AddHours(-timeadjust);
|
||||
if (endDate != DateTime.MaxValue)
|
||||
endDate = endDate.AddHours(-timeadjust);
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL + ORDER_BY, beginDate, endDate);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MachineInfoForAlert[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
MachineMake[] _makes = mc.GetMachineMakes();
|
||||
MachineModel[] _models = mc.GetMachineModels();
|
||||
|
||||
List<MachineInfoForAlert> results = new List<MachineInfoForAlert>(dt.Rows.Count);
|
||||
Dictionary<string, AssetEngineHour> machineEngineHours = GetAssetEngineHour();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
string alerttype = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty).Trim();
|
||||
if (alerttypes.Length > 0 && !alerttypes.Contains(alerttype))//alerttype
|
||||
continue;
|
||||
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ai.WorkOrderID = FIDbAccess.GetFieldInt(dr["WORKORDERID"], 0);
|
||||
ai.WorkOrderStatus = FIDbAccess.GetFieldString(dr["STATUS"], string.Empty);
|
||||
ai.MakeID = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
ai.ModelID = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
string name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
string showname = name2;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineName;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.VIN;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineID.ToString();
|
||||
ai.MachineName = showname;
|
||||
|
||||
MachineMake mk = _makes.FirstOrDefault(m => m.ID == ai.MakeID);
|
||||
if (mk != null)
|
||||
ai.Make = mk.Name;
|
||||
MachineModel md = _models.FirstOrDefault(m => m.ID == ai.ModelID);
|
||||
if (md != null)
|
||||
ai.Model = md.Name;
|
||||
|
||||
MachineInfoForAlert mi = results.FirstOrDefault((i) => i.MachineID == ai.MachineID);
|
||||
if (mi == null)
|
||||
{
|
||||
mi = new MachineInfoForAlert();
|
||||
mi.MachineID = ai.MachineID;
|
||||
mi.MachineName = ai.MachineName;
|
||||
mi.VIN = ai.VIN;
|
||||
mi.Make = ai.Make;
|
||||
mi.Model = ai.Model;
|
||||
mi.EngineHours = FIDbAccess.GetFieldDouble(dr["CENGINGHOURS"], 0);// ai.EngineHours;
|
||||
if (machineEngineHours.ContainsKey(mi.MachineID.ToString()))
|
||||
{
|
||||
var meh = machineEngineHours[mi.MachineID.ToString()];
|
||||
mi.EngineHours = meh.EngineHours;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(filtertext))
|
||||
{
|
||||
if (Helper.Contains(ai.AlertType, filtertext)
|
||||
|| Helper.Contains(ai.MachineID.ToString(), filtertext)
|
||||
|| Helper.Contains(ai.VIN, filtertext)
|
||||
|| Helper.Contains(ai.MachineName, filtertext)
|
||||
|| Helper.Contains(ai.Description, filtertext)
|
||||
//|| Helper.Contains(ai.ServiceDescription, filtertext)
|
||||
|| Helper.Contains(mi.Make, filtertext)
|
||||
|| Helper.Contains(mi.Model, filtertext))
|
||||
results.Add(mi);
|
||||
}
|
||||
else
|
||||
results.Add(mi);
|
||||
}
|
||||
|
||||
if (ai.PMType == "PM_ALERT" || ai.PMType == "TBM_ALERT" || ai.PMType == "HM_ALERT"
|
||||
|| ai.PMType == "RDM_ALERT" || ai.PMType == "ADM_ALERT")
|
||||
mi.PMAlertCount++;
|
||||
else if (ai.AlertType == "Red-Inspect" || ai.AlertType == "Yellow-Inspect" || ai.AlertType == "Info-Inspect")
|
||||
mi.InspectAlertCount++;
|
||||
else
|
||||
mi.DTCAlertCount++;
|
||||
|
||||
AlertInfo oildai = mi.Alerts.FirstOrDefault(m => m.Description == ai.Description && m.MachineID == ai.MachineID);
|
||||
if (oildai == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
mi.Alerts.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AlertCount = oildai.AlertCount;
|
||||
int index = mi.Alerts.IndexOf(oildai);
|
||||
if (ai.AlertTime_UTC > oildai.AlertTime_UTC)
|
||||
{
|
||||
ai.AlertCount++;
|
||||
mi.Alerts[index] = ai;
|
||||
}
|
||||
else
|
||||
mi.Alerts[index].AlertCount++;
|
||||
}
|
||||
mi.OpenWorkOrders = FIDbAccess.GetFieldInt(dr["OpenWorkOrderCount"], 0);
|
||||
//mi.OpenWorkOrders = mi.Alerts.Where(m => m.WorkOrderID != 0 && m.WorkOrderStatus != "Completed").Select(m => m.WorkOrderID).Distinct().Count();
|
||||
var timealerts = mi.Alerts.OrderByDescending(m => m.AlertTime_UTC).ToArray();
|
||||
mi.LatestAlertDateTime = timealerts == null ? DateTime.MinValue : timealerts[0].AlertTime_UTC;
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] SearchAcknowledgedAlerts(string sessionid, string filtertext, string[] alertstatus, string[] alerttypes, string[] assetgroups, DateTime beginDate, DateTime endDate, string useriid)
|
||||
{
|
||||
string SQL = @"select a.ALERTID,w.WORKORDERID,wo.STATUS,ALERTTYPE,a.ALERTTIME_UTC,COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME, ENGINGHOURS,ALERTDESC,m.MACHINENAME2
|
||||
,a.MAKEID,a.MODELID,pit.SERVICEDESCRIPTION,a.PMTYPE
|
||||
,(select count(1) from WORKORDER wo1 where wo1.MACHINEID=a.MACHINEID and wo1.STATUS<>'Completed') as OpenWorkOrderCount
|
||||
,a.ACKNOWLEDGEDBY,a.ACKNOWLEDGEDDATE_UTC,a.ACKNOWLEDGMENTCOMMENT
|
||||
from ALERTS a with (nolock)
|
||||
left join WORKORDER_ALERTS w with (nolock) on a.ALERTID=w.ALERTID
|
||||
left join WORKORDER wo with (nolock) on w.WORKORDERID=wo.WORKORDERID
|
||||
left join MACHINES m with (nolock) on a.MACHINEID=m.MACHINEID
|
||||
left join PM_ALERTS pa with (nolock) on a.ALERTID=pa.ALERTID
|
||||
left join PM_INTERAVLS pit with (nolock) on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
where m.MACHINEID is not null and (m.HIDE=0 or m.HIDE is null) and ISNULL(ACKNOWLEDGED,0)=1 and a.ALERTTIME_UTC>={0} and a.ALERTTIME_UTC<={1} ";
|
||||
|
||||
if (assetgroups.Length > 0)//asset group
|
||||
{
|
||||
SQL = SQL + string.Format(" and exists(select 1 from MACHINEGROUPMAP mg where mg.MACHINEID=m.MACHINEID and GROUPID in ('{0}'))", string.Join("','", assetgroups));
|
||||
}
|
||||
|
||||
const string ORDER_BY = " order by ALERTID";
|
||||
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
if (beginDate != Helper.DBMinDateTime)
|
||||
beginDate = beginDate.AddHours(-timeadjust);
|
||||
if (endDate != DateTime.MaxValue)
|
||||
endDate = endDate.AddHours(-timeadjust);
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL + ORDER_BY, beginDate, endDate);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineServiceClient2 mc = SystemParams.GetMachineServiceClient();
|
||||
MachineMake[] _makes = mc.GetMachineMakes();
|
||||
MachineModel[] _models = mc.GetMachineModels();
|
||||
UserInfo[] _users = UserManagement.GetAllAvailableUsers();
|
||||
|
||||
List<AlertInfo> result = new List<AlertInfo>(dt.Rows.Count);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
string alerttype = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty).Trim();
|
||||
if (alerttypes.Length > 0 && !alerttypes.Contains(alerttype))//alerttype
|
||||
continue;
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ai.WorkOrderID = FIDbAccess.GetFieldInt(dr["WORKORDERID"], 0);
|
||||
ai.WorkOrderStatus = FIDbAccess.GetFieldString(dr["STATUS"], string.Empty);
|
||||
ai.MakeID = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
ai.ModelID = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
string name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
string showname = name2;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineName;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.VIN;
|
||||
if (string.IsNullOrWhiteSpace(showname))
|
||||
showname = ai.MachineID.ToString();
|
||||
ai.MachineName = showname;
|
||||
|
||||
MachineMake mk = _makes.FirstOrDefault(m => m.ID == ai.MakeID);
|
||||
if (mk != null)
|
||||
ai.Make = mk.Name;
|
||||
MachineModel md = _models.FirstOrDefault(m => m.ID == ai.ModelID);
|
||||
if (md != null)
|
||||
ai.Model = md.Name;
|
||||
|
||||
ai.AcknowledgedBy = FIDbAccess.GetFieldString(dr["ACKNOWLEDGEDBY"], string.Empty);
|
||||
ai.AcknowledgedTime_UTC = FIDbAccess.GetFieldDateTime(dr["ACKNOWLEDGEDDATE_UTC"], DateTime.MinValue);
|
||||
if (ai.AcknowledgedTime_UTC != DateTime.MinValue)
|
||||
ai.AcknowledgedTime_UTC = ai.AcknowledgedTime_UTC.AddHours(timeadjust);
|
||||
ai.AcknowledgedComment = FIDbAccess.GetFieldString(dr["ACKNOWLEDGMENTCOMMENT"], string.Empty);
|
||||
if (!string.IsNullOrWhiteSpace(ai.AcknowledgedBy))
|
||||
{
|
||||
UserInfo ui = _users.FirstOrDefault(m => m.IID == ai.AcknowledgedBy);
|
||||
if (ui != null)
|
||||
ai.AcknowledgedByName = ui.DisplayName;
|
||||
}
|
||||
|
||||
ai.OpenWorkOrderCount = FIDbAccess.GetFieldInt(dr["OpenWorkOrderCount"], 0);
|
||||
|
||||
AlertInfo existAlert = result.FirstOrDefault(m => m.Description == ai.Description && m.MachineID == ai.MachineID && m.AcknowledgedComment == ai.AcknowledgedComment);
|
||||
if (existAlert == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
if (!string.IsNullOrWhiteSpace(filtertext))
|
||||
{
|
||||
if (Helper.Contains(ai.AlertType, filtertext)
|
||||
|| Helper.Contains(ai.MachineID.ToString(), filtertext)
|
||||
|| Helper.Contains(ai.VIN, filtertext)
|
||||
|| Helper.Contains(ai.MachineName, filtertext)
|
||||
|| Helper.Contains(ai.Description, filtertext)
|
||||
//|| Helper.Contains(ai.ServiceDescription, filtertext)
|
||||
|| Helper.Contains(ai.Make, filtertext)
|
||||
|| Helper.Contains(ai.Model, filtertext))
|
||||
result.Add(ai);
|
||||
}
|
||||
else
|
||||
result.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
existAlert.AlertCount++;
|
||||
if (ai.AlertTime_UTC > existAlert.AlertTime_UTC)
|
||||
existAlert.AlertTime_UTC = ai.AlertTime_UTC;
|
||||
}
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public StringKeyValue[] GetAlertTypes()
|
||||
{
|
||||
const string SQL = "select distinct ltrim(rtrim(ALERTTYPE)) as ALERTTYPE from ALERTS where ISNULL(ALERTTYPE,'')<>'' order by ALERTTYPE";
|
||||
DataTable tb = GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new StringKeyValue[0];
|
||||
}
|
||||
List<StringKeyValue> list = new List<StringKeyValue>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
string type = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty);
|
||||
StringKeyValue kv = new StringKeyValue();
|
||||
kv.Key = type;
|
||||
kv.Value = type;
|
||||
list.Add(kv);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertByID(long[] alertid)
|
||||
{
|
||||
if (alertid == null || alertid.Length == 0)
|
||||
return new AlertInfo[0];
|
||||
string SQL = SEL_ALERT + string.Format(" where ALERTID in ({0})", string.Join(",", alertid));
|
||||
DataTable tb = GetDataTableBySQL(SQL);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
ls.Add(ConvertToAlertInfo(dr, timeadjust));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByWorkOrder(long workorderid)
|
||||
{
|
||||
const string SQL = @"select a.ALERTID,ALERTTYPE,a.ALERTTIME_UTC,COMPLETED,a.MACHINEID,a.VIN,a.MACHINENAME,a.ENGINGHOURS,a.ALERTDESC,pit.SERVICEDESCRIPTION,a.PMTYPE from ALERTS a
|
||||
left join PM_ALERTS pa on a.ALERTID=pa.ALERTID left join PM_INTERAVLS pit on pa.PMINTERVALID=pit.PMINTERVALID
|
||||
where a.ALERTID in (select ALERTID from WORKORDER_ALERTS where WORKORDERID={0}) order by ALERTID";
|
||||
DataTable tb = GetDataTableBySQL(SQL, workorderid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
ai.ServiceDescription = FIDbAccess.GetFieldString(dr["SERVICEDESCRIPTION"], string.Empty);
|
||||
ls.Add(ai);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByAlerts(long[] alertids)
|
||||
{
|
||||
const string SQL = SEL_ALERT + " where ALERTID in ({ALERTIDS}) order by ALERTID";
|
||||
|
||||
string gids = "'" + string.Join("','", alertids) + "'";
|
||||
DataTable tb = GetDataTableBySQL(SQL.Replace("{ALERTIDS}", gids));
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
ls.Add(ConvertToAlertInfo(dr, timeadjust));
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public AlertInfo[] GetAlertsByMachineID(long machineid)
|
||||
{
|
||||
const string SQL = SEL_ALERT + " where MACHINEID={0} and ISNULL(COMPLETED,0)=0 and ALERTID not in(select ALERTID from WORKORDER_ALERTS)";
|
||||
|
||||
DataTable tb = GetDataTableBySQL(SQL, machineid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new AlertInfo[0];
|
||||
}
|
||||
List<AlertInfo> ls = new List<AlertInfo>(tb.Rows.Count);
|
||||
double timeadjust = SystemParams.GetHoursOffset();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
AlertInfo ai = ConvertToAlertInfo(dr, timeadjust);
|
||||
|
||||
AlertInfo oildai = ls.FirstOrDefault(m => m.Description == ai.Description);
|
||||
if (oildai == null)
|
||||
{
|
||||
ai.AlertCount = 1;
|
||||
ls.Add(ai);
|
||||
}
|
||||
else
|
||||
{
|
||||
ai.AlertCount = oildai.AlertCount;
|
||||
int index = ls.IndexOf(oildai);
|
||||
if (ai.AlertTime_UTC > oildai.AlertTime_UTC)
|
||||
{
|
||||
ai.AlertCount++;
|
||||
ls[index] = ai;
|
||||
}
|
||||
else
|
||||
ls[index].AlertCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public void AcknowledgeAlert(string useriid, long[] alertids, string acknowledgmentcomment)
|
||||
{
|
||||
const string SQL = "update ALERTS set ACKNOWLEDGED=1,ACKNOWLEDGEDBY={1},ACKNOWLEDGMENTCOMMENT={2},ACKNOWLEDGEDDATE_UTC=GETUTCDATE() where ALERTID={0}";
|
||||
const string SQL_S = "select ALERTID from ALERTS where ISNULL(ACKNOWLEDGED,0)<>1 and ISNULL(COMPLETED,0)<>1 and MACHINEID=(select MACHINEID from ALERTS where ALERTID={0}) and ALERTDESC=(select ALERTDESC from ALERTS where ALERTID={0}) ";
|
||||
|
||||
if (alertids != null && alertids.Length > 0)
|
||||
{
|
||||
FISqlConnection db = new FISqlConnection(DbConnectionString);
|
||||
foreach (long aid in alertids)
|
||||
{
|
||||
DataTable dt = db.GetDataTableBySQL(SQL_S, aid);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long alertid = FIDbAccess.GetFieldInt64(dr["ALERTID"], 0);
|
||||
ExecSQL(SQL, alertid, useriid, acknowledgmentcomment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AssignedAlertsToWorkOrder(long workorderid, long[] alertid)
|
||||
{
|
||||
const string SQL_Del = "delete from WORKORDER_ALERTS where WORKORDERID={0}";
|
||||
const string SQL_ALERT = "insert into WORKORDER_ALERTS(WORKORDERID,ALERTID,ADDEDON_UTC) values({0},{1},GETUTCDATE())";
|
||||
ExecSQL(SQL_Del, workorderid);
|
||||
if ((alertid != null) && (alertid.Length > 0))
|
||||
{
|
||||
foreach (long aid in alertid)
|
||||
{
|
||||
ExecSQL(SQL_ALERT, workorderid, aid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddMaintenanceLog(AlertInfo alert, List<Tuple<long, double, double, string>> machines, string useriid, FISqlConnection db)
|
||||
{
|
||||
const string SQL_MR = @" insert into MAINTENANCELOG(MAINTENANCEID,MACHINEID,MAINTENANCEDATE,MAINTENANCEHOURS,NOTES,ADDEDBY,ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,
|
||||
ALERTID,ODOMETER,ODOMETERUOM,LOGTYPE,COMPLETEDBY,COMPLETED,COMPLETEDDATE_UTC) values({0},{1},getdate(),{2},{3},{4},GETUTCDATE(),{4},GETUTCDATE(),{5},{6},{7},{8},{4},1,GETUTCDATE())";
|
||||
|
||||
string logtype = "";
|
||||
double enginehours = 0;
|
||||
double odometer = 0;
|
||||
string odometeruom = "";
|
||||
var machine = machines.FirstOrDefault(m => m.Item1 == alert.MachineID);
|
||||
if (machine != null)
|
||||
{
|
||||
if (string.Compare(alert.PMType, "HM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "PM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "TBM_ALERT", true) == 0)
|
||||
{
|
||||
logtype = "Hours";
|
||||
enginehours = machine.Item2;
|
||||
enginehours = enginehours > 0 ? enginehours : 0;
|
||||
}
|
||||
else if (string.Compare(alert.PMType, "ADM_ALERT", true) == 0
|
||||
|| string.Compare(alert.PMType, "RDM_ALERT", true) == 0)
|
||||
{
|
||||
logtype = "Distance";
|
||||
odometer = machine.Item3;
|
||||
odometer = odometer > 0 ? odometer : 0;
|
||||
odometeruom = machine.Item4;
|
||||
}
|
||||
}
|
||||
db.ExecSQL(SQL_MR, Guid.NewGuid().ToString().ToUpper(), alert.MachineID, enginehours, alert.Description, useriid,
|
||||
alert.AlertID, odometer, odometeruom, logtype);
|
||||
}
|
||||
|
||||
private static List<Tuple<long, double, double, string>> GetMachines(FISqlConnection db)
|
||||
{
|
||||
const string SQL = "select MACHINEID,ENGINEHOURS,ODOMETER,ODOMETERUOM from MACHINES";
|
||||
List<Tuple<long, double, double, string>> list = new List<Tuple<long, double, double, string>>();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long machineid = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
double enginhours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
double odometer = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
string odometeruom = FIDbAccess.GetFieldString(dr["ODOMETERUOM"], string.Empty);
|
||||
Tuple<long, double, double, string> t = new Tuple<long, double, double, string>(machineid, enginhours, odometer, odometeruom);
|
||||
list.Add(t);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
private static StringKeyValue[] GetMachineJobSites(FISqlConnection db)
|
||||
{
|
||||
const string SQL = "select jm.MACHINEID,j.JOBSITENAME from JOBSITEMACHINES jm left join JOBSITES j on jm.JOBSITEID=j.JOBSITEID";
|
||||
List<StringKeyValue> list = new List<StringKeyValue>();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
StringKeyValue kv = new StringKeyValue();
|
||||
kv.Key = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0).ToString();
|
||||
kv.Value = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
list.Add(kv);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static AlertInfo ConvertToAlertInfo(DataRow dr, double timeadjust)
|
||||
{
|
||||
AlertInfo ai = new AlertInfo();
|
||||
ai.AlertID = FIDbAccess.GetFieldInt(dr["ALERTID"], 0);
|
||||
ai.AlertType = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty);
|
||||
ai.AlertTime_UTC = FIDbAccess.GetFieldDateTime(dr["ALERTTIME_UTC"], DateTime.MinValue);
|
||||
if (ai.AlertTime_UTC != DateTime.MinValue)
|
||||
ai.AlertTime_UTC = ai.AlertTime_UTC.AddHours(timeadjust);
|
||||
ai.Completed = FIDbAccess.GetFieldInt(dr["COMPLETED"], 0) == 1;
|
||||
ai.MachineID = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
ai.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
ai.MachineName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
ai.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINGHOURS"], 0);
|
||||
ai.Description = FIDbAccess.GetFieldString(dr["ALERTDESC"], string.Empty);
|
||||
ai.PMType = FIDbAccess.GetFieldString(dr["PMTYPE"], string.Empty);
|
||||
return ai;
|
||||
}
|
||||
|
||||
private static Dictionary<string, AssetEngineHour> GetAssetEngineHour()
|
||||
{
|
||||
const string SQL_EH = @"select * from(select AssetId as MACHINEID,AsofTime as ASOFTIME_UTC,Amount,UOM,ROW_NUMBER() over(partition by AssetId order by AsofTime desc) as RowIndex from AssetEngineHours where Datasource<>'Calamp') t where RowIndex=1";
|
||||
|
||||
DataTable tbeh = null;
|
||||
string dbString2 = SystemParams.GetIronIntelReportDataDbString(SystemParams.CompanyID);
|
||||
if (!string.IsNullOrWhiteSpace(dbString2))
|
||||
{
|
||||
var db2 = new FISqlConnection(dbString2);
|
||||
tbeh = db2.GetDataTableBySQL(SQL_EH);
|
||||
}
|
||||
|
||||
Dictionary<string, AssetEngineHour> machineEngineHours = new Dictionary<string, AssetEngineHour>();
|
||||
if (tbeh != null && tbeh.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in tbeh.Rows)
|
||||
{
|
||||
string mID = FIDbAccess.GetFieldString(dr["MACHINEID"], string.Empty);
|
||||
var meh = new AssetEngineHour();
|
||||
meh.EngineHours = FIDbAccess.GetFieldDouble(dr["Amount"], -1);
|
||||
string uom = FIDbAccess.GetFieldString(dr["UOM"], string.Empty);
|
||||
if (uom.ToLower() == "s")
|
||||
meh.EngineHours = meh.EngineHours / 3600;
|
||||
meh.EngineHoursDate = FIDbAccess.GetFieldDateTime(dr["ASOFTIME_UTC"], DateTime.MinValue);
|
||||
if (meh.EngineHoursDate != DateTime.MinValue)
|
||||
meh.EngineHoursDate = meh.EngineHoursDate.AddHours(SystemParams.GetHoursOffset());
|
||||
|
||||
machineEngineHours[mID] = meh;
|
||||
}
|
||||
}
|
||||
|
||||
return machineEngineHours;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
54
IronIntelContractorBusiness/Maintenance/FuelRecordInfo.cs
Normal file
54
IronIntelContractorBusiness/Maintenance/FuelRecordInfo.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class FuelRecordInfo
|
||||
{
|
||||
public string RetailerName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public decimal TotalCost { get; set; }
|
||||
public decimal UnitCost { get; set; }
|
||||
public decimal Quantity { get; set; }
|
||||
public string Uom { get; set; }
|
||||
public string FuelTypeName { get; set; }
|
||||
public string FuelType { get; set; }
|
||||
public double Odomerter { get; set; }
|
||||
public string RetailerZip { get; set; }
|
||||
public string RetailerState { get; set; }
|
||||
public string RetailerCity { get; set; }
|
||||
public string RetailerAddress { get; set; }
|
||||
public bool IsComesFromAPI { get; set; }
|
||||
public string DriverName { get; set; }
|
||||
public string TicketNumber { get; set; }
|
||||
public DateTime TransactionDate { get; set; }
|
||||
public string TransactionDateStr { get { return TransactionDate == DateTime.MinValue ? "" : TransactionDate.ToString("MM/dd/yyyy HH:mm"); } }
|
||||
public string AssetModel { get; set; }
|
||||
public string AssetMake { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public long FuelID { get; set; }
|
||||
public string DataSource { get; set; }
|
||||
public string BrandName { get; set; }
|
||||
}
|
||||
|
||||
public class FuelRecordAuditItem : FuelRecordInfo
|
||||
{
|
||||
public long LogID { get; set; }
|
||||
public DateTime LogTime { get; set; }
|
||||
public string AddedByName { get; set; }
|
||||
public string AddedBy { get; set; }
|
||||
public string LasetUpdatedBy { get; set; }
|
||||
public string LasetUpdatedByName { get; set; }
|
||||
public DateTime AddedOn { get; set; }
|
||||
public string AddedOnStr { get { return AddedOn == DateTime.MinValue ? "" : AddedOn.ToString("MM/dd/yyyy HH:mm:ss"); } }
|
||||
public DateTime LastUpdatedOn { get; set; }
|
||||
public string LastUpdatedOnStr { get { return LastUpdatedOn == DateTime.MinValue ? "" : LastUpdatedOn.ToString("MM/dd/yyyy HH:mm:ss"); } }
|
||||
|
||||
}
|
||||
}
|
211
IronIntelContractorBusiness/Maintenance/IATCAlertsSyncService.cs
Normal file
211
IronIntelContractorBusiness/Maintenance/IATCAlertsSyncService.cs
Normal file
@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
using IronIntel.Contractor.Machines;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class IATCAlertsSyncService
|
||||
{
|
||||
private static bool isrunning = false;
|
||||
|
||||
private static Dictionary<string, string> _AlertTypeMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
public static void Start()
|
||||
{
|
||||
if (isrunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isrunning = true;
|
||||
InitAlertTypeMapping();
|
||||
Thread thd = new Thread(DoWork);
|
||||
thd.Start();
|
||||
}
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
isrunning = false;
|
||||
}
|
||||
|
||||
private static void InitAlertTypeMapping()
|
||||
{
|
||||
_AlertTypeMapping.Clear();
|
||||
_AlertTypeMapping["FI-DTCJ1939"] = "FI - DTC";
|
||||
_AlertTypeMapping["FI-Jpod2"] = "FI - DTC";
|
||||
_AlertTypeMapping["Green-Inspect"] = "Green-Inspect";
|
||||
_AlertTypeMapping["INFO"] = "Info";
|
||||
_AlertTypeMapping["Info-Inspect"] = "Info-Inspect";
|
||||
_AlertTypeMapping["OTHER-Abnormality"] = "Red";
|
||||
_AlertTypeMapping["OTHER-Caution"] = "Yellow";
|
||||
_AlertTypeMapping["OTHER-OilSampleResult"] = "Oil Sample";
|
||||
_AlertTypeMapping["OTHER-PreventativeMaintenance"] = null;
|
||||
_AlertTypeMapping["RED"] = "Red";
|
||||
_AlertTypeMapping["Red-Inspect"] = "Red-Inspect";
|
||||
_AlertTypeMapping["YELLOW"] = "Yellow";
|
||||
_AlertTypeMapping["Yellow-Inspect"] = "Yellow-Inspect";
|
||||
}
|
||||
|
||||
|
||||
private static void DoWork()
|
||||
{
|
||||
const int SLEEPTIME = 60;
|
||||
while (isrunning)
|
||||
{
|
||||
DateTime dt1 = DateTime.Now;
|
||||
try
|
||||
{
|
||||
IATCAlertsSyncService svc = new IATCAlertsSyncService();
|
||||
svc.SyncAlerts();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
TimeSpan sp = DateTime.Now - dt1;
|
||||
int delta = SLEEPTIME - Convert.ToInt32(sp.TotalSeconds);
|
||||
if (delta < 0)
|
||||
{
|
||||
delta = 1;
|
||||
}
|
||||
Thread.Sleep(delta * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private IATCAlertsSyncService()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private Dictionary<long, machinedata> _Machines = new Dictionary<long, machinedata>();
|
||||
|
||||
private machinedata GetMachinedata(long id)
|
||||
{
|
||||
const string SQL = "select MACHINEID,VIN,MACHINENAME,MACHINENAME2,MAKEID,MODELID,TYPEID from MACHINES where MACHINEID={0}";
|
||||
|
||||
machinedata m = null;
|
||||
if (_Machines.TryGetValue(id, out m))
|
||||
{
|
||||
return m;
|
||||
}
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, id);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
_Machines.Add(id, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
m = new machinedata();
|
||||
m.ID = Convert.ToInt64(tb.Rows[0]["MACHINEID"]);
|
||||
m.Name = FIDbAccess.GetFieldString(tb.Rows[0]["MACHINENAME"], string.Empty);
|
||||
m.Name2 = FIDbAccess.GetFieldString(tb.Rows[0]["MACHINENAME2"], string.Empty);
|
||||
m.VIN = FIDbAccess.GetFieldString(tb.Rows[0]["VIN"], string.Empty);
|
||||
m.MakeID = FIDbAccess.GetFieldInt(tb.Rows[0]["MAKEID"], -1);
|
||||
m.ModelID = FIDbAccess.GetFieldInt(tb.Rows[0]["MODELID"], -1);
|
||||
m.TypeID = FIDbAccess.GetFieldInt(tb.Rows[0]["TYPEID"], -1);
|
||||
m.ModelName = MachineManagement.GetMachineModelName(m.ModelID);
|
||||
m.MakeName = MachineManagement.GetMachineMakeName(m.MakeID);
|
||||
m.TypeName = MachineManagement.GetMachineTypeName(m.TypeID);
|
||||
|
||||
_Machines[id] = m;
|
||||
return m;
|
||||
}
|
||||
|
||||
public void SyncAlerts()
|
||||
{
|
||||
const string SQL = "select top 100 * from IATCALERTS where ALERTID>(select isnull(max(IATCALERTID),-1) from ALERTS where SRC='LOCALTABLE_IATCALERTS') order by ALERTID";//process most 100 alerts each time
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long alertid = Convert.ToInt64(dr["ALERTID"]);
|
||||
try
|
||||
{
|
||||
InsertData(db, dr);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SystemParams.WriteLog("Error", GetType().FullName + ". DoWork()", "Sync IATCALERTS failed: " + alertid, ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InsertData(FISqlConnection db, DataRow dr)
|
||||
{
|
||||
const string SQL = "if not exists(select 1 from ALERTS where SRC='LOCALTABLE_IATCALERTS' and IATCALERTID={0}) "
|
||||
+ "insert into ALERTS(ALERTTIME_UTC,ALERTTYPE,ALERTTITLE,ALERTDESC,MACHINEID,VIN,MACHINENAME,MODELID,MODELNAME,"
|
||||
+ "MAKEID,MAKENAME,TYPEID,TYPENAME,ENGINGHOURS,LATITUDE,LONGITUDE,LOCDATE_UTC,SRC,INSERTTIME,REFID,IATCALERTID) "
|
||||
+ " values({1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},'LOCALTABLE_IATCALERTS',getdate(),{0},{0})";
|
||||
|
||||
long machineid = Convert.IsDBNull(dr["MACHINEID"]) ? -1 : Convert.ToInt64(dr["MACHINEID"]);
|
||||
machinedata m = GetMachinedata(machineid);
|
||||
if (m == null)
|
||||
{
|
||||
m = new machinedata();
|
||||
m.ID = machineid;
|
||||
m.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
m.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
m.MakeName = FIDbAccess.GetFieldString(dr["MAKE"], string.Empty);
|
||||
m.ModelName = FIDbAccess.GetFieldString(dr["MODEL"], string.Empty);
|
||||
m.TypeName = FIDbAccess.GetFieldString(dr["MACHINETYPE"], string.Empty);
|
||||
}
|
||||
long alertid = Convert.ToInt64(dr["ALERTID"]);
|
||||
double hours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
double lat = FIDbAccess.GetFieldDouble(dr["CUR_LATITUDE"], 0);
|
||||
double lon = FIDbAccess.GetFieldDouble(dr["CUR_LONGITUDE"], 0);
|
||||
DateTime? locdate = FIDbAccess.GetNullableDateTime(dr["LOCATIONTIME_UTC"]);
|
||||
DateTime? alerttime = FIDbAccess.GetNullableDateTime(dr["RECEIVEDDATE"]);
|
||||
string title = FIDbAccess.GetFieldString(dr["ALERTTITLE"], string.Empty);
|
||||
string desc = FIDbAccess.GetFieldString(dr["ALERTDESC"], string.Empty);
|
||||
string alerttype = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty);
|
||||
alerttype = DetermineAlertType(alerttype.Trim());
|
||||
if (alerttype == null)
|
||||
return;
|
||||
db.ExecSQL(SQL, alertid, alerttime, alerttype, title, desc, m.ID, m.VIN, m.CustName, m.ModelID, m.ModelName, m.MakeID, m.MakeName, m.TypeID, m.TypeName, hours, lat, lon, locdate);
|
||||
}
|
||||
|
||||
private string DetermineAlertType(string alerttype)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(alerttype))
|
||||
{
|
||||
string temp = alerttype.Trim().Replace(" ", "");
|
||||
if (_AlertTypeMapping.ContainsKey(temp))
|
||||
alerttype = _AlertTypeMapping[temp];
|
||||
}
|
||||
else
|
||||
alerttype = "";
|
||||
return alerttype;
|
||||
}
|
||||
|
||||
class machinedata
|
||||
{
|
||||
public long ID = 0;
|
||||
public string VIN = string.Empty;
|
||||
public string Name = string.Empty;
|
||||
public string Name2 = string.Empty;
|
||||
public int MakeID = -1;
|
||||
public int ModelID = -1;
|
||||
public int TypeID = -1;
|
||||
public string MakeName = string.Empty;
|
||||
public string ModelName = string.Empty;
|
||||
public string TypeName = string.Empty;
|
||||
|
||||
public string CustName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(Name2))
|
||||
{
|
||||
return Name2;
|
||||
}
|
||||
return string.IsNullOrWhiteSpace(Name) ? VIN : Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
247
IronIntelContractorBusiness/Maintenance/MaintenanceInfo.cs
Normal file
247
IronIntelContractorBusiness/Maintenance/MaintenanceInfo.cs
Normal file
@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
|
||||
public class PmScheduleInfo
|
||||
{
|
||||
public string PmScheduleID { get; set; }
|
||||
public string PmScheduleName { get; set; }
|
||||
public string PmScheduleUom { get; set; }
|
||||
|
||||
public string PmScheduleType { get; set; } //PM,TBM,HM
|
||||
public string Notes { get; set; }
|
||||
|
||||
public PmIntervalItem[] Intervals { get; set; }
|
||||
public int[] AllIntervals { get; set; }
|
||||
}
|
||||
|
||||
public class PmIntervalItem
|
||||
{
|
||||
public string PmIntervalID { get; set; }
|
||||
public string ScheduleId { get; set; }
|
||||
public int Interval { get; set; }
|
||||
public int NotificationPeriod { get; set; }
|
||||
|
||||
public string ServiceName { get; set; }
|
||||
public bool Recurring { get; set; }
|
||||
public int Priority { get; set; }
|
||||
|
||||
public string ServiceDescription { get; set; }
|
||||
}
|
||||
|
||||
public class MaintenanceLogInfo
|
||||
{
|
||||
public string MaintenanceID { get; set; }
|
||||
public long MachineID { get; set; }
|
||||
public string MachinePin { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
public string MachineName2 { get; set; }
|
||||
public DateTime MaintenanceDate { get; set; }
|
||||
public double MaintenanceHours { get; set; }
|
||||
public string MachineMake { get; set; }
|
||||
public string MachineModel { get; set; }
|
||||
public string MachineType { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string Notes { get; set; }
|
||||
public long AlertID { get; set; }
|
||||
|
||||
private double _ODOMeter;
|
||||
public double ODOMeter
|
||||
{
|
||||
get
|
||||
{
|
||||
return _ODOMeter;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_ODOMeter = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string ODOMemterUOM { get; set; }
|
||||
public string LogType { get; set; }
|
||||
|
||||
public string AlertTitle { get; set; }
|
||||
public string AlertType { get; set; }
|
||||
public DateTime AlertTime { get; set; }
|
||||
|
||||
public string StrForMaintenanceDate { get { return MaintenanceDate.ToShortDateString(); } }
|
||||
|
||||
public string StrForAlertTime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (AlertTime != DateTime.MinValue)
|
||||
{
|
||||
return AlertTime.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public double Cost { get; set; }
|
||||
public string InvoiceNumber { get; set; }
|
||||
public bool Completed { get; set; }
|
||||
public string CompletedByName { get; set; }
|
||||
public bool HasAttachment { get; set; }
|
||||
|
||||
public string[] AttachmentIDs { get; set; }//用于保存
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = MachineName2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineName;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachinePin;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineID.ToString();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class MaintenanceMachineInfo
|
||||
{
|
||||
public long MachineID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string MachineName { get; set; }
|
||||
public string MachineName2 { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string MachineType { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime StartDate { get; set; }
|
||||
public double StartHours { get; set; }
|
||||
public string StartDateString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (StartDate == DateTime.MinValue)
|
||||
return "";
|
||||
else
|
||||
return StartDate.ToShortDateString();
|
||||
}
|
||||
}
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = MachineName2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineName;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = MachineID.ToString();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
|
||||
public double StartOdometer { get; set; }
|
||||
public bool Hide { get; set; }
|
||||
}
|
||||
|
||||
public class PMAlert
|
||||
{
|
||||
public string LogID { get; set; }
|
||||
public string AlertID { get; set; }
|
||||
public string AlertTitle { get; set; }
|
||||
public string AlertTime { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class PMAssetAlertInfo
|
||||
{
|
||||
public string PmScheduleID { get; set; }
|
||||
public string PmIntervalId { get; set; }
|
||||
public string ServiceName { get; set; }
|
||||
public DateTime? LastAlertTime { get; set; }
|
||||
public long AssetId { get; set; }
|
||||
public DateTime? StartDate { get; set; }
|
||||
public double? StartHours { get; set; }
|
||||
public double? StartOdometer { get; set; }
|
||||
public int? StartIntervalValue { get; set; }
|
||||
public bool Selected { get; set; }
|
||||
public int UnMaintainedAlert { get; set; }
|
||||
|
||||
|
||||
public string PmScheduleName { get; set; }
|
||||
public string PmScheduleUom { get; set; }
|
||||
public string PmScheduleType { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public PmIntervalItem[] Intervals { get; set; }
|
||||
public int[] AllIntervals { get; set; }
|
||||
|
||||
public string StartDateString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (StartDate == null)
|
||||
return "";
|
||||
else
|
||||
return StartDate.Value.ToString("MM/dd/yyyy");
|
||||
}
|
||||
}
|
||||
public string LastAlertTimeString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LastAlertTime == null)
|
||||
return "";
|
||||
else
|
||||
return LastAlertTime.Value.ToString("MM/dd/yyyy");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
939
IronIntelContractorBusiness/Maintenance/MaintenanceManagement.cs
Normal file
939
IronIntelContractorBusiness/Maintenance/MaintenanceManagement.cs
Normal file
@ -0,0 +1,939 @@
|
||||
using Foresight.Data;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class MaintenanceManagement
|
||||
{
|
||||
|
||||
#region PM SCHEDULES
|
||||
|
||||
public static PmScheduleInfo[] GetPmSchedule(string sessionid, string pmtype)
|
||||
{
|
||||
var items = FleetServiceClientHelper.CreateClient<PMClient>(sessionid).GetPMScheduleItems(SystemParams.CompanyID, pmtype, string.Empty, true);
|
||||
if (items == null || items.Length == 0)
|
||||
return new PmScheduleInfo[0];
|
||||
List<PmScheduleInfo> list = new List<PmScheduleInfo>();
|
||||
foreach (var item in items)
|
||||
{
|
||||
PmScheduleInfo pm = new PmScheduleInfo();
|
||||
pm.PmScheduleID = item.Id;
|
||||
pm.PmScheduleName = item.Name;
|
||||
pm.PmScheduleUom = item.UOM;
|
||||
pm.PmScheduleType = item.ScheduleType;
|
||||
pm.Notes = item.Notes;
|
||||
if (item.Intervals != null || item.Intervals.Count > 0)
|
||||
{
|
||||
List<PmIntervalItem> lsinterval = new List<PmIntervalItem>();
|
||||
foreach (var pi in item.Intervals)
|
||||
{
|
||||
PmIntervalItem piclient = new PmIntervalItem();
|
||||
Helper.CloneProperty(piclient, pi);
|
||||
piclient.PmIntervalID = pi.Id;
|
||||
lsinterval.Add(piclient);
|
||||
}
|
||||
pm.Intervals = lsinterval.ToArray();
|
||||
|
||||
if (pm.PmScheduleType == "HM" || pm.PmScheduleType == "RDM" || pm.PmScheduleType == "TBM")
|
||||
pm.AllIntervals = GetAllIntervals(item);
|
||||
}
|
||||
else
|
||||
pm.Intervals = new PmIntervalItem[0];
|
||||
list.Add(pm);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static PmScheduleInfo GetPMScheduleByID(string sessionid, string scheduleid)
|
||||
{
|
||||
var item = FleetServiceClientHelper.CreateClient<PMClient>(sessionid).GetPMScheduleItem(SystemParams.CompanyID, scheduleid, true);
|
||||
PmScheduleInfo pm = new PmScheduleInfo();
|
||||
pm.PmScheduleID = item.Id;
|
||||
pm.PmScheduleName = item.Name;
|
||||
pm.PmScheduleUom = item.UOM;
|
||||
pm.PmScheduleType = item.ScheduleType;
|
||||
pm.Notes = item.Notes;
|
||||
if (item.Intervals != null || item.Intervals.Count > 0)
|
||||
{
|
||||
List<PmIntervalItem> lsinterval = new List<PmIntervalItem>();
|
||||
foreach (var pi in item.Intervals)
|
||||
{
|
||||
PmIntervalItem piclient = new PmIntervalItem();
|
||||
Helper.CloneProperty(piclient, pi);
|
||||
piclient.PmIntervalID = pi.Id;
|
||||
lsinterval.Add(piclient);
|
||||
}
|
||||
pm.Intervals = lsinterval.ToArray();
|
||||
|
||||
if (pm.PmScheduleType == "HM" || pm.PmScheduleType == "RDM" || pm.PmScheduleType == "TBM")
|
||||
pm.AllIntervals = GetAllIntervals(item);
|
||||
}
|
||||
else
|
||||
pm.Intervals = new PmIntervalItem[0];
|
||||
|
||||
|
||||
return pm;
|
||||
}
|
||||
//private static int[] GetAllIntervals(PMScheduleItem sc)
|
||||
//{
|
||||
// Dictionary<int, List<PMIntervalItem>> result = new Dictionary<int, List<PMIntervalItem>>();
|
||||
|
||||
// var intervals = sc.Intervals.Where(i => i.Recurring).OrderBy(i => i.Interval).ThenByDescending(i => i.Priority).ToList();
|
||||
// if (intervals.Count == 0)
|
||||
// return new int[0];
|
||||
|
||||
// int maxInterval = intervals[intervals.Count() - 1].Interval;
|
||||
// for (int i = intervals.Count - 1; i >= 0; i--)
|
||||
// {//从最大的Interval开始
|
||||
// PMIntervalItem ia = intervals[i];
|
||||
|
||||
// int tempInterval = ia.Interval;
|
||||
// var existIntervals = result.OrderBy(kv => kv.Key).Select(kv => kv.Key).ToList();
|
||||
|
||||
// if (!result.ContainsKey(tempInterval))//加入自己
|
||||
// {
|
||||
// result[tempInterval] = new List<PMIntervalItem>();
|
||||
// }
|
||||
// result[tempInterval].Add(ia);
|
||||
|
||||
// tempInterval += ia.Interval;
|
||||
// foreach (var ti in existIntervals)
|
||||
// {//result排序后找第一个比tempInterval大的值
|
||||
// while (tempInterval < ti)
|
||||
// {
|
||||
// if (!result.ContainsKey(tempInterval))
|
||||
// {
|
||||
// result[tempInterval] = new List<PMIntervalItem>();
|
||||
// }
|
||||
// result[tempInterval].Add(ia);
|
||||
// tempInterval += ia.Interval;
|
||||
// }
|
||||
|
||||
// tempInterval = ti;
|
||||
// tempInterval += ia.Interval;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return result.Select(r => r.Key).OrderBy(r => r).ToArray();
|
||||
//}
|
||||
|
||||
private static int[] GetAllIntervals(PMScheduleItem sc)
|
||||
{
|
||||
Dictionary<int, PMIntervalItem> result = new Dictionary<int, PMIntervalItem>();
|
||||
|
||||
var intervals = sc.Intervals.Where(i => i.Recurring).OrderBy(i => i.Interval).ThenByDescending(i => i.Priority).ToList();
|
||||
if (intervals.Count == 0)
|
||||
return null;
|
||||
|
||||
int maxInterval = 0;
|
||||
for (int i = 0; i < intervals.Count; i++)
|
||||
{
|
||||
PMIntervalItem ia = intervals[i];
|
||||
if (maxInterval == 0)
|
||||
maxInterval = ia.Interval;
|
||||
else
|
||||
maxInterval = GetMinCommonMultiple(maxInterval, ia.Interval);
|
||||
}
|
||||
for (int i = 0; i < intervals.Count; i++)
|
||||
{
|
||||
PMIntervalItem ia = intervals[i];
|
||||
int tempInterval = ia.Interval;
|
||||
while (tempInterval <= maxInterval)
|
||||
{
|
||||
if (result.ContainsKey(tempInterval))
|
||||
{
|
||||
if (ia.Priority < result[tempInterval].Priority
|
||||
|| (ia.Priority == result[tempInterval].Priority
|
||||
&& ia.Interval == result[tempInterval].Interval))
|
||||
result[tempInterval] = ia;
|
||||
}
|
||||
else
|
||||
result[tempInterval] = ia;
|
||||
|
||||
tempInterval += ia.Interval;
|
||||
}
|
||||
}
|
||||
|
||||
return result.Select(r => r.Key).OrderBy(r => r).Take(1000).ToArray();
|
||||
//最大只取1000个,正常设置不会超过1000,异常设置数量太多会使前端页面卡死
|
||||
}
|
||||
|
||||
private static int GetMaxCommonDivisor(int a, int b)
|
||||
{
|
||||
if (a < b) { a = a + b; b = a - b; a = a - b; }
|
||||
return (a % b == 0) ? b : GetMaxCommonDivisor(a % b, b);
|
||||
}
|
||||
|
||||
private static int GetMinCommonMultiple(int a, int b)
|
||||
{
|
||||
return a * b / GetMaxCommonDivisor(a, b);
|
||||
}
|
||||
|
||||
public static PmIntervalItem[] GetPmInterval(string sessionid, string scheduleid)
|
||||
{
|
||||
var items = FleetServiceClientHelper.CreateClient<PMClient>(sessionid).GetPMIntervals(SystemParams.CompanyID, scheduleid);
|
||||
if (items == null || items.Length == 0)
|
||||
return new PmIntervalItem[0];
|
||||
|
||||
List<PmIntervalItem> list = new List<PmIntervalItem>();
|
||||
foreach (var pi in items)
|
||||
{
|
||||
PmIntervalItem piclient = new PmIntervalItem();
|
||||
Helper.CloneProperty(piclient, pi);
|
||||
piclient.PmIntervalID = pi.Id;
|
||||
list.Add(piclient);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static PMAssetAlertInfo[] GetPmScheduleByAsset(string sessionid, long assetid)
|
||||
{
|
||||
List<PMAssetAlertInfo> result = new List<PMAssetAlertInfo>();
|
||||
var client = FleetServiceClientHelper.CreateClient<PMClient>(sessionid);
|
||||
var sches = client.GetPMScheduleItems(SystemParams.CompanyID, "", string.Empty, true);
|
||||
var aas = client.GetPMAssetAlertItems(SystemParams.CompanyID, assetid);
|
||||
foreach (var item in sches)
|
||||
{
|
||||
PMAssetAlertInfo pm = new PMAssetAlertInfo();
|
||||
pm.PmScheduleID = item.Id;
|
||||
pm.PmScheduleName = item.Name;
|
||||
pm.PmScheduleUom = item.UOM;
|
||||
pm.PmScheduleType = item.ScheduleType;
|
||||
pm.Notes = item.Notes;
|
||||
if (item.Intervals != null || item.Intervals.Count > 0)
|
||||
{
|
||||
List<PmIntervalItem> lsinterval = new List<PmIntervalItem>();
|
||||
foreach (var pi in item.Intervals)
|
||||
{
|
||||
PmIntervalItem piclient = new PmIntervalItem();
|
||||
Helper.CloneProperty(piclient, pi);
|
||||
piclient.PmIntervalID = pi.Id;
|
||||
lsinterval.Add(piclient);
|
||||
}
|
||||
pm.Intervals = lsinterval.ToArray();
|
||||
|
||||
if (pm.PmScheduleType == "HM" || pm.PmScheduleType == "RDM" || pm.PmScheduleType == "TBM")
|
||||
pm.AllIntervals = GetAllIntervals(item);
|
||||
}
|
||||
else
|
||||
pm.Intervals = new PmIntervalItem[0];
|
||||
|
||||
if (aas != null)
|
||||
{
|
||||
var aa = aas.FirstOrDefault(a => a.PMScheduleId.Equals(pm.PmScheduleID, StringComparison.OrdinalIgnoreCase));
|
||||
if (aa != null)
|
||||
{
|
||||
pm.Selected = true;
|
||||
pm.AssetId = aa.AssetId;
|
||||
pm.PmScheduleID = aa.PMScheduleId;
|
||||
pm.PmIntervalId = aa.PMIntervalId;
|
||||
pm.ServiceName = aa.ServiceName;
|
||||
pm.LastAlertTime = aa.LastAlertTime;
|
||||
pm.StartDate = aa.StartDate;
|
||||
pm.StartHours = aa.StartHours;
|
||||
pm.StartOdometer = aa.StartOdometer;
|
||||
pm.StartIntervalValue = aa.StartIntervalValue;
|
||||
pm.UnMaintainedAlert = aa.UnMaintainedAlert;
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(pm);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static PmScheduleInfo GetPmScheduleByID(string sessionid, string scheduleid)
|
||||
{
|
||||
const string SQL = @"select PMSCHEDULEID,SCHEDULENAME,SCHEDULETYPE,NOTES,SCHEDULEUOM from PM_SCHEDULES where PMSCHEDULEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, scheduleid);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new PmScheduleInfo();
|
||||
}
|
||||
PmScheduleInfo si = ConvertPmScheduleInfo(dt.Rows[0]);
|
||||
si.Intervals = GetPmInterval(sessionid, si.PmScheduleID);
|
||||
return si;
|
||||
}
|
||||
|
||||
public static void UpdatePmSchedule(string sessionid, PmScheduleInfo si, string useriid)
|
||||
{
|
||||
PMScheduleItem pm = new PMScheduleItem();
|
||||
pm.Id = si.PmScheduleID;
|
||||
pm.Name = si.PmScheduleName;
|
||||
pm.UOM = si.PmScheduleUom;
|
||||
pm.ScheduleType = si.PmScheduleType;
|
||||
pm.Notes = si.Notes;
|
||||
if (si.Intervals != null && si.Intervals.Length > 0)
|
||||
{
|
||||
List<PMIntervalItem> list = new List<PMIntervalItem>();
|
||||
foreach (PmIntervalItem piclient in si.Intervals)
|
||||
{
|
||||
PMIntervalItem pi = new PMIntervalItem();
|
||||
Helper.CloneProperty(pi, piclient);
|
||||
pi.Id = piclient.PmIntervalID;
|
||||
pi.ScheduleId = pm.Id;
|
||||
list.Add(pi);
|
||||
}
|
||||
pm.Intervals.AddRange(list);
|
||||
}
|
||||
FleetServiceClientHelper.CreateClient<PMClient>(sessionid).UpdatePMSchedule(SystemParams.CompanyID, pm, useriid);
|
||||
}
|
||||
|
||||
public static void UpdatePmInterval(string sessionid, PmIntervalItem piclient, string useriid)
|
||||
{
|
||||
PMIntervalItem interval = new PMIntervalItem();
|
||||
Helper.CloneProperty(interval, piclient);
|
||||
interval.Id = piclient.PmIntervalID;
|
||||
FleetServiceClientHelper.CreateClient<PMClient>(sessionid).UpdatePMInterval(SystemParams.CompanyID, interval, useriid);
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetPmMachinesByScheduleId(string scheduleid)
|
||||
{
|
||||
const string SQL = @"select a.MACHINEID,a.STARTDATE,a.STARTHOURS,a.STARTOTOMETER,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,b.HIDE,
|
||||
ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,ISNULL(b.ODOMETER,0) as ODOMETER,ISNULL(b.ODOMETERUOM,'Mile') AS ODOMETERUOM
|
||||
from PM_MACHINES a,MACHINES b where a.MACHINEID=b.MACHINEID and a.PMSCHEDULEID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, scheduleid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MaintenanceMachineInfo mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
|
||||
private static object GetValueOrNull(DateTime v)
|
||||
{
|
||||
if (v == DateTime.MinValue || v == new DateTime(1900, 1, 1))
|
||||
return null;
|
||||
else
|
||||
return v;
|
||||
}
|
||||
|
||||
public static void DeletePmMachine(string scheduleid, string machineid)
|
||||
{
|
||||
const string SQL = "delete from PM_MACHINES where PMSCHEDULEID={0} and MACHINEID={1}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, scheduleid, machineid);
|
||||
}
|
||||
|
||||
private static bool CheckPmScheduleNameRepeat(string scheduleid, string schedulename)
|
||||
{
|
||||
const string SQL = "select COUNT(1) from PM_SCHEDULES where PMSCHEDULEID!={0} and SCHEDULENAME={1}";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL, scheduleid, schedulename);
|
||||
if (Convert.ToInt32(obj) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static bool CheckPmScheduleHasMachine(string scheduleid)
|
||||
{
|
||||
const string SQL_M = "select COUNT(1) from PM_MACHINES where PMSCHEDULEID={0}";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object objm = db.GetRC1BySQL(SQL_M, scheduleid);
|
||||
if (Convert.ToInt32(objm) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static PmScheduleInfo ConvertPmScheduleInfo(DataRow dr)
|
||||
{
|
||||
PmScheduleInfo si = new PmScheduleInfo();
|
||||
si.PmScheduleID = FIDbAccess.GetFieldString(dr["PMSCHEDULEID"], string.Empty);
|
||||
si.PmScheduleName = FIDbAccess.GetFieldString(dr["SCHEDULENAME"], string.Empty);
|
||||
si.PmScheduleType = FIDbAccess.GetFieldString(dr["SCHEDULETYPE"], string.Empty);
|
||||
si.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
si.PmScheduleUom = FIDbAccess.GetFieldString(dr["SCHEDULEUOM"], string.Empty);
|
||||
return si;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Maintenance Log
|
||||
|
||||
public static MaintenanceLogInfo[] GetMaintenanceLog(string sessionid, long assetid, string maintenancetype, int machinetype, string searchtxt, string useriid)
|
||||
{
|
||||
const string SQL = @"select a.MAINTENANCEID,a.MACHINEID,a.MAINTENANCEDATE,a.MAINTENANCEHOURS,a.NOTES,a.ALERTID,b.MACHINENAME,b.MACHINENAME2, b.VIN,b.MAKEID, b.MODELID,b.TYPEID,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
t.ALERTTYPE,t.ALERTTITLE,t.ALERTTIME_UTC,ISNULL(a.ODOMETER,0) AS ODOMETER,ISNULL(a.ODOMETERUOM,'Hour') AS ODOMETERUOM, isnull(LOGTYPE,'Hours') AS LOGTYPE ,a.COST,a.INVOICENUMBER,a.COMPLETEDBY,a.COMPLETEDBYUSERNAME,
|
||||
(select top 1 ATTACHID from ATTACHES where SOURCE='MaintenanceLog' and REFID=a.MAINTENANCEID and isnull(DELETED,0)=0) ATTACHID
|
||||
from MAINTENANCELOG a left join ALERTS t on a.ALERTID=t.ALERTID,MACHINES b
|
||||
where a.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1";
|
||||
const string ORDER_BY = " ORDER BY a.ADDEDON DESC";
|
||||
|
||||
string sql = SQL;
|
||||
//if (string.Compare("Distance", maintenancetype, true) == 0)
|
||||
//{
|
||||
// sql = SQL + " and a.LOGTYPE='" + maintenancetype + "'";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// sql = SQL + " and a.LOGTYPE='" + maintenancetype + "'";
|
||||
// sql = SQL + " and (a.LOGTYPE='" + maintenancetype + "' or a.LOGTYPE is null)";
|
||||
//}
|
||||
if (assetid > 0)
|
||||
{
|
||||
sql = sql + " and a.MACHINEID=" + assetid;
|
||||
}
|
||||
if (machinetype >= 0)
|
||||
{
|
||||
sql = sql + " and b.TYPEID=" + machinetype.ToString() + ORDER_BY;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = sql + ORDER_BY;
|
||||
}
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(sql, useriid);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceLogInfo[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MaintenanceLogInfo> list = new List<MaintenanceLogInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
long mid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dr, makes, models, types);
|
||||
ml.AlertTitle = FIDbAccess.GetFieldString(dr["ALERTTITLE"], string.Empty);
|
||||
ml.AlertType = FIDbAccess.GetFieldString(dr["ALERTTYPE"], string.Empty);
|
||||
ml.AlertTime = FIDbAccess.GetFieldDateTime(dr["ALERTTIME_UTC"], DateTime.MinValue);
|
||||
ml.HasAttachment = !string.IsNullOrWhiteSpace(FIDbAccess.GetFieldString(dr["ATTACHID"], string.Empty));
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(ml.MachineID.ToString(), searchtxt)
|
||||
|| Helper.Contains(ml.MachinePin, searchtxt)
|
||||
|| Helper.Contains(ml.MachineName, searchtxt)
|
||||
|| Helper.Contains(ml.MachineName2, searchtxt)
|
||||
|| Helper.Contains(ml.MachineMake, searchtxt)
|
||||
|| Helper.Contains(ml.MachineModel, searchtxt)
|
||||
|| Helper.Contains(ml.MachineType, searchtxt)
|
||||
|| Helper.Contains(ml.StrForMaintenanceDate, searchtxt)
|
||||
|| Helper.Contains(ml.Notes, searchtxt))
|
||||
{
|
||||
list.Add(ml);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list.Add(ml);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceLogInfo GetMaintenanceInfo(string maintenanceid)
|
||||
{
|
||||
const string SQL = @"select a.MAINTENANCEID,a.MACHINEID,a.MAINTENANCEDATE,a.MAINTENANCEHOURS,a.NOTES,a.ALERTID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
t.ALERTTYPE,t.ALERTTITLE,t.ALERTTIME_UTC,ISNULL(a.ODOMETER,0) AS ODOMETER,ISNULL(a.ODOMETERUOM,'Hour') AS ODOMETERUOM, isnull(LOGTYPE,'Hours') AS LOGTYPE
|
||||
,a.COST,a.INVOICENUMBER,a.COMPLETEDBY,a.COMPLETEDBYUSERNAME from MAINTENANCELOG a left join ALERTS t on a.ALERTID=t.ALERTID,MACHINES b
|
||||
where a.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 and a.MAINTENANCEID={0} ORDER BY a.ADDEDON DESC";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, maintenanceid);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceLogInfo();
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dt.Rows[0], makes, models, types);
|
||||
return ml;
|
||||
}
|
||||
|
||||
public static MaintenanceLogInfo[] GetMaintenanceLogByMachineID(long MachineID, string maintenanceType)
|
||||
{
|
||||
string SQL = @"select a.MAINTENANCEID,a.MACHINEID,a.MAINTENANCEDATE,a.MAINTENANCEHOURS,a.NOTES,a.ALERTID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS, ISNULL(a.ODOMETER,0) AS ODOMETER,ISNULL(a.ODOMETERUOM,'Mile') AS ODOMETERUOM, isnull(LOGTYPE,'Hours') AS LOGTYPE
|
||||
,a.COST,a.INVOICENUMBER,a.COMPLETEDBY,a.COMPLETEDBYUSERNAME from MAINTENANCELOG a, MACHINES b where a.MACHINEID = b.MACHINEID and a.MACHINEID={0}";
|
||||
if (maintenanceType != null)
|
||||
SQL += " and LOGTYPE={1} ";
|
||||
SQL += " ORDER BY a.ADDEDON DESC";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, MachineID, maintenanceType);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceLogInfo[0];
|
||||
}
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
List<MaintenanceLogInfo> list = new List<MaintenanceLogInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dr, makes, models, types);
|
||||
list.Add(ml);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceLogInfo GetMaintenanceLogByMaintenanceID(string MaintenanceID)
|
||||
{
|
||||
const string SQL = @"select a.MAINTENANCEID,a.MACHINEID,a.MAINTENANCEDATE,a.MAINTENANCEHOURS,a.NOTES,a.ALERTID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID
|
||||
,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,ISNULL(a.ODOMETER,0) AS ODOMETER,ISNULL(a.ODOMETERUOM,'Mile') AS ODOMETERUOM, isnull(LOGTYPE,'Hours') AS LOGTYPE
|
||||
,a.COST,a.INVOICENUMBER,a.COMPLETEDBY,a.COMPLETEDBYUSERNAME from MAINTENANCELOG a , MACHINES b where a.MACHINEID = b.MACHINEID and a.MAINTENANCEID={0}";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, MaintenanceID);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceLogInfo();
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
|
||||
MaintenanceLogInfo ml = ConvertToMaintenanceLogInfo(dt.Rows[0], makes, models, types);
|
||||
return ml;
|
||||
}
|
||||
|
||||
public static void UpdateMaintenanceLog(MaintenanceLogInfo ml, string addedby)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from MAINTENANCELOG where MAINTENANCEID={0}) update MAINTENANCELOG set MACHINEID ={1},MAINTENANCEDATE ={2},
|
||||
MAINTENANCEHOURS={3},NOTES={4},LASTUPDATEDBY={5},LASTUPDATEDON=GETUTCDATE(),ALERTID={6},ODOMETER={7},ODOMETERUOM={8},LOGTYPE={9},COST={10},INVOICENUMBER={11},COMPLETEDBYUSERNAME={12},COMPLETED={13},COMPLETEDDATE_UTC= (case {13} when 1 then GETUTCDATE() else null end) where MAINTENANCEID={0} else insert into MAINTENANCELOG(MAINTENANCEID,
|
||||
MACHINEID,MAINTENANCEDATE,MAINTENANCEHOURS,NOTES,ADDEDBY,ADDEDON,LASTUPDATEDBY,LASTUPDATEDON,ALERTID,ODOMETER,ODOMETERUOM,LOGTYPE,COST,INVOICENUMBER,COMPLETEDBYUSERNAME,COMPLETED,COMPLETEDDATE_UTC) values({0},{1},{2},{3},{4},{5},GETUTCDATE(),{5},GETUTCDATE(),{6},{7},{8},{9},{10},{11},{12},{13},(case {13} when 1 then GETUTCDATE() else null end))";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, ml.MaintenanceID, ml.MachineID, ml.MaintenanceDate, ml.MaintenanceHours, ml.Notes, addedby, ml.AlertID, ml.ODOMeter, ml.ODOMemterUOM, ml.LogType, ml.Cost, ml.InvoiceNumber, ml.CompletedByName, ml.Completed ? 1 : 0);
|
||||
}
|
||||
|
||||
public static void DeleteMaintenanceLog(string maintencelogid)
|
||||
{
|
||||
const string SQL = "delete from MAINTENANCELOG where MAINTENANCEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, maintencelogid);
|
||||
}
|
||||
|
||||
public static bool HasMaintenanceLog(long machineid)
|
||||
{
|
||||
const string SQL = "SELECT count([MAINTENANCEDATE]) FROM [MAINTENANCELOG] where MACHINEID={0}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
return (int?)db.GetRC1BySQL(SQL, machineid) > 0;
|
||||
}
|
||||
|
||||
public static PMAlert[] GetUnCompletedPMAlerts(long machineid, string maintencelogid)
|
||||
{
|
||||
List<PMAlert> alerts = new List<PMAlert>();
|
||||
const string SQL = "select LOGID,pm.ALERTID,pm.ALERTTIME_UTC,ALERTTITLE from PM_ALERTS pm left join ALERTS a on pm.ALERTID=a.ALERTID where pm.MACHINEID={0} and ((ISNULL(a.COMPLETED,0)<>1 and ISNULL(a.ACKNOWLEDGED,0)<>1) or exists(select 1 from MAINTENANCELOG ml where ml.ALERTID=a.ALERTID and MAINTENANCEID={1} ))";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, machineid, maintencelogid);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
PMAlert alert = new PMAlert();
|
||||
alert.LogID = FIDbAccess.GetFieldString(dr["LOGID"], string.Empty);
|
||||
alert.AlertID = FIDbAccess.GetFieldString(dr["ALERTID"], string.Empty);
|
||||
alert.AlertTitle = FIDbAccess.GetFieldString(dr["ALERTTITLE"], string.Empty);
|
||||
DateTime at = FIDbAccess.GetFieldDateTime(dr["ALERTTIME_UTC"], DateTime.MinValue);
|
||||
if (at != DateTime.MinValue)
|
||||
alert.AlertTime = at.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
alerts.Add(alert);
|
||||
}
|
||||
return alerts.ToArray();
|
||||
}
|
||||
|
||||
public static void SetPMAlertCompleted(long alertID, bool completed, string completedby)
|
||||
{
|
||||
const string SQL = "update ALERTS set COMPLETED={0},COMPLETEDBY={2},COMPLETEDDATE_UTC=(case {0} when 1 then GETUTCDATE() else null end) where ALERTID={1}";
|
||||
var db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, completed ? 1 : 0, alertID, completedby);
|
||||
}
|
||||
|
||||
private static MaintenanceLogInfo ConvertToMaintenanceLogInfo(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types)
|
||||
{
|
||||
MaintenanceLogInfo ml = new MaintenanceLogInfo();
|
||||
ml.MaintenanceID = FIDbAccess.GetFieldString(dr["MAINTENANCEID"], string.Empty);
|
||||
ml.MachineID = FIDbAccess.GetFieldInt(dr["MACHINEID"], 0);
|
||||
ml.MaintenanceDate = FIDbAccess.GetFieldDateTime(dr["MAINTENANCEDATE"], DateTime.MinValue);
|
||||
ml.MaintenanceHours = FIDbAccess.GetFieldDouble(dr["MAINTENANCEHOURS"], 0);
|
||||
ml.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
ml.AlertID = FIDbAccess.GetFieldInt(dr["ALERTID"], -1);
|
||||
ml.MachinePin = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
ml.MachineName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
ml.MachineName2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
ml.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
ml.ODOMeter = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
ml.ODOMemterUOM = FIDbAccess.GetFieldString(dr["ODOMETERUOM"], "Mile");
|
||||
ml.LogType = FIDbAccess.GetFieldString(dr["LOGTYPE"], "Hours");
|
||||
ml.Cost = FIDbAccess.GetFieldDouble(dr["COST"], 0);
|
||||
ml.InvoiceNumber = FIDbAccess.GetFieldString(dr["INVOICENUMBER"], "");
|
||||
ml.CompletedByName = FIDbAccess.GetFieldString(dr["COMPLETEDBYUSERNAME"], "");
|
||||
|
||||
int makeid = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
ml.MachineMake = make == null ? string.Empty : make.Name;
|
||||
|
||||
int modelid = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
ml.MachineModel = model == null ? string.Empty : model.Name;
|
||||
|
||||
int typeid = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
ml.MachineType = mtype == null ? string.Empty : mtype.Name;
|
||||
|
||||
return ml;
|
||||
}
|
||||
|
||||
public static WorkOrderInfo[] GetMaintenanceWorkOrders(string sessionid, string custid, string[] assignedusers, string[] asseitgroups, string filter, string useriid)
|
||||
{
|
||||
const string SQL = @"select m.MAINTENANCEID,m.COMPLETEDBY,(select USERNAME from USERS where USERS.USERIID=m.COMPLETEDBY) as ASSIGNEDTONAME,m.NOTES,m.MAINTENANCEDATE
|
||||
,b.MACHINEID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MAINTENANCELOG m left join MACHINES b on b.MACHINEID=m.MACHINEID
|
||||
where m.ALERTID not in (select ALERTID from WORKORDER_ALERTS) and m.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 ";
|
||||
const string SQL_FILTER = " and (m.NOTES like {0} or b.MACHINEID like {0} or b.VIN like {0} or b.MACHINENAME like {0} or b.MACHINENAME2 like {0}) ";
|
||||
const string SQL_ORDERBY = " order by m.MAINTENANCEID";
|
||||
|
||||
var user = FleetServiceClientHelper.CreateClient<UserQueryClient>(custid, sessionid).GetUserByIID(useriid);
|
||||
if (user == null || (!user.Active))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
}
|
||||
if (user == null || (!user.Active))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
}
|
||||
if (string.Compare(user.CompanyID, SystemParams.CompanyID, true) != 0 && (!user.IsForesightUser))
|
||||
{
|
||||
return new WorkOrderInfo[0];
|
||||
}
|
||||
|
||||
string sql = SQL;
|
||||
if ((!user.IsForesightUser) && (user.ContactType == Foresight.Fleet.Services.User.ContactTypes.Technician))
|
||||
{
|
||||
sql += " and m.COMPLETEDBY in ('" + useriid + "') ";
|
||||
}
|
||||
else if (assignedusers != null && assignedusers.Length > 0)
|
||||
{
|
||||
string uids = JoinSQLString(assignedusers);
|
||||
sql += " and m.COMPLETEDBY in (" + uids + ") ";
|
||||
}
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
long[] assets = null;
|
||||
if (asseitgroups != null && asseitgroups.Length > 0)
|
||||
{
|
||||
assets = MachineManagement.GetGroupMachines(asseitgroups, db);
|
||||
}
|
||||
DataTable dt = null;
|
||||
if (string.IsNullOrWhiteSpace(filter))
|
||||
dt = db.GetDataTableBySQL(sql + SQL_ORDERBY);
|
||||
else
|
||||
dt = db.GetDataTableBySQL(sql + SQL_FILTER + SQL_ORDERBY, "%" + filter + "%");
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
return new WorkOrderInfo[0];
|
||||
|
||||
List<WorkOrderInfo> list = new List<WorkOrderInfo>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
WorkOrderInfo wo = new WorkOrderInfo();
|
||||
|
||||
long assetid = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
if (assets != null && assets.Length > 0)
|
||||
{
|
||||
if (!assets.Contains(assetid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
wo.AssetID = assetid;
|
||||
wo.AssignedTo = FIDbAccess.GetFieldString(dr["COMPLETEDBY"], string.Empty);
|
||||
wo.MaintenanceID = FIDbAccess.GetFieldString(dr["MAINTENANCEID"], string.Empty);
|
||||
wo.Description = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
wo.CompleteDate = FIDbAccess.GetFieldDateTime(dr["MAINTENANCEDATE"], DateTime.MinValue);
|
||||
wo.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
wo.AssetName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
wo.AssignedToName = FIDbAccess.GetFieldString(dr["ASSIGNEDTONAME"], wo.AssignedTo);
|
||||
|
||||
list.Add(wo);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static string JoinSQLString(IEnumerable<string> items)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
foreach (string s in items)
|
||||
{
|
||||
if (sb.Length == 0)
|
||||
{
|
||||
sb.Append("'" + s + "'");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(",'" + s + "'");
|
||||
}
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Machines
|
||||
|
||||
|
||||
public static MaintenanceMachineInfo[] GetMaintenanceMachines1(string sessionid, int machinetype, string searchtxt, string useriid, string companyid = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
//普通用户机器权限过滤
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = client.GetAvailableAssetsForUsers(companyid, useriid);
|
||||
AssetBasicInfo[] assets = client.GetAssetBasicInfo(companyid, searchtxt, availableAssetsids);
|
||||
if (assets != null && machinetype != -1)
|
||||
assets = assets.Where(m => m.TypeID == machinetype).ToArray();
|
||||
long[] mids = null;
|
||||
if (assets != null)
|
||||
mids = assets.AsEnumerable().Select(m => m.ID).ToArray();
|
||||
//var ehs = SystemParams.AssetClient.GetAssetsCurrentPrimaryEngineHours(companyid, mids);
|
||||
var odos = client.GetAssetsCurrentPrimaryOdometer(companyid, mids);
|
||||
List<MaintenanceMachineInfo> list = new List<MaintenanceMachineInfo>();
|
||||
foreach (var a in assets)
|
||||
{
|
||||
if (a.Hide) continue;
|
||||
MaintenanceMachineInfo mi = new MaintenanceMachineInfo();
|
||||
mi.MachineID = a.ID;
|
||||
mi.VIN = a.VIN;
|
||||
mi.MachineName = a.Name;
|
||||
mi.MachineName2 = a.Name2;
|
||||
mi.Make = a.MakeName;
|
||||
mi.Model = a.ModelName;
|
||||
mi.TypeID = a.TypeID;
|
||||
mi.MachineType = a.TypeName;
|
||||
mi.Hide = a.Hide;
|
||||
mi.EngineHours = a.EngineHours;
|
||||
if (odos != null && odos.Length > 0)
|
||||
{
|
||||
var odo = odos.FirstOrDefault((o) => o.AssetID == mi.MachineID);
|
||||
if (odo != null)
|
||||
mi.Odometer = odo.Corrected;
|
||||
}
|
||||
|
||||
list.Add(mi);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetMaintenanceMachines(string sessionid, int machinetype, string searchtxt, string useriid, string companyid = null)
|
||||
{
|
||||
const string SQL = @"select m.MACHINEID,m.MACHINENAME2,m.MACHINENAME,m.MAKEID,m.MODELID,m.TYPEID,m.VIN,ISNULL(m.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(m.ODOMETER,0) as ODOMETER,ISNULL(m.ODOMETERUOM,'Mile') AS ODOMETERUOM,m.HIDE from MACHINES m
|
||||
where 1=1";
|
||||
const string ORDER_BY = " order by MACHINEID";
|
||||
|
||||
string sql = string.Empty;
|
||||
if (machinetype >= 0)
|
||||
{
|
||||
sql = SQL + " and TYPEID=" + machinetype.ToString() + ORDER_BY;
|
||||
}
|
||||
else
|
||||
{
|
||||
sql = SQL + ORDER_BY;
|
||||
}
|
||||
|
||||
FIDbAccess db = null;
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
{
|
||||
companyid = SystemParams.CompanyID;
|
||||
db = SystemParams.GetDbInstance();
|
||||
}
|
||||
else
|
||||
{
|
||||
string connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
db = new FISqlConnection(connetionstring);
|
||||
}
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(sql);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid).GetAvailableAssetsForUsers(companyid, useriid);
|
||||
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
long mid = Convert.ToInt64(dr["MACHINEID"]);
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(mid))
|
||||
continue;
|
||||
MaintenanceMachineInfo mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
mi.Hide = FIDbAccess.GetFieldInt(dr["HIDE"], 0) == 1;
|
||||
if (mi.Hide) continue;
|
||||
if (!string.IsNullOrWhiteSpace(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(mi.VIN, searchtxt)
|
||||
|| Helper.Contains(mi.MachineID.ToString(), searchtxt)
|
||||
|| Helper.Contains(mi.MachineName, searchtxt)
|
||||
|| Helper.Contains(mi.MachineName2, searchtxt)
|
||||
|| Helper.Contains(mi.Make, searchtxt)
|
||||
|| Helper.Contains(mi.MachineType, searchtxt)
|
||||
|| Helper.Contains(mi.Model, searchtxt))
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ls.Add(mi);
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo GetmachineByMachineID(long machineid)
|
||||
{
|
||||
string SQL = @"select MACHINEID,MACHINENAME,MACHINENAME2,MAKEID,MODELID,TYPEID,VIN,ISNULL(ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(ODOMETER,0) as ODOMETER,ISNULL(ODOMETERUOM,'Mile') AS ODOMETERUOM from MACHINES where MACHINEID={0}";
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, machineid);
|
||||
MaintenanceMachineInfo mi = new MaintenanceMachineInfo();
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
mi.MachineID = -1;
|
||||
return mi;
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
mi = ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
}
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo ConvertToMaintenanceMachineInfo(DataRow dr, MachineMake[] makes, MachineModel[] models, MachineType[] types)
|
||||
{
|
||||
MaintenanceMachineInfo mi = new MaintenanceMachineInfo();
|
||||
mi.MachineID = Convert.ToInt64(dr["MACHINEID"]);
|
||||
mi.MachineName = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.MachineName2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
mi.EngineHours = FIDbAccess.GetFieldDouble(dr["ENGINEHOURS"], 0);
|
||||
mi.Odometer = FIDbAccess.GetFieldDouble(dr["ODOMETER"], 0);
|
||||
|
||||
int makeid = FIDbAccess.GetFieldInt(dr["MAKEID"], 0);
|
||||
MachineMake make = MachineManagement.GetMachineMake(makes, makeid);
|
||||
mi.Make = make == null ? string.Empty : make.Name;
|
||||
|
||||
int modelid = FIDbAccess.GetFieldInt(dr["MODELID"], 0);
|
||||
MachineModel model = MachineManagement.GetMachineModel(models, modelid);
|
||||
mi.Model = model == null ? string.Empty : model.Name;
|
||||
|
||||
int typeid = FIDbAccess.GetFieldInt(dr["TYPEID"], 0);
|
||||
MachineType mtype = MachineManagement.GetMachineType(types, typeid);
|
||||
mi.TypeID = mtype == null ? 0 : mtype.ID;
|
||||
mi.MachineType = mtype == null ? string.Empty : mtype.Name;
|
||||
|
||||
|
||||
if (dr.Table.Columns.Contains("STARTDATE"))
|
||||
{
|
||||
mi.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
}
|
||||
if (dr.Table.Columns.Contains("STARTHOURS"))
|
||||
{
|
||||
mi.StartHours = FIDbAccess.GetFieldDouble(dr["STARTHOURS"], 0);
|
||||
}
|
||||
if (dr.Table.Columns.Contains("STARTOTOMETER"))
|
||||
{
|
||||
mi.StartOdometer = FIDbAccess.GetFieldDouble(dr["STARTOTOMETER"], 0);
|
||||
}
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static string[] GetPMDescriptionByAssetID(string companyid, long assetid)
|
||||
{
|
||||
const string SQL_1 = @"select * from usvMaintenanceAlertsMapLayer ml with (nolock) right join
|
||||
(select cast(MachineID as nvarchar) + cast(max(MaintenanceDate) as nvarchar) as MaintenanceID from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Complete'
|
||||
group by MachineID) a on ml.MaintenanceID = a.MaintenanceID where PMStatus = 'Complete' and MachineID={0}";
|
||||
const string SQL_2 = "select * from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Overdue' and MachineID={0}";
|
||||
const string SQL_3 = "select * from usvMaintenanceAlertsMapLayer with (nolock) where PMStatus = 'Upcoming' and MachineID={0}";
|
||||
|
||||
|
||||
string connetionstring = SystemParams.DataDbConnectionString;
|
||||
if (SystemParams.IsDealer)
|
||||
connetionstring = SystemParams.GetDbStringByCompany(companyid);
|
||||
|
||||
FISqlConnection db = new FISqlConnection(connetionstring);
|
||||
DataTable dt = db.GetDataTableBySQL(SQL_1, assetid);
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
dt = db.GetDataTableBySQL(SQL_2, assetid);
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
dt = db.GetDataTableBySQL(SQL_3, assetid);
|
||||
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string desc = FIDbAccess.GetFieldString(dr["DESCRIPTION"], string.Empty);
|
||||
list.Add(desc);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
26
IronIntelContractorBusiness/Maintenance/SegmentInfo.cs
Normal file
26
IronIntelContractorBusiness/Maintenance/SegmentInfo.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class SegmentInfo
|
||||
{
|
||||
public long SegmentID { get; set; }
|
||||
public long WorkOrderID { get; set; }
|
||||
public long JobsiteID { get; set; }
|
||||
public string JobsiteName { get; set; }
|
||||
public string UserIID { get; set; }
|
||||
public string UserName { get; set; }
|
||||
public decimal Cost { get; set; }
|
||||
public decimal Hours { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public bool Completed { get; set; } = false;
|
||||
public DateTime? CompletedDate { get; set; }
|
||||
public string CompletedDateStr { get { return CompletedDate == null ? "" : CompletedDate.Value.ToShortDateString(); } }
|
||||
public string Component { get; set; }
|
||||
}
|
||||
}
|
57
IronIntelContractorBusiness/Maintenance/WorkOrderInfo.cs
Normal file
57
IronIntelContractorBusiness/Maintenance/WorkOrderInfo.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class WorkOrderInfo
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string MaintenanceID { get; set; }
|
||||
public string WorkOrderType { get; set; }
|
||||
public string AssignedTo { get; set; }
|
||||
public string AssignedToName { get; set; }
|
||||
public string Status { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime? DueDate { get; set; }
|
||||
public string DueDateStr { get { return DueDate == null ? "" : DueDate.Value.ToShortDateString(); } }
|
||||
public DateTime? CompleteDate { get; set; }
|
||||
public string CompleteDateStr { get { return CompleteDate == null ? "" : CompleteDate.Value.ToShortDateString(); } }
|
||||
public string InvoiceNumber { get; set; }
|
||||
}
|
||||
|
||||
public class WorkOrderDetailInfo : WorkOrderInfo
|
||||
{
|
||||
public string MeterType { get; set; }
|
||||
public double HourMeter { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string OdometerUnits { get; set; }
|
||||
public decimal WorkOrderTotalCost { get; set; }
|
||||
public decimal HoursToComplete { get; set; }
|
||||
public string InternalID { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public decimal PartsCost { get; set; }
|
||||
public decimal TravelTimeCost { get; set; }
|
||||
public decimal LaborCost { get; set; }
|
||||
public decimal HourlyRate { get; set; }
|
||||
public decimal OtherCost { get; set; }
|
||||
}
|
||||
}
|
189
IronIntelContractorBusiness/Maintenance/WorkOrderManager.cs
Normal file
189
IronIntelContractorBusiness/Maintenance/WorkOrderManager.cs
Normal file
@ -0,0 +1,189 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
using System.Web;
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
|
||||
namespace IronIntel.Contractor.Maintenance
|
||||
{
|
||||
public class WorkOrderManager : BusinessBase
|
||||
{
|
||||
public WorkOrderManager(string dbstr) : base(dbstr)
|
||||
{
|
||||
}
|
||||
|
||||
public long[] GetOpenWorkOrderID(string machineid)
|
||||
{
|
||||
const string SQL = "select WORKORDERID from WORKORDER where MACHINEID={0} and STATUS<>'Completed' and and isnull(DELETED,0)=0";
|
||||
DataTable tb = GetDataTableBySQL(SQL, machineid);
|
||||
|
||||
List<long> result = new List<long>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
result.Add(FIDbAccess.GetFieldInt(dr[0], 0));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public bool CanAccessWorkOrder(string sessionid, string woid, string mid, string useriid)
|
||||
{
|
||||
const string SQL = "select count(1) from WORKORDER where WORKORDERID={0} and ASSIGNEDTO={1}";
|
||||
|
||||
bool result = true;
|
||||
var user = FleetServiceClientHelper.CreateClient<Foresight.Fleet.Services.User.UserQueryClient>(sessionid).GetUserByIID(useriid);
|
||||
if ((!user.IsForesightUser) && (user.ContactType == Foresight.Fleet.Services.User.ContactTypes.Technician))
|
||||
{
|
||||
result = FIDbAccess.GetFieldInt(GetRC1BySQL(SQL, woid, useriid), 0) > 0;
|
||||
}
|
||||
if (result && user.UserType < Foresight.Fleet.Services.User.UserTypes.Admin)
|
||||
{
|
||||
long assetid = -1;
|
||||
if (!string.IsNullOrEmpty(mid))
|
||||
Int64.TryParse(mid, out assetid);
|
||||
else
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderClient>(sessionid);
|
||||
var workorder = client.GetWorkOrderDetail(SystemParams.CompanyID, Convert.ToInt64(woid));
|
||||
assetid = workorder.AssetID;
|
||||
}
|
||||
long[] availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
if (availableAssetsids != null && !availableAssetsids.Contains(assetid))
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public string[] GetInvoiceNumber(string woid)
|
||||
{
|
||||
const string SQL = @"select a.INVOICENUMBER from WORKORDER_ALERTS t left join MAINTENANCELOG a on a.ALERTID=t.ALERTID,MACHINES b
|
||||
where t.WORKORDERID={0} and a.MACHINEID = b.MACHINEID and ISNULL(b.HIDE,0)<>1 and ISNULL(a.INVOICENUMBER,'')<>'' ORDER BY a.ADDEDON DESC";
|
||||
|
||||
DataTable dt = GetDataTableBySQL(SQL, woid);
|
||||
if (dt.Rows.Count == 0)
|
||||
return new string[0];
|
||||
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string num = FIDbAccess.GetFieldString(dr["INVOICENUMBER"], string.Empty);
|
||||
if (!string.IsNullOrEmpty(num))
|
||||
list.Add(num);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static string GenerateWorkOrderPrintHtml(string sessionid, string companyid, long woid)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.AppendLine("<H1 style='text-align:center;'>Work Order</H1>");
|
||||
str.AppendFormat("<div style='font-weight:bold;'>Details for work order <{0}> are listed below:</div>", woid);
|
||||
str.AppendLine("");
|
||||
//str.AppendLine("<div class='label' style='text-align:left;'>Work Order Information:</div>");
|
||||
str.AppendLine("<div style='padding-left:30px;margin-bottom:36px;'>");
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<WorkOrderClient>(companyid, sessionid);
|
||||
WorkOrderDetail wo = client.GetWorkOrderDetail(companyid, woid);
|
||||
str.Append(GenerateWorkOrderInfoHtml(wo));
|
||||
str.AppendLine("</div>");
|
||||
//str.AppendLine("<div class='label' style='text-align:left;'>Segments:</div>");
|
||||
|
||||
WorkOrderSegmentItem[] segments = client.GetSegments(companyid, woid);
|
||||
|
||||
if (segments != null && segments.Length > 0)
|
||||
{
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
{
|
||||
var se = segments[i];
|
||||
str.Append(GenerateSegmentHtml(se, i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateWorkOrderInfoHtml(WorkOrderDetail wo)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.Append("<table>");
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>Work Order Type</td><td>{0}</td></tr>", wo.WorkOrderType);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Assigned To</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.AssignedToName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Status</td><td>{0}</td></tr>", wo.Status);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Due Date</td><td>{0}</td></tr>", wo.DueDate == null ? "" : wo.DueDate.Value.ToShortDateString());
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Description</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Description).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Meter Type</td><td>{0}</td></tr>", wo.MeterType);
|
||||
str.AppendLine("");
|
||||
if (string.Compare(wo.MeterType, "HourMeter", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>Hour Meter</td><td>{0}</td></tr>", wo.HourMeter);
|
||||
if (string.Compare(wo.MeterType, "Odometer", true) == 0
|
||||
|| string.Compare(wo.MeterType, "Both", true) == 0)
|
||||
str.AppendFormat("<tr><td class='label'>Odometer</td><td>{0} {1}</td></tr>", wo.Odometer, wo.OdometerUnits);
|
||||
str.AppendFormat("<tr><td class='label'>Work Order Total Costs ($)</td><td>{0}</td></tr>", wo.WorkOrderTotalCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Other Cost ($)</td><td>{0}</td></tr>", wo.OtherCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Parts Cost ($)</td><td>{0}</td></tr>", wo.PartsCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Travel Time Cost ($)</td><td>{0}</td></tr>", wo.TravelTimeCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Labor Cost ($)</td><td>{0}</td></tr>", wo.LaborCost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Hourly Rate</td><td>{0}</td></tr>", wo.HourlyRate);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Time To Complete(Hrs)</td><td>{0}</td></tr>", wo.HoursToComplete);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed Date</td><td>{0}</td></tr>", wo.CompleteDate == null ? "" : wo.CompleteDate.Value.ToShortDateString());
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Internal ID</td><td>{0}</td></tr>", wo.InternalID);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Invoice Number</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.InvoiceNumber));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Notes</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(wo.Notes).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("</table>");
|
||||
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
private static string GenerateSegmentHtml(WorkOrderSegmentItem se, int index)
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
//str.AppendFormat("<div style='margin-bottom:36px;margin-left:30px;{0}'>", (index - 2) % 4 == 0 ? "page-break-after: always;" : "");
|
||||
//str.AppendLine("");
|
||||
str.AppendLine("<div style='margin-bottom:36px;margin-left:30px;'>");
|
||||
str.AppendLine("<table>");
|
||||
str.AppendFormat("<tr><td class='label' colspan='2' style='text-align:left;'>Segment {0}</td></tr>", index);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label' style='width:170px;'>User</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.UserName));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Hours</td><td>{0}</td></tr>", se.Hours);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Job Site</td><td>{0}</td></tr>", se.JobsiteName);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Cost</td><td>{0}</td></tr>", se.Cost);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Component</td><td>{0}</td></tr>", se.Component);
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed</td><td>{0}</td></tr>", se.Completed ? "Yes" : "No");
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Completed Date</td><td>{0}</td></tr>", se.CompletedDate == null ? "" : se.CompletedDate.Value.ToShortDateString());
|
||||
str.AppendFormat("<tr><td class='label'>Description</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Description));
|
||||
str.AppendLine("");
|
||||
str.AppendFormat("<tr><td class='label'>Notes</td><td>{0}</td></tr>", HttpUtility.HtmlEncode(se.Notes).Replace("\n", "<br>"));
|
||||
str.AppendLine("");
|
||||
str.AppendLine("</table>");
|
||||
str.AppendLine("</div>");
|
||||
return str.ToString();
|
||||
}
|
||||
}
|
||||
}
|
425
IronIntelContractorBusiness/MapView/AssetMapViewManagement.cs
Normal file
425
IronIntelContractorBusiness/MapView/AssetMapViewManagement.cs
Normal file
@ -0,0 +1,425 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using Foresight.Data;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.MapView;
|
||||
using Foresight.Fleet.Services.JobSite;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class AssetMapViewManagement : MachineManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据Contractorid获取机器列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AssetViewItem[] GetAssets(string sessionid, string companyid, string useriid, string filtertext, int onroad, MachineAlertViewQueryParameter param, bool IncludeNoLocation)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
MapViewAssetsQueryParam qp = new MapViewAssetsQueryParam();
|
||||
qp.FilterString = filtertext;
|
||||
qp.OnRoad = onroad;
|
||||
qp.IncludeNoLocation = IncludeNoLocation;
|
||||
qp.IncludeAssetGroups = true;
|
||||
qp.IncludeJobSites = true;
|
||||
if (param != null)
|
||||
{
|
||||
qp.ViewId = param.ViewID;
|
||||
qp.AlertViewQueryParam = param;
|
||||
}
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AssetMapViewPinItem[] assets = client.GetAssets(companyid, useriid, qp);
|
||||
List<AssetViewItem> result = new List<AssetViewItem>();
|
||||
foreach (var a in assets)
|
||||
{
|
||||
AssetViewItem avi = new AssetViewItem();
|
||||
Helper.CloneProperty(avi, a);
|
||||
result.Add(avi);
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static AssetDetailViewItem GetAssetDetailItem(string sessionid, string companyid, long machineid, string datasource = null)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
var asset = client.GetAssetDetailInfo(companyid, machineid);
|
||||
AssetDetailViewItem mi = new AssetDetailViewItem();
|
||||
mi.ID = asset.ID;
|
||||
mi.Name = asset.Name;
|
||||
mi.Name2 = asset.Name2;
|
||||
mi.VIN = asset.VIN;
|
||||
mi.MakeYear = asset.MakeYear;
|
||||
mi.Make = asset.MakeName;
|
||||
mi.Model = asset.ModelName;
|
||||
mi.AssetType = asset.TypeName;
|
||||
mi.GroupNames = asset.GroupNames;
|
||||
mi.IconUrl = asset.MapViewIconUrl;
|
||||
mi.AssetIconUrl = asset.AssetIconUrl;
|
||||
|
||||
if (asset.CurrentHours != null)
|
||||
{
|
||||
mi.EngineHours = asset.CurrentHours.Corrected;
|
||||
mi.EngineHoursDate = asset.CurrentHours.AsofTimeLocal;
|
||||
}
|
||||
|
||||
mi.Location = new LocationViewItem();
|
||||
var loc = asset.CurrentLocation;
|
||||
if (!string.IsNullOrWhiteSpace(datasource)
|
||||
&& (loc == null || string.Compare(datasource, loc.DataSource, true) != 0))
|
||||
{
|
||||
AssetLocationInfo[] locs = client.GetAssetCurrentLocation(companyid, machineid);
|
||||
var tempLoc = locs.FirstOrDefault(l => string.Compare(datasource, l.DataSource, true) != 0);
|
||||
if (tempLoc != null)
|
||||
{
|
||||
mi.Location.Latitude = tempLoc.Latitude;
|
||||
mi.Location.Longitude = tempLoc.Longitude;
|
||||
mi.Location.LocationTime = tempLoc.AsofTimeLocal;
|
||||
mi.Location.Speed = tempLoc.Speed;
|
||||
mi.Location.SpeedUnit = tempLoc.SpeedUnits;
|
||||
mi.Location.PostedSpeed = tempLoc.PostedSpeedLimit;
|
||||
mi.Location.PostedSpeedUnit = tempLoc.SpeedLimitUnits;
|
||||
mi.Location.Street = tempLoc.Street;
|
||||
}
|
||||
}
|
||||
else if (loc != null)
|
||||
{
|
||||
mi.Location.Latitude = loc.Latitude;
|
||||
mi.Location.Longitude = loc.Longitude;
|
||||
mi.Location.LocationTime = loc.AsofTimeLocal;
|
||||
mi.Location.Speed = loc.Speed;
|
||||
mi.Location.SpeedUnit = loc.SpeedUnits;
|
||||
mi.Location.PostedSpeed = loc.PostedSpeedLimit;
|
||||
mi.Location.PostedSpeedUnit = loc.SpeedLimitUnits;
|
||||
mi.Location.Street = loc.Street;
|
||||
}
|
||||
|
||||
if (asset.CurrentOdometer != null)
|
||||
{
|
||||
mi.Odometer = asset.CurrentOdometer.Corrected;
|
||||
mi.OdometerUOM = asset.CurrentOdometer.UOM;
|
||||
}
|
||||
|
||||
return mi;
|
||||
}
|
||||
|
||||
public static AssetGroupViewItem[] GetAssetGroups(string sessionid, string companyid, string useriid, string searchtext)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AssetGroupInfo[] gs = client.GetAvailableAssetGroups(companyid, useriid, searchtext, false);
|
||||
|
||||
List<AssetGroupViewItem> list = new List<AssetGroupViewItem>();
|
||||
foreach (var g in gs)
|
||||
{
|
||||
AssetGroupViewItem ag = new AssetGroupViewItem();
|
||||
ag.ID = g.Id;
|
||||
ag.Name = g.Name;
|
||||
//ag.Assets = g.Assets;
|
||||
list.Add(ag);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static JobSiteViewItem[] GetJobsites(string sessionid, string companyid, string useriid, string searchtext)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
MapViewJobSiteInfo[] jss = client.GetAvailableJobSites(companyid, useriid, searchtext, false);
|
||||
|
||||
List<JobSiteViewItem> list = new List<JobSiteViewItem>();
|
||||
foreach (var js in jss)
|
||||
{
|
||||
JobSiteViewItem ajs = new JobSiteViewItem();
|
||||
ajs.ID = js.ID;
|
||||
ajs.Name = js.Name;
|
||||
ajs.Latitude = js.Latitude;
|
||||
ajs.Longitude = js.Longitude;
|
||||
ajs.Radius = js.Radius;
|
||||
ajs.Radius_UOM = js.RadiusUOM;
|
||||
//ajs.Assets = js.Assets;
|
||||
|
||||
System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
try
|
||||
{
|
||||
color = System.Drawing.ColorTranslator.FromHtml(js.Color);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
ajs.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
if (js.Polygon != null)
|
||||
{
|
||||
List<PostionItem> temp = new List<PostionItem>();
|
||||
foreach (var p in js.Polygon)
|
||||
{
|
||||
temp.Add(new PostionItem(p.Latitude, p.Longtitude));
|
||||
}
|
||||
ajs.Polygon = temp.ToArray();
|
||||
}
|
||||
ajs.Notes = js.Notes;
|
||||
list.Add(ajs);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<MachineViewItem>> GetGroupAssets(string useriid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"if(select count(1) from USERMACHINEGROUPMAP where USERIID={0})=0
|
||||
select a.MACHINEID,a.GROUPID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MACHINEGROUPMAP a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0
|
||||
else
|
||||
select a.MACHINEID,a.GROUPID,b.VIN,b.MACHINENAME,b.MACHINENAME2 from MACHINEGROUPMAP a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0
|
||||
and b.MACHINEID in (select distinct MACHINEID from MACHINEGROUPMAP
|
||||
where GROUPID in (select GROUPID from USERMACHINEGROUPMAP where USERIID={0}))";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = null;
|
||||
dt = db.GetDataTableBySQL(SQL, useriid);
|
||||
|
||||
Dictionary<string, List<MachineViewItem>> result = new Dictionary<string, List<MachineViewItem>>(StringComparer.OrdinalIgnoreCase);
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
string groupID = FIDbAccess.GetFieldString(dr["GROUPID"], string.Empty);
|
||||
if (!result.ContainsKey(groupID))
|
||||
result[groupID] = new List<MachineViewItem>();
|
||||
result[groupID].Add(mi);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void ConvertSpeedUnitToMile(LocationViewItem loc)
|
||||
{
|
||||
if (loc == null) return;
|
||||
if (loc.Speed >= 0 && loc.SpeedUnit.StartsWith("K", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loc.Speed = loc.Speed * 0.6213712;
|
||||
loc.SpeedUnit = "mi/h";
|
||||
}
|
||||
if (loc.PostedSpeed > 0 && loc.PostedSpeedUnit.StartsWith("K", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
loc.PostedSpeed = loc.PostedSpeed * 0.6213712;
|
||||
loc.PostedSpeedUnit = "mi/h";
|
||||
}
|
||||
}
|
||||
|
||||
public static AssetLocationHistoryViewItem GetMachineLocationHistory(string sessionid, string machineid, DateTime startTime, DateTime endTime, string companyid, bool notShow00loc, string datasource)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<AssetQueryClient>(companyid, sessionid);
|
||||
AssetBasicInfo asset = client.GetAssetBasicInfoByID(companyid, Convert.ToInt64(machineid));
|
||||
AssetViewItem ai = new AssetViewItem();
|
||||
Helper.CloneProperty(ai, asset);
|
||||
|
||||
double timeOffset = SystemParams.GetHoursOffset();
|
||||
startTime = startTime.AddHours(-timeOffset);
|
||||
endTime = endTime.AddHours(-timeOffset);
|
||||
|
||||
AssetLocationInfo[] assetLocs = client.GetAssetBasicLocationHistory(companyid, long.Parse(machineid), startTime, endTime, datasource, "", !notShow00loc);
|
||||
|
||||
List<LocationViewItem> ls = new List<LocationViewItem>();
|
||||
foreach (AssetLocationInfo assetLoc in assetLocs)
|
||||
{
|
||||
LocationViewItem li = new LocationViewItem();
|
||||
li.Latitude = assetLoc.Latitude;
|
||||
li.Longitude = assetLoc.Longitude;
|
||||
li.LocationTime = assetLoc.AsofTime.AddHours(timeOffset);
|
||||
|
||||
li.Speed = assetLoc.Speed;
|
||||
li.SpeedUnit = assetLoc.SpeedUnits;
|
||||
li.PostedSpeed = assetLoc.PostedSpeedLimit;
|
||||
li.PostedSpeedUnit = assetLoc.SpeedLimitUnits;
|
||||
li.Street = assetLoc.Street;
|
||||
li.HarshDringEvent = assetLoc.HarshDringEvent;
|
||||
li.SpeedingBehavior = assetLoc.SpeedingBehavior;
|
||||
li.IconURL = GenerateLocationIconUrl(assetLoc);
|
||||
li.SmartWitnessVideoUrl = assetLoc.SmartWitnessVideoUrl;
|
||||
|
||||
ConvertSpeedUnitToMile(li);
|
||||
ls.Add(li);
|
||||
}
|
||||
AssetLocationHistoryViewItem al = new AssetLocationHistoryViewItem();
|
||||
al.Machine = ai;
|
||||
al.Locations = ls.ToArray();
|
||||
return al;
|
||||
}
|
||||
|
||||
private static string GenerateLocationIconUrl(AssetLocationInfo loc)
|
||||
{
|
||||
//http://iron.soft.rz/admin/machinetypeicon.ashx
|
||||
//http://iron.soft.rz/admin/machinemovingicon.ashx
|
||||
string path = SystemParams.MachineTypeMapViewIconUrl.ToLower().Replace("machinetypeicon.ashx", "machinemovingicon.ashx");
|
||||
const string PARAM = "?tp={0}&bkcolor={1}&heading={2}";
|
||||
int tp = (int)HarshDrivingEvents.HardAccelerationEvent;
|
||||
string color = "";
|
||||
switch (loc.HarshDringEvent)
|
||||
{
|
||||
case HarshDrivingEvents.None:
|
||||
break;
|
||||
case HarshDrivingEvents.HardAccelerationEvent:
|
||||
color = "#ff3f48cc";
|
||||
break;
|
||||
case HarshDrivingEvents.HardBrakeEvent:
|
||||
color = "#ff00a8f3";
|
||||
break;
|
||||
case HarshDrivingEvents.HardTurnEvent:
|
||||
color = "#fffff200";
|
||||
break;
|
||||
}
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.SpeedingBehavior == SpeedingBehaviors.MinorSpeeding)
|
||||
color = "#ffff7f27";
|
||||
else if (loc.SpeedingBehavior == SpeedingBehaviors.SevereSpeeding)
|
||||
color = "#ffec1c24";
|
||||
}
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.MoveStatus == AssetMoveStatus.InMotion)
|
||||
color = "#ff228B22";
|
||||
}
|
||||
|
||||
if (loc.Speed <= 0 && loc.MoveStatus == AssetMoveStatus.Unknown)
|
||||
loc.Heading = -1;
|
||||
|
||||
if (string.IsNullOrEmpty(color))
|
||||
{
|
||||
if (loc.MoveStatus == AssetMoveStatus.StoppedOn)
|
||||
return path + "?legend=StoppedOn";
|
||||
else if (loc.MoveStatus == AssetMoveStatus.StoppedOff)
|
||||
return path + "?legend=StoppedOff";
|
||||
}
|
||||
color = HttpUtility.UrlEncode(color);
|
||||
path = path + string.Format(PARAM, tp, color, loc.Heading);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public static MapAlertViewDefinitionItem[] GetMapAlertViews(string sessionid, string companyid, string selectedViewID)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(companyid))
|
||||
companyid = SystemParams.CompanyID;
|
||||
|
||||
var client = FleetServiceClientHelper.CreateClient<MapViewQueryClient>(companyid, sessionid);
|
||||
AlertViewMapItem[] views = client.GetAlertViewMapItems(companyid);
|
||||
|
||||
AlertViewMapItem viewInfo = null;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(selectedViewID))//获取View下使用的数据源信息
|
||||
viewInfo = client.GetAlertViewMapItem(companyid, selectedViewID);
|
||||
}
|
||||
catch { }
|
||||
|
||||
string path = SystemParams.MachineTypeMapViewIconUrl;
|
||||
List<MapAlertViewDefinitionItem> ls = new List<MapAlertViewDefinitionItem>();
|
||||
foreach (AlertViewMapItem ai in views)
|
||||
{
|
||||
MapAlertViewDefinitionItem mi = new MapAlertViewDefinitionItem();
|
||||
mi.ID = ai.ID;
|
||||
mi.Name = ai.Name;
|
||||
|
||||
if (viewInfo != null && viewInfo.ID.Equals(mi.ID, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
mi.Layers = new MapAlertLayerDefinitionItem[viewInfo.Layers.Count];
|
||||
for (int i = 0; i < viewInfo.Layers.Count; i++)
|
||||
{
|
||||
var layer = viewInfo.Layers[i];
|
||||
mi.Layers[i] = new MapAlertLayerDefinitionItem();
|
||||
mi.Layers[i].ID = layer.LayerId;
|
||||
mi.Layers[i].Title = layer.Title;
|
||||
mi.Layers[i].LegendUrl = layer.LegendUrl;
|
||||
|
||||
if (layer.Pivots != null && layer.Pivots.Count > 0)
|
||||
mi.Layers[i].Pivots = ConvertPivotsDefine(layer.Pivots);
|
||||
}
|
||||
//mi.Layers = mi.Layers.OrderBy((l) => l.AlertLayerType).ToArray();
|
||||
mi.LookupDataSources = ConvertLookupData(viewInfo.LookupDataSources);
|
||||
}
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.OrderBy((mal) => mal.Name).ToArray();
|
||||
|
||||
}
|
||||
|
||||
private static List<LookupDataSourceDataItem> ConvertLookupData(List<LookupDataSourceData> data)
|
||||
{
|
||||
List<LookupDataSourceDataItem> result = new List<LookupDataSourceDataItem>();
|
||||
if (data != null)
|
||||
{
|
||||
foreach (LookupDataSourceData d in data)
|
||||
{
|
||||
LookupDataSourceDataItem item = new LookupDataSourceDataItem();
|
||||
item.ID = d.ID;
|
||||
item.Name = d.Name;
|
||||
item.Items.AddRange(d.Items);
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static AlertLayerPivotViewItem[] ConvertPivotsDefine(List<AlertLayerPivot> paramerters)
|
||||
{
|
||||
List<AlertLayerPivotViewItem> list = new List<AlertLayerPivotViewItem>();
|
||||
foreach (AlertLayerPivot pd in paramerters)
|
||||
{
|
||||
AlertLayerPivotViewItem pi = new AlertLayerPivotViewItem();
|
||||
Helper.CloneProperty(pi, pd);
|
||||
if (pi.DataType == DataTypes.Datetime)
|
||||
{
|
||||
try
|
||||
{
|
||||
pi.DefaultValue = DateTime.Parse(pi.DefaultValue).ToString("M/d/yyyy");
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
list.Add(pi);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static long[] GetNoGroupAssets(string companyid)
|
||||
{
|
||||
const string SQL = @"select b.MACHINEID from MACHINES b where not exists(select 1 from MACHINEGROUPMAP a where a.MACHINEID=b.MACHINEID) and isnull(b.HIDE,0)=0";
|
||||
|
||||
string dbs = SystemParams.GetCompanyDbString(companyid);
|
||||
FISqlConnection db = new FISqlConnection(dbs);
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
|
||||
List<long> result = new List<long>();
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new long[0];
|
||||
}
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
result.Add(FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0));
|
||||
}
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
123
IronIntelContractorBusiness/MapView/AssetViewItems.cs
Normal file
123
IronIntelContractorBusiness/MapView/AssetViewItems.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using Foresight;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.MapView;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class AssetViewItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string AlertTips { get; set; }
|
||||
public List<string> AssetGroups { get; set; }
|
||||
public List<long> JobSites { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = ID.ToString();
|
||||
return name;
|
||||
}
|
||||
}//由于地图显示及排序的名称
|
||||
|
||||
}
|
||||
public class AssetDetailViewItem
|
||||
{
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
public string GroupNames { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string OdometerUOM { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
public string AssetType { get; set; }
|
||||
public string Model { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string Name { get; set; }
|
||||
public long ID { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string AssetIconUrl { get; set; }
|
||||
public LocationViewItem Location { get; set; }
|
||||
public string EngineHoursDateText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EngineHoursDate != DateTime.MinValue)
|
||||
{
|
||||
return EngineHoursDate.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class AssetLocationHistoryViewItem
|
||||
{
|
||||
public AssetViewItem Machine { get; set; }
|
||||
public LocationViewItem[] Locations { get; set; }
|
||||
}
|
||||
|
||||
public class AlertLayerPivotViewItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DataTypes DataType { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ParameterValue { get; set; }
|
||||
public QueryParameterDisplayStyles DisplayStyle { get; set; }
|
||||
public string LookupDatasourceID { get; set; }
|
||||
public bool DisplayCaptionField { get; set; }
|
||||
public bool IsField { get; set; }
|
||||
public bool IsAllAllowed { get; set; }
|
||||
public bool MutipleSelect { get; set; }
|
||||
public bool IsCriteriaSQL { get; set; }
|
||||
}
|
||||
}
|
125
IronIntelContractorBusiness/MapView/JobManagement.cs
Normal file
125
IronIntelContractorBusiness/MapView/JobManagement.cs
Normal file
@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight.Data;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class JobManagement
|
||||
{
|
||||
public static JobSiteViewItem[] GetJobSite(string searchtext, int onroad, string companyid)
|
||||
{
|
||||
const string sql_1 = @"select JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE ,RADIUS,RADUIS_UOM,CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON from JOBSITES where ENDDATE is null or ENDDATE>getdate() order by JOBSITENAME";
|
||||
const string sql_2 = @"select JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE ,RADIUS,RADUIS_UOM,CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON from JOBSITES where (ENDDATE is null or ENDDATE>getdate()) and JOBSITENAME like {0} order by JOBSITENAME";
|
||||
|
||||
FISqlConnection db = SystemParams.GetCompanyDbConnection(companyid);
|
||||
if (db == null)
|
||||
{
|
||||
return new JobSiteViewItem[0];
|
||||
}
|
||||
DataTable dt = null;
|
||||
if (string.IsNullOrWhiteSpace(searchtext))
|
||||
{
|
||||
dt = db.GetDataTableBySQL(sql_1);
|
||||
}
|
||||
else
|
||||
{
|
||||
dt = db.GetDataTableBySQL(sql_2, "%" + searchtext + "%");
|
||||
}
|
||||
List<JobSiteViewItem> list = new List<JobSiteViewItem>();
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
JobSiteViewItem js = new JobSiteViewItem();
|
||||
long JobSiteId = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.ID = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.Name = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
js.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
js.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
js.Radius = FIDbAccess.GetFieldDouble(dr["RADIUS"], 0);
|
||||
js.Radius_UOM = FIDbAccess.GetFieldString(dr["RADUIS_UOM"], string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(js.Radius_UOM))
|
||||
js.Radius_UOM = "Mile";
|
||||
js.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
js.ColorString = FIDbAccess.GetFieldString(dr["COLOR"], string.Empty);
|
||||
System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
try
|
||||
{
|
||||
color = System.Drawing.ColorTranslator.FromHtml(js.ColorString);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
js.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
|
||||
js.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
js.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
js.EndDate = FIDbAccess.GetFieldDateTime(dr["ENDDATE"], DateTime.MinValue);
|
||||
string polygon = FIDbAccess.GetFieldString(dr["POLYGON"], string.Empty);
|
||||
js.Polygon = ConvertPolygonToPointItem(polygon);
|
||||
MachineViewItem[] msiary = GetJobSiteMachines(JobSiteId, onroad, db);
|
||||
if (msiary.Count() > 0)
|
||||
{
|
||||
js.Machines = msiary.OrderBy((m) => m.VIN).ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
js.Machines = null;
|
||||
}
|
||||
list.Add(js);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static MachineViewItem[] GetJobSiteMachines(long jobsiteid, int onroad, FISqlConnection db = null)
|
||||
{
|
||||
const string sql_m = @"select a.MACHINEID,b.VIN,b.MACHINENAME,b.MACHINENAME2,ONROAD from JOBSITEMACHINES a,MACHINES b where a.MACHINEID=b.MACHINEID and ISNULL(b.HIDE,0)=0 and a.JOBSITEID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = null;
|
||||
dt = db.GetDataTableBySQL(sql_m, jobsiteid);
|
||||
|
||||
if (dt.Rows.Count == 0)
|
||||
{
|
||||
return new MachineViewItem[0];
|
||||
}
|
||||
List<MachineViewItem> list = new List<MachineViewItem>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
MachineViewItem mi = new MachineViewItem();
|
||||
mi.ID = FIDbAccess.GetFieldInt64(dr["MACHINEID"], 0);
|
||||
mi.Name = FIDbAccess.GetFieldString(dr["MACHINENAME"], string.Empty);
|
||||
mi.Name2 = FIDbAccess.GetFieldString(dr["MACHINENAME2"], string.Empty);
|
||||
mi.VIN = FIDbAccess.GetFieldString(dr["VIN"], string.Empty);
|
||||
mi.Onroad = FIDbAccess.GetFieldInt(dr["ONROAD"], 0);
|
||||
if (onroad < 0 || onroad == mi.Onroad)
|
||||
list.Add(mi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static PostionItem[] ConvertPolygonToPointItem(string polygon)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(polygon))
|
||||
return null;
|
||||
|
||||
List<PostionItem> list = new List<PostionItem>();
|
||||
var polygons = polygon.Split(';');
|
||||
foreach (var py in polygons)
|
||||
{
|
||||
PostionItem pi = new PostionItem();
|
||||
var sap = py.Split(',');
|
||||
pi.Latitude = Convert.ToDouble(sap[0]);
|
||||
pi.Longitude = Convert.ToDouble(sap[1]);
|
||||
list.Add(pi);
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
55
IronIntelContractorBusiness/MapView/LocationManagement.cs
Normal file
55
IronIntelContractorBusiness/MapView/LocationManagement.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Foresight.Fleet.Services.Customer;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class LocationManagement
|
||||
{
|
||||
public static CompanyLocationViewItem[] GetCompanyLocations(string companyid)
|
||||
{
|
||||
List<CompanyLocationViewItem> ls = new List<CompanyLocationViewItem>();
|
||||
if (string.IsNullOrWhiteSpace(companyid) || string.Compare(companyid, SystemParams.CompanyID, true) == 0)
|
||||
{
|
||||
GetCompanyLocations(SystemParams.CompanyID, ls);
|
||||
if (!SystemParams.IsDealer)
|
||||
{
|
||||
Services.Customers.CustomerInfo dealer = SystemParams.GetFirstDealerInfo();
|
||||
if (dealer != null)
|
||||
{
|
||||
GetCompanyLocations(dealer.ID, ls);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
private static void GetCompanyLocations(string companyid, List<CompanyLocationViewItem> ls)
|
||||
{
|
||||
CustomerLocation[] locations = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerLocations(companyid);
|
||||
|
||||
foreach (CustomerLocation loc in locations)
|
||||
{
|
||||
ls.Add(ConvertToViewItem(loc, companyid));
|
||||
}
|
||||
}
|
||||
|
||||
private static CompanyLocationViewItem ConvertToViewItem(CustomerLocation loc, string companyid)
|
||||
{
|
||||
CompanyLocationViewItem li = new CompanyLocationViewItem();
|
||||
li.CompanyID = companyid;
|
||||
li.ID = loc.ID;
|
||||
li.LocationName = loc.Name;
|
||||
li.Latitude = loc.Latitude;
|
||||
li.Longitude = loc.Longitude;
|
||||
li.Notes = loc.Notes;
|
||||
|
||||
return li;
|
||||
}
|
||||
}
|
||||
}
|
298
IronIntelContractorBusiness/MapView/MachineStateInfo.cs
Normal file
298
IronIntelContractorBusiness/MapView/MachineStateInfo.cs
Normal file
@ -0,0 +1,298 @@
|
||||
using Foresight;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using IronIntel.Services.Common;
|
||||
using IronIntel.Services.MapView;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public class MachineViewItem
|
||||
{
|
||||
public string VIN { get; set; }
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
public string EmptyIconUrl { get; set; }//不包含机器图标
|
||||
public string MachineType { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public int MakeYear { get; set; }
|
||||
|
||||
private double _EngineHours;
|
||||
public double EngineHours
|
||||
{
|
||||
get
|
||||
{
|
||||
return _EngineHours;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_EngineHours = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public DateTime EngineHoursDate { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string AlertTip { get; set; }
|
||||
public bool OnSite { get; set; }
|
||||
public string JobSiteName { get; set; }//当前所在的JobSiteName
|
||||
public double DistanceFromSite { get; set; }//机器与Jobsite之间的距离
|
||||
public bool WithinSite { get; set; }//机器是否在JobSite多边形范围内
|
||||
public LocationViewItem Location { get; set; }
|
||||
|
||||
private double _Odometer;
|
||||
public double Odometer
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Odometer;
|
||||
}
|
||||
set
|
||||
{
|
||||
value = value > 0 ? value : 0;
|
||||
_Odometer = Math.Round(value, 2);
|
||||
}
|
||||
}
|
||||
public string OdometerUOM { get; set; }
|
||||
public int Onroad { get; set; }
|
||||
public string IconFileName { get; set; }
|
||||
public string MoveStatus { get; set; }
|
||||
public int Directionalheading { get; set; }
|
||||
public int MapAlertLayerPriority { get; set; }
|
||||
public Int64 GpsDeviceID { get; set; } //空 -1
|
||||
public string AssetGroupNames { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
//Name取值顺序为Name2,Name,VIN,ID用于前端显示
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = ID.ToString();
|
||||
return name;
|
||||
}
|
||||
}//由于地图显示及排序的名称
|
||||
|
||||
public string EngineHoursDateText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EngineHoursDate != DateTime.MinValue)
|
||||
{
|
||||
return EngineHoursDate.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class JobSiteViewItem
|
||||
{
|
||||
public Int64 ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string[] Types { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public double Radius { get; set; }
|
||||
public string Radius_UOM { get; set; }
|
||||
public string ContractorID { get; set; }
|
||||
public string ColorString { get; set; }
|
||||
public IIColor Color { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public DateTime StartDate { get; set; }
|
||||
public DateTime EndDate { get; set; }
|
||||
public PostionItem[] Polygon { get; set; }
|
||||
public Int64 BaseOnMachineID { get; set; }
|
||||
public string Code { get; set; }
|
||||
public long[] Assets { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public string strStartDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (StartDate == DateTime.MinValue)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return StartDate.ToShortDateString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public string strEndDate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (EndDate == DateTime.MinValue)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
else
|
||||
{
|
||||
return EndDate.ToShortDateString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MachineViewItem[] Machines { get; set; }
|
||||
}
|
||||
|
||||
public class AssetGroupViewItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public long[] Assets { get; set; }
|
||||
}
|
||||
|
||||
public class CompanyLocationViewItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string CompanyID { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public string LocationName { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public string IconUrl { get; set; }
|
||||
}
|
||||
|
||||
public class MapAlertViewDefinitionItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public MapAlertLayerDefinitionItem[] Layers { get; set; }
|
||||
public List<LookupDataSourceDataItem> LookupDataSources { get; set; }
|
||||
}
|
||||
|
||||
public class LookupDataSourceDataItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
|
||||
private List<KeyValuePair<string, string>> _Items = new List<KeyValuePair<string, string>>();
|
||||
public List<KeyValuePair<string, string>> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Items;
|
||||
}
|
||||
}
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class MapAlertLayerDefinitionItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string IconColor { get; set; }
|
||||
public string AlertLayerType { get; set; }//Primary/Secondary
|
||||
public string LegendUrl { get; set; }
|
||||
public DbQueryParameterItem[] CriteriaSQLParameters { get; set; }
|
||||
public DbQueryParameterItem[] AlertSQLParameters { get; set; }
|
||||
public AlertLayerPivotViewItem[] Pivots { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class DbQueryParameterItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Caption { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DataTypes DataType { get; set; }
|
||||
public string DefaultValue { get; set; }
|
||||
public string ParameterValue { get; set; }
|
||||
public QueryParameterDisplayStyles DisplayStyle { get; set; }
|
||||
public string LookupDatasourceID { get; set; }
|
||||
public bool DisplayCaptionField { get; set; }//当参数显示为dropdown时,指示显示Key或者text
|
||||
public bool IsField { get; set; }//表明该参数名是一个数据库参数或是结果集的字段,如果是结果集的字段,则该定义必须要与lookupdatasource关联。
|
||||
public bool IsAllAllowed { get; set; }
|
||||
public bool MutipleSelect { get; set; }
|
||||
}
|
||||
|
||||
public class QueryParameterSource
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
public class LocationViewItem
|
||||
{
|
||||
public double Latitude { get; set; }
|
||||
public double Longitude { get; set; }
|
||||
public DateTime LocationTime { get; set; }
|
||||
public string LocationTimeText
|
||||
{
|
||||
get
|
||||
{
|
||||
if (LocationTime != DateTime.MinValue)
|
||||
{
|
||||
return LocationTime.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
public double Speed { get; set; } = -1;
|
||||
public string SpeedUnit { get; set; }
|
||||
public double PostedSpeed { get; set; } = -1;
|
||||
public string PostedSpeedUnit { get; set; }
|
||||
public string Street { get; set; } = string.Empty;
|
||||
public string IconURL { get; set; } = string.Empty;
|
||||
public List<KeyValuePair<string, string>> SmartWitnessVideoUrl { get; set; }
|
||||
public SpeedingBehaviors SpeedingBehavior { get; set; }
|
||||
public HarshDrivingEvents HarshDringEvent { get; set; }
|
||||
}
|
||||
|
||||
public class MachineLocationHistoryViewItem
|
||||
{
|
||||
public MachineViewItem Machine { get; set; }
|
||||
public LocationViewItem[] Locations { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class MachineTypeItem
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 供JobSite选中的Mahcine
|
||||
/// </summary>
|
||||
public class AvailableMachines
|
||||
{
|
||||
public MachineViewItem[] Assigned { get; set; }
|
||||
public MachineViewItem[] Unassigned { get; set; }
|
||||
}
|
||||
public struct PostionItem
|
||||
{
|
||||
public double Latitude;
|
||||
public double Longitude;
|
||||
|
||||
public PostionItem(double latitude, double longitude)
|
||||
{
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShapeFileItem
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
1232
IronIntelContractorBusiness/MapView/MachinesMapViewerManagement.cs
Normal file
1232
IronIntelContractorBusiness/MapView/MachinesMapViewerManagement.cs
Normal file
File diff suppressed because it is too large
Load Diff
44
IronIntelContractorBusiness/MapView/MapViewer.cs
Normal file
44
IronIntelContractorBusiness/MapView/MapViewer.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.MapView;
|
||||
using IronIntel.Services.Customers;
|
||||
|
||||
namespace IronIntel.Contractor.MapView
|
||||
{
|
||||
public static class MapViewer
|
||||
{
|
||||
public static KeyValuePair<string, string>[] GetContractors(string useriid)
|
||||
{
|
||||
Users.UserInfo userinfo = UserManagement.GetUserByIID(useriid);
|
||||
CustomerInfo[] cps = SystemParams.GetContractors();
|
||||
List<KeyValuePair<string, string>> ls = new List<KeyValuePair<string, string>>();
|
||||
if (userinfo.UserType == UserTypes.Admin || userinfo.UserType == UserTypes.SupperAdmin)
|
||||
{
|
||||
foreach (CustomerInfo cp in cps)
|
||||
{
|
||||
ls.Add(new KeyValuePair<string, string>(cp.ID, cp.Name));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] str = Acl.GetUserAvailableContractors(useriid);
|
||||
foreach (CustomerInfo cp in cps)
|
||||
{
|
||||
foreach (string s in str)
|
||||
{
|
||||
if (string.Compare(cp.ID, s, true) == 0)
|
||||
{
|
||||
ls.Add(new KeyValuePair<string, string>(cp.ID, cp.Name));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
94
IronIntelContractorBusiness/OTRConfig/HarshDrivingItem.cs
Normal file
94
IronIntelContractorBusiness/OTRConfig/HarshDrivingItem.cs
Normal file
@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.OTRConfig
|
||||
{
|
||||
public class HarshDrivingItem
|
||||
{
|
||||
public long LogID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Name2 { get; set; }
|
||||
public string VIN { get; set; }
|
||||
public int MakeID { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public int ModelID { get; set; }
|
||||
public string MakeName { get; set; }
|
||||
public string ModelName { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
|
||||
public DateTime AsofTime { get; set; }
|
||||
public string AsofTimeStr { get { return AsofTime == DateTime.MinValue ? "" : AsofTime.ToString(); } }
|
||||
public DateTime AsofTimeLocal { get; set; }
|
||||
public string AsofTimeLocalStr { get { return AsofTimeLocal == DateTime.MinValue ? "" : AsofTimeLocal.ToString(); } }
|
||||
public string EventType { get; set; }
|
||||
public string Street { get; set; }
|
||||
public string City { get; set; }
|
||||
public string State { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
public double StartingSpeed { get; set; }
|
||||
public string SpeedUnits { get; set; }
|
||||
public double Duration { get; set; }
|
||||
public string DurationUnits { get; set; }
|
||||
public double Magnitude { get; set; }
|
||||
public string MagnitudeUnits { get; set; }
|
||||
public bool Excluded { get; set; }
|
||||
|
||||
public HarshDrivingEvents HarshDringEvent { get; set; }
|
||||
public SpeedingBehaviors SpeedingBehavior { get; set; }
|
||||
public string ShowName
|
||||
{
|
||||
get
|
||||
{
|
||||
string name = Name2;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = Name;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = VIN;
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
name = AssetID.ToString();
|
||||
return name;
|
||||
}
|
||||
}
|
||||
public string EventDesc
|
||||
{
|
||||
get
|
||||
{
|
||||
string desc = EventType;
|
||||
if (string.Compare(desc, "ACCEL", true) == 0)
|
||||
desc = "Hard Acceleration";
|
||||
else if (string.Compare(desc, "DECEL", true) == 0)
|
||||
desc = "Hard Brake";
|
||||
else if (string.Compare(desc, "HARD_CORNERING_LEFT", true) == 0 || string.Compare(EventType, "HARD_CORNERING_RIGHT", true) == 0)
|
||||
desc = "Hard Turn";
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
public class HarshDrivintClient
|
||||
{
|
||||
public long LogID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public bool Excluded { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
|
||||
public enum HarshDrivingEvents
|
||||
{
|
||||
None = 0,
|
||||
HardAccelerationEvent = 1,
|
||||
HardBrakeEvent = 2,
|
||||
HardTurnEvent = 3
|
||||
}
|
||||
|
||||
public enum SpeedingBehaviors
|
||||
{
|
||||
None = 0,
|
||||
MinorSpeeding = 1,
|
||||
SevereSpeeding = 2
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.OTRConfig;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.OTRConfig
|
||||
{
|
||||
public class HarshDrivingManagement
|
||||
{
|
||||
public static HarshDrivingItem[] GetHarshDrivingEvents(string sessionid, DateTime startdate, DateTime enddate, string searchtxt, string useriid)
|
||||
{
|
||||
HarshDrivingInfo[] hds = FleetServiceClientHelper.CreateClient<OTRConfigClient>(sessionid).GetHarshDrivingEvents(SystemParams.CompanyID, startdate, enddate);
|
||||
if (hds == null || hds.Length == 0)
|
||||
return new HarshDrivingItem[0];
|
||||
|
||||
long[] availableAssetsids = null;
|
||||
var user = Users.UserManagement.GetUserByIID(useriid);
|
||||
if (user.UserType < Users.UserTypes.Admin)
|
||||
availableAssetsids = FleetServiceClientHelper.CreateClient<AssetQueryClient>(sessionid).GetAvailableAssetsForUsers(SystemParams.CompanyID, useriid);
|
||||
|
||||
List<HarshDrivingItem> list = new List<HarshDrivingItem>();
|
||||
foreach (HarshDrivingInfo hd in hds)
|
||||
{
|
||||
if (user.UserType < Users.UserTypes.Admin && !availableAssetsids.Contains(hd.AssetID))
|
||||
continue;
|
||||
HarshDrivingItem item = new HarshDrivingItem();
|
||||
Helper.CloneProperty(item, hd);
|
||||
|
||||
if (!string.IsNullOrEmpty(searchtxt))
|
||||
{
|
||||
if (Helper.Contains(item.VIN, searchtxt)
|
||||
|| Helper.Contains(item.AssetID.ToString(), searchtxt)
|
||||
|| Helper.Contains(item.Name, searchtxt)
|
||||
|| Helper.Contains(item.Name2, searchtxt)
|
||||
|| Helper.Contains(item.MakeName, searchtxt)
|
||||
|| Helper.Contains(item.TypeName, searchtxt)
|
||||
|| Helper.Contains(item.ModelName, searchtxt)
|
||||
|| Helper.Contains(item.Street, searchtxt)
|
||||
|| Helper.Contains(item.City, searchtxt)
|
||||
|| Helper.Contains(item.State, searchtxt)
|
||||
|| Helper.Contains(item.PostalCode, searchtxt))
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
list.Add(item);
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static void ExcludedHarshDrivingEvents(string sessionid, HarshDrivintClient hd, string useriid)
|
||||
{
|
||||
long[] logids = new long[] { hd.LogID };
|
||||
var client = FleetServiceClientHelper.CreateClient<OTRConfigClient>(sessionid);
|
||||
if (hd.Excluded)
|
||||
client.IncludedHarshDrivingEvents(SystemParams.CompanyID, hd.AssetID, logids, useriid, hd.Notes);
|
||||
else
|
||||
client.ExcludedHarshDrivingEvents(SystemParams.CompanyID, hd.AssetID, logids, useriid, hd.Notes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
27
IronIntelContractorBusiness/OTRConfig/SpeedingItem.cs
Normal file
27
IronIntelContractorBusiness/OTRConfig/SpeedingItem.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.OTRConfig
|
||||
{
|
||||
public class SpeedingItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public long AssetID { get; set; }
|
||||
public string AssetName { get; set; }
|
||||
public string Make { get; set; }
|
||||
public string Model { get; set; }
|
||||
public DateTime EventTime { get; set; }
|
||||
public string EventTimeStr { get { return EventTime == DateTime.MinValue ? "" : EventTime.ToString(); } }
|
||||
public string Street { get; set; }
|
||||
public string City { get; set; }
|
||||
public string State { get; set; }
|
||||
public string PostalCode { get; set; }
|
||||
public string Country { get; set; }
|
||||
public double TopSpeed { get; set; }
|
||||
public double PostedSpeedLimit { get; set; }
|
||||
public double SpeedingOverage { get; set; }
|
||||
}
|
||||
}
|
36
IronIntelContractorBusiness/Properties/AssemblyInfo.cs
Normal file
36
IronIntelContractorBusiness/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("IronIntelContractorBusiness")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Foresight Intelligence")]
|
||||
[assembly: AssemblyProduct("IronIntelContractorBusiness")]
|
||||
[assembly: AssemblyCopyright("Copyright © Foresight Intelligence 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("515fb61f-f032-4a48-8f32-93b59b9d37f8")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("2.20.429")]
|
25
IronIntelContractorBusiness/Security/CurfewInfo.cs
Normal file
25
IronIntelContractorBusiness/Security/CurfewInfo.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using Foresight.ServiceModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Security
|
||||
{
|
||||
public class CurfewInfo
|
||||
{
|
||||
public string CurfewID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Day { get; set; }
|
||||
public string StartTime { get; set; }
|
||||
public string EndTime { get; set; }
|
||||
public int IsEnabled { get; set; }
|
||||
public DateTime DateAdded { get; set; }
|
||||
public string AddBy { get; set; }
|
||||
public DateTime DateUpdated { get; set; }
|
||||
public string UpdatedBy { get; set; }
|
||||
public string TimePeriod { get; set; }
|
||||
public StringKeyValue[] TimePeriods { get; set; }
|
||||
}
|
||||
}
|
281
IronIntelContractorBusiness/Security/CurfewManagement.cs
Normal file
281
IronIntelContractorBusiness/Security/CurfewManagement.cs
Normal file
@ -0,0 +1,281 @@
|
||||
using Foresight.Data;
|
||||
using Foresight.ServiceModel;
|
||||
using IronIntel.Contractor.Machines;
|
||||
using IronIntel.Contractor.Maintenance;
|
||||
using IronIntel.Contractor.MapView;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Security
|
||||
{
|
||||
public class CurfewManagement
|
||||
{
|
||||
public static CurfewInfo[] GetCurfews(string sessionid, string searchtext, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = "select CURFEWID,TITLE,DAY,STARTTIME,ENDTIME,ISENABLED,DATEADDED_UTC,ADDBY,DATEUPDATED_UTC,UPDATEDBY,TIMEPERIOD from CURFEW where ISENABLED=1";
|
||||
|
||||
List<CurfewInfo> list = new List<CurfewInfo>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
UserInfo[] users = UserManagement.GetUsers();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
CurfewInfo ci = ConvertToCurfewInfo(dr);
|
||||
if (string.IsNullOrWhiteSpace(searchtext)
|
||||
|| Helper.Contains(ci.Title, searchtext))
|
||||
list.Add(ci);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static CurfewInfo GetCurfewInfo(string curfewid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = "select CURFEWID,TITLE,DAY,STARTTIME,ENDTIME,ISENABLED,DATEADDED_UTC,ADDBY,DATEUPDATED_UTC,UPDATEDBY,TIMEPERIOD from CURFEW where ISENABLED=1 and CURFEWID={0}";
|
||||
|
||||
List<CurfewInfo> list = new List<CurfewInfo>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, curfewid);
|
||||
CurfewInfo ci = new CurfewInfo();
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
ci = ConvertToCurfewInfo(dt.Rows[0]);
|
||||
}
|
||||
return ci;
|
||||
}
|
||||
|
||||
|
||||
public static void SaveCurfew(CurfewInfo ci, string useriid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from CURFEW where CURFEWID={0}) update CURFEW set TITLE={1},DAY={2},STARTTIME={3},ENDTIME={4},DATEUPDATED_UTC=GETUTCDATE(),UPDATEDBY={5},TIMEPERIOD={6} where CURFEWID={0}
|
||||
else insert CURFEW(CURFEWID,TITLE,DAY,STARTTIME,ENDTIME,ISENABLED,DATEADDED_UTC,ADDBY,DATEUPDATED_UTC,UPDATEDBY,TIMEPERIOD) values({0},{1},{2},{3},{4},1,GETUTCDATE(),{5},GETUTCDATE(),{5},{6})";
|
||||
|
||||
const string SQL_C = "select COUNT(1) from CURFEW where CURFEWID!={0} and TITLE={1} and ISENABLED=1";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL_C, ci.CurfewID, ci.Title);
|
||||
if (Convert.ToInt32(obj) > 0)
|
||||
{
|
||||
throw new Exception("The curfew title must be unique.");
|
||||
}
|
||||
|
||||
string timeperiodStr = "";
|
||||
if (ci.TimePeriods == null || ci.TimePeriods.Length <= 0)
|
||||
throw new Exception("Period cannot be empty.");
|
||||
|
||||
foreach (StringKeyValue item in ci.TimePeriods)
|
||||
{
|
||||
int st = Convert.ToInt32(item.Tag1 + item.Tag2);
|
||||
int et = Convert.ToInt32(item.Tag3 + item.Tag4);
|
||||
if (st >= et)
|
||||
throw new Exception("End Time must be later than Start Time.");
|
||||
|
||||
string str = item.Tag1 + ":" + item.Tag2 + "-" + item.Tag3 + ":" + item.Tag4;
|
||||
if (string.IsNullOrWhiteSpace(timeperiodStr))
|
||||
timeperiodStr = str;
|
||||
else
|
||||
timeperiodStr = timeperiodStr + "," + str;
|
||||
}
|
||||
|
||||
|
||||
db.ExecSQL(SQL, ci.CurfewID, ci.Title, ci.Day, ci.StartTime, ci.EndTime, useriid, timeperiodStr);
|
||||
|
||||
}
|
||||
|
||||
public static void DeleteCurfew(string curfewid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"update CURFEW set ISENABLED=0 where CURFEWID={0}";
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, curfewid);
|
||||
}
|
||||
|
||||
public static MaintenanceMachineInfo[] GetCurfewMachinesByID(string curfewid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"select a.RELATEDID as MACHINEID,b.MACHINENAME,b.MACHINENAME2,b.VIN,b.MAKEID,b.MODELID,b.TYPEID,b.HIDE,ISNULL(b.ENGINEHOURS,0) as ENGINEHOURS,
|
||||
ISNULL(b.ODOMETER,0) as ODOMETER,ISNULL(b.ODOMETERUOM,'Mile') AS ODOMETERUOM from RELATIONSHIP a,MACHINES b
|
||||
where a.RELATEDID=b.MACHINEID and a.RELATIONSHIPTYPEID='CurfewToMachine' and a.REMOVED<>1 and a.PRIMARYID={0}";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, curfewid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new MaintenanceMachineInfo[0];
|
||||
}
|
||||
MachineManagement.RefreshBaseData();
|
||||
MachineMake[] makes = MachineManagement.GetMachineMakes();
|
||||
MachineModel[] models = MachineManagement.GetMachineModels();
|
||||
MachineType[] types = MachineManagement.GetMachineTypes();
|
||||
List<MaintenanceMachineInfo> ls = new List<MaintenanceMachineInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
MaintenanceMachineInfo mi = MaintenanceManagement.ConvertToMaintenanceMachineInfo(dr, makes, models, types);
|
||||
ls.Add(mi);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public static void SaveCurfewMachines(string curfewid, string contractorid, string[] machineids, FISqlConnection db)
|
||||
{
|
||||
const string SQL_R = "update RELATIONSHIP set REMOVEDON=GETUTCDATE(),REMOVED=1 where RELATIONSHIPTYPEID='CurfewToMachine' and REMOVED<>1 and PRIMARYID={0}";
|
||||
const string SQL = @"if exists(select 1 from RELATIONSHIP where RELATIONSHIPTYPEID='CurfewToMachine' and PRIMARYID={0} and RELATEDID={1}) update RELATIONSHIP
|
||||
set REMOVEDON=null,REMOVED=0 where RELATIONSHIPTYPEID='CurfewToMachine' and PRIMARYID={0} and RELATEDID={1} else insert into RELATIONSHIP
|
||||
(RELATIONSHIPID,RELATIONSHIPTYPEID,CONTRACTORID,PRIMARYID,RELATEDID,ADDEDON) values({3},'CurfewToMachine',{2},{0},{1},GETUTCDATE())";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_R, curfewid);
|
||||
|
||||
foreach (var mid in machineids)
|
||||
{
|
||||
db.ExecSQL(SQL, curfewid, mid, contractorid, Guid.NewGuid().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private static CurfewInfo ConvertToCurfewInfo(DataRow dr)
|
||||
{
|
||||
CurfewInfo ci = new CurfewInfo();
|
||||
ci.CurfewID = FIDbAccess.GetFieldString(dr["CURFEWID"], string.Empty);
|
||||
ci.Title = FIDbAccess.GetFieldString(dr["TITLE"], string.Empty);
|
||||
ci.Day = FIDbAccess.GetFieldString(dr["DAY"], string.Empty);
|
||||
ci.StartTime = FIDbAccess.GetFieldString(dr["STARTTIME"], string.Empty);
|
||||
ci.EndTime = FIDbAccess.GetFieldString(dr["ENDTIME"], string.Empty);
|
||||
ci.IsEnabled = FIDbAccess.GetFieldInt(dr["ISENABLED"], 0);
|
||||
ci.DateAdded = FIDbAccess.GetFieldDateTime(dr["DATEADDED_UTC"], DateTime.MinValue);
|
||||
ci.DateAdded = ci.DateAdded.AddHours(SystemParams.GetHoursOffset());
|
||||
ci.AddBy = FIDbAccess.GetFieldString(dr["ADDBY"], string.Empty);
|
||||
ci.DateUpdated = FIDbAccess.GetFieldDateTime(dr["DATEUPDATED_UTC"], DateTime.MinValue);
|
||||
ci.DateUpdated = ci.DateUpdated.AddHours(SystemParams.GetHoursOffset());
|
||||
ci.UpdatedBy = FIDbAccess.GetFieldString(dr["UPDATEDBY"], string.Empty);
|
||||
ci.TimePeriod = FIDbAccess.GetFieldString(dr["TIMEPERIOD"], string.Empty);
|
||||
if (!string.IsNullOrWhiteSpace(ci.TimePeriod))
|
||||
{
|
||||
List<StringKeyValue> list = new List<StringKeyValue>();
|
||||
string[] periods = ci.TimePeriod.Split(',');
|
||||
foreach (string pd in periods)
|
||||
{
|
||||
StringKeyValue kv = new StringKeyValue();
|
||||
string[] time = pd.Split('-');
|
||||
string[] starttime = time[0].Split(':');
|
||||
string[] endtime = time[1].Split(':');
|
||||
kv.Tag1 = starttime[0];
|
||||
kv.Tag2 = starttime[1];
|
||||
kv.Tag3 = endtime[0];
|
||||
kv.Tag4 = endtime[1];
|
||||
list.Add(kv);
|
||||
}
|
||||
ci.TimePeriods = list.ToArray();
|
||||
}
|
||||
else
|
||||
ci.TimePeriods = new StringKeyValue[0];
|
||||
return ci;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static JobSiteViewItem[] GetCurfewJobsitesByID(string curfewid, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = @"select a.RELATEDID as JOBSITEID,JOBSITENAME,LATITUDE,LONGITUDE ,RADIUS,RADUIS_UOM,b.CONTRACTORID,COLOR,NOTES,STARTDATE,ENDDATE,POLYGON from RELATIONSHIP a,JOBSITES b
|
||||
where a.RELATIONSHIPTYPEID='CurfewToJobsite' and a.REMOVED<>1 and a.RELATEDID=b.JOBSITEID and a.PRIMARYID={0}";
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL, curfewid);
|
||||
if (tb.Rows.Count == 0)
|
||||
{
|
||||
return new JobSiteViewItem[0];
|
||||
}
|
||||
List<JobSiteViewItem> ls = new List<JobSiteViewItem>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
JobSiteViewItem js = ConvertToJobSiteViewItem(dr);
|
||||
ls.Add(js);
|
||||
}
|
||||
return ls.ToArray();
|
||||
|
||||
}
|
||||
|
||||
public static void SaveCurfewJobsites(string curfewid, string contractorid, string[] jobsiteids, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL_R = "update RELATIONSHIP set REMOVEDON=GETUTCDATE(),REMOVED=1 where RELATIONSHIPTYPEID='CurfewToJobsite' and REMOVED<>1 and PRIMARYID={0}";
|
||||
const string SQL = @"if exists(select 1 from RELATIONSHIP where RELATIONSHIPTYPEID='CurfewToJobsite' and PRIMARYID={0} and RELATEDID={1}) update RELATIONSHIP
|
||||
set REMOVEDON=null,REMOVED=0 where RELATIONSHIPTYPEID='CurfewToJobsite' and PRIMARYID={0} and RELATEDID={1} else insert into RELATIONSHIP
|
||||
(RELATIONSHIPID,RELATIONSHIPTYPEID,CONTRACTORID,PRIMARYID,RELATEDID,ADDEDON) values({3},'CurfewToJobsite',{2},{0},{1},GETUTCDATE())";
|
||||
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_R, curfewid);
|
||||
|
||||
foreach (var mid in jobsiteids)
|
||||
{
|
||||
db.ExecSQL(SQL, curfewid, mid, contractorid, Guid.NewGuid().ToString());
|
||||
}
|
||||
}
|
||||
private static JobSiteViewItem ConvertToJobSiteViewItem(DataRow dr)
|
||||
{
|
||||
JobSiteViewItem js = new JobSiteViewItem();
|
||||
long JobSiteId = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.ID = FIDbAccess.GetFieldInt(dr["JOBSITEID"], 0);
|
||||
js.Name = FIDbAccess.GetFieldString(dr["JOBSITENAME"], string.Empty);
|
||||
js.Latitude = FIDbAccess.GetFieldDouble(dr["LATITUDE"], 0);
|
||||
js.Longitude = FIDbAccess.GetFieldDouble(dr["LONGITUDE"], 0);
|
||||
js.Radius = FIDbAccess.GetFieldDouble(dr["RADIUS"], 0);
|
||||
js.Radius_UOM = FIDbAccess.GetFieldString(dr["RADUIS_UOM"], string.Empty);
|
||||
if (string.IsNullOrWhiteSpace(js.Radius_UOM))
|
||||
js.Radius_UOM = "Mile";
|
||||
js.ContractorID = FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty);
|
||||
//js.ColorString = FIDbAccess.GetFieldString(dr["COLOR"], string.Empty);
|
||||
//System.Drawing.Color color = System.Drawing.Color.Orange;
|
||||
//try
|
||||
//{
|
||||
// color = System.Drawing.ColorTranslator.FromHtml(js.ColorString);
|
||||
//}
|
||||
//catch
|
||||
//{
|
||||
//}
|
||||
//js.Color = new IIColor() { Alpha = color.A, Red = color.R, Green = color.G, Blue = color.B };
|
||||
|
||||
js.Notes = FIDbAccess.GetFieldString(dr["NOTES"], string.Empty);
|
||||
js.StartDate = FIDbAccess.GetFieldDateTime(dr["STARTDATE"], DateTime.MinValue);
|
||||
js.EndDate = FIDbAccess.GetFieldDateTime(dr["ENDDATE"], DateTime.MinValue);
|
||||
return js;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取机器Curfew和机器的对应关系
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Dictionary<int, List<string>> GetCurfewMachines(FISqlConnection db)
|
||||
{
|
||||
const string SQL_C = "select PRIMARYID,RELATEDID from RELATIONSHIP where RELATIONSHIPTYPEID='CurfewToMachine' and REMOVED<>1";
|
||||
|
||||
Dictionary<int, List<string>> result = new Dictionary<int, List<string>>();
|
||||
if (db == null)
|
||||
db = SystemParams.GetDbInstance();
|
||||
DataTable tb = db.GetDataTableBySQL(SQL_C);
|
||||
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
int machineid = FIDbAccess.GetFieldInt(dr["RELATEDID"], 0);
|
||||
string curfewid = FIDbAccess.GetFieldString(dr["PRIMARYID"], "");
|
||||
if (!result.ContainsKey(machineid))
|
||||
result[machineid] = new List<string>();
|
||||
result[machineid].Add(curfewid);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Security
|
||||
{
|
||||
public class CurfewMovementToleranceInfo
|
||||
{
|
||||
public decimal DefaultTolerance { get; set; }
|
||||
public List<JobSiteCurfewMovementToleranceInfo> JobSites { get; set; }
|
||||
}
|
||||
|
||||
public class JobSiteCurfewMovementToleranceInfo
|
||||
{
|
||||
public long JobSiteId { get; set; }
|
||||
public string JobSiteName { get; set; }
|
||||
public decimal Tolerance { get; set; }
|
||||
}
|
||||
}
|
23
IronIntelContractorBusiness/Security/JobsiteLimitInfo.cs
Normal file
23
IronIntelContractorBusiness/Security/JobsiteLimitInfo.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Security
|
||||
{
|
||||
public class JobsiteLimitInfo
|
||||
{
|
||||
public long ID { get; set; }
|
||||
public long JobSiteID { get; set; }
|
||||
public string JobSiteName { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public string StartTime { get; set; }
|
||||
public string EndTime { get; set; }
|
||||
public int MinTrucks { get; set; }
|
||||
public int MaxTrucks { get; set; }
|
||||
public string AssetTypes { get; set; }
|
||||
public string AssetTypeNames { get; set; }
|
||||
public string Notes { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using Foresight.Data;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Security
|
||||
{
|
||||
public class JobsiteLimitManagement
|
||||
{
|
||||
public static UserInfo[] GetSubscribeContacts(Int64 jlid)
|
||||
{
|
||||
const string SQL = "select u.USERIID,u.USERNAME,u.CONTACTTYPE from JOBSITELIMITSUBSCRIBE js left join USERS u on js.CONTACTID=u.USERIID where js.JOBSITELIMITID={0} and u.USERIID is not null";
|
||||
|
||||
List<UserInfo> list = new List<UserInfo>();
|
||||
DataTable dt = SystemParams.GetDbInstance().GetDataTableBySQL(SQL, jlid);
|
||||
if (dt.Rows.Count > 0)
|
||||
{
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
UserInfo ci = new UserInfo();
|
||||
ci.IID = FIDbAccess.GetFieldString(dr["USERIID"], string.Empty);
|
||||
ci.DisplayName = FIDbAccess.GetFieldString(dr["USERNAME"], string.Empty);
|
||||
ci.ContactType = (ContactTypes)FIDbAccess.GetFieldInt(dr["CONTACTTYPE"], 100);
|
||||
list.Add(ci);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
public static void SaveSubscribeContacts(string jlid, string[] contactids)
|
||||
{
|
||||
const string SQL_D = "delete from JOBSITELIMITSUBSCRIBE where JOBSITELIMITID={0}";
|
||||
const string SQL = @"insert into JOBSITELIMITSUBSCRIBE(JOBSITELIMITID,CONTACTID) values({0},{1})";
|
||||
|
||||
FISqlConnection db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL_D, jlid);
|
||||
|
||||
foreach (var cid in contactids)
|
||||
{
|
||||
db.ExecSQL(SQL, jlid, cid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
127
IronIntelContractorBusiness/Shape/MapPoint.cs
Normal file
127
IronIntelContractorBusiness/Shape/MapPoint.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace IronIntel.Contractor.Shape
|
||||
{
|
||||
public sealed class MapPoint
|
||||
{
|
||||
public double Longitude = 0;
|
||||
public double Latitude = 0;
|
||||
}
|
||||
|
||||
public sealed class MapPoints
|
||||
{
|
||||
private List<MapPoint> _Points = new List<MapPoint>();
|
||||
public List<MapPoint> Points
|
||||
{
|
||||
get { return _Points; }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class Polyline
|
||||
{
|
||||
private List<MapPoints> _Parts = new List<MapPoints>();
|
||||
|
||||
public List<MapPoints> Parts
|
||||
{
|
||||
get { return _Parts; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示extent的左上角
|
||||
/// </summary>
|
||||
public MapPoint TopLeft = null;
|
||||
|
||||
/// <summary>
|
||||
/// 表示extent的右下角
|
||||
/// </summary>
|
||||
public MapPoint BottomRight = null;
|
||||
}
|
||||
|
||||
public sealed class Polygon
|
||||
{
|
||||
private List<MapPoints> _Rings = new List<MapPoints>();
|
||||
|
||||
public List<MapPoints> Rings
|
||||
{
|
||||
get { return _Rings; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示extent的左上角
|
||||
/// </summary>
|
||||
public MapPoint TopLeft = null;
|
||||
|
||||
/// <summary>
|
||||
/// 表示extent的右下角
|
||||
/// </summary>
|
||||
public MapPoint BottomRight = null;
|
||||
}
|
||||
|
||||
public sealed class Shape
|
||||
{
|
||||
private List<MapPoints> _Points = new List<MapPoints>();
|
||||
private List<Polyline> _Polylines = new List<Polyline>();
|
||||
private List<Polygon> _Polygones = new List<Polygon>();
|
||||
|
||||
public List<MapPoints> Points
|
||||
{
|
||||
get { return _Points; }
|
||||
}
|
||||
|
||||
public List<Polyline> Polylines
|
||||
{
|
||||
get { return _Polylines; }
|
||||
}
|
||||
|
||||
public List<Polygon> Polygons
|
||||
{
|
||||
get { return _Polygones; }
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SimpleShape
|
||||
{
|
||||
private List<MapPoint> _Points = new List<MapPoint>();
|
||||
private List<MapPoints> _Polylines = new List<MapPoints>();
|
||||
private List<MapPoints> _Polygones = new List<MapPoints>();
|
||||
|
||||
public List<MapPoint> Points
|
||||
{
|
||||
get { return _Points; }
|
||||
}
|
||||
|
||||
public List<MapPoints> Polylines
|
||||
{
|
||||
get { return _Polylines; }
|
||||
}
|
||||
|
||||
public List<MapPoints> Polygons
|
||||
{
|
||||
get { return _Polygones; }
|
||||
}
|
||||
|
||||
public void FromShapeObj(Shape s)
|
||||
{
|
||||
if (s != null)
|
||||
{
|
||||
foreach (var p in s.Points)
|
||||
{
|
||||
Points.AddRange(p.Points);
|
||||
}
|
||||
foreach (var p in s.Polylines)
|
||||
{
|
||||
Polylines.AddRange(p.Parts);
|
||||
}
|
||||
foreach (var p in s.Polygons)
|
||||
{
|
||||
Polygons.AddRange(p.Rings);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
324
IronIntelContractorBusiness/Shape/ShapeFileParser.cs
Normal file
324
IronIntelContractorBusiness/Shape/ShapeFileParser.cs
Normal file
@ -0,0 +1,324 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace IronIntel.Contractor.Shape
|
||||
{
|
||||
public static class ShapeFileParser
|
||||
{
|
||||
private static void ParsePoints(BinaryReader binaryReader, MapPoints points)
|
||||
{
|
||||
while (binaryReader.PeekChar() != -1)
|
||||
{
|
||||
binaryReader.ReadUInt32();
|
||||
binaryReader.ReadInt32();
|
||||
int shapeType = binaryReader.ReadInt32();
|
||||
|
||||
MapPoint p = new MapPoint();
|
||||
p.Longitude = binaryReader.ReadDouble();
|
||||
p.Latitude = binaryReader.ReadDouble();
|
||||
points.Points.Add(p);
|
||||
|
||||
if (shapeType == 11)//PointZ
|
||||
{
|
||||
binaryReader.ReadDouble();//Z
|
||||
binaryReader.ReadDouble();//M
|
||||
}
|
||||
else if (shapeType == 21)//PointM
|
||||
{
|
||||
binaryReader.ReadDouble();//M
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParsePolylines(BinaryReader binaryReader, List<Polyline> polylines)
|
||||
{
|
||||
while (binaryReader.PeekChar() != -1)
|
||||
{
|
||||
Polyline polyling = new Polyline();
|
||||
polylines.Add(polyling);
|
||||
|
||||
binaryReader.ReadUInt32();
|
||||
binaryReader.ReadInt32();
|
||||
int shapeType = binaryReader.ReadInt32();
|
||||
|
||||
polyling.TopLeft = new MapPoint();
|
||||
polyling.BottomRight = new MapPoint();
|
||||
polyling.TopLeft.Longitude = binaryReader.ReadDouble();
|
||||
polyling.TopLeft.Latitude = binaryReader.ReadDouble();
|
||||
polyling.BottomRight.Longitude = binaryReader.ReadDouble();
|
||||
polyling.BottomRight.Latitude = binaryReader.ReadDouble();
|
||||
|
||||
List<int> parts = new List<int>();//记录每条线的起始点索引
|
||||
int partCount = binaryReader.ReadInt32();
|
||||
int pointCount = binaryReader.ReadInt32();
|
||||
for (int i = 0; i < partCount; i++)
|
||||
{
|
||||
int part = new int();
|
||||
part = binaryReader.ReadInt32();
|
||||
parts.Add(part);
|
||||
}
|
||||
|
||||
MapPoints ring = null;
|
||||
int partIndex = 0;
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
if (partIndex < parts.Count && parts[partIndex] == j)
|
||||
{
|
||||
ring = new MapPoints();
|
||||
polyling.Parts.Add(ring);
|
||||
}
|
||||
MapPoint mp = new MapPoint();
|
||||
mp.Longitude = binaryReader.ReadDouble();
|
||||
mp.Latitude = binaryReader.ReadDouble();
|
||||
ring.Points.Add(mp);
|
||||
}
|
||||
|
||||
if (shapeType == 13)//PolylineZ
|
||||
{
|
||||
binaryReader.ReadDouble();//Zmin
|
||||
binaryReader.ReadDouble();//Zmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Zarray
|
||||
}
|
||||
|
||||
binaryReader.ReadDouble();//Mmin
|
||||
binaryReader.ReadDouble();//Mmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Marray
|
||||
}
|
||||
}
|
||||
else if (shapeType == 23)//PolylineM
|
||||
{
|
||||
binaryReader.ReadDouble();//Mmin
|
||||
binaryReader.ReadDouble();//Mmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Marray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void ParsePolygons(BinaryReader binaryReader, List<Polygon> ls)
|
||||
{
|
||||
while (binaryReader.PeekChar() != -1)
|
||||
{
|
||||
binaryReader.ReadUInt32();
|
||||
binaryReader.ReadInt32();
|
||||
int shapeType = binaryReader.ReadInt32();
|
||||
|
||||
Polygon p = new Polygon();
|
||||
p.TopLeft = new MapPoint();
|
||||
p.BottomRight = new MapPoint();
|
||||
p.TopLeft.Longitude = binaryReader.ReadDouble();
|
||||
p.TopLeft.Latitude = binaryReader.ReadDouble();
|
||||
p.BottomRight.Longitude = binaryReader.ReadDouble();
|
||||
p.BottomRight.Latitude = binaryReader.ReadDouble();
|
||||
|
||||
List<int> parts = new List<int>();//记录每个区域的起始点索引
|
||||
int partCount = binaryReader.ReadInt32();
|
||||
int pointCount = binaryReader.ReadInt32();
|
||||
for (int j = 0; j < partCount; j++)
|
||||
{
|
||||
int part = binaryReader.ReadInt32();
|
||||
parts.Add(part);
|
||||
}
|
||||
|
||||
MapPoints ring = null;
|
||||
int partIndex = 0;
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
if (partIndex < parts.Count && parts[partIndex] == j)
|
||||
{
|
||||
ring = new MapPoints();
|
||||
p.Rings.Add(ring);
|
||||
partIndex++;
|
||||
}
|
||||
MapPoint mp = new MapPoint();
|
||||
mp.Longitude = binaryReader.ReadDouble();
|
||||
mp.Latitude = binaryReader.ReadDouble();
|
||||
ring.Points.Add(mp);
|
||||
}
|
||||
|
||||
ls.Add(p);
|
||||
|
||||
if (shapeType == 15)//PolygonZ
|
||||
{
|
||||
binaryReader.ReadDouble();//Zmin
|
||||
binaryReader.ReadDouble();//Zmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Zarray
|
||||
}
|
||||
|
||||
binaryReader.ReadDouble();//Mmin
|
||||
binaryReader.ReadDouble();//Mmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Marray
|
||||
}
|
||||
}
|
||||
else if (shapeType == 25)//PolygonM
|
||||
{
|
||||
binaryReader.ReadDouble();//Mmin
|
||||
binaryReader.ReadDouble();//Mmax
|
||||
for (int j = 0; j < pointCount; j++)
|
||||
{
|
||||
binaryReader.ReadDouble();//Marray
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析.shp文件
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
public static void ParseFromShapeFile(string fileName, Shape shape)
|
||||
{
|
||||
using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
ParseFromShapeFile(fileStream, shape);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析.shp文件
|
||||
/// </summary>
|
||||
/// <param name="buffer">.shp文件数据</param>
|
||||
/// <param name="shape"></param>
|
||||
public static void ParseFromShapeFile(byte[] buffer, Shape shape)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream(buffer, false))
|
||||
{
|
||||
ParseFromShapeFile(ms, shape);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析.shp文件
|
||||
/// </summary>
|
||||
/// <param name="fs">装载.shp文件数据的流</param>
|
||||
public static void ParseFromShapeFile(Stream fs, Shape shape)
|
||||
{
|
||||
fs.Seek(0, SeekOrigin.Begin);
|
||||
using (BinaryReader binaryReader = new BinaryReader(fs))
|
||||
{
|
||||
binaryReader.ReadBytes(24);
|
||||
|
||||
int FileLength = binaryReader.ReadInt32();//<0代表数据长度未知
|
||||
int FileBanben = binaryReader.ReadInt32();
|
||||
int ShapeType = binaryReader.ReadInt32();
|
||||
|
||||
double xmin = binaryReader.ReadDouble();
|
||||
double ymax = -1 * binaryReader.ReadDouble();
|
||||
double xmax = binaryReader.ReadDouble();
|
||||
double ymin = -1 * binaryReader.ReadDouble();
|
||||
double width = xmax - xmin;
|
||||
double height = ymax - ymin;
|
||||
|
||||
binaryReader.ReadBytes(32);
|
||||
|
||||
switch (ShapeType)
|
||||
{
|
||||
case 1://Point
|
||||
case 11://PointZ
|
||||
case 21://PointM
|
||||
MapPoints points = new MapPoints();
|
||||
shape.Points.Add(points);
|
||||
ParsePoints(binaryReader, points);
|
||||
break;
|
||||
case 3://PolyLine
|
||||
case 13://PolyLineZ
|
||||
case 23://PolyLineM
|
||||
ParsePolylines(binaryReader, shape.Polylines);
|
||||
break;
|
||||
case 5://Polygon
|
||||
case 15://PolygonZ
|
||||
case 25://PolygonM
|
||||
ParsePolygons(binaryReader, shape.Polygons);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从zip文件当中解析.shp
|
||||
/// </summary>
|
||||
/// <param name="stream">装载.zip文件内容的流</param>
|
||||
/// <param name="shape"></param>
|
||||
public static void ParseFromZipFile(Stream stream, Shape shape)
|
||||
{
|
||||
const string EXT = ".shp";
|
||||
//using (ZipInputStream s = new ZipInputStream(stream))
|
||||
//{
|
||||
// ZipEntry zipentry = s.GetNextEntry();
|
||||
// while (zipentry != null)
|
||||
// {
|
||||
// if (zipentry.IsDirectory)
|
||||
// {
|
||||
// zipentry = s.GetNextEntry();
|
||||
// continue;
|
||||
// }
|
||||
// string ext = Path.GetExtension(zipentry.FileName);
|
||||
// if (string.Compare(ext, EXT, true) == 0)
|
||||
// {
|
||||
// Stream shpStream = new MemoryStream();
|
||||
// int size = 0;
|
||||
// byte[] data = new byte[2048];
|
||||
// while (true)
|
||||
// {
|
||||
// size = s.Read(data, 0, data.Length);
|
||||
// if (size > 0)
|
||||
// {
|
||||
// shpStream.Write(data, 0, size);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// ParseFromShapeFile(shpStream, shape);
|
||||
// }
|
||||
// zipentry = s.GetNextEntry();
|
||||
// }//while
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从.zip文件当中解析.shp
|
||||
/// </summary>
|
||||
/// <param name="buffer">.zip文件数据</param>
|
||||
/// <param name="shape"></param>
|
||||
public static void ParseFromZipFile(byte[] buffer, Shape shape)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream(buffer, false))
|
||||
{
|
||||
ParseFromZipFile(ms, shape);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从.zip文件当中解析.shp
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <param name="shape"></param>
|
||||
public static void ParseFromZipFile(string filename, Shape shape)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
ParseFromZipFile(fs, shape);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
841
IronIntelContractorBusiness/SystemParams.cs
Normal file
841
IronIntelContractorBusiness/SystemParams.cs
Normal file
@ -0,0 +1,841 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Net;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Data.SqlClient;
|
||||
using Foresight.Security;
|
||||
using Foresight.Data;
|
||||
using IronIntel.Services;
|
||||
using IronIntel.Services.Business.Admin;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services.Contractor.Machine;
|
||||
using IronIntel.Services.Users;
|
||||
using Foresight.Fleet.Services.Asset;
|
||||
using Foresight.Fleet.Services.Attachment;
|
||||
using Foresight.ServiceModel;
|
||||
using Foresight.Fleet.Services.FITracker;
|
||||
using Foresight.Fleet.Services.AssetHealth;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using Foresight.Fleet.Services.Device;
|
||||
using Foresight.Fleet.Services.JobSite;
|
||||
using Foresight.Fleet.Services;
|
||||
using Foresight.Fleet.Services.OTRConfig;
|
||||
using Foresight.Fleet.Services.Customer;
|
||||
using Foresight.Fleet.Services.MapView;
|
||||
using Foresight.Fleet.Services.SystemOption;
|
||||
using Foresight.Fleet.Services.Inspection;
|
||||
|
||||
namespace IronIntel.Contractor
|
||||
{
|
||||
public static class SystemParams
|
||||
{
|
||||
private static Dictionary<string, string> _CompanyDbString = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private static ConcurrentDictionary<string, string> _Params = new ConcurrentDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private static readonly byte[] KEY = new byte[] { 134, 109, 104, 92, 86, 241, 196, 160, 203, 10, 175, 253, 14, 48, 138, 42, 131, 123, 238, 226, 146, 45, 125, 185, 217, 119, 183, 64, 16, 113, 37, 62 };
|
||||
private static readonly byte[] IV = new byte[] { 178, 198, 121, 147, 158, 41, 192, 222, 198, 61, 142, 50, 24, 111, 158, 169 };
|
||||
|
||||
private static string _ContractorVersion = "";
|
||||
private static string _FICVersion = "";
|
||||
|
||||
private static string EncryptString(string s)
|
||||
{
|
||||
byte[] buf = Encoding.UTF8.GetBytes(s);
|
||||
byte[] tmp = SecurityHelper.AesEncrypt(buf, KEY, IV);
|
||||
return Convert.ToBase64String(tmp);
|
||||
}
|
||||
|
||||
private static string GetAssemblyFileVersion()
|
||||
{
|
||||
try
|
||||
{
|
||||
string filename = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
|
||||
string fn = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\" + filename);
|
||||
FileVersionInfo fv = FileVersionInfo.GetVersionInfo(fn);
|
||||
return fv.FileVersion.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateDbObjects()
|
||||
{
|
||||
try
|
||||
{
|
||||
FI.FIC.Database.FIC.FICDbInitializer ficdb = new FI.FIC.Database.FIC.FICDbInitializer(FICDbConnectionString);
|
||||
ficdb.RunIronIntel();
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
public static string AppVersion
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetVersion();
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetCompanyDbString(string companyid)
|
||||
{
|
||||
string rst = null;
|
||||
if (_CompanyDbString.TryGetValue(companyid, out rst))
|
||||
{
|
||||
return rst;
|
||||
}
|
||||
try
|
||||
{
|
||||
CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
|
||||
string dbstr = cust.MasterDataDbString;
|
||||
if (!string.IsNullOrWhiteSpace(dbstr))
|
||||
{
|
||||
_CompanyDbString[companyid] = dbstr;
|
||||
return dbstr;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
internal static FISqlConnection GetCompanyDbConnection(string companyid)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(companyid) || string.Compare(companyid, CompanyID, true) == 0)
|
||||
{
|
||||
return GetDbInstance();
|
||||
}
|
||||
string s = GetCompanyDbString(companyid);
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return new FISqlConnection(s);
|
||||
}
|
||||
}
|
||||
|
||||
private static string DecryptString(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
byte[] tmp = Convert.FromBase64String(s);
|
||||
byte[] buf = SecurityHelper.AesDecrypt(tmp, KEY, IV);
|
||||
return Encoding.UTF8.GetString(buf);
|
||||
}
|
||||
|
||||
private static string _HostName = null;
|
||||
|
||||
public static string HostName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_HostName == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_HostName = Dns.GetHostName();
|
||||
}
|
||||
catch
|
||||
{
|
||||
_HostName = string.Empty;
|
||||
}
|
||||
}
|
||||
return _HostName;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _DataDbConnectionString = null;
|
||||
|
||||
/// <summary>
|
||||
/// 获取主数据库连接字符串
|
||||
/// </summary>
|
||||
/// <returns>获取主数据库连接字符串</returns>
|
||||
public static string DataDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DataDbConnectionString == null)
|
||||
{
|
||||
SqlConnectionStringBuilder sb = new SqlConnectionStringBuilder(ConfigurationManager.AppSettings["DbConntionString"]);
|
||||
try
|
||||
{
|
||||
sb.Password = DecryptString(sb.Password);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
_DataDbConnectionString = sb.ToString();
|
||||
}
|
||||
return _DataDbConnectionString;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _ficdbstr = null;
|
||||
|
||||
public static string FICDbConnectionString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ficdbstr == null)
|
||||
{
|
||||
string db = GetStringParam("FICSysDBName");
|
||||
if (string.IsNullOrWhiteSpace(db))
|
||||
{
|
||||
_ficdbstr = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
SqlConnectionStringBuilder sc = new SqlConnectionStringBuilder(DataDbConnectionString);
|
||||
sc.InitialCatalog = db;
|
||||
_ficdbstr = sc.ToString();
|
||||
}
|
||||
}
|
||||
return _ficdbstr;
|
||||
}
|
||||
}
|
||||
|
||||
public static FISqlConnection GetDbInstance()
|
||||
{
|
||||
return new FISqlConnection(DataDbConnectionString);
|
||||
}
|
||||
|
||||
public static FISqlConnection FICDBInstance
|
||||
{
|
||||
get
|
||||
{
|
||||
return new FISqlConnection(FICDbConnectionString);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetStringParam(string paramname, string value)
|
||||
{
|
||||
const string SQL = "if exists(select 1 from SYSPARAMS where PARAMNAME={0}) update SYSPARAMS set PARAMVALUE={1} where PARAMNAME={0}"
|
||||
+ " else insert into SYSPARAMS(PARAMNAME,PARAMVALUE) values({0},{1})";
|
||||
FIDbAccess db = GetDbInstance();
|
||||
db.ExecSQL(SQL, paramname, value);
|
||||
_Params[paramname] = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据参数名称获取参数值
|
||||
/// </summary>
|
||||
/// <param name="paramname">参数名称</param>
|
||||
/// <returns>参数值</returns>
|
||||
public static string GetStringParam(string paramname, bool useCache = true, FISqlConnection db = null)
|
||||
{
|
||||
const string SQL = "select PARAMVALUE from SYSPARAMS where PARAMNAME={0}";
|
||||
|
||||
string v = null;
|
||||
if (useCache && _Params.TryGetValue(paramname, out v))
|
||||
{
|
||||
return v;
|
||||
}
|
||||
if (db == null)
|
||||
db = GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL, paramname);
|
||||
v = FIDbAccess.GetFieldString(obj, string.Empty);
|
||||
_Params[paramname] = v;
|
||||
return v;
|
||||
}
|
||||
|
||||
public static string GetFICStringParam(string paramcode)
|
||||
{
|
||||
const string SQL = "select PARAMVALUE from SystemParams where PARAMCODE={0}";
|
||||
if (string.IsNullOrWhiteSpace(FICDbConnectionString))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
object obj = FICDBInstance.GetRC1BySQL(SQL, paramcode);
|
||||
return FIDbAccess.GetFieldString(obj, string.Empty);
|
||||
}
|
||||
|
||||
public static void SetFICStringParameter(string paramname, string value)
|
||||
{
|
||||
const string SQL = "if exists(select 1 from SYSTEMPARAMS where PARAMCODE={0}) "
|
||||
+ " update SYSTEMPARAMS set PARAMVALUE={1} where PARAMCODE={0} "
|
||||
+ " else insert into SYSTEMPARAMS(IID,PARAMTYPE,PARAMCODE,PARAMNAME,PARAMVALUE,PARAMMEMO) values(newid(),1,{0},{0},{1},{0}) ";
|
||||
|
||||
FICDBInstance.ExecSQL(SQL, paramname, value);
|
||||
}
|
||||
|
||||
private static Services.Customers.CustomerInfo _Company = null;
|
||||
|
||||
public static string CompanyID
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetStringParam("CompanyID");
|
||||
}
|
||||
}
|
||||
|
||||
private static CustomerDetail _Customer = null;
|
||||
private static object _syccust = new object();
|
||||
|
||||
public static CustomerDetail CustomerDetail
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_Customer == null)
|
||||
{
|
||||
lock (_syccust)
|
||||
{
|
||||
if (_Customer == null)
|
||||
{
|
||||
_Customer = FleetServiceClientHelper.CreateClient<CustomerProvider>().GetCustomerDetail(CompanyID);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _Customer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static T GetServiceClient<T>() where T : Foresight.ServiceModel.ServiceClientBase, new()
|
||||
{
|
||||
T rst = new T();
|
||||
rst.ServiceAddress = SystemServiceAddresses[0];
|
||||
rst.AppName = APPNAME;
|
||||
return rst;
|
||||
}
|
||||
|
||||
public static T GetServiceClient<T>(string sessionid) where T : Foresight.ServiceModel.ServiceClientBase, new()
|
||||
{
|
||||
T rst = new T();
|
||||
rst.ServiceAddress = SystemServiceAddresses[0];
|
||||
rst.AppName = APPNAME;
|
||||
rst.LoginSessionID = sessionid;
|
||||
return rst;
|
||||
}
|
||||
|
||||
public static Services.LicenseInfo GetLicense()
|
||||
{
|
||||
var ic = GetServiceClient<Services.Customers.CustomerProvider>();
|
||||
return ic.GetLicenseInfo(CompanyID);
|
||||
}
|
||||
|
||||
public static bool HasLicense(string itemName)
|
||||
{
|
||||
bool result = false;
|
||||
var license = SystemParams.GetLicense();
|
||||
if (license != null && license.Items.Count > 0)
|
||||
{
|
||||
var item = license.Items.FirstOrDefault(m => m.Key.Equals(itemName, StringComparison.OrdinalIgnoreCase));
|
||||
if (item != null && Helper.IsTrue(item.Value))
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetVersion()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_ContractorVersion))
|
||||
{
|
||||
//IronSysServiceClient ic = GetIronSystemServiceClient();
|
||||
//_ContractorVersion = ic.GetServerVersion();
|
||||
_ContractorVersion = GetAssemblyFileVersion();
|
||||
}
|
||||
return _ContractorVersion;
|
||||
}
|
||||
|
||||
public static string GetFICVersion()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_FICVersion))
|
||||
{
|
||||
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\FICBLC.dll");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
FileVersionInfo fv = FileVersionInfo.GetVersionInfo(path);
|
||||
_FICVersion = fv.FileVersion.ToString();
|
||||
}
|
||||
}
|
||||
return _FICVersion;
|
||||
}
|
||||
|
||||
private static string[] _IronIntelSystemServiceAddresses = null;
|
||||
|
||||
public static string[] SystemServiceAddresses
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_IronIntelSystemServiceAddresses == null)
|
||||
{
|
||||
string s = GetStringParam("MasterServiceAddress");
|
||||
_IronIntelSystemServiceAddresses = s.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
return _IronIntelSystemServiceAddresses;
|
||||
}
|
||||
}
|
||||
|
||||
private static string _ReportDbString = string.Empty;
|
||||
|
||||
public static string GetIronIntelReportDataDbString(string companyid = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(companyid))
|
||||
companyid = CompanyID;
|
||||
if (!string.IsNullOrWhiteSpace(_ReportDbString))
|
||||
{
|
||||
return _ReportDbString;
|
||||
}
|
||||
string svcaddress = GetStringParam("IronIntelSystemServiceAddress");
|
||||
if (string.IsNullOrWhiteSpace(svcaddress))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
|
||||
string dbstring = cust.ReportDataDbString;
|
||||
if (!string.IsNullOrEmpty(dbstring))
|
||||
{
|
||||
_ReportDbString = dbstring;
|
||||
return _ReportDbString;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
static Dictionary<string, string> _CompanyDBStrings = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
public static string GetDbStringByCompany(string companyid)
|
||||
{
|
||||
return GetCustomerDbString(companyid, "MASTER_DATA_DB");
|
||||
}
|
||||
|
||||
public static string GetCustomerDbString(string companyid, string dbtype)
|
||||
{
|
||||
string key = companyid + dbtype;
|
||||
if (_CompanyDBStrings.ContainsKey(key))
|
||||
return _CompanyDBStrings[key];
|
||||
|
||||
CustomerDetail cust = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerDetail(companyid);
|
||||
string dbstring = cust.MasterDataDbString;
|
||||
_CompanyDBStrings[key] = dbstring;
|
||||
return dbstring;
|
||||
}
|
||||
|
||||
public static Services.Customers.CustomerInfo GetCompanyInfo()
|
||||
{
|
||||
if (_Company == null)
|
||||
{
|
||||
var ic = GetCustomerProvider();
|
||||
_Company = ic.GetCustomerByID(CompanyID);
|
||||
}
|
||||
return _Company;
|
||||
}
|
||||
public static MainStyle GetMainStyle()
|
||||
{
|
||||
IronSysServiceClient ic = GetIronSystemServiceClient();
|
||||
return ic.GetMainStyle(CompanyID);
|
||||
}
|
||||
|
||||
public static bool IsDealer
|
||||
{
|
||||
get
|
||||
{
|
||||
return CustomerDetail.IsDealer;
|
||||
}
|
||||
}
|
||||
|
||||
public static Services.Customers.CustomerInfo[] GetContractors()
|
||||
{
|
||||
if (IsDealer)
|
||||
{
|
||||
var cust = GetCustomerProvider();
|
||||
return cust.GetContractors(CompanyID);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Services.Customers.CustomerInfo[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] GetCompanyLOGO(string companyid)
|
||||
{
|
||||
return FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetCustomerLOGO(companyid);
|
||||
}
|
||||
|
||||
public static byte[] GetForesightLOGOInMainStyle()
|
||||
{
|
||||
IronSysServiceClient ic = GetIronSystemServiceClient();
|
||||
return ic.GetLogoInMainStyle(CompanyID, 1);
|
||||
}
|
||||
|
||||
public static byte[] GetCompanyLocationLOGO(string companyid)
|
||||
{
|
||||
byte[] buffer = FleetServiceClientHelper.CreateClient<CustomerProvider>(companyid, string.Empty).GetDefaultLocationLOGO(companyid);
|
||||
if ((buffer == null) || (buffer.Length == 0))
|
||||
{
|
||||
return GetCompanyLOGO(companyid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
public static Services.Customers.CustomerInfo GetFirstDealerInfo()
|
||||
{
|
||||
if (IsDealer)
|
||||
{
|
||||
return GetCompanyInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
var cust = GetCustomerProvider();
|
||||
var cmps = cust.GetDealers(CompanyID);
|
||||
if ((cmps != null) && (cmps.Length > 0))
|
||||
{
|
||||
return cmps[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static bool HasLOGO(string companyid)
|
||||
{
|
||||
IronSysServiceClient ic = GetIronSystemServiceClient();
|
||||
return ic.HasLOGO(companyid);
|
||||
}
|
||||
public static void ExecSQL(FIDbAccess db, int retrytimes, string sql, params object[] values)
|
||||
{
|
||||
int n = 0;
|
||||
while (true)
|
||||
{
|
||||
n++;
|
||||
try
|
||||
{
|
||||
db.ExecSQL(sql, values);
|
||||
return;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (n >= retrytimes)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
System.Threading.Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
public static IronSysServiceClient GetIronSystemServiceClient()
|
||||
{
|
||||
IronSysServiceClient ic = GetServiceClient<IronSysServiceClient>();
|
||||
return ic;
|
||||
}
|
||||
|
||||
public static MachineServiceClient2 GetMachineServiceClient()
|
||||
{
|
||||
MachineServiceClient2 ic = GetServiceClient<MachineServiceClient2>();
|
||||
return ic;
|
||||
}
|
||||
|
||||
public static MapAlertLayerClient GetMapAlertLayerClient()
|
||||
{
|
||||
MapAlertLayerClient ic = GetServiceClient<MapAlertLayerClient>();
|
||||
return ic;
|
||||
}
|
||||
|
||||
public static Services.Customers.CustomerProvider GetCustomerProvider()
|
||||
{
|
||||
var ic = GetServiceClient<Services.Customers.CustomerProvider>();
|
||||
return ic;
|
||||
}
|
||||
|
||||
/**Fleet Service***/
|
||||
public static string[] FleetAssetServiceAddresses
|
||||
{
|
||||
get
|
||||
{
|
||||
string addresses = ConfigurationManager.AppSettings["FleetAssetServiceAddress"];
|
||||
if (!string.IsNullOrWhiteSpace(addresses))
|
||||
return addresses.Split(';');
|
||||
return new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
//public static T GetFleetServiceClient<T>() where T : Foresight.Fleet.Services.RemoteClientBase, new()
|
||||
//{
|
||||
// T rst = (T)System.Activator.CreateInstance(typeof(T), new object[] { FleetAssetServiceAddresses });
|
||||
// return rst;
|
||||
//}
|
||||
|
||||
//public static T GetFleetServiceClient<T>(string sessionid, string workingCompanyID) where T : Foresight.Fleet.Services.RemoteClientBase, new()
|
||||
//{
|
||||
// T rst = (T)System.Activator.CreateInstance(typeof(T), new object[] { FleetAssetServiceAddresses });
|
||||
// rst.SessionID = sessionid;
|
||||
// rst.WorkingCompanyID = sessionid;
|
||||
// return rst;
|
||||
//}
|
||||
|
||||
|
||||
private static string _MachineTypeMapViewIconUrl = string.Empty;
|
||||
public static string MachineTypeMapViewIconUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_MachineTypeMapViewIconUrl))
|
||||
{
|
||||
MachineServiceClient2 mc2 = SystemParams.GetMachineServiceClient();
|
||||
_MachineTypeMapViewIconUrl = mc2.GetMachineTypeIconUrl();
|
||||
}
|
||||
return _MachineTypeMapViewIconUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static CustUIStyle GetUIStyle(string useriid)
|
||||
{
|
||||
//var up = UserParams.GetUserParams(useriid);
|
||||
string sid = UserParams.GetStringParameter(useriid, UserParams._SystemStyleID);
|
||||
int styleID = -1;
|
||||
if (string.IsNullOrEmpty(sid) || !int.TryParse(sid, out styleID))
|
||||
styleID = -1;
|
||||
var sc = GetIronSystemServiceClient();
|
||||
CustUIStyle style = sc.GetDefaultUIStyle(SystemParams.CompanyID, styleID);
|
||||
return style;
|
||||
}
|
||||
|
||||
//public static int GetTimeAdjust()
|
||||
//{
|
||||
// var sc = GetIronSystemServiceClient();
|
||||
// return sc.GetCompanyTimeAdjust(CompanyID);
|
||||
//}
|
||||
|
||||
public static double GetHoursOffset()
|
||||
{
|
||||
//double offsetMinutes = 0;
|
||||
//string offset = GetStringParam("CustomerTimeZoneOffset");
|
||||
//if (!string.IsNullOrEmpty(offset) && double.TryParse(offset, out offsetMinutes))
|
||||
//{
|
||||
// return offsetMinutes / 60;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
string tzName = GetStringParam("CustomerTimeZone");
|
||||
if (!string.IsNullOrEmpty(tzName))
|
||||
{
|
||||
var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName.Trim());
|
||||
if (tz != null)
|
||||
{
|
||||
TimeSpan offset = tz.GetUtcOffset(DateTime.UtcNow);
|
||||
return offset.Hours + (double)offset.Minutes / 60;
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
||||
var sc = GetIronSystemServiceClient();
|
||||
double offsetHours = sc.GetCompanyTimeAdjust(CompanyID);
|
||||
return offsetHours;
|
||||
}
|
||||
|
||||
public static TimeZoneInfo GetTimeZoneInfo(string custid, FISqlConnection db = null)
|
||||
{
|
||||
|
||||
string tzName = GetStringParam("CustomerTimeZone", true, db);
|
||||
if (string.IsNullOrEmpty(tzName))
|
||||
tzName = FleetServiceClientHelper.CreateClient<CustomerProvider>(custid, string.Empty).GetCustomerTimeZoneName(custid);
|
||||
var tz = TimeZoneInfo.FindSystemTimeZoneById(tzName.Trim());
|
||||
return tz;
|
||||
}
|
||||
|
||||
public static StringKeyValue[] GetTimeZones()
|
||||
{
|
||||
var tzs = TimeZoneInfo.GetSystemTimeZones();
|
||||
List<StringKeyValue> result = new List<StringKeyValue>();
|
||||
|
||||
foreach (TimeZoneInfo tz in tzs)
|
||||
{
|
||||
StringKeyValue skv = new StringKeyValue();
|
||||
skv.Key = tz.Id;
|
||||
TimeSpan offset = tz.GetUtcOffset(DateTime.UtcNow);
|
||||
skv.Value = string.Format("{0}{1}:{2}", offset.Hours >= 0 ? "+" : "", offset.Hours.ToString("00"), Math.Abs(offset.Minutes).ToString("00"));
|
||||
|
||||
skv.Tag1 = offset.TotalMinutes.ToString();
|
||||
result.Add(skv);
|
||||
}
|
||||
return result.OrderBy(tz => double.Parse(tz.Tag1)).ThenBy(tz => tz.Key).ToArray();
|
||||
//const string SQL = "select name,current_utc_offset as offset from sys.time_zone_info";
|
||||
|
||||
//FISqlConnection db = GetDbInstance();
|
||||
//DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
//if (tb.Rows.Count > 0)
|
||||
//{
|
||||
// foreach (DataRow dr in tb.Rows)
|
||||
// {
|
||||
// StringKeyValue skv = new StringKeyValue();
|
||||
// skv.Key = FIDbAccess.GetFieldString(dr["name"], string.Empty);
|
||||
// skv.Value = FIDbAccess.GetFieldString(dr["offset"], string.Empty);
|
||||
|
||||
// string offsetstr = skv.Value;
|
||||
// string symbol = offsetstr.Substring(0, 1);
|
||||
// string offset = offsetstr.Remove(0, 1);
|
||||
// string[] strs = offset.Split(':');
|
||||
|
||||
// skv.Tag1 = (int.Parse(symbol + strs[0]) * 60 + int.Parse(symbol + strs[1])).ToString();
|
||||
// result.Add(skv);
|
||||
// }
|
||||
//}
|
||||
//return result.ToArray();
|
||||
}
|
||||
|
||||
|
||||
public const string APPNAME = "IronIntelCustomerSite";
|
||||
private const string WORKING_COMPANY_HEADER = "WorkingCompanyID";
|
||||
|
||||
public static void SendMail(System.Net.Mail.MailMessage msg)
|
||||
{
|
||||
SendMail(APPNAME, msg);
|
||||
}
|
||||
|
||||
public static void SendMail(string appname, System.Net.Mail.MailMessage msg)
|
||||
{
|
||||
FleetServiceClientHelper.CreateClient<SystemUtil>().SendMail(CompanyID, appname, msg);
|
||||
}
|
||||
|
||||
public static void WriteLog(string logType, string source, string message, string detail)
|
||||
{
|
||||
try
|
||||
{
|
||||
FleetServiceClientHelper.CreateClient<SystemUtil>().WriteLog(CompanyID, APPNAME, logType, source, message, detail, string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLog(string logType, string category, string source, string message, string detail)
|
||||
{
|
||||
try
|
||||
{
|
||||
FleetServiceClientHelper.CreateClient<SystemUtil>().WriteLog(CompanyID, category, logType, source, message, detail, string.Empty);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteRefreshLog(string useriid, string userhost, string objname, string refreshtype)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(new WaitCallback((e) => { _WriteRefreshLog(useriid, userhost, objname, refreshtype); }), null);
|
||||
}
|
||||
|
||||
|
||||
private static void _WriteRefreshLog(string useriid, string userhost, string objname, string refreshtype)
|
||||
{
|
||||
const string SQL = "insert into REFRESHLOG(USERIID,HOSTADDRESS,OBJNAME,REFRESHTYPE,REFRESHTIME_UTC) values({0},{1},{2},{3},GETUTCDATE())";
|
||||
|
||||
try
|
||||
{
|
||||
FIDbAccess db = GetDbInstance();
|
||||
db.ExecSQL(SQL, useriid, userhost, objname, refreshtype);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
public static string GetResourceLock(string resourceid, int locksecond)
|
||||
{
|
||||
try
|
||||
{
|
||||
return FleetServiceClientHelper.CreateClient<SystemUtil>().GetResourceLock(CompanyID, resourceid, locksecond);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReleaseResourceLock(string lockid)
|
||||
{
|
||||
try
|
||||
{
|
||||
FleetServiceClientHelper.CreateClient<SystemUtil>().ReleaseResourceLock(lockid);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
public static string ConnectorToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("ConnectorToken");
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConnectorServer
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("ConnectorServer");
|
||||
}
|
||||
}
|
||||
|
||||
public static string LdapAgentID
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("LdapAgentID");
|
||||
}
|
||||
}
|
||||
|
||||
public static string LdapAgentToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("LdapAgentToken");
|
||||
}
|
||||
}
|
||||
public static bool CanUseConnectorLDAP
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("CanUseConnectorLDAP") == "1";
|
||||
}
|
||||
}
|
||||
public static bool RedisEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return string.Equals(GetFICStringParam("RedisEnabled"), "Yes", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
|
||||
public static string RedisToken
|
||||
{
|
||||
get
|
||||
{
|
||||
return GetFICStringParam("RedisToken");
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> GetAdditionalParameter()
|
||||
{
|
||||
var dict = new Dictionary<string, string>
|
||||
{
|
||||
{ "ConnectorToken", ConnectorToken },
|
||||
{ "ConnectorServer", ConnectorServer },
|
||||
{ "LdapAgentID", LdapAgentID },
|
||||
{ "LdapAgentToken", LdapAgentToken },
|
||||
{ "CanUseConnectorLDAP", CanUseConnectorLDAP ? "1" : "0" }
|
||||
};
|
||||
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
}
|
45
IronIntelContractorBusiness/Users/Acl.cs
Normal file
45
IronIntelContractorBusiness/Users/Acl.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Foresight.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
public static class Acl
|
||||
{
|
||||
public static string[] GetUserAvailableContractors(string useriid)
|
||||
{
|
||||
const string SQL = @"select distinct CONTRACTORID from USERTOCONTRACTOR where USERIID={0}
|
||||
or USERIID in(select GROUPID from USERGROUPMAP where USERIID ={0})";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, useriid);
|
||||
List<string> list = new List<string>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
list.Add(FIDbAccess.GetFieldString(dr["CONTRACTORID"], string.Empty));
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
public static AppModuleInfo[] GetAvailableAppModuleInfos(UserInfo user)
|
||||
{
|
||||
return AppModulesManagement.GetAvailableAppModuleInfos(user);
|
||||
}
|
||||
|
||||
public static AppModuleInfo[] GetAvailableAppModuleInfos(string useriid)
|
||||
{
|
||||
UserInfo ui = UserManagement.GetUserByIID(useriid);
|
||||
return GetAvailableAppModuleInfos(ui);
|
||||
}
|
||||
|
||||
public static SecurityNavigateItem[] GetSecurityNavigateItems(UserInfo user)
|
||||
{
|
||||
return AppModulesManagement.GetSecurityNavigateItems(user);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
38
IronIntelContractorBusiness/Users/AppModuleInfo.cs
Normal file
38
IronIntelContractorBusiness/Users/AppModuleInfo.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
public class AppModuleInfo
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool Visible { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string IconPath { get; set; }
|
||||
public string BackColor { get; set; }
|
||||
public string ForeColor { get; set; }
|
||||
public bool OpenInNewWindow { get; set; }
|
||||
public AppModuleType ModuleType { get; set; }
|
||||
}
|
||||
|
||||
public class SecurityNavigateItem
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Url { get; set; }
|
||||
public string IconPath { get; set; }
|
||||
}
|
||||
|
||||
public enum AppModuleType
|
||||
{
|
||||
System,
|
||||
Workspace
|
||||
}
|
||||
}
|
195
IronIntelContractorBusiness/Users/AppModulesManagement.cs
Normal file
195
IronIntelContractorBusiness/Users/AppModulesManagement.cs
Normal file
@ -0,0 +1,195 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Data;
|
||||
using Foresight.Data;
|
||||
using IronIntel.Contractor.Users;
|
||||
using IronIntel.Services;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
class AppModulesManagement
|
||||
{
|
||||
private const string FITracker = "FITracker";
|
||||
private const string Inspect = "Inspection";
|
||||
private const string TeamIntelligence = "TeamIntelligence";
|
||||
public static AppModuleInfo[] GetAvailableAppModuleInfos(UserInfo user)
|
||||
{
|
||||
const string SQL = @"select ID,APPMODULENAME,APPMODULEDESC,URL,ICONPATH,BACKCOLOR,FORECOLOR,OPENINNEWWINDOW from APPMODULES where VISIBLE>0 and (isnull(SITETYPE,'All')='All' or SITETYPE={0}) ";
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
return new AppModuleInfo[0];
|
||||
}
|
||||
|
||||
string sql = SQL;
|
||||
switch (user.UserType)
|
||||
{
|
||||
case UserTypes.Readonly:
|
||||
sql = SQL + " and SECURITYLEVEL=0";
|
||||
break;
|
||||
case UserTypes.Common:
|
||||
sql = SQL + " and SECURITYLEVEL<=1";
|
||||
break;
|
||||
case UserTypes.Admin:
|
||||
sql = SQL + " and SECURITYLEVEL<=2";
|
||||
break;
|
||||
case UserTypes.SupperAdmin:
|
||||
sql = SQL + " and SECURITYLEVEL<=3";
|
||||
break;
|
||||
default:
|
||||
sql = SQL;
|
||||
break;
|
||||
}
|
||||
|
||||
sql = sql + " order by ORDERINDEX ";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(sql, SystemParams.CustomerDetail.CustomerType);
|
||||
|
||||
CustUIStyle style = SystemParams.GetUIStyle(user.IID);//获取样式设置
|
||||
string moudleBackgroundColor = "#0078D7";
|
||||
if (style != null && !string.IsNullOrEmpty(style.MenuBackgroundColor))
|
||||
moudleBackgroundColor = style.MenuBackgroundColor;
|
||||
|
||||
List<AppModuleInfo> list = new List<AppModuleInfo>();
|
||||
bool fitracter = SystemParams.HasLicense(FITracker);
|
||||
bool inspect = SystemParams.HasLicense(Inspect);
|
||||
bool teamintelligence = SystemParams.HasLicense(TeamIntelligence);
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
AppModuleInfo ami = ConvertToAppModule(dr);
|
||||
ami.BackColor = moudleBackgroundColor;
|
||||
if (ami.ID.Equals(FITracker, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (fitracter)
|
||||
list.Add(ami);
|
||||
}
|
||||
else if (ami.ID.Equals(Inspect, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (inspect)
|
||||
list.Add(ami);
|
||||
}
|
||||
else if (ami.ID.Equals(TeamIntelligence, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (teamintelligence)
|
||||
list.Add(ami);
|
||||
}
|
||||
else
|
||||
list.Add(ami);
|
||||
}
|
||||
AppModuleInfo[] wsps = GetFICWorkspace(user);
|
||||
foreach (AppModuleInfo ap in wsps)
|
||||
{
|
||||
if (!Exists(ap.Url, list))
|
||||
{
|
||||
ap.BackColor = moudleBackgroundColor;
|
||||
list.Add(ap);
|
||||
}
|
||||
}
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
private static bool Exists(string url, IEnumerable<AppModuleInfo> items)
|
||||
{
|
||||
foreach (AppModuleInfo item in items)
|
||||
{
|
||||
if (string.Compare(url, item.Url, true) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static AppModuleInfo ConvertToAppModule(DataRow dr)
|
||||
{
|
||||
AppModuleInfo ai = new AppModuleInfo();
|
||||
ai.ID = FIDbAccess.GetFieldString(dr["ID"], string.Empty);
|
||||
ai.Name = FIDbAccess.GetFieldString(dr["APPMODULENAME"], string.Empty);
|
||||
ai.Description = FIDbAccess.GetFieldString(dr["APPMODULEDESC"], string.Empty);
|
||||
ai.Url = FIDbAccess.GetFieldString(dr["URL"], string.Empty);
|
||||
ai.IconPath = FIDbAccess.GetFieldString(dr["ICONPATH"], string.Empty);
|
||||
ai.BackColor = FIDbAccess.GetFieldString(dr["BACKCOLOR"], string.Empty);
|
||||
ai.ForeColor = FIDbAccess.GetFieldString(dr["FORECOLOR"], string.Empty);
|
||||
ai.OpenInNewWindow = FIDbAccess.GetFieldInt(dr["OPENINNEWWINDOW"], 0) == 1;
|
||||
ai.Visible = true;
|
||||
ai.ModuleType = AppModuleType.System;
|
||||
return ai;
|
||||
}
|
||||
|
||||
private static AppModuleInfo[] GetFICWorkspace(UserInfo user)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(SystemParams.FICDbConnectionString))
|
||||
{
|
||||
return new AppModuleInfo[0];
|
||||
}
|
||||
|
||||
string SQL = @"select w.IID,isnull(l.WorkSpaceName,w.WSPNAME) as WSPNAME,w.WSPDESCRIPTION from WORKSPACE w
|
||||
left join WorkSpaceLanguage l on w.IID=l.WorkspaceIID and l.LanguageCode='en-us'
|
||||
where (ISPUBLIC=1 or ISPUBLIC>10)";
|
||||
|
||||
FISqlConnection db = new FISqlConnection(SystemParams.FICDbConnectionString);
|
||||
if (user.UserType == UserTypes.Readonly)
|
||||
{
|
||||
SQL += " and w.IID in( select ObjectValue from UserDefaultInfo where UserID='" + user.IID + "' and UserDefaultType=0)";
|
||||
}
|
||||
SQL += " order by isnull(l.WorkspaceName,w.WSPNAME)";
|
||||
|
||||
|
||||
|
||||
DataTable tb = db.GetDataTableBySQL(SQL);
|
||||
List<AppModuleInfo> ls = new List<AppModuleInfo>();
|
||||
foreach (DataRow dr in tb.Rows)
|
||||
{
|
||||
AppModuleInfo ap = new AppModuleInfo();
|
||||
ap.ID = dr["IID"].ToString();
|
||||
ap.Name = FIDbAccess.GetFieldString(dr["WSPNAME"], string.Empty);
|
||||
ap.OpenInNewWindow = false;
|
||||
ap.Description = FIDbAccess.GetFieldString(dr["WSPDESCRIPTION"], string.Empty);
|
||||
ap.Visible = true;
|
||||
if (string.IsNullOrWhiteSpace(ap.Description))
|
||||
{
|
||||
ap.Description = ap.Name;
|
||||
}
|
||||
ap.ForeColor = "white";
|
||||
ap.Url = @"fic/Workspace.aspx?IID=" + ap.ID;
|
||||
ap.IconPath = @"img/modules/pie1.png?t=0";
|
||||
ap.ModuleType = AppModuleType.Workspace;
|
||||
ls.Add(ap);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
|
||||
public static SecurityNavigateItem[] GetSecurityNavigateItems(UserInfo user)
|
||||
{
|
||||
const string SQL = "select * from SECURITYNAVNODE where (isnull(SITETYPE,'All')='All' or SITETYPE={0}) order by ORDERINDEX";
|
||||
|
||||
if ((user == null) || (user.UserType == UserTypes.Readonly) || (user.UserType == UserTypes.Common))
|
||||
{
|
||||
return new SecurityNavigateItem[0];
|
||||
}
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(SQL, SystemParams.CustomerDetail.CustomerType);
|
||||
List<SecurityNavigateItem> ls = new List<SecurityNavigateItem>();
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
SecurityNavigateItem si = new SecurityNavigateItem();
|
||||
si.ID = FIDbAccess.GetFieldString(dr["NODEID"], string.Empty);
|
||||
si.Title = FIDbAccess.GetFieldString(dr["TITLE"], string.Empty);
|
||||
si.IconPath = FIDbAccess.GetFieldString(dr["ICONPATH"], string.Empty);
|
||||
si.Url = FIDbAccess.GetFieldString(dr["TARGETURL"], string.Empty);
|
||||
|
||||
if ("nav_dts" == si.ID.ToLower())
|
||||
si.Url = "../fic/fic/Management/DataTablePermission.aspx";
|
||||
if ("nav_filters" == si.ID.ToLower())
|
||||
si.Url = "../fic/fic/Management/FiltersManagement.aspx";
|
||||
ls.Add(si);
|
||||
}
|
||||
return ls.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
26
IronIntelContractorBusiness/Users/UserGroupInfo.cs
Normal file
26
IronIntelContractorBusiness/Users/UserGroupInfo.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
public class UserGroupInfo
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Notes { get; set; }
|
||||
|
||||
public UserInfo[] Users { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class UserToContractorInfo
|
||||
{
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool IsChecked { get; set; }
|
||||
public bool AuthorizedIngroup { get; set; } //用户权限是否继承至组权限
|
||||
}
|
||||
}
|
84
IronIntelContractorBusiness/Users/UserInfo.cs
Normal file
84
IronIntelContractorBusiness/Users/UserInfo.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using FI.FIC;
|
||||
using FI.FIC.Contracts.DataObjects.BaseObject;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
public class UserInfo
|
||||
{
|
||||
private static string[] ContactTypeNames = { "Foreman", "Driver", "Inventory Manager", "Rental Manager", "Service Manager", "Fleet Manager", "Technician", "Other" };
|
||||
public string IID { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string DisplayName { get; set; }
|
||||
public string TextAddress { get; set; }
|
||||
public bool IsUser { get; set; }
|
||||
public ContactTypes ContactType { get; set; }
|
||||
public string Mobile { get; set; }
|
||||
public string BusinessPhone { get; set; }
|
||||
public string Notes { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public UserTypes UserType { get; set; }
|
||||
public string TransPass { get; set; }
|
||||
public string ManagerIID { get; set; }
|
||||
public string ManagerName { get; set; }
|
||||
public bool EmailOptOut { get; set; }
|
||||
public bool InspectEmailList { get; set; }
|
||||
public bool TeamIntelligenceUser { get; set; }
|
||||
public string FOB { get; set; }
|
||||
public decimal HourlyRate { get; set; }
|
||||
public string[] GroupIDs { get; set; }
|
||||
public string[] GroupNames { get; set; }
|
||||
public string GroupNamesStr { get { return (GroupNames == null || GroupNames.Length == 0) ? "" : string.Join(",", GroupNames); } }
|
||||
|
||||
public string ContactTypeName
|
||||
{
|
||||
get
|
||||
{
|
||||
int cType = (int)ContactType;
|
||||
if (cType > 7)
|
||||
cType = 7;
|
||||
return ContactTypeNames[cType];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UserObject
|
||||
{
|
||||
public UserInfo UserInfo { get; set; }
|
||||
public SubscribeMessageByEmail Subscribe { get; set; }
|
||||
public KeyValuePair<int, Foresight.Fleet.Services.User.Permissions[]>[] Features { get; set; }
|
||||
|
||||
public EmailSchedule Schedule { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public enum UserTypes
|
||||
{
|
||||
Readonly = 0,
|
||||
Common = 1,
|
||||
Admin = 2,
|
||||
SupperAdmin = 3
|
||||
}
|
||||
public enum ContactTypes
|
||||
{
|
||||
Foreman = 0,
|
||||
Driver = 1,
|
||||
InventoryManager = 2,
|
||||
RentalManager = 3,
|
||||
ServiceManager = 4,
|
||||
FleetManager = 5,
|
||||
Technician = 6,
|
||||
Other = 100
|
||||
}
|
||||
|
||||
public class UserNameInfoItem
|
||||
{
|
||||
public string IID { get; set; }
|
||||
public string ID { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
1200
IronIntelContractorBusiness/Users/UserManagement.cs
Normal file
1200
IronIntelContractorBusiness/Users/UserManagement.cs
Normal file
File diff suppressed because it is too large
Load Diff
423
IronIntelContractorBusiness/Users/UserParams.cs
Normal file
423
IronIntelContractorBusiness/Users/UserParams.cs
Normal file
@ -0,0 +1,423 @@
|
||||
using Foresight;
|
||||
using Foresight.Data;
|
||||
using Foresight.Fleet.Services.User;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace IronIntel.Contractor.Users
|
||||
{
|
||||
public static class UserParams
|
||||
{
|
||||
private const string _AutoRecenterMap = "AutoRecenterMap";
|
||||
private const string _BaseMap = "BaseMap";
|
||||
private const string _MapViewContratorID = "MapViewContratorID";
|
||||
private const string _MapAlertLayer = "MapAlertLayer";
|
||||
public const string _SystemStyleID = "SystemStyleID";
|
||||
private const string _MapRefreshInterval = "MapRefreshInterval";
|
||||
private const string _AssetDefaultSearch = "AssetDefaultSearch";
|
||||
private const string _JobSiteDefaultSearch = "JobSiteDefaultSearch";
|
||||
private const string _AssetGroupDefaultSearch = "AssetGroupDefaultSearch";
|
||||
private const string _UnShownMachines = "UnShownMachines";
|
||||
private const string _UnShownJobsites = "UnShownJobsites";
|
||||
private const string _UnShownJobsiteMachines = "UnShownJobsiteMachines";
|
||||
private const string _Onroad = "Onroad";
|
||||
private const string _ExcludeNoLocation = "ExcludeNoLocation";
|
||||
|
||||
private const string _MapViewSearches = "MapViewSearches";
|
||||
|
||||
public static UserParamInfo GetUserParams(string sessionid, string useriid)
|
||||
{
|
||||
UserParamInfo userParams = new UserParamInfo();
|
||||
string sql = "select PARAMNAME,PARAMVALUE from USERSPARAM where USERIID={0} ";
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
DataTable dt = db.GetDataTableBySQL(sql, useriid);
|
||||
|
||||
foreach (DataRow dr in dt.Rows)
|
||||
{
|
||||
string name = FIDbAccess.GetFieldString(dr["PARAMNAME"], "");
|
||||
string value = FIDbAccess.GetFieldString(dr["PARAMVALUE"], "");
|
||||
switch (name)
|
||||
{
|
||||
case _AutoRecenterMap:
|
||||
userParams.AutoRecenterMap = Helper.IsTrue(value);
|
||||
break;
|
||||
case _BaseMap:
|
||||
userParams.BaseMap = value;
|
||||
break;
|
||||
case _MapViewContratorID:
|
||||
userParams.MapViewContratorID = value;
|
||||
break;
|
||||
case _MapAlertLayer:
|
||||
userParams.MapAlertLayer = value;
|
||||
break;
|
||||
case _SystemStyleID:
|
||||
userParams.SystemStyleID = value;
|
||||
break;
|
||||
case _AssetDefaultSearch:
|
||||
userParams.AssetDefaultSearch = value;
|
||||
break;
|
||||
case _JobSiteDefaultSearch:
|
||||
userParams.JobSiteDefaultSearch = value;
|
||||
break;
|
||||
case _AssetGroupDefaultSearch:
|
||||
userParams.AssetGroupDefaultSearch = value;
|
||||
break;
|
||||
case _UnShownMachines:
|
||||
userParams.UnShownMachines = value.Split(',');
|
||||
break;
|
||||
case _UnShownJobsites:
|
||||
userParams.UnShownJobsites = value.Split(',');
|
||||
break;
|
||||
case _UnShownJobsiteMachines:
|
||||
userParams.UnShownJobsiteMachines = value.Split(',');
|
||||
break;
|
||||
case _Onroad:
|
||||
userParams.Onroad = int.Parse(value);
|
||||
break;
|
||||
case _ExcludeNoLocation:
|
||||
userParams.ExcludeNoLocation = int.Parse(value) == 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
userParams.MapViewSearches = GetMapViewSearches(sessionid, useriid);
|
||||
|
||||
//if (string.IsNullOrEmpty(userParams.SystemStyleID))
|
||||
//{
|
||||
// var defaultStyle = SystemParams.GetUIStyle();//获取系统默认Style
|
||||
// userParams.SystemStyleID = defaultStyle.UIStyleID.ToString();
|
||||
//}
|
||||
string intervalStr = SystemParams.GetStringParam(_MapRefreshInterval);
|
||||
int interval = 0;
|
||||
if (!string.IsNullOrWhiteSpace(intervalStr) && int.TryParse(intervalStr, out interval) && interval > 60)
|
||||
userParams.MapRefreshInterval = interval;
|
||||
else
|
||||
userParams.MapRefreshInterval = 60;
|
||||
userParams.MachineIconURL = SystemParams.MachineTypeMapViewIconUrl;
|
||||
return userParams;
|
||||
}
|
||||
|
||||
public static void SetUserParams(string useriid, UserParamInfo userParams)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
|
||||
update USERSPARAM set PARAMVALUE = {2}, BINCONTENT = null where USERIID = {0} and PARAMNAME = {1}
|
||||
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},{2},null) ";
|
||||
const string SQL_Delete = @"delete from USERSPARAM where USERIID={0} and PARAMNAME={1} ";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, useriid, _AutoRecenterMap, userParams.AutoRecenterMap ? "true" : "false");
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.BaseMap))
|
||||
db.ExecSQL(SQL, useriid, _BaseMap, userParams.BaseMap);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _BaseMap);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.MapViewContratorID))
|
||||
db.ExecSQL(SQL, useriid, _MapViewContratorID, userParams.MapViewContratorID);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _MapViewContratorID);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.MapAlertLayer))
|
||||
db.ExecSQL(SQL, useriid, _MapAlertLayer, userParams.MapAlertLayer);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _MapAlertLayer);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.SystemStyleID))
|
||||
db.ExecSQL(SQL, useriid, _SystemStyleID, userParams.SystemStyleID);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _SystemStyleID);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.AssetDefaultSearch))
|
||||
db.ExecSQL(SQL, useriid, _AssetDefaultSearch, userParams.AssetDefaultSearch);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _AssetDefaultSearch);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.JobSiteDefaultSearch))
|
||||
db.ExecSQL(SQL, useriid, _JobSiteDefaultSearch, userParams.JobSiteDefaultSearch);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _JobSiteDefaultSearch);
|
||||
|
||||
if (!string.IsNullOrEmpty(userParams.AssetGroupDefaultSearch))
|
||||
db.ExecSQL(SQL, useriid, _AssetGroupDefaultSearch, userParams.AssetGroupDefaultSearch);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _AssetGroupDefaultSearch);
|
||||
|
||||
if (userParams.UnShownMachines != null && userParams.UnShownMachines.Length > 0)
|
||||
db.ExecSQL(SQL, useriid, _UnShownMachines, string.Join(",", userParams.UnShownMachines));
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _UnShownMachines);
|
||||
|
||||
if (userParams.UnShownJobsites != null && userParams.UnShownJobsites.Length > 0)
|
||||
db.ExecSQL(SQL, useriid, _UnShownJobsites, string.Join(",", userParams.UnShownJobsites));
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _UnShownJobsites);
|
||||
|
||||
if (userParams.UnShownJobsiteMachines != null && userParams.UnShownJobsiteMachines.Length > 0)
|
||||
db.ExecSQL(SQL, useriid, _UnShownJobsiteMachines, string.Join(",", userParams.UnShownJobsiteMachines));
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _UnShownJobsiteMachines);
|
||||
|
||||
if (userParams.Onroad >= 0)
|
||||
db.ExecSQL(SQL, useriid, _Onroad, userParams.Onroad);
|
||||
else
|
||||
db.ExecSQL(SQL_Delete, useriid, _Onroad);
|
||||
|
||||
if (userParams.ExcludeNoLocation)
|
||||
db.ExecSQL(SQL, useriid, _ExcludeNoLocation, userParams.ExcludeNoLocation ? 1 : 0);
|
||||
}
|
||||
|
||||
public static string GetStringParameter(string useriid, string paramname)
|
||||
{
|
||||
const string SQL = "select PARAMVALUE from USERSPARAM where USERIID={0} and PARAMNAME={1}";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL, useriid, paramname);
|
||||
return FIDbAccess.GetFieldString(obj, string.Empty);
|
||||
}
|
||||
|
||||
public static void SetStringParameter(string useriid, string paramname, string value)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
|
||||
update USERSPARAM set PARAMVALUE = {2}, BINCONTENT = null where USERIID = {0} and PARAMNAME = {1}
|
||||
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},{2},null) ";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, useriid, paramname, value);
|
||||
}
|
||||
|
||||
public static byte[] GetBinaryParameter(string useriid, string paramname)
|
||||
{
|
||||
const string SQL = "select BINCONTENT from USERSPARAM where USERIID={0} and PARAMNAME={1}";
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
object obj = db.GetRC1BySQL(SQL, useriid, paramname);
|
||||
return FIDbAccess.GetFieldBytes(obj);
|
||||
}
|
||||
|
||||
public static void SetBinaryParameter(string useriid, string paramname, byte[] buffer)
|
||||
{
|
||||
const string SQL = @"if exists(select 1 from USERSPARAM where USERIID={0} and PARAMNAME={1})
|
||||
update USERSPARAM set PARAMVALUE = '', BINCONTENT = {2} where USERIID = {0} and PARAMNAME = {1}
|
||||
else insert into USERSPARAM(USERIID, PARAMNAME, PARAMVALUE, BINCONTENT) values({0},{1},'',{2})";
|
||||
|
||||
|
||||
FIDbAccess db = SystemParams.GetDbInstance();
|
||||
db.ExecSQL(SQL, useriid, paramname, buffer);
|
||||
}
|
||||
|
||||
private static MapViewSearchItem[] GetMapViewSearches(string sessionid, string useriid)
|
||||
{
|
||||
try
|
||||
{
|
||||
string xmlstr = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid).GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
|
||||
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
|
||||
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new MapViewSearchItem[0];
|
||||
}
|
||||
}
|
||||
|
||||
public static MapViewSearchItem[] SaveMapViewSearch(string sessionid, string useriid, MapViewSearchItem search)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid);
|
||||
string xmlstr = client.GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
|
||||
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
|
||||
|
||||
var item = searches.FirstOrDefault((s) => s.Name.Equals(search.Name, StringComparison.OrdinalIgnoreCase));
|
||||
if (item != null)//如果已经存在,先移除
|
||||
searches.Remove(item);
|
||||
|
||||
if (search.IsDefault)
|
||||
{
|
||||
foreach (var s in searches)
|
||||
{
|
||||
s.IsDefault = false;
|
||||
}
|
||||
}
|
||||
searches.Add(search);
|
||||
|
||||
client.SetUserParam(SystemParams.CompanyID, useriid, _MapViewSearches, MapViewSearcheHelper.ToXml(searches).InnerXml);
|
||||
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
|
||||
}
|
||||
|
||||
private static MapViewSearchItem[] AddSearchItem(MapViewSearchItem[] searches, string search, bool isDefault)
|
||||
{
|
||||
List<MapViewSearchItem> result = null;
|
||||
if (searches != null)
|
||||
{
|
||||
result = searches.ToList();
|
||||
var item = result.FirstOrDefault((s) => s.Name.Equals(search, StringComparison.OrdinalIgnoreCase));
|
||||
if (item != null)//already exists, remove it
|
||||
result.Remove(item);
|
||||
}
|
||||
else
|
||||
result = new List<MapViewSearchItem>();
|
||||
if (isDefault)
|
||||
{
|
||||
foreach (var s in result)
|
||||
{
|
||||
s.IsDefault = false;
|
||||
}
|
||||
}
|
||||
result.Add(new MapViewSearchItem() { Name = search, IsDefault = isDefault });
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
public static MapViewSearchItem[] DeleteMapViewSearch(string sessionid, string useriid, string searchName)
|
||||
{
|
||||
var client = FleetServiceClientHelper.CreateClient<UserProfileProvider>(sessionid);
|
||||
string xmlstr = client.GetUserParams(SystemParams.CompanyID, useriid, _MapViewSearches);
|
||||
List<MapViewSearchItem> searches = MapViewSearcheHelper.FromXML(xmlstr);
|
||||
var item = searches.FirstOrDefault((s) => s.Name.Equals(searchName, StringComparison.OrdinalIgnoreCase));
|
||||
if (item != null)// remove it
|
||||
searches.Remove(item);
|
||||
|
||||
client.SetUserParam(SystemParams.CompanyID, useriid, _MapViewSearches, MapViewSearcheHelper.ToXml(searches).InnerXml);
|
||||
return searches.OrderByDescending(s => s.IsDefault).ThenBy(s => s.Name).ToArray();
|
||||
}
|
||||
|
||||
private static MapViewSearchItem[] RemoveSearchItem(MapViewSearchItem[] searches, string search)
|
||||
{
|
||||
if (searches == null) return null;
|
||||
List<MapViewSearchItem> result = searches.ToList();
|
||||
var item = result.FirstOrDefault((s) => s.Name.Equals(search, StringComparison.OrdinalIgnoreCase));
|
||||
if (item != null)// remove it
|
||||
result.Remove(item);
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
public class UserParamInfo
|
||||
{
|
||||
public bool AutoRecenterMap { get; set; } = false;
|
||||
public string BaseMap { get; set; }
|
||||
public string MapViewContratorID { get; set; }
|
||||
public string MapAlertLayer { get; set; }
|
||||
public string SystemStyleID { get; set; }
|
||||
public int MapRefreshInterval { get; set; }
|
||||
public string MachineIconURL { get; set; }
|
||||
public string AssetDefaultSearch { get; set; }
|
||||
public string JobSiteDefaultSearch { get; set; }
|
||||
public string AssetGroupDefaultSearch { get; set; }
|
||||
public string[] UnShownMachines { get; set; }
|
||||
public string[] UnShownJobsites { get; set; }
|
||||
public string[] UnShownJobsiteMachines { get; set; }
|
||||
public int Onroad { get; set; } = -1;
|
||||
public bool ExcludeNoLocation { get; set; } = true;
|
||||
|
||||
public MapViewSearchItem[] MapViewSearches { get; set; }
|
||||
}
|
||||
|
||||
public class MapViewSearcheHelper
|
||||
{
|
||||
public static List<MapViewSearchItem> FromXML(string xmlstr)
|
||||
{
|
||||
List<MapViewSearchItem> searches = new List<MapViewSearchItem>();
|
||||
if (!string.IsNullOrEmpty(xmlstr))
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xmlstr);
|
||||
XmlNode ch = doc.DocumentElement.FirstChild;
|
||||
if (string.Compare(ch.Name, "Searches", true) == 0)
|
||||
{
|
||||
foreach (XmlNode node in ch.ChildNodes)
|
||||
{
|
||||
searches.Add(FromXml(node));
|
||||
}
|
||||
}
|
||||
}
|
||||
return searches;
|
||||
}
|
||||
|
||||
private static MapViewSearchItem FromXml(XmlNode node)
|
||||
{
|
||||
MapViewSearchItem item = new MapViewSearchItem();
|
||||
foreach (XmlNode ch in node.ChildNodes)
|
||||
{
|
||||
if (string.Compare(ch.Name, "Name", true) == 0)
|
||||
item.Name = ch.InnerText;
|
||||
else if (string.Compare(ch.Name, "IsDefault", true) == 0)
|
||||
item.IsDefault = Helper.IsTrue(ch.InnerText);
|
||||
else if (string.Compare(ch.Name, "Onroad", true) == 0)
|
||||
item.Onroad = Convert.ToInt32(ch.InnerText);
|
||||
else if (string.Compare(ch.Name, "AssetDefaultSearch", true) == 0)
|
||||
item.AssetDefaultSearch = ch.InnerText;
|
||||
else if (string.Compare(ch.Name, "JobSiteDefaultSearch", true) == 0)
|
||||
item.JobSiteDefaultSearch = ch.InnerText;
|
||||
else if (string.Compare(ch.Name, "AssetGroupDefaultSearch", true) == 0)
|
||||
item.AssetGroupDefaultSearch = ch.InnerText;
|
||||
else if (string.Compare(ch.Name, "ExcludeNoLocation", true) == 0)
|
||||
item.ExcludeNoLocation = Convert.ToInt32(ch.InnerText) == 1;
|
||||
else if (string.Compare(ch.Name, "UnShownMachines", true) == 0)
|
||||
item.UnShownMachines = ch.InnerText.Split(',');
|
||||
else if (string.Compare(ch.Name, "UnShownJobsites", true) == 0)
|
||||
item.UnShownJobsites = ch.InnerText.Split(',');
|
||||
else if (string.Compare(ch.Name, "UnShownJobsiteMachines", true) == 0)
|
||||
item.UnShownJobsiteMachines = ch.InnerText.Split(',');
|
||||
|
||||
}
|
||||
return item;
|
||||
}
|
||||
public static XmlDocument ToXml(List<MapViewSearchItem> searches)
|
||||
{
|
||||
XmlDocument doc = XmlHelper.CreateXmlDocument();
|
||||
XmlNode node = XmlHelper.AppendChildNode(doc.DocumentElement, "Searches", "");
|
||||
if (searches != null && searches.Count > 0)
|
||||
{
|
||||
foreach (var search in searches)
|
||||
{
|
||||
var sn = AddSubNode(node, "Search", "");
|
||||
|
||||
AddSubNode(sn, "Name", search.Name);
|
||||
AddSubNode(sn, "IsDefault", search.IsDefault ? "Yes" : "No");
|
||||
if (!string.IsNullOrEmpty(search.AssetDefaultSearch))
|
||||
AddSubNode(sn, "AssetDefaultSearch", search.AssetDefaultSearch);
|
||||
if (!string.IsNullOrEmpty(search.JobSiteDefaultSearch))
|
||||
AddSubNode(sn, "JobSiteDefaultSearch", search.JobSiteDefaultSearch);
|
||||
if (!string.IsNullOrEmpty(search.AssetGroupDefaultSearch))
|
||||
AddSubNode(sn, "AssetGroupDefaultSearch", search.AssetGroupDefaultSearch);
|
||||
AddSubNode(sn, "Onroad", search.Onroad.ToString());
|
||||
AddSubNode(sn, "ExcludeNoLocation", search.ExcludeNoLocation ? "1" : "0");
|
||||
if (search.UnShownMachines != null && search.UnShownMachines.Length > 0)
|
||||
AddSubNode(sn, "UnShownMachines", string.Join(",", search.UnShownMachines));
|
||||
if (search.UnShownJobsites != null && search.UnShownJobsites.Length > 0)
|
||||
AddSubNode(sn, "UnShownJobsites", string.Join(",", search.UnShownJobsites));
|
||||
if (search.UnShownJobsiteMachines != null && search.UnShownJobsiteMachines.Length > 0)
|
||||
AddSubNode(sn, "UnShownJobsiteMachines", string.Join(",", search.UnShownJobsiteMachines));
|
||||
}
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
private static XmlNode AddSubNode(XmlNode parent, string nodename, string innertext)
|
||||
{
|
||||
XmlNode node = parent.OwnerDocument.CreateNode(XmlNodeType.Element, nodename, string.Empty);
|
||||
if (!string.IsNullOrEmpty(innertext))
|
||||
{
|
||||
node.InnerText = innertext;
|
||||
}
|
||||
parent.AppendChild(node);
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
public class MapViewSearchItem
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public int Onroad { get; set; } = -1;
|
||||
public string AssetDefaultSearch { get; set; } = "";
|
||||
public string JobSiteDefaultSearch { get; set; } = "";
|
||||
public string AssetGroupDefaultSearch { get; set; } = "";
|
||||
public bool ExcludeNoLocation { get; set; } = true;
|
||||
public string[] UnShownMachines { get; set; }
|
||||
public string[] UnShownJobsites { get; set; }
|
||||
public string[] UnShownJobsiteMachines { get; set; }
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user