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
        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.º 3
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;
                }
            }
        }