Exemplo n.º 1
0
 protected void BindData(Dictionary<Guid, Guid> multiBuffer)
 {
     using (EditConfigurationProvider provider = new EditConfigurationProvider())
     {
         System.Data.DataTable dt = provider.GetList(ProductID).Tables[0];
         if (multiBuffer.Count > 0)
         {
             System.Data.DataTable bfDt = provider.GetAppendList(multiBuffer).Tables[0];
             dt.Merge(bfDt);
         }
         EditConfigurationGrid.DataSource = dt;
         EditConfigurationGrid.DataBind();
     }
 }
Exemplo n.º 2
0
        private void BindGridColumns()
        {
            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                Aspect.Domain.Product prod = provider.GetProduct(this.ProductID);
                if (prod == null) return;
                this.Title = HeaderLiteral.Text = string.Format(HeaderLiteral.Text, prod.PublicName, prod.Version == null ? string.Empty : prod.Version.ToString());
                HeaderDateLiteral.Text = string.Format(HeaderDateLiteral.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                //---
                SelectorProductGridField selector = new SelectorProductGridField(string.Empty, "ConfigurationID", true);
                selector.ItemStyle.Width = new Unit(15, UnitType.Pixel);
                EditConfigurationGrid.Columns.Add(selector);
                //---

                bool actionColumnAdded = false;
                List<GridColumn> list = provider.GetGridColumns();
                foreach (GridColumn item in list)
                {
                    BoundField field = null;
                    EditableGridColumn editableColumn = item as EditableGridColumn;
                    if (editableColumn == null)
                    {
                        if (item.GridColumnType == TypeEnum.Boolean)
                        {
                            field = new BooleanGridField();
                            field.DataField = item.DataItem;
                            field.HeaderText = item.Name;
                            field.ReadOnly = true;
                        }
                        else
                        {
                            if (!actionColumnAdded)
                            {
                                field = new ActionProductGridField(item.Name, item.DataItem);
                                actionColumnAdded = true;
                            }
                            else
                            {
                                field = new ProductGridField(item.Name, item.DataItem);
                            }
                            field.ItemStyle.Font.Size = new FontUnit(FontSize.Smaller);
                        }
                        //field = new ActionProductGridField(item.Name, item.DataItem);
                    }
                    else
                    {

                        if (editableColumn.View == EditableGridColumn.GridColumnView.TextBox)
                        {
                            field = new TextBoxProductGridField(editableColumn);
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.DropDown)
                        {
                            field = new DropDownProductGridField(editableColumn/*, editableColumn.DataSource.DataSource*/);
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.CheckBox)
                        {
                            field = new CheckBoxProductGridField(editableColumn);
                        }
                    }

                    if (field != null)
                    {
                        EditConfigurationGrid.Columns.Add(field);
                        //EditAddedConfigurationGrid.Columns.Add(field);
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected void PrintSelected_Click(object sender, EventArgs e)
        {
            string fileName = string.Format("configurations-{0:yyyy-MM-dd_hh-mm-ss}.odt", DateTime.Now);

            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
            Response.ContentType = "application/octet-stream";

            TextDocument document = new TextDocument();
            AODL.Document.Content.Tables.Table table;
            document.New();

            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                List<GridColumn> columns = provider.GetGridColumns();
                DataTable data = provider.GetList(ProductID).Tables[0];

                List<Guid> selectedRows;
                if (SelectedProductsHidden.Value != "")
                    selectedRows = SelectedProductsHidden.Value.Split(',').Select(s => new Guid(s)).ToList();
                else
                    selectedRows = new List<Guid>();

                //Create a table for a text document using the TableBuilder
                table = TableBuilder.CreateTextDocumentTable(
                    document,
                    "table1",
                    "table1",
                    selectedRows.Count + 1,
                    columns.Count,
                    16.99,
                    false,
                    true);

                //Fill the cells
                int columnIndex = 0, rowIndex = 0;
                foreach (GridColumn column in columns)
                {
                    Cell cell = table.RowCollection[0].CellCollection[columnIndex];
                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    paragraph.TextContent.Add(new SimpleText(document, column.Name));
                    cell.Content.Add(paragraph);
                    columnIndex++;
                }
                rowIndex++;

                foreach (DataRow row in data.Rows)
                {
                    Guid rodId = row.Field<Guid>("ConfigurationID");
                    if (!selectedRows.Contains(rodId)) continue;

                    columnIndex = 0;
                    foreach (GridColumn column in columns)
                    {
                        if (!row.IsNull(column.DataItem))
                        {
                            try
                            {
                                Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                string value = row.Field<string>(column.DataItem);
                                paragraph.TextContent.Add(new SimpleText(document, value));
                                cell.Content.Add(paragraph);
                            }
                            catch (System.Exception)
                            {
                                try
                                {
                                    Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                    Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                    int value = row.Field<int>(column.DataItem);
                                    paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                    cell.Content.Add(paragraph);
                                }
                                catch (System.Exception)
                                {
                                    try
                                    {
                                        Cell cell = table.RowCollection[rowIndex].CellCollection[columnIndex];
                                        Paragraph paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                                        decimal value = row.Field<decimal>(column.DataItem);
                                        paragraph.TextContent.Add(new SimpleText(document, value.ToString()));
                                        cell.Content.Add(paragraph);
                                    }
                                    catch (System.Exception)
                                    {

                                    }
                                }
                            }
                        }
                        columnIndex++;
                    }
                    rowIndex++;
                }

            }

            //Merge some cells. Notice this is only available in text documents!
            // table.RowCollection[1].MergeCells(document, 1, 2, true);
            //Add table to the document
            document.Content.Add(table);
            //Save the document
            String fs_guid = Server.MapPath(String.Format("/tmp/{0}.odt", Guid.NewGuid().ToString()));
            document.SaveTo(fs_guid);
            document.Dispose();

            // Copy file to Response stream
            FileStream fs = new FileStream(fs_guid, FileMode.Open);

            int bufferSize = 4096;
            byte[] buffer = new byte[bufferSize];
            while (true)
            {
                int read = fs.Read(buffer, 0, buffer.Length);
                if (read <= 0)
                {
                    break;
                }
                Response.OutputStream.Write(buffer, 0, read);
            }

            fs.Close(); //закрываем writer
            File.Delete(fs_guid);
            Response.End(); //заканчиваем ответ сервера, иначе после этого вставится весь контент страницы
            return;
        }
Exemplo n.º 4
0
        /*private void BindGridColumns()
        {
            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                Aspect.Domain.Product prod = provider.GetProduct(this.ProductID);
                if (prod == null) return;
                this.Title = HeaderLiteral.Text = string.Format(HeaderLiteral.Text, prod.PublicName, prod.Version == null ? string.Empty : prod.Version.ToString());
                HeaderDateLiteral.Text = string.Format(HeaderDateLiteral.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                //---
                SelectorProductGridField selector = new SelectorProductGridField(string.Empty, "ConfigurationID", true);
                selector.ItemStyle.Width = new Unit(15, UnitType.Pixel);
                EditConfigurationGrid.Columns.Add(selector);
                //---

                bool actionColumnAdded = false;
                List<GridColumn> list = provider.GetGridColumns();
                foreach (GridColumn item in list)
                {
                    BoundField field = null;
                    EditableGridColumn editableColumn = item as EditableGridColumn;
                    if (editableColumn == null)
                    {
                        if (item.GridColumnType == TypeEnum.Boolean)
                        {
                            field = new BooleanGridField();
                            field.DataField = item.DataItem;
                            field.HeaderText = item.Name;
                            field.ReadOnly = true;
                        }
                        else
                        {
                            if (!actionColumnAdded)
                            {
                                field = new ActionProductGridField(item.Name, item.DataItem);
                                actionColumnAdded = true;
                            }
                            else
                            {
                                field = new ProductGridField(item.Name, item.DataItem);
                            }
                            field.ItemStyle.Font.Size = new FontUnit(FontSize.Smaller);
                        }
                        //field = new ActionProductGridField(item.Name, item.DataItem);
                    }
                    else
                    {

                        if (editableColumn.View == EditableGridColumn.GridColumnView.TextBox)
                        {
                            field = new TextBoxProductGridField(editableColumn);
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.DropDown)
                        {
                            field = new DropDownProductGridField(editableColumn);
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.CheckBox)
                        {
                            field = new CheckBoxProductGridField(editableColumn);
                        }
                    }

                    if (field != null)
                    {
                        EditConfigurationGrid.Columns.Add(field);
                        //EditAddedConfigurationGrid.Columns.Add(field);
                    }
                }
            }
        }*/
        private void BindGridColumns2()
        {
            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                Aspect.Domain.Product prod = provider.GetProduct(this.ProductID);
                if (prod == null) return;

                this.Title = HeaderLiteral.Text = string.Format(HeaderLiteral.Text, prod.PublicName, prod.Version == null ? string.Empty : prod.Version.ToString());
                HeaderDateLiteral.Text = string.Format(HeaderDateLiteral.Text, DateTime.Now.ToShortDateString(), DateTime.Now.ToLongTimeString());

                // извлекаем ширины колонок для данного класса
                List<ColumnWidth> columnWidths = provider.ColumnWidths.Where(p => p.ClassificationTreeID == new Guid("11110000-0000-0000-0000-000011110001")
                    && p.UserID == this.User.ID).ToList();

                List<GridColumn> list = provider.GetGridColumns();

                // sort columns by user's order
                list = list.OrderBy(clm => columnWidths.Exists(w => w.ColumnID == clm.ID) ? columnWidths.Single(w => w.ColumnID == clm.ID).Index : Int32.MaxValue).ToList();

                foreach (GridColumn column in list)
                {
                    Ext.Net.ColumnBase extjsColumn = null;
                    EditableGridColumn editableColumn = column as EditableGridColumn;
                    if (editableColumn == null)
                    {
                        if (column.GridColumnType == TypeEnum.Boolean)
                        {
                            extjsColumn = new Ext.Net.CheckColumn();
                            extjsColumn.DataIndex = column.DataItem;
                            extjsColumn.Header = column.Name;
                        }
                        else
                        {
                            extjsColumn = new Ext.Net.Column();
                            extjsColumn.DataIndex = column.DataItem;
                            extjsColumn.Header = column.Name;
                        }
                    }
                    else
                    {

                        if (editableColumn.View == EditableGridColumn.GridColumnView.TextBox)
                        {
                            extjsColumn = new Ext.Net.Column();
                            if (editableColumn.Type == typeof(int) || editableColumn.Type == typeof(decimal))
                            {
                                Ext.Net.TextField field = new Ext.Net.TextField();
                                field.Regex = @"^\d+(,\d+)?$";
                                field.RegexText = "0";
                                extjsColumn.Editor.Add(field);
                            }
                            else
                            {
                                extjsColumn.Editor.Add(new Ext.Net.TextField());
                            }
                            extjsColumn.DataIndex = column.DataItem;
                            extjsColumn.Header = column.Name;
                            extjsColumn.Editable = true;
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.DropDown)
                        {
                            extjsColumn = new Ext.Net.Column();
                            extjsColumn.DataIndex = column.DataItem;
                            extjsColumn.Header = column.Name;
                            extjsColumn.Editable = true;

                            StringBuilder renderFunction = new StringBuilder();
                            renderFunction.AppendLine("function(value){");
                            Ext.Net.ComboBox field = new Ext.Net.ComboBox();
                            field.Editable = false;
                            foreach (Pair<Guid, string> itemDropList in (editableColumn.DataSource.DataSource as List<Pair<Guid, string>>))
                            {
                                field.Items.Add(new Ext.Net.ListItem(itemDropList.Second, itemDropList.First.ToString()));
                                renderFunction.AppendFormat("if (value=='{0}') return '{1}';\n", itemDropList.First.ToString(), itemDropList.Second);
                            }
                            renderFunction.AppendLine("return 'error'; }");

                            extjsColumn.Editor.Add(field);
                            extjsColumn.Renderer.Handler = renderFunction.ToString();
                        }
                        else if (editableColumn.View == EditableGridColumn.GridColumnView.CheckBox)
                        {
                            extjsColumn = new Ext.Net.CheckColumn();
                            extjsColumn.DataIndex = column.DataItem;
                            extjsColumn.Header = column.Name;
                            extjsColumn.Editable = true;
                            extjsColumn.Editor.Add(new Ext.Net.Checkbox());
                        }
                    }

                    if (extjsColumn != null)
                    {
                        // setting visibility column
                        extjsColumn.Hidden = columnWidths.Exists(w => w.ColumnID == column.ID) ? columnWidths.Single(w => w.ColumnID == column.ID).Hidden : false;

                        extjsColumn.ColumnID = column.ID.ToString();
                        foreach (int width in columnWidths.Where(p => p.ColumnID == column.ID).Select(p => p.Width))
                        {
                            extjsColumn.Width = width;
                        }
                        Store1.AddField( new Ext.Net.RecordField(extjsColumn.DataIndex));
                        GridPanel.ColumnModel.Columns.Add(extjsColumn);
                    }
                }
                // дополнительные поля
                Store1.AddField(new Ext.Net.RecordField("ID"));
                Store1.AddField(new Ext.Net.RecordField("CID"));
                Store1.AddField(new Ext.Net.RecordField("ConfID"));
            }
        }
Exemplo n.º 5
0
        protected void Save_Click(object sender, EventArgs e)
        {
            this.Validate();
            if (this.IsValid)
            {
                // Проверяем, является ли продукт основной версией
                ProductProvider productProvider = new ProductProvider();
                if (productProvider.IsMainVersion(this.ProductID))
                {
                    LabelErrorMessage.Text = "[ ! ] Содержащий данную спецификацию продукт является основной версией. Сохранение отменено.";
                    return;
                }

                JavaScriptSerializer js = new JavaScriptSerializer();
                List<Dictionary<string, string>> rows = js.Deserialize<List<Dictionary<string, string>>>(hiddenStoreData.Value.ToString());
                EditConfigurationProvider provider = new EditConfigurationProvider();
                List<GridColumn> gridColumns = provider.GetGridColumns();

                // Сохраняем данные, полученные от пользователя в списке конфигураций
                List<Aspect.Domain.Configuration> result = new List<Aspect.Domain.Configuration>();
                #region convert Request to list of Configuration
                foreach (Dictionary<string, string> row in rows)
                {
                    Guid productID = new Guid(row["ID"]);
                    Aspect.Domain.Configuration conf = new Aspect.Domain.Configuration();
                    conf.ID = new Guid(row["ConfID"]);
                    conf.ProductID = productID;
                    conf.ProductOwnerID = this.ProductID;
                    conf.UserID = this.User.ID;

                    foreach (GridColumn column in gridColumns)
                    {
                        if (column is EditableGridColumn)
                        {
                            System.Reflection.PropertyInfo prop = typeof(Aspect.Domain.Configuration).GetProperty(column.DataItem);
                            if (prop.PropertyType == typeof(decimal) || prop.PropertyType == typeof(Nullable<decimal>))
                            {
                                prop.SetValue(conf, Convert.ToDecimal(row[column.DataItem]), null);
                            }
                            else if (prop.PropertyType == typeof(int) || prop.PropertyType == typeof(Nullable<int>))
                            {
                                prop.SetValue(conf, Convert.ToInt32(row[column.DataItem]), null);
                            }
                            else if (prop.PropertyType == typeof(Guid) || prop.PropertyType == typeof(Nullable<Guid>))
                            {
                                prop.SetValue(conf, new Guid(row[column.DataItem]), null);
                            }
                            else if (prop.PropertyType == typeof(Boolean) || prop.PropertyType == typeof(Nullable<Boolean>))
                            {
                                prop.SetValue(conf, Convert.ToBoolean(row[column.DataItem]), null);
                            }
                            else
                            {
                                prop.SetValue(conf, row[column.DataItem], null);
                            }
                        }
                    }

                    result.Add(conf);
                }
                #endregion

                using (CommonDomain domain = new CommonDomain())
                {
                    // Проверка на включение материалов
                    #region check_including_material
                    foreach (Aspect.Domain.Configuration conf in result)
                    {
                        Product prod = domain.Products.Single(p => p.ID == conf.ProductID);
                        if (prod._dictNomen.cod >= 1000000)
                        {
                            LabelErrorMessage.Text = "[ ! ] Обнаружены материалы в спецификации. Сохранение отменино.";
                            return;
                        }
                    }
                    #endregion

                    // Проверка на циклы
                    #region check_for_cycles
                    Guid dictNomenID = (Guid) (from p in domain.Products
                                               where p.ID == this.ProductID
                                               select p).Single()._dictNomenID;
                    foreach (Aspect.Domain.Configuration conf in result)
                    {
                        Product prod = domain.Products.Where(p => p.ID == conf.ProductID).Single();
                        if (dictNomenID == prod._dictNomenID)
                        {
                            LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино.";
                            return;
                        }
                        if (fnCheckContains(dictNomenID, prod.ID))
                        {
                            LabelErrorMessage.Text = "[ ! ] Обнаружены циклические включения продуктов в спецификацию. Сохранение отменино.";
                            return;
                        }
                    }
                    #endregion
                }

                provider.SaveProductConfiguration(this.ProductID, result, this.User.ID);

                // установка признака "Основная версия"
                if (MadeBasicVersion.Checked)
                {
                    productProvider.SetMainVersion(this.User.ID, new List<Guid>{ProductID});
                }

                // устанавливаем основание изменений
                if (!String.IsNullOrEmpty(ReasonChanges.Text))
                {
                    ProductProperty reasonProperty = productProvider.ProductProperties.SingleOrDefault(
                        pr => pr.PropertyID == new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A")
                        && pr.ProductID == this.ProductID);

                    if (reasonProperty == null)
                    {
                        reasonProperty = new ProductProperty()
                        {
                            ID = Guid.NewGuid(),
                            PropertyID = new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A"),
                            ProductID = this.ProductID,
                            Value = ReasonChanges.Text
                        };
                        productProvider.ProductProperties.InsertOnSubmit(reasonProperty);
                    }
                    else
                    {
                        reasonProperty.Value = ReasonChanges.Text;
                    }
                    productProvider.SubmitChanges();
                }

                // Очищаем сообщение об ошибке и обновляем данные о спецификации
                LabelErrorMessage.Text = "";
                this.BindGridColumns2();
                this.BindData(new Dictionary<Guid, Guid>());
            }
        }
Exemplo n.º 6
0
        protected void BindData(Dictionary<Guid, Guid> productsConfigurations)
        {
            using (EditConfigurationProvider provider = new EditConfigurationProvider())
            {
                System.Data.DataTable dt = provider.GetList(ProductID).Tables[0];
                if (productsConfigurations.Count > 0)
                {
                    System.Data.DataTable bfDt = provider.GetAppendList(productsConfigurations).Tables[0];
                    dt.Merge(bfDt);
                }

                // FOR NEW
                using (EditConfigurationProvider prov = new EditConfigurationProvider())
                {
                    List<object> lst = new List<object>();

                    List<ColumnWidth> columnWidths = provider.ColumnWidths.Where(p => p.ClassificationTreeID == new Guid("11110000-0000-0000-0000-000011110001") && p.UserID == this.User.ID).ToList();
                    List<GridColumn> list = prov.GetGridColumns();
                    list = list.OrderBy(clm => columnWidths.Exists(w => w.ColumnID == clm.ID) ? columnWidths.Single(w => w.ColumnID == clm.ID).Index : Int32.MaxValue).ToList();

                    foreach (DataRow row in dt.Rows)
                    {
                        List<object> lst_sub = new List<object>();
                        foreach (GridColumn column in list)
                        {
                            if (column.GridColumnType == TypeEnum.Boolean)
                            {
                                if (row[column.DataItem].ToString() == "0") lst_sub.Add(false);
                                else lst_sub.Add(true);
                            }
                            else
                            {
                                lst_sub.Add(row[column.DataItem].ToString());
                            }
                        }
                        // дополнительные поля
                        lst_sub.Add(row["ID"].ToString());
                        lst_sub.Add(this.RequestClassificationTreeID.ToString());
                        lst_sub.Add(row["ConfigurationID"].ToString());
                        lst.Add(lst_sub.ToArray());
                    }

                    Store1.DataSource = lst;
                    Store1.DataBind();
                }

                //EditConfigurationGrid.DataSource = dt;
                //EditConfigurationGrid.DataBind();

                // загружаем основание изменений
                ProductProperty reasonProperty = provider.ProductProperties.SingleOrDefault(
                    pr => pr.PropertyID == new Guid("C266B994-9740-41F6-94DD-07EA5B5FA34A")
                    && pr.ProductID == this.ProductID);

                if (reasonProperty != null)
                {
                    ReasonChanges.Text = reasonProperty.Value;
                }
            }
        }
Exemplo n.º 7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (EditConfigurationProvider provider = new EditConfigurationProvider())
     {
         Aspect.Domain.Product prodLeft = provider.GetProduct(this.ProductID1);
         Aspect.Domain.Product prodRight = provider.GetProduct(this.ProductID2);
         HeaderLiteralLeft.Text = string.Format(HeaderLiteralLeft.Text, prodLeft.PublicName, prodLeft.Version == null ? string.Empty : prodLeft.Version.ToString());
         HeaderLiteralRight.Text = string.Format(HeaderLiteralRight.Text, prodRight.PublicName, prodRight.Version == null ? string.Empty : prodRight.Version.ToString());
     }
     this.Title = String.Format("Сравнение: {0} | {1}", HeaderLiteralLeft.Text, HeaderLiteralRight.Text);
     BindGridColumns();
     BindData();
 }