www.pudn.com > DevPrintReport.rar > XRptGVMX.cs, change:2011-05-06,size:16423b


using System; 
using System.Drawing; 
using System.Collections; 
using System.ComponentModel; 
using DevExpress.XtraReports.UI; 
using System.Data; 
using System.Collections.Generic; 
 
namespace TZL_Print 
{ 
    public partial class XRptGVMX : DevExpress.XtraReports.UI.XtraReport 
    { 
        public XRptGVMX() 
        { 
            InitializeComponent(); 
        } 
        DataSet DataS_打印 = new DataSet(); 
        string uc_类名 = ""; 
        public XRptGVMX(ref DataSet ds, string uc_name) 
            : this() 
        { 
            DataS_打印 = ds; 
            uc_类名 = uc_name; 
            try 
            { 
                Data_TPrint = DataS_打印.Tables[DataS_打印.Tables.Count - 1]; 
            } 
            catch { } 
        } 
        DataTable dtgv = new DataTable(); 
        DataTable Data_TPrint = new DataTable(); 
        public XRptGVMX(ref DataTable dt, string uc_name) 
            : this() 
        { 
            this.DataSource = dt; 
            Data_TPrint = dt; 
            uc_类名 = uc_name; 
            SetGvData(Data_TPrint); 
            //this.advBandedGridView1.RefreshData(); 
            this.advBandedGridView1.OptionsPrint.UsePrintStyles = true; 
            this.advBandedGridView1.OptionsPrint.PrintHeader = false; 
            this.advBandedGridView1.AppearancePrint.BandPanel.BackColor = System.Drawing.Color.White; 
            this.advBandedGridView1.AppearancePrint.FooterPanel.BackColor = System.Drawing.Color.White; 
            //this.advBandedGridView1.CustomDrawBandHeader += new DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventHandler(advBandedGridView1_CustomDrawBandHeader); 
            //this.advBandedGridView1.CustomDrawColumnHeader += new DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventHandler(advBandedGridView1_CustomDrawColumnHeader); 
            //this.advBandedGridView1.BestFitColumns(); 
            advBandedGridView1.OptionsFilter.AllowColumnMRUFilterList = false; 
            advBandedGridView1.OptionsFilter.AllowFilterEditor = false; 
            advBandedGridView1.OptionsCustomization.AllowFilter = false; 
            advBandedGridView1.OptionsFilter.AllowColumnMRUFilterList = false; 
            advBandedGridView1.OptionsView.AllowCellMerge = true; 
            bandedGridColumn1.Width = 60; 
            //bandedGridColumn1.OptionsColumn.FixedWidth = true; 
        } 
 
        void advBandedGridView1_CustomDrawColumnHeader(object sender, DevExpress.XtraGrid.Views.Grid.ColumnHeaderCustomDrawEventArgs e) 
        { 
            e.Appearance.BackColor = Color.White; 
        } 
 
