Kingdee k3cloud sales order import secondary development

1, Foreword

The company purchased and used the ERP system of Kingdee k3ccloud. Finance, supply chain, sales, warehouse, etc. are all done on it. But on the other hand, standardized things are difficult to adapt to all companies. They will carry out simple secondary development more or less. The official secondary development cost of Kingdee is frighteningly high. Moreover, the company's demand will always change. It is impossible to find people from the original factory to develop it every time. So in June 2018, the company paid for a three-day training at Kingdee headquarters. I just learned a little fur.

2, Demand

At present, the company adopts the customer service sales system developed by me in Java. Provide external network customers with online orders. At the same time, it is necessary to synchronize the orders from the Internet to Kingdee's K3 system at regular intervals to achieve semi automation. I carry out secondary development in two ways. Unlike the plug-in that they recommend using C# to write dll, I use non-invasive secondary development because I am a halfway monk. Import orders through WebAPI. Then query the sales delivery data by directly querying the SQL Server database, show it to customers and do data analysis.

3, Introduction to WebAPI

  1. Create a normal C# winform project

Add a reference to [Kingdee.BOS.WebApi.Client.dll]. You can search the installation directory of K3 to find this dll library.

  2. Query current data center (A / C set) ID

When logging in, click [View http data]

  3. Query the current request business object ID and corresponding parameters

This webapi SDK function requires administrator permission to have a corresponding menu.

For example, if you select a function, you can see the corresponding parameter description and examples

Due to different companies, the corresponding business data and fields are different. Therefore, you can also click the above [online test WebAPI] to generate data

 

4, Code part

Here is an example, part of my code

Login and logout

 1         /// <summary>
 2         /// land
 3         /// </summary>
 4         /// <param name="conf"></param>
 5         /// <returns></returns>
 6         public static K3CloudApiClient K3Login(ConfigModel conf)
 7         {
 8             K3CloudApiClient client = new K3CloudApiClient(conf.CONF_URL);
 9             bool loginResult = client.Login(conf.CONF_DBID, conf.CONF_USERNAME,
10                 conf.CONF_PASSWORD, conf.CONF_ICID );
11             if (!loginResult)
12             {
13                 return null;
14             }
15             return client;
16         }
17         /// <summary>
18         /// Log out
19         /// </summary>
20         /// <param name="client"></param>
21         public static void K3Logout(K3CloudApiClient client)
22         {
23             if(client != null)
24             {
25                 client.Logout();
26             }
27         }

Check whether the material exists

 1         /// <summary>
 2         /// Check that the material is in K3 Is there any in the system
 3         /// </summary>
 4         /// <param name="client"></param>
 5         /// <param name="chipname">model</param>
 6         /// <returns></returns>
 7         public static Boolean checkChipname(K3CloudApiClient client, string chipname)
 8         {
 9             string responseData = string.Empty;
10             string formid = "BD_MATERIAL";
11             string requestData = "{\"CreateOrgId\":\"0\",\"Number\":\"" + chipname + "\",\"Id\":\"\"}";
12             responseData = client.View(formid, requestData);
13             Dictionary<string, object> mate = getObject(responseData);
14             string status = getJSONValue(mate, "Result");
15             mate = getObject(status);
16             status = getJSONValue(mate, "ResponseStatus");
17             if(status == null || status == "")
18             {
19                 return true;
20             }
21             mate = getObject(status);
22             string ret = getJSONValue(mate, "IsSuccess");
23             ret = ret.ToUpper();
24             if(ret == "FALSE")
25             {
26                 return false;
27             }
28             return true;
29         }

Obtain the corresponding customer information according to the code

 1        /// <summary>
 2         /// obtain K3 Vendor information in the system
 3         /// </summary>
 4         /// <param name="client"></param>
 5         /// <param name="cust_id"></param>
 6         /// <returns></returns>
 7         public static CustomerModel getCustomerModel(K3CloudApiClient client, string cust_id)
 8         {
 9             CustomerModel model = new CustomerModel();
10             string responseDate = string.Empty;
11             string formid = "BD_Customer";
12             string requestData = "{\"CreateOrgId\":\"0\",\"Number\":\"" + cust_id + "\",\"Id\":\"\"}";
13             responseDate = client.View(formid, requestData);
14             Dictionary<string, object> cust = getObject(responseDate);
15             string tmp = getJSONValue(cust, "Result");
16             cust = getObject(tmp);
17             string status = getJSONValue(cust, "ResponseStatus");
18             if (status != null && status != "")
19             {
20                 MessageController.showErrorMessage("manufacturer ID:[" + cust_id + "]Error, please confirm");
21                 return null;
22             }
23             tmp = getJSONValue(cust, "Result");
24             cust = getObject(tmp);
25             tmp = getJSONValue(cust, "BD_CUSTCONTACT");
26             List<Dictionary<string, object>> contacts = getListObject(tmp);
27             string addr = "";
28             string addr_id = "";
29             string fname = "";
30             string loc_id = "";
31             for(int i=0; i<contacts.Count; i++)
32             {
33                 if(addr_id == "")
34                 {
35                     addr_id = getJSONValue(contacts[i], "NUMBER");
36                 }
37                 if(addr == "")
38                 {
39                     addr = getJSONValue(contacts[i], "ADDRESS");
40                 }
41                 tmp = getJSONValue(contacts[i], "TContact");
42                 Dictionary<String, object> cont = getObject(tmp);
43                 if (cont == null) continue;
44                 if(loc_id == "")
45                 {
46                     loc_id = getJSONValue(cont, "Number");
47                     tmp = getJSONValue(cont, "Name");
48                     List<Dictionary<string, object>> name = getListObject(tmp);
49                     if (name.Count >= 1)
50                     {
51                         fname = getJSONValue(name[0], "Value");
52                     }
53                 }
54             }
55 
56             model.addr = addr;
57             model.addr_id = addr_id;
58             model.cust_id = cust_id;
59             model.fname = fname;
60             model.loc_id = loc_id;
61 
62             return model;
63         }

