コード例 #1
0
        public Logic(Config cnf, string action, string result)
        {
            if (action == null)
            {
                throw new ArgumentNullException();
            }

            //Исправлено везде сравнение строк с помощью string.equals
            if (action.Equals("Open"))
            {
                DataBaseReader reader = new DataBaseReader();
                Questions = new List <Question>();
                foreach (var q in reader.GetQuestion(cnf.DataPath))
                {
                    Questions.Add(new Question()
                    {
                        id       = q.id,
                        question = q.question,
                        answerA  = q.answerA,
                        answerB  = q.answerB
                    });
                }
            }
            if (action.Equals("Result"))
            {
                DataBaseReader reader = new DataBaseReader();
                Result = new Result();
                Result = reader.GetResult(cnf.DataPath, result);
            }
        }
コード例 #2
0
        private void RelatedListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            var link = sender as LinkButton;

            RelatedListView.SelectedIndex = Convert.ToInt32(link.CommandArgument);

            var row = RelatedListView.SelectedRow;

            var titles = new StringBuilder();

            for (int i = 2; i < row.Cells.Count; i++)
            {
                titles.Append(row.Cells[i].Text).Append(" ~ ");
            }



            var constrName = OpenedRelation.SystemName;

            OpenedRelation.Card.DependencyRelations.RelationTableTitleAttributes[constrName] = titles.ToString();


            OpenedRelation.Value = titles.ToString();

            DataBaseReader.FillRelation(OpenedRelation, Convert.ToInt32(RelatedListView.SelectedDataKey["objID"]));

            DisplayRelatedList = false;

            OpenedRelationSystemName = null;

            RecreateChildControls();
        }
コード例 #3
0
 /// <summary>
 /// Assign the private members the values read from the database file header. I.e. Next primary key, row count, number of rows deleted.
 /// </summary>
 private void AssignHeaderVariables()
 {
     DataBaseStream.Position = HEADER_INFO_NEXT_PRIMARY_KEY;
     NextPrimaryKey          = DataBaseReader.ReadInt32();
     RowCount        = DataBaseReader.ReadInt32();
     DeletedRowCount = DataBaseReader.ReadInt32();
 }
