예제 #1
0
        public List <ListCompareTable> InportOriginData(DataTable dt, int nNowYear, long lProvinceID, long lGxID)
        {
            List <ListCompareTable> listReturn   = new List <ListCompareTable>();
            List <T_tddw_Origin>    OriginModels = InportSomeTddwOriginTable(dt, nNowYear, lProvinceID);
            TableStatusManage       statusManage = new TableStatusManage();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //T_tddw_Origin OriginModel = InportOneTddwOriginTable(dr, nNowYear, lProvinceID);
                long lNowRelationID = Convert.ToInt64(OriginModels[i].RelationID);
                if (lNowRelationID != 0) //原始表中已经存在,直接取用
                {
                    ListCompareTable oneTable = new ListCompareTable();
                    oneTable.sOldID    = dt.Rows[i]["TDDWDM"].ToString();
                    oneTable.lNewID    = lNowRelationID;
                    oneTable.lOriginID = OriginModels[i].ID;
                    listReturn.Add(oneTable);
                }
                else
                {
                    long   lNewID = 0;
                    T_tddw obj    = getOneMainRecord(lGxID, OriginModels[i]);
                    string MC     = GetOneStrValue(dt.Rows[i], "TDDWMC");
                    if (obj == null) //目前主表中不存在
                    {
                        while (!statusManage.BeginUpdate <T_tddw>())
                        {
                            Random ra = new Random();
                            Thread.Sleep(ra.Next(100, 1000));
                        }
                        obj = getOneMainRecord(lGxID, OriginModels[i]);
                        if (obj == null)  //还是不存在
                        {
                            T_tddw model = new T_tddw();
                            model.Name   = MC;
                            model.Code   = GetOneStrValue(dt.Rows[i], "TDDWDM");
                            model.Remark = GetOneStrValue(dt.Rows[i], "BZ");

                            ListCompareTable oneCompare = GetCompareList(PCDM_list, GetOneStrValue(dt.Rows[i], "PCDM", CosDataBase.LONGINT_TYPE));
                            if (oneCompare != null)
                            {
                                model.PcdmOrigin = oneCompare.lOriginID;
                                model.Pcdm       = oneCompare.lNewID;
                            }

                            oneCompare = GetCompareList(KLDM_list, GetOneStrValue(dt.Rows[i], "KLDM", CosDataBase.LONGINT_TYPE));
                            if (oneCompare != null)
                            {
                                model.KldmOrigin = oneCompare.lOriginID;
                                model.Kldm       = oneCompare.lNewID;
                            }

                            oneCompare = GetCompareList(JHXZDM_list, GetOneStrValue(dt.Rows[i], "JHXZDM", CosDataBase.LONGINT_TYPE));
                            if (oneCompare != null)
                            {
                                model.JhxzdmOrigin = oneCompare.lOriginID;
                                model.Jhxzdm       = oneCompare.lNewID;
                            }

                            oneCompare = GetCompareList(JHLBDM_list, GetOneStrValue(dt.Rows[i], "JHLBDM", CosDataBase.LONGINT_TYPE));
                            if (oneCompare != null)
                            {
                                model.JhlbdmOrigin = oneCompare.lOriginID;
                                model.Jhlbdm       = oneCompare.lNewID;
                            }

                            model.Csmbh = GetOneStrValue(dt.Rows[i], "CSMBH");
                            model.Tag   = GetOneStrValue(dt.Rows[i], "TAG");
                            model.GxID  = lGxID;

                            model.JoinNames = model.Name;

                            string[] EditColumns = { "Name",         "Code",   "Remark",       "PcdmOrigin", "Pcdm",  "KldmOrigin", "Kldm",
                                                     "JhxzdmOrigin", "Jhxzdm", "JhlbdmOrigin", "Jhlbdm",     "Csmbh", "Tag",        "GxID", "JoinNames" };

                            lNewID = SaveOneSimpleRecord(model, "tddwTable", EditColumns);
                            statusManage.EndUpdate <T_tddw>();
                            ListCompareTable oneTable = new ListCompareTable();
                            oneTable.sOldID    = GetOneStrValue(dt.Rows[i], "TDDWDM");
                            oneTable.lNewID    = lNewID;
                            oneTable.lOriginID = OriginModels[i].ID;
                            listReturn.Add(oneTable);
                        }
                        else
                        {
                            if (obj.DelFlag)
                            {
                                lNewID = obj.JoinID;
                            }
                            else
                            {
                                lNewID = obj.ID;
                            }
                            ListCompareTable oneTable = new ListCompareTable();
                            oneTable.sOldID    = GetOneStrValue(dt.Rows[i], "TDDWDM");
                            oneTable.lNewID    = lNewID;
                            oneTable.lOriginID = OriginModels[i].ID;
                            listReturn.Add(oneTable);
                        }
                    }
                    else //目前主表中存在
                    {
                        if (obj.DelFlag)
                        {
                            lNewID = obj.JoinID;
                        }
                        else
                        {
                            lNewID = obj.ID;
                        }
                        ListCompareTable oneTable = new ListCompareTable();
                        oneTable.sOldID    = GetOneStrValue(dt.Rows[i], "TDDWDM");
                        oneTable.lNewID    = lNewID;
                        oneTable.lOriginID = OriginModels[i].ID;
                        listReturn.Add(oneTable);
                    }
                    ////不管存在与否,都需修改原始表中相应的RelationID
                    string[] EditColumn = { "RelationID" };
                    OriginModels[i].GetType().GetProperty("RelationID").SetValue(OriginModels[i], lNewID, null);
                    SaveOneRecord(OriginModels[i], EditColumn);
                }
            }
            return(listReturn);
        }
        /// <summary>
        /// 导入基础数据表的公共函数
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="T1"></typeparam>
        /// <param name="dataTable"></param>
        /// <param name="nYear"></param>
        /// <param name="lProvinceID"></param>
        /// <param name="keyword"></param>
        /// <param name="mainColumns"></param>
        /// <param name="moreColumns"></param>
        /// <param name="moreColumnTypes"></param>
        /// <returns></returns>
        public List <ListCompareTable> InportSimpleTableOriginData <T, T1>(DataTable dataTable, int nYear, long lProvinceID, string keyword, string[] mainColumns = null, string[] moreColumns = null, int[] moreColumnTypes = null) where T : class, new() where T1 : class, new()
        {
            List <ListCompareTable> listReturn = new List <ListCompareTable>();

            try
            {
                if (dataTable != null)
                {
                    DataView dataView = dataTable.DefaultView;
                    if (mainColumns == null)
                    {
                        mainColumns    = new string[2];
                        mainColumns[0] = dataTable.Columns[0].ColumnName;
                        mainColumns[1] = dataTable.Columns[1].ColumnName;
                    }
                    DataTable         dt           = dataView.ToTable(true, mainColumns[0], mainColumns[1]);
                    List <T1>         OriginModels = InportSomeRowsOriginTable <T1>(dt, nYear, lProvinceID, mainColumns, moreColumns, moreColumnTypes);
                    TableStatusManage statusManage = new TableStatusManage();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        long lNowRelationID = Convert.ToInt64(OriginModels[i].GetType().GetProperty("RelationID").GetValue(OriginModels[i], null));
                        if (lNowRelationID == 0) //原始表中新加入的字段
                        {
                            long lNewID = 0;
                            T    obj    = getOneMainRecord <T>(dt.Rows[i][1].ToString());
                            if (obj == null) //目前主表中不存在
                            {
                                while (!statusManage.BeginUpdate <T>())
                                {
                                    Random ra = new Random();
                                    Thread.Sleep(ra.Next(100, 1000));
                                }
                                obj = getOneMainRecord <T>(dt.Rows[i][1].ToString());
                                if (obj == null)  //还是不存在
                                {
                                    int num = 4;
                                    if (moreColumns != null)
                                    {
                                        num = num + moreColumns.Length;
                                    }
                                    string[] EditColumns = new string[num];
                                    EditColumns[0] = "Name";
                                    EditColumns[1] = "Remark";
                                    EditColumns[2] = "Code";
                                    EditColumns[3] = "JoinNames";
                                    if (moreColumns != null)
                                    {
                                        for (int j = 0; j < moreColumns.Length; j++)
                                        {
                                            EditColumns[j + 4] = moreColumns[j];
                                        }
                                    }

                                    T model = new T();
                                    model.GetType().GetProperty("Name").SetValue(model, dt.Rows[i][1].ToString(), null);
                                    model.GetType().GetProperty("Code").SetValue(model, dt.Rows[i][0].ToString(), null);
                                    model.GetType().GetProperty("JoinNames").SetValue(model, dt.Rows[i][1].ToString(), null);

                                    if ((dt.Columns.Count > 2) && (dt.Columns[2].ColumnName == "BZ"))
                                    {
                                        model.GetType().GetProperty("Remark").SetValue(model, dt.Rows[i][2].ToString(), null);
                                    }
                                    model = ArrangeMoreColumns(moreColumns, moreColumnTypes, dt.Rows[i], model);

                                    lNewID = SaveOneSimpleRecord(model, keyword, EditColumns);
                                    statusManage.EndUpdate <T>();
                                    ListCompareTable oneTable = new ListCompareTable();
                                    oneTable.sOldID    = dt.Rows[i][0].ToString();
                                    oneTable.lNewID    = lNewID;
                                    oneTable.lOriginID = Convert.ToInt64(OriginModels[i].GetType().GetProperty("ID").GetValue(OriginModels[i], null));
                                    listReturn.Add(oneTable);
                                }
                                else //主表中存在了
                                {
                                    statusManage.EndUpdate <T>();
                                    lNewID = Convert.ToInt64(obj.GetType().GetProperty("ID").GetValue(obj, null));
                                    ListCompareTable oneTable = new ListCompareTable();
                                    oneTable.sOldID    = dt.Rows[i][0].ToString();
                                    oneTable.lNewID    = lNewID;
                                    oneTable.lOriginID = Convert.ToInt64(OriginModels[i].GetType().GetProperty("ID").GetValue(OriginModels[i], null));
                                    listReturn.Add(oneTable);
                                }
                            }
                            else //目前主表中存在
                            {
                                lNewID = Convert.ToInt64(obj.GetType().GetProperty("ID").GetValue(obj, null));
                                ListCompareTable oneTable = new ListCompareTable();
                                oneTable.sOldID    = dt.Rows[i][0].ToString();
                                oneTable.lNewID    = lNewID;
                                oneTable.lOriginID = Convert.ToInt64(OriginModels[i].GetType().GetProperty("ID").GetValue(OriginModels[i], null));
                                listReturn.Add(oneTable);
                            }
                            //不管存在与否,都需修改原始表中相应的RelationID
                            //string[] EditColumn = { "RelationID" };
                            OriginModels[i].GetType().GetProperty("RelationID").SetValue(OriginModels[i], lNewID, null);
                            //SaveOneRecord(OriginModels[i], EditColumn);
                        }
                        else //原始表中已有相关字段,直接取用
                        {
                            ListCompareTable oneTable = new ListCompareTable();
                            oneTable.sOldID    = dt.Rows[i][0].ToString();
                            oneTable.lNewID    = lNowRelationID;
                            oneTable.lOriginID = Convert.ToInt64(OriginModels[i].GetType().GetProperty("ID").GetValue(OriginModels[i], null));
                            listReturn.Add(oneTable);
                        }
                    }
                    SaveManyRecords(OriginModels);
                }
                return(listReturn);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
예제 #3
0
        public List <ListCompareTable> InportOriginData(DataTable dt, int nNowYear, long lProvinceID, long lParentDepartmentID, long GxID)
        {
            List <ListCompareTable> listReturn = new List <ListCompareTable>();

            if (dt != null)
            {
                List <Td_zydh_Origin> OriginModels = InportSomeRowsOriginTable <Td_zydh_Origin>(dt, nNowYear, lProvinceID);
                TableStatusManage     statusManage = new TableStatusManage();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    //先导入原始表
                    long lNowRelationID = Convert.ToInt64(OriginModels[i].RelationID);
                    if (lNowRelationID != 0) //原始表中已经存在,直接取用
                    {
                        ListCompareTable oneTable = new ListCompareTable();
                        oneTable.sOldID    = dt.Rows[i]["ZYDH"].ToString();
                        oneTable.lNewID    = OriginModels[i].RelationID;
                        oneTable.lOriginID = OriginModels[i].ID;
                        listReturn.Add(oneTable);
                    }
                    else
                    {
                        long    lNewID = 0;
                        Td_zydh obj    = getOneMainRecord(lParentDepartmentID, OriginModels[i]);
                        if (obj == null) //目前主表中不存在
                        {
                            while (!statusManage.BeginUpdate <Td_zydh>())
                            {
                                Random ra = new Random();
                                Thread.Sleep(ra.Next(100, 1000));
                            }
                            obj = getOneMainRecord(lParentDepartmentID, OriginModels[i]);
                            if (obj == null)  //还是不存在
                            {
                                Td_zydh model = new Td_zydh();
                                model.Name   = GetOneStrValue(dt.Rows[i], "ZYMC");
                                model.Code   = GetOneStrValue(dt.Rows[i], "ZYDH");
                                model.Remark = GetOneStrValue(dt.Rows[i], "BZ");

                                ListCompareTable oneCompare = GetCompareList(CCDM_list, GetOneStrValue(dt.Rows[i], "CCDM", CosDataBase.LONGINT_TYPE));
                                if (oneCompare != null)
                                {
                                    model.CcdmOrigin = oneCompare.lOriginID;
                                    model.Ccdm       = oneCompare.lNewID;
                                }

                                oneCompare = GetCompareList(KLDM_list, GetOneStrValue(dt.Rows[i], "KLDM", CosDataBase.LONGINT_TYPE));
                                if (oneCompare != null)
                                {
                                    model.KldmOrigin = oneCompare.lOriginID;
                                    model.Kldm       = oneCompare.lNewID;
                                }

                                string sXzdm = GetXzdm(dt.Rows[i]);
                                oneCompare = GetCompareList(XZDM_list, sXzdm);
                                if (oneCompare != null)
                                {
                                    model.XzdmOrigin = oneCompare.lOriginID;
                                    model.Xzdm       = oneCompare.lNewID;
                                }

                                oneCompare = GetCompareList(ZYLBDM_list, GetOneStrValue(dt.Rows[i], "ZYLBDM", CosDataBase.LONGINT_TYPE));
                                if (oneCompare != null)
                                {
                                    model.ZylbdmOrigin = oneCompare.lOriginID;
                                    model.Zylbdm       = oneCompare.lNewID;
                                }

                                model.Zkfx               = GetOneStrValue(dt.Rows[i], "ZKFX");
                                model.Tjsxbz             = GetOneStrValue(dt.Rows[i], "TJSXBZ");
                                model.Sfks               = Convert.ToBoolean(GetOneStrValue(dt.Rows[i], "SFKZ", CosDataBase.BOOLEAN_TYPE));
                                model.Sfbz               = Convert.ToInt32(GetOneStrValue(dt.Rows[i], "Sfbz", CosDataBase.INT_TYPE));
                                model.Bxdd               = GetOneStrValue(dt.Rows[i], "BXDD");
                                model.Wyyz               = GetOneStrValue(dt.Rows[i], "WYYZ");
                                model.ParentDepartmentID = lParentDepartmentID;
                                model.GxID               = GxID;
                                model.JoinNames          = model.Name;
                                string[] EditColumns = { "Name",       "Code", "Remark",       "CcdmOrigin", "Ccdm", "KldmOrigin", "Kldm",
                                                         "XzdmOrigin", "Xzdm", "ZylbdmOrigin", "Zylbdm",     "Zkfx", "Tjsxbz",     "Sfks","Sfbz","Bxdd", "Wyyz", "ParentDepartmentID", "GxID", "JoinNames" };
                                lNewID = SaveOneSimpleRecord(model, "zydhTable", EditColumns);
                                statusManage.EndUpdate <Td_zydh>();
                                ListCompareTable oneTable = new ListCompareTable();
                                oneTable.sOldID    = dt.Rows[i]["ZYDH"].ToString();
                                oneTable.lNewID    = lNewID;
                                oneTable.lOriginID = OriginModels[i].ID;
                                listReturn.Add(oneTable);
                            }
                            else //目前主表中存在
                            {
                                if (obj.DelFlag)
                                {
                                    lNewID = obj.JoinID;
                                }
                                else
                                {
                                    lNewID = obj.ID;
                                }

                                ListCompareTable oneTable = new ListCompareTable();
                                oneTable.sOldID    = dt.Rows[i]["ZYDH"].ToString();
                                oneTable.lNewID    = lNewID;
                                oneTable.lOriginID = OriginModels[i].ID;
                                listReturn.Add(oneTable);
                            }
                        }
                        else //目前主表中存在
                        {
                            if (obj.DelFlag)
                            {
                                lNewID = obj.JoinID;
                            }
                            else
                            {
                                lNewID = obj.ID;
                            }

                            ListCompareTable oneTable = new ListCompareTable();
                            oneTable.sOldID    = dt.Rows[i]["ZYDH"].ToString();
                            oneTable.lNewID    = lNewID;
                            oneTable.lOriginID = OriginModels[i].ID;
                            listReturn.Add(oneTable);
                        }
                        ////不管存在与否,都需修改原始表中相应的RelationID
                        string[] EditColumn = { "RelationID" };
                        OriginModels[i].RelationID = lNewID;
                        SaveOneRecord(OriginModels[i], EditColumn);
                    }
                }
            }
            return(listReturn);
        }