コード例 #1
0
        private void GetData()
        {
            m_Offers   = CrossDataHelper.LoadTestOffers();
            m_Requests = CrossDataHelper.LoadTestPurchseRequest();
            GetColumsVisibility();

            m_OfferHeaders = new List <OfferHeader>();
            List <CustomOffers> coList = new List <CustomOffers>();
            int offerID = 1;

            foreach (var grByTitle in m_Offers.offers.GroupBy(x => x.Title).OrderBy(x => x.Key))
            {
                Offers      offer = grByTitle.First();
                OfferHeader oh    = new OfferHeader();
                oh.HeaderNumber = offerID;
                oh.Row1         = offer.Title;
                oh.Row2         = offer.PaymentType + " " + offer.DelayDays + " дн.";
                oh.Row3         = offer.DeliveryType + " " + offer.Area;
                m_OfferHeaders.Add(oh);

                foreach (Offers o in grByTitle)
                {
                    CustomOffers co = new CustomOffers();
                    co.InitialOffer = o;
                    co.Number       = offerID;
                    coList.Add(co);
                }
                offerID++;
            }

            m_CustomRequests = new List <CustomRequests>();
            foreach (Requests rd in m_Requests.requests)
            {
                CustomRequests cr = new CustomRequests();
                var            offersByRequest = coList.Where(x => x.InitialOffer.variants.Any(y => y.requestId.Equals(rd.ID)));

                List <CustomOffers> ncoList = new List <CustomOffers>();
                foreach (CustomOffers co in offersByRequest)
                {
                    CustomOffers nco = new CustomOffers();
                    nco.InitialOffer = co.InitialOffer;
                    nco.Number       = co.Number;
                    nco.Variants     = co.InitialOffer.variants.Where(y => y.requestId.Equals(rd.ID)).ToList();
                    ncoList.Add(nco);
                }
                cr.InitialOffers.AddRange(ncoList);
                cr.InitialRequest = rd;
                m_CustomRequests.Add(cr);
            }
        }
