Beispiel #1
0
        /// <summary>
        /// Loads <see cref="VendorDevice"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="keys">Keys of the Measurement to be loaded from the database</param>
        /// <returns>Collection of <see cref="VendorDevice"/>.</returns>
        public static ObservableCollection <VendorDevice> Load(AdoDataConnection database, IList <int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string query;
                string commaSeparatedKeys;

                VendorDevice[] vendorDeviceList = null;
                DataTable      vendorDeviceTable;
                int            id;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => key.ToString()).Aggregate((str1, str2) => str1 + "," + str2);
                    query             = string.Format("SELECT * FROM VendorDeviceDetail WHERE ID IN ({0})", commaSeparatedKeys);
                    vendorDeviceTable = database.Connection.RetrieveData(database.AdapterType, query);
                    vendorDeviceList  = new VendorDevice[vendorDeviceTable.Rows.Count];

                    foreach (DataRow row in vendorDeviceTable.Rows)
                    {
                        id = row.ConvertField <int>("ID");

                        vendorDeviceList[keys.IndexOf(id)] = new VendorDevice()
                        {
                            ID           = id,
                            VendorID     = row.ConvertField <int>("VendorID"),
                            Name         = row.Field <string>("Name"),
                            Description  = row.Field <string>("Description"),
                            URL          = row.Field <string>("URL"),
                            m_vendorName = row.Field <string>("VendorName")
                        };
                    }
                }

                return(new ObservableCollection <VendorDevice>(vendorDeviceList ?? new VendorDevice[0]));
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Saves <see cref="VendorDevice"/> information to database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="vendorDevice">Information about <see cref="VendorDevice"/>.</param>
        /// <returns>String, for display use, indicating success.</returns>
        public static string Save(AdoDataConnection database, VendorDevice vendorDevice)
        {
            bool   createdConnection = false;
            string query;

            try
            {
                createdConnection = CreateConnection(ref database);

                if (vendorDevice.ID == 0)
                {
                    query = database.ParameterizedQueryString("INSERT INTO VendorDevice (VendorID, Name, Description, URL, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                                                              "Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", "vendorID", "name", "description", "url", "updatedBy", "updatedOn", "createdBy", "createdOn");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, vendorDevice.VendorID, vendorDevice.Name, vendorDevice.Description.ToNotNull(),
                                                        vendorDevice.URL.ToNotNull(), CommonFunctions.CurrentUser, database.UtcNow, CommonFunctions.CurrentUser, database.UtcNow);
                }
                else
                {
                    query = database.ParameterizedQueryString("UPDATE VendorDevice SET VendorID = {0}, Name = {1}, Description = {2}, URL = {3}, UpdatedBy = {4}, " +
                                                              "UpdatedOn = {5} WHERE ID = {6}", "vendorID", "name", "description", "url", "updatedBy", "updatedOn", "id");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, vendorDevice.VendorID, vendorDevice.Name, vendorDevice.Description.ToNotNull(),
                                                        vendorDevice.URL.ToNotNull(), CommonFunctions.CurrentUser, database.UtcNow, vendorDevice.ID);
                }

                return("Vendor Device information saved successfully");
            }
            finally
            {
                if (createdConnection && database != null)
                {
                    database.Dispose();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Saves <see cref="VendorDevice"/> information to database.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="vendorDevice">Information about <see cref="VendorDevice"/>.</param>        
        /// <returns>String, for display use, indicating success.</returns>
        public static string Save(AdoDataConnection database, VendorDevice vendorDevice)
        {
            bool createdConnection = false;
            string query;

            try
            {
                createdConnection = CreateConnection(ref database);

                if (vendorDevice.ID == 0)
                {
                    query = database.ParameterizedQueryString("INSERT INTO VendorDevice (VendorID, Name, Description, URL, UpdatedBy, UpdatedOn, CreatedBy, CreatedOn) " +
                        "Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7})", "vendorID", "name", "description", "url", "updatedBy", "updatedOn", "createdBy", "createdOn");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, vendorDevice.VendorID, vendorDevice.Name, vendorDevice.Description.ToNotNull(),
                        vendorDevice.URL.ToNotNull(), CommonFunctions.CurrentUser, database.UtcNow, CommonFunctions.CurrentUser, database.UtcNow);
                }
                else
                {
                    query = database.ParameterizedQueryString("UPDATE VendorDevice SET VendorID = {0}, Name = {1}, Description = {2}, URL = {3}, UpdatedBy = {4}, " +
                        "UpdatedOn = {5} WHERE ID = {6}", "vendorID", "name", "description", "url", "updatedBy", "updatedOn", "id");

                    database.Connection.ExecuteNonQuery(query, DefaultTimeout, vendorDevice.VendorID, vendorDevice.Name, vendorDevice.Description.ToNotNull(),
                        vendorDevice.URL.ToNotNull(), CommonFunctions.CurrentUser, database.UtcNow, vendorDevice.ID);
                }

                return "Vendor Device information saved successfully";
            }
            finally
            {


                if (createdConnection && database != null)
                    database.Dispose();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Loads <see cref="VendorDevice"/> information as an <see cref="ObservableCollection{T}"/> style list.
        /// </summary>
        /// <param name="database"><see cref="AdoDataConnection"/> to connection to database.</param>
        /// <param name="keys">Keys of the Measurement to be loaded from the database</param>
        /// <returns>Collection of <see cref="VendorDevice"/>.</returns>
        public static ObservableCollection<VendorDevice> Load(AdoDataConnection database, IList<int> keys)
        {
            bool createdConnection = false;

            try
            {
                createdConnection = CreateConnection(ref database);

                string query;
                string commaSeparatedKeys;

                VendorDevice[] vendorDeviceList = null;
                DataTable vendorDeviceTable;
                int id;

                if ((object)keys != null && keys.Count > 0)
                {
                    commaSeparatedKeys = keys.Select(key => key.ToString()).Aggregate((str1, str2) => str1 + "," + str2);
                    query = string.Format("SELECT * FROM VendorDeviceDetail WHERE ID IN ({0})", commaSeparatedKeys);
                    vendorDeviceTable = database.Connection.RetrieveData(database.AdapterType, query);
                    vendorDeviceList = new VendorDevice[vendorDeviceTable.Rows.Count];

                    foreach (DataRow row in vendorDeviceTable.Rows)
                    {
                        id = row.ConvertField<int>("ID");

                        vendorDeviceList[keys.IndexOf(id)] = new VendorDevice()
                        {
                            ID = id,
                            VendorID = row.ConvertField<int>("VendorID"),
                            Name = row.Field<string>("Name"),
                            Description = row.Field<string>("Description"),
                            URL = row.Field<string>("URL"),
                            m_vendorName = row.Field<string>("VendorName")
                        };
                    }
                }

                return new ObservableCollection<VendorDevice>(vendorDeviceList ?? new VendorDevice[0]);
            }
            finally
            {
                if (createdConnection && database != null)
                    database.Dispose();
            }
        }