Exemplo n.º 1
0
        public void Copy_to_clipboard()
        {
            var grid = new DataGrid {
                CanUserAddRows = false,
                Columns        =
                {
                    new DataGridTextColumn {
                        Binding = new Binding("ProductSynonym"),
                        Header  = "Наименование",
                    },
                    new DataGridTextColumn {
                        Binding = new Binding("Cost"),
                        Header  = "Цена"
                    }
                }
            };

            grid.ItemsSource = new List <Offer> {
                new Offer(new Price("тест"), 100)
                {
                    ProductSynonym = "Тестовый продукт"
                },
                new Offer(new Price("тест"), 150)
                {
                    ProductSynonym = "Тестовый продукт 2"
                },
            };
            Persistable.CopyToClipboard(grid);
            var content = Clipboard.GetText();

            Assert.AreEqual("Наименование\tЦена\r\nТестовый продукт\t100\r\nТестовый продукт 2\t150\r\n", content);
        }
 public override void Merge(Persistable another)
 {
     CreationDate = ((Contract)another).CreationDate;
     Description = ((Contract)another).Description;
     Value = ((Contract)another).Value;
     IsCounted = ((Contract)another).IsCounted;
 }
Exemplo n.º 3
0
        private void DeleteClick(object sender, EventArgs e)
        {
            TableUtility tableUtility   = new TableUtility();
            Persistable  objectToDelete = currentDataGridView.Rows[currentRowIndex].DataBoundItem as Persistable;

            currentDataGridView.Rows.RemoveAt(currentRowIndex);
            tableUtility.DeleteTableRow(objectToDelete);
        }
