using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using MediII.Adapter.BaseBiz;
using MediII.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using MediII.Adapter.BizComponent.Base;

namespace MediII.Adapter.BizComponent.MFN
{
    public class BizComponent_MFN : BaseBizComponent, IBizComponent
    {
        //数据库连接
        protected Database ctx
        {
            get { return base.HealthCarectx; }
        }

        protected Database healthCarectx
        {
            get { return base.HealthCarectx; }
        }
        public override string DoProcess(string m,string msgType)
        {
            //只插入数据后续处理
            //SyncInsert(m);

            try
            {

                try
                {
                    //根据不同的类型再分开不同的类处理
                    MFNBase processor = MFNBase.GetProcessor(msgType.Replace('^', '_'), ctx);//
                    int result = processor.Process(m,msgType);
                    return string.Empty;

                    //string ack = SetACK(m, "ACK", mType, "ACK");
                    //return ack;
                }
                catch (Exception ex)
                {

                    if (ex.InnerException == null)
                    {
                        return ex.Message;
                    }
                    else
                    {
                        return ex.Message + " InnerException:" + ex.InnerException.Message;
                    }
                }

            }
            catch (Exception ex)
            {
                //var tmp = ex.EntityValidationErrors.FirstOrDefault().ValidationErrors;
                //string errString = "";
                //foreach (var item in tmp)
                //{
                //    errString += item.ErrorMessage;
                //}
                //string ack = SetACK(m, "ACK", mType, "ACK", ex.EntityValidationErrors.ToString());
                //throw new Exception(string.Format("{0}\r\n{1}", ex.EntityValidationErrors.ToString()));

                return ex.Message;
            }
        }
    }
}
