Esempio n. 1
0
        public string CreateInterfacePost(T_InterfaceInfo model, string VoucherJson)
        {
            JsonModel jsonModel = new JsonModel();

            try
            {
                var assembly = Assembly.LoadFile(@model.Route);

                var type = assembly.GetType(model.ClassName);

                var instance = assembly.CreateInstance(model.ClassName);

                //type.GetProperty("strJson").SetValue(instance, modeJson, null);
                //strError =  type.GetProperty("strErrMsg").GetValue(instance).ToString();

                object[] obj = new object[1];
                obj[0] = VoucherJson;
                var method = type.GetMethod(model.FunctionName);
                return(method.Invoke(instance, obj).ToString());
            }
            catch (Exception ex)
            {
                jsonModel.result = "false";
                jsonModel.ErrMsg = "调用ERP接口异常:" + ex.Message + ex.InnerException;
                LogNet.LogInfo("CreateInterfacePost----" + jsonModel.ErrMsg);
                return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
            }
        }
Esempio n. 2
0
        public string CreateInterfaceGet(T_InterfaceInfo model, string VoucherJson)
        {
            JsonModel jsonModel = new JsonModel();

            jsonModel.payload                    = new PayLoad();
            jsonModel.payload.std_data           = new Std();
            jsonModel.payload.std_data.execution = new Exe();
            try
            {
                LogNet.LogInfo("VoucherJson:" + VoucherJson);

                var assembly = Assembly.LoadFile(@model.Route);

                var type = assembly.GetType(model.ClassName);

                var instance = assembly.CreateInstance(model.ClassName);

                //type.GetProperty("strJson").SetValue(instance, modeJson, null);
                //strError =  type.GetProperty("strErrMsg").GetValue(instance).ToString();

                object[] obj = new object[1];
                obj[0] = VoucherJson;
                var method = type.GetMethod(model.FunctionName);
                LogNet.LogInfo("---------------------调用ERP接口:" + model.ClassName + model.FunctionName + "参数:" + VoucherJson);
                return(method.Invoke(instance, obj).ToString());
            }
            catch (Exception ex)
            {
                LogNet.LogInfo("CreateInterface:" + ex.InnerException + ex.Message);
                jsonModel.payload.std_data.execution.code        = "1";
                jsonModel.payload.std_data.execution.description = "调用ERP接口异常:" + ex.InnerException + ex.Message;
                return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
            }
        }
