using ClassLibrary1;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Diagnostics;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Text;
|
|
namespace DeviceITisation
|
{
|
public class DeviceOnline
|
{
|
public bool AddDevice(out string msg, string test_date, string device_type, string device_name, string device_sn,
|
string device_fw, string location, string user_name, string assets_no, string device_status, string remark = "",
|
string pc_name = "", string pc_ip = "", string pc_mac = "", string bom = "", string odf = "")
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(pc_name))
|
pc_name = SystemInfoHelper.GetComputerName();
|
|
if (string.IsNullOrEmpty(pc_ip))
|
pc_ip = SystemInfoHelper.GetLocalIPAddress();
|
|
if (string.IsNullOrEmpty(pc_mac))
|
pc_mac = SystemInfoHelper.GetFirstMacAddress();
|
|
string[] colsName = new string[]
|
{
|
"bom","odf","test_date","device_type","device_name","device_sn",
|
"device_fw","location","pc_name","pc_ip","pc_mac","user_name",
|
"assets_no","device_status","remark"
|
};
|
|
if (MySqlCommand.CheckRecordExists("device_ol_log", new string[] { "device_sn" }, colsName,
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
string last_location = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "location");
|
string last_remark = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "remark");
|
string last_date = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "date");
|
|
//if (!string.IsNullOrEmpty(last_remark))
|
//{
|
// if (!string.IsNullOrEmpty(remark))
|
// remark += $"[{last_remark}]";
|
// else
|
// remark += $"{last_remark}";
|
//}
|
|
if (last_location != location)
|
remark += $"[{last_date}位置为{last_location}]";
|
|
if (MySqlCommand.AddRow("device_ol_log", colsName, new string[] { "device_sn" },
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
Debug.WriteLine($"{device_sn}更新成功");
|
msg = $"{device_sn}更新成功";
|
return true;
|
}
|
else
|
{
|
Debug.WriteLine($"{device_sn}更新失败");
|
msg = $"{device_sn}更新失败";
|
return false;
|
}
|
}
|
else
|
{
|
if (MySqlCommand.AddRow("device_ol_log", colsName, new string[] { "device_sn" },
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
Debug.WriteLine($"{device_sn}添加成功");
|
msg = $"{device_sn}添加成功";
|
return true;
|
}
|
else
|
{
|
Debug.WriteLine($"{device_sn}添加失败");
|
msg = $"{device_sn}添加失败";
|
return false;
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
Debug.WriteLine($"添加{device_sn}时发生异常:{e.Message}【{e.StackTrace}】");
|
msg = $"添加{device_sn}时发生异常:{e.Message}【{e.StackTrace}】";
|
return false;
|
}
|
}
|
|
public bool AddDeviceBySN(out string msg, string test_date, string device_type, string device_name, string device_sn,
|
string device_fw, string location, string user_name, string assets_no, string device_status, string sn, string remark = "",
|
string pc_name = "", string pc_ip = "", string pc_mac = "")
|
{
|
try
|
{
|
if (string.IsNullOrEmpty(pc_name))
|
pc_name = SystemInfoHelper.GetComputerName();
|
|
if (string.IsNullOrEmpty(pc_ip))
|
pc_ip = SystemInfoHelper.GetLocalIPAddress();
|
|
if (string.IsNullOrEmpty(pc_mac))
|
pc_mac = SystemInfoHelper.GetFirstMacAddress();
|
|
string[] colsName = new string[]
|
{
|
"bom","odf","test_date","device_type","device_name","device_sn",
|
"device_fw","location","pc_name","pc_ip","pc_mac","user_name",
|
"assets_no","device_status","remark"
|
};
|
|
GetBomAndOdf(sn, out string bom, out string odf);
|
|
if (MySqlCommand.CheckRecordExists("device_ol_log", new string[] { "device_sn" }, colsName,
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
string last_location = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "location");
|
string last_remark = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "remark");
|
string last_date = MySqlCommand.FindValueFromIndexName("device_ol_log", "device_sn", device_sn, "date");
|
|
//if (!string.IsNullOrEmpty(last_remark))
|
//{
|
// if (!string.IsNullOrEmpty(remark))
|
// remark += $"[{last_remark}]";
|
// else
|
// remark += $"{last_remark}";
|
//}
|
|
if (last_location != location)
|
remark += $"[{last_date}位置为{last_location}]";
|
|
if (MySqlCommand.AddRow("device_ol_log", colsName, new string[] { "device_sn" },
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
Debug.WriteLine($"{device_sn}更新成功");
|
msg = $"{device_sn}更新成功";
|
return true;
|
}
|
else
|
{
|
Debug.WriteLine($"{device_sn}更新失败");
|
msg = $"{device_sn}更新失败";
|
return false;
|
}
|
}
|
else
|
{
|
if (MySqlCommand.AddRow("device_ol_log", colsName, new string[] { "device_sn" },
|
bom, odf, test_date, device_type, device_name, device_sn,
|
device_fw, location, pc_name, pc_ip, pc_mac, user_name,
|
assets_no, device_status, remark))
|
{
|
Debug.WriteLine($"{device_sn}添加成功");
|
msg = $"{device_sn}添加成功";
|
return true;
|
}
|
else
|
{
|
Debug.WriteLine($"{device_sn}添加失败");
|
msg = $"{device_sn}添加失败";
|
return false;
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
Debug.WriteLine($"添加{device_sn}时发生异常:{e.Message}【{e.StackTrace}】");
|
msg = $"添加{device_sn}时发生异常:{e.Message}【{e.StackTrace}】";
|
return false;
|
}
|
}
|
|
public bool GetBomAndOdf(string sn, out string bom, out string odf)
|
{
|
try
|
{
|
bom = string.Empty;
|
odf = string.Empty;
|
string GetTVInfoMessage = ClassLibrary1.Class1.GetTVinfo(sn);
|
if (GetTVInfoMessage != "null")
|
{
|
try
|
{
|
List<GetTVInfo> GetTVInfo1 = JsonConvert.DeserializeObject<List<GetTVInfo>>("[" + GetTVInfoMessage + "]");
|
foreach (GetTVInfo l in GetTVInfo1)
|
{
|
bom = l.ProductCode;
|
odf = l.ODF;
|
}
|
return true;
|
}
|
catch
|
{
|
bom = string.Empty;
|
odf = string.Empty;
|
return false;
|
}
|
}
|
else
|
{
|
try
|
{
|
string sHtml = ClassLibrary1.Class1.PostXml(" http://10.222.16.22:9002/SAPService.asmx?op=GetMaInfo", sn);
|
RootObject5 rb = JsonConvert.DeserializeObject<RootObject5>(sHtml);
|
|
bom = rb.BOM;
|
odf = rb.ODF;
|
return true;
|
}
|
catch
|
{
|
bom = string.Empty;
|
odf = string.Empty;
|
return false;
|
}
|
}
|
|
}
|
catch
|
{
|
bom = string.Empty;
|
odf = string.Empty;
|
return false;
|
}
|
}
|
}
|
}
|