using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Data.SqlClient; using Mesnac.Codd.Session; using System.Data.SQLite; namespace Mesnac.Equip.FictitiousPlc { public class DbHelperFactory { #region 单例模式 private static DbHelperFactory _this; public static DbHelperFactory Instance { get { if (null == _this) _this = new DbHelperFactory(); return _this; } } private DbHelperFactory() { } #endregion private void CreatNullFile(string fileName) { FileInfo fi = new FileInfo(fileName); if (fi.Exists) { return; } FileStream fs = File.Create(fileName); fs.Close(); } public DbHelper NewDbHelper(string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; path = new System.IO.FileInfo(path).Directory.FullName; fileName = System.IO.Path.Combine(path, "Plc.db"); } CreatNullFile(fileName); string constr = "Data Source=" + fileName; DbSession dbsession = new DbSession(SQLiteFactory.Instance, constr); return new DbHelper(dbsession); } public DbHelper NewDbHelper() { return NewDbHelper(string.Empty); } } }