using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace MainForm
{
///
/// 进站数据
///
public class StationIn
{
#region 变量
///
/// 主键
///
public string GUID { get; set; } = Guid.NewGuid().ToString();
///
/// 车间订单号
///
public string Workorder_code { get; set; } = string.Empty;
///
/// 产品型号(物料号)
///
public string Mtltmrk { get; set; } = string.Empty;
///
/// 产品序列号
///
public string Sn { get; set; } = string.Empty;
///
/// 进站接口Json数据 - Body
///
public string StationIn_body { get; set; } = string.Empty;
///
/// 进站数据
///
public List Parameter_values { get; set; } = new List();
///
/// 员工Id;操作员工编号,如:system
///
public string Write_user = "system";
///
/// 进站时间
///
public string Test_time { get; set; } = string.Empty;
///
/// 上传
///
public string Upload { get; set; } = string.Empty;
#endregion 变量
///
/// 生产插入的语句
///
/// 上传状态
///
public string ToStringInsert(int upload)
{
string values = JsonConvert.SerializeObject(Parameter_values);
return string.Format(
"insert into StationIn" +
"(" +
"GUID," +
"Workorder_code," +
"Mtltmrk," +
"Sn," +
"StationIn_body," +
"Parameter_values," +
"Write_user," +
"Test_time," +
"Upload" +
") " +
"values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}')",
GUID,
Workorder_code,
Mtltmrk,
Sn,
StationIn_body,
values,
Write_user,
Test_time,
upload);
}
///
/// 更新上传状态
///
/// 上传状态
///
public string ToStringUpdateStatusByID(int upload)
{
return string.Format(
"update StationIn" +
" set " +
" Upload = '{0}' " +
" where GUID = '{1}'",
upload, GUID);
}
///
/// 更新回传
///
/// 上传状态
///
public string ToStringUpdateStationInReturn_body(string StationOut_body)
{
return string.Format(
"update StationIn" +
" set " +
" StationInReturn_body = '{0}' " +
" where GUID = '{1}'",
StationOut_body, GUID);
}
///
/// 查询数据
///
/// 开始日期
/// 结束日期
/// 上传状态
///
public string ToStringQuery(string startDate, string endDate, string upload)
{
switch (upload)
{
case "All":
upload = "All";
break;
case "已上传":
upload = "1";
break;
case "未上传":
upload = "0";
break;
}
StringBuilder strSQL = new StringBuilder();
strSQL.AppendFormat("select " +
"GUID as 主键," +
"Workorder_code 车间订单号," +
"Mtltmrk 物料号," +
"Sn 产品序列号," +
"StationIn_body 进站Body数据," +
"Parameter_values 进站数据, " +
"Write_user 员工ID," +
"Test_time 进站时间, " +
"case when Upload = 1 then '已上传' else '未上传' end 上传状态 " +
"from StationIn " +
"where convert(datetime, Test_time, 120) " +
"between convert(datetime, '{0}', 120) " +
"and convert(datetime, '{1}', 120) ",
startDate,
endDate);
if (upload != "All")
strSQL.AppendFormat("and Upload='{0}' ", upload);
strSQL.Append(" Order By Test_time desc");
return strSQL.ToString();
}
///
/// 查询数据量
///
/// 结束日期
/// 上传状态
///
public string ToStringQueryCount(string endDate, string upload)
{
switch (upload)
{
case "All":
upload = "All";
break;
case "已上传":
upload = "1";
break;
case "未上传":
upload = "0";
break;
}
StringBuilder strSQL = new StringBuilder();
strSQL.AppendFormat("SELECT COUNT(*) FROM StationIn " +
"where convert(datetime,test_time,120) < convert(datetime, '{0}', 120) ",
endDate);
if (upload != "All")
{
strSQL.AppendFormat("and Upload='{0}' ", upload);
}
return strSQL.ToString();
}
}
}