コード例 #1
0
ファイル: frm5MinuteMPS.cs プロジェクト: quyhd/DataLoggerND
 public frm5MinuteMPS(data_value obj, LanguageService _lang)
 {
     InitializeComponent();
     obj_data_value = obj;
     lang           = _lang;
     switch_language();
 }
コード例 #2
0
ファイル: frm5MinuteTP.cs プロジェクト: quyhd/DataLoggerDN
 public frm5MinuteTP(data_value obj, LanguageService _lang)
 {
     InitializeComponent();
     obj_data_value = obj;
     //res_man = obj_res_man;
     //cul = obj_cul;
     lang = _lang;
     switch_language();
 }
コード例 #3
0
        /// <summary>
        /// get info by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public data_value get_info_by_id(int id)
        {
            using (NpgsqlDBConnection db = new NpgsqlDBConnection())
            {
                try
                {
                    data_value obj = null;
                    if (db.open_connection())
                    {
                        string sql_command = "SELECT * FROM data_values WHERE id = " + id;
                        sql_command += " LIMIT 1";
                        using (NpgsqlCommand cmd = db._conn.CreateCommand())
                        {
                            cmd.CommandText = sql_command;

                            NpgsqlDataReader reader = cmd.ExecuteReader();

                            while (reader.Read())
                            {
                                obj = new data_value();
                                obj = (data_value)_get_info(reader);
                                break;
                            }
                            reader.Close();
                            db.close_connection();
                            return(obj);
                        }
                    }
                    else
                    {
                        db.close_connection();
                        return(null);
                    }
                }
                catch
                {
                    if (db != null)
                    {
                        db.close_connection();
                    }
                    return(null);
                }
                finally
                { db.close_connection(); }
            }
        }
コード例 #4
0
        ///// <summary>
        ///// update
        ///// </summary>
        ///// <param name="obj"></param>
        ///// <returns></returns>
        //public int update(ref data_value obj)
        //{
        //    using (NpgsqlDBConnection db = new NpgsqlDBConnection())
        //    {
        //        try
        //        {

        //            if (db.open_connection())
        //            {
        //                string sql_command = "UPDATE data_values set  " +
        //                                    " data_value_key = :data_value_key, data_value_value =:data_value_value, " +
        //                                    " data_value_type =:data_value_type, " +
        //                                    " note = :note " +
        //                                    " where id = :id";

        //                using (NpgsqlCommand cmd = db._conn.CreateCommand())
        //                {
        //                    cmd.CommandText = sql_command;

        //                    cmd.Parameters.Add(new NpgsqlParameter(":data_value_key", obj.data_value_key));
        //                    cmd.Parameters.Add(new NpgsqlParameter(":data_value_value", obj.data_value_value));
        //                    cmd.Parameters.Add(new NpgsqlParameter(":data_value_type", obj.data_value_type));
        //                    cmd.Parameters.Add(new NpgsqlParameter(":note", obj.note));
        //                    cmd.Parameters.Add(new NpgsqlParameter(":id", obj.id));

        //                    cmd.ExecuteNonQuery();

        //                    db.close_connection();
        //                    return obj.id;
        //                }
        //            }
        //            else
        //            {
        //                db.close_connection();
        //                return -1;
        //            }
        //        }
        //        catch
        //        {
        //            if (db != null)
        //            {
        //                db.close_connection();
        //            }
        //            return -1;
        //        }
        //    }
        //}


        ///// <summary>
        ///// delete
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public bool delete(int id)
        //{
        //    using (NpgsqlDBConnection db = new NpgsqlDBConnection())
        //    {
        //        try
        //        {
        //            bool result = false;

        //            if (db.open_connection())
        //            {
        //                string sql_command = "DELETE from data_values where id = " + id;

        //                using (NpgsqlCommand cmd = db._conn.CreateCommand())
        //                {
        //                    cmd.CommandText = sql_command;
        //                    result = cmd.ExecuteNonQuery() > 0;
        //                    db.close_connection();
        //                    return true;
        //                }
        //            }
        //            else
        //            {
        //                db.close_connection();
        //                return result;
        //            }
        //        }
        //        catch
        //        {
        //            if (db != null)
        //            {
        //                db.close_connection();
        //            }
        //            return false;
        //        }
        //        finally
        //        { db.close_connection(); }
        //    }
        //}

        /// <summary>
        /// Get all
        /// </summary>
        /// <returns></returns>
        public IEnumerable <data_value> get_all()
        {
            List <data_value> listUser = new List <data_value>();

            using (NpgsqlDBConnection db = new NpgsqlDBConnection())
            {
                try
                {
                    if (db.open_connection())
                    {
                        string sql_command = "SELECT * FROM data_values";
                        using (NpgsqlCommand cmd = db._conn.CreateCommand())
                        {
                            cmd.CommandText = sql_command;
                            NpgsqlDataReader reader = cmd.ExecuteReader();
                            while (reader.Read())
                            {
                                data_value obj = new data_value();
                                obj = (data_value)_get_info(reader);
                                listUser.Add(obj);
                            }
                            reader.Close();
                            db.close_connection();
                            return(listUser);
                        }
                    }
                    else
                    {
                        db.close_connection();
                        return(null);
                    }
                }
                catch
                {
                    if (db != null)
                    {
                        db.close_connection();
                    }
                    return(null);
                }
                finally
                { db.close_connection(); }
            }
        }