コード例 #2
0
        private void BindGrid()
        {
            int secTabAmount = m_Offers.offers.GroupBy(x => x.Title).Count();

            for (int i = 0; i < CrossTableData.MainTableColumns.Length; i++)
            {
                if (m_MainColVisibility[i])
                {
                    ColumnInfo    ci = CrossTableData.MainTableColumns[i];
                    TemplateField tf = new TemplateField();
                    tf.HeaderTemplate = new DynamicallyTemplatedGridViewHandler
                                            (ListItemType.Header, ci.DataHeader, String.Empty);
                    tf.ItemTemplate = new DynamicallyTemplatedGridViewHandler
                                          (ListItemType.Item, ci.DataSource, String.Empty, ci.WidthPX);

                    tf.HeaderStyle.CssClass = ci.DataSource;
                    tf.ItemStyle.CssClass   = ci.DataSource;

                    GridView1.Columns.Add(tf);
                }
            }

            for (int i = 0; i < secTabAmount; i++)
            {
                for (int j = 0; j < CrossTableData.SecondaryTableColumns.Length; j++)
                {
                    if (m_SecColVisibility[j])
                    {
                        ColumnInfo ci      = CrossTableData.SecondaryTableColumns[j];
                        string     postfix = "_" + i.ToString();

                        /*string postfix = String.Empty;
                         * if (i != 0)
                         * {
                         *  postfix = "_" + (i + 1).ToString();
                         * }*/

                        TemplateField tf = new TemplateField();
                        tf.HeaderTemplate = new DynamicallyTemplatedGridViewHandler
                                                (ListItemType.Header, ci.DataHeader, String.Empty);
                        if (ci.DataControlType == typeof(TextBox))
                        {
                            tf.ItemTemplate = new DynamicallyTemplatedGridViewHandler
                                                  (ListItemType.EditItem, ci.DataSource + postfix, String.Empty, ci.WidthPX);
                        }
                        else if (ci.DataControlType == typeof(CheckBox))
                        {
                            tf.ItemTemplate = new DynamicallyTemplatedGridViewHandler
                                                  (ListItemType.EditItem, ci.DataSource + postfix, "CheckBox", ci.WidthPX);
                        }
                        else if (ci.DataControlType == typeof(Button))
                        {
                            tf.ItemTemplate = new DynamicallyTemplatedGridViewHandler
                                                  (ListItemType.EditItem, ci.DataSource + postfix, "Button", ci.WidthPX);
                        }
                        else
                        {
                            tf.ItemTemplate = new DynamicallyTemplatedGridViewHandler
                                                  (ListItemType.Item, ci.DataSource + postfix, String.Empty, ci.WidthPX);
                        }

                        tf.HeaderStyle.CssClass = ci.DataSource;
                        tf.ItemStyle.CssClass   = ci.DataSource;

                        GridView1.Columns.Add(tf);
                    }
                }
            }

            DataTable dt = new DataTable();

            dt.Columns.Add("Number", typeof(string));
            dt.Columns.Add("NomenclatureName", typeof(string));
            dt.Columns.Add("NomenclatureCode", typeof(string));
            dt.Columns.Add("TransferQuantityMO", typeof(string));
            dt.Columns.Add("Availability", typeof(string));
            dt.Columns.Add("TotalQuantityMO", typeof(string));

            for (int i = 0; i < secTabAmount; i++)
            {
                string postfix = "_" + i.ToString();

                /*string postfix = String.Empty;
                 * if (i != 0)
                 * {
                 *  postfix = "_" + (i + 1).ToString();
                 * }*/

                dt.Columns.Add("NomenclatureNameAnalog" + postfix, typeof(string));
                dt.Columns.Add("NomenclatureCodeAnalog" + postfix, typeof(string));
                dt.Columns.Add("History" + postfix, typeof(string));
                dt.Columns.Add("AutorHeadSelect" + postfix, typeof(bool));
                dt.Columns.Add("ManagerSelect" + postfix, typeof(bool));
                dt.Columns.Add("TransferQuantity" + postfix, typeof(string));
                dt.Columns.Add("CostInRub" + postfix, typeof(string));
                dt.Columns.Add("Total" + postfix, typeof(string));
                dt.Columns.Add("Term" + postfix, typeof(string));
                dt.Columns.Add("VariantID" + postfix, typeof(string));
            }

            decimal[] totals = new decimal[secTabAmount];

            int rowNum = 1;

            foreach (CustomRequests cr in m_CustomRequests.OrderBy(x => x.InitialRequest.NomenclatureName))
            {
                for (int l = 0; cr.InitialOffers.Any(x => x.Variants.Count > l); l++)
                {
                    DataRow dr1 = dt.NewRow();
                    dr1["Number"]             = rowNum.ToString();
                    dr1["NomenclatureName"]   = cr.InitialRequest.NomenclatureName;
                    dr1["NomenclatureCode"]   = cr.InitialRequest.NomenclatureCode;
                    dr1["TransferQuantityMO"] = cr.InitialRequest.TransferQuantityMO;
                    dr1["Availability"]       = cr.InitialRequest.Availability;
                    dr1["TotalQuantityMO"]    = cr.InitialRequest.TotalQuantityMO;
                    for (int i = 0; i < secTabAmount; i++)
                    {
                        string postfix = "_" + i.ToString();

                        /*string postfix = String.Empty;
                         * if (i != 0)
                         * {
                         *  postfix = "_" + (i + 1).ToString();
                         * }*/

                        CustomOffers co = cr.InitialOffers.FirstOrDefault(x => (x.Number == (i + 1) &&
                                                                                x.Variants.Count > l));
                        if (co != null)
                        {
                            dr1["NomenclatureNameAnalog" + postfix] = co.Variants[l].NomeclatureNameAnalog;
                            dr1["NomenclatureCodeAnalog" + postfix] = co.Variants[l].NomeclatureCodeAnalog;
                            dr1["History" + postfix]          = "History";
                            dr1["AutorHeadSelect" + postfix]  = co.Variants[l].AuthorHeadSelect;
                            dr1["ManagerSelect" + postfix]    = co.Variants[l].ManagerSelect;
                            dr1["TransferQuantity" + postfix] = co.Variants[l].transferQuantity;
                            dr1["CostInRub" + postfix]        = co.Variants[l].CostInRub;
                            dr1["Total" + postfix]            = co.Variants[l].Total;
                            dr1["Term" + postfix]             = co.Variants[l].Term;
                            dr1["VariantID" + postfix]        = co.Variants[l].ID;

                            var strTotal = co.Variants[l].Total;
                            strTotal = strTotal.Replace(" ", "");
                            strTotal = strTotal.Replace(",", ".");
                            decimal currentTotal;
                            if (decimal.TryParse(strTotal, out currentTotal))
                            {
                                totals[i] += currentTotal;
                            }
                        }
                    }
                    dt.Rows.Add(dr1);
                }
                rowNum++;
            }

            ViewState["Data"]    = dt;
            GridView1.DataSource = ViewState["Data"];
            GridView1.DataBind();

            GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);

            HeaderGridRow.ID = "1_HEADER_ROW";
            TableCell HeaderCell = new TableCell();

            HeaderCell.BackColor   = System.Drawing.Color.White;
            HeaderCell.BorderColor = System.Drawing.Color.White;
            HeaderCell.Text        = "";
            HeaderCell.ColumnSpan  = MainVisibleColNum;
            HeaderCell.ID          = "1_HEADER_CELL";
            HeaderGridRow.Cells.Add(HeaderCell);
            for (int i = 0; i < secTabAmount; i++)
            {
                HeaderCell             = new TableCell();
                HeaderCell.BackColor   = AllowedColors.Colors[i % 4];
                HeaderCell.BorderColor = AllowedColors.Colors[i % 4];
                HeaderCell.Text        = m_OfferHeaders[i].Row1;
                HeaderCell.ColumnSpan  = SecVisibleColNum;
                HeaderCell.ID          = "1_HEADER_CELL" + i.ToString();
                HeaderGridRow.Cells.Add(HeaderCell);
            }
            GridView1.Controls[0].Controls.AddAt(0, HeaderGridRow);

            HeaderGridRow          = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            HeaderGridRow.ID       = "2_HEADER_ROW";
            HeaderCell             = new TableCell();
            HeaderCell.BackColor   = System.Drawing.Color.White;
            HeaderCell.BorderColor = System.Drawing.Color.White;
            HeaderCell.Text        = "";
            HeaderCell.ColumnSpan  = MainVisibleColNum;
            HeaderCell.ID          = "2_HEADER_CELL";
            HeaderGridRow.Cells.Add(HeaderCell);
            for (int i = 0; i < secTabAmount; i++)
            {
                HeaderCell             = new TableCell();
                HeaderCell.BackColor   = AllowedColors.Colors[i % 4];
                HeaderCell.BorderColor = AllowedColors.Colors[i % 4];
                HeaderCell.Text        = m_OfferHeaders[i].Row2;
                HeaderCell.ColumnSpan  = SecVisibleColNum;
                HeaderCell.ID          = "2_HEADER_CELL" + i.ToString();
                HeaderGridRow.Cells.Add(HeaderCell);
            }
            GridView1.Controls[0].Controls.AddAt(0, HeaderGridRow);

            HeaderGridRow          = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            HeaderGridRow.ID       = "3_HEADER_ROW";
            HeaderCell             = new TableCell();
            HeaderCell.BackColor   = System.Drawing.Color.White;
            HeaderCell.BorderColor = System.Drawing.Color.White;
            HeaderCell.Text        = "";
            HeaderCell.ColumnSpan  = MainVisibleColNum;
            HeaderCell.ID          = "3_HEADER_CELL";
            HeaderGridRow.Cells.Add(HeaderCell);
            for (int i = 0; i < secTabAmount; i++)
            {
                HeaderCell             = new TableCell();
                HeaderCell.BackColor   = AllowedColors.Colors[i % 4];
                HeaderCell.BorderColor = AllowedColors.Colors[i % 4];
                HeaderCell.Text        = m_OfferHeaders[i].Row3;
                HeaderCell.ColumnSpan  = SecVisibleColNum;
                HeaderCell.ID          = "3_HEADER_CELL" + i.ToString();
                HeaderGridRow.Cells.Add(HeaderCell);
            }
            GridView1.Controls[0].Controls.AddAt(0, HeaderGridRow);

            HeaderGridRow          = new GridViewRow(0, 0, DataControlRowType.Footer, DataControlRowState.Insert);
            HeaderGridRow.ID       = "1_FOOTER_ROW";
            HeaderCell             = new TableCell();
            HeaderCell.BackColor   = System.Drawing.Color.White;
            HeaderCell.BorderColor = System.Drawing.Color.White;
            HeaderCell.ColumnSpan  = MainVisibleColNum;
            HeaderCell.ID          = "1_FOOTER_CELL";
            HeaderGridRow.Cells.Add(HeaderCell);
            for (int i = 0; i < secTabAmount; i++)
            {
                string postfix = "_" + i.ToString();

                /*string postfix = String.Empty;
                 * if (i != 0)
                 * {
                 *  postfix = "_" + (i + 1).ToString();
                 * }*/

                HeaderCell                 = new TableCell();
                HeaderCell.BackColor       = System.Drawing.Color.White;
                HeaderCell.BorderColor     = System.Drawing.Color.White;
                HeaderCell.Text            = "Итого";
                HeaderCell.Font.Bold       = true;
                HeaderCell.HorizontalAlign = HorizontalAlign.Right;
                HeaderCell.ColumnSpan      = SecVisibleColNum - 2;
                HeaderCell.ID              = "1_FOOTER_CELL_1" + postfix;
                HeaderGridRow.Cells.Add(HeaderCell);

                HeaderCell             = new TableCell();
                HeaderCell.BackColor   = System.Drawing.Color.White;
                HeaderCell.BorderColor = System.Drawing.Color.White;

                var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
                nfi.NumberGroupSeparator = " ";
                var total = totals[i].ToString("#,0.00", nfi);
                total           = total.Replace('.', ',');
                HeaderCell.Text = total;

                HeaderCell.Font.Bold  = true;
                HeaderCell.ColumnSpan = 2;
                HeaderCell.ID         = "1_FOOTER_CELL_2" + postfix;
                HeaderGridRow.Cells.Add(HeaderCell);
            }
            GridView1.Controls[0].Controls.AddAt(GridView1.Controls[0].Controls.Count - 1, HeaderGridRow);

            SpanRowsRecursive(0, 0, GridView1.Rows.Count);
            SpanColumns();
        }