        void advBandedGridView1_CustomDrawBandHeader(object sender, DevExpress.XtraGrid.Views.BandedGrid.BandHeaderCustomDrawEventArgs e) 
        { 
            e.Appearance.BackColor = Color.White; 
        } 
        private void XtraReport1_DesignerLoaded(object sender, DevExpress.XtraReports.UserDesigner.DesignerLoadedEventArgs e) 
        { 
            //dgv_data.DataSource = Data_TPrint;// this.DataSource; 
            //xrPivotGrid1.DataSource = Data_TPrint; 
            SetGvData(Data_TPrint); 
            //dgv_data.DataSource = dtgv; 
            advBandedGridView1.BestFitColumns(); 
            bandedGridColumn1.Width = 60; 
            //bandedGridColumn1.OptionsColumn.FixedWidth = true; 
        } 
        private bool SetGvData(DataTable dgv_DataSoure) 
        { 
            try 
            { 
                List<string> khname = new List<string>(); 
                List<string> colorname = new List<string>(); 
                List<string> sizename = new List<string>(); 
                try 
                { 
                    dtgv.Rows.Clear(); 
                    dtgv.Columns.Clear(); 
                } 
                catch { } 
                dtgv = new DataTable(); 
                bool IsHaveLx = false; 
                try 
                { 
                    IsHaveLx = dgv_DataSoure.Columns.Contains("类型"); 
                } 
                catch { IsHaveLx = false; } 
                string oldkh = ""; 
                string oldcolor = ""; 
                string oldsize = ""; 
                for (int i = 0; i < dgv_DataSoure.Rows.Count; i++) 
                { 
                    string khcolor = dgv_DataSoure.Rows[i]["款号"].ToString() + "|" + dgv_DataSoure.Rows[i]["颜色"].ToString(); 
                    if (IsHaveLx) 
                        khcolor += "|" + dgv_DataSoure.Rows[i]["类型"].ToString(); 
                    if (!oldcolor.Contains("," + khcolor)) 
                    { 
                        oldcolor += "," + khcolor; 
                        colorname.Add(khcolor); 
                    } 
                    string size = dgv_DataSoure.Rows[i]["尺码"].ToString(); 
                    if (!oldsize.Contains("," + size)) 
                    { 
                        oldsize += "," + size; 
                        sizename.Add(size); 
                    } 
                } 
                this.advBandedGridView1.Columns.Clear(); 
                this.advBandedGridView1.Bands.Clear(); 
                if (IsHaveLx) 
                { 
                    //  
                    // bandedGridColumn1 
                    //  
                    this.bandedGridColumn0.Caption = "类型"; 
                    this.bandedGridColumn0.FieldName = "类型"; 
                    this.bandedGridColumn0.Name = "bandedGridColumn0"; 
                    this.bandedGridColumn0.OptionsColumn.AllowEdit = false; 
                    this.bandedGridColumn0.OptionsColumn.ReadOnly = true; 
                    this.bandedGridColumn0.OptionsFilter.AllowFilter = false; 
                    this.bandedGridColumn0.SortMode = DevExpress.XtraGrid.ColumnSortMode.DisplayText; 
                    this.bandedGridColumn0.Visible = true; 
                    this.bandedGridColumn0.MinWidth = 30; 
                    this.bandedGridColumn0.Width = 60; 
                    //  
                    // gridBand1 
                    //  
                    this.gridBand0.Caption = "类型"; 
                    this.gridBand0.Columns.Add(this.bandedGridColumn0); 
                    this.gridBand0.MinWidth = 30; 
                    this.gridBand0.Name = "gridBand0"; 
                    this.gridBand0.Width = 60; 
 
                    dtgv.Columns.Add("类型"); 
                    this.advBandedGridView1.Bands.Add(this.gridBand0); 
                    this.advBandedGridView1.Columns.Add(this.bandedGridColumn0); 
                } 
                //  
                // bandedGridColumn1 
                //  
                this.bandedGridColumn1.Caption = "款号"; 
                this.bandedGridColumn1.FieldName = "款号"; 
                this.bandedGridColumn1.Name = "bandedGridColumn1"; 
                this.bandedGridColumn1.OptionsColumn.AllowEdit = false; 
                this.bandedGridColumn1.OptionsColumn.ReadOnly = true; 
                this.bandedGridColumn1.OptionsFilter.AllowFilter = false; 
                this.bandedGridColumn1.SortMode = DevExpress.XtraGrid.ColumnSortMode.DisplayText; 
                this.bandedGridColumn1.Visible = true; 
                this.bandedGridColumn1.MinWidth = 60; 
                this.bandedGridColumn1.Width = 70; 
                //  
                // bandedGridColumn2 
                //  
                this.bandedGridColumn2.Caption = "颜色"; 
                this.bandedGridColumn2.FieldName = "颜色"; 
                this.bandedGridColumn2.Name = "bandedGridColumn2"; 
                this.bandedGridColumn2.OptionsColumn.AllowEdit = false; 
                this.bandedGridColumn2.OptionsColumn.ReadOnly = true; 
                this.bandedGridColumn2.OptionsFilter.AllowFilter = false; 
                this.bandedGridColumn2.SortMode = DevExpress.XtraGrid.ColumnSortMode.DisplayText; 
                this.bandedGridColumn2.Visible = true; 
                this.bandedGridColumn2.MinWidth = 30; 
                this.bandedGridColumn2.Width = 30; 
                this.bandedGridColumn2.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Custom; 
                this.bandedGridColumn2.SummaryItem.DisplayFormat = "合计"; 
                //  
                // bandedGridColumn3 
                //  
                this.bandedGridColumn3.Caption = "合计"; 
                this.bandedGridColumn3.FieldName = "合计"; 
                this.bandedGridColumn3.Name = "bandedGridColumn3"; 
                this.bandedGridColumn3.OptionsColumn.AllowEdit = false; 
                this.bandedGridColumn3.OptionsColumn.ReadOnly = true; 
                this.bandedGridColumn3.Visible = true; 
                this.bandedGridColumn3.MinWidth = 30; 
                this.bandedGridColumn3.Width = 30; 
                this.bandedGridColumn3.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; 
                this.bandedGridColumn3.SummaryItem.DisplayFormat = "{0}"; 
                //  
                // gridBand1 
                //  
                this.gridBand1.Caption = "款号"; 
                this.gridBand1.Columns.Add(this.bandedGridColumn1); 
 
                //this.gridBand1.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; 
                this.gridBand1.MinWidth = 60; 
                this.gridBand1.Name = "gridBand1"; 
                this.gridBand1.Width = 70; 
                //  
                // gridBand2 
                //  
                this.gridBand2.Caption = "颜色"; 
                this.gridBand2.Columns.Add(this.bandedGridColumn2); 
                //this.gridBand2.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Left; 
                this.gridBand2.MinWidth = 20; 
                this.gridBand2.Name = "gridBand2"; 
                this.gridBand2.Width = 30; 
                //  
                // gridBand3 
                //  
                this.gridBand3.AutoFillDown = true; 
                this.gridBand3.Caption = "尺码"; 
                this.gridBand3.MinWidth = 20; 
                this.gridBand3.Name = "gridBand3"; 
                this.gridBand3.Width = 360; 
                //  
                // gridBand4 
                //  
                this.gridBand4.Caption = "合计"; 
                this.gridBand4.Columns.Add(this.bandedGridColumn3); 
                //this.gridBand4.Fixed = DevExpress.XtraGrid.Columns.FixedStyle.Right; 
                this.gridBand4.MinWidth = 20; 
                this.gridBand4.Name = "gridBand4"; 
                this.gridBand4.Width = 30; 
 
                dtgv.Columns.Add("款号"); 
                dtgv.Columns.Add("颜色"); 
                this.advBandedGridView1.Bands.Add(this.gridBand1); 
                this.advBandedGridView1.Bands.Add(this.gridBand2); 
                this.advBandedGridView1.Columns.Add(this.bandedGridColumn1); 
                this.advBandedGridView1.Columns.Add(this.bandedGridColumn2); 
 
                gridBand3.Children.Clear(); 
                for (int i = 0; i < sizename.Count; i++) 
                { 
                    dtgv.Columns.Add(sizename[i], typeof(int)); 
 
                    DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn bGColumn1 = new DevExpress.XtraGrid.Views.BandedGrid.BandedGridColumn(); 
                    //  
                    // bGColumn 
                    //  
                    bGColumn1.Caption = sizename[i]; 
                    bGColumn1.FieldName = sizename[i]; 
                    bGColumn1.Name = "bGColumn" + sizename[i]; 
                    bGColumn1.Visible = true; 
                    bGColumn1.MinWidth = 20; 
                    bGColumn1.Width = 20; 
                    //DevExpress.XtraEditors.Repository.RepositoryItem RepositoryItem1 = new DevExpress.XtraEditors.Repository.RepositoryItem(); 
                    //RepositoryItem1.Name = "RepositoryItem" + i; 
                    //RepositoryItem1.Properties.NullText = "0"; 
                    //bGColumn1.ColumnEdit = RepositoryItem1; 
                    bGColumn1.SummaryItem.SummaryType = DevExpress.Data.SummaryItemType.Sum; 
                    bGColumn1.SummaryItem.DisplayFormat = "{0}"; 
 
                    DevExpress.XtraGrid.Views.BandedGrid.GridBand gBand2 = new DevExpress.XtraGrid.Views.BandedGrid.GridBand(); 
                    //  
                    // gridBand 
                    //  
                    gBand2.Caption = sizename[i]; 
                    gBand2.Name = "gridBand" + sizename[i]; 
                    gBand2.MinWidth = 20; 
                    gBand2.Width = 20; 
                    gBand2.OptionsBand.AllowSize = true; 
                    gBand2.OptionsBand.FixedWidth = true; 
                    gBand2.Columns.Add(bGColumn1); 
 
                    gridBand3.Children.Add(gBand2); 
                    this.advBandedGridView1.Columns.Add(bGColumn1); 
                } 
                this.advBandedGridView1.Bands.Add(this.gridBand3); 
 
                dtgv.Columns.Add("合计", typeof(int)); 
                this.advBandedGridView1.Bands.Add(this.gridBand4); 
                this.advBandedGridView1.Columns.Add(this.bandedGridColumn3); 
                string lxstr = ""; 
                for (int i = 0; i < colorname.Count; i++) 
                { 
 
                    string[] khcolor = colorname[i].Split('|'); 
                    DataRow dr = dtgv.NewRow(); 
                    dr["款号"] = khcolor[0]; 
                    dr["颜色"] = khcolor[1]; 
                    int sumsl = 0; 
                    if (IsHaveLx) 
                    { 
                        lxstr = khcolor[2]; 
                        dr["类型"] = lxstr; 
                        for (int j = 0; j < sizename.Count; j++) 
                        { 
                            try 
                            { 
                                DataRow[] drs = dgv_DataSoure.Select("类型='" + lxstr + "' and 款号='" + khcolor[0] + "' and 颜色='" + khcolor[1] + "'  and 尺码='" + sizename[j] + "'"); 
                                if (drs.Length > 0) 
                                { 
                                    int sl = 0; 
                                    if (int.TryParse(drs[0]["数量"].ToString(), out sl)) 
                                        dr[sizename[j]] = sl; 
                                    else 
                                        dr[sizename[j]] = DBNull.Value; 
                                    sumsl += sl; 
                                } 
                                else 
                                { 
                                    dr[sizename[j]] = 0; 
                                } 
                            } 
                            catch { dr[2 + j] = 0; } 
                        } 
                    } 
                    else 
                    { 
                        for (int j = 0; j < sizename.Count; j++) 
                        { 
                            try 
                            { 
                                DataRow[] drs = dgv_DataSoure.Select("款号='" + khcolor[0] + "' and 颜色='" + khcolor[1] + "'  and 尺码='" + sizename[j] + "'"); 
                                if (drs.Length > 0) 
                                { 
                                    int sl = 0; 
                                    if (int.TryParse(drs[0]["数量"].ToString(), out sl)) 
                                        dr[sizename[j]] = sl; 
                                    else 
                                        dr[sizename[j]] = DBNull.Value; 
                                    sumsl += sl; 
                                } 
                                else 
                                { 
                                    dr[sizename[j]] = 0; 
                                } 
                            } 
                            catch { dr[2 + j] = 0; } 
                        } 
                    } 
                    dr["合计"] = sumsl; 
                    dtgv.Rows.Add(dr); 
                } 
                dgv_data.DataSource = dtgv; 
                dtgv.AcceptChanges(); 
            } 
            catch { } 
            return true; 
        } 
 
        private void dgv_data_VisibleChanged(object sender, EventArgs e) 
        { 
            //if (this.Visible) 
            //    this.advBandedGridView1.BestFitColumns(); 
        } 
 
    } 
}