Example #1
0
        public bool ExecuteNonQueryFromFile(string path, bool deleteFile = true)
        {
            try
            {
                if (!File.Exists(path))
                {
                    return(false);
                }

                _db.BeginTransaction();

                using (var read = new StreamReader(path, System.Text.Encoding.UTF8, true, 128))
                {
                    string line = string.Empty;

                    while ((line = read.ReadLine()) != null)
                    {
                        if (!_db.ExecuteNonQuery(line, false))
                        {
                            _db.Rollback();
                            return(false);
                        }
                    }
                }

                _db.Commit();

                if (deleteFile)
                {
                    try
                    {
                        File.Delete(path);
                    }
                    catch (Exception)
                    {
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Example #2
0
        public DataTable GetDeviceList(bool getAll = true)
        {
            string sql = string.Empty;

            sql += " SELECT ";
            sql += "    * ";
            sql += " FROM ";
            sql += "    m_device ";
            sql += " WHERE ";
            sql += "    {0} " + (!getAll ? " AND device_type > 0" : "");
            sql += " ORDER BY ";
            sql += "    device_type ASC ";

            DataTable rst           = null;
            DataTable defaultDevice = null;
            Dictionary <string, object> deviceData = null;

            try
            {
                rst = _db.GetTable(string.Format(sql, " userid = " + userGetDeviceList));

                if (clsCommon.TableIsNullOrEmpty(rst) && getAll)
                {
                    defaultDevice = _db.GetTable(string.Format(sql, " userid IS NULL "));

                    if (!clsCommon.TableIsNullOrEmpty(defaultDevice))
                    {
                        _db.BeginTransaction();

                        foreach (DataRow row in defaultDevice.Rows)
                        {
                            deviceData = new Dictionary <string, object>();
                            deviceData.Add("device_name", clsCommon.CnvNullToString(row["device_name"]));
                            deviceData.Add("ip_address", clsCommon.CnvNullToString(row["ip_address"]));
                            deviceData.Add("port", clsCommon.CnvNullToInt(row["port"]));
                            deviceData.Add("alarm_value", clsCommon.CnvNullToInt(row["alarm_value"]));
                            deviceData.Add("period", clsCommon.CnvNullToInt(row["period"]));
                            deviceData.Add("fail_level", clsCommon.CnvNullToInt(row["fail_level"]));
                            deviceData.Add("samples", clsCommon.CnvNullToInt(row["samples"]));
                            deviceData.Add("active", clsCommon.CnvNullToInt(row["active"]));
                            deviceData.Add("device_type", clsCommon.CnvNullToInt(row["device_type"]));
                            deviceData.Add("userid", userGetDeviceList);

                            if (!_db.InsertTable("m_device", deviceData, false))
                            {
                                _db.Rollback();
                                return(rst);
                            }
                        }

                        _db.Commit();

                        rst = _db.GetTable(string.Format(sql, " userid = " + userGetDeviceList));
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                _lastSqlQuery = _db.LastSqlQuery;
                clsCommon.TableDispose(ref defaultDevice);
                deviceData = null;
            }

            return(rst);
        }