[code]using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.WebApi.Client;
using Newtonsoft.Json.Linq;
namespace ConsoleApplication2
{
class Program
{
//处理webapi-json数据函数,如修改数据,请注意关联规则
public string data()
{
//单据头必录
string FPrdOrgId = "101.1"; //生产组织
string FDate = "2019-02-27 00:00:00"; //日期
string FStockOrgId = "101.1"; //入库组织
string FOwnerTypeId0 = "BD_OwnerOrg"; //货主类型
string FOwnerId0 = "101.1"; //货主
string FBillType = "JDSCRK01_SYS";//单据类型
//单据体必录
string FMaterialId = "010101"; //物料编码
string FInStockType = "1"; //入库类型
string FUnitID = "kg"; //单位
string FOwnerTypeId = "BD_OwnerOrg"; // 货主类型
string FOwnerId = "101.1";//货主
string FStockId = "CK001";//仓库
string FWorkShopId1 = "BM000020";//生产车间
string FStockStatusId = "KCZT01_SYS";// 库存状态
string FKeeperTypeId = "BD_KeeperOrg";//保管者类型
string FKeeperId = "101.1";//保管者
string FLot = "010101"; //批号
string str_r = "{\"Creator\": \"\",\"NeedUpDateFields\": [],\"NeedReturnFields\": [],\"IsDeleteEntry\": \"true\","+
"\"SubSystemId\": \"\",\"IsVerifyBaseDataField\": \"false\",\"IsEntryBatchFill\": \"true\",\"ValidateFlag\": \"true\"," +
"\"NumberSearch\": \"true\",\"InterationFlags\": \"\",\"IsAutoSubmitAndAudit\": \"true\"," +
"\"Model\": {" +
"\"FID\": 0," +
"\"FBillType\": {" +
"\"FNUMBER\": \""+ FBillType + "\"" +
"}," +
"\"FDate\": \""+ FDate + "\"," +
"\"FStockOrgId\": {" +
"\"FNumber\": \""+ FStockOrgId + "\"" +
"}," +
"\"FPrdOrgId\": {" +
"\"FNumber\": \""+ FPrdOrgId + "\"" +
"}," +
"\"FCurrId\": {" +
"\"FNumber\": \"PRE001\"" + //本位币编码
"}," +
"\"FOwnerTypeId0\": \""+ FOwnerTypeId0 + "\"," +
"\"FOwnerId0\": {" +
"\"FNumber\": \""+ FOwnerId0 + "\"" +
"}," +
"\"FTransferBizTypeId\": {" +
"\"FNumber\": \"OverOrgPrdIn\"" + //跨组织业务类型
"}," +
"\"FEntity\": [" +
"{" +
"\"FMaterialId\": {" +
"\"FNumber\": \""+ FMaterialId + "\"" +
"}," +
"\"FInStockType\": \""+ FInStockType + "\"," + //
"\"FUnitID\": {" +
"\"FNumber\": \""+ FUnitID + "\"" + //单位
"}," +
"\"FMustQty\": 1.0," + //应收数量
"\"FRealQty\": 1.0," + //实收数量
"\"FLot\": {"+
"\"FNumber\": \""+ FLot + "\""+
"},"+
"\"FStockId\": {" +
"\"FNumber\": \""+ FStockId + "\"" +
"}," +
"\"FWorkShopId1\": {" +
"\"FNumber\": \""+ FWorkShopId1 + "\"" +
"}," +
"\"FIsAffectCost\": false," +
"\"FOwnerTypeId\": \""+ FOwnerTypeId + "\"," +
"\"FOwnerId\": {" +
"\"FNumber\": \""+ FOwnerId + "\"" +
"}," +
"\"FStockUnitId\": {" +
"\"FNumber\": \"kg\"" + //单位
"}," +
"\"FStockRealQty\": 1.0," + //库存单位实收数量
"\"FBaseUnitId\": {" +
"\"FNumber\": \"kg\"" + //基本单位
"}," +
"\"FExtAuxUnitId\": {" +
"\"FNumber\": \"001022202\"" + //辅单位
"}," +
"\"FBaseRealQty\": 1.0," + // 基本单位实收数量
"\"FExtAuxUnitQty\": 1.0," + //实收数量(辅单位)
"\"FStockStatusId\": {" +
"\"FNumber\": \""+ FStockStatusId + "\"" +
"}," +
"\"FSecUnitId\": {" +
"\"FNumber\": \"001022202\"" + //库存辅单位
"}," +
"\"FSecRealQty\": 1.0," + // 实收数量(库存辅单位)
"\"FBaseMustQty\": 1.0," + //基本单位应收数量
"\"FKeeperTypeId\": \""+ FKeeperTypeId + "\"," +
"\"FKeeperId\": {" +
"\"FNumber\": \""+ FKeeperId + "\"" +
"}" +
"}" +
"]" +
"}" +
"}";
return str_r;
}
static void Main(string[] args)
{
Console.WriteLine("请输入账套ID");
string acctID = Console.ReadLine();
Console.WriteLine("请输入用户名");
string user = Console.ReadLine();
Console.WriteLine("请输入密码");
string pw = Console.ReadLine();
// 使用webapi引用组件Kingdee.BOS.WebApi.Client.dll
K3CloudApiClient client = new K3CloudApiClient("http://localhost/K3Cloud/");
var loginResult = client.ValidateLogin(acctID, user, pw, 2052);
var resultType = JObject.Parse(loginResult)["LoginResultType"].Value
//调用data方法 获取数据 //
Program nn = new Program();
string str_r = nn.data();
//登录结果类型等于1,代表登录成功
if (resultType == 1)
{
var uname = JObject.Parse(loginResult)["Context"]["UserName"];
Console.WriteLine("登陆成功,欢迎你:" + uname);
//保存传入的数据包
var rz = client.Save("SP_InStock", str_r);
bool flag = JObject.Parse(rz)["Result"]["ResponseStatus"]["IsSuccess"].Value
if (flag)
{
Console.WriteLine("添加数据成功");
}
else
{
Console.WriteLine("添加数据失败");
}
//暂停,查看控制台输出数据
string str = Console.ReadLine();//输入一行
}
else
{
Console.WriteLine("登陆失败,请检查错误日志 \n错误日志:\n"+ loginResult);
//暂停,查看控制台输出数据
string str = Console.ReadLine();//输入一行
};
}
}
}
[/code]
推荐阅读