Save sales order

 1         /// <summary>
 2         /// Save order information
 3         /// </summary>
 4         /// <param name="client"></param>
 5         /// <param name="order"></param>
 6         /// <returns></returns>
 7         public static Boolean saveK3SaleOrder(K3CloudApiClient client, K3SaleOrderModel order)
 8         {
 9             string formid = "SAL_SaleOrder";
10             string requestData = JsonConvert.SerializeObject(order);
11             string responseData = client.Save(formid, requestData);
12             Dictionary<string, object> result = getObject(responseData);
13             string tmp = getJSONValue(result, "Result");
14             result = getObject(tmp);
15             string status = getJSONValue(result, "ResponseStatus");
16             Dictionary<string, object> res = getObject(status);
17             string isSuccess = getJSONValue(res, "IsSuccess");
18             isSuccess = isSuccess.ToUpper();
19             Boolean flag = false;
20             if(isSuccess == "TRUE")
21             {
22                 string number = getJSONValue(result, "Number");
23                 RET_MESSAGE = "Successfully imported Order No:[" + number + "]";
24                 flag = true;
25             }
26             else
27             {
28                 string errors = getJSONValue(res, "Errors");
29                 RET_MESSAGE = errors;
30             }
31             //Print log
32             return flag;
33         }

The key to saving the order above is the K3SaleOrderModel, which should correspond to the fields returned in the above WebAPI example one by one. To ensure that the order is saved successfully.

  K3SaleOrderModel

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace SaleOrderTool.Model
 7 {
 8     /// <summary>
 9     /// K3 Sales order complete submission model
10     /// </summary>
11     class K3SaleOrderModel
12     {
13         public K3SaleOrderModel()
14         {
15             this.Model = new K3SaleOrderBillModel();
16         }
17         public string Creator { get; set; }
18         public List<FNumberModel> NeedUpDateFields { get; set; }
19         public List<FNumberModel> NeedReturnFields { get; set; }
20         public string IsDeleteEntry { get; set; }
21         public string SubsystemId { get; set; }
22         public string IsVerifyBaseDataField { get; set; }
23         public K3SaleOrderBillModel Model { get; set; }
24     }
25 }

  K3SaleOrderBillModel

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace SaleOrderTool.Model
 7 {
 8     /// <summary>
 9     /// K3 Sales order model
10     /// </summary>
11     class K3SaleOrderBillModel
12     {
13         public K3SaleOrderBillModel()
14         {
15             this.FBillTypeID = new FNumberModel();
16             this.FSaleOrgId = new FNumberModel();
17             this.FCustId = new FNumberModel();
18             this.FHeadDeliveryWay = new FNumberModel();
19             this.FReceiveId = new FNumberModel();
20             this.FHeadLocId = new FNumberModel();
21             this.FCorrespondOrgId = new FNumberModel();
22             this.FSaleDeptId = new FNumberModel();
23             this.FSaleGroupId = new FNumberModel();
24             this.FSalerId = new FNumberModel();
25             this.FSettleId = new FNumberModel();
26             this.FReceiveContact = new FNameModel();
27             this.FChargeId = new FNumberModel();
28             this.FSalePhaseID = new FNumberModel();
29             this.F_PAEZ_Base = new FNumberModel();
30             this.FSaleOrderFinance = new FSaleOrderFinanceModel();
31             this.FSaleOrderEntry = new List<FSaleOrderEntryModel>();
32         }
33         public string Fid { get; set; }
34         public FNumberModel FBillTypeID { get; set; }
35         public string FBillNo { get; set; }
36         public string FDate { get; set; }
37         public FNumberModel FSaleOrgId { get; set; }
38         public FNumberModel FCustId { get; set; }
39         public FNumberModel FHeadDeliveryWay { get; set; }
40         public FNumberModel FReceiveId { get; set; }
41         public FNumberModel FHeadLocId { get; set; }
42         public FNumberModel FCorrespondOrgId { get; set; }
43         public FNumberModel FSaleDeptId { get; set; }
44         public FNumberModel FSaleGroupId { get; set; }
45         public FNumberModel FSalerId { get; set; }
46         public string FReceiveAddress { get; set; }
47         public FNumberModel FSettleId { get; set; }
48         public FNameModel FReceiveContact { get; set; }
49         public FNumberModel FChargeId { get; set; }
50         public string FNetOrderBillNo { get; set; }
51         public int FNetOrderBillId { get; set; }
52         public int FOppID { get; set; }
53         public FNumberModel FSalePhaseID { get; set; }
54         public Boolean Fisinit { get; set; }
55         public string FNote { get; set; }
56         public Boolean FIsMobile { get; set; }
57         public FNumberModel F_PAEZ_Base { get; set; }
58         public FSaleOrderFinanceModel FSaleOrderFinance { get; set; }
59         public List<FSaleOrderEntryModel> FSaleOrderEntry { get; set; }
60     }
61 }

Other models are omitted

 

Address: https://www.cnblogs.com/wunaozai/p/13819707.html
Personal homepage: https://www.wunaozai.com/

 

Posted by matijarma on Wed, 11 May 2022 19:12:42 +0300