This commit is contained in:
2023-04-28 12:21:24 +08:00
parent 156d145a48
commit 88e0a25ecd
162 changed files with 26324 additions and 7519 deletions

View File

@@ -1,4 +1,5 @@
using Foresight.Fleet.Services.Customer;
using Foresight.Standard;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@@ -11,6 +12,20 @@ namespace IronIntel.Contractor.Site.SystemSettings
{
public class CustomerProviderBasePage : ContractorBasePage
{
protected bool IsDev
{
get
{
var session = GetCurrentLoginSession();
if (session != null)
{
if (Helper.DevAccounts.Contains(session.User.ID, StringComparer.OrdinalIgnoreCase))
return true;
}
return false;
}
}
protected void ProcessRequest(string methodName)
{
object result = null;
@@ -29,6 +44,30 @@ namespace IronIntel.Contractor.Site.SystemSettings
case "DELETECUSTOMERLOCATION":
result = DeleteCustomerLocation();
break;
case "GETDEPARTMENTS":
result = GetDepartments();
break;
case "SAVEDEPARTMENT":
result = SaveDepartment();
break;
case "DELETEDEPARTMENT":
result = DeleteDepartment();
break;
case "GETREGIONS":
result = GetRegions();
break;
case "SAVEREGION":
result = SaveRegion();
break;
case "DELETEREGION":
result = DeleteRegion();
break;
case "GETSYSTEMPARAMS":
result = GetSystemParams();
break;
case "SETSYSTEMPARAMS":
result = SetSystemParams();
break;
}
}
}
@@ -49,19 +88,15 @@ namespace IronIntel.Contractor.Site.SystemSettings
var session = GetCurrentLoginSession();
if (session != null)
{
CustomerLocation[] locations = CreateClient<CustomerProvider>().GetCustomerLocations(SystemParams.CompanyID);
List<CustomerLocationItem> list = new List<CustomerLocationItem>();
foreach (CustomerLocation lc in locations)
CustomerLocation[] alllocs = CreateClient<CustomerProvider>().GetLocations(SystemParams.CompanyID);
var plocs = alllocs.Where(d => d.PId <= 0).OrderBy(d => d.Name);
List<CustomerLocation> result = new List<CustomerLocation>();
foreach (var ploc in plocs)
{
CustomerLocationItem item = new CustomerLocationItem();
Helper.CloneProperty(item, lc);
list.Add(item);
result.Add(ploc);
result.AddRange(alllocs.Where(d => d.PId == ploc.ID).OrderBy(d => d.Name));
}
if (list.Count() > 0)
return list.ToArray().OrderBy(m => m.Name);
else
return new CustomerLocationItem[0];
return result.ToArray();
}
else
{
@@ -79,7 +114,7 @@ namespace IronIntel.Contractor.Site.SystemSettings
{
if (GetCurrentLoginSession() != null)
{
string data = HttpUtility.UrlDecode(Request.Params["ClientData"]);
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
HttpPostedFile uploadFile = null;
byte[] logobyte = null;
if (Request.Files.Count > 0)
@@ -88,18 +123,16 @@ namespace IronIntel.Contractor.Site.SystemSettings
logobyte = ConvertFile2bytes(uploadFile);
}
CustomerLocationItem item = JsonConvert.DeserializeObject<CustomerLocationItem>(data);
CustomerLocation location = new CustomerLocation();
Helper.CloneProperty(location, item);
CustomerLocation location = JsonConvert.DeserializeObject<CustomerLocation>(data);
var cp = CreateClient<CustomerProvider>();
int locationid = location.ID;
if (locationid == -1)
locationid = cp.AddCustomerLocation(SystemParams.CompanyID, location);
locationid = cp.AddLocation(SystemParams.CompanyID, location);
else
cp.UpdateCustomerLocation(location);
cp.UpdateLocation(SystemParams.CompanyID, location);
if (logobyte != null)
cp.ChangeLocationLOGO(locationid, logobyte);
cp.ChangeLocationLOGO(SystemParams.CompanyID, locationid, logobyte);
return "OK";
}
else
@@ -113,16 +146,234 @@ namespace IronIntel.Contractor.Site.SystemSettings
}
}
private string DeleteCustomerLocation()
private object DeleteCustomerLocation()
{
try
{
if (GetCurrentLoginSession() != null)
{
string id = HttpUtility.UrlDecode(Request.Params["ClientData"]);
string id = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
int locationid = -1;
int.TryParse(id, out locationid);
CreateClient<CustomerProvider>().DeleteCustomerLocation(locationid);
CreateClient<CustomerProvider>().DeleteLocation(SystemParams.CompanyID, locationid);
return new string[0];
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object GetDepartments()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
DepartmentInfo[] alldeps = CreateClient<CustomerProvider>().GetAllDepartments(SystemParams.CompanyID);
var pdeps = alldeps.Where(d => d.PId <= 0).OrderBy(d => d.Name);
List<DepartmentInfo> result = new List<DepartmentInfo>();
foreach (var pdep in pdeps)
{
result.Add(pdep);
result.AddRange(alldeps.Where(d => d.PId == pdep.Id).OrderBy(d => d.Name));
}
return result.ToArray();
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object SaveDepartment()
{
try
{
if (GetCurrentLoginSession() != null)
{
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
DepartmentInfo dep = JsonConvert.DeserializeObject<DepartmentInfo>(data);
var cp = CreateClient<CustomerProvider>();
if (dep.Id > 0)
cp.UpdateDepartment(SystemParams.CompanyID, dep);
else
dep = cp.AddNewDepartment(SystemParams.CompanyID, dep);
return dep.Id;
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteDepartment()
{
try
{
if (GetCurrentLoginSession() != null)
{
string id = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
int depid = -1;
int.TryParse(id, out depid);
CreateClient<CustomerProvider>().DeleteDepartment(SystemParams.CompanyID, depid);
return new string[0];
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
#region Region
private object GetRegions()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
RegionInfo[] regions = CreateClient<CustomerProvider>().GetRegions(SystemParams.CompanyID);
if (regions == null || regions.Length == 0)
return new RegionItem[0];
List<RegionItem> ls = new List<RegionItem>();
foreach (var region in regions)
{
RegionItem item = new RegionItem();
Helper.CloneProperty(item, region);
ls.Add(item);
}
return ls.ToArray();
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object SaveRegion()
{
try
{
if (GetCurrentLoginSession() != null)
{
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
RegionInfo region = JsonConvert.DeserializeObject<RegionInfo>(data);
var cp = CreateClient<CustomerProvider>();
if (region.Id > 0)
cp.UpdateRegion(SystemParams.CompanyID, region);
else
cp.AddNewRegion(SystemParams.CompanyID, region);
return new string[0];
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object DeleteRegion()
{
try
{
if (GetCurrentLoginSession() != null)
{
string clientdata = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
int id = -1;
int.TryParse(clientdata, out id);
CreateClient<CustomerProvider>().DeleteRegion(SystemParams.CompanyID, id);
return new string[0];
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
#endregion
#region System Params
private object GetSystemParams()
{
try
{
var session = GetCurrentLoginSession();
if (session != null)
{
StringKeyValue[] items = CreateClient<CustomerProvider>().GetSystemParams(SystemParams.CompanyID);
if (items == null || items.Length == 0)
return new StringKeyValue[0];
return items;
}
else
{
throw new Exception("not login.");
}
}
catch (Exception ex)
{
return ex.Message;
}
}
private object SetSystemParams()
{
try
{
if (GetCurrentLoginSession() != null && IsDev)
{
string data = HttpUtility.HtmlDecode(Request.Params["ClientData"]);
string[] pstr = JsonConvert.DeserializeObject<string[]>(data);
var cp = CreateClient<CustomerProvider>();
cp.SetSystemParams(SystemParams.CompanyID, pstr[0], pstr[1]);
return "OK";
}
else
@@ -136,14 +387,14 @@ namespace IronIntel.Contractor.Site.SystemSettings
}
}
public class CustomerLocationItem
{
public int ID { get; set; }
public string Name { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public string Address { get; set; }
public string Notes { get; set; }
}
#endregion
}
class RegionItem : RegionInfo
{
public string StartDateStr { get { return StartDate == null ? "" : StartDate.Value.ToShortDateString(); } }
public string EndDateStr { get { return EndDate == null ? "" : EndDate.Value.ToShortDateString(); } }
public string ProjectedEndDateStr { get { return ProjectedEndDate == null ? "" : ProjectedEndDate.Value.ToShortDateString(); } }
}
}