示例#1
0
        private void SaveData <T>(List <T> srcList)
        {
            if (srcList == null || srcList.Count == 0 || this.OnTestMode)
            {
                return;
            }

            string typeName = typeof(T).Name;

            //搜索到当前DataLoader
            DataLoaderManager dlm = DataLoaderManagerList.Find(delegate(DataLoaderManager w) { return(w.TableName.ToLower() == typeName.ToLower()); });

            if (dlm == null || dlm.IsActive == false)
            {
                //DataMessageManager.GetInstance().AddMessage(DataMessageType.Infomation, LibConsts.C_Msg_NotActive + ":" + typeName, "", "", null, null);
                return;
            }

            //保存入数据库
            if (dlm.SaveToDB)
            {
                Type       dcType = this._DataCenter.GetType();
                MethodInfo mi     = dcType.GetMethod("Save" + typeName);
                mi.Invoke(this._DataCenter, new object[] { srcList });
            }
        }
示例#2
0
        public void BuildWorkerByDBConfig()
        {
            //==============================
            //搜索现有的数据源
            //==============================
            string sql = "select * from datacentersrc where active = 1";

            DataSet dsDataSrc = this._DBInstance.ExecuteSQL(sql);

            if (dsDataSrc == null || dsDataSrc.Tables.Count == 0 || dsDataSrc.Tables[0].Rows.Count == 0)
            {
                return;
            }

            foreach (DataRow oRow in dsDataSrc.Tables[0].Rows)
            {
                string dbType = oRow[LibConsts.C_Col_DBType].ToString();
                string dbConn = oRow[LibConsts.C_Col_DBConnection].ToString();
                string vandor = oRow[LibConsts.C_Col_DataVandor].ToString();


                DBInstanceType dbInstanceType = (DBInstanceType)Enum.Parse(typeof(DBInstanceType), dbType, true);
                ADBInstance    inst           = DBInstanceFactory.GetDBInstance(dbInstanceType, dbConn);
                VandorType     vandorType     = (VandorType)Enum.Parse(typeof(VandorType), vandor, true);
                ADataLoader    loader         = DataLoaderFactory.GetDataLoader(inst, vandorType);

                _DataLoaderList.Add(loader);
            }

            //==============================
            //搜索现有的数据表
            //==============================
            sql = @"Select A.Tablename, B.Vandor as Mainsrc, C.Vandor as Subsrc, D.Vandor as Chksrc, A.SaveDB
                    From datacenterconfig A
                    Left join datacentersrc B
                         ON A.Mainsrc = B.Src
                    Left join datacentersrc C
                         ON A.Subsrc = C.Src 
                    Left join datacentersrc D
                         ON A.Chksrc = D.Src ";

            if (OnTestMode)
            {
                sql += "Where A.ActiveTest = 1";
            }
            else
            {
                sql += "Where A.Active = 1";
            }

            DataSet dsDataTables = this._DBInstance.ExecuteSQL(sql);

            if (dsDataTables == null || dsDataTables.Tables.Count == 0 || dsDataTables.Tables[0].Rows.Count == 0)
            {
                return;
            }

            foreach (DataRow oRow in dsDataTables.Tables[0].Rows)
            {
                DataLoaderManager w = new DataLoaderManager();
                w.TableName = oRow[LibConsts.C_Col_TableName].ToString();

                //Main
                string     strVandor  = oRow[LibConsts.C_Col_MainSource].ToString();
                VandorType vandorType = (VandorType)Enum.Parse(typeof(VandorType), strVandor, true);
                w.MainSource = _DataLoaderList.Find(delegate(ADataLoader l) { return(l.CurrentVandor == vandorType); });

                //Sub
                strVandor = (oRow[LibConsts.C_Col_SubSource] == DBNull.Value) ? "" : oRow[LibConsts.C_Col_SubSource].ToString();
                if (strVandor.Length > 0)
                {
                    vandorType  = (VandorType)Enum.Parse(typeof(VandorType), strVandor, true);
                    w.SubSource = _DataLoaderList.Find(delegate(ADataLoader l) { return(l.CurrentVandor == vandorType); });
                }

                //Check
                strVandor = (oRow[LibConsts.C_Col_CheckSource] == DBNull.Value) ? "" : oRow[LibConsts.C_Col_CheckSource].ToString();
                if (strVandor.Length > 0)
                {
                    vandorType    = (VandorType)Enum.Parse(typeof(VandorType), strVandor, true);
                    w.CheckSource = _DataLoaderList.Find(delegate(ADataLoader l) { return(l.CurrentVandor == vandorType); });
                }

                //Save
                if (oRow[LibConsts.C_Col_SaveDB] == DBNull.Value)
                {
                    w.SaveToDB = false;
                }
                else
                {
                    if (oRow[LibConsts.C_Col_SaveDB].ToString() == "1")
                    {
                        w.SaveToDB = true;
                    }
                    else
                    {
                        w.SaveToDB = false;
                    }
                }

                this.DataLoaderManagerList.Add(w);
            }
        }
