Exemple #1
0
        private bool PMMoidZipInput(string path, string dbName)
        {
            //初始化XML文件夹
            string      xmlPath = @"..\..\PMXMLFile";//路径xml文件夹
            MrInputData mrclass = new MrInputData();

            mrclass.ClearXMLFile(xmlPath);

            //解压
            bool a = false;//解压是否成功

            string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
            if (files.Length == 0)
            {
                return(false);
            }
            foreach (string file in files)
            {
                if (Path.GetExtension(file) == ".zip")
                {
                    a = mrclass.Decompress(file, xmlPath);
                    if (!a)
                    {
                        return(false);
                    }
                }
            }
            //
            List <PMAllMoid> pMALLData = new List <PMAllMoid>();

            string[] xmlFiles = Directory.GetFiles(xmlPath, "*.*", SearchOption.AllDirectories);
            if (xmlFiles.Length == 0)
            {
                return(false);
            }

            //读取XML
            foreach (string file in xmlFiles)
            {
                if (Path.GetExtension(file) == ".xml")
                {
                    GetPMMo(file, pMALLData);
                }
            }
            int xmlNumber = pMALLData.Count();

            using (var db = new LROSRDbContext(dbName))
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;

                int KPid = 0;//设置主键ID
                ///!!!
                int columnNumber = db.PMAllMoid.Count();
                if (columnNumber != 0)
                {
                    KPid = db.PMAllMoid.Select(q => q.KPid).Max() + 1;
                }

                foreach (PMAllMoid item in pMALLData)
                {
                    item.KPid = KPid;
                    KPid++;
                }
                db.PMAllMoid.AddRange(pMALLData);
                try
                {
                    int dbNUmber = db.SaveChanges();
                    if (dbNUmber != xmlNumber)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(true);
        }
Exemple #2
0
        public bool PMTableListZipInput(string path, string deName)
        {
            int xmlNumber = 0;
            int dbNUmber  = 0;

            string      xmlPath = @"..\..\XMLFile";//路径xml文件夹
            MrInputData mrclass = new MrInputData();

            mrclass.ClearXMLFile(xmlPath);

            //解压
            bool a = false;//解压是否成功

            string[] files = Directory.GetFiles(path, "*.*", SearchOption.AllDirectories);
            if (files.Length == 0)
            {
                return(false);
            }
            foreach (string file in files)
            {
                if (Path.GetExtension(file) == ".zip")
                {
                    a = mrclass.Decompress(file, xmlPath);
                    if (!a)
                    {
                        return(false);
                    }
                }
            }

            string[] filenames = Directory.GetFiles(xmlPath);
            List <PMTableListColumn> PMTableList = new List <PMTableListColumn>();

            if (filenames.Length == 0)
            {
                return(false);
            }
            //解析XML
            foreach (string file in filenames)
            {
                if (Path.GetExtension(file) == ".xml")
                {
                    PMTableList.Add(GetPMTable(file));
                }
            }
            xmlNumber = PMTableList.Count;

            //数据入库
            using (var db = new LROSRDbContext(deName))
            {
                db.Configuration.AutoDetectChangesEnabled = false;
                db.Configuration.ValidateOnSaveEnabled    = false;
                //db.anto

                int KPid         = 0;//设置主键ID
                int columnNumber = db.PMTableListColumn.Count();
                if (columnNumber != 0)
                {
                    KPid = db.PMTableListColumn.Select(q => q.KPid).Max() + 1;
                }

                foreach (PMTableListColumn item in PMTableList)
                {
                    item.KPid = KPid;
                    KPid++;
                }
                db.PMTableListColumn.AddRange(PMTableList);
                //db.PMTableListColumn.AddRange()
                try
                {
                    dbNUmber = db.SaveChanges();
                    if (dbNUmber != xmlNumber)
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(true);
        }