using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Kingdee.BOS.WebApi.Client;
namespace BLL
{
public class ClsKf_ProductInBill
{
///
/// 根据过滤条件,返回源单信息-生产任务单列表
///
/// 过滤条件
/// 错误信息
///
public DataSet GetSc_ICMOBillList(string sWhere, ref string sErr)
{
try
{
DAL.Cls_S_IF_ICMOBill_Lite dal = new DAL.Cls_S_IF_ICMOBill_Lite();
return dal.DisSourceBillList(sWhere);
}
catch (Exception e)
{
sErr = sErr + "," + e.Message;
return null;
}
}
public DataSet GetSc_ICMOReportBillList(string sWhere, ref string sErr)
{
try
{
DAL.Cls_S_IF_ICMOReportBill_Lite dal = new DAL.Cls_S_IF_ICMOReportBill_Lite();
return dal.DisSourceBillList(sWhere);
}
catch (Exception e)
{
sErr = sErr + "," + e.Message;
return null;
}
}
#region 产品入库CLOUD 多源单
//生成产品入库单 多源单
public bool set_SaveProductInBill_MulSource_CLD(Model.ClsKf_ProductInBillMain oMain, ref string sHBillNo, ref string sErrMsg)
{
sHBillNo = oMain.HBillNo;
//获取系统参数
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
if (oSystemParameter.ShowBill(ref sErrMsg) == false)
{
sErrMsg = "获取系统参数失败! " + sErrMsg;
return false;
}
//
if (oSystemParameter.omodel.Kf_ProductInBill_ERPMode.ToUpper() == "CLOUD") //判断同步模式是金蝶CLOUD
{
if (SaveProductInBill_MulSource_CLD(oMain, oSystemParameter.omodel, ref sHBillNo, ref sErrMsg))
{
//"保存成功!";
sErrMsg = "保存成功!" + sHBillNo;
return true;
}
else
{
//"保存失败!";
sErrMsg = sErrMsg;
return false;
}
}
sErrMsg = "同步模式设置错误,保存产品入库单失败!" + sErrMsg;
return false;
}
///
/// 产品入库单 多源单
///
///
///
///
public bool SaveProductInBill_MulSource_CLD(Model.ClsKf_ProductInBillMain oMain, Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain, ref string sHBillNo, ref string sErrMsg)
{
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
try
{
string sJson_Main_PL = "";
string sJson_Model_PL = "";
string sJson_Entry_PL = "";
string sJson_End_PL = "";
string HBillNo_PL = "";
string HBillNo = "";
long HOrgID = 0;
DataSet Ds;
DataSet Ds1;
//写入WMS产品入库单
oCn.BeginTran();
//插入子表
oCn.RunProc("EXEC h_p_Kf_ProductInBillSub_Insert " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'");
//插入主表
oCn.RunProc("Insert Into Kf_ICStockBillMain " +
"(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMainSourceBillType" +
",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
",HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
",HKeeperID,HDeptID,HExplanation,HInnerBillNo,HRedBlueFlag" +
") " +
" values('1202','1202'," + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "',convert(varchar(10),getdate(),120),'" + oMain.HMainSourceBillType + "'" +
",2012,1,'" + oMain.HRemark + "','" + oMain.HMaker + "',convert(varchar(10),getdate(),120)" +
", " + oMain.HSupID.ToString() + "," + oMain.HWHID.ToString() + "," + oMain.HSCWHID.ToString() + "," + oMain.HEmpID.ToString() + "," + oMain.HManagerID.ToString() + "," + oMain.HSecManagerID.ToString() +
", " + oMain.HKeeperID.ToString() + "," + oMain.HDeptID.ToString() + ",'" + oMain.HExplanation + "','" + oMain.HInnerBillNo + "'," + DBUtility.ClsPub.BoolToString(oMain.HRedBlueFlag) +
") ");
//更新关联数量
oCn.RunProc("exec h_p_Sc_UpDateICMORelation_Add " + oMain.HInterID.ToString());
if (oSystemParameterMain.Kf_ProductInBill_AutoCheck == "Y") //系统参数 自动审核
{
//审核单据
oCn.RunProc("Update Kf_ICStockBillMain Set HChecker='" + oMain.HMaker + "',HCheckDate=convert(varchar(10),getdate(),120),HBillStatus=2 where HInterID= " + oMain.HInterID.ToString());
}
//根据单据ID获取扫描的组织有哪几个
string tt = "";
Ds1 = oCn.RunProcReturn("exec h_p_Kf_GetOrgIDByTemp_CLD " + oMain.HInterID.ToString(), "h_p_Kf_GetOrgIDByTemp_CLD");
if (Ds1 == null || Ds1.Tables[0].Rows.Count == 0)
{
sErrMsg = "获取子表信息失败!";
oCn.RollBack();
return false;
}
else
{
sJson_Main_PL = "{\"NumberSearch\":\"true\",\"ValidateFlag\":\"true\",\"IsDeleteEntry\":\"true\"," +
"\"IsEntryBatchFill\":\"false\",\"NeedUpDateFields\":[],\"NeedReturnFields\":[], \"SubSystemId\": \"\"," +
"\"InterationFlags\": \"\",\"IsAutoSubmitAndAudit\":\"false\", \"Model\":[";
for (int y = 0; y < Ds1.Tables[0].Rows.Count; y++)
{
HOrgID = Pub_Class.ClsPub.isLong(Ds1.Tables[0].Rows[y][0]);
//根据TMP表 返回 子表信息
Ds = oCn.RunProcReturn("exec h_p_Kf_GetProductInBillByOrgID_CLD " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'," + HOrgID.ToString(), "h_p_Kf_GetProductInBillByOrgID_CLD");
if (Ds == null || Ds.Tables[0].Rows.Count == 0 || Ds.Tables[1].Rows.Count == 0)
{
sErrMsg = "获取子表信息失败!";
continue;
//return false;
}
else
{
if (sJson_Model_PL != "")
{
sJson_Model_PL = sJson_Model_PL + ",";
}
int s = y + 1;
HBillNo = oMain.HBillNo + "-" + s;
sJson_Model_PL = sJson_Model_PL + "{ \"FBILLNO\":\"" + HBillNo + "\"," +
/*\"FID\":\"" + oMain.HInterID.ToString() + "\"," +*/
"\"FStockOrgId\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HStockORGID"]) + "\"}, " +
"\"FPRDORGID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HPRDORGID"]) + "\"}, " +
"\"FOwnerId0\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOWNERID"]) + "\"}," +
"\"FBillType\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FBillType"]) + "\" " +
" }, \"FEntity\": [ ";
sJson_Entry_PL = "";
for (int i = 0; i < Ds.Tables[1].Rows.Count; i++)
{
if (sJson_Entry_PL != "")
{
sJson_Entry_PL = sJson_Entry_PL + " , ";
}
string sJson_BatchNo = "";
string sJson_StockPlace = "";
string sJson_Custom = ""; //韩电
if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HISBATCHMANAGE"]) == "1") //是否启用批次管理
{
sJson_BatchNo = " \"FLOT\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\"}, \"FLOT_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\" , ";
}
else
{
sJson_BatchNo = "";
}
if (oSystemParameterMain.WMS_CampanyName == "韩电") //系统参数 客户定制化名称 空白为通用 仓位
{
if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) == "")
{
sJson_StockPlace = "";
}
else
{
sJson_StockPlace = Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}},";
}
sJson_Custom = " \"F_QOUL_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_QOUL_TEXT"]) + "\", "; //销售订单号
}
else
{
if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) == "")
{
sJson_StockPlace = "";
}
else
{
sJson_StockPlace = Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}},";
}
}
sJson_Entry_PL = sJson_Entry_PL + " { \"FOWNERID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HOWNERID"]) + "\"}," +
// "\"FSEQ\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSEQ"]) + "\", " +
" \"FBFLOWID\":{\"FID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FBFLOWID"]) + "\"} , " +
" \"FMOBILLNO\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOBILLNO"]) + "\" , " +
" \"FMOID\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOID"]) + "\" , " +
" \"FMOENTRYID\" : " + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOENTRYID"]) + " , " +
" \"FMOENTRYSEQ\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOENTRYSEQ"]) + "\" , " +
// " \"F_PAEZ_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_PAEZ_TEXT"]) + "\", " +
" \"FSRCBILLTYPE\" : \"PRD_MO\" , \"FSRCBILLNO\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCBILLNO"]) + "\" , " +
" \"FSRCINTERID\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCINTERID"]) + "\" , " +
" \"FSRCENTRYID\" : " + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCENTRYID"]) + " , " +
" \"FSRCENTRYSEQ\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCENTRYSEQ"]) + "\" , " +
" \"FMATERIALID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMATERIALID"]) + "\"} , " +
" \"FInStockType\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FInStockType"]) + "\"," +
" \"FWORKSHOPID1\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FWORKSHOPID"]) + "\"}," +
" \"FUNITID\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FUNITID"]) + "\"}," +
" \"FBASEUNITID\" : {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FBASEUNITID"]) + "\"} , " +
" \"FSTOCKID\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSTOCKID"]) + "\"}, " +
sJson_StockPlace +
//"\"FStockLocId\":{\"FSTOCKLOCID__FF100002\":{\"FNUMBER\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}}," +
" \"FPRODUCTTYPE\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FPRODUCTTYPE"]) + "\" , " +
" \"FMUSTQty\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMUSTQty"]) + "\", " +
" \"FRealQty\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FRealQty"]) + "\", " +
" \"FCOSTRATE\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FCOSTRATE"]) + "\", " +
sJson_BatchNo +
//"\"FLot\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLot"]) + "\"}," +
" \"FMOMAINENTRYID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOMAINENTRYID"]) + "\" , " +
" \"FREQSRC\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQSRC"]) + "\" , " +
" \"FREQBILLID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQBILLID"]) + "\" , " +
" \"FREQBILLNO\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQBILLNO"]) + "\" , " +
" \"FREQENTRYID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQENTRYID"]) + "\" , " +
" \"FREQENTRYSEQ\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQENTRYSEQ"]) + "\" , " +
sJson_Custom +
" \"FEntity_Link\": [ { " +
" \"FEntity_Link_FFlowId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FFlowId"]) + "\" , " +
" \"FEntity_Link_FFlowLineId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FFlowLineId"]) + "\" , " +
" \"FEntity_Link_FRuleId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FRuleId"]) + "\" , " +
" \"FEntity_Link_FSTableName\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FSTableName"]) + "\" , " +
" \"FEntity_Link_FSBillId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FSBillId"]) + "\" , " +
" \"FEntity_Link_FSId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HICMOEntryID"]) + "\" " +
" } ]} ";
}
sJson_Entry_PL = sJson_Entry_PL + "]}";
sJson_Model_PL = sJson_Model_PL + sJson_Entry_PL;
//单据号
if (HBillNo_PL != "")
{
HBillNo_PL = HBillNo_PL + " , ";
}
HBillNo_PL = HBillNo_PL + "'" + HBillNo + "'";
}
sHBillNo = HBillNo_PL;
///////////////////
}
sJson_End_PL = " ], \"BatchCount\":\"0\"}";
string sJson = sJson_Main_PL + sJson_Model_PL + sJson_End_PL;
tt = tt + HBillNo_PL + "----";
//
//生成 入库单
//从配置文件获取 CLOUD网址、账套信息、登录用户、登录密码
if (!Pub_Class.ClsPub.GetCLOUDLoginInfo(ref Pub_Class.ClsPub.sExeReturnInfo))
{
sErrMsg = Pub_Class.ClsPub.sExeReturnInfo;
return false;
}
//生成 入库单
string HReturn;
ApiClient client = new ApiClient(Pub_Class.ClsPub.sCLOUDUrl);
string dbId = Pub_Class.ClsPub.sCLOUDAcc; //AotuTest117
bool bLogin = client.Login(dbId, Pub_Class.ClsPub.sCLOUDUseName, Pub_Class.ClsPub.sCLOUDPsd, 2052);
if (bLogin)
{
var result = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.BatchSave",
new object[] { "PRD_INSTOCK", sJson }); //调用保存方式
if (oSystemParameterMain.Kf_ProductInBill_AutoCheck == "Y") //系统参数 自动审核
{
string sJson2 = "{\"CreateOrgId\":0,\"Numbers\":[" + HBillNo_PL + "]}";
var result2 = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit",
new object[] { "PRD_INSTOCK", sJson2 }); //提交单据
string sJson3 = "{\"CreateOrgId\":0,\"Numbers\":[" + HBillNo_PL + "]}";
var result3 = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit",
new object[] { "PRD_INSTOCK", sJson3 }); //审核单据
HReturn = result.ToString() + "," + result2.ToString() + "," + result3.ToString();
}
else
{
HReturn = result.ToString();
}
if (HReturn.Contains("\"IsSuccess\":false") == true)
{
sErrMsg = sErrMsg + "产品入库单失败!" + HReturn + "999" + tt + "888" + sJson;
oCn.RollBack();
return false;
}
else
{
sErrMsg = sErrMsg + "999" + tt + "888" + HReturn;
oCn.Commit();
return true;
}
}
else
{
sErrMsg = sErrMsg + "产品入库单失败!登录失败!";
oCn.RollBack();
return false;
}
sErrMsg = sErrMsg + "999" + tt + "888" + HReturn;
return true;
}
}
catch (Exception e)
{
sErrMsg = sErrMsg + "产品入库单失败!" + e.Message;
return false;
}
}
#endregion
#region 产品入库 *
//生成产品入库单
public bool set_SaveProductInBill_New(Model.ClsKf_ProductInBillMain oMain, string sHSourceType, ref string sErrMsg)
{
//获取系统参数
Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
if (oSystemParameter.ShowBill(ref sErrMsg) == false)
{
sErrMsg = "获取系统参数失败! " + sErrMsg;
return false;
}
//
if (oSystemParameter.omodel.Kf_ProductInBill_ERPMode.ToUpper() == "WISE") //判断同步模式是金蝶WISE
{
if (SaveProductInBill_K3(oMain, sHSourceType, oSystemParameter.omodel, ref sErrMsg))
{
//"保存成功!";
sErrMsg = "保存成功!" + oMain.HBillNo;
return true;
}
else
{
//"保存失败!";
sErrMsg = sErrMsg;
return false;
}
}
if (oSystemParameter.omodel.Kf_ProductInBill_ERPMode.ToUpper() == "CLOUD") //判断同步模式是金蝶CLOUD
{
if (set_SaveProductInBill_CLD(oMain, sHSourceType, oSystemParameter.omodel, ref sErrMsg) == true)
{
//"保存成功!";
return true;
}
else
{
//"保存失败!";
return false;
}
}
sErrMsg = "保存产品入库单失败!" + sErrMsg;
return false;
}
#endregion
#region 产品入库K3 *
///
/// 生成产品入库单K3
///
///
///
///
public bool SaveProductInBill_K3(Model.ClsKf_ProductInBillMain oMain, string sHSourceType, Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain, ref string sErrMsg)
{
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
DAL.ClsKf_ProductInBill dal = new DAL.ClsKf_ProductInBill();
dal.omodel = oMain;
//上传前必填项判断
if (oMain.HDeptID == 0)
{
sErrMsg = "部门没有选择!";
return false;
}
if (oMain.HSecManagerID == 0)
{
sErrMsg = "验收没有选择!";
return false;
}
if (oMain.HKeeperID == 0)
{
sErrMsg = "保管没有选择!";
return false;
}
try
{
//判断会计期是否合理
string s = "";
int sYear = 0;
int sPeriod = 0;
if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(oMain.HDate, ref sYear, ref sPeriod, ref s) == false)
{
sErrMsg = s;
return false;
}
oMain.HYear = sYear;
oMain.HPeriod = sPeriod;
DataSet Ds;
oCn.BeginTran();
//生成出入库单据
//插入子表
oCn.RunProc("EXEC h_p_Kf_ProductInBillSub_Insert_New " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "','" + sHSourceType + "'");
//插入主表
oCn.RunProc("Insert Into Kf_ICStockBillMain " +
"(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMainSourceBillType" +
",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
",HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
",HKeeperID,HDeptID,HExplanation,HInnerBillNo,HRedBlueFlag" +
") " +
" values('1202','1202'," + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "',convert(varchar(10),getdate(),120),'" + oMain.HMainSourceBillType + "'" +
", " + oMain.HYear.ToString() + "," + oMain.HPeriod.ToString() + ",'" + oMain.HRemark + "','" + oMain.HMaker + "',convert(varchar(10),getdate(),120)" +
", " + oMain.HSupID.ToString() + "," + oMain.HWHID.ToString() + "," + oMain.HSCWHID.ToString() + "," + oMain.HEmpID.ToString() + "," + oMain.HManagerID.ToString() + "," + oMain.HSecManagerID.ToString() +
", " + oMain.HKeeperID.ToString() + "," + oMain.HDeptID.ToString() + ",'" + oMain.HExplanation + "','" + oMain.HInnerBillNo + "'," + DBUtility.ClsPub.BoolToString(oMain.HRedBlueFlag) +
") ");
//新增K3子表、主表
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_Insert_New " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'," + oMain.HBillerID.ToString() + ",'" + sHSourceType + "'");
//更新关联数量
if (sHSourceType == "3710") //生产任务单
{
oCn.RunProc("exec h_p_Sc_UpDateRelation_ICMOToProductIn_Add " + oMain.HInterID.ToString());
//回填K3关联数量
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_UpdateBillRelateData_ICMO_New " + oMain.HInterID.ToString());
}
else //无源单
{
//回填K3关联数量
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_UpdateBillRelateData_New " + oMain.HInterID.ToString());
}
//审核单据
if (oSystemParameterMain.Kf_ProductInBill_AutoCheck == "Y") //系统参数 自动审核
{
//审核单据
oCn.RunProc("Update Kf_ICStockBillMain Set HChecker='" + oMain.HMaker + "',HCheckDate=convert(varchar(10),getdate(),120) where HInterID= " + oMain.HInterID.ToString());
//审核K3单据
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_Check_New " + oMain.HInterID.ToString() + "," + oMain.HBillerID.ToString());
//更新K3库存
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_UpdateStock_New " + oMain.HInterID.ToString());
oCn.RunProc("exec h_p_IFK3_ToERP_ProductInBill_UpdateOrderStock_New " + oMain.HInterID.ToString());
}
sErrMsg = "新增单据成功!";
oCn.Commit();
return true;
}
catch (Exception e)
{
sErrMsg = "生成产品入库单失败!" + e.Message;
oCn.RollBack();
return false;
}
}
#endregion
#region 产品入库CLOUD
//生成产品入库单
public bool set_SaveProductInBill_CLD(Model.ClsKf_ProductInBillMain oMain, string sHSourceType, Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain, ref string sErrMsg)
{
if (SaveProductInBill_CLD(oMain, oSystemParameterMain, ref sErrMsg))
{
//"保存成功!";
sErrMsg = "保存成功!" + oMain.HBillNo;
return true;
}
else
{
//"保存失败!";
sErrMsg = sErrMsg;
return false;
}
}
///
/// 产品入库单
///
///
///
///
public bool SaveProductInBill_CLD(Model.ClsKf_ProductInBillMain oMain, Pub_Class.ClsXt_SystemParameterMain oSystemParameterMain, ref string sErrMsg)
{
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); //建立一个 事务;
try
{
DataSet Ds;
//写入WMS产品入库单
oCn.BeginTran();
//插入子表
oCn.RunProc("EXEC h_p_Kf_ProductInBillSub_Insert " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'");
//插入主表
oCn.RunProc("Insert Into Kf_ICStockBillMain " +
"(HBillType,HBillSubType,HInterID,HBillNo,HDate,HMainSourceBillType" +
",HYear,HPeriod,HRemark,HMaker,HMakeDate" +
",HSupID,HWHID,HSCWHID,HEmpID,HManagerID,HSecManagerID" +
",HKeeperID,HDeptID,HExplanation,HInnerBillNo,HRedBlueFlag" +
") " +
" values('1202','1202'," + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "',convert(varchar(10),getdate(),120),'" + oMain.HMainSourceBillType + "'" +
",2012,1,'" + oMain.HRemark + "','" + oMain.HMaker + "',convert(varchar(10),getdate(),120)" +
", " + oMain.HSupID.ToString() + "," + oMain.HWHID.ToString() + "," + oMain.HSCWHID.ToString() + "," + oMain.HEmpID.ToString() + "," + oMain.HManagerID.ToString() + "," + oMain.HSecManagerID.ToString() +
", " + oMain.HKeeperID.ToString() + "," + oMain.HDeptID.ToString() + ",'" + oMain.HExplanation + "','" + oMain.HInnerBillNo + "'," + DBUtility.ClsPub.BoolToString(oMain.HRedBlueFlag) +
") ");
//更新关联数量
oCn.RunProc("exec h_p_Sc_UpDateICMORelation_Add " + oMain.HInterID.ToString());
if (oSystemParameterMain.Kf_ProductInBill_AutoCheck == "Y") //系统参数 自动审核
{
//审核单据
oCn.RunProc("Update Kf_ICStockBillMain Set HChecker='" + oMain.HMaker + "',HCheckDate=convert(varchar(10),getdate(),120),HBillStatus=2 where HInterID= " + oMain.HInterID.ToString());
}
//根据TMP表 返回 子表信息
Ds = oCn.RunProcReturn("exec h_p_Kf_GetProductInBill_CLD " + oMain.HInterID.ToString() + ",'" + oMain.HBillNo + "'", "h_p_Kf_GetProductInBill_CLD");
if (Ds == null || Ds.Tables[0].Rows.Count == 0 || Ds.Tables[1].Rows.Count == 0)
{
sErrMsg = "获取子表信息失败!";
oCn.RollBack();
return false;
}
else
{
string sJson_Main = "{\"Creator\":\"\",\"NeedUpDateFields\":[], \"IsEntryBatchFill\": \"false\", \"Model\": { \"FBILLNO\":\"" + oMain.HBillNo + "\"," +
/*\"FID\":\"" + oMain.HInterID.ToString() + "\"," +*/
"\"FStockOrgId\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HStockORGID"]) + "\"}, " +
"\"FPRDORGID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HPRDORGID"]) + "\"}, " +
"\"FOwnerId0\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HOWNERID"]) + "\"}," +
"\"FBillType\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["FBillType"]) + "\" " +
" }, \"FEntity\": [ ";
string sJson_Entry = "";
for (int i = 0; i < Ds.Tables[1].Rows.Count; i++)
{
if (sJson_Entry != "")
{
sJson_Entry = sJson_Entry + " , ";
}
string sJson_BatchNo = "";
string sJson_StockPlace = "";
string sJson_Custom = ""; //卓力
if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HISBATCHMANAGE"]) == "1") //是否启用批次管理
{
sJson_BatchNo = " \"FLOT\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\"}, \"FLOT_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLOT"]) + "\" , ";
}
else
{
sJson_BatchNo = "";
}
if (oSystemParameterMain.WMS_CampanyName == "卓力") //系统参数 客户定制化名称 空白为通用 仓位
{
sJson_StockPlace = "\"FStockLocId\":{\"FSTOCKLOCID__FF100002\":{\"FNUMBER\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}},";
sJson_Custom = " \"F_ZBH\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_ZBH"]) + "\" , " + //栈板数
" \"F_QIMB_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_QIMB_TEXT"]) + "\" , " + //需求单号
" \"F_DDQTY\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_DDQTY"]) + "\", "; //订单数量
}
else
{
if (Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) == "")
{
sJson_StockPlace = "";
}
else
{
sJson_StockPlace = Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}},";
}
}
//自定义字段处理
//
sJson_Entry = sJson_Entry + " { \"FOWNERID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HOWNERID"]) + "\"}," +
// "\"FSEQ\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSEQ"]) + "\", " +
" \"FBFLOWID\":{\"FID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FBFLOWID"]) + "\"} , " +
" \"FMOBILLNO\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOBILLNO"]) + "\" , " +
" \"FMOID\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOID"]) + "\" , " +
" \"FMOENTRYID\" : " + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOENTRYID"]) + " , " +
" \"FMOENTRYSEQ\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOENTRYSEQ"]) + "\" , " +
// " \"F_PAEZ_TEXT\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["F_PAEZ_TEXT"]) + "\", " +
" \"FSRCBILLTYPE\" : \"PRD_MO\" , \"FSRCBILLNO\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCBILLNO"]) + "\" , " +
" \"FSRCINTERID\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCINTERID"]) + "\" , " +
" \"FSRCENTRYID\" : " + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCENTRYID"]) + " , " +
" \"FSRCENTRYSEQ\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSRCENTRYSEQ"]) + "\" , " +
" \"FMATERIALID\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMATERIALID"]) + "\"} , " +
" \"FWORKSHOPID1\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FWORKSHOPID"]) + "\"}," +
" \"FUNITID\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FUNITID"]) + "\"}," +
" \"FBASEUNITID\" : {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FBASEUNITID"]) + "\"} , " +
" \"FSTOCKID\": {\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FSTOCKID"]) + "\"}, " +
sJson_StockPlace +
//"\"FStockLocId\":{\"FSTOCKLOCID__FF100002\":{\"FNUMBER\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FStockLocId"]) + "\"}}," +
" \"FPRODUCTTYPE\" : \"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FPRODUCTTYPE"]) + "\" , " +
" \"FMUSTQty\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMUSTQty"]) + "\", " +
" \"FRealQty\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FRealQty"]) + "\", " +
" \"FCOSTRATE\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FCOSTRATE"]) + "\", " +
sJson_BatchNo +
//"\"FLot\":{\"FNumber\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FLot"]) + "\"}," +
" \"FMOMAINENTRYID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FMOMAINENTRYID"]) + "\" , " +
" \"FREQSRC\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQSRC"]) + "\" , " +
" \"FREQBILLID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQBILLID"]) + "\" , " +
" \"FREQBILLNO\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQBILLNO"]) + "\" , " +
" \"FREQENTRYID\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQENTRYID"]) + "\" , " +
" \"FREQENTRYSEQ\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FREQENTRYSEQ"]) + "\" , " +
sJson_Custom +
" \"FEntity_Link\": [ { " +
" \"FEntity_Link_FFlowId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FFlowId"]) + "\" , " +
" \"FEntity_Link_FFlowLineId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FFlowLineId"]) + "\" , " +
" \"FEntity_Link_FRuleId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FRuleId"]) + "\" , " +
" \"FEntity_Link_FSTableName\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FSTableName"]) + "\" , " +
" \"FEntity_Link_FSBillId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FEntity_Link_FSBillId"]) + "\" , " +
" \"FEntity_Link_FSId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["HICMOEntryID"]) + "\" " +
" } ] } ";
}
//"\"FInStockEntry_Link_FSId\":" + Pub_Class.ClsPub.isStrNull(Ds.Tables[1].Rows[i]["FInStockEntry_Link_FSId"]) +
string sJson_End = " ] }}";
string sJson = sJson_Main + sJson_Entry + sJson_End;
//从配置文件获取 CLOUD网址、账套信息、登录用户、登录密码
if (!Pub_Class.ClsPub.GetCLOUDLoginInfo(ref Pub_Class.ClsPub.sExeReturnInfo))
{
sErrMsg = Pub_Class.ClsPub.sExeReturnInfo;
return false;
}
//生成 入库单
string HReturn;
ApiClient client = new ApiClient(Pub_Class.ClsPub.sCLOUDUrl);
string dbId = Pub_Class.ClsPub.sCLOUDAcc; //AotuTest117
bool bLogin = client.Login(dbId, Pub_Class.ClsPub.sCLOUDUseName, Pub_Class.ClsPub.sCLOUDPsd, 2052);
if (bLogin)
{
var result = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save",
new object[] { "PRD_INSTOCK", sJson }); //调用保存方式
if (oSystemParameterMain.Kf_ProductInBill_AutoCheck == "Y") //系统参数 自动审核
{
string sJson2 = "{\"CreateOrgId\":0,\"Numbers\":[\"" + oMain.HBillNo + "\"]}";
var result2 = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit",
new object[] { "PRD_INSTOCK", sJson2 }); //提交单据
string sJson3 = "{\"CreateOrgId\":0,\"Numbers\":[\"" + oMain.HBillNo + "\"]}";
var result3 = client.Execute("Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit",
new object[] { "PRD_INSTOCK", sJson3 }); //审核单据
HReturn = result.ToString() + "," + result2.ToString() + "," + result3.ToString();
}
else
{
HReturn = result.ToString();
}
if (HReturn.Contains("\"IsSuccess\":false") == true)
{
sErrMsg = "产品入库单失败!" + HReturn + sJson;
oCn.RollBack();
return false;
}
else
{
oCn.Commit();
return true;
}
}
else
{
sErrMsg = "产品入库单失败!登录失败!";
oCn.RollBack();
return false;
}
}
}
catch (Exception e)
{
sErrMsg = "产品入库单失败!" + e.Message;
oCn.RollBack();
return false;
}
}
#endregion
}
}