using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using Pub_Class;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Data.SqlClient;
|
using System.Web.Http;
|
using WebAPI.Models;
|
|
|
namespace WebAPI.Controllers
|
{
|
public class MES_ProcessCheckBill_PDAController : ApiController
|
{
|
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
private json objJsonResult = new json();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
DataSet ds;
|
|
#region 工序检验PDA新增保存
|
[Route("MES_ProcessCheckBill_PDA/ProcessCheckAddBill")]
|
[HttpPost]
|
public object ProcessCheckAddBill([FromBody] JObject oMain)
|
{
|
var _value = oMain["oMain"].ToString();
|
string msg1 = _value.ToString();
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
try
|
{
|
//反序列化
|
string msg2 = "[" + sArray[0].ToString() + "]";
|
string user = sArray[1].ToString();//用户名
|
string OperationType = sArray[2].ToString();//类型
|
string msg_entry = sArray[3].ToString(); //明细行信息
|
|
//判断是否有编辑权限
|
if (!DBUtility.ClsPub.Security_Log("QC_ProcessCheckBill_Edit", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无编辑权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
DAL.ClsQC_ProcessCheckBill BillNew = new DAL.ClsQC_ProcessCheckBill();
|
|
List<Model.ClsQC_ProcessCheckBillMain> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsQC_ProcessCheckBillMain>>(msg2);
|
string BillType = "7507";
|
string HBillSubType = "7507";
|
long HInterID = list[0].HInterID;//递入type得到的单据ID
|
string HBillNo = list[0].HBillNo;//递入type得到的单据号
|
int HBillStatus = 1;
|
string HMaker = user;//制单人
|
int HYear = DateTime.Now.Year;
|
double HPeriod = DateTime.Now.Month;
|
long HSourceID = list[0].HSourceID;//生产资源
|
long HICMOInterID = list[0].HICMOInterID;//任务单ID
|
long HICMOEntryID = list[0].HICMOEntryID;//任务单子ID
|
string HICMOBillNo = list[0].HICMOBillNo;//任务单
|
string HProcExchBillNo = list[0].HProcExchBillNo;//指引卡
|
long HMaterID = list[0].HMaterID;//产品ID
|
//long HUnitID = list[0].HUnitID;//计量单位
|
long HProcID = list[0].HProcID;//工序ID
|
long HPRDORGID = list[0].HPRDORGID;//组织ID
|
bool HLastResult = list[0].HLastResult;//试样结论
|
long HQCSchemeID = list[0].HQCSchemeID;//检验方案
|
Int64 HProcExchInterID = list[0].HProcExchInterID;//指引卡ID
|
Int64 HProcExchEntryID = list[0].HProcExchEntryID;//指引卡子ID
|
string HBatchNo = list[0].HBatchNo;//流转卡批次号
|
long HMainSourceInterID = list[0].HMainSourceInterID;//源单ID
|
long HMainSourceEntryID = list[0].HMainSourceEntryID;//源单子ID
|
string HMainSourceBillNo = list[0].HMainSourceBillNo;//源单单号
|
string HMainSourceBillType = list[0].HMainSourceBillType;//源单类型
|
|
//表体数据
|
List<Model.ClsQC_ProcessCheckBillSub> subList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsQC_ProcessCheckBillSub>>(msg_entry);
|
for (int i = 0; i < subList.ToArray().Length; i++)
|
{
|
if (subList.ToArray().Length >= 0)
|
{
|
Model.ClsQC_ProcessCheckBillSub oSub = new Model.ClsQC_ProcessCheckBillSub();
|
oSub.HEntryID = i + 1;
|
oSub.HRemark = ClsPub.isStrNull(subList[i].HRemark);
|
oSub.HSourceInterID = ClsPub.isLong(subList[i].HSourceInterID);
|
oSub.HSourceEntryID = ClsPub.isLong(subList[i].HSourceEntryID);
|
oSub.HSourceBillType = ClsPub.isStrNull(subList[i].HSourceBillType);
|
oSub.HSourceBillNo = ClsPub.isStrNull(subList[i].HSourceBillNo);
|
oSub.HRelationQty = DBUtility.ClsPub.isDoule(subList[i].HRelationQty);
|
oSub.HRelationMoney = DBUtility.ClsPub.isDoule(subList[i].HRelationMoney);
|
oSub.HCloseMan = DBUtility.ClsPub.isStrNull(subList[i].HCloseMan);
|
oSub.HCloseType = DBUtility.ClsPub.isBool(subList[i].HCloseType);
|
oSub.HQCCheckItemID = DBUtility.ClsPub.isLong(subList[i].HQCCheckItemID);
|
oSub.HQCStd = DBUtility.ClsPub.isStrNull(subList[i].HQCStd);
|
oSub.HResult = DBUtility.ClsPub.isStrNull(subList[i].HResult);
|
oSub.HQCRelValue = DBUtility.ClsPub.isStrNull(subList[i].HQCRelValue);
|
//oSub.HProcCheckTime = HDate;
|
//oSub.HBillNo_bak = DBUtility.ClsPub.isStrNull(mainList[0].HBillNo);
|
//oSub.HProcCheckEmp = ClsPub.isLong(mainList[0].HFirstCheckEmp);
|
oSub.HSampleSchemeID = DBUtility.ClsPub.isLong(subList[i].HSampleSchemeID);
|
oSub.HSampleQty = DBUtility.ClsPub.isLong(subList[i].HSampleQty);
|
oSub.HSampleDamageQty = DBUtility.ClsPub.isDoule(subList[i].HSampleDamageQty);
|
oSub.HAcceptQty = DBUtility.ClsPub.isLong(subList[i].HAcceptQty);
|
oSub.HRejectQty = DBUtility.ClsPub.isLong(subList[i].HRejectQty);
|
oSub.HSampleUnRightQty = DBUtility.ClsPub.isDoule(subList[i].HSampleUnRightQty);
|
oSub.HStatus = DBUtility.ClsPub.isStrNull(subList[i].HStatus);
|
oSub.HUnitID = DBUtility.ClsPub.isLong(subList[i].HUnitID);
|
oSub.HInspectVal = DBUtility.ClsPub.isStrNull(subList[i].HInspectVal);
|
oSub.HTargetVal = DBUtility.ClsPub.isStrNull(subList[i].HTargetVal);
|
oSub.HUpLimit = DBUtility.ClsPub.isStrNull(subList[i].HUpLimit);
|
oSub.HDownLimit = DBUtility.ClsPub.isStrNull(subList[i].HDownLimit);
|
oSub.HUpOffSet = DBUtility.ClsPub.isStrNull(subList[i].HUpOffSet);
|
oSub.HDownOffSet = DBUtility.ClsPub.isStrNull(subList[i].HDownOffSet);
|
oSub.HAnalysisMethod = DBUtility.ClsPub.isStrNull(subList[i].HAnalysisMethod);
|
oSub.HKeyInspect = DBUtility.ClsPub.isLong(subList[i].HKeyInspect);
|
oSub.HInspectInstruMentID = DBUtility.ClsPub.isLong(subList[i].HInspectInstruMentID);
|
oSub.HInspectResult = DBUtility.ClsPub.isStrNull(subList[i].HResult == "True" ? 1 : 0);
|
|
oSub.HQCNote = DBUtility.ClsPub.isStrNull(subList[i].HQCNote);//检验记录
|
oSub.HMax = DBUtility.ClsPub.isStrNull(subList[i].HMax);
|
oSub.HMin = DBUtility.ClsPub.isStrNull(subList[i].HMin);
|
oSub.HAvg = DBUtility.ClsPub.isStrNull(subList[i].HAvg);
|
|
BillNew.DetailColl.Add(oSub);
|
}
|
else
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无明细行信息!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
|
//单据完整性判断
|
if (HProcExchBillNo == "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "流转卡没有选择!请扫描条形码或输入条形码后回车";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
var num = 0;
|
|
oCN.BeginTran();
|
if (OperationType == "1")
|
{
|
num = 1;
|
|
ds = oCN.RunProcReturn("select * from QC_ProcessCheckBillMain where HBillNo='" + HBillNo + "'", "QC_ProcessCheckBillMain");
|
if (ds.Tables[0].Rows.Count == 1)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据号重复!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
oCN.RunProc("Insert Into QC_ProcessCheckBillMain " +
|
"(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
|
",HYear,HPeriod,HMaterID,HSourceID,HICMOInterID,HICMOEntryID,HICMOBillNo,HProcExchBillNo" +
|
",HPRDORGID,HLastResult,HProcExchInterID,HProcExchEntryID,HProcID,HQCSchemeID,HBatchNo," +
|
"HMainSourceInterID,HMainSourceEntryID,HMainSourceBillNo,HMainSourceBillType)" +
|
" values('" + BillType + "','" + HBillSubType + "'," + HInterID + ",'" + HBillNo + "'," + HBillStatus + ",getdate(),'" + HMaker + "',getdate()" +
|
"," + HYear + "," + HPeriod + ",'" + HMaterID + "','" + HSourceID + "'," + HICMOInterID + "," + HICMOEntryID + ",'" + HICMOBillNo + "','" + HProcExchBillNo + "'" +
|
"," + HPRDORGID + ",'" + HLastResult + "'," + HProcExchInterID + "," + HProcExchEntryID + ",'" + HProcID + "','" + HQCSchemeID + "','" + HBatchNo + "'" +
|
"," + HMainSourceInterID + "," + HMainSourceEntryID + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'" + ") ");
|
|
//插入子表
|
foreach (Model.ClsQC_ProcessCheckBillSub oSub in BillNew.DetailColl)
|
{
|
oCN.RunProc("Insert into QC_ProcessCheckBillSub " +
|
" (HInterID,HBillNo_bak,HEntryID" +
|
",HRemark,HSourceInterID" +
|
",HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney" +
|
",HQCCheckClassID,HQCCheckItemID,HQCStd,HQCRelValue,HResult" +
|
",HProcCheckEmp,HProcCheckTime,HStatus,HUnitID,HKeyInspect,HAnalysisMethod,HInspectInstruMentID,HInspectResult" +
|
",HQCNote,HMax,HMin,HAvg" +
|
") values("
|
+ HInterID.ToString() + ",'" + oSub.HBillNo_bak + "'," + oSub.HEntryID.ToString() + ",'" + oSub.HRemark + "'," + HMainSourceInterID.ToString() +
|
"," + HMainSourceEntryID.ToString() + ",'" + HMainSourceBillNo + "','" + HMainSourceBillType + "'," + oSub.HRelationQty.ToString() + "," + oSub.HRelationMoney.ToString() +
|
"," + oSub.HQCCheckClassID.ToString() + "," + oSub.HQCCheckItemID.ToString() + ",'" + oSub.HQCStd + "','" + oSub.HQCRelValue + "','" + oSub.HResult + "'" +
|
"," + oSub.HProcCheckEmp.ToString() + ",GETDATE()" + ",'" + oSub.HStatus +
|
"'," + oSub.HUnitID + "," + oSub.HKeyInspect + ",'" + oSub.HAnalysisMethod + "'," + oSub.HInspectInstruMentID + ",'" + oSub.HInspectResult + "'" +
|
", '" + oSub.HQCNote + "', '" + oSub.HMax + "', '" + oSub.HMin + "', '" + oSub.HAvg + "'" +
|
") ");
|
}
|
}
|
else
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "操作类型无效!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.Commit();
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "新增单据成功!";
|
objJsonResult.data = ds.Tables[0];
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 工序检验_PDA 查询列表
|
[Route("ProcessCheck/ProcessCheckList")]
|
[HttpGet]
|
public object ProcessCheckList(string sWhere, string user)
|
{
|
try
|
{
|
|
//判断是否有编辑权限
|
if (!DBUtility.ClsPub.Security_Log("QC_ProcessCheckBill_Query", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无查询权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select ManagerFlag from gy_czygl where czymc='" + user.Trim() + "'", "gy_czygl");
|
if (!(bool)ds.Tables[0].Rows[0]["ManagerFlag"]) //是否管理员
|
{
|
//不是管理员
|
sWhere += " and 制单人 = '" + user + "'";
|
}
|
|
string sql = "select * from h_v_QC_ProcessCheckBillMainList where 1=1 " + sWhere + " order by 日期 ";
|
|
ds = oCN.RunProcReturn(sql, "h_v_QC_ProcessCheckBillMainList");
|
|
DataTable dt = ds.Tables[0];
|
|
//获取列名
|
List<object> columnNameList = new List<object>();
|
//添加列名
|
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.list = columnNameList;
|
objJsonResult.data = dt;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "Exception!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 工序检验_PDA 删除功能
|
[Route("ProcessCheck/DelProcessCheckBill")]
|
[HttpGet]
|
public object DelProcessCheckBill(Int64 lngBillKey, string user)
|
{
|
DataSet ds;
|
string ModRightNameCheck = "QC_ProcessCheckBill_Delete";
|
try
|
{
|
//删除权限
|
if (!DBUtility.ClsPub.Security_Log(ModRightNameCheck, 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "删除失败!无权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
if (lngBillKey == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据id为空!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
|
oCN.BeginTran();//开始事务
|
ds = oCN.RunProcReturn("select * from QC_ProcessCheckBillMain where HInterID=" + lngBillKey, "QC_ProcessCheckBillMain");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "没有数据,无法删除!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
}
|
string HChecker = Convert.ToString(ds.Tables[0].Rows[0]["HChecker"]);
|
if (HChecker != "")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "单据已经审核,不能删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.RunProc("delete from QC_ProcessCheckBillMain where HInterID=" + lngBillKey);
|
|
oCN.Commit();//提交事务
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "* 数据删除成功!";
|
objJsonResult.data = null;
|
return objJsonResult; ;
|
|
}
|
catch (Exception e)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "删除失败!" + e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
}
|
}
|