Ejemplo n.º 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        public static bool Init()
        {
            try
            {
                string dbPath = Environment.CurrentDirectory + "/" + "flow_history.db";

                //如果不存在数据库文件,则创建该数据库文件
                if (!System.IO.File.Exists(dbPath))
                {
                    SQLiteDBHelper.CreateDB(dbPath);
                }

                db = new SQLiteDBHelper(dbPath);

                string sql;
                sql = "CREATE TABLE IF NOT EXISTS flow(fid integer PRIMARY KEY autoincrement DEFAULT (1),pid integer, flow_up long, flow_down long, note_date date);";
                db.ExecuteNonQuery(sql, null);  // 创建 flow 表

                sql = "CREATE TABLE IF NOT EXISTS program(pid integer PRIMARY KEY autoincrement DEFAULT (1), name varchar(30), path text, describe text);";
                db.ExecuteNonQuery(sql, null);  // 创建 program 表
            }
            catch (Exception e)
            {
                //FM_Info.showError(e);
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public void InitDataBase()
        {
            // 创建数据库文件
            if (!File.Exists(_dataFile))
            {
                SQLiteDBHelper.CreateDB(_dataFile);

                // 设置连接字符串
                SQLiteDBHelper.SetConnectionString(Environment.CurrentDirectory + "\\" + _dataFile);

                // 创建表结构
                _repository.CreateSchema();

                UserRepository userRep    = new UserRepository();
                User           systemUser = new User();
                systemUser.Id       = this.NewGUID();
                systemUser.Name     = "系统管理员";
                systemUser.Account  = "admin";
                systemUser.Password = "******";

                userRep.Insert(systemUser);
            }
            else
            {
                // 设置连接字符串
                SQLiteDBHelper.SetConnectionString(Environment.CurrentDirectory + "\\" + _dataFile);
            }
        }
Ejemplo n.º 3
0
        private void button_NewDBFile_Click(object sender, EventArgs e)
        {
            SQLiteDBHelper _helper = new SQLiteDBHelper(Config.CfgInfo.StaticDB_PATH);
            string         path    = Config.CfgInfo.FoldBrowserPath + "\\" + textBox_new_wellname.Text.Trim() + "_" + textBox_new_wellid.Text.Trim() + "_" + textBox_new_welltime.Text.Trim() + ".db3";

            _helper.CreateDB(path, "2", "07", getXMLConfig());
            WitsTable wt = new WitsTable("APS", "07", getXMLConfig());
        }
Ejemplo n.º 4
0
 public void CreateTable()
 {
     //如果不存在改数据库文件,则创建该数据库文件
     if (!System.IO.File.Exists(_dbPath))
     {
         SQLiteDBHelper.CreateDB(_dbPath);
     }
     //SQLiteDBHelper db = new SQLiteDBHelper(dbPath);
     //string sql = "CREATE TABLE Product(Id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Url varchar(200),CreateTime datetime)";
     //db.ExecuteNonQuery(sql, null);
 }
Ejemplo n.º 5
0
        private void button3_Click(object sender, EventArgs e)
        {
            string dbPath = connectionString;

            //如果不存在改数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(connectionString);
            }
            string sqlcreatetab = "CREATE TABLE CriticalData" +
                                  "(id integer IDENTITY(1,1) NOT NULL," +
                                  "lcNum varchar(1,20) NOT NULL," +
                                  "generatorId int NOT NULL," +
                                  "oilPress real NOT NULL," +
                                  "waterTemp real NOT NULL," +
                                  "frequency real NOT NULL," +
                                  "motorSpeed real NOT NULL," +
                                  "voltage real NOT NULL," +
                                  "current real NOT NULL," +
                                  "motorPower real NOT NULL," +
                                  "powerFactor real ," +
                                  "oilMass real NOT NULL," +
                                  "alarmValue int NOT NULL," +
                                  "dateTime datetime NOT NULL)";


            string Inspe = "CREATE TABLE InspectionRecords(" +
                           "id int IDENTITY(1,1) NOT NULL," +
                           "lcNum nchar(20) NOT NULL," +
                           "status nchar(10) NOT NULL," +
                           "planTime datetime NOT NULL," +
                           "recordTime datetime NULL," +
                           "worker nchar(20) NOT NULL," +
                           "remarks nchar(30) NULL)";

            StringBuilder temperaturesql = new StringBuilder();

            temperaturesql.Append(" CREATE TABLE tab_temperature (lcnum nvarchar(10) NULL,");
            for (int i = 1; i <= 57; i++)
            {
                temperaturesql.Append("s" + i + " int NULL,t" + i + " real NULL,");
            }
            temperaturesql.Append("sendtime datetime NULL)");
            SQLiteDBHelper db      = new SQLiteDBHelper("");
            bool           result1 = db.ExecuteNonQuery(sqlcreatetab, null) > 0;
            bool           result2 = db.ExecuteNonQuery(Inspe, null) > 0;
            bool           result3 = db.ExecuteNonQuery(temperaturesql.ToString(), null) > 0;

            if (result1 && result2 && result3)
            {
                MessageBox.Show("ok");
            }
        }
Ejemplo n.º 6
0
        public static void CreateTable()
        {
            string EXEPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string dbPath  = EXEPath + "Demo.db3";

            //如果不存在改数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(dbPath);
            }
            InitConsumableRecord();
            //SQLiteDBHelper db = new SQLiteDBHelper(dbPath);
            //string sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name char(3),TypeName varchar(50),addDate datetime,UpdateTime Date,Time time,Comments blob)";
        }
