using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using Tools;
using WebService.Model;
namespace Webservice
{
///
/// WMSWebService 的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class WMSWebService : System.Web.Services.WebService
{
[WebMethod]
public string ConnectTest()
{
return "Connection is Ready.";
}
///
/// 调用WMS接口03
/// 喷涂合格入库
///
/// 条码号:A2048856739-P.190605.0008(二维码)
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void WMSSprayingForApp(string barcode)
{
string errorReason = "";
JsonModel model = new JsonModel();
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = errorReason;
model.DataList = null;
#region 参数判断
if (string.IsNullOrWhiteSpace(barcode))
{
model.ErrReason = "条码号不能为空";
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
string stcokNo = "";
string batchNo = "";
string partNo = "";
string colorName = string.Empty;
string productName = string.Empty;
string carType = string.Empty;
Function.GetCode(barcode, out stcokNo, out batchNo, out partNo);
if (string.IsNullOrWhiteSpace(stcokNo) && string.IsNullOrWhiteSpace(partNo))
{
model.ErrReason = "条码号无效,请检查条码是否破损缺失";
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
#endregion
//string res = Function.WMSSpraying("60000000562010090015", 1, "6000000056", "86511-BU020RBC", "210721");
string res = Function.WMSSpraying(barcode, 1, stcokNo, partNo, batchNo, ref colorName, ref productName, ref carType);
LogHelper.WriteSysLogBase("WMS接口:条码:" + barcode + ",MES返回结果:" + res, MethodBase.GetCurrentMethod().Name);
Context.Response.Write(res);
}
///
/// 调用WMS接口03
/// 喷涂报废接口
///
/// 条码号:A2048856739-P.190605.0008(二维码)
/// 0-不合格;1-合格;
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public bool WMSSprayingForCS(string barcode, int isOK, out string errorReason)
{
LogHelper.WriteSysLogBase("【WMS报废调入MES接口】条码:" + barcode, MethodBase.GetCurrentMethod().Name);
errorReason = "";
//return true;
if (string.IsNullOrWhiteSpace(barcode))
{
//model.ErrReason = "条码号不能为空";
//Context.Response.Write(JSONTools.ScriptSerialize>(model));
errorReason = "条码号不能为空";
return false;
}
bool sendRst = true;
string stcokNo = "";
string batchNo = "";
string partNo = "";
string colorName = string.Empty;
string productName = string.Empty;
string carType = string.Empty;
try
{
sendRst = SendToWmsService(barcode, ref stcokNo, ref batchNo, ref partNo, ref colorName, ref productName, ref carType);
errorReason = "";
return sendRst;
}
catch (Exception ex)
{
errorReason = ex.Message;
LogHelper.WriteSysLogBase("【WMS报废调入MES接口】条码:" + barcode + ",报错:" + errorReason, MethodBase.GetCurrentMethod().Name);
return false;
}
}
///
/// 喷涂下线
///
///
///
[WebMethod(EnableSession = true)]
public string PaintLineDown(string barCode)
{
bool sendRst = true;
string colorName = string.Empty;
string productName = string.Empty;
string carType = string.Empty;
string stcokNo = string.Empty;
string batchNo = string.Empty;
string partNo = string.Empty;
try
{
sendRst = SendToWmsService(barCode, ref stcokNo, ref batchNo, ref partNo, ref colorName, ref productName, ref carType);
if (sendRst == true)
{
Function.SaveLineDownInfo(barCode, carType, colorName, productName);
if (Context.Session["LastBarCode"] != null)
{
if (ExsitBarCode(Context.Session["LastBarCode"].ToString()) == false)
{
Function.SaveLineDownInfo(Context.Session["LastBarCode"].ToString(), Context.Session["LastCarType"].ToString(), Context.Session["LastColorName"].ToString(), Context.Session["LastProductName"].ToString());
}
}
Context.Session["LastBarCode"] = barCode;
Context.Session["LastCarType"] = carType;
Context.Session["LastColorName"] = colorName;
Context.Session["LastProductName"] = productName;
return "操作成功!";
}
else
{
return "发送到WMS接口失败,请重新操作.";
}
}
catch (Exception ex)
{
return ex.Message;
}
}
///
/// 下悬挂链记录,是否存在该条码
///
///
///
private bool ExsitBarCode(string barCode)
{
return Function.ExsitBarCodeInDownRecord(barCode);
}
bool SendToWmsService(string barCode, ref string stcokNo, ref string batchNo, ref string partNo, ref string colorName, ref string productName, ref string carType)
{
string errorMsg = string.Empty;
string errorReason = "";
//return true;
#region 参数判断
if (string.IsNullOrWhiteSpace(barCode))
{
throw new Exception("条码号不能为空");
}
Function.GetCode(barCode, out stcokNo, out batchNo, out partNo);
if (string.IsNullOrWhiteSpace(stcokNo) && string.IsNullOrWhiteSpace(partNo))
{
throw new Exception("条码号无效,请检查条码是否破损缺失");
}
#endregion
string res = Function.WMSSpraying(barCode, 1, stcokNo, partNo, batchNo, ref colorName, ref productName, ref carType);
JsonModel model = JSONTools.ScriptDeserialize>(res);
if (model.Result == "0")
{
throw new Exception(model.ErrReason);
}
return true;
}
///
/// 当WMS调拨入库时,即报废的产品再次入库,WMS传入条码,MES记录入库
///
///
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void AddStockInBarcode(string barcode)
{
string errorReason = "";
JsonModel model = new JsonModel();
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = errorReason;
model.DataList = null;
#region 参数判断
if (string.IsNullOrWhiteSpace(barcode))
{
model.ErrReason = "条码号不能为空";
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
#endregion
#region 保存入库记录
bool res = Function.AddStockInBarcode(barcode, out errorReason);
if (res == true)
{
model.Result = "1";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = "成功";
model.DataList = null;
}
else
{
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = "接收失败:" + errorReason;
model.DataList = null;
}
#endregion
LogHelper.WriteSysLogBase("【WMS报废再入库】入参:" + barcode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name);
Context.Response.Write(JSONTools.ScriptSerialize>(model));
}
///
/// 手持设备做质量判定
///
///
///
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void InsertInspect(string barcode, string InspectTimes)
{
string errorReason = "";
JsonModel model = new JsonModel();
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = errorReason;
model.DataList = null;
#region 参数判断
if (string.IsNullOrWhiteSpace(barcode))
{
model.ErrReason = "条码号不能为空";
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
if (string.IsNullOrWhiteSpace(InspectTimes))
{
model.ErrReason = "一次合格或抛光合格参数不能为空";
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
#endregion
#region 判断老外库里是否有该条码,有则返回颜色,没有则补打条码,直接入库
if (barcode.Contains("."))
{
barcode = Function.TransToBarCodeOne(barcode);
}
LogHelper.WriteSysLogBase("【手持设备质检判定】入参:barcode:" + barcode + ",InspectTimes:" + InspectTimes, MethodBase.GetCurrentMethod().Name);
bool exsitInLine = Function.ExistInLine(barcode);
if (!exsitInLine)
{
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = "喷涂线上找不到该条码,请补打条码后扫码入库,或在工位上附加颜色并进行质量判定";
model.DataList = null;
LogHelper.WriteSysLogBase("【手持设备质检判定】入参:barcode:" + barcode + ",InspectTimes:" + InspectTimes + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name);
Context.Response.Write(JSONTools.ScriptSerialize>(model));
return;
}
#endregion
#region 整理参数,保存质检结果
InspectModel InModel = new InspectModel();
InModel.ID = Guid.NewGuid().ToString();
InModel.barcode = barcode;
InModel.side = Function.GetSide(barcode); ;
InModel.position = "手持设备";
InModel.stationNo = "S20";
InModel.workClass = Function.GetWorkClass();
InModel.inspectResult = "[合格]";
InModel.productInfo = Function.GetProductInfo(barcode);
InModel.InspectTimes = InspectTimes;
InModel.productOption = "";
InModel.damnPosition = "";
InModel.defectID = "";
InModel.reason = "";
InModel.remark1 = "";
InModel.remark2 = "";
InModel.remark3 = "";
int res = Function.InsertInspect(InModel);
if (res > 0)
{
model.Result = "1";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = "成功";
model.DataList = null;
}
else
{
model.Result = "0";
model.ResultType = "Result";
model.ResultRowsCount = "0";
model.ErrReason = "失败";
model.DataList = null;
}
LogHelper.WriteSysLogBase("【手持设备质检判定】入参:barcode:" + barcode + ",InspectTimes:" + InspectTimes + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name);
Context.Response.Write(JSONTools.ScriptSerialize>(model));
#endregion
}
///
/// WMS入库接口-一码到底
///
///
///
///
///
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public bool WMSInterfaceStockIn(string barcode, string partNo, string batchNo, int isOK, int LineId)
{
bool res = false;
res = Function.WMSInterfaceStockIn(barcode, partNo, batchNo, isOK, LineId);
return res;
}
}
}