public class K3CloudWebApi
{
#region 表单保存、提交、审核
///
/// 验证登陆
///
///
///
///
///
///
///
public static KeyValuePair ValidateLogin(Context context, string DBCenterID, string F_AT_ServiceSettings, string F_AT_USERNAME, string F_AT_Password)
{
F_AT_ServiceSettings = F_AT_ServiceSettings + "/";
K3CloudApiClient client = new K3CloudApiClient(F_AT_ServiceSettings);
var ret = client.ValidateLogin(DBCenterID, F_AT_USERNAME, F_AT_Password, 2052);
var result = JObject.Parse(ret)["LoginResultType"].Value();
if (result == 1)
{
return new KeyValuePair(true, client);
}
return new KeyValuePair(false, null);
}
///
/// 保存
///
///
///
///
///
public static KeyValuePair FormSave(K3CloudApiClient client, string formId, RequestBase Entity)
{
var ret1 = client.Save(formId, JsonConvert.SerializeObject(Entity));
var result1 = JsonConvert.DeserializeObject(ret1);
if (!result1.Result.ResponseStatus.IsSuccess)
{
string errMsg = "保存失败原因:";
foreach (var error in result1.Result.ResponseStatus.Errors)
{
errMsg += error.Message + ";";
}
return new KeyValuePair(false, errMsg + "\n");
}
else
{
string Number = "";
foreach (var entity in result1.Result.ResponseStatus.SuccessEntitys)
{
Number += entity.Number + ",";
}
return new KeyValuePair(true, Number.Trim(','));
}
}
///
/// 提交
///
///
///
///
///
public static KeyValuePair FormSubmit(K3CloudApiClient client, string formId, string[] Numbers)
{
//提交
var submitDate = new
{
CreateOrgId = 0,
Numbers = Numbers,
Ids = "",
SelectedPostId = 0
};
var ret1 = client.Submit(formId, JsonConvert.SerializeObject(submitDate));
var result1 = JsonConvert.DeserializeObject(ret1);
if (!result1.Result.ResponseStatus.IsSuccess)
{
string errMsg = "提交失败原因:";
foreach (var error in result1.Result.ResponseStatus.Errors)
{
errMsg += error.Message + ";";
}
return new KeyValuePair(false, errMsg + "\n");
}
else
{
string Number = "";
foreach (var entity in result1.Result.ResponseStatus.SuccessEntitys)
{
Number += entity.Number + ",";
}
return new KeyValuePair(true, Number.Trim(','));
}
}
///
/// 审核
///
///
///
///
///
public static KeyValuePair FormAudit(K3CloudApiClient client, string formId, string[] Numbers)
{
//审核
var auditDate = new
{
CreateOrgId = 0,
Numbers = Numbers,
Ids = "",
InterationFlags = ""
};
var ret1 = client.Audit(formId, JsonConvert.SerializeObject(auditDate));
var result1 = JsonConvert.DeserializeObject(ret1);
if (!result1.Result.ResponseStatus.IsSuccess)
{
string errMsg = "审核失败原因:";
foreach (var error in result1.Result.ResponseStatus.Errors)
{
errMsg += error.Message + ";";
}
return new KeyValuePair(false, errMsg + "\n");
}
else
{
string Number = "";
foreach (var entity in result1.Result.ResponseStatus.SuccessEntitys)
{
Number += entity.Number + ",";
}
return new KeyValuePair(true, Number.Trim(','));
}
}
#endregion
#region 查询
public static KeyValuePair>> ExecuteBillQuery(K3CloudApiClient client, string formId, string FieldKeys, string FilterString)
{
//查询
var date = new
{
FormId = formId,
FieldKeys = FieldKeys,//"FID,FBILLNO,FEntity_FENTRYID,FEntity_FSeq,FMaterialID,FMaterialName,FMaterialID.FName,FMaterialID.FStockId",
FilterString = FilterString,//"FBILLNO = 'XSCKD000001'",
OrderString = "",
TopRowCount = 0,
StartRow = 0,
Limit = 0
};
var result1 = client.ExecuteBillQuery(JsonConvert.SerializeObject(date));
if (result1.Any())
{
return new KeyValuePair>>(true, result1);
}
return new KeyValuePair>>(false, null);
}
#endregion
///
/// 新增--销售订单
///
///
///
///
public static KeyValuePair InsertSalOrder(K3CloudApiClient client, RequestBase Entity)
{
return FormSave(client, "SAL_SaleOrder", Entity);
}
///
/// 新增--客户
///
///
///
///
public static KeyValuePair InsertSalCust(K3CloudApiClient client, RequestBase Entity)
{
var saveResult = FormSave(client, "BD_Customer", Entity);
if (saveResult.Key)
{
string[] Numbers = { saveResult.Value };
var submitResult = FormSubmit(client, "BD_Customer", Numbers);
if (submitResult.Key)
{
return FormAudit(client, "BD_Customer", Numbers);
}
return new KeyValuePair(false, submitResult.Value);
}
return new KeyValuePair(false, saveResult.Value);
}
///
/// 新增--计量单位
///
///
///
///
public static KeyValuePair InsertSalUnit(K3CloudApiClient client, RequestBase Entity)
{
var saveResult = FormSave(client, "BD_UNIT", Entity);
if (saveResult.Key)
{
string[] Numbers = { saveResult.Value };
var submitResult = FormSubmit(client, "BD_UNIT", Numbers);
if (submitResult.Key)
{
return FormAudit(client, "BD_UNIT", Numbers);
}
return new KeyValuePair(false, submitResult.Value);
}
return new KeyValuePair(false, saveResult.Value);
}
///
/// 新增--物料
///
///
///
///
public static KeyValuePair InsertSalMaterial(K3CloudApiClient client, RequestBase Entity)
{
var saveResult = FormSave(client, "BD_MATERIAL", Entity);
if (saveResult.Key)
{
string[] Numbers = { saveResult.Value };
var submitResult = FormSubmit(client, "BD_MATERIAL", Numbers);
if (submitResult.Key)
{
return FormAudit(client, "BD_MATERIAL", Numbers);
}
return new KeyValuePair(false, submitResult.Value);
}
return new KeyValuePair(false, saveResult.Value);
}
///
/// 新增--职员
///
///
///
///
public static KeyValuePair InsertEmployee(K3CloudApiClient client, RequestBase Entity)
{
var saveResult = FormSave(client, "HR_EMPINFO" ,Entity);
if (saveResult.Key)
{
string[] Numbers = { saveResult.Value };
var submitResult = FormSubmit(client, "HR_EMPINFO", Numbers);
if (submitResult.Key)
{
return FormAudit(client, "HR_EMPINFO", Numbers);
}
return new KeyValuePair(false, submitResult.Value);
}
return new KeyValuePair(false, saveResult.Value);
}
///
/// 新增--供应商
///
///
///
///
public static KeyValuePair InsertSupplier(K3CloudApiClient client, RequestBase Entity)
{
var saveResult = FormSave(client, "BD_SUPPLIER",Entity);
if (saveResult.Key)
{
string[] Numbers = { saveResult.Value };
var submitResult = FormSubmit(client, "BD_SUPPLIER", Numbers);
if (submitResult.Key)
{
return FormAudit(client, "BD_SUPPLIER", Numbers);
}
return new KeyValuePair(false, submitResult.Value);
}
return new KeyValuePair(false, saveResult.Value);
}
}