Exemplo n.º 4
0
        private void DeleteClick(object sender, EventArgs e)
        {
            TableUtility tableUtility   = new TableUtility(Globals.WatchdogAddIn.Application.ActiveWorkbook);
            Persistable  objectToDelete = currentDataGridView.Rows[currentRowIndex].DataBoundItem as Persistable;

            currentDataGridView.Rows.RemoveAt(currentRowIndex);
            tableUtility.DeleteTableRow(objectToDelete, objectToDelete.GetIndex());
        }
        public void Register(Persistable obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            mObjects.AddOrUpdate(new StringKey(obj.Key), obj);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Binds an <see cref="Persistable"/> object to a <see cref="Control"/>
 /// </summary>
 /// <param name="control">Control to be bound</param>
 /// <param name="bindingObject">Object to bind</param>
 /// <returns>Control with bound object</returns>
 public static Control BindObjectToControl(Control control, Persistable bindingObject)
 {
     if (bindingObject != null)
     {
         Binding binding = new Binding(string.Empty, bindingObject, string.Empty);
         control.DataBindings.Add(binding);
     }
     return(control);
 }
 public override void Merge(Persistable another)
 {
     CreationDate = ((WorkRecord)another).CreationDate;
     HourlyRate = ((WorkRecord)another).HourlyRate;
     MinutesWorked = ((WorkRecord)another).MinutesWorked;
     WorkStartDate = ((WorkRecord)another).WorkStartDate;
     Description = ((WorkRecord)another).Description;
     IsBonus = ((WorkRecord)another).IsBonus;
 }
        private void DeleteFundClick(object sender, EventArgs e)
        {
            TableUtility    tableUtility   = new TableUtility();
            DataGridViewRow selectedRow    = dataGridFunds.SelectedRows[0];
            Persistable     objectToDelete = selectedRow.DataBoundItem as Persistable;

            dataGridFunds.Rows.RemoveAt(selectedRow.Index);
            tableUtility.DeleteTableRow(objectToDelete);
        }
Exemplo n.º 9
0
 public Workbook CreateMissingTable(Persistable persistable)
 {
     if (FindWorksheet(persistable.GetTableName()) != null)
     {
         return(workbook);
     }
     CreateWorksheet(persistable);
     InsertRowCounter(persistable);
     return(workbook);
 }
Exemplo n.º 10
0
 /// <summary>
 /// Checks if the class of the passed object is a subclass.
 /// </summary>
 /// <param name="persistable"><see cref="Persistable"/> default object</param>
 /// <returns>If subclass, then it returns the table name, else an empty string</returns>
 private string IsJoinedTable(Persistable persistable)
 {
     if (Attribute.GetCustomAttribute(persistable.GetType(), typeof(JoinedTable), false) is JoinedTable attribute)
     {
         if (persistable.GetType().IsGenericType)
         {
             return(persistable.GetTableName());
         }
         return(attribute.Name);
     }
     return("");
 }
Exemplo n.º 11
0
 /// <summary>
 /// Gets object type based on the table name.
 /// The table names will be cross checked with a subset of types.
 /// </summary>
 /// <param name="types">Types for cross check</param>
 /// <param name="tableName">Table name</param>
 /// <returns>Found type</returns>
 private Type GetTypeByTableName(Type[] types, string tableName)
 {
     foreach (Type type in types)
     {
         Persistable persistable  = Activator.CreateInstance(type) as Persistable;
         string      objTableName = IsJoinedTable(persistable);
         if (objTableName.Equals(tableName))
         {
             return(type);
         }
     }
     return(null);
 }
Exemplo n.º 12
0
        private int InsertRowCounter(Persistable persistable)
        {
            Worksheet ws = FindWorksheet(sequenceTableName);

            if (ws == null)
            {
                ws = CreateSequenceTable();
            }
            int emptyColumn = FindFirstEmtpyColumn(sequenceTableName);

            ws.Cells[1, emptyColumn].Value = persistable.GetTableName();
            ws.Cells[2, emptyColumn].Value = 1;
            return(emptyColumn);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets a list of properties, which are marked with the specified attribute.
        /// </summary>
        /// <param name="persistable">Object to check (can be default object)</param>
        /// <param name="attributeType">Type of the marking attribute</param>
        /// <returns></returns>
        private List <PropertyInfo> GetPropertiesByAttribute(Persistable persistable, Type attributeType)
        {
            PropertyInfo[]      properties           = persistable.GetType().GetProperties();
            List <PropertyInfo> multiValueProperties = new List <PropertyInfo>();

            foreach (PropertyInfo property in properties)
            {
                if (property.GetCustomAttributes(attributeType, false).Length != 0)
                {
                    multiValueProperties.Add(property);
                }
            }
            return(multiValueProperties);
        }
Exemplo n.º 14
0
 public virtual void write(Persistable p)
 {
     lock (wrapper)
     {
         wrapper.Data = p;
         if (wrapper is IMetaData)
         {
             storage.write(new FauxIndexedPersistable(p, wrapper, (IMetaData)wrapper));
         }
         else
         {
             storage.write(new FauxIndexedPersistable(p, wrapper));
         }
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Refreshes an table row with the actual object data.
        /// </summary>
        /// <param name="persistable">Persisted object</param>
        /// <param name="row">Row with the new data</param>
        /// <returns><code>True</code> if update is successful, else <code>false</code></returns>
        private bool ReplaceRange(Persistable persistable, Range row)
        {
            string tableName = IsJoinedTable(persistable);

            if (tableName == "")
            {
                tableName = persistable.GetTableName();
            }
            if (row.Worksheet.Name != tableName)
            {
                return(false);
            }
            int colCounter = 2;
            List <PropertyInfo> properties = SortPersistableFieldList(GetPropertiesByAttribute(persistable, typeof(PersistableField)));

            foreach (PropertyInfo property in properties)
            {
                Type propertyType = property.PropertyType;
                if (!propertyType.IsPrimitive && propertyType != typeof(string) && !propertyType.IsEnum)
                {
                    MultiValue multiValueProperty = property.GetCustomAttribute <MultiValue>();
                    if (multiValueProperty != null)
                    {
                        var    items   = property.GetValue(persistable);
                        string content = "";
                        foreach (Persistable item in items as IEnumerable <Persistable> )
                        {
                            if (item.GetIndex() != 0)
                            {
                                content += item.GetIndex() + ";";
                            }
                        }
                        row.Cells[1, colCounter].Value = content;
                    }
                    else
                    {
                        Persistable nestedObject = property.GetValue(persistable) as Persistable;
                        row.Cells[1, colCounter].Value = nestedObject.GetIndex();
                    }
                }
                else
                {
                    row.Cells[1, colCounter].Value = property.GetValue(persistable);
                }
                colCounter++;
            }
            return(true);
        }
Exemplo n.º 16
0
        private double ChangeRowCounter(Persistable persistable, bool decrement)
        {
            int       column  = FindOrCreateRowCounterColumn(persistable);
            Worksheet ws      = FindWorksheet(sequenceTableName);
            double    counter = ws.Cells[2, column].Value;

            if (decrement)
            {
                counter--;
            }
            else
            {
                counter++;
            }
            ws.Cells[2, column].Value = counter;
            return(counter);
        }
Exemplo n.º 17
0
        public bool Save()
        {
            try
            {
                var persistable = Persistable.ToArray();

                if (string.IsNullOrWhiteSpace(ToolboxApp.Project.State.ProjectFolder))
                {
                    OnRecreateMenuItems(new RecreateMenuItemsEventArgs(persistable));
                    return(false);
                }

                var proj   = new XenProjectFile(_fs);
                var loaded = proj.Load(ToolboxApp.Project.State.XenProjectFilePath);

                if (!loaded)
                {
                    ToolboxApp.Log.Info($"Creating new project file: {ToolboxApp.Project.State.XenProjectFilePath}.");
                    proj.Schema = XenFormsEnvironment.ProjectFileSchema;
                }

                proj.Views = persistable;
                proj.Save(ToolboxApp.Project.State.XenProjectFilePath);

                foreach (var pv in proj.Views)
                {
                    pv.Persisted = true;
                }

                OnRecreateMenuItems(new RecreateMenuItemsEventArgs(proj.Views));
                return(true);
            }
            catch (Exception ex)
            {
                ToolboxApp.Log.Error(ex, $"Error saving file: {ToolboxApp.Project.State.XenProjectFilePath}.");

                MessageBox.Show(Application.Instance.MainForm,
                                "There was an error saving the project file. Please check the log for more information.",
                                "XenForms",
                                MessageBoxButtons.OK,
                                MessageBoxType.Error);

                return(false);
            }
        }
        public void CollectionPerformanceTest() {

            var p = new Persistable<People>(Path);
            Stopwatch watch = new Stopwatch();

            watch.Start();
            for (int i = 0; i < 1000; i++) {
                p.Value.Persons.Add(new Person {
                    FirstName = "Velio",
                    LastName = "Ivanov",
                    Age = 40
                });
                p.Save();
            }
            watch.Stop();

            Console.Out.WriteLine(string.Format("Time elapsed: {0}", watch.Elapsed));
        }
        private Label GenerateLabel(string text, Persistable bindingObject)
        {
            Padding padding = Padding.Empty;
            Padding margin  = new Padding(1, 0, 0, 1);
            Label   label   = new Label
            {
                Text      = text,
                Width     = 150,
                Height    = 50,
                Margin    = margin,
                Padding   = padding,
                BackColor = Color.White,
                TextAlign = ContentAlignment.MiddleRight,
                Font      = new Font(Font, Font.Style | FontStyle.Bold)
            };

            FormUtility.BindObjectToControl(label, bindingObject);
            return(label);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Checks if there is already an exisiting table (<see cref="Worksheet"/>) according to the object, which needs to persisted.
        /// If not, a table will be created.
        /// </summary>
        /// <param name="persistable"><see cref="Persistable"/> default object</param>
        public void CreateTable(Persistable persistable)
        {
            string    joinedTable = IsJoinedTable(persistable);
            Worksheet ws;

            if (joinedTable != "")
            {
                ws = FindWorksheet(joinedTable);
            }
            else
            {
                ws = FindWorksheet(persistable.GetTableName());
            }
            if (ws != null)
            {
                return;
            }
            CreateTableWorksheet(persistable);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Persists a new object.
        /// The index will be set as well.
        /// </summary>
        /// <param name="persistable">Object to be persisted</param>
        /// <returns>Index of the object</returns>
        public double InsertTableRow(Persistable persistable)
        {
            string tableName = IsJoinedTable(persistable);

            if (tableName == "")
            {
                tableName = persistable.GetTableName();
            }
            double row      = ChangeRowCounter(tableName, false);
            double sequence = IncrementSequence();

            persistable.SetIndex(sequence);
            Worksheet ws = FindWorksheet(tableName);

            ws.Cells[row, 1].Value = sequence;
            Range rowToInsert = ws.Rows[row];

            ReplaceRange(persistable, rowToInsert);
            return(sequence);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Gets the table row of the specified object based on its index.
        /// </summary>
        /// <param name="persistable"><see cref="Persistable"/> object</param>
        /// <returns>Table row</returns>
        public Range ReadTableRow(Persistable persistable)
        {
            string    joinedTable = IsJoinedTable(persistable);
            Worksheet worksheet;

            if (joinedTable != "")
            {
                worksheet = FindWorksheet(joinedTable);
            }
            else
            {
                worksheet = FindWorksheet(persistable.GetTableName());
            }
            int rowIndex = BinarySearchTable(persistable);

            if (rowIndex < 0)
            {
                return(null);
            }
            return(worksheet.UsedRange.Rows[rowIndex]);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Gets all the rows of a certain table.
        /// If the type is a base class, the tables of the subclasses will also
        /// be taken into account.
        /// </summary>
        /// <param name="persistable"><see cref="Persistable"/> object</param>
        /// <returns>List of all ranges</returns>
        public List <Range> ReadAllRows(Persistable persistable)
        {
            List <Range> searchResult           = new List <Range>();
            bool         isJoinedTableBaseClass = IsJoinedTableBaseClass(persistable.GetType());

            if (isJoinedTableBaseClass)
            {
                Type[] derivedTypes = JoinedTableBaseClassGetSubClasses(persistable.GetType());
                foreach (Type derivedType in derivedTypes)
                {
                    List <Range> subList = ReadAllRows(GetDefaultObject(derivedType));
                    searchResult.AddRange(subList);
                }
            }

            string    joinedTable = IsJoinedTable(persistable);
            Worksheet worksheet;

            if (joinedTable != "")
            {
                worksheet = FindWorksheet(joinedTable);
            }
            else
            {
                worksheet = FindWorksheet(persistable.GetTableName());
            }
            if (worksheet == null)
            {
                return(searchResult);
            }
            Range rows = worksheet.UsedRange.Rows;

            for (int index = 2; index < rows.Count + 1; index++)
            {
                searchResult.Add(rows[index]);
            }
            return(searchResult);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Binary search implementation for finding the table row based on the object index.
        /// </summary>
        /// <param name="persistable"></param>
        /// <returns></returns>
        private int BinarySearchTable(Persistable persistable)
        {
            string    joinedTable = IsJoinedTable(persistable);
            Worksheet worksheet;

            if (joinedTable != "")
            {
                worksheet = FindWorksheet(joinedTable);
            }
            else
            {
                worksheet = FindWorksheet(persistable.GetTableName());
            }

            Range  firstColumn = worksheet.UsedRange.Columns[1];
            int    left = 2, right = firstColumn.Cells.Count, mid;
            double target = persistable.GetIndex();

            while (left <= right)
            {
                mid = left + (right - left) / 2;
                double cellValue = worksheet.Cells[mid, 1].Value;
                if (target == cellValue)
                {
                    return(mid);
                }
                if (target < cellValue)
                {
                    right = mid - 1;
                }
                else
                {
                    left = mid + 1;
                }
            }
            return(-1);
        }
Exemplo n.º 25
0
        private int FindOrCreateRowCounterColumn(Persistable persistable)
        {
            Worksheet ws = FindWorksheet(sequenceTableName);

            if (ws == null)
            {
                CreateSequenceTable();
                return(InsertRowCounter(persistable));
            }
            int c = 1;

            while (true)
            {
                if (persistable.GetTableName().Equals(ws.Cells[1, c].Value))
                {
                    return(c);
                }
                if (ws.Cells[1, c].Value == null)
                {
                    return(-1);
                }
                c++;
            }
        }
Exemplo n.º 26
0
        public Workbook InsertTableRow(Persistable persistable, List <string> data)
        {
            if (data.Count != persistable.GetTableHeader().Count)
            {
                throw new ArgumentException("The data row's length does not match the the number of table columns.");
            }
            Worksheet ws = FindWorksheet(persistable.GetTableName());

            if (ws == null)
            {
                MessageBox.Show("Tabelle existiert nicht.");
                return(workbook);
            }
            double row      = ChangeRowCounter(persistable, false);
            double sequence = IncrementSequence();

            ws.Cells[row, 1].Value = sequence;
            persistable.SetIndex(sequence);
            for (int i = 0; i < data.Count; i++)
            {
                ws.Cells[row, i + 2].Value = data[i];
            }
            return(workbook);
        }
Exemplo n.º 27
0
 public override void Merge(Persistable another)
 {
     PasswordHash = ((User)another).PasswordHash;
     Roles = ((User)another).Roles;
 }
Exemplo n.º 28
0
 public void remove(Persistable p)
 {
     storage.remove(p);
 }
 public override void Merge(Persistable another)
 {
     HourlyRate = ((EmployeeDescription)another).HourlyRate;
     SumMinutesWorked = ((EmployeeDescription)another).SumMinutesWorked;
 }
 public override void Merge(Persistable another)
 {
     Login = ((PublicUserInfo)another).Login;
     Name = ((PublicUserInfo)another).Name;
     Surname = ((PublicUserInfo)another).Surname;
 }
Exemplo n.º 31
0
 public override void Merge(Persistable other)
 {
     Date = ((Summary)other).Date;
     MinutesWorked = ((Summary)other).MinutesWorked;
     MoneyWorked = ((Summary)other).MoneyWorked;
 }
Exemplo n.º 32
0
 public FauxIndexedPersistable(Persistable p, WrappingStorageUtility.SerializationWrapper w)
 {
     this.p = p;
     this.w = w;
     this.m = null;
 }
Exemplo n.º 33
0
 public FauxIndexedPersistable(Persistable p, WrappingStorageUtility.SerializationWrapper w, IMetaData m)
 {
     this.p = p;
     this.w = w;
     this.m = m;
 }
Exemplo n.º 34
0
        /// <summary>
        /// Searches a table row with search parameters.
        /// The search parameters have to passed with a dictionary. The keys are the
        /// column names and the values are the search parameters.
        /// </summary>
        /// <param name="persistable"><see cref="Persistable"/>object (to get to the correct table)</param>
        /// <param name="searchParameters">Search parameters</param>
        /// <param name="queryOperator"><see cref="QueryOperator"/></param>
        /// <returns>List with found rows</returns>
        public List <Range> ReadTableRow(Persistable persistable, Dictionary <string, string> searchParameters, QueryOperator queryOperator)
        {
            List <Range> searchResult = new List <Range>();
            Worksheet    worksheet;
            string       joinedTable = IsJoinedTable(persistable);

            if (joinedTable != "")
            {
                worksheet = FindWorksheet(joinedTable);
            }
            else
            {
                worksheet = FindWorksheet(persistable.GetTableName());
            }
            List <string> searchKeys = searchParameters.Keys.ToList();
            Dictionary <string, double> columnIndizes = new Dictionary <string, double>();

            foreach (string key in searchKeys)
            {
                double col = FindColumn(worksheet, key);
                columnIndizes.Add(key, col);
            }

            foreach (Range row in worksheet.UsedRange.Rows)
            {
                foreach (string key in columnIndizes.Keys.ToList())
                {
                    Range rowCell = row.Cells[1, columnIndizes[key]];
                    if (rowCell.Value == null)
                    {
                        break;
                    }
                    string cellValue      = rowCell.Value.ToString();
                    bool   breakIteration = false;
                    bool   rowFound       = false;
                    switch (queryOperator)
                    {
                    case QueryOperator.AND:
                        if (!cellValue.Equals(searchParameters[key]))
                        {
                            breakIteration = true;
                        }
                        rowFound = true;
                        break;

                    case QueryOperator.OR:
                        if (cellValue.Equals(searchParameters[key]))
                        {
                            searchResult.Add(row);
                            breakIteration = true;
                        }
                        break;
                    }
                    if (breakIteration)
                    {
                        break;
                    }
                    if (rowFound)
                    {
                        searchResult.Add(row);
                        break;
                    }
                }
            }
            return(searchResult);
        }
Exemplo n.º 35
0
        /// <summary>
        /// Creates an instance of the specified type.
        /// </summary>
        /// <param name="type">Type</param>
        /// <returns>Object of type <see cref="Persistable"/></returns>
        private Persistable GetDefaultObject(Type type)
        {
            Persistable persistable = Activator.CreateInstance(type) as Persistable;

            return(persistable);
        }