Esempio n. 3
0
        public List <T_InterfaceInfo> GetInterface()
        {
            try
            {
                List <T_InterfaceInfo> lstModel = new List <T_InterfaceInfo>();
                string sql = "select * from v_depinterface";

                using (IDataReader reader = dbFactory.ExecuteReader(sql))
                {
                    while (reader.Read())
                    {
                        T_InterfaceInfo model = new T_InterfaceInfo();
                        model.DLLName        = reader["DLLName"].ToDBString();
                        model.Route          = reader["Route"].ToDBString();
                        model.FunctionName   = reader["FunctionName"].ToDBString();
                        model.Function       = reader["Function"].ToDBString();
                        model.VoucherType    = reader["VoucherType"].ToInt32();
                        model.StrVoucherType = reader["StrVoucherType"].ToDBString();
                        model.ClassName      = reader["ClassName"].ToDBString();
                        lstModel.Add(model);
                    }
                }
                return(lstModel);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Esempio n. 4
0
        public string PostCheck(string Json)
        {
            JsonModel jsonModel = new JsonModel();

            jsonModel.payload                    = new PayLoad();
            jsonModel.payload.std_data           = new Std();
            jsonModel.payload.std_data.execution = new Exe();

            try
            {
                List <T_InterfaceInfo> lstModel = GetInterface("8887");
                if (lstModel == null || lstModel.Count == 0)
                {
                    //jsonModel.payload.std_data.execution.code = "1";
                    //jsonModel.payload.std_data.execution.description = "没有配置获取数据二开接口!";
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "没有配置获取数据二开接口!";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                T_InterfaceInfo model = lstModel.Find(t => t.Function == "3");

                if (model == null)
                {
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "没有配置获取数据二开接口!";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                JsonModel jsonModel1 = new JsonModel();
                jsonModel1.payload                    = new PayLoad();
                jsonModel1.payload.std_data           = new Std();
                jsonModel1.payload.std_data.execution = new Exe();

                LogNet.LogInfo("VoucherJson:" + Json);
                var      assembly = Assembly.LoadFile(@model.Route);
                var      type     = assembly.GetType(model.ClassName);
                var      instance = assembly.CreateInstance(model.ClassName);
                object[] obj      = new object[1];
                obj[0] = Json;
                var method = type.GetMethod(model.FunctionName);
                LogNet.LogInfo("---------------------调用ERP接口:" + model.ClassName + model.FunctionName + "参数:" + Json);
                return(method.Invoke(instance, obj).ToString());
            }
            catch (Exception ex)
            {
                //jsonModel.payload.std_data.execution.code = "1";
                //jsonModel.payload.std_data.execution.description = ex.Message;
                jsonModel.result      = "0";
                jsonModel.resultValue = ex.Message;
                return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 获取二开接口数据
        /// </summary>
        /// <param name="VoucherJson"></param>
        /// <returns></returns>
        public string GetModelListByInterface(string VoucherJson)
        {
            JsonModel jsonModel = new JsonModel();

            jsonModel.payload                    = new PayLoad();
            jsonModel.payload.std_data           = new Std();
            jsonModel.payload.std_data.execution = new Exe();

            try
            {
                if (string.IsNullOrEmpty(VoucherJson))
                {
                    //jsonModel.payload.std_data.execution.code = "1";
                    //jsonModel.payload.std_data.execution.description = "解析JSON为空";
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "解析JSON为空";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                JToken jtoken      = JToken.Parse(VoucherJson);
                string VoucherType = jtoken["VoucherType"].ToString();

                if (string.IsNullOrEmpty(VoucherType))
                {
                    //jsonModel.payload.std_data.execution.code = "1";
                    //jsonModel.payload.std_data.execution.description = "单据类型为空!";
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "单据类型为空!";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                List <T_InterfaceInfo> lstModel = GetInterface(VoucherType);
                if (lstModel == null || lstModel.Count == 0)
                {
                    //jsonModel.payload.std_data.execution.code = "1";
                    //jsonModel.payload.std_data.execution.description = "没有配置获取数据二开接口!";
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "没有配置获取数据二开接口!";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                T_InterfaceInfo model = lstModel.Find(t => t.Function == "3");

                if (model == null)
                {
                    //jsonModel.payload.std_data.execution.code = "1";
                    //jsonModel.payload.std_data.execution.description = "没有配置获取数据二开接口!";
                    jsonModel.result      = "0";
                    jsonModel.resultValue = "没有配置获取数据二开接口!";
                    return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
                }

                return(CreateInterfaceGet(model, VoucherJson));
            }
            catch (Exception ex)
            {
                //jsonModel.payload.std_data.execution.code = "1";
                //jsonModel.payload.std_data.execution.description = ex.Message;
                jsonModel.result      = "0";
                jsonModel.resultValue = ex.Message;
                return(JSONUtil.JSONHelper.ObjectToJson <JsonModel>(jsonModel));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 过账二开接口
        /// </summary>
        /// <param name="VoucherJson"></param>
        /// <returns></returns>
        public string PostModelListToInterface(string VoucherJson)
        {
            BaseMessage_Model <List <T_InterfaceInfo> > messageModel = new BaseMessage_Model <List <T_InterfaceInfo> >();

            try
            {
                string VoucherType = "";
                string ErpJson     = string.Empty;
                string Result      = string.Empty;

                JToken jtoken = JToken.Parse(VoucherJson);


                if (jtoken.GetType().Name == "JObject")
                {
                    VoucherType = jtoken["VoucherType"].ToString();
                }
                else
                {
                    VoucherType = jtoken[0]["VoucherType"].ToString();
                }

                if (string.IsNullOrEmpty(VoucherType))
                {
                    messageModel.HeaderStatus = "E";
                    messageModel.MaterialDoc  = string.Empty;
                    messageModel.ModelJson    = null;
                    messageModel.Message      = "过账检查单据类型为空!";
                    return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                }

                if (!string.IsNullOrEmpty(VoucherType))
                {
                    if (Convert.ToInt32(VoucherType) == 0)
                    {
                        messageModel.HeaderStatus = "E";
                        messageModel.MaterialDoc  = string.Empty;
                        messageModel.ModelJson    = null;
                        messageModel.Message      = "过账检查单据类型为零!";
                        return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                    }
                }

                List <T_InterfaceInfo> lstModel = GetInterface(VoucherType);

                if (lstModel == null || lstModel.Count == 0)
                {
                    messageModel.HeaderStatus = "S";
                    messageModel.MaterialDoc  = string.Empty;
                    messageModel.ModelJson    = null;
                    return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                }

                //配置了过账前检查
                T_InterfaceInfo model = GetInterface(VoucherType).Find(t => t.Function == "1");

                if (model != null)
                {
                    CreateInterfacePost(model, VoucherJson);
                }

                T_InterfaceInfo modelPost = GetInterface(VoucherType).Find(t => t.Function == "2");

                if (modelPost == null)
                {
                    messageModel.HeaderStatus = "S";
                    messageModel.MaterialDoc  = string.Empty;
                    messageModel.ModelJson    = null;
                    messageModel.Message      = string.Empty;
                    return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                }
                //LogNet.LogInfo("ymh:ERPbefor-" + modelPost.ClassName + "-" + modelPost.FunctionName);

                ErpJson = CreateInterfacePost(modelPost, VoucherJson);

                //LogNet.LogInfo("ymh:ERPBACK-" + ErpJson);

                jtoken = JToken.Parse(ErpJson);

                if (jtoken.GetType().Name == "JObject")
                {
                    Result = jtoken["result"].ToString();
                }
                else
                {
                    Result = jtoken[0]["result"].ToString();
                }

                if (Result == "1")
                {
                    messageModel.HeaderStatus = "S";
                    messageModel.MaterialDoc  = jtoken["resultValue"].ToString();
                    messageModel.ModelJson    = null;
                    messageModel.Message      = string.Empty;
                    return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                }
                else
                {
                    messageModel.HeaderStatus = "E";
                    messageModel.MaterialDoc  = string.Empty;
                    messageModel.ModelJson    = null;
                    messageModel.Message      = "ERP接口" + jtoken["resultValue"].ToString();
                    return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
                }
            }
            catch (Exception ex)
            {
                messageModel.HeaderStatus = "E";
                messageModel.MaterialDoc  = string.Empty;
                messageModel.Message      = ex.Message;
                messageModel.ModelJson    = null;
                return(JSONUtil.JSONHelper.ObjectToJson <BaseMessage_Model <List <T_InterfaceInfo> > >(messageModel));
            }
        }