예제 #1
0
        static void Main(string[] args)
        {
            BaseFunc.InitConfigs(); //配置初始化

            #region 测试
            //int t = '0' - '0';

            //double x = 1, y = 1, z = 1;
            //int m = 1;
            //double d = Math.Sqrt((Math.Sign(4 - m) == 1 ? 1 : 0) * Math.Pow(x, 2) + (Math.Sign(3 - m) == 1 ? 1 : 0) * Math.Pow(y, 2) + (Math.Sign(2 - m) == 1 ? 1 : 0) * Math.Pow(z, 2));
            ////int level = BaseFunc.GetThreatLevelByValue(-1);
            //int temp = 1;

            //Radar radar = new Radar() { DegreeYoz = -90, DegreeXoy = 0, DegreeXoz = -60, DegreeGeneral = 180 };
            //List<ObjectGeneral> list = new List<ObjectGeneral>() { new ObjectGeneral(null, radar) { DistLong = 2, DistLat = 2, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 5, DistLat = 5, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 3, DistLat = 3, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 1, DistLat = 1, Color = Color.FromArgb(255, 255, 0) } };
            //list.Sort((o1, o2) => o1.DistanceToBorder.CompareTo(o2.DistanceToBorder));
            //////BaseFunc.WriteMessagesToFile<ObjectGeneral>(list, false);
            ////BaseFunc.WriteMessagesToFile<ObjectGeneral>(list, true);
            //return;

            //string base64 = Convert.ToBase64String(File.ReadAllBytes("ars_coor.png")); //将文件转换为base64编码
            //File.WriteAllBytes("ars_coor1.png", Convert.FromBase64String(base64));

            //List<SensorMessage> list = new List<SensorMessage>();
            //list.Add(new ClusterGeneral());
            //list.Add(new ClusterGeneral());
            //list.Add(new ObjectGeneral());
            //list.Add(new ObjectGeneral());
            //int count1 = list.Count(m => m is ClusterGeneral), count2 = list.Count(m => m is ObjectGeneral);
            //List<ClusterGeneral> list = new List<ClusterGeneral>();
            //ClusterGeneral o = new ClusterGeneral();
            //o = (dynamic)o;

            //list.Add((dynamic)o);
            //ClusterGeneral g = Converter.Convert<ClusterGeneral>(o);
            //int temp = 1;

            //string test = "\r\nsometest".TrimEnd('\r', '\n');
            //test = "\r\n".TrimEnd('\r', '\n');

            //string t = Base.StartupPath;
            //byte r, g, b;
            //r = (g = (b = 120));
            //int rgb = ((int)r << 16 | (int)g << 8 | (int)b);

            //List<SensorMessage> messages = new List<SensorMessage>();
            //messages.Add(new ClusterGeneral());
            //messages.Add(new ClusterStatus());
            //foreach (var message in messages)
            //{
            //    Type type = message.GetType();
            //    string temp = message.GetType().ToString();
            //    int t = 1;
            //}

            //char[] cs = "05 00 00 06 00 0D 04 BF 43 10 00 00 00".ToCharArray();
            //byte b = Convert.ToByte("11001101", 2);
            //int msg_0;
            //byte sensor = BaseFunc.GetSensorIdByMessageId(0x721, out msg_0);
            //SensorMessageId_0 messageid = (SensorMessageId_0)msg_0;
            //string message = messageid.GetDescription();

            //int temp = 1;
            #endregion


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form form;

            form = new FormMain();
            string argstring = args == null ? string.Empty : ";" + string.Join(";", args).ToUpper() + ";";
            //if (args != null && args.Contains(single"))
            if (argstring.Contains(";SINGLE;"))
            {
                form = new FormDisplay();
            }

            //Application.Run(new FormMain());
            Application.Run(form);
        }
