Ejemplo n.º 1
0
        void DoRestoreAccount()
        {
            string  name = RestoreAccount.Name;
            Account act  = RestoreAccount;

            if (act != null)
            {
                string fileName = _fileName;
                this.Cursor = Cursors.WaitCursor;
                Core.ToolTip tip = new UnvaryingSagacity.Core.ToolTip();
                tip.ShowPrompt(this, "正在还原文件:" + fileName + " 到 账套[" + act.Name + "]\n\n耗费时间由数据量决定, 请等待......");
                string fileBackup = System.Environment.GetEnvironmentVariable("TEMP") + @"\" + act.ID + DateTime.Now.ToString("yyyyMMddHHmmss");
                if (System.IO.File.Exists(fileBackup + ".tmp"))
                {
                    System.IO.File.Delete(fileBackup + ".tmp");
                }
                System.IO.File.Move(act.FullPath, fileBackup + ".tmp");
                try
                {
                    DataProvider dpDst = new DataProvider(fileBackup);
                    DataProvider dpSrc = new DataProvider(fileName);
                    ///清理数据库建好后的默认数据

                    foreach (DataTable dt in dpDst.dataSet.Tables)
                    {
                        DataTable dstDt = dpDst.dataSet.Tables[dt.TableName];
                        DataRow[] drs   = dpDst.GetDataRows(dt.TableName, "", "");
                        dstDt.Rows.Clear();
                        dstDt.AcceptChanges();
                    }
                    foreach (DataTable dt in dpSrc.dataSet.Tables)
                    {
                        DataTable dstDt = dpDst.dataSet.Tables[dt.TableName];
                        DataRow[] drs   = dpSrc.GetDataRows(dt.TableName, "", "");
                        bool      b     = false;
                        foreach (DataRow dr in drs)
                        {
                            DataRow  dstDr      = dstDt.NewRow();
                            object[] rItemArray = new object[dstDr.ItemArray.Length];

                            dr.ItemArray.CopyTo(rItemArray, 0);
                            dstDr.ItemArray = rItemArray;
                            dstDt.Rows.Add(dstDr);
                            if (!b)
                            {
                                b = true;
                            }
                        }
                        if (b)
                        {
                            dstDt.AcceptChanges();
                        }
                    }
                    DateTime last = DateTime.Today;
                    dpDst.LastBackupDateTime = last;
                    dpDst.SetConfig(DataProvider.CONFIG_备份账套名称, "");
                    dpDst.SetConfig(DataProvider.CONFIG_备份账套编号, "");
                    dpDst.SetConfig(DataProvider.CONFIG_备份创建人, "");
                    System.IO.File.Move(fileBackup, act.FullPath);
                    tip.Hide();
                    this.Cursor = Cursors.Default;
                    MessageBox.Show(this, "还原账套已经顺利完成.", "还原账套", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                catch (Exception ex)
                {
                    tip.Hide();
                    this.Cursor = Cursors.Default;
                    MessageBox.Show(this, ex.Message + "\n\n还原账套失败.", "还原账套", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (!System.IO.File.Exists(act.FullPath))
                    {
                        System.IO.File.Move(fileBackup + ".tmp", act.FullPath);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        void BackupAccount(string name)
        {
            if (_e.CurrentUser.GetRightState("0104") != UserAndRight.RightState.完全)
            {
                MessageBox.Show(this, UIMain.RIGHT_ERROR, "检查权限", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            Account act = _e.GetAccount(name);

            if (act != null)
            {
                SaveFileDialog sf = new SaveFileDialog();
                sf.AddExtension    = false;
                sf.CheckPathExists = true;
                sf.OverwritePrompt = true;
                sf.ValidateNames   = true;
                sf.FileName        = "日记账备份_" + act.ID + "_" + DateTime.Today.ToString("yyyyMMdd");
                if (sf.ShowDialog(this) == DialogResult.OK)
                {
                    string fileName = sf.FileName;
                    if (System.IO.File.Exists(fileName))
                    {
                        //if (MessageBox.Show(this, "文件:\n\n" + fileName + "\n\n已经存在,您确定要覆盖吗?", "账套备份", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                        //{
                        //    return;
                        //}
                        System.IO.File.Delete(fileName);
                    }
                    this.Cursor = Cursors.WaitCursor;
                    Core.ToolTip tip = new UnvaryingSagacity.Core.ToolTip();
                    tip.ShowPrompt(this, "正在备份账套[" + act.Name + "] 到 文件:" + fileName + "\n\n耗费时间由数据量决定, 请等待......");
                    try
                    {
                        DataProvider dpSrc = new DataProvider(act.FullPath);
                        DataProvider dpDst = new DataProvider(fileName);
                        ///清理数据库建好后的默认数据

                        foreach (DataTable dt in dpDst.dataSet.Tables)
                        {
                            DataTable dstDt = dpDst.dataSet.Tables[dt.TableName];
                            DataRow[] drs   = dpDst.GetDataRows(dt.TableName, "", "");
                            dstDt.Rows.Clear();
                            dstDt.AcceptChanges();
                        }
                        foreach (DataTable dt in dpSrc.dataSet.Tables)
                        {
                            DataTable dstDt = dpDst.dataSet.Tables[dt.TableName];
                            DataRow[] drs   = dpSrc.GetDataRows(dt.TableName, "", "");
                            bool      b     = false;
                            foreach (DataRow dr in drs)
                            {
                                DataRow  dstDr      = dstDt.NewRow();
                                object[] rItemArray = new object[dstDr.ItemArray.Length];
                                for (int i = 0; i < dstDt.Columns.Count; i++)
                                {
                                    rItemArray[i] = dr[dstDt.Columns[i].ColumnName];
                                }
                                dstDr.ItemArray = rItemArray;
                                dstDt.Rows.Add(dstDr);
                                if (!b)
                                {
                                    b = true;
                                }
                            }
                            if (b)
                            {
                                dstDt.AcceptChanges();
                            }
                        }
                        DateTime last = DateTime.Today;
                        dpSrc.LastBackupDateTime = last;
                        dpDst.LastBackupDateTime = last;
                        dpDst.SetConfig(DataProvider.CONFIG_备份账套名称, act.Name);
                        dpDst.SetConfig(DataProvider.CONFIG_备份账套编号, act.ID);
                        dpDst.SetConfig(DataProvider.CONFIG_备份创建人, _e.CurrentUser.Name);
                        tip.ShowPrompt(this, "正在检查备份文件:" + fileName + "\n\n, 请稍等......");
                        dpDst.Refresh(true);
                        dpDst.Closed();
                        System.IO.FileInfo fiSrc  = new System.IO.FileInfo(act.FullPath);
                        System.IO.FileInfo fiDst  = new System.IO.FileInfo(fileName);
                        string             prompt = "账套[" + act.Name + "]已经成功备份到文件:\n\n" + fileName;
                        if (fiDst.Length < fiSrc.Length)
                        {
                            prompt = "备份文件的大小不正确,请删除下面的文件后重新备份:\n\n" + fileName;
                        }
                        tip.Hide();
                        this.Cursor = Cursors.Default;
                        MessageBox.Show(this, prompt, "账套备份", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        tip.Hide();
                        this.Cursor = Cursors.Default;
                        MessageBox.Show(this, ex.Message, "账套备份", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                }
            }
        }