Ejemplo n.º 7
0
        public static void CreateTable()
        {
            string dbPath = "D:\\Demo.db3";

            //如果不存在改数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB("D:\\Demo.db3");
            }
            SQLiteDBHelper db  = new SQLiteDBHelper("D:\\Demo.db3");
            string         sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name char(3),TypeName varchar(50),addDate datetime,UpdateTime Date,Time time,Comments blob)";

            db.ExecuteNonQuery(sql, null);
        }
Ejemplo n.º 8
0
        public GreateDataBase()
        {
            string DataBase = "Log//Log.db";

            SQLiteDBHelper.CreateLogDB(DataBase);

            string DataPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"Data";

            DataBase = "Data//Data.db";
            if (!System.IO.File.Exists(DataBase))
            {
                System.IO.Directory.CreateDirectory(DataPath);
                SQLiteDBHelper.CreateDB(DataBase);
                Lognet.Log.Warn("箱号数据库不存在,重新创建数据库");
            }
        }
Ejemplo n.º 9
0
 void GetDataBase()
 {
     path = GetCurrentPath();
     if (File.Exists(path))
     {
         db = new SQLiteDBHelper(path);
     }
     else
     {
         SQLiteDBHelper.CreateDB(path);
         db = new SQLiteDBHelper(path);
         string sql = "CREATE TABLE CodeMass(ID integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," +
                      "CodeName char(40)," +
                      "Language char(3)," +
                      "Comments varchar(100)," +
                      "AddTime datetime,UpdateTime Date," +
                      "Source_Code Text)";
         db.ExecuteNonQuery(sql, null);
     }
 }
Ejemplo n.º 10
0
        private void GetSip2Form_Load(object sender, EventArgs e)
        {
            //获取基目录,它由程序集冲突解决程序用来探测程序集。
            string         dbPath = AppDomain.CurrentDomain.BaseDirectory + "Sip2Info.db";
            SQLiteDBHelper db     = new SQLiteDBHelper(dbPath);

            //如果不存在数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(dbPath);
                // 创建表
                string sqlCreate = "CREATE TABLE Sip2Info(" +
                                   "id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE" +
                                   ",name varchar(500)" +
                                   ",ip varchar(500)" +
                                   ",port varchar(500)" +
                                   ",ao varchar(500)" +
                                   ",ap varchar(500)" +
                                   ",charset varchar(500)" +
                                   ",uid varchar(500)" +
                                   ",pwd varchar(500)" +
                                   ",VP varchar(500)" +
                                   ",locationcode varchar(500)" +
                                   ",readercode varchar(500)" +
                                   ",PIN varchar(500)" +
                                   ",bookcode varchar(500)" +
                                   ")";
                db.ExecuteNonQuery(sqlCreate, null);
            }
            // 查询数据
            string    sql = "select id, name as 名称, ip, port, ao, ap, charset as 字符集, uid, pwd, vp, locationcode, readercode, pin, bookcode from Sip2Info";
            DataTable dt  = db.ExecuteDataTable(sql, null);
            DataSet   ds  = new DataSet();

            ds.Tables.Add(dt);
            dgvSip2Server.DataSource = ds.Tables[0];
        }