예제 #2
0
        /// <summary>
        /// 建立資料庫命令產生器。
        /// </summary>
        /// <param name="sessionInfo">連線資訊。</param>
        /// <param name="programDefine">程式定義。</param>
        public static IDbCommandBuilder CreateDbCommandBuilder(GSessionInfo sessionInfo, GProgramDefine programDefine)
        {
            string sMessage;

            switch (sessionInfo.DatabaseType)
            {
            case EDatabaseType.SQLServer:
                return(new GSqlCommandBuilder(sessionInfo.SessionGuid, programDefine));

            case EDatabaseType.Oracle:
                return(new GOracleCommandBuilder(sessionInfo.SessionGuid, programDefine));

            default:
                sMessage = StrFunc.StrFormat(@"DatabaseType={0} Not Supported IDbCommandBuilder", BaseFunc.GetEnumName(sessionInfo.DatabaseType));
                throw new NotSupportedException(sMessage);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            BaseFunc.InitConfigs(); //配置初始化
            #region 测试
            //int level = BaseFunc.GetThreatLevelByValue(-999, RadarGroupType.Bucket);
            //int a = 1, b = 2;
            //    goto markb;
            //marka:
            //    a = 3;
            //markb:
            //    b = 4;
            //    int c = 5;
            //IPEndPoint point = (IPEndPoint)null;
            //string temp1 = false.ToString();
            //bool flag1 = bool.Parse(temp1);
            //temp1 = true.ToString();
            //DataFrameMessages info = new DataFrameMessages();
            //List<double> numbers = new List<double>() { 0, 0, 7.2, 7.4, 7.5, 7.6, 7.3, 7.1, 10, 10.2, 4, 3.8, 7.2, 10, 10.1, 10.2, 10.3, 10.2, 7, 10.2, 0, 0, 0, 0, 0 };
            //foreach (var number in numbers)
            //{
            //    info.IterateDistance(number);
            //}

            //List<FalseAlarmProbability> list = "".Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(p => (FalseAlarmProbability)int.Parse(p)).ToList();

            //string t = "";
            //MatchCollection matches = BaseConst.RegWrapped.Matches(t);
            //int i = 1;

            //string testie = string.Format("{0}", (int)Directions.Down);
            //testie = testie;
            //int t = '0' - '0';

            //double x = 1, y = 1, z = 1;
            //int m = 1;
            //double d = Math.Sqrt((Math.Sign(4 - m) == 1 ? 1 : 0) * Math.Pow(x, 2) + (Math.Sign(3 - m) == 1 ? 1 : 0) * Math.Pow(y, 2) + (Math.Sign(2 - m) == 1 ? 1 : 0) * Math.Pow(z, 2));
            ////int level = BaseFunc.GetThreatLevelByValue(-1);
            //int temp = 1;

            //Radar radar = new Radar() { DegreeYoz = -90, DegreeXoy = 0, DegreeXoz = -60, DegreeGeneral = 180 };
            //List<ObjectGeneral> list = new List<ObjectGeneral>() { new ObjectGeneral(null, radar) { DistLong = 2, DistLat = 2, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 5, DistLat = 5, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 3, DistLat = 3, Color = Color.FromArgb(255, 255, 0) }, new ObjectGeneral(null, radar) { DistLong = 1, DistLat = 1, Color = Color.FromArgb(255, 255, 0) } };
            //list.Sort((o1, o2) => o1.DistanceToBorder.CompareTo(o2.DistanceToBorder));
            //////BaseFunc.WriteMessagesToFile<ObjectGeneral>(list, false);
            ////BaseFunc.WriteMessagesToFile<ObjectGeneral>(list, true);
            //return;

            //string base64 = Convert.ToBase64String(File.ReadAllBytes("ars_coor.png")); //将文件转换为base64编码
            //File.WriteAllBytes("ars_coor1.png", Convert.FromBase64String(base64));

            //List<SensorMessage> list = new List<SensorMessage>();
            //list.Add(new ClusterGeneral());
            //list.Add(new ClusterGeneral());
            //list.Add(new ObjectGeneral());
            //list.Add(new ObjectGeneral());
            //int count1 = list.Count(m => m is ClusterGeneral), count2 = list.Count(m => m is ObjectGeneral);
            //List<ClusterGeneral> list = new List<ClusterGeneral>();
            //ClusterGeneral o = new ClusterGeneral();
            //o = (dynamic)o;

            //list.Add((dynamic)o);
            //ClusterGeneral g = Converter.Convert<ClusterGeneral>(o);
            //int temp = 1;

            //string test = "\r\nsometest".TrimEnd('\r', '\n');
            //test = "\r\n".TrimEnd('\r', '\n');

            //string t = Base.StartupPath;
            //byte r, g, b;
            //r = (g = (b = 120));
            //int rgb = ((int)r << 16 | (int)g << 8 | (int)b);

            //List<SensorMessage> messages = new List<SensorMessage>();
            //messages.Add(new ClusterGeneral());
            //messages.Add(new ClusterStatus());
            //foreach (var message in messages)
            //{
            //    Type type = message.GetType();
            //    string temp = message.GetType().ToString();
            //    int t = 1;
            //}

            //char[] cs = "05 00 00 06 00 0D 04 BF 43 10 00 00 00".ToCharArray();
            //byte b = Convert.ToByte("11001101", 2);
            //int msg_0;
            //byte sensor = BaseFunc.GetSensorIdByMessageId(0x721, out msg_0);
            //SensorMessageId_0 messageid = (SensorMessageId_0)msg_0;
            //string message = messageid.GetDescription();

            //int temp = 1;
            #endregion

            //double x = 100, y = 200, h = 20, phi = 75; //本地XY坐标与海拔,大臂航向
            //double rc = 45, hc = 10, lamda = 47.9457; //定位天线距俯仰轴距离,俯仰轴海拔,坝基方向与真北夹角
            //double x_prime = x - Math.Sqrt(Math.Pow(rc, 2) - Math.Pow(hc - h, 2)) * Math.Cos(phi - lamda);
            //double y_prime = y - Math.Sqrt(Math.Pow(rc, 2) - Math.Pow(hc - h, 2)) * Math.Sin(phi - lamda);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string argstring = args == null ? string.Empty : ";" + string.Join(";", args).ToUpper() + ";";
            int    temp      = 1;
            if (temp == 2)
            {
                argstring = ";SINGLE;";
            }
            Form form = argstring.Contains(";SINGLE;") ? (Form) new FormDisplay() : new FormMain();

            Application.Run(form);
        }
예제 #4
0
 public FrmPvsCancelScn()
 {
     InitializeComponent();
     myFunc = new BaseFunc();
 }
예제 #5
0
        /// <summary>
        /// 依資料庫類型建立資料庫命令輔助類別。
        /// </summary>
        /// <param name="databaseType">資料庫類型。</param>
        /// <param name="commandText">命令字串。</param>
        public static IDbCommandHelper CreateDbCommandHelper(EDatabaseType databaseType, string commandText)
        {
            string sMessage;

            switch (databaseType)
            {
            case EDatabaseType.SQLServer:
                return(new GSqlCommandHelper(commandText));

            case EDatabaseType.Oracle:
                return(new GOracleCommandHelper(commandText));

            default:
                sMessage = StrFunc.StrFormat(@"DatabaseType={0} Not Supported IDbCommandHelper", BaseFunc.GetEnumName(databaseType));
                throw new NotSupportedException(sMessage);
            }
        }
예제 #6
0
        public Object operEjecutarTransaccion(string sClase, string sMetodo, Object objParam)
        {
            object        oEntidad    = null;
            Object        oResultado  = null;
            DbConnection  connection  = null;
            DbTransaction transaction = null;
            BaseFunc      bfEntidad   = null;

            Type tyObjeto = Type.GetType(sClase);

            if (tyObjeto == null)
            {
                return(null);
            }

            try
            {
                using (connection = ObtenerObjeto <DbConnection>(_objDbModel.objDbConnection))
                {
                    connection.ConnectionString = _objDbModel.connectionString;
                    connection.Open();
                    transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
                    try
                    {
                        oEntidad = Activator.CreateInstance(tyObjeto, connection, null, _objDbModel.objDbDataAdapter);
                        if (objParam == null)
                        {
                            bfEntidad = (BaseFunc)oEntidad.GetType().GetMethod(sMetodo).Invoke(oEntidad, null);
                        }
                        else
                        {
                            bfEntidad = (BaseFunc)oEntidad.GetType().GetMethod(sMetodo).Invoke(oEntidad, new[] { objParam });
                        }

                        if (bfEntidad.MsjError == "" || bfEntidad.MsjError == null)
                        {
                            transaction.Commit();
                        }
                        else
                        {
                            MsjError = bfEntidad.MsjError;
                            transaction.Rollback();
                        }
                    }
                    catch (Exception e)
                    {
                        if (bfEntidad.MsjError != null)
                        {
                            MsjError = bfEntidad.MsjError;
                        }
                        else
                        {
                            MsjError = e.Message;
                        }

                        oResultado = null;
                        transaction.Rollback();
                        Console.WriteLine("Operación cancelada : " + e.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                MsjError = "Error al conextarse a la Base de Datos";
                Console.WriteLine("Error en la conexión  : " + e.ToString());
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }

            return(oResultado);
        }
예제 #7
0
        public Object operEjecutarTransaccion <T>(string sNombre, object objParam)
        {
            BaseFunc      bfEntidad   = null;
            Object        oResultado  = null;
            DbConnection  connection  = null;
            DbTransaction transaction = null;

            try
            {
                using (connection = ObtenerObjeto <DbConnection>(_objDbModel.objDbConnection))
                {
                    connection.ConnectionString = _objDbModel.connectionString;
                    connection.Open();
                    transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
                    try
                    {
                        bfEntidad = Activator.CreateInstance(typeof(T), connection, transaction, _objDbModel.objDbDataAdapter) as BaseFunc;
                        if (objParam == null)
                        {
                            oResultado = bfEntidad.GetType().GetMethod(sNombre).Invoke(bfEntidad, null);
                        }
                        else
                        {
                            oResultado = bfEntidad.GetType().GetMethod(sNombre).Invoke(bfEntidad, new[] { objParam });
                        }

                        // si el objeto es de cierto tipo.. omitir la transaccion..
                        if (bfEntidad.MsjError == "" || bfEntidad.MsjError == null)
                        {
                            transaction.Commit();
                        }
                        else
                        {
                            // HUbo un error lógico o existia un try catch que lo resolvio..
                            MsjError = bfEntidad.MsjError;
                            transaction.Rollback();
                        }
                    }
                    catch (Exception e)
                    {
                        if (bfEntidad.MsjError != null)
                        {
                            MsjError = bfEntidad.MsjError;
                        }
                        else
                        {
                            MsjError = e.Message;
                        }

                        oResultado = null;
                        transaction.Rollback();
                        Console.WriteLine("Operación cancelada : " + e.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error al conextarse a la Base de Datos  : " + e.ToString());
            }
            finally
            {
                if (connection != null)
                {
                    connection.Close();
                }
            }
            return(oResultado);
        }
예제 #8
0
        /// <summary>
        /// 建立 Select 語法的資料庫命令。
        /// </summary>
        /// <param name="tableName">資料表名稱。</param>
        /// <param name="selectFields">要取得的欄位集合字串,以逗點分隔欄位名稱,空字串表示取得所有欄位。</param>
        /// <param name="filterItems">資料過濾條件項目集合。</param>
        /// <param name="userFilter">自訂過濾條件。</param>
        /// <param name="isOrderBy">執行排序</param>
        public virtual DbCommand BuildSelectCommand(string tableName, string selectFields,
                                                    GFilterItemCollection filterItems, string userFilter, bool isOrderBy = true)
        {
            IDbCommandHelper     oHelper;
            GTableJoinProvider   oTableJoinProvider;
            StringBuilder        oBuffer;
            StringBuilder        oFilterBuffer;
            IFilterBuilder       oFilterBuilder;
            GTableDefine         oTableDefine;
            GSortFieldCollection oSortFields;
            GFilterInputArgs     oFilterInputArgs;
            string sCommandText;
            string sFilter;
            string sSort;
            string sJoin;

            // 無資料表定義則離開
            oTableDefine = this.GeGTableDefine(tableName);
            if (BaseFunc.IsNull(oTableDefine))
            {
                return(null);
            }

            // 建立資料庫命令輔助類別
            oHelper = DatabaseFunc.CreateDbCommandHelper(this.DatabaseType);

            // 取得排序欄位集合
            oSortFields = GetSortFields(oTableDefine);

            // 建置資料表關連資訊
            oTableJoinProvider = new GTableJoinProvider();
            oTableJoinProvider.Execute(this.ProgramDefine, tableName, selectFields, filterItems, oSortFields);

            oBuffer = new StringBuilder();

            // 產生 SELECT 欄位的語法
            sCommandText = GetSelectFieldsCommandText(oHelper, oTableJoinProvider, tableName, selectFields);
            oBuffer.AppendLine(sCommandText);


            oFilterBuffer = new StringBuilder();
            // 查詢過濾條件
            oFilterInputArgs = new GFilterInputArgs(oHelper, this.ProgramDefine, tableName, oTableJoinProvider, filterItems, this.SessionInfo, true);
            oFilterBuilder   = new GFilterBuilder(oFilterInputArgs);
            sFilter          = oFilterBuilder.GetFilter(out sJoin);
            AddFilter(oFilterBuffer, sFilter);

            // 自訂過濾條件
            AddFilter(oFilterBuffer, userFilter);

            // 產生 FROM 及 JOIN 語法
            sCommandText = GeGTableJoinCommandText(oHelper, oTableJoinProvider, oTableDefine);
            oBuffer.Append(sCommandText);

            if (StrFunc.StrIsNotEmpty(sJoin))
            {
                oBuffer.Append(sJoin);
            }

            // 加入過濾條件
            if (oFilterBuffer.Length > 0)
            {
                oBuffer.AppendLine(" Where ");
                oBuffer.AppendLine(oFilterBuffer.ToString());
            }

            // 加入排序語法
            if (isOrderBy)
            {
                sSort = GetSortCommandText(oHelper, oTableJoinProvider, oTableDefine, oSortFields);
                if (StrFunc.StrIsNotEmpty(sSort))
                {
                    oBuffer.Append(sSort);
                }
            }

            oHelper.SetCommandText(oBuffer.ToString());
            return(oHelper.DbCommand);
        }
예제 #9
0
        /// <summary>
        /// 建立 Update 語法的資料庫命令。
        /// </summary>
        /// <param name="tableName">資料表名稱。</param>
        public virtual DbCommand BuildUpdateCommand(string tableName)
        {
            IDbCommandHelper oHelper;
            StringBuilder    oBuffer;
            GTableDefine     oTableDefine;
            GFieldDefine     oKeyFieldDefine;
            DbParameter      oParameter;
            string           sSeparator, sFormat;

            string[] oKeyFields;

            // 無資料表定義或不啟用資料庫命令,則傳回 Null
            oTableDefine = this.GeGTableDefine(tableName);
            if (BaseFunc.IsNull(oTableDefine))
            {
                return(null);
            }

            // 建立資料庫命令輔助類別
            oHelper = DatabaseFunc.CreateDbCommandHelper(this.DatabaseType);

            oBuffer = new StringBuilder();
            oBuffer.AppendFormat("UPDATE {0} WITH ( ROWLOCK ) ", oHelper.GetTableName(oTableDefine.DbTableName));
            oBuffer.AppendLine();

            // 處理 Update 的欄位名稱與值
            sSeparator = string.Empty;
            oBuffer.AppendLine("SET");

            foreach (GFieldDefine fieldDefine in oTableDefine.Fields)
            {
                // FieldType 為 DataField 才需做更新,但排除 SYS_CompanyID、SYS_ID、SYS_RowID、SYS_INSDAT、SYS_USR
                if (fieldDefine.FieldType == EFieldType.DataField && !StrFunc.SameTextOr(fieldDefine.FieldName, SysFields.CompanyID, SysFields.ID, SysFields.RowID, SysFields.InsertDate, SysFields.InsertUser))
                {
                    // 加入命令參數
                    oParameter = oHelper.AddParameter(fieldDefine);
                    sFormat    = "{0}{1}={2}";
                    oBuffer.AppendFormat(sFormat, sSeparator, oHelper.GetFieldName(fieldDefine.DbFieldName), oParameter.ParameterName);
                    oBuffer.AppendLine();
                    sSeparator = ", ";
                }
            }

            // 更新主鍵優先順序為 SYS_RowID、SYS_CompanyID+SYS_ID,CompanyID+SYS_ID、PrimaryKey
            if (oTableDefine.Fields.Contains(SysFields.RowID))
            {
                oKeyFields = new string[] { SysFields.RowID }
            }
            ;
            else if (oTableDefine.Fields.Contains(SysFields.CompanyID) && oTableDefine.Fields.Contains(SysFields.ID))
            {
                oKeyFields = new string[] { SysFields.CompanyID, SysFields.ID }
            }
            ;
            else if (oTableDefine.Fields.Contains(SysFields.CommonCompanyID) && oTableDefine.Fields.Contains(SysFields.ID))
            {
                oKeyFields = new string[] { SysFields.CommonCompanyID, SysFields.ID }
            }
            ;
            else if (StrFunc.StrIsNotEmpty(oTableDefine.PrimaryKey))
            {
                oKeyFields = StrFunc.StrSplit(oTableDefine.PrimaryKey, ",");
            }
            else
            {
                throw new GException("{0} 未包含 Sys_ID 或 Sys_RowID 欄位,無法建立 Update Command", tableName);
            }

            // 產生更新的 Where 條件
            oBuffer.AppendLine("WHERE 1=1");
            foreach (string sFieldName in oKeyFields)
            {
                oKeyFieldDefine = oTableDefine.Fields[sFieldName];
                oParameter      = oHelper.AddOriginalParameter(oKeyFieldDefine);
                sFormat         = "AND {0}={1}";
                oBuffer.AppendLine(StrFunc.StrFormat(sFormat, oHelper.GetFieldName(oKeyFieldDefine.DbFieldName), oParameter.ParameterName));
            }

            oHelper.SetCommandText(oBuffer.ToString());
            return(oHelper.DbCommand);;
        }
예제 #10
0
        /// <summary>
        /// 建立資料表關連。
        /// </summary>
        /// <param name="key">關連鍵值。</param>
        /// <param name="provider">資料表關連資訊提供者。</param>
        /// <param name="fieldDefine">關連欄位定義。</param>
        /// <param name="returnFields">關連取回欄位集合。</param>
        /// <param name="leftTableAlias">左側資料表別名。</param>
        /// <param name="detailTableName">明細資料表名稱。</param>
        /// <param name="destFieldName">目的欄位名稱。</param>
        private void BuildTableJoin(string key, GTableJoinProvider provider, GFieldDefine fieldDefine, GStringHashSet returnFields, string leftTableAlias, string detailTableName, string destFieldName = "")
        {
            // 取得關連程式定義
            var programDefine = CacheFunc.GetProgramDefine(fieldDefine.LinkProgID);

            if (BaseFunc.IsNull(programDefine))
            {
                throw new GException("'{0}' ProgramDefine not found", fieldDefine.LinkProgID);
            }

            // 取得關連資料表定義
            var tableDefine = programDefine.MasterTable;

            foreach (string fieldName in returnFields)
            {
                var linkReturnField = fieldDefine.LinkReturnFields.FindByDestField(fieldName);
                if (BaseFunc.IsNull(linkReturnField))
                {
                    throw new GException("'{0}' FieldDefine's LinkReturnFields not find DestField '{1}'", fieldDefine.FieldName, fieldName);
                }

                var sourceFieldDefine = tableDefine.Fields[linkReturnField.SourceField];
                if (BaseFunc.IsNull(sourceFieldDefine))
                {
                    throw new GException("'{0}' TableDefine not find '{1}' FieldDefine", tableDefine.TableName, linkReturnField.SourceField);
                }

                if (sourceFieldDefine.FieldType == EFieldType.VirtualField)
                {
                    throw new GException("'{0}' TableDefine's '{1}' FieldDefine not allow VirtualField", tableDefine.TableName, sourceFieldDefine.FieldName);
                }

                var tableJoin = provider.TableJoins[key];
                if (BaseFunc.IsNull(tableJoin))
                {
                    // 建立資料表關連
                    tableJoin = new GTableJoin
                    {
                        Key             = key,
                        LeftTableAlias  = leftTableAlias,
                        LeftFieldName   = tableDefine.GetLinkReturnActiveField(fieldDefine).DbFieldName,
                        RightTableName  = tableDefine.DbTableName,
                        RightTableAlias = GetActiveTableAlias()
                    };
                    var sKeyField = tableDefine.Fields.Contains(SysFields.ID) ? SysFields.ID : SysFields.RowID;
                    tableJoin.RightFieldName = tableDefine.Fields[sKeyField].DbFieldName;
                    if (tableDefine.Fields.Contains(SysFields.CompanyID))
                    {
                        tableJoin.RightCompanyID = tableDefine.Fields[SysFields.CompanyID].DbFieldName;
                    }
                    else if (tableDefine.Fields.Contains(SysFields.CommonCompanyID))
                    {
                        tableJoin.RightCompanyID = tableDefine.Fields[SysFields.CommonCompanyID].DbFieldName;
                    }
                    provider.TableJoins.Add(tableJoin);
                }

                // 若來源欄位的欄位類型是 LinkField,則需往上階找關連來源
                if (sourceFieldDefine.FieldType == EFieldType.LinkField)
                {
                    var linkFieldDefine = tableDefine.GetLinkReturnActiveField(sourceFieldDefine);
                    var sKey            = key + "." + linkFieldDefine.LinkProgID;
                    var returnFieldSet  = new GStringHashSet {
                        sourceFieldDefine.DbFieldName
                    };
                    BuildTableJoin(sKey, provider, linkFieldDefine, returnFieldSet, tableJoin.RightTableAlias, detailTableName, fieldName);
                }
                else
                {
                    // 記錄關連欄位對應
                    var linkFieldMapping = new GLinkFieldMapping();
                    linkFieldMapping.FieldName = (StrFunc.StrIsNotEmpty(destFieldName)) ? destFieldName : fieldName;
                    if (StrFunc.StrIsNotEmpty(detailTableName))
                    {
                        linkFieldMapping.FieldName = StrFunc.StrFormat("{0}.{1}", detailTableName, linkFieldMapping.FieldName);
                    }
                    linkFieldMapping.TableAlias      = tableJoin.RightTableAlias;
                    linkFieldMapping.SourceFieldName = sourceFieldDefine.DbFieldName;
                    provider.Mappings.Add(linkFieldMapping);
                }
            }
        }