Beispiel #1
0
        /// <summary>
        /// Deletes the property and value given the property name specified.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        public bool Delete <T>(string propertyName)
        {
            lock (_lock)
            {
                if (PropertyNameList.Contains(propertyName) &&
                    PropertyNameList[propertyName].DataType == typeof(T))
                {
                    PropertyNameList.Remove(propertyName);
                    IsDirty = true;

                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Stores the new value for the names property. If the property does not exist in the blob
        /// a new column will be created. Property names are case insensitive.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propName"></param>
        /// <param name="value"></param>
        public void Set <T>(string propertyName, T value)
        {
            lock (_lock)
            {
                if (!PropertyNameList.Contains(propertyName))
                {
                    PropertyNameList.Add(propertyName, typeof(T));
                }

                ItemColumn column = PropertyNameList[propertyName];
                PropertyValueList.Insert(PropertyNameList.IndexOf(column), value);

                IsDirty = true;

                RaisePropertyChanged(propertyName);
            }
        }
Beispiel #3
0
 private void pname_TextChanged(object sender, EventArgs e)
 {
     if (pname.Text != "" && pname.SelectedItem == null)
     {
         string strSQL = "Select ID,Address from Place where Address like '" + pname.Text + "%'";
         PropertyNameList.Items.Clear();
         PropertyNameList.BringToFront();
         //Customer.SendToBack();
         using (OleDbConnection connection = new OleDbConnection(connectionString))
         {
             OleDbCommand command = new OleDbCommand(strSQL, connection);
             try
             {
                 connection.Open();
                 using (OleDbDataReader reader = command.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         PropertyNameList.Items.Add(reader[0].ToString() + "-" + reader[1].ToString());
                     }
                     if (reader.HasRows)
                     {
                         PropertyNameList.Visible = true;
                     }
                     else
                     {
                         PropertyNameList.Visible = false;
                     }
                 }
                 connection.Close();
             }
             catch (Exception ex)
             {
                 // MessageBox.Show(ex.Message);
             }
         }
     }
     else
     {
         CustomerNameslist.Visible = false;
     }
 }
Beispiel #4
0
        /// <summary>
        /// Get the current value of a property. If the property does not exist, the default value
        /// for the type will be returned and the function returns FALSE. Property names are
        /// case insensitive.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Get <T>(string propertyName, out T value)
        {
            lock (_lock)
            {
                value = default(T);

                if (PropertyNameList.Contains(propertyName) &&
                    PropertyNameList[propertyName].DataType == typeof(T))
                {
                    ItemColumn column = PropertyNameList[propertyName];
                    int        index  = PropertyNameList.IndexOf(column);

                    value = (T)PropertyValueList[index];

                    return(true);
                }
            }

            return(false);
        }
Beispiel #5
0
        public void JsonDeserialize(string json)
        {
            lock (_lock)
            {
                try
                {
                    PropertyBag newBag = (PropertyBag)JsonConvert.DeserializeObject <PropertyBag>(json);
                    this.PropertyValueList = newBag.PropertyValueList;
                    this.PropertyNameList  = newBag.PropertyNameList;

                    // Setup the rollback data
                    this.RollbackPropertyValueList = new List <object>(this.PropertyValueList);
                    this.RollbackPropertyNameList  = new ItemColumnCollection();
                    foreach (ItemColumn column in this.PropertyNameList)
                    {
                        this.RollbackPropertyNameList.Add(new ItemColumn(column.ColumnName, column.DataType));
                    }

                    foreach (ItemColumn column in PropertyNameList)
                    {
                        int index = PropertyNameList.IndexOf(column);

                        // We may have arrived here as a result of serialization/deserialization.
                        // Coerce some types back into their correct type and assignment them
                        // back to the blob so they have the right type on output.
                        if (column.DataType == typeof(Int32))
                        {
                            Int32 result = Convert.ToInt32(PropertyValueList[index]);
                            PropertyValueList[index] = result;
                        }
                        else if (column.DataType == typeof(Int64))
                        {
                            Int64 result = Convert.ToInt64(PropertyValueList[index]);
                            PropertyValueList[index] = result;
                        }
                        else if (column.DataType == typeof(double))
                        {
                            double result = Convert.ToDouble(PropertyValueList[index]);
                            PropertyValueList[index] = result;
                        }
                        else if (column.DataType == typeof(float))
                        {
                            float result = Convert.ToSingle(PropertyValueList[index]);
                            PropertyValueList[index] = result;
                        }
                        else if (column.DataType == typeof(Guid))
                        {
                            Guid result = Guid.Parse((string)PropertyValueList[index]);
                            PropertyValueList[index] = result;
                        }
                    }

                    IsDirty = false;

                    foreach (ItemColumn column in PropertyNameList)
                    {
                        RaisePropertyChanged(column.ColumnName);
                    }
                }
                catch
                {
                    PropertyNameList.Clear();
                    PropertyValueList.Clear();
                }
            }
        }