Ejemplo n.º 11
0
        //创建curveName字典和数据库及其表
        private void createCurveNameDictionaryAndDB()
        {
            //创建数据库
            if (m_wellConfig_From.getwellcountPath() == "" || m_wellConfig_From.getwellcountPath() == null)
            {
                MessageBox.Show("未配置井路径,请配置!");
                return;
            }
            String wellcountPath = m_wellConfig_From.getwellcountPath();
            String wellcount     = m_wellConfig_From.getwellcount();
            String filename      = wellcount + ".db3";
            String dbPath        = m_wellConfig_From.creatDirectory(wellcountPath, filename);

            m_realDBHelper = m_wellConfig_From.getRealDBHelper();
            m_realDBHelper.CreateDB(dbPath);
            //m_realDBHelper.InsertWellInfo(dbPath);
            m_dBHelper = new SQLiteDBHelper(dbPath);
            m_dBHelper.CreateDB(dbPath);
            List <String> serverTableList = new List <string>();
            List <String> clientTableList = new List <string>();
            DataTable     curveNameTable  = new DataTable();
            List <String> curveNameList   = new List <string>();
            //获取Server和Client所选仪器及对应选择的表号
            Dictionary <String, List <String> > selectServerToolDictionary = m_recConfig_Form.getSelectServerToolDictionary();
            Dictionary <String, List <String> > selectClientToolDictionary = m_recConfig_Form.getSelectClientToolDictionary();

            //创建曲线字典和wits表
            if (selectServerToolDictionary != null)
            {
                foreach (String toolName in selectServerToolDictionary.Keys)
                {
                    if (selectServerToolDictionary.TryGetValue(toolName, out serverTableList))
                    {
                        //根据toolName创建Wits表字典,供查询index对应的curveName(短助记符)
                        Dictionary <String, DataTable> curveNameDictionary = m_CurveNameDictionary.createDictionary(toolName, serverTableList);
                        m_curveNameDictionary.Add(toolName, m_CurveNameDictionary.createDictionary(toolName, serverTableList));
                        serverTableList.Clear();
                        //同一个仪器名下的wits表
                        Dictionary <String, WitsTable> witsTableDic = new Dictionary <string, WitsTable>();
                        //创建数据库表和WITS表
                        foreach (String tableNo in curveNameDictionary.Keys)
                        {
                            if (curveNameDictionary.TryGetValue(tableNo, out curveNameTable))
                            {
                                for (int i = 0; i < curveNameTable.Rows.Count; i++)
                                {
                                    curveNameList.Add(curveNameTable.Rows[i][1].ToString());
                                }
                                m_dBHelper.CreateTabs(toolName, tableNo, curveNameList);
                                WitsTable witsTable = new WitsTable(toolName, tableNo, curveNameList);
                                witsTableDic.Add(tableNo, witsTable);
                                curveNameTable.Clear();
                                curveNameList.Clear();
                            }
                        }
                        m_witsTableDictionary.Add(toolName, witsTableDic);
                    }
                }
            }
            if (selectClientToolDictionary != null)
            {
                foreach (String toolName in selectClientToolDictionary.Keys)
                {
                    if (selectClientToolDictionary.TryGetValue(toolName, out clientTableList))
                    {
                        //根据toolName创建Wits表字典,供查询index对应的curveName(短助记符)
                        Dictionary <String, DataTable> curveNameDictionary = m_CurveNameDictionary.createDictionary(toolName, clientTableList);
                        m_curveNameDictionary.Add(toolName, m_CurveNameDictionary.createDictionary(toolName, clientTableList));
                        clientTableList.Clear();
                        //同一个仪器名下的wits表
                        Dictionary <String, WitsTable> witsTableDic = new Dictionary <string, WitsTable>();
                        //创建数据库表和WITS表
                        foreach (String tableNo in curveNameDictionary.Keys)
                        {
                            if (curveNameDictionary.TryGetValue(tableNo, out curveNameTable))
                            {
                                for (int i = 0; i < curveNameTable.Rows.Count; i++)
                                {
                                    curveNameList.Add(curveNameTable.Rows[i][1].ToString());
                                }
                                m_dBHelper.CreateTabs(toolName, tableNo, curveNameList);
                                WitsTable witsTable = new WitsTable(toolName, tableNo, curveNameList);
                                witsTableDic.Add(tableNo, witsTable);
                                curveNameTable.Clear();
                                curveNameList.Clear();
                            }
                        }
                        m_witsTableDictionary.Add(toolName, witsTableDic);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            //获取基目录,它由程序集冲突解决程序用来探测程序集。
            string         dbPath = AppDomain.CurrentDomain.BaseDirectory + "Sip2Info.db";
            SQLiteDBHelper db     = new SQLiteDBHelper(dbPath);

            //如果不存在数据库文件,则创建该数据库文件
            if (!System.IO.File.Exists(dbPath))
            {
                SQLiteDBHelper.CreateDB(dbPath);
                // 创建表
                string sql = "CREATE TABLE Sip2Info(" +
                             "id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE" +
                             ",name varchar(500)" +
                             ",ip varchar(500)" +
                             ",port varchar(500)" +
                             ",ao varchar(500)" +
                             ",ap varchar(500)" +
                             ",charset varchar(500)" +
                             ",uid varchar(500)" +
                             ",pwd varchar(500)" +
                             ",VP varchar(500)" +
                             ",locationcode varchar(500)" +
                             ",readercode varchar(500)" +
                             ",PIN varchar(500)" +
                             ",bookcode varchar(500)" +
                             ")";
                db.ExecuteNonQuery(sql, null);
            }
            // 添加数据
            string name         = txtName.Text;
            string ip           = txtIP.Text;
            string port         = txtPort.Text;
            string ao           = txtAO.Text;
            string ap           = txtAP.Text;
            string charset      = txtCharset.Text;
            string uid          = txtUserName.Text;
            string pwd          = txtPwd.Text;
            string vp           = cboxVP.Text;
            string locationcode = txtLocationCode.Text;
            string readercode   = txtReaderCode.Text;
            string pin          = txtPIN.Text;
            string bookcode     = txtBookCode.Text;

            SQLiteParameter[] ps =
            {
                new SQLiteParameter()
                {
                    ParameterName = "id",
                    Value         = id
                },
                new SQLiteParameter()
                {
                    ParameterName = "name",
                    Value         = name
                },
                new SQLiteParameter()
                {
                    ParameterName = "ip",
                    Value         = ip
                },
                new SQLiteParameter()
                {
                    ParameterName = "port",
                    Value         = port
                },
                new SQLiteParameter()
                {
                    ParameterName = "ao",
                    Value         = ao
                },
                new SQLiteParameter()
                {
                    ParameterName = "ap",
                    Value         = ap
                },
                new SQLiteParameter()
                {
                    ParameterName = "charset",
                    Value         = charset
                },
                new SQLiteParameter()
                {
                    ParameterName = "uid",
                    Value         = uid
                },
                new SQLiteParameter()
                {
                    ParameterName = "pwd",
                    Value         = pwd
                },
                new SQLiteParameter()
                {
                    ParameterName = "vp",
                    Value         = vp
                },
                new SQLiteParameter()
                {
                    ParameterName = "locationcode",
                    Value         = locationcode
                },
                new SQLiteParameter()
                {
                    ParameterName = "readercode",
                    Value         = readercode
                },
                new SQLiteParameter()
                {
                    ParameterName = "pin",
                    Value         = pin
                },
                new SQLiteParameter()
                {
                    ParameterName = "bookcode",
                    Value         = bookcode
                },
            };

            if (id == 0)
            {
                string addSql = "Insert into Sip2Info(name, ip, port, ao, ap, charset, uid, pwd, vp, locationcode, readercode, pin, bookcode) values(@name, @ip, @port, @ao, @ap, @charset, @uid, @pwd, @vp, @locationcode, @readercode, @pin, @bookcode)";
                db.ExecuteNonQuery(addSql, ps);
            }
            else
            {
                string updateSql = "update Sip2Info set name = @name, ip = @ip, port = @port, ao = @ao, ap = @ap, charset = @charset, uid = @uid , pwd = @pwd, vp = @vp, locationcode = @locationcode, readercode = @readercode, pin = @pin, bookcode = @bookcode where id = @id";
                db.ExecuteNonQuery(updateSql, ps);
            }

            // 关闭窗口
            this.Close();
            if (getForm != null)
            {
                getForm.Reload();
            }
        }