示例#3
0
        private List <T> ReadData <T>()
        {
            try
            {
                string typeName = typeof(T).Name;

                //搜索到当前DataLoader
                DataLoaderManager dlm = DataLoaderManagerList.Find(delegate(DataLoaderManager w) { return(w.TableName.ToLower() == typeName.ToLower()); });

                if (dlm == null || dlm.IsActive == false)
                {
                    if (dlm != null)
                    {
                        this.CurrentActive = dlm.IsActive;
                    }
                    else
                    {
                        this.CurrentActive = false;
                    }

                    DataMessageManager.GetInstance().AddMessage(DataMessageType.Infomation, LibConsts.C_Msg_NotActive, typeName, null);
                    return(null);
                }

                //===========================
                //  Main Source
                //===========================
                if (dlm.MainSource == null)
                {
                    DataMessageManager.GetInstance().AddMessage(DataMessageType.Error, LibConsts.C_Msg_MissingMainSource, typeName, null);
                    return(null);
                }

                List <T> mainSrcList = null, subSrcList, chkSrcList;
                object   mainSrcObj = null, subSrcObj = null, chkSrcObj = null;

                //即将调用的方法名
                string methodName = "Get" + typeName;

                if (dlm.MainSource != null)
                {
                    //预设参数
                    dlm.MainSource.SetParameter(this.Para_WindCode, this.Para_StartDate, this.Para_EndDate, this.Para_LoopingDate);

                    //通过反射方法调用
                    mainSrcObj = dlm.MainSource.GetType().GetMethod(methodName).Invoke(dlm.MainSource, null);
                }

                //===========================
                //  Sub Source
                //===========================
                if (dlm.SubSource != null)
                {
                    //预设参数
                    dlm.SubSource.SetParameter(this.Para_WindCode, this.Para_StartDate, this.Para_EndDate, this.Para_LoopingDate);

                    //通过反射方法调用
                    subSrcObj = dlm.SubSource.GetType().GetMethod(methodName).Invoke(dlm.SubSource, null);
                }

                //===========================
                //  Check Source
                //===========================
                if (dlm.CheckSource != null)
                {
                    //预设参数
                    dlm.CheckSource.SetParameter(this.Para_WindCode, this.Para_StartDate, this.Para_EndDate, this.Para_LoopingDate);

                    //通过反射方法调用
                    chkSrcObj = dlm.CheckSource.GetType().GetMethod(methodName).Invoke(dlm.CheckSource, null);
                }


                if (mainSrcObj is List <T> )
                {
                    mainSrcList = mainSrcObj as List <T>;
                    subSrcList  = subSrcObj as List <T>;
                    chkSrcList  = chkSrcObj as List <T>;

                    if (!this.checkSrc(mainSrcList, subSrcList, chkSrcList, typeName))
                    {
                        return(null);
                    }

                    //获得数据结构的主键
                    Type      objType = mainSrcList[0].GetType();
                    FieldInfo fldPK   = objType.GetField(AShareBase.C_Property_PrimaryKey);

                    foreach (T m in mainSrcList)
                    {
                        //记录主键值得变量
                        string pkInfo = "";

                        if (subSrcList != null)
                        {
                            //按主键搜索不同数据源中对应的记录
                            T s = subSrcList.Find(delegate(T d)
                            {
                                string primaryKey = fldPK.GetValue(d).ToString();
                                string[] pkArray  = primaryKey.Split(",".ToCharArray());

                                pkInfo = "";
                                foreach (string pk in pkArray)
                                {
                                    FieldInfo fld = objType.GetField(pk.Trim());

                                    if (!fld.GetValue(d).Equals(fld.GetValue(m)))
                                    {
                                        return(false);
                                    }

                                    pkInfo += fld.GetValue(d).ToString() + "|";
                                }

                                pkInfo = pkInfo.Substring(0, pkInfo.Length - 1);
                                return(true);
                            }
                                                  );

                            T c = default(T);
                            if (chkSrcList != null)
                            {
                                c = chkSrcList.Find(delegate(T d)
                                {
                                    string primaryKey = fldPK.GetValue(d).ToString();
                                    string[] pkArray  = primaryKey.Split(",".ToCharArray());

                                    //pkInfo = "";
                                    foreach (string pk in pkArray)
                                    {
                                        FieldInfo fld = objType.GetField(pk.Trim());

                                        if (!fld.GetValue(d).Equals(fld.GetValue(m)))
                                        {
                                            return(false);
                                        }

                                        //pkInfo += fld.GetValue(d).ToString() + "|";
                                    }

                                    //pkInfo = pkInfo.Substring(0, pkInfo.Length - 1);
                                    return(true);
                                }
                                                    );
                            }

                            //比较记录
                            if (s != null)
                            {
                                MethodInfo method = m.GetType().GetMethod(AShareBase.C_Method_CleanBy);
                                method.Invoke(m, new object[] { s, c, pkInfo, typeof(T).Name, this.Para_LoopingDate.ToString("yyyyMMdd") });
                            }
                        }
                    }
                }

                return(mainSrcList);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }