using DBUtility;
|
using Newtonsoft.Json;
|
using Newtonsoft.Json.Linq;
|
using SQLHelper;
|
using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.IO;
|
using System.Linq;
|
using System.Net;
|
using System.Net.Http;
|
using System.Web;
|
using System.Web.Http;
|
using System.Web.Script.Serialization;
|
using WebAPI.Code;
|
using WebAPI.Models;
|
using WebAPI.Utility;
|
|
namespace WebAPI.Controllers
|
{
|
public class SRM_MaterialBarCodeBillController : ApiController
|
{
|
private JsonResult objJsonResult = new JsonResult();
|
private json objjson = new json();
|
public new ClsCN oCn = new ClsCN();
|
//获取系统参数
|
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
|
// GET: SRM_MaterialBarCodeBill
|
#region 条码批量生辰
|
[Route("GetSRMHBarCodeShowBillMain")]
|
public object GetSRMHBarCodeShowBillMain(string HInterID)
|
{
|
try
|
{
|
DataSet ds;
|
string s = "";
|
string ShowItem = " * ";//显示的字段
|
//if (DBUtility.ClsPub.isLong(HInterID) == 0)
|
//{
|
// objjson.code = "0";
|
// objjson.count = 0;
|
// objjson.Message = "获取失败";
|
// objjson.data = null;
|
// return objjson;
|
//}
|
DAL.ClsWeb_BarCodeBill oClsWeb_BarCodeBill = new DAL.ClsWeb_BarCodeBill();
|
//string sql = string.Format(@"select * from h_v_Cg_POOrderBillMain_ForWeb2 where HInterID = " + sMsg);
|
string sql = string.Format(@"select * from h_v_SRM_BarCodeBill where HItemID in ( " + HInterID + ")");
|
ds = oCn.RunProcReturn(sql, "h_v_SRM_BarCodeBill");
|
//ds = oClsWeb_BarCodeBill.ShowBillMain1(DBUtility.ClsPub.isLong(sMsg), ShowItem, ref DBUtility.ClsPub.sExeReturnInfo);
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objjson.code = "0";
|
objjson.count = 0;
|
objjson.Message = "获取失败";
|
objjson.data = null;
|
return objjson;
|
}
|
else
|
{
|
|
objjson.code = "0";
|
objjson.count = 10000;
|
objjson.Message = "获取成功";
|
objjson.data = ds.Tables[0];
|
return objjson;
|
}
|
}
|
catch (Exception e)
|
{
|
objjson.code = "0";
|
objjson.count = 0;
|
objjson.Message = "获取失败" + e.ToString();
|
objjson.data = null;
|
return objjson;
|
}
|
}
|
#endregion
|
|
#region 条码保存
|
[Route("SRM_MaterialBarCodeBillController/GetBarcodeSaveBillBoxBycg")]
|
[HttpPost]
|
/// <summary>
|
/// 生成条码
|
/// </summary>
|
/// <param name="msg"></param>
|
/// <param name="msg2"></param>
|
/// <returns></returns>
|
public object GetBarcodeSaveBillBoxBycg([FromBody] JObject msg)
|
{
|
string FCusName = oSystemParameter.GetSingleSystemParameter("WMS_CampanyName", ref DBUtility.ClsPub.sExeReturnInfo);
|
var _value = msg["msg"].ToString();
|
string msg1 = _value.ToString();
|
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
string msg2 = sArray[0].ToString();//
|
string msg3 = sArray[1].ToString();//
|
string UserName = "";
|
ListModels oListModels = new ListModels();
|
try
|
{
|
#region 获取用户以及相关参数
|
List<Model.Cls_MaterialHandingModel> lsmain = new List<Model.Cls_MaterialHandingModel>();
|
msg2 = msg2.Replace("\\", "");
|
msg2 = msg2.Replace("\n", ""); //\n
|
lsmain = oListModels.getObjectByJson_MaterialHanding(msg2);
|
int get_BarCodecount = 0;
|
foreach (Model.Cls_MaterialHandingModel oItem in lsmain)
|
{
|
get_BarCodecount++;
|
UserName = oItem.HMaker;
|
}
|
DAL.ClsWeb_BarCodeBill oBill = new DAL.ClsWeb_BarCodeBill();
|
msg3 = msg3.Substring(1, msg3.Length - 2);
|
msg3 = msg3.Replace("\\", "");
|
msg3 = msg3.Replace("\n", ""); //\n
|
#endregion
|
List<Model.ClsGy_MaterialBarCodeBillModel> ls = new List<Model.ClsGy_MaterialBarCodeBillModel>();
|
|
ls = oListModels.getObjectByJson_BarCodeBill(msg3);//列表数据model
|
|
|
#region 数据准备
|
long linterid = Pub_Class.ClsPub.CreateBillID_SRMProd("8888", ref DBUtility.ClsPub.sExeReturnInfo);
|
int LSHlen = 6; //流水号长度
|
int SumLen = 10; //总长度
|
string TM = ""; //条码
|
double HSumQty = 0; //产品数量
|
int LSH = 0; //流水号
|
string LSH2 = ""; //流水号转换成字符
|
string sDate = ""; //日期
|
string sYear = ""; //年
|
string sPeriod = ""; //月
|
string sDay = ""; //日
|
string WeiShu = ""; //尾数
|
string HKFDQDate= ls[0].HKFDQDate;//到期日期
|
long HKFPeriod= (ls[0].HKFPeriod.ToString()==""?0: ls[0].HKFPeriod);//保质期
|
string HKFDate= ls[0].HKFDQDate==null? DateTime.Now.ToString("yyyy/MM/dd"): ls[0].HKFDQDate;//生产日期
|
string HKFDate_1 = string.Join("", HKFDate.Split('/').Select(x => x.PadLeft(2, '0')));
|
double HMinQty= ls[0].HMinQty;//标准包装数
|
|
double HBQty= ls[0].HBQty;//最小包装数
|
long HISKFPERIOD= ls[0].HISKFPERIOD;//是否启用保质期
|
long HBatchManager= ls[0].HBatchManager;//是否启用批号
|
|
string HSourceBillType= ls[0].HSourceBillType;//条码类型
|
|
string HBatchNo= ls[0].HBatchNo==null?"": ls[0].HBatchNo;//批号
|
//物料
|
long HMaterID=ls[0].HMaterID;
|
string HMaterNumber= ls[0].HMaterNumber;
|
string HMaterShortNumber = ls[0].HMaterShortNumber;
|
string HMaterName = ls[0].HMaterName;
|
//供应商
|
long HSupID= ls[0].HSupID;
|
string HSupName= ls[0].HSupName;
|
string HMaker= ls[0].HMaker;
|
DateTime HMakeDate= ls[0].HMakeDate;
|
double HQty= ls[0].HQty; //本次生成条码数量
|
double biaoqianzhangshu= ls[0].biaoqianzhangshu;
|
//流水号
|
DataSet Ds;
|
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
|
oCn.BeginTran();
|
Ds = oCn.RunProcReturn("exec GetLSH '" + DateTime.Today + "'", "GetLSH");
|
LSH = ClsPub.isInt(Ds.Tables[0].Rows[0][0]);
|
#endregion
|
|
foreach (Model.ClsGy_MaterialBarCodeBillModel oItemSub in ls)
|
{
|
//数量为0 跳过
|
if (oItemSub.HQty == 0 || oItemSub.HMinQty == 0 )
|
continue;
|
if(oItemSub.HBatchManager!=0&&oItemSub.HBatchNo=="")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "已启用批号,批号不能为空,请核对";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
if (oItemSub.HISKFPERIOD != 0 && oItemSub.HKFPeriod == 0)
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "已启用保质期,保质期不能为0,请核对";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
string sql = "";
|
//校验批号 和 生产日期
|
//string sql = $"select top 1 HKFDate from Gy_BarCodeBill where HSupID = '{oItemSub.HSupID}' and HBatchNo = '{HBatchNo.TrimStart().TrimEnd()}' and HMaterID ={oItemSub.HMaterID} and isnull(HKFDate, '') <> ''";
|
//LogService.Write($"sql:{sql}");
|
//DataTable dt = oCn.RunProcReturn(sql, "tables").Tables[0];
|
//if (dt.Rows.Count > 0)
|
//{
|
// LogService.Write($"HKFDate:{dt.Rows[0][0]}");
|
// sql = $"select DATEDIFF(D,{dt.Rows[0][0]},{HKFDate})";
|
// DataSet ds = oCn.RunProcReturn(sql, "tables2");
|
// LogService.Write($"DATEDIFF:{Convert.ToInt32(ds.Tables[0].Rows[0][0])}");
|
// if (ds.Tables[0].Rows.Count > 0 && Convert.ToInt32(ds.Tables[0].Rows[0][0]) != 0)
|
// {
|
// objJsonResult.code = "0";
|
// objJsonResult.count = 0;
|
// objJsonResult.Message = $"物料编码{oItemSub.HMaterNumber},批号{oItemSub.HBatchNo.TrimStart().TrimEnd()},生产日期为{dt.Rows[0][0]},请核对";
|
// objJsonResult.data = null;
|
// return objJsonResult;
|
// }
|
//}
|
if (ClsPub.isLong(oItemSub.HMaterID) != 0)
|
{
|
|
HMaterID = oItemSub.HMaterID;//物料代码
|
HQty = ClsPub.isDoule(oItemSub.HQty);//本次生成条码数量
|
HBQty = ClsPub.isInt(oItemSub.HBQty);//最小包装数(内箱数)
|
HMinQty = ClsPub.isDoule(oItemSub.HMinQty);//标准包装数
|
int virtualCount = 1;//实际上插入数量
|
// HSumQty = ClsPub.isDoule(oItemSub.HQty); //产品数量
|
for (int i = 0; i < biaoqianzhangshu; i++)
|
{
|
///供应商名称+@+物料代码+@+物料简称+@+数量+@+日期+@+流水号
|
LSH += 1;
|
TM = $"{oItemSub.HSupName}@{oItemSub.HMaterID}@{oItemSub.HMaterName}@{oItemSub.biaoqianzhangshu}@{HKFDate_1}@{LSH}";
|
Model.ClsGy_BarCodeBill_WMS_Model bar = new Model.ClsGy_BarCodeBill_WMS_Model();
|
|
// var HBarCode_verify = TM.Split('@'); //校验条码信息
|
// var HMaterNumber_verify = HBarCode_verify[0]; //校验物料编码
|
// var HMaterName_verify = HBarCode_verify[1]; //校验物料名称
|
// //var HMaterModel_verify = HBarCode_verify[2]; //校验规格型号
|
// var HSupName_verify = HBarCode_verify[7]; //校验供应商
|
//// var HSourceBillNo_verify = HBarCode_verify[8]; //校验采购订单号
|
|
// sql = $"select * from Gy_Material where HNumber = '{HMaterNumber_verify}' and HName = '{HMaterName_verify}'";
|
// DataSet verifyMatInfo = oCn.RunProcReturn(sql, "tables");
|
|
|
// sql = $"select * from Gy_Supplier where HName = '{HSupName_verify}'";
|
// DataSet verifySupInfo = oCn.RunProcReturn(sql, "tables");
|
string HBarCodeType = "唯一条码";
|
//sql = "insert into Gy_BarCodeBill (HInterID,HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HKFDate,HKFPeriod,HKFDQDate" +
|
// ",HBatchNo,HBarcodeQtys,HBarcodeNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HEndQty,HSupflag" +
|
// ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HMTONO,HProduceDate,HExpiryDate,HISKFPERIOD" +
|
// ") values ("
|
// + linterid.ToString() + ",'" + TM + "','" + HBarCodeType + "'," + HMaterID + "," + "" + "," + HQty + ",'" + HKFDate + "'," + HKFPeriod + ",'" + HKFDQDate
|
// + "','" + HBatchNo + "','" + get_BarCodecount + "','" + virtualCount + "'," + HSupID + "," + "" + ",'" + ClsPub.CurUserName + "','" + DateTime.Today + "'," + "1" + ",'" + DateTime.Today + "',1"
|
// + "," + "1" + "," + "1" + ",'" + "1" + "','" + HSourceBillType + "','" + "1" + "','"
|
// + HKFDate + "','" + HKFDQDate + "'," + HISKFPERIOD + ")";
|
sql = "INSERT INTO Gy_BarCodeBill (HInterID, HBarCode, HBarCodeType, HMaterID, HUnitID, HQty, HKFDate, HKFPeriod, HKFDQDate, " +
|
"HBatchNo, HBarcodeQtys, HBarcodeNo, HSupID, HGroupID, HMaker, HMakeDate, HPrintQty, HEndQty, HSupflag, " +
|
"HSourceInterID, HSourceEntryID, HSourceBillNo, HSourceBillType, HMTONO, HProduceDate, HExpiryDate, HISKFPERIOD) " +
|
"VALUES (" +
|
linterid.ToString() + ", '" + TM + "', '" + HBarCodeType + "', " + HMaterID + ", " + "0" + ", " + HQty + ", '" + HKFDate + "', " + HKFPeriod + ", '" + HKFDQDate + "', " +
|
"'" + HBatchNo + "', " + get_BarCodecount + ", '" + virtualCount + "', " + HSupID + ", " + "0" + ", '" + ClsPub.CurUserName + "', '" + DateTime.Today.ToString("yyyy-MM-dd") + "', " + "1" + ", " + "0" + ", 1, " +
|
"1, 1, '1', '" + HSourceBillType + "', '1', '" +
|
HKFDate + "', '" + HKFDQDate + "', " + HISKFPERIOD + ")";
|
LogService.Write("生成条码: " + sql);
|
oCn.RunProc(sql);
|
oCn.RunProc("exec setLSH '" + DateTime.Today + "'");
|
virtualCount++;
|
}
|
|
}
|
}
|
oCn.Commit();
|
|
}
|
catch (Exception e)
|
{
|
LogService.Write("生成条码发生错误: " + e);
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "" + e.Message + DBUtility.ClsPub.sExeReturnInfo;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "生成条码成功!";
|
WebAPIController.Add_Log("条码下推", UserName, "生成条码");
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
#endregion
|
|
#region 条码列表
|
[Route("showHBarCodeBillDetail")]
|
[HttpGet]
|
public object showHBarCodeBillDetail(string sMsg,string Organization)
|
{
|
try
|
{
|
DataSet ds;
|
string s = "";
|
string ShowItem = " * ";//显示的字段
|
if (sMsg == "")
|
{
|
objjson.code = "0";
|
objjson.count = 0;
|
objjson.Message = "获取失败";
|
objjson.data = null;
|
return objjson;
|
}
|
string sql = string.Format(@"select * from h_v_Gy_UserMaterRelationPrint where HItemID in ( " + sMsg)+")";
|
ds = oCn.RunProcReturn(sql, "h_v_Gy_UserMaterRelationPrint");
|
if (ds == null || ds.Tables[0].Rows.Count == 0)
|
{
|
objjson.code = "0";
|
objjson.count = 0;
|
objjson.Message = "获取失败" + DBUtility.ClsPub.sExeReturnInfo;
|
objjson.data = null;
|
return objjson;
|
}
|
else
|
{
|
objjson.code = "0";
|
objjson.count = 1;
|
objjson.Message = "获取成功!";
|
objjson.data = ds.Tables[0];
|
return objjson;
|
|
}
|
}
|
catch (Exception e)
|
{
|
objjson.code = "0";
|
objjson.count = 0;
|
objjson.Message = "获取单据表体失败:" + e.Message;
|
objjson.data = null;
|
return objjson;
|
}
|
}
|
#endregion
|
|
|
}
|
}
|