コード例 #5
0
        private data_value _get_info(NpgsqlDataReader dataReader)
        {
            data_value obj = new data_value();

            try
            {
                if (!DBNull.Value.Equals(dataReader["id"]))
                {
                    obj.id = Convert.ToInt32(dataReader["id"].ToString().Trim());
                }
                else
                {
                    obj.id = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_pH"]))
                {
                    obj.MPS_pH = Convert.ToDouble(dataReader["MPS_pH"].ToString().Trim());
                }
                else
                {
                    obj.MPS_pH = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_pH_status"]))
                {
                    obj.MPS_pH_status = Convert.ToInt32(dataReader["MPS_pH_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_pH_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_EC"]))
                {
                    obj.MPS_EC = Convert.ToDouble(dataReader["MPS_EC"].ToString().Trim());
                }
                else
                {
                    obj.MPS_EC = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_EC_status"]))
                {
                    obj.MPS_EC_status = Convert.ToInt32(dataReader["MPS_EC_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_EC_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_DO"]))
                {
                    obj.MPS_DO = Convert.ToDouble(dataReader["MPS_DO"].ToString().Trim());
                }
                else
                {
                    obj.MPS_DO = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_DO_status"]))
                {
                    obj.MPS_DO_status = Convert.ToInt32(dataReader["MPS_DO_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_DO_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_Turbidity"]))
                {
                    obj.MPS_Turbidity = Convert.ToDouble(dataReader["MPS_Turbidity"].ToString().Trim());
                }
                else
                {
                    obj.MPS_Turbidity = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_Turbidity_status"]))
                {
                    obj.MPS_Turbidity_status = Convert.ToInt32(dataReader["MPS_Turbidity_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_Turbidity_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_ORP"]))
                {
                    obj.MPS_ORP = Convert.ToDouble(dataReader["MPS_ORP"].ToString().Trim());
                }
                else
                {
                    obj.MPS_ORP = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_ORP_status"]))
                {
                    obj.MPS_ORP_status = Convert.ToInt32(dataReader["MPS_ORP_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_ORP_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_Temp"]))
                {
                    obj.MPS_Temp = Convert.ToDouble(dataReader["MPS_Temp"].ToString().Trim());
                }
                else
                {
                    obj.MPS_Temp = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_Temp_status"]))
                {
                    obj.MPS_Temp_status = Convert.ToInt32(dataReader["MPS_Temp_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_Temp_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["MPS_SS"]))
                {
                    obj.MPS_SS = Convert.ToDouble(dataReader["MPS_SS"].ToString().Trim());
                }
                else
                {
                    obj.MPS_SS = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_SS_status"]))
                {
                    obj.MPS_SS_status = Convert.ToInt32(dataReader["MPS_SS_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_SS_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["TN"]))
                {
                    obj.TN = Convert.ToDouble(dataReader["TN"].ToString().Trim());
                }
                else
                {
                    obj.TN = 0;
                }
                if (!DBNull.Value.Equals(dataReader["TN_status"]))
                {
                    obj.TN_status = Convert.ToInt32(dataReader["TN_status"].ToString().Trim());
                }
                else
                {
                    obj.TN_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["TP"]))
                {
                    obj.TP = Convert.ToDouble(dataReader["TP"].ToString().Trim());
                }
                else
                {
                    obj.TP = 0;
                }
                if (!DBNull.Value.Equals(dataReader["TP_status"]))
                {
                    obj.TP_status = Convert.ToInt32(dataReader["TP_status"].ToString().Trim());
                }
                else
                {
                    obj.TP_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["TOC"]))
                {
                    obj.TOC = Convert.ToDouble(dataReader["TOC"].ToString().Trim());
                }
                else
                {
                    obj.TOC = 0;
                }
                if (!DBNull.Value.Equals(dataReader["TOC_status"]))
                {
                    obj.TOC_status = Convert.ToInt32(dataReader["TOC_status"].ToString().Trim());
                }
                else
                {
                    obj.TOC_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Power"]))
                {
                    obj.module_Power = Convert.ToInt32(dataReader["module_Power"].ToString().Trim());
                }
                else
                {
                    obj.module_Power = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_UPS"]))
                {
                    obj.module_UPS = Convert.ToInt32(dataReader["module_UPS"].ToString().Trim());
                }
                else
                {
                    obj.module_UPS = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Door"]))
                {
                    obj.module_Door = Convert.ToInt32(dataReader["module_Door"].ToString().Trim());
                }
                else
                {
                    obj.module_Door = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Fire"]))
                {
                    obj.module_Fire = Convert.ToInt32(dataReader["module_Fire"].ToString().Trim());
                }
                else
                {
                    obj.module_Fire = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Flow"]))
                {
                    obj.module_Flow = Convert.ToInt32(dataReader["module_Flow"].ToString().Trim());
                }
                else
                {
                    obj.module_Flow = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpLAM"]))
                {
                    obj.module_PumpLAM = Convert.ToInt32(dataReader["module_PumpLAM"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpLAM = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpLRS"]))
                {
                    obj.module_PumpLRS = Convert.ToInt32(dataReader["module_PumpLRS"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpLRS = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpLFLT"]))
                {
                    obj.module_PumpLFLT = Convert.ToInt32(dataReader["module_PumpLFLT"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpLFLT = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpRAM"]))
                {
                    obj.module_PumpRAM = Convert.ToInt32(dataReader["module_PumpRAM"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpRAM = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpRRS"]))
                {
                    obj.module_PumpRRS = Convert.ToInt32(dataReader["module_PumpRRS"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpRRS = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_PumpRFLT"]))
                {
                    obj.module_PumpRFLT = Convert.ToInt32(dataReader["module_PumpRFLT"].ToString().Trim());
                }
                else
                {
                    obj.module_PumpRFLT = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_air1"]))
                {
                    obj.module_air1 = Convert.ToInt32(dataReader["module_air1"].ToString().Trim());
                }
                else
                {
                    obj.module_air1 = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_air2"]))
                {
                    obj.module_air2 = Convert.ToInt32(dataReader["module_air2"].ToString().Trim());
                }
                else
                {
                    obj.module_air2 = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_cleaning"]))
                {
                    obj.module_cleaning = Convert.ToInt32(dataReader["module_cleaning"].ToString().Trim());
                }
                else
                {
                    obj.module_cleaning = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Temperature"]))
                {
                    obj.module_Temperature = Convert.ToDouble(dataReader["module_Temperature"].ToString().Trim());
                }
                else
                {
                    obj.module_Temperature = 0;
                }

                if (!DBNull.Value.Equals(dataReader["module_Humidity"]))
                {
                    obj.module_Humidity = Convert.ToDouble(dataReader["module_Humidity"].ToString().Trim());
                }
                else
                {
                    obj.module_Humidity = 0;
                }

                if (!DBNull.Value.Equals(dataReader["pumping_system_status"]))
                {
                    obj.pumping_system_status = Convert.ToInt32(dataReader["pumping_system_status"].ToString().Trim());
                }
                else
                {
                    obj.pumping_system_status = 0;
                }
                if (!DBNull.Value.Equals(dataReader["station_status"]))
                {
                    obj.station_status = Convert.ToInt32(dataReader["station_status"].ToString().Trim());
                }
                else
                {
                    obj.station_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["stored_date"]))
                {
                    obj.stored_date = Convert.ToDateTime(dataReader["stored_date"].ToString().Trim());
                }
                else
                {
                    obj.stored_date = DateTime.Now;
                }
                if (!DBNull.Value.Equals(dataReader["stored_hour"]))
                {
                    obj.stored_hour = Convert.ToInt32(dataReader["stored_hour"].ToString().Trim());
                }
                else
                {
                    obj.stored_hour = 0;
                }
                if (!DBNull.Value.Equals(dataReader["stored_minute"]))
                {
                    obj.stored_minute = Convert.ToInt32(dataReader["stored_minute"].ToString().Trim());
                }
                else
                {
                    obj.stored_minute = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_status"]))
                {
                    obj.MPS_status = Convert.ToInt32(dataReader["MPS_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_status = 0;
                }
                if (!DBNull.Value.Equals(dataReader["refrigeration_temperature"]))
                {
                    obj.refrigeration_temperature = Convert.ToDouble(dataReader["refrigeration_temperature"].ToString().Trim());
                }
                else
                {
                    obj.refrigeration_temperature = 0;
                }

                if (!DBNull.Value.Equals(dataReader["bottle_position"]))
                {
                    obj.bottle_position = Convert.ToInt32(dataReader["bottle_position"].ToString().Trim());
                }
                else
                {
                    obj.bottle_position = 0;
                }
                if (!DBNull.Value.Equals(dataReader["equipment_status"]))
                {
                    obj.equipment_status = Convert.ToInt32(dataReader["equipment_status"].ToString().Trim());
                }
                else
                {
                    obj.equipment_status = 0;
                }
                if (!DBNull.Value.Equals(dataReader["door_status"]))
                {
                    obj.door_status = Convert.ToInt32(dataReader["door_status"].ToString().Trim());
                }
                else
                {
                    obj.door_status = 0;
                }
                if (!DBNull.Value.Equals(dataReader["created"]))
                {
                    obj.created = Convert.ToDateTime(dataReader["created"].ToString().Trim());
                }
                else
                {
                    obj.created = DateTime.Now;
                }

                if (!DBNull.Value.Equals(dataReader["push"]))
                {
                    obj.push = Convert.ToInt32(dataReader["push"].ToString().Trim());
                }
                else
                {
                    obj.push = -1;
                }
                if (!DBNull.Value.Equals(dataReader["push_time"]))
                {
                    obj.push_time = Convert.ToDateTime(dataReader["push_time"].ToString().Trim());
                }
                else
                {
                    obj.push_time = new DateTime();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }
コード例 #6
0
        /// <summary>
        /// add new
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int add(ref data_value obj)
        {
            using (NpgsqlDBConnection db = new NpgsqlDBConnection())
            {
                try
                {
                    Int32 ID = -1;

                    if (db.open_connection())
                    {
                        string sql_command = "INSERT INTO data_values (MPS_pH, MPS_pH_status, MPS_EC, MPS_EC_status, " +
                                             " MPS_DO, MPS_DO_status, MPS_Turbidity, MPS_Turbidity_status, " +
                                             " MPS_ORP, MPS_ORP_status, MPS_Temp, MPS_Temp_status, MPS_SS, MPS_SS_status, " +
                                             " TN, TN_status, TP, TP_status, TOC, TOC_status, " +
                                             " module_Power, module_UPS, module_Door, module_Fire, module_Flow, " +
                                             " module_PumpLAM, module_PumpLRS, module_PumpLFLT, module_PumpRAM, module_PumpRRS, module_PumpRFLT, " +
                                             " module_air1, module_air2, module_cleaning, " +
                                             " module_Temperature, module_Humidity, " +
                                             " stored_date, stored_hour, stored_minute, MPS_status,pumping_system_status, station_status, " +
                                             " refrigeration_temperature, bottle_position, door_status, equipment_status, " +
                                             " push, push_time, " +
                                             " created)" +
                                             " VALUES (:MPS_pH, :MPS_pH_status, :MPS_EC, :MPS_EC_status, " +
                                             " :MPS_DO,:MPS_DO_status, :MPS_Turbidity, :MPS_Turbidity_status, " +
                                             " :MPS_ORP, :MPS_ORP_status, :MPS_Temp, :MPS_Temp_status,  :MPS_SS, :MPS_SS_status, " +
                                             " :TN, :TN_status, :TP, :TP_status, :TOC, :TOC_status, " +
                                             " :module_Power, :module_UPS, :module_Door, :module_Fire, :module_Flow, " +
                                             " :module_PumpLAM,:module_PumpLRS,:module_PumpLFLT,:module_PumpRAM,:module_PumpRRS,:module_PumpRFLT, " +
                                             " :module_air1, :module_air2, :module_cleaning, " +
                                             " :module_Temperature, :module_Humidity," +
                                             " :stored_date, :stored_hour, :stored_minute, :MPS_status, :pumping_system_status, :station_status, " +
                                             " :refrigeration_temperature, :bottle_position, :door_status, :equipment_status, " +
                                             " :push, :push_time, " +
                                             " :created)";
                        sql_command += " RETURNING id;";

                        using (NpgsqlCommand cmd = db._conn.CreateCommand())
                        {
                            cmd.CommandText = sql_command;

                            cmd.Parameters.Add(":MPS_pH", NpgsqlTypes.NpgsqlDbType.Double).Value                = obj.MPS_pH;
                            cmd.Parameters.Add(":MPS_pH_status", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.MPS_pH_status;
                            cmd.Parameters.Add(":MPS_EC", NpgsqlTypes.NpgsqlDbType.Double).Value                = obj.MPS_EC;
                            cmd.Parameters.Add(":MPS_EC_status", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.MPS_EC_status;
                            cmd.Parameters.Add(":MPS_DO", NpgsqlTypes.NpgsqlDbType.Double).Value                = obj.MPS_DO;
                            cmd.Parameters.Add(":MPS_DO_status", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.MPS_DO_status;
                            cmd.Parameters.Add(":MPS_Turbidity", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.MPS_Turbidity;
                            cmd.Parameters.Add(":MPS_Turbidity_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.MPS_Turbidity_status;
                            cmd.Parameters.Add(":MPS_ORP", NpgsqlTypes.NpgsqlDbType.Double).Value               = obj.MPS_ORP;
                            cmd.Parameters.Add(":MPS_ORP_status", NpgsqlTypes.NpgsqlDbType.Integer).Value       = obj.MPS_ORP_status;
                            cmd.Parameters.Add(":MPS_Temp", NpgsqlTypes.NpgsqlDbType.Double).Value              = obj.MPS_Temp;
                            cmd.Parameters.Add(":MPS_Temp_status", NpgsqlTypes.NpgsqlDbType.Integer).Value      = obj.MPS_Temp_status;
                            cmd.Parameters.Add(":MPS_SS", NpgsqlTypes.NpgsqlDbType.Double).Value                = obj.MPS_SS;
                            cmd.Parameters.Add(":MPS_SS_status", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.MPS_SS_status;
                            cmd.Parameters.Add(":TN", NpgsqlTypes.NpgsqlDbType.Double).Value          = obj.TN;
                            cmd.Parameters.Add(":TN_status", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.TN_status;
                            cmd.Parameters.Add(":TP", NpgsqlTypes.NpgsqlDbType.Double).Value          = obj.TP;
                            cmd.Parameters.Add(":TP_status", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.TP_status;
                            cmd.Parameters.Add(":TOC", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.TOC;
                            cmd.Parameters.Add(":TOC_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.TOC_status;

                            cmd.Parameters.Add(":module_Power", NpgsqlTypes.NpgsqlDbType.Integer).Value   = obj.module_Power;
                            cmd.Parameters.Add(":module_UPS", NpgsqlTypes.NpgsqlDbType.Integer).Value     = obj.module_UPS;
                            cmd.Parameters.Add(":module_Door", NpgsqlTypes.NpgsqlDbType.Integer).Value    = obj.module_Door;
                            cmd.Parameters.Add(":module_Fire", NpgsqlTypes.NpgsqlDbType.Integer).Value    = obj.module_Fire;
                            cmd.Parameters.Add(":module_Flow", NpgsqlTypes.NpgsqlDbType.Integer).Value    = obj.module_Flow;
                            cmd.Parameters.Add(":module_PumpLAM", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.module_PumpLAM;

                            cmd.Parameters.Add(":module_PumpLRS", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.module_PumpLRS;
                            cmd.Parameters.Add(":module_PumpLFLT", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.module_PumpLFLT;
                            cmd.Parameters.Add(":module_PumpRAM", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.module_PumpRAM;
                            cmd.Parameters.Add(":module_PumpRRS", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.module_PumpRRS;
                            cmd.Parameters.Add(":module_PumpRFLT", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.module_PumpRFLT;
                            cmd.Parameters.Add(":module_air1", NpgsqlTypes.NpgsqlDbType.Integer).Value     = obj.module_air1;
                            cmd.Parameters.Add(":module_air2", NpgsqlTypes.NpgsqlDbType.Integer).Value     = obj.module_air2;
                            cmd.Parameters.Add(":module_cleaning", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.module_cleaning;

                            cmd.Parameters.Add(":module_Temperature", NpgsqlTypes.NpgsqlDbType.Double).Value = obj.module_Temperature;
                            cmd.Parameters.Add(":module_Humidity", NpgsqlTypes.NpgsqlDbType.Double).Value    = obj.module_Humidity;

                            cmd.Parameters.Add(":stored_date", NpgsqlTypes.NpgsqlDbType.Date).Value              = obj.stored_date;
                            cmd.Parameters.Add(":stored_hour", NpgsqlTypes.NpgsqlDbType.Integer).Value           = obj.stored_hour;
                            cmd.Parameters.Add(":stored_minute", NpgsqlTypes.NpgsqlDbType.Integer).Value         = obj.stored_minute;
                            cmd.Parameters.Add(":MPS_status", NpgsqlTypes.NpgsqlDbType.Integer).Value            = obj.MPS_status;
                            cmd.Parameters.Add(":pumping_system_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.pumping_system_status;
                            cmd.Parameters.Add(":station_status", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.station_status;

                            cmd.Parameters.Add(":refrigeration_temperature", NpgsqlTypes.NpgsqlDbType.Double).Value = obj.refrigeration_temperature;
                            cmd.Parameters.Add(":bottle_position", NpgsqlTypes.NpgsqlDbType.Integer).Value          = obj.bottle_position;
                            cmd.Parameters.Add(":door_status", NpgsqlTypes.NpgsqlDbType.Integer).Value      = obj.door_status;
                            cmd.Parameters.Add(":equipment_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.equipment_status;
                            cmd.Parameters.Add(":created", NpgsqlTypes.NpgsqlDbType.Timestamp).Value        = obj.created;

                            cmd.Parameters.Add(":push", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.push;
                            cmd.Parameters.Add(":push_time", NpgsqlTypes.NpgsqlDbType.Timestamp).Value = obj.push_time;

                            //cmd.ExecuteNonQuery();
                            ID     = (Int32)cmd.ExecuteScalar();
                            obj.id = ID;

                            db.close_connection();
                            return(ID);
                        }
                    }
                    else
                    {
                        db.close_connection();
                        return(-1);
                    }
                }
                catch (Exception e)
                {
                    if (db != null)
                    {
                        db.close_connection();
                    }
                    return(-1);
                }
                finally
                {
                    db.close_connection();
                }
            }
        }
コード例 #7
0
        private data_value _get_info(NpgsqlDataReader dataReader)
        {
            data_value obj = new data_value();

            try
            {
                if (!DBNull.Value.Equals(dataReader["id"]))
                {
                    obj.id = Convert.ToInt32(dataReader["id"].ToString().Trim());
                }
                else
                {
                    obj.id = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var1"]))
                {
                    obj.var1 = Convert.ToDouble(dataReader["var1"].ToString().Trim());
                }
                else
                {
                    obj.var1 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var1_status"]))
                {
                    obj.var1_status = Convert.ToInt32(dataReader["var1_status"].ToString().Trim());
                }
                else
                {
                    obj.var1_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var2"]))
                {
                    obj.var2 = Convert.ToDouble(dataReader["var2"].ToString().Trim());
                }
                else
                {
                    obj.var2 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var2_status"]))
                {
                    obj.var2_status = Convert.ToInt32(dataReader["var2_status"].ToString().Trim());
                }
                else
                {
                    obj.var2_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var3"]))
                {
                    obj.var3 = Convert.ToDouble(dataReader["var3"].ToString().Trim());
                }
                else
                {
                    obj.var3 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var3_status"]))
                {
                    obj.var3_status = Convert.ToInt32(dataReader["var3_status"].ToString().Trim());
                }
                else
                {
                    obj.var3_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var4"]))
                {
                    obj.var4 = Convert.ToDouble(dataReader["var4"].ToString().Trim());
                }
                else
                {
                    obj.var4 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var4_status"]))
                {
                    obj.var4_status = Convert.ToInt32(dataReader["var4_status"].ToString().Trim());
                }
                else
                {
                    obj.var4_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var5"]))
                {
                    obj.var5 = Convert.ToDouble(dataReader["var5"].ToString().Trim());
                }
                else
                {
                    obj.var5 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var5_status"]))
                {
                    obj.var5_status = Convert.ToInt32(dataReader["var5_status"].ToString().Trim());
                }
                else
                {
                    obj.var5_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var6"]))
                {
                    obj.var6 = Convert.ToDouble(dataReader["var6"].ToString().Trim());
                }
                else
                {
                    obj.var6 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var6_status"]))
                {
                    obj.var6_status = Convert.ToInt32(dataReader["var6_status"].ToString().Trim());
                }
                else
                {
                    obj.var6_status = 0;
                }

                //if (!DBNull.Value.Equals(dataReader["TN"]))
                //    obj.TN = Convert.ToDouble(dataReader["TN"].ToString().Trim());
                //else
                //    obj.TN = 0;
                //if (!DBNull.Value.Equals(dataReader["TN_status"]))
                //    obj.TN_status = Convert.ToInt32(dataReader["TN_status"].ToString().Trim());
                //else
                //    obj.TN_status = 0;

                //if (!DBNull.Value.Equals(dataReader["TP"]))
                //    obj.TP = Convert.ToDouble(dataReader["TP"].ToString().Trim());
                //else
                //    obj.TP = 0;
                //if (!DBNull.Value.Equals(dataReader["TP_status"]))
                //    obj.TP_status = Convert.ToInt32(dataReader["TP_status"].ToString().Trim());
                //else
                //    obj.TP_status = 0;

                //if (!DBNull.Value.Equals(dataReader["TOC"]))
                //    obj.TOC = Convert.ToDouble(dataReader["TOC"].ToString().Trim());
                //else
                //    obj.TOC = 0;
                //if (!DBNull.Value.Equals(dataReader["TOC_status"]))
                //    obj.TOC_status = Convert.ToInt32(dataReader["TOC_status"].ToString().Trim());
                //else
                //    obj.TOC_status = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Power"]))
                //    obj.module_Power = Convert.ToInt32(dataReader["module_Power"].ToString().Trim());
                //else
                //    obj.module_Power = 0;

                //if (!DBNull.Value.Equals(dataReader["module_UPS"]))
                //    obj.module_UPS = Convert.ToInt32(dataReader["module_UPS"].ToString().Trim());
                //else
                //    obj.module_UPS = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Door"]))
                //    obj.module_Door = Convert.ToInt32(dataReader["module_Door"].ToString().Trim());
                //else
                //    obj.module_Door = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Fire"]))
                //    obj.module_Fire = Convert.ToInt32(dataReader["module_Fire"].ToString().Trim());
                //else
                //    obj.module_Fire = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Flow"]))
                //    obj.module_Flow = Convert.ToInt32(dataReader["module_Flow"].ToString().Trim());
                //else
                //    obj.module_Flow = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpLAM"]))
                //    obj.module_PumpLAM = Convert.ToInt32(dataReader["module_PumpLAM"].ToString().Trim());
                //else
                //    obj.module_PumpLAM = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpLRS"]))
                //    obj.module_PumpLRS = Convert.ToInt32(dataReader["module_PumpLRS"].ToString().Trim());
                //else
                //    obj.module_PumpLRS = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpLFLT"]))
                //    obj.module_PumpLFLT = Convert.ToInt32(dataReader["module_PumpLFLT"].ToString().Trim());
                //else
                //    obj.module_PumpLFLT = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpRAM"]))
                //    obj.module_PumpRAM = Convert.ToInt32(dataReader["module_PumpRAM"].ToString().Trim());
                //else
                //    obj.module_PumpRAM = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpRRS"]))
                //    obj.module_PumpRRS = Convert.ToInt32(dataReader["module_PumpRRS"].ToString().Trim());
                //else
                //    obj.module_PumpRRS = 0;

                //if (!DBNull.Value.Equals(dataReader["module_PumpRFLT"]))
                //    obj.module_PumpRFLT = Convert.ToInt32(dataReader["module_PumpRFLT"].ToString().Trim());
                //else
                //    obj.module_PumpRFLT = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Temperature"]))
                //    obj.module_Temperature = Convert.ToDouble(dataReader["module_Temperature"].ToString().Trim());
                //else
                //    obj.module_Temperature = 0;

                //if (!DBNull.Value.Equals(dataReader["module_Humidity"]))
                //    obj.module_Humidity = Convert.ToDouble(dataReader["module_Humidity"].ToString().Trim());
                //else
                //    obj.module_Humidity = 0;

                //if (!DBNull.Value.Equals(dataReader["pumping_system_status"]))
                //    obj.pumping_system_status = Convert.ToInt32(dataReader["pumping_system_status"].ToString().Trim());
                //else
                //    obj.pumping_system_status = 0;
                //if (!DBNull.Value.Equals(dataReader["station_status"]))
                //    obj.station_status = Convert.ToInt32(dataReader["station_status"].ToString().Trim());
                //else
                //    obj.station_status = 0;

                if (!DBNull.Value.Equals(dataReader["stored_date"]))
                {
                    obj.stored_date = Convert.ToDateTime(dataReader["stored_date"].ToString().Trim());
                }
                else
                {
                    obj.stored_date = DateTime.Now;
                }
                if (!DBNull.Value.Equals(dataReader["stored_hour"]))
                {
                    obj.stored_hour = Convert.ToInt32(dataReader["stored_hour"].ToString().Trim());
                }
                else
                {
                    obj.stored_hour = 0;
                }
                if (!DBNull.Value.Equals(dataReader["stored_minute"]))
                {
                    obj.stored_minute = Convert.ToInt32(dataReader["stored_minute"].ToString().Trim());
                }
                else
                {
                    obj.stored_minute = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_status"]))
                {
                    obj.MPS_status = Convert.ToInt32(dataReader["MPS_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_status = 0;
                }
                //if (!DBNull.Value.Equals(dataReader["refrigeration_temperature"]))
                //    obj.refrigeration_temperature = Convert.ToDouble(dataReader["refrigeration_temperature"].ToString().Trim());
                //else
                //    obj.refrigeration_temperature = 0;

                //if (!DBNull.Value.Equals(dataReader["bottle_position"]))
                //    obj.bottle_position = Convert.ToInt32(dataReader["bottle_position"].ToString().Trim());
                //else
                //    obj.bottle_position = 0;
                //if (!DBNull.Value.Equals(dataReader["equipment_status"]))
                //    obj.equipment_status = Convert.ToInt32(dataReader["equipment_status"].ToString().Trim());
                //else
                //    obj.equipment_status = 0;
                //if (!DBNull.Value.Equals(dataReader["door_status"]))
                //    obj.door_status = Convert.ToInt32(dataReader["door_status"].ToString().Trim());
                //else
                //    obj.door_status = 0;
                if (!DBNull.Value.Equals(dataReader["created"]))
                {
                    obj.created = Convert.ToDateTime(dataReader["created"].ToString().Trim());
                }
                else
                {
                    obj.created = DateTime.Now;
                }

                if (!DBNull.Value.Equals(dataReader["push"]))
                {
                    obj.push = Convert.ToInt32(dataReader["push"].ToString().Trim());
                }
                else
                {
                    obj.push = -1;
                }
                if (!DBNull.Value.Equals(dataReader["push_time"]))
                {
                    obj.push_time = Convert.ToDateTime(dataReader["push_time"].ToString().Trim());
                }
                else
                {
                    obj.push_time = new DateTime();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }
コード例 #8
0
        /// <summary>
        /// add new
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int add(ref data_value obj)
        {
            using (NpgsqlDBConnection db = new NpgsqlDBConnection())
            {
                try
                {
                    Int32 ID = -1;

                    if (db.open_connection())
                    {
                        string sql_command = "INSERT INTO data_values (var1, var1_status, var2, var2_status, " +
                                             " var3, var3_status, var4, var4_status, " +
                                             " var5, var5_status, var6, var6_status, " +
                                             " stored_date, stored_hour, stored_minute, MPS_status," +
                                             " push, push_time, " +
                                             " created)" +
                                             " VALUES (:var1, :var1_status, :var2, :var2_status, " +
                                             " :var3,:var3_status, :var4, :var4_status, " +
                                             " :var5, :var5_status, :var6, :var6_status, " +
                                             " :stored_date, :stored_hour, :stored_minute, :MPS_status, " +
                                             " :push, :push_time, " +
                                             " :created)";
                        sql_command += " RETURNING id;";

                        using (NpgsqlCommand cmd = db._conn.CreateCommand())
                        {
                            cmd.CommandText = sql_command;

                            cmd.Parameters.Add(":var1", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var1;
                            cmd.Parameters.Add(":var1_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var1_status;
                            cmd.Parameters.Add(":var2", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var2;
                            cmd.Parameters.Add(":var2_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var2_status;
                            cmd.Parameters.Add(":var3", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var3;
                            cmd.Parameters.Add(":var3_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var3_status;
                            cmd.Parameters.Add(":var4", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var4;
                            cmd.Parameters.Add(":var4_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var4_status;
                            cmd.Parameters.Add(":var5", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var5;
                            cmd.Parameters.Add(":var5_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var5_status;
                            cmd.Parameters.Add(":var6", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var6;
                            cmd.Parameters.Add(":var6_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var6_status;

                            cmd.Parameters.Add(":stored_date", NpgsqlTypes.NpgsqlDbType.Date).Value      = obj.stored_date;
                            cmd.Parameters.Add(":stored_hour", NpgsqlTypes.NpgsqlDbType.Integer).Value   = obj.stored_hour;
                            cmd.Parameters.Add(":stored_minute", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.stored_minute;
                            cmd.Parameters.Add(":MPS_status", NpgsqlTypes.NpgsqlDbType.Integer).Value    = obj.MPS_status;

                            cmd.Parameters.Add(":created", NpgsqlTypes.NpgsqlDbType.Timestamp).Value   = obj.created;
                            cmd.Parameters.Add(":push", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.push;
                            cmd.Parameters.Add(":push_time", NpgsqlTypes.NpgsqlDbType.Timestamp).Value = obj.push_time;
                            //cmd.ExecuteNonQuery();
                            ID     = (Int32)cmd.ExecuteScalar();
                            obj.id = ID;

                            db.close_connection();
                            return(ID);
                        }
                        Console.Write("ADD data_values TRUE");
                    }
                    else
                    {
                        db.close_connection();
                        return(-1);

                        Console.Write("ADD data_values FALSE");
                    }
                }
                catch (Exception e)
                {
                    if (db != null)
                    {
                        db.close_connection();
                    }
                    return(-1);

                    Console.Write(e.StackTrace);
                }
                finally
                {
                    db.close_connection();
                }
            }
        }
コード例 #9
0
        private data_value _get_info(NpgsqlDataReader dataReader)
        {
            data_value obj = new data_value();

            try
            {
                if (!DBNull.Value.Equals(dataReader["id"]))
                {
                    obj.id = Convert.ToInt32(dataReader["id"].ToString().Trim());
                }
                else
                {
                    obj.id = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var1"]))
                {
                    obj.var1 = Convert.ToDouble(dataReader["var1"].ToString().Trim());
                }
                else
                {
                    obj.var1 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var1_status"]))
                {
                    obj.var1_status = Convert.ToInt32(dataReader["var1_status"].ToString().Trim());
                }
                else
                {
                    obj.var1_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var2"]))
                {
                    obj.var2 = Convert.ToDouble(dataReader["var2"].ToString().Trim());
                }
                else
                {
                    obj.var2 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var2_status"]))
                {
                    obj.var2_status = Convert.ToInt32(dataReader["var2_status"].ToString().Trim());
                }
                else
                {
                    obj.var2_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var3"]))
                {
                    obj.var3 = Convert.ToDouble(dataReader["var3"].ToString().Trim());
                }
                else
                {
                    obj.var3 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var3_status"]))
                {
                    obj.var3_status = Convert.ToInt32(dataReader["var3_status"].ToString().Trim());
                }
                else
                {
                    obj.var3_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var4"]))
                {
                    obj.var4 = Convert.ToDouble(dataReader["var4"].ToString().Trim());
                }
                else
                {
                    obj.var4 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var4_status"]))
                {
                    obj.var4_status = Convert.ToInt32(dataReader["var4_status"].ToString().Trim());
                }
                else
                {
                    obj.var4_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var5"]))
                {
                    obj.var5 = Convert.ToDouble(dataReader["var5"].ToString().Trim());
                }
                else
                {
                    obj.var5 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var5_status"]))
                {
                    obj.var5_status = Convert.ToInt32(dataReader["var5_status"].ToString().Trim());
                }
                else
                {
                    obj.var5_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var6"]))
                {
                    obj.var6 = Convert.ToDouble(dataReader["var6"].ToString().Trim());
                }
                else
                {
                    obj.var6 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var6_status"]))
                {
                    obj.var6_status = Convert.ToInt32(dataReader["var6_status"].ToString().Trim());
                }
                else
                {
                    obj.var6_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var7"]))
                {
                    obj.var7 = Convert.ToDouble(dataReader["var7"].ToString().Trim());
                }
                else
                {
                    obj.var7 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var7_status"]))
                {
                    obj.var7_status = Convert.ToInt32(dataReader["var7_status"].ToString().Trim());
                }
                else
                {
                    obj.var7_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var8"]))
                {
                    obj.var8 = Convert.ToDouble(dataReader["var8"].ToString().Trim());
                }
                else
                {
                    obj.var8 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var8_status"]))
                {
                    obj.var8_status = Convert.ToInt32(dataReader["var8_status"].ToString().Trim());
                }
                else
                {
                    obj.var8_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var9"]))
                {
                    obj.var9 = Convert.ToDouble(dataReader["var9"].ToString().Trim());
                }
                else
                {
                    obj.var9 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var9_status"]))
                {
                    obj.var9_status = Convert.ToInt32(dataReader["var9_status"].ToString().Trim());
                }
                else
                {
                    obj.var9_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var10"]))
                {
                    obj.var10 = Convert.ToDouble(dataReader["var10"].ToString().Trim());
                }
                else
                {
                    obj.var10 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var10_status"]))
                {
                    obj.var10_status = Convert.ToInt32(dataReader["var10_status"].ToString().Trim());
                }
                else
                {
                    obj.var10_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var11"]))
                {
                    obj.var11 = Convert.ToDouble(dataReader["var11"].ToString().Trim());
                }
                else
                {
                    obj.var11 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var11_status"]))
                {
                    obj.var11_status = Convert.ToInt32(dataReader["var11_status"].ToString().Trim());
                }
                else
                {
                    obj.var11_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var12"]))
                {
                    obj.var12 = Convert.ToDouble(dataReader["var12"].ToString().Trim());
                }
                else
                {
                    obj.var12 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var12_status"]))
                {
                    obj.var12_status = Convert.ToInt32(dataReader["var12_status"].ToString().Trim());
                }
                else
                {
                    obj.var12_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var13"]))
                {
                    obj.var13 = Convert.ToDouble(dataReader["var13"].ToString().Trim());
                }
                else
                {
                    obj.var13 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var13_status"]))
                {
                    obj.var13_status = Convert.ToInt32(dataReader["var13_status"].ToString().Trim());
                }
                else
                {
                    obj.var13_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var14"]))
                {
                    obj.var14 = Convert.ToDouble(dataReader["var14"].ToString().Trim());
                }
                else
                {
                    obj.var14 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var14_status"]))
                {
                    obj.var14_status = Convert.ToInt32(dataReader["var14_status"].ToString().Trim());
                }
                else
                {
                    obj.var14_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var15"]))
                {
                    obj.var15 = Convert.ToDouble(dataReader["var15"].ToString().Trim());
                }
                else
                {
                    obj.var15 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var15_status"]))
                {
                    obj.var15_status = Convert.ToInt32(dataReader["var15_status"].ToString().Trim());
                }
                else
                {
                    obj.var15_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var16"]))
                {
                    obj.var16 = Convert.ToDouble(dataReader["var16"].ToString().Trim());
                }
                else
                {
                    obj.var16 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var16_status"]))
                {
                    obj.var16_status = Convert.ToInt32(dataReader["var16_status"].ToString().Trim());
                }
                else
                {
                    obj.var16_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var17"]))
                {
                    obj.var17 = Convert.ToDouble(dataReader["var17"].ToString().Trim());
                }
                else
                {
                    obj.var17 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var17_status"]))
                {
                    obj.var17_status = Convert.ToInt32(dataReader["var17_status"].ToString().Trim());
                }
                else
                {
                    obj.var17_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["var18"]))
                {
                    obj.var18 = Convert.ToDouble(dataReader["var18"].ToString().Trim());
                }
                else
                {
                    obj.var18 = 0;
                }
                if (!DBNull.Value.Equals(dataReader["var18_status"]))
                {
                    obj.var18_status = Convert.ToInt32(dataReader["var18_status"].ToString().Trim());
                }
                else
                {
                    obj.var18_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["stored_date"]))
                {
                    obj.stored_date = Convert.ToDateTime(dataReader["stored_date"].ToString().Trim());
                }
                else
                {
                    obj.stored_date = DateTime.Now;
                }
                if (!DBNull.Value.Equals(dataReader["stored_hour"]))
                {
                    obj.stored_hour = Convert.ToInt32(dataReader["stored_hour"].ToString().Trim());
                }
                else
                {
                    obj.stored_hour = 0;
                }
                if (!DBNull.Value.Equals(dataReader["stored_minute"]))
                {
                    obj.stored_minute = Convert.ToInt32(dataReader["stored_minute"].ToString().Trim());
                }
                else
                {
                    obj.stored_minute = 0;
                }
                if (!DBNull.Value.Equals(dataReader["MPS_status"]))
                {
                    obj.MPS_status = Convert.ToInt32(dataReader["MPS_status"].ToString().Trim());
                }
                else
                {
                    obj.MPS_status = 0;
                }

                if (!DBNull.Value.Equals(dataReader["created"]))
                {
                    obj.created = Convert.ToDateTime(dataReader["created"].ToString().Trim());
                }
                else
                {
                    obj.created = DateTime.Now;
                }

                if (!DBNull.Value.Equals(dataReader["push"]))
                {
                    obj.push = Convert.ToInt32(dataReader["push"].ToString().Trim());
                }
                else
                {
                    obj.push = -1;
                }
                if (!DBNull.Value.Equals(dataReader["push_time"]))
                {
                    obj.push_time = Convert.ToDateTime(dataReader["push_time"].ToString().Trim());
                }
                else
                {
                    obj.push_time = new DateTime();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }
コード例 #10
0
        /// <summary>
        /// add new
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public int add(ref data_value obj)
        {
            using (NpgsqlDBConnection db = new NpgsqlDBConnection())
            {
                try
                {
                    Int32 ID = -1;

                    if (db.open_connection())
                    {
                        string sql_command = "INSERT INTO data_values (var1, var1_status, var2, var2_status, " +
                                             " var3, var3_status, var4, var4_status, " +
                                             " var5, var5_status, var6, var6_status, var7, var7_status, " +
                                             " var8, var8_status, var9, var9_status, var10, var10_status, " +
                                             " var11, var11_status, var12, var12_status, var13, var13_status, " +
                                             " var14, var14_status, var15, var15_status, var16, var16_status, " +
                                             " var17, var17_status, var18, var18_status, " +
                                             " var19, var19_status, var20, var20_status, " +
                                             " var21, var21_status, var22, var22_status, var23, var23_status, " +
                                             " var24, var24_status, var25, var25_status, var26, var26_status, " +
                                             " var27, var27_status, var28, var28_status, var29, var29_status, " +
                                             " var30, var30_status, var31, var31_status, var32, var32_status, " +
                                             " var33, var33_status, var34, var34_status,  var35, var35_status," +
                                             " stored_date, stored_hour, stored_minute, MPS_status, " +
                                             " push, push_time, " +
                                             " created)" +
                                             " VALUES (:var1, :var1_status, :var2, :var2_status, " +
                                             " :var3,:var3_status, :var4, :var4_status, " +
                                             " :var5, :var5_status, :var6, :var6_status, :var7, :var7_status, " +
                                             " :var8, :var8_status, :var9, :var9_status, :var10, :var10_status, " +
                                             " :var11, :var11_status, :var12, :var12_status, :var13, :var13_status, " +
                                             " :var14, :var14_status, :var15, :var15_status, :var16, :var16_status, " +
                                             " :var17, :var17_status, :var18, :var18_status, " +
                                             " :var19, :var19_status, :var20, :var20_status, " +
                                             " :var21, :var21_status, :var22, :var22_status, :var23, :var23_status, " +
                                             " :var24, :var24_status, :var25, :var25_status, :var26, :var26_status, " +
                                             " :var27, :var27_status, :var28, :var28_status, :var29, :var29_status, " +
                                             " :var30, :var30_status, :var31, :var31_status, :var32, :var32_status, " +
                                             " :var33, :var33_status, :var34, :var34_status, :var35, :var35_status," +
                                             " :stored_date, :stored_hour, :stored_minute, :MPS_status, " +
                                             " :push, :push_time, " +
                                             " :created)";
                        sql_command += " RETURNING id;";

                        using (NpgsqlCommand cmd = db._conn.CreateCommand())
                        {
                            cmd.CommandText = sql_command;

                            cmd.Parameters.Add(":var1", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var1;
                            cmd.Parameters.Add(":var1_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var1_status;
                            cmd.Parameters.Add(":var2", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var2;
                            cmd.Parameters.Add(":var2_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var2_status;
                            cmd.Parameters.Add(":var3", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var3;
                            cmd.Parameters.Add(":var3_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var3_status;
                            cmd.Parameters.Add(":var4", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var4;
                            cmd.Parameters.Add(":var4_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var4_status;
                            cmd.Parameters.Add(":var5", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var5;
                            cmd.Parameters.Add(":var5_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var5_status;
                            cmd.Parameters.Add(":var6", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var6;
                            cmd.Parameters.Add(":var6_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var6_status;
                            cmd.Parameters.Add(":var7", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var7;
                            cmd.Parameters.Add(":var7_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var7_status;

                            cmd.Parameters.Add(":var8", NpgsqlTypes.NpgsqlDbType.Double).Value          = obj.var8;
                            cmd.Parameters.Add(":var8_status", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.var8_status;
                            cmd.Parameters.Add(":var9", NpgsqlTypes.NpgsqlDbType.Double).Value          = obj.var9;
                            cmd.Parameters.Add(":var9_status", NpgsqlTypes.NpgsqlDbType.Integer).Value  = obj.var9_status;
                            cmd.Parameters.Add(":var10", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var10;
                            cmd.Parameters.Add(":var10_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var10_status;
                            cmd.Parameters.Add(":var11", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var11;
                            cmd.Parameters.Add(":var11_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var11_status;
                            cmd.Parameters.Add(":var12", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var12;
                            cmd.Parameters.Add(":var12_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var12_status;
                            cmd.Parameters.Add(":var13", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var13;
                            cmd.Parameters.Add(":var13_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var13_status;
                            cmd.Parameters.Add(":var14", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var14;
                            cmd.Parameters.Add(":var14_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var14_status;
                            cmd.Parameters.Add(":var15", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var15;
                            cmd.Parameters.Add(":var15_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var15_status;
                            cmd.Parameters.Add(":var16", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var16;
                            cmd.Parameters.Add(":var16_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var16_status;
                            cmd.Parameters.Add(":var17", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var17;
                            cmd.Parameters.Add(":var17_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var17_status;
                            cmd.Parameters.Add(":var18", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var18;
                            cmd.Parameters.Add(":var18_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var18_status;

                            cmd.Parameters.Add(":var19", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var19;
                            cmd.Parameters.Add(":var19_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var19_status;
                            cmd.Parameters.Add(":var20", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var20;
                            cmd.Parameters.Add(":var20_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var20_status;
                            cmd.Parameters.Add(":var21", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var21;
                            cmd.Parameters.Add(":var21_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var21_status;
                            cmd.Parameters.Add(":var22", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var22;
                            cmd.Parameters.Add(":var22_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var22_status;
                            cmd.Parameters.Add(":var23", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var23;
                            cmd.Parameters.Add(":var23_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var23_status;
                            cmd.Parameters.Add(":var24", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var24;
                            cmd.Parameters.Add(":var24_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var24_status;
                            cmd.Parameters.Add(":var25", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var25;
                            cmd.Parameters.Add(":var25_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var25_status;

                            cmd.Parameters.Add(":var26", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var26;
                            cmd.Parameters.Add(":var26_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var26_status;
                            cmd.Parameters.Add(":var27", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var27;
                            cmd.Parameters.Add(":var27_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var27_status;
                            cmd.Parameters.Add(":var28", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var28;
                            cmd.Parameters.Add(":var28_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var28_status;
                            cmd.Parameters.Add(":var29", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var29;
                            cmd.Parameters.Add(":var29_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var29_status;
                            cmd.Parameters.Add(":var30", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var30;
                            cmd.Parameters.Add(":var30_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var30_status;
                            cmd.Parameters.Add(":var31", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var31;
                            cmd.Parameters.Add(":var31_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var31_status;
                            cmd.Parameters.Add(":var32", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var32;
                            cmd.Parameters.Add(":var32_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var32_status;
                            cmd.Parameters.Add(":var33", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var33;
                            cmd.Parameters.Add(":var33_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var33_status;
                            cmd.Parameters.Add(":var34", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var34;
                            cmd.Parameters.Add(":var34_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var34_status;
                            cmd.Parameters.Add(":var35", NpgsqlTypes.NpgsqlDbType.Double).Value         = obj.var35;
                            cmd.Parameters.Add(":var35_status", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.var35_status;

                            cmd.Parameters.Add(":stored_date", NpgsqlTypes.NpgsqlDbType.Date).Value      = obj.stored_date;
                            cmd.Parameters.Add(":stored_hour", NpgsqlTypes.NpgsqlDbType.Integer).Value   = obj.stored_hour;
                            cmd.Parameters.Add(":stored_minute", NpgsqlTypes.NpgsqlDbType.Integer).Value = obj.stored_minute;
                            cmd.Parameters.Add(":MPS_status", NpgsqlTypes.NpgsqlDbType.Integer).Value    = obj.MPS_status;
                            cmd.Parameters.Add(":created", NpgsqlTypes.NpgsqlDbType.Timestamp).Value     = obj.created;

                            cmd.Parameters.Add(":push", NpgsqlTypes.NpgsqlDbType.Integer).Value        = obj.push;
                            cmd.Parameters.Add(":push_time", NpgsqlTypes.NpgsqlDbType.Timestamp).Value = obj.push_time;

                            //cmd.ExecuteNonQuery();
                            ID     = (Int32)cmd.ExecuteScalar();
                            obj.id = ID;

                            db.close_connection();
                            return(ID);
                        }
                    }
                    else
                    {
                        db.close_connection();
                        return(-1);
                    }
                }
                catch (Exception e)
                {
                    if (db != null)
                    {
                        db.close_connection();
                    }
                    return(-1);
                }
                finally
                {
                    db.close_connection();
                }
            }
        }