示例#1
0
 /// <summary>
 /// 磁盘清理方案
 /// </summary>
 /// <param name="flag">1,表示需要用户清理磁盘空间;2,表示程序直接清理磁盘空间</param>
 private void c_FreeSpace(int flag)
 {
     if (flag == 2)
     {
         string[] strFileName = accImp.FindAllMDBOfFile(strAccessPath);
         if (strFileName != null)
         {
             if (strFileName.Length > 0)
             {
                 try
                 {
                     accImp.CancelFileReadOnly(strFileName[0]);
                     File.Delete(strFileName[0]);
                     if (ErrorMessage != null)
                     {
                         ErrorMessage(4020001, "", "", "");
                         //ShowMessage("注意:系统已经帮您清理出一些磁盘空间,为保证程序的正确运行请您尽快大量清理磁盘!", true);
                     }
                 }
                 catch (Exception ex)
                 {
                     if (ErrorMessage != null)
                     {
                         ErrorMessage(6020013, ex.StackTrace, ex.Source, ex.Message);
                     }
                 }
             }
         }
     }
     else if (flag == 1)
     {
         if (ErrorMessage != null)
         {
             ErrorMessage(4020002, "", "", "");
             //ShowMessage("注意:磁盘空间不足200M,请尽快清理磁盘!当磁盘容量小于100M时,我们将强制清理磁盘!", true);
         }
     }
 }
示例#2
0
        /*
         * 外部调用
         */

        #region [ 方法: 按条件查询 ]

        /// <summary>
        /// 查询Access数据库
        /// </summary>
        /// <param name="strCommand">命令</param>
        /// <param name="name0">连接字符串</param>
        /// <returns>数据集</returns>
        public DataTable DataSelete(string strCommand, string name0)
        {
            DataTable        dtSelect = new DataTable();
            OleDbConnection  connAcc  = null;
            OleDbDataAdapter myDA     = null;

            try
            {
                connAcc            = DAO.GetConn(name0);
                myDA               = new OleDbDataAdapter();
                myDA.SelectCommand = new OleDbCommand(strCommand, connAcc);
                myDA.Fill(dtSelect);
            }
            catch (Exception ex)
            {
                if (ex.Message.IndexOf("找不到输出表") != -1)
                {
                    if (ex.Message.IndexOf("NewData") != -1)
                    {
                        //插入New表
                        accImp.CreateNewTable(name0, ex.Message.Substring(ex.Message.IndexOf("'") + 1, 9));
                    }
                    else if (ex.Message.IndexOf("OrgData") != -1)
                    {
                        //插入Org表
                        accImp.CreateOrgTable(name0, ex.Message.Substring(ex.Message.IndexOf("'") + 1, 9));
                    }
                    else if (ex.Message.IndexOf("ConfigData") != -1)
                    {
                        //插入Config表
                        accImp.CreateConfigTable(name0, ex.Message.Substring(ex.Message.IndexOf("'") + 1, 12));
                    }
                }
                else if (ex.Message.IndexOf("操作必须使用一个可更新的查询") != -1)
                {
                    try
                    {
                        accImp.CancelFileReadOnly(connAcc.DataSource);
                    }
                    catch { }
                }
                else if (ex.Message.IndexOf("找不到文件") != -1)
                {
                    try
                    {
                        accImp.CopyMDB(connAcc.DataSource);
                    }
                    catch { }
                }
                else if (ex.Message.IndexOf("当前被锁定") != -1)
                {
                    if (ErrorMessage != null)
                    {
                        ErrorMessage(6020006, ex.StackTrace, "[InsertAccess:InsertData]", ex.Message + Thread.CurrentThread.Name);
                    }
                    Thread.Sleep(100);
                }
                else if (ex.Message.IndexOf("由于您和其他用户试图同时改变同一数据") != -1)
                {
                    if (connAcc.State != ConnectionState.Closed)
                    {
                        connAcc.Close();
                        connAcc.Dispose();
                        connAcc = null;
                    }
                    try
                    {
                        string strfilenameTemp = name0.Replace(".mdb", ".ldb");
                        if (File.Exists(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + strfilenameTemp))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + strfilenameTemp);
                        }
                        File.Delete(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + name0);
                    }
                    catch { }
                    Thread.Sleep(100);
                }
                else if (ex.Message.IndexOf("不可识别的数据库格式") != -1)
                {
                    //if (ErrorMessage != null)
                    //{
                    //    ErrorMessage(6020006, ex.StackTrace, "[InsertAccess:InsertData]", ex.Message + Thread.CurrentThread.Name);
                    //}
                    if (connAcc.State != ConnectionState.Closed)
                    {
                        connAcc.Close();
                        connAcc.Dispose();
                        connAcc = null;
                    }
                    try
                    {
                        string strfilenameTemp = name0.Replace(".mdb", ".ldb");
                        if (File.Exists(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + strfilenameTemp))
                        {
                            File.Delete(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + strfilenameTemp);
                        }
                        File.Delete(System.Windows.Forms.Application.StartupPath.ToString() + @"\AccessDB\" + name0);
                    }
                    catch { }
                    //catch (Exception ee)
                    //{
                    //    string s = ee.Message;
                    //}
                    Thread.Sleep(100);
                }

                if (ErrorMessage != null)
                {
                    ErrorMessage(6020011, ex.StackTrace, "[SelectAccess:DataSelete]", ex.Message);
                }
            }
            finally
            {
                if (myDA != null)
                {
                    myDA.Dispose();
                    myDA = null;
                }
                if (connAcc != null)
                {
                    connAcc.Dispose();
                    connAcc = null;
                }
            }

            return(dtSelect);
        }