using DBUtility;
|
using Model;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Linq;
|
using System.Web;
|
using System.Web.Http;
|
using System.Windows.Forms;
|
using WebAPI.Models;
|
|
namespace WebAPI.Controllers.品质管理.产线返修平台
|
{
|
public class Sc_SourceLineRepairBillController : ApiController
|
{
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
|
private json objJsonResult = new json();
|
public DataSet ds = new DataSet();
|
public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
public DAL.ClsSc_SourceLineRepairBill BillOld = new DAL.ClsSc_SourceLineRepairBill();
|
string user_LongShan = "";
|
string HName_LongShan = "";
|
|
#region 产线质检平台 保存
|
/// <summary>
|
/// 新增单据-保存按钮
|
///参数:string sql。
|
///返回值:object。
|
/// </summary>
|
[Route("Sc_SourceLineRepairBillSub/AddSourceLineRepairBill")]
|
[HttpPost]
|
public object AddSourceLineRepairBill([FromBody] JObject sMainSub)
|
{
|
try
|
{
|
//获取参数
|
var _value = sMainSub["sMainSub"].ToString();
|
string msg1 = _value.ToString();
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg2 = sArray[0].ToString(); //表头数据
|
string msg3 = sArray[1].ToString();
|
string msg4 = sArray[2].ToString();
|
string user = sArray[3].ToString(); //操作用户的用户名
|
string HComputerName = SystemInformation.ComputerName; //设备名称
|
|
////判断是否有新增权限
|
//if (!DBUtility.ClsPub.Security_Log("Sc_ICMOBillQualityStatus_Tmp_Edit", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无新增权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
msg2 = "[" + msg2.ToString() + "]";
|
List<Model.ClsSc_SourceLineRepairBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_SourceLineRepairBillMain>>(msg2);
|
BillOld.omodel = mainList[0];
|
|
msg3 = "[" + msg3.ToString() + "]";
|
List<Model.ClsSc_SourceLineRepairBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_SourceLineRepairBillSub>>(msg3);
|
BillOld.DetailColl = subList;
|
|
//msg4 = "[" + msg4.ToString() + "]";
|
List<Model.ClsSc_SourceLineRepairBillSub_Mater> subMaterList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_SourceLineRepairBillSub_Mater>> (msg4);
|
BillOld.DetailMaterColl = subMaterList;
|
|
if (!BillOld.AddBill(ref DBUtility.ClsPub.sExeReturnInfo))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 产线返修平台 获取表头信息
|
[Route("Sc_SourceLineRepairBill/getMainInfo")]
|
[HttpGet]
|
public object getMainInfo(string Czybm, string user)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
//查看权限
|
//if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无查看权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
string sql = "exec h_p_Sc_ICMOBillQualityStatus_Tmp_Init '" + Czybm + "'";
|
ds = oCN.RunProcReturn(sql, "h_p_Sc_ICMOBillQualityStatus_Tmp_Init");
|
|
if(ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "未找到相关数据!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
|
//添加列名
|
foreach (DataColumn col in ds.Tables[0].Columns)
|
{
|
Type dataType = col.DataType;
|
string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
|
columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 产线返修平台 获取子表1信息
|
[Route("Sc_SourceLineRepairBill/getSubInfo")]
|
[HttpGet]
|
public object getSubInfo(Int64 HSourceInterID, Int64 HSourceEntryID, string HDate, string user)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
//查看权限
|
//if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无查看权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
string sql = @"select b.HInterID, b.HEntryID, a.HDate 日期, c.HName 产品名称, a.HBarCode SN码, d.HName 不良原因, b.HRepairResult 维修结果
|
from Sc_SourceLineRepairBillMain AS a
|
inner join Sc_SourceLineRepairBillSub AS b on a.HInterID = b.HInterID
|
LEFT OUTER JOIN Gy_Material AS c on a.HMaterID = c.HItemID
|
LEFT OUTER JOIN Gy_BadReason AS d on b.HBadReasonID = d.HItemID
|
where b.HSourceInterID = " + HSourceInterID + "and HSourceEntryID = " + HSourceEntryID + " and CONVERT(varchar(100),a.HDate, 23) = '" + HDate + "' " +
|
"order by a.HDate desc, b.HInterID desc, b.HEntryID desc";
|
ds = oCN.RunProcReturn(sql, "Sc_SourceLineRepairBill");
|
|
//添加列名
|
foreach (DataColumn col in ds.Tables[0].Columns)
|
{
|
Type dataType = col.DataType;
|
string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
|
columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 产线返修平台 子表1删除
|
[Route("Sc_SourceLineRepairBill/deleteSubInfo")]
|
[HttpGet]
|
public object deleteSubInfo(int HInterID, int HEntryID, string user)
|
{
|
try
|
{
|
//查看权限
|
//if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无查看权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
string sql = "delete from Sc_SourceLineRepairBillMain where HInterID = " + HInterID;
|
oCN.RunProc(sql);
|
sql = "delete from Sc_SourceLineRepairBillSub where HInterID = " + HInterID + " and HEntryID = " + HEntryID;
|
oCN.RunProc(sql);
|
sql = "delete from Sc_SourceLineRepairBillSub_Mater where HInterID = " + HInterID;
|
oCN.RunProc(sql);
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 产线返修平台 获取不良率占比分析图数据
|
[Route("Sc_SourceLineRepairBill/getBadReasonRateInfo")]
|
[HttpGet]
|
public object getBadReasonRateInfo(int HSourceInterID, int HSourceEntryID)
|
{
|
try
|
{
|
List<object> columnNameList = new List<object>();
|
//查看权限
|
//if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无查看权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
string sql = @"select a.HBadReasonID, b.HName HBadReasonName, count(a.HBadReasonID) HBadReasonQty
|
from Sc_SourceLineRepairBillSub AS a
|
LEFT OUTER JOIN Gy_BadReason AS b on a.HBadReasonID = b.HItemID
|
where a.HSourceInterID = " + HSourceInterID + " and HSourceEntryID = " + HSourceEntryID + " and ISNULL(a.HBadReasonID,0)<>0 " +
|
"group by a.HBadReasonID,b.HName order by COUNT(a.HBadReasonID) desc";
|
|
ds = oCN.RunProcReturn(sql, "getBadReasonRateInfo");
|
|
//添加列名
|
foreach (DataColumn col in ds.Tables[0].Columns)
|
{
|
Type dataType = col.DataType;
|
string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
|
columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
objJsonResult.list = columnNameList;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 产线返修平台 根据条形码获取信息
|
[Route("Sc_SourceLineRepairBill/getBarCodeInfo")]
|
[HttpGet]
|
public object getBarCodeInfo(string HBarCode)
|
{
|
try
|
{
|
//查看权限
|
//if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
|
//{
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = "无查看权限!";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
//}
|
|
if(HBarCode == null || HBarCode == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "条形码不可为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
string sql = @"select a.*, b.HNumber HMaterNumber, b.HName HMaterName
|
from Gy_BarCodeBill AS a
|
LEFT OUTER JOIN Gy_Material AS b on a.HMaterID = b.HItemID
|
where HBarCode = '" + HBarCode + "'";
|
|
|
|
ds = oCN.RunProcReturn(sql, "Gy_BarCodeBill");
|
|
if(ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "该条码不存在!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "Sucess!";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
}
|
}
|