Beispiel #1
0
        /// <summary>
        /// Open document from the database
        /// </summary>
        /// <param name="id"></param>
        /// <exception cref="AssortmentException"></exception>
        public void Open(int id)
        {
            if (id < 1)
            {
                throw new AssortmentException("Номер документа некорректный");
            }

            Id = id;
            AssortmentProcedure.DocumentOpen.Parameters["i_id_doc"].Value = id;

            var parameters = _db.CallProcedure(AssortmentProcedure.DocumentOpen);

            var clob = (OracleClob)parameters["o_layout"];
            var layoutBytes = Convert.FromBase64String(clob.Value);
            var layout = new Layout();
            layout.LoadFromArray(layoutBytes);
            _description = parameters["o_desc"].ToString();
            PivotLayout = layout;

            AssortmentProcedure.DocumentTypeGet.Parameters["i_id_doc"].Value = id;
            parameters = _db.CallProcedure(AssortmentProcedure.DocumentTypeGet);
            DocType = parameters["o_doc_type"].ToString();
        }
        public Layout GetLayout()
        {
            var layout = new Layout();

            var fields = GetFieldsByArea(FieldArea.ColumnArea);
            for (int index = 0; index < fields.Count; index++)
            {
                var pivotGridField = fields[index];
                layout.ColumnArea.Add(index, FieldGetValues(pivotGridField));
            }

            fields = GetFieldsByArea(FieldArea.RowArea);
            for (int index = 0; index < fields.Count; index++)
            {
                var pivotGridField = fields[index];
                layout.RowArea.Add(index, FieldGetValues(pivotGridField));
            }

            fields = GetFieldsByArea(FieldArea.DataArea);
            for (int index = 0; index < fields.Count; index++)
            {
                var pivotGridField = fields[index];
                layout.DataArea.Add(index, FieldGetValues(pivotGridField));
            }

            fields = GetFieldsByArea(FieldArea.FilterArea);
            for (int index = 0; index < fields.Count; index++)
            {
                var pivotGridField = fields[index];
                layout.FilterArea.Add(index, FieldGetValues(pivotGridField));
            }

            return layout;
        }
Beispiel #3
0
        /// <summary>
        /// Method saves assortment document to database
        /// </summary>
        /// <param name="layout"></param>
        /// <exception cref="AssortmentLayoutNullException"></exception>
        /// <exception cref="AssortmentDescNullException"></exception>
        public void Save(Layout layout)
        {
            if (layout == null)
            {
                throw new AssortmentLayoutNullException("Структура документа (Layout) не инициализирована");
            }
            if (_description == null)
            {
                throw new AssortmentDescNullException("Комментарий не задан");
            }

            if (Id == -1) // create document
            {
                AssortmentProcedure.DocumentCreate.Parameters["i_desc"].Value = _description;
                AssortmentProcedure.DocumentCreate.Parameters["i_layout"].Value = Convert.ToBase64String(layout.SaveToArray());
                AssortmentProcedure.DocumentCreate.Parameters["i_doc_type"].Value = DocType;
                var parameters = _db.CallProcedure(AssortmentProcedure.DocumentCreate);
                Id = Convert.ToInt32(parameters["o_id_doc"].ToString());
            }
            else
            {
                if (DocType != DocTypes.ExpendMaterial)_db.WhRowsClear();
                AssortmentProcedure.DocumentUpdate.Parameters["i_id_doc"].Value = Id;
                AssortmentProcedure.DocumentUpdate.Parameters["i_desc"].Value = _description;
                AssortmentProcedure.DocumentUpdate.Parameters["i_layout"].Value = Convert.ToBase64String(layout.SaveToArray());
                var parameters = _db.CallProcedure(AssortmentProcedure.DocumentUpdate);
            }
            PivotLayout = layout;
            Saved = true;
        }
        public void SetLayout(Layout layout)
        {
            if (layout == null) return;

            ClearLayout();

            for (int index = 0; index < layout.ColumnArea.Count; index++)
            {
                LayoutField field;
                if (layout.ColumnArea.TryGetValue(index, out field) == false) continue;
                Fields[field.Name].Area = FieldArea.ColumnArea;
                Fields[field.Name].Visible = true;
                Fields[field.Name].SetAreaPosition(FieldArea.ColumnArea, index);
                //Fields[field.Name].FilterValues.Clear();
                FieldSetValues(field);
            }
            for (int index = 0; index < layout.RowArea.Count; index++)
            {
                LayoutField field;
                if (layout.RowArea.TryGetValue(index, out field) == false) continue;
                Fields[field.Name].Area = FieldArea.RowArea;
                Fields[field.Name].Visible = true;
                Fields[field.Name].SetAreaPosition(FieldArea.RowArea, index);
                //Fields[field.Name].FilterValues.Clear();
                FieldSetValues(field);
            }
            for (int index = 0; index < layout.DataArea.Count; index++)
            {
                LayoutField field;
                if (layout.DataArea.TryGetValue(index, out field) == false) continue;
                Fields[field.Name].Area = FieldArea.DataArea;
                Fields[field.Name].Visible = true;
                Fields[field.Name].SetAreaPosition(FieldArea.DataArea, index);
                //Fields[field.Name].FilterValues.Clear();
                FieldSetValues(field);
            }
            for (int index = 0; index < layout.FilterArea.Count; index++)
            {
                LayoutField field;
                if (layout.FilterArea.TryGetValue(index, out field) == false) continue;
                Fields[field.Name].Area = FieldArea.FilterArea;
                Fields[field.Name].Visible = true;
                Fields[field.Name].SetAreaPosition(FieldArea.FilterArea, index);
                //Fields[field.Name].FilterValues.Clear();
                FieldSetValues(field);
            }

        }