コード例 #4
0
        /// <summary>
        /// Get the rows that match the primary keys in <param name="primaryKeys">.
        /// </summary>
        /// <param name="primaryKeys">
        /// A list of <see cref="int"/> representing the primary keys of the rows to get.
        /// </param>
        public List <Row> GetRows(List <int> primaryKeys)
        {
            List <Row> result = new List <Row> ();

            foreach (int i in primaryKeys)
            {
                // If the index contains the primary key
                if (Index.ContainsKey(i))
                {
                    // Set the database stream to the location of the row
                    DataBaseStream.Position = (Index [i] - 1) * ROW_BYTE_SIZE + HEADER_BYTE_SIZE;
                    Row toReturn = new Row();
                    // Assign the row values to a row.
                    toReturn.Status        = DataBaseReader.ReadBoolean();
                    toReturn.PrimaryKey    = DataBaseReader.ReadInt32();
                    toReturn.TextData      = new string (DataBaseReader.ReadChars(20));
                    toReturn.NumberData    = DataBaseReader.ReadSingle();
                    toReturn.NewTextData   = toReturn.TextData;
                    toReturn.NewNumberData = toReturn.NumberData;
                    toReturn.Action        = Row.RowAction.Stable;
                    // If the row hasn't been deleted, add it to the list of rows to return.
                    if (toReturn.Status)
                    {
                        result.Add(toReturn);
                    }
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: events.cs プロジェクト: KeyEugene/ProjectMonitoring
        private void RelationClearedButton_Click(object sender, EventArgs e)
        {
            if (sender is IButtonControl)
            {
                var constraintName = (sender as IButtonControl).CommandArgument;

                OpenedRelationSystemName = constraintName;

                foreach (var card in Cards.Values)
                {
                    SaveState(card);
                }
                OpenedRelationEntityID = (sender as IButtonControl).CommandName;

                DataBaseReader.GetRelations(OpenedRelation);

                OpenedRelation.Card.DependencyRelations.RelationTableTitleAttributes[constraintName] = "";

                OpenedRelation.Value = "";

                DataBaseReader.FillRelation(OpenedRelation, -1);

                OpenedRelationSystemName = null;

                OpenedRelationEntityID = null;

                RecreateChildControls();
            }

            RecreateChildControls();
        }
コード例 #6
0
 /// <summary>
 /// Print the table header information to the console.
 /// </summary>
 public void PrintHeader()
 {
     DataBaseStream.Position = 0;
     Console.WriteLine(DataBaseReader.ReadChars(20));
     Console.WriteLine(DataBaseReader.ReadInt32());
     Console.WriteLine(DataBaseReader.ReadInt32());
     Console.WriteLine(DataBaseReader.ReadInt32());
 }
コード例 #7
0
        public void DataBaseReaderTestCotrShouldSetLanguageType()
        {
            //Assign
            int langType = 1;
            //Act
            var dBReader = new DataBaseReader(langType);

            //Assert
            Assert.IsNotNull(dBReader._languageType);
        }
コード例 #8
0
        public void ReaderFactoryTestShouldCreateDBReader()
        {
            //Assign
            var         languageType  = 1;
            var         readerFactory = new ReaderFactory(languageType);
            IDataReader dataReader    = new DataBaseReader(languageType);

            //Act
            var DataReader = readerFactory.ReadFromDb();

            //Assert
            Assert.IsInstanceOfType(DataReader, dataReader.GetType());
        }
コード例 #9
0
        /// <summary>
        /// Compact and resize both the database and database index file by overwriting rows that are marked as deleted
        /// with rows that are not marked as deleted and finally resizing the files appropriately.
        /// </summary>
        public void CompactDatabase()
        {
            // Location of the deleted row that will be overwritten.
            int locationToMoveTo;
            // The number of rows before compacting.
            int initialNumberOfRows = RowCount;
            // The location of the next row to check to see if it is not marked as deleted.
            int locationOfNextRowToCheck = RowCount;
            // Dictionary used to represent the new data in the database and the index file.
            Dictionary <Row, int> newIndex = new Dictionary <Row, int> ();

            // Search from the top to find a row that is marked as deleted.
            for (int i = 0; i < initialNumberOfRows; i++)
            {
                DataBaseStream.Position = (i * ROW_BYTE_SIZE) + HEADER_BYTE_SIZE;
                // If the row is marked as deleted
                if (!DataBaseReader.ReadBoolean())
                {
                    // Remove it from the dictionary index.
                    Index.Remove(DataBaseReader.ReadInt32());
                    // Set the location of the row that needs to be overwritten.
                    locationToMoveTo = i + 1;
                    // Search from the bottom up to the location of the current row to overwrite for a row that is not marked as deleted.
                    for (int j = locationOfNextRowToCheck - 1; j >= locationToMoveTo; j--)
                    {
                        DataBaseStream.Position = (j * ROW_BYTE_SIZE) + HEADER_BYTE_SIZE;
                        if (DataBaseReader.ReadBoolean())
                        {
                            // We've got our row to move!
                            Row rowToMove = new Row();
                            // Assign the location of the next row to check for as un-deleted.
                            locationOfNextRowToCheck = j;
                            // Read the row's details into a new row object
                            rowToMove.Status     = true;
                            rowToMove.PrimaryKey = DataBaseReader.ReadInt32();
                            rowToMove.TextData   = new string(DataBaseReader.ReadChars(20));
                            rowToMove.NumberData = DataBaseReader.ReadSingle();
                            // Add the row to the new index dictionary.
                            newIndex.Add(rowToMove, locationToMoveTo);
                            // Find the next row that is deletd.
                            break;
                        }
                    }
                }
            }
            // Rearrange the database file and index file accordingly.
            RearrangeRowsAndIndex(newIndex);
        }
コード例 #10
0
        private void DownloadFile(object sender, EventArgs e)
        {
            if (sender is IButtonControl)
            {
                var button = sender as IButtonControl;

                Card card;
                var  entityID = Convert.ToInt32(button.CommandName);
                Cards.TryGetValue(entityID, out card);
                var field   = card.Fields.First(f => f.SystemName == button.CommandArgument);
                var content = DataBaseReader.GetFileContent(card, int.Parse(card.EntityInstance.EntityInstanceID));


                var response = Page.Response;
                response.Clear();
                response.AddHeader("content-disposition", string.Concat("attachment;fileName=", field.Value));
                response.BinaryWrite(content);
                response.Flush();
                response.End();
            }
        }
コード例 #11
0
        private List <Warehouses> GetWarehousesList()
        {
            List <Warehouses> listWarehouses = new List <Warehouses>();
            DataBaseReader    dbReader       = new DataBaseReader(this.sqlConnect);

            string command = "SELECT [Warehouses].[WarehouseID], " +
                             "[Warehouses].[WarehouseName] FROM [Warehouses]";

            dbReader.GetSqlReader(command);

            while (dbReader.SqlReader.Read())
            {
                listWarehouses.Add(new Warehouses
                {
                    RowNumber     = dbReader.SqlReader[0].ToString(),
                    WarehouseName = dbReader.SqlReader[1].ToString()
                });
            }

            dbReader.CloseReader();

            return(listWarehouses);
        }
コード例 #12
0
        private Control CreateRelatedList()
        {
            var ContainerDiv = new HtmlGenericControl("div")
            {
                ID = "ListAttributeContainer"
            };

            ContainerDiv.Visible = DisplayRelatedList;


#warning Style for RelatedList.
            ContainerDiv.Attributes.Add("class", "ListAttributeContainer");

            var toolBarDiv = new HtmlGenericControl("div");
            toolBarDiv.Attributes.Add("class", "ListAttributeContent");

            RelatedListView = new GridView
            {
                ID                  = "ListView",
                DataKeyNames        = new[] { "objID" },
                AutoGenerateColumns = true,
                UseAccessibleHeader = true
            };

            RelatedListView.RowDataBound         += RelatedListView_RowDataBound;
            RelatedListView.SelectedIndexChanged += RelatedListView_SelectedIndexChanged;



            if (DisplayRelatedList)
            {
                var sourceTable = DataBaseReader.GetRelations(OpenedRelation);
                RelatedListView.DataSource = sourceTable;

                RelatedListView.DataBind();
            }

            var headerDiv = new HtmlGenericControl("div");

            headerDiv.Attributes.Add("class", "headDiv");

            var closeButton = new Button {
                Text = "Закрыть"
            };
            closeButton.Click += CloseRelatedListHandler;

            headerDiv.Controls.Add(closeButton);
            toolBarDiv.Controls.Add(headerDiv);

            var searchPanelDiv = CreateSearchPanel();
            toolBarDiv.Controls.Add(searchPanelDiv);

            var bodyDiv = new HtmlGenericControl("div");
            bodyDiv.Attributes.Add("class", "bodyDiv");

            bodyDiv.Controls.Add(RelatedListView);
            toolBarDiv.Controls.Add(bodyDiv);

            ContainerDiv.Controls.Add(toolBarDiv);


            Controls.Add(ContainerDiv);

            if (DisplayRelatedList)
            {
                ContainerDiv.FindControl("ListAttributeSearchText").Focus();
            }

            return(ContainerDiv);
        }
コード例 #13
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            bool sellerIsSelected =
                (comboSeller.SelectedItem != null &&
                 !comboSeller.SelectedItem.ToString().Equals("Выберите покупателя")) ? true : false;

            bool tableIsFiled = moovingList.Count > 0 ? true : false;

            if (!sellerIsSelected)
            {
                MessageBox.Show("Выберите продавца из списка или создайте нового",
                                "Продавец не выбран", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            else if (!tableIsFiled)
            {
                ErrorMessages.MoovingTableIsEmpty();
            }

            else if (sellerIsSelected && tableIsFiled)
            {
                DataBaseReader dbReader = new DataBaseReader(this.sqlConnect);

                string sellerID;
                string sellerName = comboSeller.SelectedItem.ToString();

                string command = "SELECT [Buyers].[BuyerID] FROM [Buyers] " +
                                 "WHERE [Buyers].[BuyerName] = '" + sellerName + "'";

                sellerID = dbReader.GetString(command);

                string lastUpdate = Convert.ToDateTime(DateTime.Now).ToString("yyyyMMdd");

                List <Warehouses> listWarehouses = GetWarehousesList();

                for (int i = 0; i < moovingList.Count; i++)
                {
                    string goodsID;
                    string goodsName = moovingList[i].GoodsName;

                    command = "SELECT [Goods].[GoodsID] FROM [Goods] " +
                              "WHERE [Goods].[GoodsName] = '" + goodsName + "'";

                    goodsID = dbReader.GetString(command);

                    string goodsQuantity = moovingList[i].GoodsQuantity;
                    string goodsPrice    = moovingList[i].GoodsPrice;

                    //ID склада
                    string warehouseSourse = moovingList[i].WarehouseSourse;
                    int    index           = listWarehouses.FindIndex(
                        indx => string.Equals(indx.WarehouseName, warehouseSourse, StringComparison.CurrentCultureIgnoreCase));
                    string warehouseSourceID = listWarehouses[index].RowNumber;

                    command = "SELECT [GoodsInSale].[GoodsName] FROM [GoodsInSale] " +
                              "WHERE [GoodsInSale].[BuyerName] = '" + sellerID + "' " +
                              "AND [GoodsInSale].[GoodsName] = '" + goodsID + "'";
                    bool rowIsFinded = dbReader.SearchMatch(command);

                    DataBaseWriter dbWriter = new DataBaseWriter(this.sqlConnect);

                    if (rowIsFinded)
                    {
                        command = "SELECT [GoodsInSale].[GoodsQuantity] FROM [GoodsInSale] " +
                                  "WHERE [GoodsInSale].[BuyerName] = '" + sellerID + "' " +
                                  "AND [GoodsInSale].[GoodsName] = '" + goodsID + "'";
                        float oldQuantityFromSeller = float.Parse(dbReader.GetString(command));
                        float newQuantityFromSeller = oldQuantityFromSeller + float.Parse(goodsQuantity);

                        command = "UPDATE [GoodsInSale] " +
                                  "SET [GoodsQuantity] = '" + TextHandler.FloatToString(newQuantityFromSeller) + "', " +
                                  "[GoodsPrice] = '" + goodsPrice + "', " +
                                  "[LastUpdate] = '" + lastUpdate + "' " +
                                  "WHERE [GoodsInSale].[BuyerName] = '" + sellerID + "' " +
                                  "AND [GoodsInSale].[GoodsName] = '" + goodsID + "'";
                        dbWriter.WriteData(command);
                    }
                    else
                    {
                        //Продавец
                        dbWriter.InsDataRow.Add(new InsertDataToRow {
                            ColumnName = "BuyerName", Data = sellerID
                        });

                        //Товар
                        dbWriter.InsDataRow.Add(new InsertDataToRow {
                            ColumnName = "GoodsName", Data = goodsID
                        });

                        //Количество
                        dbWriter.InsDataRow.Add(new InsertDataToRow {
                            ColumnName = "GoodsQuantity", Data = goodsQuantity
                        });

                        //Цена
                        dbWriter.InsDataRow.Add(new InsertDataToRow {
                            ColumnName = "GoodsPrice", Data = goodsPrice
                        });

                        //Дата последней поставки
                        dbWriter.InsDataRow.Add(new InsertDataToRow {
                            ColumnName = "LastUpdate", Data = lastUpdate
                        });

                        command = "INSERT INTO [GoodsInSale] (BuyerName, GoodsName, GoodsQuantity, GoodsPrice, LastUpdate) " +
                                  "VALUES (@BuyerName, @GoodsName, @GoodsQuantity, @GoodsPrice, @LastUpdate)";

                        dbWriter.WriteData(command);
                    }

                    //Обновления количества товара на складе поставщике
                    command = "SELECT [GoodsInWarehouses].[GoodsBalance] FROM [GoodsInWarehouses] " +
                              "WHERE [GoodsInWarehouses].[WarehouseName] = '" + warehouseSourceID + "' " +
                              "AND [GoodsInWarehouses].[GoodsName] = '" + goodsID + "'";

                    float oldQuantity = float.Parse(dbReader.GetString(command));
                    float newQuantity = oldQuantity - float.Parse(goodsQuantity);

                    DataBaseWriter updateData = new DataBaseWriter(this.sqlConnect);
                    command = "UPDATE [GoodsInWarehouses]" +
                              "SET [GoodsBalance] = " + TextHandler.FloatToString(newQuantity) + " " +
                              "WHERE [GoodsName] = '" + goodsID + "'" +
                              "AND [WarehouseName] = '" + warehouseSourceID + "'";
                    updateData.WriteData(command);
                }

                GoodsMoved?.Invoke(sender, e);

                MessageBox.Show(string.Format("Перемещение {0} продавцу {1} успешно завершено",
                                              moovingList.Count > 1 ? "товаров" : "товара", sellerName), "Выполнено",
                                MessageBoxButton.OK, MessageBoxImage.Information);

                this.Close();
            }
        }
コード例 #14
0
        private void CreateRow(IField field)
        {
            if (CurrentMode == Mode.ReadOnly || !(field is CardListRelationField))
            {
                if (field is CardListRelationField)
                {
                    var listRelation = field as CardListRelationField;

                    if (listRelation.Card.IsAncestor && listRelation.Entity.AncestorID == Convert.ToInt32(listRelation.Card.Entity.ID))
                    {
                        return;
                    }
                }

                if (field is CardRelationField)
                {
                    var f = field as CardRelationField;

                    if (f.SystemName == "Person_erp_Executive")
                    {
                    }


                    Card currentCard;
                    Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                    if (currentCard.EntityInstance == null)
                    {
                        DataBaseReader.FillEntityInstance(currentCard, "");
                    }

                    var constraint = currentCard.EntityInstance.Constraints.First(c => c.ConstraintName == field.SystemName);

                    if (constraint.IsIdentified && currentCard.Entity.AncestorID != -1)
                    {
                        return;
                    }
                }



                var row = new TableRow();

                var headerCell = new TableHeaderCell();

                headerCell.Controls.Add(new Literal {
                    Text = field.Name
                });


                if (CurrentMode != Mode.ReadOnly && !field.IsNullable)
                {
                    headerCell.Controls.Add(new Literal {
                        Text = "<span style='color:red'>*</span>"
                    });
                }


                row.Cells.Add(headerCell);

                var dataCell = new TableCell();

                row.Cells.Add(dataCell);

                FillDataCell(field, dataCell);

                Table.Rows.Add(row);
            }
        }
コード例 #15
0
        private void FillDataCellWhenEditMode(IField field, TableCell cell)
        {
            Card currentCard;

            if (field is CardRelationField)
            {
                var f = field as CardRelationField;

                var label = new Label {
                    Text = f.Value
                };

                cell.Controls.Add(label);

                Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                if (currentCard.EntityInstance == null)
                {
                    DataBaseReader.FillEntityInstance(currentCard, "");
                }

                Constraint constraint = currentCard.EntityInstance.Constraints.First(c => c.ConstraintName == field.SystemName);


                //если режим создания объекта
                if (string.IsNullOrEmpty(currentCard.EntityInstance.EntityInstanceID))
                {
                    var RelationEditedButton = CreateRelationEditedButton(f);
                    cell.Controls.Add(RelationEditedButton);

                    if (constraint.IsNullable)
                    {
                        var RelationClearedButton = CreateRelationClearedButton(f);
                        cell.Controls.Add(RelationClearedButton);
                    }
                }
                else if (!constraint.IsIdentified)
                {
                    var RelationEditedButton = CreateRelationEditedButton(f);
                    cell.Controls.Add(RelationEditedButton);

                    if (constraint.IsNullable)
                    {
                        var RelationClearedButton = CreateRelationClearedButton(f);
                        cell.Controls.Add(RelationClearedButton);
                    }
                }
            }
            else if (field is CardSelfField)
            {
                WebControl control = null;

                var f = field as CardSelfField;

                Cards.TryGetValue(Convert.ToInt32(f.Card.Entity.ID), out currentCard);

                if (f.IsReadOnly(CurrentMode))
                {
                    control = new Label {
                        Text = f.Value.ToString()
                    }
                }
                ;
                else
                {
                    switch (f.TypeCode)
                    {
                    case CardSelfField.Type.Object:
                        control = new TextBox
                        {
                            TextMode = TextBoxMode.MultiLine,
                            Text     = f.Value.ToString()
                        };
                        break;

                    case CardSelfField.Type.Boolean:
                        if (f.Value == "")
                        {
                            f.Value = false;         // очень явно, для случая очистки всех полей при создании
                        }
                        control = new CheckBox {
                            Checked = (bool)f.Value
                        };
                        break;

                    case CardSelfField.Type.FileName:
                        control = new FileUpload();

                        if (f.ContainsNonEmptyValue())
                        {
                            cell.Controls.Add(new Literal {
                                Text = (f.Value as File).FileName
                            });
                        }
                        break;

                    case CardSelfField.Type.Float:
                    case CardSelfField.Type.ShortString:
                    case CardSelfField.Type.Numeric:
                        control = new TextBox {
                            Text = f.Value.ToString()
                        };
                        break;

                    case CardSelfField.Type.DateTime:
                        var textBox = new TextBox();
                        control = textBox;

                        if (f.ContainsNonEmptyValue())
                        {
                            var date = DateTime.Parse(f.Value.ToString());

                            textBox.Text = date.ToString("yyyy-MM-dd");
                        }
                        break;

                    default:
                        throw new NotImplementedException("Не реализована часть для варианта " + f.TypeCode.ToString());
                    }
                }
                if (control != null)
                {
                    if (control is TextBox)
                    {
                        var textBox = control as TextBox;

                        var entityType = Schema.Entities.First(e => e.ID.ToString() == currentCard.Entity.ID.ToString());
                        var attribute  = entityType.Attributes.Single(a => a.ID.ToString() == f.ID);

                        textBox.ApplyType(attribute.Type);
                    }

                    cell.Controls.Add(control);
                    WebControls.Add(field.SystemName, control);
                }
            }
        }