Esempio n. 1
0
        private bool StartRemove(string saveLoc, System.ComponentModel.BackgroundWorker _bgWorker)
        {
            string destFilename = Globals.Projectname;

            destFolder = saveLoc;

            string dest_temp = Path.GetDirectoryName(saveLoc);

            tempFullName = dest_temp + "\\" + Guid.NewGuid().ToString();
            if (System.IO.Directory.Exists(tempFullName))
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
            }
            MyCommon.DeleteAndCreateEmptyDirectory(tempFullName);

            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, false);
            MyCommon.DeleteAndCreateEmptyDirectory(destFolder, true);

            if (Index_temp > 100)
            {
                Index_temp = 0;
            }
            _bgWorker.ReportProgress(Index_temp++);


            ERM.CBLL.CreateSip projectFactory = new ERM.CBLL.CreateSip(Globals.ProjectNO);
            // DataSet dsFinalArchive = projectFactory.GetListArchive(Globals.ProjectNO, "");
            DataSet dsFinalArchive = new Archive().pb_setXmlInfo();

            if (dsFinalArchive.Tables.Count < 1 || dsFinalArchive.Tables[0].Rows.Count < 1)
            {
                TXMessageBoxExtensions.Info("没有任何案卷可以移交!");
                return(false);
            }
            int count_FinalArchive = dsFinalArchive.Tables[0].Rows.Count;

            //DataSet dsFinalArchive_temp = projectFactory.GetListArchive(Globals.ProjectNO, "");
            DataSet dsFinalArchive_temp = dsFinalArchive;

            dsFinalArchive_temp.DataSetName         = "案卷信息";
            dsFinalArchive_temp.Tables[0].TableName = "记录";

            string       _filename = tempFullName + "\\index.dat";
            StreamWriter w1        = new StreamWriter(_filename, false, Encoding.Default);

            if (dsFinalArchive_temp != null && dsFinalArchive_temp.Tables.Count > 0 && dsFinalArchive_temp.Tables[0].Rows.Count > 0)
            {
                for (int i1 = 0; i1 < dsFinalArchive_temp.Tables[0].Rows.Count; i1++)
                {
                    w1.WriteLine("<FileList><File>" + dsFinalArchive_temp.Tables[0].Rows[i1][0].ToString() + ".sip</File>");
                    w1.WriteLine("<Title>" + dsFinalArchive_temp.Tables[0].Rows[i1]["案卷题名"].ToString() + "</Title></FileList>");
                }
            }
            w1.Flush();
            w1.Close();

            if (Index_temp > 100)
            {
                Index_temp = 0;
            }
            _bgWorker.ReportProgress(Index_temp++);

            try
            {
                for (int i = 0; i < count_FinalArchive; i++)
                {
                    if (Index_temp > 100)
                    {
                        Index_temp = 0;
                    }
                    _bgWorker.ReportProgress(Index_temp++);

                    if (!Directory.Exists(tempFullName))
                    {
                        MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, true);
                    }

                    StreamWriter gc = new StreamWriter(tempFullName + "\\a#sgwj_gc.xml", false, Encoding.Default);
                    gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                    gc.WriteLine("<项目工程信息>");
                    gc.WriteLine("  <项目信息>");
                    DataSet   ds    = new Item().pb_setXmlInfo(new T_Projects_BLL().Find(Globals.ProjectNO).ItemID);
                    Hashtable _Item = new Hashtable();
                    if (ds.Tables.Count > 0)
                    {
                        for (int n = 0; n < ds.Tables[0].Rows.Count; n++)
                        {
                            for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                            {
                                _Item.Add(ds.Tables[0].Columns[j].ColumnName, ds.Tables[0].Rows[n][j].ToString());
                            }
                        }

                        foreach (System.Collections.DictionaryEntry objDE in _Item)
                        {
                            if (_Item[objDE.Key] != null)
                            {
                                if (_Item[objDE.Key].GetType() != typeof(System.String[]))
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                                }
                                else
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_Item[objDE.Key])[0] + "</" + objDE.Key + ">");
                                }
                            }
                            else
                            {
                                gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                            }
                        }
                    }
                    gc.WriteLine("  </项目信息>");
                    gc.WriteLine("  <工程信息>");
                    Hashtable _detail = new Hashtable();
                    DataSet   ds1     = new ERM.UI.Common.XmlMapping.Project().pb_setXmlInfo(new T_Projects_BLL().Find(Globals.ProjectNO).ProjectCategory);
                    if (ds1.Tables.Count > 0)
                    {
                        for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
                        {
                            for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
                            {
                                _detail.Add(ds1.Tables[0].Columns[j].ColumnName, ds1.Tables[0].Rows[n][j].ToString());
                            }
                        }

                        foreach (System.Collections.DictionaryEntry objDE in _detail)
                        {
                            if (_detail[objDE.Key] != null)
                            {
                                if (_detail[objDE.Key].GetType() != typeof(System.String[]))
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                                }
                                else
                                {
                                    gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_detail[objDE.Key])[0] + "</" + objDE.Key + ">");
                                }
                            }
                            else
                            {
                                gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                            }
                        }
                        gc.WriteLine("  </工程信息>");
                        gc.WriteLine("</项目工程信息>");
                        gc.Flush();
                        gc.Close();
                    }

                    if (Convert.ToBoolean(Properties.Settings.Default.SipIncludeDoc))
                    {
                        #region ==================================
                        //20120530 屏蔽XML文件

                        //DataSet dsFinalArchive_temp1 = projectFactory.GetListArchive(Globals.ProjectNO, dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        DataSet dsFinalArchive_temp1 = new Archive().pb_setXmlInfo(Globals.ProjectNO, dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        dsFinalArchive_temp1.DataSetName         = "案卷信息";
                        dsFinalArchive_temp1.Tables[0].TableName = "记录";

                        _filename = tempFullName + "\\a#sgwj_file.xml";
                        if (System.IO.File.Exists(_filename))
                        {
                            try
                            {
                                System.IO.File.Delete(_filename);
                            }
                            catch { }
                        }

                        gc = new StreamWriter(_filename, true, Encoding.Default);
                        gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                        gc.Flush();
                        gc.Close();
                        System.IO.FileStream     stream_archive    = new System.IO.FileStream(_filename, System.IO.FileMode.Append);
                        System.Xml.XmlTextWriter xmlWriter_archive = new System.Xml.XmlTextWriter(stream_archive, System.Text.Encoding.Default);
                        dsFinalArchive_temp1.WriteXml(xmlWriter_archive);
                        xmlWriter_archive.Close();

                        #endregion

                        #region ===========================

                        //DataSet dsFinalFile = projectFactory.GetListFile(Globals.ProjectNO,
                        //  dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString());
                        DataSet dsFinalFile = new ERM.UI.Common.XmlMapping.File().pb_setXmlInfo("pb_queryByFileNo", dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);

                        dsFinalFile.DataSetName         = "文件信息";
                        dsFinalFile.Tables[0].TableName = "记录";

                        _filename = tempFullName + "\\a#sgwj_document.xml";
                        if (System.IO.File.Exists(_filename))
                        {
                            try
                            {
                                System.IO.File.Delete(_filename);
                            }
                            catch { }
                        }

                        gc = new StreamWriter(_filename, true, Encoding.Default);
                        gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
                        gc.Flush();
                        gc.Close();
                        System.IO.FileStream     stream_file    = new System.IO.FileStream(_filename, System.IO.FileMode.Append);
                        System.Xml.XmlTextWriter xmlWriter_file = new System.Xml.XmlTextWriter(stream_file, System.Text.Encoding.Default);
                        dsFinalFile.WriteXml(xmlWriter_file);
                        xmlWriter_file.Close();

                        #endregion

                        BLL.T_FileList_BLL fileBLL = new ERM.BLL.T_FileList_BLL();
                        //IList<MDL.T_FileList> fileList = fileBLL.FindByArchiveID2(dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                        DataSet fileList = new ERM.UI.Common.XmlMapping.File().pb_setXmlInfo("pb_FindByArchiveID2", dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString(), Globals.ProjectNO);
                        if (fileList.Tables.Count > 0)
                        {
                            for (int j = 0; j < fileList.Tables[0].Rows.Count; j++)
                            {
                                DataRow obj = fileList.Tables[0].Rows[j];
                                if (Index_temp > 100)
                                {
                                    Index_temp = 0;
                                }
                                _bgWorker.ReportProgress(Index_temp++);

                                string FileID = obj["FileID"].ToString();
                                if (obj["filepath"] != null)
                                {
                                    string tFilePath = obj["filepath"].ToString().Replace("MPDF\\", "");
                                    string decMfile  = tempFullName + "\\" + tFilePath;
                                    string sourMfile = Globals.ProjectPath + obj["filepath"];
                                    try
                                    {
                                        if (System.IO.File.Exists(sourMfile))
                                        {
                                            System.IO.File.Copy(sourMfile, decMfile, true);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MyCommon.WriteLog("生成移交文件时,拷贝文件失败!错误信息:" + ex.Message);
                                    }
                                }
                                BLL.T_CellAndEFile_BLL     cellBLL  = new ERM.BLL.T_CellAndEFile_BLL();
                                IList <MDL.T_CellAndEFile> cellList = cellBLL.FindByFileID(FileID, Globals.ProjectNO, 1);

                                foreach (MDL.T_CellAndEFile obj2 in cellList)
                                {
                                    string yswjpath = obj2.filepath.Replace("ODOC\\", "");

                                    string dec  = tempFullName + "\\" + yswjpath;
                                    string sour = Globals.ProjectPath + obj2.filepath;
                                    try
                                    {
                                        if (System.IO.File.Exists(sour))
                                        {
                                            System.IO.File.Copy(sour, dec, true);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        MyCommon.WriteLog("生成移交文件时,拷贝原文件失败!错误信息:" + ex.Message);
                                    }
                                }
                            }
                        }
                    }
                    if (System.IO.File.Exists(tempFullName + "\\index.dat"))
                    {
                        System.IO.File.Move(tempFullName + "\\index.dat", destFolder + "\\index.dat");

                        string gcInfo  = System.IO.File.ReadAllText(tempFullName + "\\a#sgwj_gc.xml", Encoding.GetEncoding("gb2312"));
                        string docList = System.IO.File.ReadAllText(destFolder + "\\index.dat");
                        gcInfo = gcInfo.Replace("</项目工程信息>", "<ArchiveFileList>" + docList + "</ArchiveFileList></项目工程信息>");
                        System.IO.File.WriteAllText(destFolder + "\\index.dat", gcInfo, Encoding.GetEncoding("gb2312"));
                    }
                    SevenZip.SevenZipCompressor.SetLibraryPath(Application.StartupPath + "\\7z.dll");
                    SevenZip.SevenZipCompressor tmp = new SevenZip.SevenZipCompressor();
                    tmp.ArchiveFormat = SevenZip.OutArchiveFormat.Zip;
                    tmp.CompressDirectory(tempFullName, destFolder + "\\" + dsFinalArchive.Tables[0].Rows[i]["案卷ID"].ToString() + ".sip");

                    MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                }
            }
            catch (Exception ex)
            {
                MyCommon.DeleteAndCreateEmptyDirectory(tempFullName, false);
                TXMessageBoxExtensions.Info("封装数据时发生意外错误!错误002");
                MyCommon.WriteLog("生成移交文件时失败!错误信息:" + ex.Message);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// 系统不需要字库的
        /// </summary>
        /// <param name="projectFactory"></param>
        private static void GetProjectXML(ERM.CBLL.CreateSip projectFactory, string filepath_flg)
        {
            StreamWriter gc = new StreamWriter(filepath_flg + "\\a#sgwj_gc.xml", false, Encoding.Default);

            gc.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>");
            gc.WriteLine("<项目工程信息>");
            gc.WriteLine("  <项目信息>");
            DataSet   ds    = new Item().pb_setXmlInfo(new T_Projects_BLL().Find(Globals.ProjectNO).ItemID);
            Hashtable _Item = new Hashtable();

            if (ds.Tables.Count == 0 || ds.Tables == null)
            {
                return;
            }

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
                {
                    _Item.Add(ds.Tables[0].Columns[j].ColumnName, ds.Tables[0].Rows[i][j].ToString());
                }
            }

            foreach (System.Collections.DictionaryEntry objDE in _Item)
            {
                if (_Item[objDE.Key] != null)
                {
                    if (_Item[objDE.Key].GetType() != typeof(System.String[]))
                    {
                        gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                    }
                    else
                    {
                        gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_Item[objDE.Key])[0] + "</" + objDE.Key + ">");
                    }
                }
                else
                {
                    gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                }
            }
            gc.WriteLine("  </项目信息>");
            gc.WriteLine("  <工程信息>");

            Hashtable _detail     = new Hashtable();
            string    projectType = new T_Projects_BLL().Find(Globals.ProjectNO).ProjectCategory;
            DataSet   ds1         = new ERM.UI.Common.XmlMapping.Project().pb_setXmlInfo(projectType);

            if (ds1.Tables.Count > 0)
            {
                for (int n = 0; n < ds1.Tables[0].Rows.Count; n++)
                {
                    for (int j = 0; j < ds1.Tables[0].Columns.Count; j++)
                    {
                        _detail.Add(ds1.Tables[0].Columns[j].ColumnName, ds1.Tables[0].Rows[n][j].ToString());
                    }
                }
                projectFactory.UnitSetting(_detail);
                foreach (System.Collections.DictionaryEntry objDE in _detail)
                {
                    if (_detail[objDE.Key] != null)
                    {
                        if (_detail[objDE.Key].GetType() != typeof(System.String[]))
                        {
                            gc.WriteLine("    <" + objDE.Key + ">" + objDE.Value + "</" + objDE.Key + ">");
                        }
                        else
                        {
                            gc.WriteLine("    <" + objDE.Key + ">" + ((string[])_detail[objDE.Key])[0] + "</" + objDE.Key + ">");
                        }
                    }
                    else
                    {
                        gc.WriteLine("    <" + objDE.Key + "></" + objDE.Key + ">");
                    }
                }

                if (projectType == "Traffic")
                {
                    DataSet _trafficDetail = new Traffic().PB_setXmlInfo(ds1.Tables[0].Rows[0]["ID"].ToString());
                    if (_trafficDetail.Tables.Count > 0)
                    {
                        gc.WriteLine("<交通管道详细>");
                        for (int n = 0; n < _trafficDetail.Tables[0].Rows.Count; n++)
                        {
                            gc.WriteLine("<" + ReplaceColumnName(_trafficDetail.Tables[0].Rows[n]["Types"].ToString()) + ">");
                            for (int j = 0; j < _trafficDetail.Tables[0].Columns.Count; j++)
                            {
                                if (_trafficDetail.Tables[0].Columns[j].ColumnName != "Types")
                                {
                                    gc.WriteLine("    <" + _trafficDetail.Tables[0].Columns[j].ColumnName + ">" + _trafficDetail.Tables[0].Rows[n][j].ToString() + "</" + _trafficDetail.Tables[0].Columns[j].ColumnName + ">");
                                }
                            }
                            gc.WriteLine("</" + ReplaceColumnName(_trafficDetail.Tables[0].Rows[n]["types"].ToString()) + ">");
                        }
                        gc.WriteLine("</交通管道详细>");
                    }
                }

                gc.WriteLine("  </工程信息>");
                gc.WriteLine("</项目工程信息>");
                gc.Flush();
                gc.Close();
            }
        }