示例#1
0
 private void dofinish()
 {
     BaseForm.AsyncDelegate del = delegate
     {
         DirectoryInfo directoryInfo = new DirectoryInfo(EntityElement.TempPath);
         this.setprogress(99, "删除导入过程中的所有临时文件...");
         FileInfo[] files = directoryInfo.GetFiles();
         FileInfo[] array = files;
         for (int i = 0; i < array.Length; i++)
         {
             FileInfo fileInfo = array[i];
             try
             {
                 fileInfo.Delete();
             }
             catch (Exception)
             {
             }
         }
         BaseForm.MethodInvoker uiDelegate = delegate
         {
             base.Close();
         };
         base.UpdateUI(uiDelegate, this);
     };
     base.BeginInvoke(del);
 }
 protected void UpdateUI(BaseForm.MethodInvoker uiDelegate, Form form)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(uiDelegate);
         return;
     }
     uiDelegate();
 }
示例#3
0
 private void setprogress(int cval, string msg)
 {
     BaseForm.MethodInvoker uiDelegate = delegate
     {
         this.pbar.Value = cval;
         this.lbmsg.Text = msg;
     };
     base.UpdateUI(uiDelegate, this);
 }
示例#4
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            this.lbinfo.Text = "请稍后...";
            frmExtFileEditor.IsUploadedExtFile = false;
            this.btnCancel.Enabled             = false;
            this.btnConfirm.Enabled            = false;
            string text = "";

            FileOp.RunWordInstCheck(out text);
            BaseForm.AsyncDelegate del = delegate
            {
                DirectoryInfo directoryInfo = new DirectoryInfo(EntityElement.FilesStorePath);
                FileInfo[]    files         = directoryInfo.GetFiles();
                FileInfo[]    array         = files;
                for (int i = 0; i < array.Length; i++)
                {
                    FileInfo fileInfo = array[i];
                    try
                    {
                        fileInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        BaseForm.MethodInvoker uiDelegate = delegate
                        {
                            MessageBox.Show("待删除文件正在被其他程序使用,请关闭其他程序后,再重新新建。\r\n详细错误:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            this.Close();
                        };
                        base.UpdateUI(uiDelegate, this);
                        return;
                    }
                }
                DBMgrService dBMgrService = new DBMgrService();
                dBMgrService.InitDB();
                BaseForm.MethodInvoker uiDelegate2 = delegate
                {
                    this.OnClearOKEvent(EventArgs.Empty);
                    if (this._baseControls != null)
                    {
                        foreach (BaseControl current in this._baseControls)
                        {
                            current.RefreshCall();
                        }
                    }
                    base.Close();
                };
                base.UpdateUI(uiDelegate2, this);
            };
            base.BeginInvoke(del);
        }
