| | |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Web; |
| | | using System.Text; |
| | | using System.Web.Services; |
| | | using System.Data.SqlClient; |
| | | using System.Globalization; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace CLOUDWEB |
| | | { |
| | |
| | | //从配置文件获取 CLOUD网址、账套信息、登录用户、登录密码 |
| | | if (!Pub_Class.ClsPub.GetCLOUDLoginInfo(ref Pub_Class.ClsPub.sExeReturnInfo)) |
| | | { |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='同步失败',HInterFaceRemark='获取金蝶云账套信息失败' where HInterID=" + HInterID.ToString()); |
| | | sErrMsg = "单据号:" + HBillNo + ";" + Pub_Class.ClsPub.sExeReturnInfo; |
| | | return false; |
| | | } |
| | |
| | | } |
| | | |
| | | string HReturn; |
| | | K3CloudApiClient client = new K3CloudApiClient(Pub_Class.ClsPub.sCLOUDUrl); |
| | | //ApiClient client = new ApiClient(Pub_Class.ClsPub.sCLOUDUrl); |
| | | ApiClient client = new ApiClient(Pub_Class.ClsPub.sCLOUDUrl); |
| | | string dbId = Pub_Class.ClsPub.sCLOUDAcc; //AotuTest117 |
| | | bool bLogin = client.Login(dbId, sCLOUDUseName, sCLOUDPsd, 2052); |
| | | |
| | |
| | | |
| | | if (Ds == null || Ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='同步失败',HInterFaceRemark='获取WEBAPI所需递入数据失败' where HInterID=" + HInterID.ToString()); |
| | | sErrMsg = "单据号:" + HBillNo + ";获取WEBAPI所需递入数据失败!"; |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | string sJson_Custom = ""; //自定义字段 |
| | | string sJson_Custom2 = ""; //自定义字段 |
| | | sJson_Custom = Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Custom"]); |
| | | sJson_Custom2 = Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["Custom2"]); |
| | | |
| | | string sJson = "{\"AutoAudit\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["AutoAudit"]) + "\"," + //自动审核 |
| | | " \"Datas\": [ { " + |
| | |
| | | " \"EpmId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["EpmId"]) + "\"," + //操作工 |
| | | " } ]," + |
| | | " } ]," + |
| | | " \"Sst_Customers\": [ { " + //携带二开扩展字段赋值 |
| | | " \"EntryId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["EntryId"]) + "\"," + //工序计划序列Id |
| | | " \"DetailId\":\"" + Pub_Class.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["DetailId"]) + "\"," + //工序计划工序Id |
| | | sJson_Custom2 + |
| | | " } ]" + |
| | | " } ]}"; |
| | | |
| | | sRemark = sRemark + " ;获取CLOUD单据API递入值" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); |
| | |
| | | |
| | | HReturn = result.ToString(); |
| | | |
| | | if (HReturn.Contains("\"IsSuccess\":false") == true) |
| | | if (HReturn.Contains("\"IsSuccess\":\"false") == true) |
| | | { |
| | | //反序列化json数据 |
| | | var retModel = JsonConvert.DeserializeObject<KingdeeResponse>(HReturn); |
| | | //接收金蝶报错信息 |
| | | var strErrorMsg = string.Empty; |
| | | //遍历获取报错信息 |
| | | foreach (var item in retModel.Result.ResponseStatus.Errors) |
| | | //获取金蝶云返回报错信息中的中文 |
| | | var chineseChars = new StringBuilder(); |
| | | foreach (char c in HReturn) |
| | | { |
| | | strErrorMsg += item.Message + "\r\n"; |
| | | }; |
| | | sErrMsg = "单据号:" + HBillNo + ";生成工序汇报单失败!金蝶云提示:" + strErrorMsg; |
| | | // 中文字符的Unicode范围:\u4e00-\u9fa5 |
| | | if (c >= '\u4e00' && c <= '\u9fa5') |
| | | { |
| | | chineseChars.Append(c); |
| | | } |
| | | } |
| | | string input = chineseChars.ToString(); |
| | | //截取字符长度 |
| | | string result2 = input.Length <= 240 ? input : input.Substring(0, 240); |
| | | |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='同步失败',HInterFaceRemark='" + result2 + "' where HInterID=" + HInterID.ToString()); |
| | | sErrMsg = "单据号:" + HBillNo + ";生成工序汇报单失败!金蝶云提示:" + HReturn; |
| | | LogService.Write("单据号:" + HBillNo + ";工序计划下推工序汇报失败!" + HReturn + sJson); //写入txt文本 |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='已同步' where HInterID=" + HInterID.ToString()); |
| | | sRemark = sRemark + sJson; |
| | | LogService.Write("单据号:" + HBillNo + ";工序计划下推工序汇报成功!" + sRemark +"------"+ HReturn); //写入txt文本 |
| | | return true; |
| | |
| | | } |
| | | else |
| | | { |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='同步失败',HInterFaceRemark='金蝶云登录失败' where HInterID=" + HInterID.ToString()); |
| | | sErrMsg = "单据号:" + HBillNo + ";生成工序汇报单失败!金蝶云登录失败!"; |
| | | return false; |
| | | } |
| | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //更新工序汇报单状态 |
| | | oCn.RunProc("Update Sc_StationOutBillMain Set HInterFaceStatus='同步失败',HInterFaceRemark='错误回滚' where HInterID=" + HInterID.ToString()); |
| | | LogService.Write("单据号:" + HBillNo + ";生成回滚" + e.Message + sRemark); |
| | | sErrMsg = "单据号:" + HBillNo + ";生成工序汇报单失败!" + e.Message; |
| | | return false; |