示例#5
0
        private void btnconfirm_Click(object sender, EventArgs e)
        {
            this.btncancel.Visible  = false;
            this.btnconfirm.Visible = false;
            this.lbcontinue.Visible = false;
            this.pbar.Visible       = true;
            string text = "";

            FileOp.RunWordInstCheck(out text);
            BaseForm.AsyncDelegate del = delegate
            {
                if (File.Exists(this._zipfilepath))
                {
                    if (!isOKPackage(this._zipfilepath))
                    {
                        MessageBox.Show("对不起,申报数据包格式错误!", "提示");
                        if (IsHandleCreated)
                        {
                            Invoke(new MethodInvoker(delegate()
                            {
                                Close();
                            }));
                        }
                        return;
                    }

                    this.setprogress(1, "解压缩文件...");
                    DirectoryInfo directoryInfo = new DirectoryInfo(EntityElement.TempPath);
                    FileInfo[]    files         = directoryInfo.GetFiles();
                    FileInfo[]    array         = files;
                    for (int i = 0; i < array.Length; i++)
                    {
                        FileInfo fileInfo = array[i];
                        try
                        {
                            fileInfo.Delete();
                        }
                        catch (Exception)
                        {
                        }
                    }
                    bool           flag           = false;
                    ZipInputStream zipInputStream = null;
                    try
                    {
                        ZipInputStream zipInputStream2;
                        zipInputStream = (zipInputStream2 = new ZipInputStream(File.OpenRead(this._zipfilepath)));
                        try
                        {
                            int      num = 2;
                            ZipEntry nextEntry;
                            while ((nextEntry = zipInputStream.GetNextEntry()) != null)
                            {
                                this.setprogress(num++, "解压缩文件...");
                                if (nextEntry.IsFile)
                                {
                                    string fileName = Path.GetFileName(nextEntry.Name);
                                    if (fileName == EntityElement.DBName)
                                    {
                                        flag = true;
                                    }
                                    using (FileStream fileStream = File.Create(Path.Combine(EntityElement.TempPath, fileName)))
                                    {
                                        byte[] array2 = new byte[2048];
                                        while (true)
                                        {
                                            int num2 = zipInputStream.Read(array2, 0, array2.Length);
                                            if (num2 <= 0)
                                            {
                                                break;
                                            }
                                            fileStream.Write(array2, 0, num2);
                                        }
                                        fileStream.Close();
                                    }
                                }
                            }
                            zipInputStream.Close();
                        }
                        finally
                        {
                            if (zipInputStream2 != null)
                            {
                                ((IDisposable)zipInputStream2).Dispose();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (zipInputStream != null)
                        {
                            try
                            {
                                zipInputStream.Close();
                            }
                            catch (Exception)
                            {
                            }
                        }
                        BaseForm.MethodInvoker uiDelegate = delegate
                        {
                            MessageBox.Show("文件解压失败,请检查压缩包是否正确。\r\n详细错误:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            this.dofinish();
                        };
                        base.UpdateUI(uiDelegate, this);
                        return;
                    }
                    if (flag)
                    {
                        this.setprogress(40, "清理目标文件夹...");
                        directoryInfo = new DirectoryInfo(EntityElement.FilesStorePath);
                        files         = directoryInfo.GetFiles();
                        FileInfo[] array3 = files;
                        for (int j = 0; j < array3.Length; j++)
                        {
                            FileInfo fileInfo2 = array3[j];
                            try
                            {
                                fileInfo2.Delete();
                            }
                            catch (Exception ex)
                            {
                                BaseForm.MethodInvoker uiDelegate2 = delegate
                                {
                                    MessageBox.Show("文件删除失败,请关闭任何使用该文件的进程后重新导入。\r\n详细错误:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                                    this.dofinish();
                                };
                                base.UpdateUI(uiDelegate2, this);
                                return;
                            }
                        }
                        this.setprogress(60, "导入数据库...");
                        File.Copy(Path.Combine(EntityElement.TempPath, EntityElement.DBName), Path.Combine(EntityElement.DBStorePath, EntityElement.DBName), true);
                        File.Delete(Path.Combine(EntityElement.TempPath, EntityElement.DBName));
                        this.setprogress(70, "导入附件...");
                        directoryInfo = new DirectoryInfo(EntityElement.TempPath);
                        files         = directoryInfo.GetFiles();
                        FileInfo[] array4 = files;
                        for (int k = 0; k < array4.Length; k++)
                        {
                            FileInfo fileInfo3 = array4[k];
                            File.Move(fileInfo3.FullName, Path.Combine(EntityElement.FilesStorePath, Path.GetFileName(fileInfo3.FullName)));
                        }
                        this.setprogress(85, "读取新数据...");
                        BaseForm.MethodInvoker uiDelegate3 = delegate
                        {
                            this.OnImportOKEvent(EventArgs.Empty);
                            if (this._baseControls != null)
                            {
                                foreach (BaseControl current in this._baseControls)
                                {
                                    current.RefreshCall();
                                }
                                this.setprogress(95, "更新完成...");
                                this.dofinish();
                            }
                        };
                        base.UpdateUI(uiDelegate3, this);
                        return;
                    }
                    BaseForm.MethodInvoker uiDelegate4 = delegate
                    {
                        MessageBox.Show("导入数据中用户数据丢失,导入失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        this.dofinish();
                    };
                    base.UpdateUI(uiDelegate4, this);
                }
            };
            base.BeginInvoke(del);
        }